Whamcloud - gitweb
LU-8703 libcfs: remove usless abstraction
[fs/lustre-release.git] / libcfs / libcfs / libcfs_cpu.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 021110-1307, USA
20  *
21  * GPL HEADER END
22  */
23 /*
24  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
25  * Copyright (c) 2012, 2013, Intel Corporation.
26  */
27 /*
28  * This file is part of Lustre, http://www.lustre.org/
29  * Lustre is a trademark of Sun Microsystems, Inc.
30  *
31  * Please see comments in libcfs/include/libcfs/libcfs_cpu.h for introduction
32  *
33  * Author: liang@whamcloud.com
34  */
35
36 #define DEBUG_SUBSYSTEM S_LNET
37
38 #include <libcfs/libcfs.h>
39
40 /** Global CPU partition table */
41 struct cfs_cpt_table   *cfs_cpt_table __read_mostly = NULL;
42 EXPORT_SYMBOL(cfs_cpt_table);
43
44 #ifndef HAVE_LIBCFS_CPT
45
46 #define CFS_CPU_VERSION_MAGIC           0xbabecafe
47
48 #define CFS_CPT_DISTANCE                1       /* Arbitrary positive value */
49
50 struct cfs_cpt_table *
51 cfs_cpt_table_alloc(unsigned int ncpt)
52 {
53         struct cfs_cpt_table *cptab;
54
55         if (ncpt != 1) {
56                 CERROR("Can't support cpu partition number %d\n", ncpt);
57                 return NULL;
58         }
59
60         LIBCFS_ALLOC(cptab, sizeof(*cptab));
61         if (cptab != NULL) {
62                 cptab->ctb_version = CFS_CPU_VERSION_MAGIC;
63                 cpu_set(0, cptab->ctb_cpumask);
64                 node_set(0, cptab->ctb_nodemask);
65                 cptab->ctb_nparts  = ncpt;
66         }
67
68         return cptab;
69 }
70 EXPORT_SYMBOL(cfs_cpt_table_alloc);
71
72 void
73 cfs_cpt_table_free(struct cfs_cpt_table *cptab)
74 {
75         LASSERT(cptab->ctb_version == CFS_CPU_VERSION_MAGIC);
76
77         LIBCFS_FREE(cptab, sizeof(*cptab));
78 }
79 EXPORT_SYMBOL(cfs_cpt_table_free);
80
81 int
82 cfs_cpt_table_print(struct cfs_cpt_table *cptab, char *buf, int len)
83 {
84         int     rc = 0;
85
86         rc = snprintf(buf, len, "%d\t: %d\n", 0, 0);
87         len -= rc;
88         if (len <= 0)
89                 return -EFBIG;
90
91         return rc;
92 }
93 EXPORT_SYMBOL(cfs_cpt_table_print);
94
95 int
96 cfs_cpt_distance_print(struct cfs_cpt_table *cptab, char *buf, int len)
97 {
98         int     rc = 0;
99
100         rc = snprintf(buf, len, "%d\t: %d:%d\n", 0, CFS_CPT_DISTANCE);
101         len -= rc;
102         if (len <= 0)
103                 return -EFBIG;
104
105         return rc;
106 }
107 EXPORT_SYMBOL(cfs_cpt_distance_print);
108
109 int
110 cfs_cpt_number(struct cfs_cpt_table *cptab)
111 {
112         return 1;
113 }
114 EXPORT_SYMBOL(cfs_cpt_number);
115
116 int
117 cfs_cpt_weight(struct cfs_cpt_table *cptab, int cpt)
118 {
119         return 1;
120 }
121 EXPORT_SYMBOL(cfs_cpt_weight);
122
123 int
124 cfs_cpt_online(struct cfs_cpt_table *cptab, int cpt)
125 {
126         return 1;
127 }
128 EXPORT_SYMBOL(cfs_cpt_online);
129
130 cpumask_t *
131 cfs_cpt_cpumask(struct cfs_cpt_table *cptab, int cpt)
132 {
133         return &cptab->ctb_mask;
134 }
135 EXPORT_SYMBOL(cfs_cpt_cpumask);
136
137 nodemask_t *
138 cfs_cpt_nodemask(struct cfs_cpt_table *cptab, int cpt)
139 {
140         return &cptab->ctb_nodemask;
141 }
142 EXPORT_SYMBOL(cfs_cpt_nodemask);
143
144 unsigned
145 cfs_cpt_distance(struct cfs_cpt_table *cptab, int cpt1, int cpt2)
146 {
147         return CFS_CPT_DISTANCE;
148 }
149 EXPORT_SYMBOL(cfs_cpt_distance);
150
151 int
152 cfs_cpt_set_cpu(struct cfs_cpt_table *cptab, int cpt, int cpu)
153 {
154         return 1;
155 }
156 EXPORT_SYMBOL(cfs_cpt_set_cpu);
157
158 void
159 cfs_cpt_unset_cpu(struct cfs_cpt_table *cptab, int cpt, int cpu)
160 {
161 }
162 EXPORT_SYMBOL(cfs_cpt_unset_cpu);
163
164 int
165 cfs_cpt_set_cpumask(struct cfs_cpt_table *cptab, int cpt, const cpumask_t *mask)
166 {
167         return 1;
168 }
169 EXPORT_SYMBOL(cfs_cpt_set_cpumask);
170
171 void
172 cfs_cpt_unset_cpumask(struct cfs_cpt_table *cptab, int cpt,
173                       const cpumask_t *mask)
174 {
175 }
176 EXPORT_SYMBOL(cfs_cpt_unset_cpumask);
177
178 int
179 cfs_cpt_set_node(struct cfs_cpt_table *cptab, int cpt, int node)
180 {
181         return 1;
182 }
183 EXPORT_SYMBOL(cfs_cpt_set_node);
184
185 void
186 cfs_cpt_unset_node(struct cfs_cpt_table *cptab, int cpt, int node)
187 {
188 }
189 EXPORT_SYMBOL(cfs_cpt_unset_node);
190
191 int
192 cfs_cpt_set_nodemask(struct cfs_cpt_table *cptab, int cpt, nodemask_t *mask)
193 {
194         return 1;
195 }
196 EXPORT_SYMBOL(cfs_cpt_set_nodemask);
197
198 void
199 cfs_cpt_unset_nodemask(struct cfs_cpt_table *cptab, int cpt, nodemask_t *mask)
200 {
201 }
202 EXPORT_SYMBOL(cfs_cpt_unset_nodemask);
203
204 int
205 cfs_cpt_spread_node(struct cfs_cpt_table *cptab, int cpt)
206 {
207         return 0;
208 }
209 EXPORT_SYMBOL(cfs_cpt_spread_node);
210
211 int
212 cfs_cpt_current(struct cfs_cpt_table *cptab, int remap)
213 {
214         return 0;
215 }
216 EXPORT_SYMBOL(cfs_cpt_current);
217
218 int
219 cfs_cpt_of_cpu(struct cfs_cpt_table *cptab, int cpu)
220 {
221         return 0;
222 }
223 EXPORT_SYMBOL(cfs_cpt_of_cpu);
224
225 int
226 cfs_cpt_of_node(struct cfs_cpt_table *cptab, int node)
227 {
228         return 0;
229 }
230 EXPORT_SYMBOL(cfs_cpt_of_node);
231
232 int
233 cfs_cpt_bind(struct cfs_cpt_table *cptab, int cpt)
234 {
235         return 0;
236 }
237 EXPORT_SYMBOL(cfs_cpt_bind);
238
239 void
240 cfs_cpu_fini(void)
241 {
242         if (cfs_cpt_table != NULL) {
243                 cfs_cpt_table_free(cfs_cpt_table);
244                 cfs_cpt_table = NULL;
245         }
246 }
247
248 int
249 cfs_cpu_init(void)
250 {
251         cfs_cpt_table = cfs_cpt_table_alloc(1);
252
253         return cfs_cpt_table != NULL ? 0 : -1;
254 }
255
256 #endif /* HAVE_LIBCFS_CPT */