Whamcloud - gitweb
LU-9859 libcfs: delete libcfs/linux/libcfs.h
[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, 2017, 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/linux/linux-cpu.h>
39 #include <libcfs/libcfs.h>
40
41 /** Global CPU partition table */
42 struct cfs_cpt_table *cfs_cpt_table __read_mostly = NULL;
43 EXPORT_SYMBOL(cfs_cpt_table);
44
45 #ifndef HAVE_LIBCFS_CPT
46
47 #define CFS_CPU_VERSION_MAGIC           0xbabecafe
48
49 #define CFS_CPT_DISTANCE                1       /* Arbitrary positive value */
50
51 struct cfs_cpt_table *cfs_cpt_table_alloc(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 cfs_cpt_table_free(struct cfs_cpt_table *cptab)
73 {
74         LASSERT(cptab->ctb_version == CFS_CPU_VERSION_MAGIC);
75
76         LIBCFS_FREE(cptab, sizeof(*cptab));
77 }
78 EXPORT_SYMBOL(cfs_cpt_table_free);
79
80 int cfs_cpt_table_print(struct cfs_cpt_table *cptab, char *buf, int len)
81 {
82         int rc = 0;
83
84         rc = snprintf(buf, len, "%d\t: %d\n", 0, 0);
85         len -= rc;
86         if (len <= 0)
87                 return -EFBIG;
88
89         return rc;
90 }
91 EXPORT_SYMBOL(cfs_cpt_table_print);
92
93 int cfs_cpt_distance_print(struct cfs_cpt_table *cptab, char *buf, int len)
94 {
95         int     rc = 0;
96
97         rc = snprintf(buf, len, "%d\t: %d:%d\n", 0, CFS_CPT_DISTANCE);
98         len -= rc;
99         if (len <= 0)
100                 return -EFBIG;
101
102         return rc;
103 }
104 EXPORT_SYMBOL(cfs_cpt_distance_print);
105
106 int cfs_cpt_number(struct cfs_cpt_table *cptab)
107 {
108         return 1;
109 }
110 EXPORT_SYMBOL(cfs_cpt_number);
111
112 int cfs_cpt_weight(struct cfs_cpt_table *cptab, int cpt)
113 {
114         return 1;
115 }
116 EXPORT_SYMBOL(cfs_cpt_weight);
117
118 int cfs_cpt_online(struct cfs_cpt_table *cptab, int cpt)
119 {
120         return 1;
121 }
122 EXPORT_SYMBOL(cfs_cpt_online);
123
124 cpumask_t *cfs_cpt_cpumask(struct cfs_cpt_table *cptab, int cpt)
125 {
126         return &cptab->ctb_mask;
127 }
128 EXPORT_SYMBOL(cfs_cpt_cpumask);
129
130 nodemask_t *cfs_cpt_nodemask(struct cfs_cpt_table *cptab, int cpt)
131 {
132         return &cptab->ctb_nodemask;
133 }
134 EXPORT_SYMBOL(cfs_cpt_nodemask);
135
136 unsigned cfs_cpt_distance(struct cfs_cpt_table *cptab, int cpt1, int cpt2)
137 {
138         return CFS_CPT_DISTANCE;
139 }
140 EXPORT_SYMBOL(cfs_cpt_distance);
141
142 int cfs_cpt_set_cpu(struct cfs_cpt_table *cptab, int cpt, int cpu)
143 {
144         return 1;
145 }
146 EXPORT_SYMBOL(cfs_cpt_set_cpu);
147
148 void cfs_cpt_unset_cpu(struct cfs_cpt_table *cptab, int cpt, int cpu)
149 {
150 }
151 EXPORT_SYMBOL(cfs_cpt_unset_cpu);
152
153 int cfs_cpt_set_cpumask(struct cfs_cpt_table *cptab, int cpt,
154                         const cpumask_t *mask)
155 {
156         return 1;
157 }
158 EXPORT_SYMBOL(cfs_cpt_set_cpumask);
159
160 void cfs_cpt_unset_cpumask(struct cfs_cpt_table *cptab, int cpt,
161                            const cpumask_t *mask)
162 {
163 }
164 EXPORT_SYMBOL(cfs_cpt_unset_cpumask);
165
166 int cfs_cpt_set_node(struct cfs_cpt_table *cptab, int cpt, int node)
167 {
168         return 1;
169 }
170 EXPORT_SYMBOL(cfs_cpt_set_node);
171
172 void cfs_cpt_unset_node(struct cfs_cpt_table *cptab, int cpt, int node)
173 {
174 }
175 EXPORT_SYMBOL(cfs_cpt_unset_node);
176
177 int cfs_cpt_set_nodemask(struct cfs_cpt_table *cptab, int cpt,
178                          const nodemask_t *mask)
179 {
180         return 1;
181 }
182 EXPORT_SYMBOL(cfs_cpt_set_nodemask);
183
184 void cfs_cpt_unset_nodemask(struct cfs_cpt_table *cptab, int cpt,
185                             const nodemask_t *mask)
186 {
187 }
188 EXPORT_SYMBOL(cfs_cpt_unset_nodemask);
189
190 int cfs_cpt_spread_node(struct cfs_cpt_table *cptab, int cpt)
191 {
192         return 0;
193 }
194 EXPORT_SYMBOL(cfs_cpt_spread_node);
195
196 int cfs_cpt_current(struct cfs_cpt_table *cptab, int remap)
197 {
198         return 0;
199 }
200 EXPORT_SYMBOL(cfs_cpt_current);
201
202 int cfs_cpt_of_cpu(struct cfs_cpt_table *cptab, int cpu)
203 {
204         return 0;
205 }
206 EXPORT_SYMBOL(cfs_cpt_of_cpu);
207
208 int cfs_cpt_of_node(struct cfs_cpt_table *cptab, int node)
209 {
210         return 0;
211 }
212 EXPORT_SYMBOL(cfs_cpt_of_node);
213
214 int cfs_cpt_bind(struct cfs_cpt_table *cptab, int cpt)
215 {
216         return 0;
217 }
218 EXPORT_SYMBOL(cfs_cpt_bind);
219
220 void cfs_cpu_fini(void)
221 {
222         if (cfs_cpt_table != NULL) {
223                 cfs_cpt_table_free(cfs_cpt_table);
224                 cfs_cpt_table = NULL;
225         }
226 }
227
228 int cfs_cpu_init(void)
229 {
230         cfs_cpt_table = cfs_cpt_table_alloc(1);
231
232         return cfs_cpt_table != NULL ? 0 : -1;
233 }
234
235 #endif /* HAVE_LIBCFS_CPT */