Whamcloud - gitweb
LU-6399 lnet: socket cleanup
[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  * GPL HEADER END
17  */
18 /*
19  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
20  * Copyright (c) 2012, 2017, Intel Corporation.
21  */
22 /*
23  * This file is part of Lustre, http://www.lustre.org/
24  * Lustre is a trademark of Sun Microsystems, Inc.
25  *
26  * Please see comments in libcfs/include/libcfs/libcfs_cpu.h for introduction
27  *
28  * Author: liang@whamcloud.com
29  */
30
31 #define DEBUG_SUBSYSTEM S_LNET
32
33 #include <libcfs/linux/linux-cpu.h>
34 #include <libcfs/libcfs.h>
35
36 /** Global CPU partition table */
37 struct cfs_cpt_table *cfs_cpt_table __read_mostly;
38 EXPORT_SYMBOL(cfs_cpt_table);
39
40 #ifndef CONFIG_SMP
41
42 #define CFS_CPT_DISTANCE        1       /* Arbitrary positive value */
43
44 struct cfs_cpt_table *cfs_cpt_table_alloc(int ncpt)
45 {
46         struct cfs_cpt_table *cptab;
47
48         if (ncpt != 1) {
49                 CERROR("Can't support cpu partition number %d\n", ncpt);
50                 return NULL;
51         }
52
53         LIBCFS_ALLOC(cptab, sizeof(*cptab));
54         if (!cptab)
55                 return NULL;
56
57         cpumask_set_cpu(0, cptab->ctb_cpumask);
58         node_set(0, cptab->ctb_nodemask);
59
60         return cptab;
61 }
62 EXPORT_SYMBOL(cfs_cpt_table_alloc);
63
64 void cfs_cpt_table_free(struct cfs_cpt_table *cptab)
65 {
66         LIBCFS_FREE(cptab, sizeof(*cptab));
67 }
68 EXPORT_SYMBOL(cfs_cpt_table_free);
69
70 int cfs_cpt_table_print(struct cfs_cpt_table *cptab, char *buf, int len)
71 {
72         int rc;
73
74         rc = snprintf(buf, len, "%d\t: %d\n", 0, 0);
75         len -= rc;
76         if (len <= 0)
77                 return -EFBIG;
78
79         return rc;
80 }
81 EXPORT_SYMBOL(cfs_cpt_table_print);
82
83 int cfs_cpt_distance_print(struct cfs_cpt_table *cptab, char *buf, int len)
84 {
85         int rc;
86
87         rc = snprintf(buf, len, "0\t: 0:%d\n", CFS_CPT_DISTANCE);
88         len -= rc;
89         if (len <= 0)
90                 return -EFBIG;
91
92         return rc;
93 }
94 EXPORT_SYMBOL(cfs_cpt_distance_print);
95
96 int cfs_cpt_number(struct cfs_cpt_table *cptab)
97 {
98         return 1;
99 }
100 EXPORT_SYMBOL(cfs_cpt_number);
101
102 int cfs_cpt_weight(struct cfs_cpt_table *cptab, int cpt)
103 {
104         return 1;
105 }
106 EXPORT_SYMBOL(cfs_cpt_weight);
107
108 int cfs_cpt_online(struct cfs_cpt_table *cptab, int cpt)
109 {
110         return 1;
111 }
112 EXPORT_SYMBOL(cfs_cpt_online);
113
114 cpumask_t *cfs_cpt_cpumask(struct cfs_cpt_table *cptab, int cpt)
115 {
116         return &cptab->ctb_cpumask;
117 }
118 EXPORT_SYMBOL(cfs_cpt_cpumask);
119
120 nodemask_t *cfs_cpt_nodemask(struct cfs_cpt_table *cptab, int cpt)
121 {
122         return &cptab->ctb_nodemask;
123 }
124 EXPORT_SYMBOL(cfs_cpt_nodemask);
125
126 unsigned int cfs_cpt_distance(struct cfs_cpt_table *cptab, int cpt1, int cpt2)
127 {
128         return CFS_CPT_DISTANCE;
129 }
130 EXPORT_SYMBOL(cfs_cpt_distance);
131
132 int cfs_cpt_set_cpu(struct cfs_cpt_table *cptab, int cpt, int cpu)
133 {
134         return 1;
135 }
136 EXPORT_SYMBOL(cfs_cpt_set_cpu);
137
138 void cfs_cpt_unset_cpu(struct cfs_cpt_table *cptab, int cpt, int cpu)
139 {
140 }
141 EXPORT_SYMBOL(cfs_cpt_unset_cpu);
142
143 int cfs_cpt_set_cpumask(struct cfs_cpt_table *cptab, int cpt,
144                         const cpumask_t *mask)
145 {
146         return 1;
147 }
148 EXPORT_SYMBOL(cfs_cpt_set_cpumask);
149
150 void cfs_cpt_unset_cpumask(struct cfs_cpt_table *cptab, int cpt,
151                            const cpumask_t *mask)
152 {
153 }
154 EXPORT_SYMBOL(cfs_cpt_unset_cpumask);
155
156 int cfs_cpt_set_node(struct cfs_cpt_table *cptab, int cpt, int node)
157 {
158         return 1;
159 }
160 EXPORT_SYMBOL(cfs_cpt_set_node);
161
162 void cfs_cpt_unset_node(struct cfs_cpt_table *cptab, int cpt, int node)
163 {
164 }
165 EXPORT_SYMBOL(cfs_cpt_unset_node);
166
167 int cfs_cpt_set_nodemask(struct cfs_cpt_table *cptab, int cpt,
168                          const nodemask_t *mask)
169 {
170         return 1;
171 }
172 EXPORT_SYMBOL(cfs_cpt_set_nodemask);
173
174 void cfs_cpt_unset_nodemask(struct cfs_cpt_table *cptab, int cpt,
175                             const nodemask_t *mask)
176 {
177 }
178 EXPORT_SYMBOL(cfs_cpt_unset_nodemask);
179
180 int cfs_cpt_spread_node(struct cfs_cpt_table *cptab, int cpt)
181 {
182         return 0;
183 }
184 EXPORT_SYMBOL(cfs_cpt_spread_node);
185
186 int cfs_cpt_current(struct cfs_cpt_table *cptab, int remap)
187 {
188         return 0;
189 }
190 EXPORT_SYMBOL(cfs_cpt_current);
191
192 int cfs_cpt_of_cpu(struct cfs_cpt_table *cptab, int cpu)
193 {
194         return 0;
195 }
196 EXPORT_SYMBOL(cfs_cpt_of_cpu);
197
198 int cfs_cpt_of_node(struct cfs_cpt_table *cptab, int node)
199 {
200         return 0;
201 }
202 EXPORT_SYMBOL(cfs_cpt_of_node);
203
204 int cfs_cpt_bind(struct cfs_cpt_table *cptab, int cpt)
205 {
206         return 0;
207 }
208 EXPORT_SYMBOL(cfs_cpt_bind);
209
210 void cfs_cpu_fini(void)
211 {
212         if (cfs_cpt_table) {
213                 cfs_cpt_table_free(cfs_cpt_table);
214                 cfs_cpt_table = NULL;
215         }
216 }
217
218 int cfs_cpu_init(void)
219 {
220         cfs_cpt_table = cfs_cpt_table_alloc(1);
221
222         return cfs_cpt_table ? 0 : -1;
223 }
224
225 #endif /* !CONFIG_SMP */