1 // SPDX-License-Identifier: GPL-2.0
5 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
20 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
21 * Copyright (c) 2012, Intel Corporation.
24 * This file is part of Lustre, http://www.lustre.org/
25 * Lustre is a trademark of Sun Microsystems, Inc.
27 * Please see comments in libcfs/include/libcfs/libcfs_cpu.h for introduction
29 * Author: liang@whamcloud.com
32 #define DEBUG_SUBSYSTEM S_LNET
34 #include <linux/libcfs/libcfs.h>
36 /** Global CPU partition table */
37 struct cfs_cpt_table *cfs_cpt_table __read_mostly;
38 EXPORT_SYMBOL(cfs_cpt_table);
40 #ifndef HAVE_LIBCFS_CPT
42 #define CFS_CPU_VERSION_MAGIC 0xbabecafe
44 struct cfs_cpt_table *
45 cfs_cpt_table_alloc(unsigned int ncpt)
47 struct cfs_cpt_table *cptab;
50 CERROR("Can't support cpu partition number %d\n", ncpt);
54 LIBCFS_ALLOC(cptab, sizeof(*cptab));
56 cptab->ctb_version = CFS_CPU_VERSION_MAGIC;
57 node_set(0, cptab->ctb_nodemask);
58 cptab->ctb_nparts = ncpt;
63 EXPORT_SYMBOL(cfs_cpt_table_alloc);
66 cfs_cpt_table_free(struct cfs_cpt_table *cptab)
68 LASSERT(cptab->ctb_version == CFS_CPU_VERSION_MAGIC);
70 LIBCFS_FREE(cptab, sizeof(*cptab));
72 EXPORT_SYMBOL(cfs_cpt_table_free);
76 cfs_cpt_table_print(struct cfs_cpt_table *cptab, char *buf, int len)
80 rc = snprintf(buf, len, "%d\t: %d\n", 0, 0);
87 EXPORT_SYMBOL(cfs_cpt_table_print);
88 #endif /* CONFIG_SMP */
91 cfs_cpt_number(struct cfs_cpt_table *cptab)
95 EXPORT_SYMBOL(cfs_cpt_number);
98 cfs_cpt_weight(struct cfs_cpt_table *cptab, int cpt)
102 EXPORT_SYMBOL(cfs_cpt_weight);
105 cfs_cpt_online(struct cfs_cpt_table *cptab, int cpt)
109 EXPORT_SYMBOL(cfs_cpt_online);
112 cfs_cpt_nodemask(struct cfs_cpt_table *cptab, int cpt)
114 return &cptab->ctb_nodemask;
116 EXPORT_SYMBOL(cfs_cpt_cpumask);
119 cfs_cpt_set_cpu(struct cfs_cpt_table *cptab, int cpt, int cpu)
123 EXPORT_SYMBOL(cfs_cpt_set_cpu);
126 cfs_cpt_unset_cpu(struct cfs_cpt_table *cptab, int cpt, int cpu)
129 EXPORT_SYMBOL(cfs_cpt_unset_cpu);
132 cfs_cpt_set_cpumask(struct cfs_cpt_table *cptab, int cpt, cpumask_t *mask)
136 EXPORT_SYMBOL(cfs_cpt_set_cpumask);
139 cfs_cpt_unset_cpumask(struct cfs_cpt_table *cptab, int cpt, cpumask_t *mask)
142 EXPORT_SYMBOL(cfs_cpt_unset_cpumask);
145 cfs_cpt_set_node(struct cfs_cpt_table *cptab, int cpt, int node)
149 EXPORT_SYMBOL(cfs_cpt_set_node);
152 cfs_cpt_unset_node(struct cfs_cpt_table *cptab, int cpt, int node)
155 EXPORT_SYMBOL(cfs_cpt_unset_node);
158 cfs_cpt_set_nodemask(struct cfs_cpt_table *cptab, int cpt, nodemask_t *mask)
162 EXPORT_SYMBOL(cfs_cpt_set_nodemask);
165 cfs_cpt_unset_nodemask(struct cfs_cpt_table *cptab, int cpt, nodemask_t *mask)
168 EXPORT_SYMBOL(cfs_cpt_unset_nodemask);
171 cfs_cpt_clear(struct cfs_cpt_table *cptab, int cpt)
174 EXPORT_SYMBOL(cfs_cpt_clear);
177 cfs_cpt_spread_node(struct cfs_cpt_table *cptab, int cpt)
181 EXPORT_SYMBOL(cfs_cpt_spread_node);
184 cfs_cpu_ht_nsiblings(int cpu)
188 EXPORT_SYMBOL(cfs_cpu_ht_nsiblings);
191 cfs_cpt_current(struct cfs_cpt_table *cptab, int remap)
195 EXPORT_SYMBOL(cfs_cpt_current);
198 cfs_cpt_of_cpu(struct cfs_cpt_table *cptab, int cpu)
202 EXPORT_SYMBOL(cfs_cpt_of_cpu);
205 cfs_cpt_bind(struct cfs_cpt_table *cptab, int cpt)
209 EXPORT_SYMBOL(cfs_cpt_bind);
215 cfs_cpt_table_free(cfs_cpt_table);
216 cfs_cpt_table = NULL;
223 cfs_cpt_table = cfs_cpt_table_alloc(1);
225 return cfs_cpt_table ? 0 : -1;
228 #endif /* HAVE_LIBCFS_CPT */