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