4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
24 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
26 * Copyright (c) 2012, 2016, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * Author: liang@whamcloud.com
35 #define DEBUG_SUBSYSTEM S_LNET
37 #include <linux/cpu.h>
38 #include <linux/sched.h>
39 #include <libcfs/libcfs.h>
44 * modparam for setting number of partitions
46 * 0 : estimate best value based on cores or NUMA nodes
47 * 1 : disable multiple partitions
48 * >1 : specify number of partitions
50 static int cpu_npartitions;
51 module_param(cpu_npartitions, int, 0444);
52 MODULE_PARM_DESC(cpu_npartitions, "# of CPU partitions");
55 * modparam for setting CPU partitions patterns:
57 * i.e: "0[0,1,2,3] 1[4,5,6,7]", number before bracket is CPU partition ID,
58 * number in bracket is processor ID (core or HT)
60 * i.e: "N 0[0,1] 1[2,3]" the first character 'N' means numbers in bracket
61 * are NUMA node ID, number before bracket is CPU partition ID.
63 * i.e: "N", shortcut expression to create CPT from NUMA & CPU topology
65 * NB: If user specified cpu_pattern, cpu_npartitions will be ignored
67 static char *cpu_pattern = "N";
68 module_param(cpu_pattern, charp, 0444);
69 MODULE_PARM_DESC(cpu_pattern, "CPU partitions pattern");
71 /* return number of HTs in the same core of \a cpu */
73 cfs_cpu_ht_nsiblings(int cpu)
75 return cpumask_weight(topology_sibling_cpumask(cpu));
77 EXPORT_SYMBOL(cfs_cpu_ht_nsiblings);
80 cfs_cpt_table_free(struct cfs_cpt_table *cptab)
84 if (cptab->ctb_cpu2cpt != NULL) {
85 LIBCFS_FREE(cptab->ctb_cpu2cpt,
87 sizeof(cptab->ctb_cpu2cpt[0]));
90 for (i = 0; cptab->ctb_parts != NULL && i < cptab->ctb_nparts; i++) {
91 struct cfs_cpu_partition *part = &cptab->ctb_parts[i];
93 if (part->cpt_nodemask != NULL) {
94 LIBCFS_FREE(part->cpt_nodemask,
95 sizeof(*part->cpt_nodemask));
98 if (part->cpt_cpumask != NULL)
99 LIBCFS_FREE(part->cpt_cpumask, cpumask_size());
102 if (cptab->ctb_parts != NULL) {
103 LIBCFS_FREE(cptab->ctb_parts,
104 cptab->ctb_nparts * sizeof(cptab->ctb_parts[0]));
107 if (cptab->ctb_nodemask != NULL)
108 LIBCFS_FREE(cptab->ctb_nodemask, sizeof(*cptab->ctb_nodemask));
109 if (cptab->ctb_cpumask != NULL)
110 LIBCFS_FREE(cptab->ctb_cpumask, cpumask_size());
112 LIBCFS_FREE(cptab, sizeof(*cptab));
114 EXPORT_SYMBOL(cfs_cpt_table_free);
116 struct cfs_cpt_table *
117 cfs_cpt_table_alloc(unsigned int ncpt)
119 struct cfs_cpt_table *cptab;
122 LIBCFS_ALLOC(cptab, sizeof(*cptab));
126 cptab->ctb_nparts = ncpt;
128 LIBCFS_ALLOC(cptab->ctb_cpumask, cpumask_size());
129 LIBCFS_ALLOC(cptab->ctb_nodemask, sizeof(*cptab->ctb_nodemask));
131 if (cptab->ctb_cpumask == NULL || cptab->ctb_nodemask == NULL)
134 LIBCFS_ALLOC(cptab->ctb_cpu2cpt,
135 num_possible_cpus() * sizeof(cptab->ctb_cpu2cpt[0]));
136 if (cptab->ctb_cpu2cpt == NULL)
139 memset(cptab->ctb_cpu2cpt, -1,
140 num_possible_cpus() * sizeof(cptab->ctb_cpu2cpt[0]));
142 LIBCFS_ALLOC(cptab->ctb_parts, ncpt * sizeof(cptab->ctb_parts[0]));
143 if (cptab->ctb_parts == NULL)
146 for (i = 0; i < ncpt; i++) {
147 struct cfs_cpu_partition *part = &cptab->ctb_parts[i];
149 LIBCFS_ALLOC(part->cpt_cpumask, cpumask_size());
150 LIBCFS_ALLOC(part->cpt_nodemask, sizeof(*part->cpt_nodemask));
151 if (part->cpt_cpumask == NULL || part->cpt_nodemask == NULL)
158 cfs_cpt_table_free(cptab);
161 EXPORT_SYMBOL(cfs_cpt_table_alloc);
164 cfs_cpt_table_print(struct cfs_cpt_table *cptab, char *buf, int len)
171 for (i = 0; i < cptab->ctb_nparts; i++) {
173 rc = snprintf(tmp, len, "%d\t: ", i);
183 for_each_cpu(j, cptab->ctb_parts[i].cpt_cpumask) {
184 rc = snprintf(tmp, len, "%d ", j);
204 EXPORT_SYMBOL(cfs_cpt_table_print);
207 cfs_cpt_number(struct cfs_cpt_table *cptab)
209 return cptab->ctb_nparts;
211 EXPORT_SYMBOL(cfs_cpt_number);
214 cfs_cpt_weight(struct cfs_cpt_table *cptab, int cpt)
216 LASSERT(cpt == CFS_CPT_ANY || (cpt >= 0 && cpt < cptab->ctb_nparts));
218 return cpt == CFS_CPT_ANY ?
219 cpumask_weight(cptab->ctb_cpumask) :
220 cpumask_weight(cptab->ctb_parts[cpt].cpt_cpumask);
222 EXPORT_SYMBOL(cfs_cpt_weight);
225 cfs_cpt_online(struct cfs_cpt_table *cptab, int cpt)
227 LASSERT(cpt == CFS_CPT_ANY || (cpt >= 0 && cpt < cptab->ctb_nparts));
229 return cpt == CFS_CPT_ANY ?
230 cpumask_any_and(cptab->ctb_cpumask,
231 cpu_online_mask) < nr_cpu_ids :
232 cpumask_any_and(cptab->ctb_parts[cpt].cpt_cpumask,
233 cpu_online_mask) < nr_cpu_ids;
235 EXPORT_SYMBOL(cfs_cpt_online);
238 cfs_cpt_cpumask(struct cfs_cpt_table *cptab, int cpt)
240 LASSERT(cpt == CFS_CPT_ANY || (cpt >= 0 && cpt < cptab->ctb_nparts));
242 return cpt == CFS_CPT_ANY ?
243 cptab->ctb_cpumask : cptab->ctb_parts[cpt].cpt_cpumask;
245 EXPORT_SYMBOL(cfs_cpt_cpumask);
248 cfs_cpt_nodemask(struct cfs_cpt_table *cptab, int cpt)
250 LASSERT(cpt == CFS_CPT_ANY || (cpt >= 0 && cpt < cptab->ctb_nparts));
252 return cpt == CFS_CPT_ANY ?
253 cptab->ctb_nodemask : cptab->ctb_parts[cpt].cpt_nodemask;
255 EXPORT_SYMBOL(cfs_cpt_nodemask);
258 cfs_cpt_set_cpu(struct cfs_cpt_table *cptab, int cpt, int cpu)
262 LASSERT(cpt >= 0 && cpt < cptab->ctb_nparts);
264 if (cpu < 0 || cpu >= nr_cpu_ids || !cpu_online(cpu)) {
265 CDEBUG(D_INFO, "CPU %d is invalid or it's offline\n", cpu);
269 if (cptab->ctb_cpu2cpt[cpu] != -1) {
270 CDEBUG(D_INFO, "CPU %d is already in partition %d\n",
271 cpu, cptab->ctb_cpu2cpt[cpu]);
275 cptab->ctb_cpu2cpt[cpu] = cpt;
277 LASSERT(!cpumask_test_cpu(cpu, cptab->ctb_cpumask));
278 LASSERT(!cpumask_test_cpu(cpu, cptab->ctb_parts[cpt].cpt_cpumask));
280 cpumask_set_cpu(cpu, cptab->ctb_cpumask);
281 cpumask_set_cpu(cpu, cptab->ctb_parts[cpt].cpt_cpumask);
283 node = cpu_to_node(cpu);
285 /* first CPU of @node in this CPT table */
286 if (!node_isset(node, *cptab->ctb_nodemask))
287 node_set(node, *cptab->ctb_nodemask);
289 /* first CPU of @node in this partition */
290 if (!node_isset(node, *cptab->ctb_parts[cpt].cpt_nodemask))
291 node_set(node, *cptab->ctb_parts[cpt].cpt_nodemask);
295 EXPORT_SYMBOL(cfs_cpt_set_cpu);
298 cfs_cpt_unset_cpu(struct cfs_cpt_table *cptab, int cpt, int cpu)
303 LASSERT(cpt == CFS_CPT_ANY || (cpt >= 0 && cpt < cptab->ctb_nparts));
305 if (cpu < 0 || cpu >= nr_cpu_ids) {
306 CDEBUG(D_INFO, "Invalid CPU id %d\n", cpu);
310 if (cpt == CFS_CPT_ANY) {
311 /* caller doesn't know the partition ID */
312 cpt = cptab->ctb_cpu2cpt[cpu];
313 if (cpt < 0) { /* not set in this CPT-table */
314 CDEBUG(D_INFO, "Try to unset cpu %d which is "
315 "not in CPT-table %p\n", cpt, cptab);
319 } else if (cpt != cptab->ctb_cpu2cpt[cpu]) {
321 "CPU %d is not in cpu-partition %d\n", cpu, cpt);
325 LASSERT(cpumask_test_cpu(cpu, cptab->ctb_parts[cpt].cpt_cpumask));
326 LASSERT(cpumask_test_cpu(cpu, cptab->ctb_cpumask));
328 cpumask_clear_cpu(cpu, cptab->ctb_parts[cpt].cpt_cpumask);
329 cpumask_clear_cpu(cpu, cptab->ctb_cpumask);
330 cptab->ctb_cpu2cpt[cpu] = -1;
332 node = cpu_to_node(cpu);
334 LASSERT(node_isset(node, *cptab->ctb_parts[cpt].cpt_nodemask));
335 LASSERT(node_isset(node, *cptab->ctb_nodemask));
337 for_each_cpu(i, cptab->ctb_parts[cpt].cpt_cpumask) {
338 /* this CPT has other CPU belonging to this node? */
339 if (cpu_to_node(i) == node)
344 node_clear(node, *cptab->ctb_parts[cpt].cpt_nodemask);
346 for_each_cpu(i, cptab->ctb_cpumask) {
347 /* this CPT-table has other CPU belonging to this node? */
348 if (cpu_to_node(i) == node)
353 node_clear(node, *cptab->ctb_nodemask);
355 EXPORT_SYMBOL(cfs_cpt_unset_cpu);
358 cfs_cpt_set_cpumask(struct cfs_cpt_table *cptab, int cpt, const cpumask_t *mask)
362 if (cpumask_weight(mask) == 0 ||
363 cpumask_any_and(mask, cpu_online_mask) >= nr_cpu_ids) {
364 CDEBUG(D_INFO, "No online CPU is found in the CPU mask "
365 "for CPU partition %d\n", cpt);
369 for_each_cpu(cpu, mask) {
370 if (!cfs_cpt_set_cpu(cptab, cpt, cpu))
376 EXPORT_SYMBOL(cfs_cpt_set_cpumask);
379 cfs_cpt_unset_cpumask(struct cfs_cpt_table *cptab, int cpt,
380 const cpumask_t *mask)
384 for_each_cpu(cpu, mask)
385 cfs_cpt_unset_cpu(cptab, cpt, cpu);
387 EXPORT_SYMBOL(cfs_cpt_unset_cpumask);
390 cfs_cpt_set_node(struct cfs_cpt_table *cptab, int cpt, int node)
392 const cpumask_t *mask;
395 if (node < 0 || node >= MAX_NUMNODES) {
397 "Invalid NUMA id %d for CPU partition %d\n", node, cpt);
401 mask = cpumask_of_node(node);
402 rc = cfs_cpt_set_cpumask(cptab, cpt, mask);
406 EXPORT_SYMBOL(cfs_cpt_set_node);
409 cfs_cpt_unset_node(struct cfs_cpt_table *cptab, int cpt, int node)
411 const cpumask_t *mask;
413 if (node < 0 || node >= MAX_NUMNODES) {
415 "Invalid NUMA id %d for CPU partition %d\n", node, cpt);
419 mask = cpumask_of_node(node);
420 cfs_cpt_unset_cpumask(cptab, cpt, mask);
423 EXPORT_SYMBOL(cfs_cpt_unset_node);
426 cfs_cpt_set_nodemask(struct cfs_cpt_table *cptab, int cpt, nodemask_t *mask)
430 for_each_node_mask(i, *mask) {
431 if (!cfs_cpt_set_node(cptab, cpt, i))
437 EXPORT_SYMBOL(cfs_cpt_set_nodemask);
440 cfs_cpt_unset_nodemask(struct cfs_cpt_table *cptab, int cpt, nodemask_t *mask)
444 for_each_node_mask(i, *mask)
445 cfs_cpt_unset_node(cptab, cpt, i);
447 EXPORT_SYMBOL(cfs_cpt_unset_nodemask);
449 int cfs_cpt_spread_node(struct cfs_cpt_table *cptab, int cpt)
456 /* convert CPU partition ID to HW node id */
458 if (cpt < 0 || cpt >= cptab->ctb_nparts) {
459 mask = cptab->ctb_nodemask;
460 rotor = cptab->ctb_spread_rotor++;
462 mask = cptab->ctb_parts[cpt].cpt_nodemask;
463 rotor = cptab->ctb_parts[cpt].cpt_spread_rotor++;
466 weight = nodes_weight(*mask);
471 for_each_node_mask(node, *mask) {
479 EXPORT_SYMBOL(cfs_cpt_spread_node);
482 cfs_cpt_current(struct cfs_cpt_table *cptab, int remap)
484 int cpu = smp_processor_id();
485 int cpt = cptab->ctb_cpu2cpt[cpu];
491 /* don't return negative value for safety of upper layer,
492 * instead we shadow the unknown cpu to a valid partition ID */
493 cpt = cpu % cptab->ctb_nparts;
498 EXPORT_SYMBOL(cfs_cpt_current);
501 cfs_cpt_of_cpu(struct cfs_cpt_table *cptab, int cpu)
503 LASSERT(cpu >= 0 && cpu < nr_cpu_ids);
505 return cptab->ctb_cpu2cpt[cpu];
507 EXPORT_SYMBOL(cfs_cpt_of_cpu);
510 cfs_cpt_bind(struct cfs_cpt_table *cptab, int cpt)
513 nodemask_t *nodemask;
517 LASSERT(cpt == CFS_CPT_ANY || (cpt >= 0 && cpt < cptab->ctb_nparts));
519 if (cpt == CFS_CPT_ANY) {
520 cpumask = cptab->ctb_cpumask;
521 nodemask = cptab->ctb_nodemask;
523 cpumask = cptab->ctb_parts[cpt].cpt_cpumask;
524 nodemask = cptab->ctb_parts[cpt].cpt_nodemask;
527 if (cpumask_any_and(cpumask, cpu_online_mask) >= nr_cpu_ids) {
528 CERROR("No online CPU found in CPU partition %d, did someone "
529 "do CPU hotplug on system? You might need to reload "
530 "Lustre modules to keep system working well.\n", cpt);
534 for_each_online_cpu(i) {
535 if (cpumask_test_cpu(i, cpumask))
538 rc = set_cpus_allowed_ptr(current, cpumask);
539 set_mems_allowed(*nodemask);
541 schedule(); /* switch to allowed CPU */
546 /* don't need to set affinity because all online CPUs are covered */
549 EXPORT_SYMBOL(cfs_cpt_bind);
552 * Choose max to \a number CPUs from \a node and set them in \a cpt.
553 * We always prefer to choose CPU in the same core/socket.
556 cfs_cpt_choose_ncpus(struct cfs_cpt_table *cptab, int cpt,
557 cpumask_t *node, int number)
559 cpumask_t *socket = NULL;
560 cpumask_t *core = NULL;
566 if (number >= cpumask_weight(node)) {
567 while (!cpumask_empty(node)) {
568 cpu = cpumask_first(node);
570 rc = cfs_cpt_set_cpu(cptab, cpt, cpu);
573 cpumask_clear_cpu(cpu, node);
578 /* allocate scratch buffer */
579 LIBCFS_ALLOC(socket, cpumask_size());
580 LIBCFS_ALLOC(core, cpumask_size());
581 if (socket == NULL || core == NULL) {
586 while (!cpumask_empty(node)) {
587 cpu = cpumask_first(node);
589 /* get cpumask for cores in the same socket */
590 cpumask_copy(socket, topology_core_cpumask(cpu));
591 cpumask_and(socket, socket, node);
593 LASSERT(!cpumask_empty(socket));
595 while (!cpumask_empty(socket)) {
598 /* get cpumask for hts in the same core */
599 cpumask_copy(core, topology_sibling_cpumask(cpu));
600 cpumask_and(core, core, node);
602 LASSERT(!cpumask_empty(core));
604 for_each_cpu(i, core) {
605 cpumask_clear_cpu(i, socket);
606 cpumask_clear_cpu(i, node);
608 rc = cfs_cpt_set_cpu(cptab, cpt, i);
617 cpu = cpumask_first(socket);
623 LIBCFS_FREE(socket, cpumask_size());
625 LIBCFS_FREE(core, cpumask_size());
629 #define CPT_WEIGHT_MIN 4u
632 cfs_cpt_num_estimate(void)
634 unsigned nnode = num_online_nodes();
635 unsigned ncpu = num_online_cpus();
638 if (ncpu <= CPT_WEIGHT_MIN) {
643 /* generate reasonable number of CPU partitions based on total number
644 * of CPUs, Preferred N should be power2 and match this condition:
645 * 2 * (N - 1)^2 < NCPUS <= 2 * N^2 */
646 for (ncpt = 2; ncpu > 2 * ncpt * ncpt; ncpt <<= 1) {}
648 if (ncpt <= nnode) { /* fat numa system */
652 } else { /* ncpt > nnode */
653 while ((nnode << 1) <= ncpt)
660 #if (BITS_PER_LONG == 32)
661 /* config many CPU partitions on 32-bit system could consume
663 ncpt = min(2U, ncpt);
665 while (ncpu % ncpt != 0)
666 ncpt--; /* worst case is 1 */
671 static struct cfs_cpt_table *
672 cfs_cpt_table_create(int ncpt)
674 struct cfs_cpt_table *cptab = NULL;
675 cpumask_t *mask = NULL;
681 rc = cfs_cpt_num_estimate();
685 if (ncpt > num_online_cpus() || ncpt > 4 * rc) {
686 CWARN("CPU partition number %d is larger than suggested "
687 "value (%d), your system may have performance"
688 "issue or run out of memory while under pressure\n",
692 if (num_online_cpus() % ncpt != 0) {
693 CERROR("CPU number %d is not multiple of cpu_npartition %d, "
694 "please try different cpu_npartitions value or"
695 "set pattern string by cpu_pattern=STRING\n",
696 (int)num_online_cpus(), ncpt);
700 cptab = cfs_cpt_table_alloc(ncpt);
702 CERROR("Failed to allocate CPU map(%d)\n", ncpt);
706 num = num_online_cpus() / ncpt;
708 CERROR("CPU changed while setting CPU partition\n");
712 LIBCFS_ALLOC(mask, cpumask_size());
714 CERROR("Failed to allocate scratch cpumask\n");
718 for_each_online_node(i) {
719 cpumask_copy(mask, cpumask_of_node(i));
721 while (!cpumask_empty(mask)) {
722 struct cfs_cpu_partition *part;
725 /* Each emulated NUMA node has all allowed CPUs in
727 * End loop when all partitions have assigned CPUs.
732 part = &cptab->ctb_parts[cpt];
734 n = num - cpumask_weight(part->cpt_cpumask);
737 rc = cfs_cpt_choose_ncpus(cptab, cpt, mask, n);
741 LASSERT(num >= cpumask_weight(part->cpt_cpumask));
742 if (num == cpumask_weight(part->cpt_cpumask))
748 num != cpumask_weight(cptab->ctb_parts[ncpt - 1].cpt_cpumask)) {
749 CERROR("Expect %d(%d) CPU partitions but got %d(%d), "
750 "CPU hotplug/unplug while setting?\n",
751 cptab->ctb_nparts, num, cpt,
752 cpumask_weight(cptab->ctb_parts[ncpt - 1].cpt_cpumask));
756 LIBCFS_FREE(mask, cpumask_size());
761 CERROR("Failed to setup CPU-partition-table with %d "
762 "CPU-partitions, online HW nodes: %d, HW cpus: %d.\n",
763 ncpt, num_online_nodes(), num_online_cpus());
766 LIBCFS_FREE(mask, cpumask_size());
769 cfs_cpt_table_free(cptab);
774 static struct cfs_cpt_table *
775 cfs_cpt_table_create_pattern(char *pattern)
777 struct cfs_cpt_table *cptab;
787 str = cfs_trimwhite(pattern);
788 if (*str == 'n' || *str == 'N') {
790 if (*pattern != '\0') {
791 node = 1; /* numa pattern */
793 } else { /* shortcut to create CPT from NUMA & CPU topology */
795 ncpt = num_online_nodes();
799 if (ncpt == 0) { /* scanning bracket which is mark of partition */
800 for (str = pattern;; str++, ncpt++) {
801 str = strchr(str, '[');
808 (node && ncpt > num_online_nodes()) ||
809 (!node && ncpt > num_online_cpus())) {
810 CERROR("Invalid pattern %s, or too many partitions %d\n",
815 cptab = cfs_cpt_table_alloc(ncpt);
817 CERROR("Failed to allocate cpu partition table\n");
821 if (node < 0) { /* shortcut to create CPT from NUMA & CPU topology */
823 for_each_online_node(i) {
825 CERROR("CPU changed while setting CPU "
826 "partition table, %d/%d\n", cpt, ncpt);
830 rc = cfs_cpt_set_node(cptab, cpt++, i);
837 high = node ? MAX_NUMNODES - 1 : nr_cpu_ids - 1;
839 for (str = cfs_trimwhite(pattern), c = 0;; c++) {
840 struct cfs_range_expr *range;
841 struct cfs_expr_list *el;
842 char *bracket = strchr(str, '[');
845 if (bracket == NULL) {
847 CERROR("Invalid pattern %s\n", str);
849 } else if (c != ncpt) {
850 CERROR("expect %d partitions but found %d\n",
857 if (sscanf(str, "%d%n", &cpt, &n) < 1) {
858 CERROR("Invalid cpu pattern %s\n", str);
862 if (cpt < 0 || cpt >= ncpt) {
863 CERROR("Invalid partition id %d, total partitions %d\n",
868 if (cfs_cpt_weight(cptab, cpt) != 0) {
869 CERROR("Partition %d has already been set.\n", cpt);
873 str = cfs_trimwhite(str + n);
874 if (str != bracket) {
875 CERROR("Invalid pattern %s\n", str);
879 bracket = strchr(str, ']');
880 if (bracket == NULL) {
881 CERROR("missing right bracket for cpt %d, %s\n",
886 if (cfs_expr_list_parse(str, (bracket - str) + 1,
887 0, high, &el) != 0) {
888 CERROR("Can't parse number range: %s\n", str);
892 list_for_each_entry(range, &el->el_exprs, re_link) {
893 for (i = range->re_lo; i <= range->re_hi; i++) {
894 if ((i - range->re_lo) % range->re_stride != 0)
897 rc = node ? cfs_cpt_set_node(cptab, cpt, i) :
898 cfs_cpt_set_cpu(cptab, cpt, i);
900 cfs_expr_list_free(el);
906 cfs_expr_list_free(el);
908 if (!cfs_cpt_online(cptab, cpt)) {
909 CERROR("No online CPU is found on partition %d\n", cpt);
913 str = cfs_trimwhite(bracket + 1);
919 cfs_cpt_table_free(cptab);
923 #ifdef CONFIG_HOTPLUG_CPU
925 cfs_cpu_notify(struct notifier_block *self, unsigned long action, void *hcpu)
927 unsigned int cpu = (unsigned long)hcpu;
932 case CPU_DEAD_FROZEN:
934 case CPU_ONLINE_FROZEN:
936 if (action != CPU_DEAD && action != CPU_DEAD_FROZEN) {
937 CDEBUG(D_INFO, "CPU changed [cpu %u action %lx]\n",
942 /* if all HTs in a core are offline, it may break affinity */
943 warn = cpumask_any_and(topology_sibling_cpumask(cpu),
944 cpu_online_mask) >= nr_cpu_ids;
945 CDEBUG(warn ? D_WARNING : D_INFO,
946 "Lustre: can't support CPU plug-out well now, "
947 "performance and stability could be impacted"
948 "[CPU %u action: %lx]\n", cpu, action);
954 static struct notifier_block cfs_cpu_notifier = {
955 .notifier_call = cfs_cpu_notify,
964 if (cfs_cpt_table != NULL)
965 cfs_cpt_table_free(cfs_cpt_table);
967 #ifdef CONFIG_HOTPLUG_CPU
968 unregister_hotcpu_notifier(&cfs_cpu_notifier);
975 LASSERT(cfs_cpt_table == NULL);
977 #ifdef CONFIG_HOTPLUG_CPU
978 register_hotcpu_notifier(&cfs_cpu_notifier);
981 if (*cpu_pattern != 0) {
982 char *cpu_pattern_dup = kstrdup(cpu_pattern, GFP_KERNEL);
984 if (cpu_pattern_dup == NULL) {
985 CERROR("Failed to duplicate cpu_pattern\n");
989 cfs_cpt_table = cfs_cpt_table_create_pattern(cpu_pattern_dup);
990 kfree(cpu_pattern_dup);
991 if (cfs_cpt_table == NULL) {
992 CERROR("Failed to create cptab from pattern %s\n",
998 cfs_cpt_table = cfs_cpt_table_create(cpu_npartitions);
999 if (cfs_cpt_table == NULL) {
1000 CERROR("Failed to create ptable with npartitions %d\n",
1007 LCONSOLE(0, "HW nodes: %d, HW CPU cores: %d, npartitions: %d\n",
1008 num_online_nodes(), num_online_cpus(),
1009 cfs_cpt_number(cfs_cpt_table));