Whamcloud - gitweb
LU-10308 misc: update Intel copyright messages for 2017
[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/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 *cfs_cpt_table_alloc(int ncpt)
51 {
52         struct cfs_cpt_table *cptab;
53
54         if (ncpt != 1) {
55                 CERROR("Can't support cpu partition number %d\n", ncpt);
56                 return NULL;
57         }
58
59         LIBCFS_ALLOC(cptab, sizeof(*cptab));
60         if (cptab != NULL) {
61                 cptab->ctb_version = CFS_CPU_VERSION_MAGIC;
62                 cpu_set(0, cptab->ctb_cpumask);
63                 node_set(0, cptab->ctb_nodemask);
64                 cptab->ctb_nparts  = ncpt;
65         }
66
67         return cptab;
68 }
69 EXPORT_SYMBOL(cfs_cpt_table_alloc);
70
71 void cfs_cpt_table_free(struct cfs_cpt_table *cptab)
72 {
73         LASSERT(cptab->ctb_version == CFS_CPU_VERSION_MAGIC);
74
75         LIBCFS_FREE(cptab, sizeof(*cptab));
76 }
77 EXPORT_SYMBOL(cfs_cpt_table_free);
78
79 int cfs_cpt_table_print(struct cfs_cpt_table *cptab, char *buf, int len)
80 {
81         int rc = 0;
82
83         rc = snprintf(buf, len, "%d\t: %d\n", 0, 0);
84         len -= rc;
85         if (len <= 0)
86                 return -EFBIG;
87
88         return rc;
89 }
90 EXPORT_SYMBOL(cfs_cpt_table_print);
91
92 int cfs_cpt_distance_print(struct cfs_cpt_table *cptab, char *buf, int len)
93 {
94         int     rc = 0;
95
96         rc = snprintf(buf, len, "%d\t: %d:%d\n", 0, CFS_CPT_DISTANCE);
97         len -= rc;
98         if (len <= 0)
99                 return -EFBIG;
100
101         return rc;
102 }
103 EXPORT_SYMBOL(cfs_cpt_distance_print);
104
105 int cfs_cpt_number(struct cfs_cpt_table *cptab)
106 {
107         return 1;
108 }
109 EXPORT_SYMBOL(cfs_cpt_number);
110
111 int cfs_cpt_weight(struct cfs_cpt_table *cptab, int cpt)
112 {
113         return 1;
114 }
115 EXPORT_SYMBOL(cfs_cpt_weight);
116
117 int cfs_cpt_online(struct cfs_cpt_table *cptab, int cpt)
118 {
119         return 1;
120 }
121 EXPORT_SYMBOL(cfs_cpt_online);
122
123 cpumask_t *cfs_cpt_cpumask(struct cfs_cpt_table *cptab, int cpt)
124 {
125         return &cptab->ctb_mask;
126 }
127 EXPORT_SYMBOL(cfs_cpt_cpumask);
128
129 nodemask_t *cfs_cpt_nodemask(struct cfs_cpt_table *cptab, int cpt)
130 {
131         return &cptab->ctb_nodemask;
132 }
133 EXPORT_SYMBOL(cfs_cpt_nodemask);
134
135 unsigned cfs_cpt_distance(struct cfs_cpt_table *cptab, int cpt1, int cpt2)
136 {
137         return CFS_CPT_DISTANCE;
138 }
139 EXPORT_SYMBOL(cfs_cpt_distance);
140
141 int cfs_cpt_set_cpu(struct cfs_cpt_table *cptab, int cpt, int cpu)
142 {
143         return 1;
144 }
145 EXPORT_SYMBOL(cfs_cpt_set_cpu);
146
147 void cfs_cpt_unset_cpu(struct cfs_cpt_table *cptab, int cpt, int cpu)
148 {
149 }
150 EXPORT_SYMBOL(cfs_cpt_unset_cpu);
151
152 int cfs_cpt_set_cpumask(struct cfs_cpt_table *cptab, int cpt,
153                         const cpumask_t *mask)
154 {
155         return 1;
156 }
157 EXPORT_SYMBOL(cfs_cpt_set_cpumask);
158
159 void cfs_cpt_unset_cpumask(struct cfs_cpt_table *cptab, int cpt,
160                            const cpumask_t *mask)
161 {
162 }
163 EXPORT_SYMBOL(cfs_cpt_unset_cpumask);
164
165 int cfs_cpt_set_node(struct cfs_cpt_table *cptab, int cpt, int node)
166 {
167         return 1;
168 }
169 EXPORT_SYMBOL(cfs_cpt_set_node);
170
171 void cfs_cpt_unset_node(struct cfs_cpt_table *cptab, int cpt, int node)
172 {
173 }
174 EXPORT_SYMBOL(cfs_cpt_unset_node);
175
176 int cfs_cpt_set_nodemask(struct cfs_cpt_table *cptab, int cpt,
177                          const nodemask_t *mask)
178 {
179         return 1;
180 }
181 EXPORT_SYMBOL(cfs_cpt_set_nodemask);
182
183 void cfs_cpt_unset_nodemask(struct cfs_cpt_table *cptab, int cpt,
184                             const nodemask_t *mask)
185 {
186 }
187 EXPORT_SYMBOL(cfs_cpt_unset_nodemask);
188
189 int cfs_cpt_spread_node(struct cfs_cpt_table *cptab, int cpt)
190 {
191         return 0;
192 }
193 EXPORT_SYMBOL(cfs_cpt_spread_node);
194
195 int cfs_cpt_current(struct cfs_cpt_table *cptab, int remap)
196 {
197         return 0;
198 }
199 EXPORT_SYMBOL(cfs_cpt_current);
200
201 int cfs_cpt_of_cpu(struct cfs_cpt_table *cptab, int cpu)
202 {
203         return 0;
204 }
205 EXPORT_SYMBOL(cfs_cpt_of_cpu);
206
207 int cfs_cpt_of_node(struct cfs_cpt_table *cptab, int node)
208 {
209         return 0;
210 }
211 EXPORT_SYMBOL(cfs_cpt_of_node);
212
213 int cfs_cpt_bind(struct cfs_cpt_table *cptab, int cpt)
214 {
215         return 0;
216 }
217 EXPORT_SYMBOL(cfs_cpt_bind);
218
219 void cfs_cpu_fini(void)
220 {
221         if (cfs_cpt_table != NULL) {
222                 cfs_cpt_table_free(cfs_cpt_table);
223                 cfs_cpt_table = NULL;
224         }
225 }
226
227 int cfs_cpu_init(void)
228 {
229         cfs_cpt_table = cfs_cpt_table_alloc(1);
230
231         return cfs_cpt_table != NULL ? 0 : -1;
232 }
233
234 #endif /* HAVE_LIBCFS_CPT */