aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/cpumask.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/cpumask.h')
-rw-r--r--include/linux/cpumask.h284
1 files changed, 133 insertions, 151 deletions
diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index 21e1dd43e52a..7c178a6baae3 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -268,6 +268,25 @@ static inline void __cpus_shift_left(cpumask_t *dstp,
268 bitmap_shift_left(dstp->bits, srcp->bits, n, nbits); 268 bitmap_shift_left(dstp->bits, srcp->bits, n, nbits);
269} 269}
270 270
271/**
272 * to_cpumask - convert an NR_CPUS bitmap to a struct cpumask *
273 * @bitmap: the bitmap
274 *
275 * There are a few places where cpumask_var_t isn't appropriate and
276 * static cpumasks must be used (eg. very early boot), yet we don't
277 * expose the definition of 'struct cpumask'.
278 *
279 * This does the conversion, and can be used as a constant initializer.
280 */
281#define to_cpumask(bitmap) \
282 ((struct cpumask *)(1 ? (bitmap) \
283 : (void *)sizeof(__check_is_bitmap(bitmap))))
284
285static inline int __check_is_bitmap(const unsigned long *bitmap)
286{
287 return 1;
288}
289
271/* 290/*
272 * Special-case data structure for "single bit set only" constant CPU masks. 291 * Special-case data structure for "single bit set only" constant CPU masks.
273 * 292 *
@@ -278,11 +297,11 @@ static inline void __cpus_shift_left(cpumask_t *dstp,
278extern const unsigned long 297extern const unsigned long
279 cpu_bit_bitmap[BITS_PER_LONG+1][BITS_TO_LONGS(NR_CPUS)]; 298 cpu_bit_bitmap[BITS_PER_LONG+1][BITS_TO_LONGS(NR_CPUS)];
280 299
281static inline const cpumask_t *get_cpu_mask(unsigned int cpu) 300static inline const struct cpumask *get_cpu_mask(unsigned int cpu)
282{ 301{
283 const unsigned long *p = cpu_bit_bitmap[1 + cpu % BITS_PER_LONG]; 302 const unsigned long *p = cpu_bit_bitmap[1 + cpu % BITS_PER_LONG];
284 p -= cpu / BITS_PER_LONG; 303 p -= cpu / BITS_PER_LONG;
285 return (const cpumask_t *)p; 304 return to_cpumask(p);
286} 305}
287 306
288/* 307/*
@@ -339,36 +358,6 @@ extern cpumask_t cpu_mask_all;
339#endif 358#endif
340#define CPUMASK_PTR(v, m) cpumask_t *v = &(m->v) 359#define CPUMASK_PTR(v, m) cpumask_t *v = &(m->v)
341 360
342#define cpumask_scnprintf(buf, len, src) \
343 __cpumask_scnprintf((buf), (len), &(src), NR_CPUS)
344static inline int __cpumask_scnprintf(char *buf, int len,
345 const cpumask_t *srcp, int nbits)
346{
347 return bitmap_scnprintf(buf, len, srcp->bits, nbits);
348}
349
350#define cpumask_parse_user(ubuf, ulen, dst) \
351 __cpumask_parse_user((ubuf), (ulen), &(dst), NR_CPUS)
352static inline int __cpumask_parse_user(const char __user *buf, int len,
353 cpumask_t *dstp, int nbits)
354{
355 return bitmap_parse_user(buf, len, dstp->bits, nbits);
356}
357
358#define cpulist_scnprintf(buf, len, src) \
359 __cpulist_scnprintf((buf), (len), &(src), NR_CPUS)
360static inline int __cpulist_scnprintf(char *buf, int len,
361 const cpumask_t *srcp, int nbits)
362{
363 return bitmap_scnlistprintf(buf, len, srcp->bits, nbits);
364}
365
366#define cpulist_parse(buf, dst) __cpulist_parse((buf), &(dst), NR_CPUS)
367static inline int __cpulist_parse(const char *buf, cpumask_t *dstp, int nbits)
368{
369 return bitmap_parselist(buf, dstp->bits, nbits);
370}
371
372#define cpu_remap(oldbit, old, new) \ 361#define cpu_remap(oldbit, old, new) \
373 __cpu_remap((oldbit), &(old), &(new), NR_CPUS) 362 __cpu_remap((oldbit), &(old), &(new), NR_CPUS)
374static inline int __cpu_remap(int oldbit, 363static inline int __cpu_remap(int oldbit,
@@ -446,74 +435,63 @@ int __next_cpu_nr(int n, const cpumask_t *srcp);
446 435
447/* 436/*
448 * The following particular system cpumasks and operations manage 437 * The following particular system cpumasks and operations manage
449 * possible, present, active and online cpus. Each of them is a fixed size 438 * possible, present, active and online cpus.
450 * bitmap of size NR_CPUS. 439 *
440 * cpu_possible_mask- has bit 'cpu' set iff cpu is populatable
441 * cpu_present_mask - has bit 'cpu' set iff cpu is populated
442 * cpu_online_mask - has bit 'cpu' set iff cpu available to scheduler
443 * cpu_active_mask - has bit 'cpu' set iff cpu available to migration
451 * 444 *
452 * #ifdef CONFIG_HOTPLUG_CPU 445 * If !CONFIG_HOTPLUG_CPU, present == possible, and active == online.
453 * cpu_possible_map - has bit 'cpu' set iff cpu is populatable
454 * cpu_present_map - has bit 'cpu' set iff cpu is populated
455 * cpu_online_map - has bit 'cpu' set iff cpu available to scheduler
456 * cpu_active_map - has bit 'cpu' set iff cpu available to migration
457 * #else
458 * cpu_possible_map - has bit 'cpu' set iff cpu is populated
459 * cpu_present_map - copy of cpu_possible_map
460 * cpu_online_map - has bit 'cpu' set iff cpu available to scheduler
461 * #endif
462 * 446 *
463 * In either case, NR_CPUS is fixed at compile time, as the static 447 * The cpu_possible_mask is fixed at boot time, as the set of CPU id's
464 * size of these bitmaps. The cpu_possible_map is fixed at boot 448 * that it is possible might ever be plugged in at anytime during the
465 * time, as the set of CPU id's that it is possible might ever 449 * life of that system boot. The cpu_present_mask is dynamic(*),
466 * be plugged in at anytime during the life of that system boot. 450 * representing which CPUs are currently plugged in. And
467 * The cpu_present_map is dynamic(*), representing which CPUs 451 * cpu_online_mask is the dynamic subset of cpu_present_mask,
468 * are currently plugged in. And cpu_online_map is the dynamic 452 * indicating those CPUs available for scheduling.
469 * subset of cpu_present_map, indicating those CPUs available
470 * for scheduling.
471 * 453 *
472 * If HOTPLUG is enabled, then cpu_possible_map is forced to have 454 * If HOTPLUG is enabled, then cpu_possible_mask is forced to have
473 * all NR_CPUS bits set, otherwise it is just the set of CPUs that 455 * all NR_CPUS bits set, otherwise it is just the set of CPUs that
474 * ACPI reports present at boot. 456 * ACPI reports present at boot.
475 * 457 *
476 * If HOTPLUG is enabled, then cpu_present_map varies dynamically, 458 * If HOTPLUG is enabled, then cpu_present_mask varies dynamically,
477 * depending on what ACPI reports as currently plugged in, otherwise 459 * depending on what ACPI reports as currently plugged in, otherwise
478 * cpu_present_map is just a copy of cpu_possible_map. 460 * cpu_present_mask is just a copy of cpu_possible_mask.
479 * 461 *
480 * (*) Well, cpu_present_map is dynamic in the hotplug case. If not 462 * (*) Well, cpu_present_mask is dynamic in the hotplug case. If not
481 * hotplug, it's a copy of cpu_possible_map, hence fixed at boot. 463 * hotplug, it's a copy of cpu_possible_mask, hence fixed at boot.
482 * 464 *
483 * Subtleties: 465 * Subtleties:
484 * 1) UP arch's (NR_CPUS == 1, CONFIG_SMP not defined) hardcode 466 * 1) UP arch's (NR_CPUS == 1, CONFIG_SMP not defined) hardcode
485 * assumption that their single CPU is online. The UP 467 * assumption that their single CPU is online. The UP
486 * cpu_{online,possible,present}_maps are placebos. Changing them 468 * cpu_{online,possible,present}_masks are placebos. Changing them
487 * will have no useful affect on the following num_*_cpus() 469 * will have no useful affect on the following num_*_cpus()
488 * and cpu_*() macros in the UP case. This ugliness is a UP 470 * and cpu_*() macros in the UP case. This ugliness is a UP
489 * optimization - don't waste any instructions or memory references 471 * optimization - don't waste any instructions or memory references
490 * asking if you're online or how many CPUs there are if there is 472 * asking if you're online or how many CPUs there are if there is
491 * only one CPU. 473 * only one CPU.
492 * 2) Most SMP arch's #define some of these maps to be some
493 * other map specific to that arch. Therefore, the following
494 * must be #define macros, not inlines. To see why, examine
495 * the assembly code produced by the following. Note that
496 * set1() writes phys_x_map, but set2() writes x_map:
497 * int x_map, phys_x_map;
498 * #define set1(a) x_map = a
499 * inline void set2(int a) { x_map = a; }
500 * #define x_map phys_x_map
501 * main(){ set1(3); set2(5); }
502 */ 474 */
503 475
504extern cpumask_t cpu_possible_map; 476extern const struct cpumask *const cpu_possible_mask;
505extern cpumask_t cpu_online_map; 477extern const struct cpumask *const cpu_online_mask;
506extern cpumask_t cpu_present_map; 478extern const struct cpumask *const cpu_present_mask;
507extern cpumask_t cpu_active_map; 479extern const struct cpumask *const cpu_active_mask;
480
481/* These strip const, as traditionally they weren't const. */
482#define cpu_possible_map (*(cpumask_t *)cpu_possible_mask)
483#define cpu_online_map (*(cpumask_t *)cpu_online_mask)
484#define cpu_present_map (*(cpumask_t *)cpu_present_mask)
485#define cpu_active_map (*(cpumask_t *)cpu_active_mask)
508 486
509#if NR_CPUS > 1 487#if NR_CPUS > 1
510#define num_online_cpus() cpus_weight_nr(cpu_online_map) 488#define num_online_cpus() cpumask_weight(cpu_online_mask)
511#define num_possible_cpus() cpus_weight_nr(cpu_possible_map) 489#define num_possible_cpus() cpumask_weight(cpu_possible_mask)
512#define num_present_cpus() cpus_weight_nr(cpu_present_map) 490#define num_present_cpus() cpumask_weight(cpu_present_mask)
513#define cpu_online(cpu) cpu_isset((cpu), cpu_online_map) 491#define cpu_online(cpu) cpumask_test_cpu((cpu), cpu_online_mask)
514#define cpu_possible(cpu) cpu_isset((cpu), cpu_possible_map) 492#define cpu_possible(cpu) cpumask_test_cpu((cpu), cpu_possible_mask)
515#define cpu_present(cpu) cpu_isset((cpu), cpu_present_map) 493#define cpu_present(cpu) cpumask_test_cpu((cpu), cpu_present_mask)
516#define cpu_active(cpu) cpu_isset((cpu), cpu_active_map) 494#define cpu_active(cpu) cpumask_test_cpu((cpu), cpu_active_mask)
517#else 495#else
518#define num_online_cpus() 1 496#define num_online_cpus() 1
519#define num_possible_cpus() 1 497#define num_possible_cpus() 1
@@ -526,10 +504,6 @@ extern cpumask_t cpu_active_map;
526 504
527#define cpu_is_offline(cpu) unlikely(!cpu_online(cpu)) 505#define cpu_is_offline(cpu) unlikely(!cpu_online(cpu))
528 506
529#define for_each_possible_cpu(cpu) for_each_cpu_mask_nr((cpu), cpu_possible_map)
530#define for_each_online_cpu(cpu) for_each_cpu_mask_nr((cpu), cpu_online_map)
531#define for_each_present_cpu(cpu) for_each_cpu_mask_nr((cpu), cpu_present_map)
532
533/* These are the new versions of the cpumask operators: passed by pointer. 507/* These are the new versions of the cpumask operators: passed by pointer.
534 * The older versions will be implemented in terms of these, then deleted. */ 508 * The older versions will be implemented in terms of these, then deleted. */
535#define cpumask_bits(maskp) ((maskp)->bits) 509#define cpumask_bits(maskp) ((maskp)->bits)
@@ -540,9 +514,6 @@ extern cpumask_t cpu_active_map;
540 [BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD \ 514 [BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD \
541} 515}
542 516
543/* This produces more efficient code. */
544#define nr_cpumask_bits NR_CPUS
545
546#else /* NR_CPUS > BITS_PER_LONG */ 517#else /* NR_CPUS > BITS_PER_LONG */
547 518
548#define CPU_BITS_ALL \ 519#define CPU_BITS_ALL \
@@ -550,9 +521,15 @@ extern cpumask_t cpu_active_map;
550 [0 ... BITS_TO_LONGS(NR_CPUS)-2] = ~0UL, \ 521 [0 ... BITS_TO_LONGS(NR_CPUS)-2] = ~0UL, \
551 [BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD \ 522 [BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD \
552} 523}
524#endif /* NR_CPUS > BITS_PER_LONG */
553 525
526#ifdef CONFIG_CPUMASK_OFFSTACK
527/* Assuming NR_CPUS is huge, a runtime limit is more efficient. Also,
528 * not all bits may be allocated. */
554#define nr_cpumask_bits nr_cpu_ids 529#define nr_cpumask_bits nr_cpu_ids
555#endif /* NR_CPUS > BITS_PER_LONG */ 530#else
531#define nr_cpumask_bits NR_CPUS
532#endif
556 533
557/* verify cpu argument to cpumask_* operators */ 534/* verify cpu argument to cpumask_* operators */
558static inline unsigned int cpumask_check(unsigned int cpu) 535static inline unsigned int cpumask_check(unsigned int cpu)
@@ -714,7 +691,7 @@ static inline void cpumask_clear_cpu(int cpu, struct cpumask *dstp)
714 * No static inline type checking - see Subtlety (1) above. 691 * No static inline type checking - see Subtlety (1) above.
715 */ 692 */
716#define cpumask_test_cpu(cpu, cpumask) \ 693#define cpumask_test_cpu(cpu, cpumask) \
717 test_bit(cpumask_check(cpu), (cpumask)->bits) 694 test_bit(cpumask_check(cpu), cpumask_bits((cpumask)))
718 695
719/** 696/**
720 * cpumask_test_and_set_cpu - atomically test and set a cpu in a cpumask 697 * cpumask_test_and_set_cpu - atomically test and set a cpu in a cpumask
@@ -946,22 +923,61 @@ static inline void cpumask_copy(struct cpumask *dstp,
946#define cpumask_of(cpu) (get_cpu_mask(cpu)) 923#define cpumask_of(cpu) (get_cpu_mask(cpu))
947 924
948/** 925/**
949 * to_cpumask - convert an NR_CPUS bitmap to a struct cpumask * 926 * cpumask_scnprintf - print a cpumask into a string as comma-separated hex
950 * @bitmap: the bitmap 927 * @buf: the buffer to sprintf into
928 * @len: the length of the buffer
929 * @srcp: the cpumask to print
951 * 930 *
952 * There are a few places where cpumask_var_t isn't appropriate and 931 * If len is zero, returns zero. Otherwise returns the length of the
953 * static cpumasks must be used (eg. very early boot), yet we don't 932 * (nul-terminated) @buf string.
954 * expose the definition of 'struct cpumask'. 933 */
934static inline int cpumask_scnprintf(char *buf, int len,
935 const struct cpumask *srcp)
936{
937 return bitmap_scnprintf(buf, len, cpumask_bits(srcp), nr_cpumask_bits);
938}
939
940/**
941 * cpumask_parse_user - extract a cpumask from a user string
942 * @buf: the buffer to extract from
943 * @len: the length of the buffer
944 * @dstp: the cpumask to set.
955 * 945 *
956 * This does the conversion, and can be used as a constant initializer. 946 * Returns -errno, or 0 for success.
957 */ 947 */
958#define to_cpumask(bitmap) \ 948static inline int cpumask_parse_user(const char __user *buf, int len,
959 ((struct cpumask *)(1 ? (bitmap) \ 949 struct cpumask *dstp)
960 : (void *)sizeof(__check_is_bitmap(bitmap)))) 950{
951 return bitmap_parse_user(buf, len, cpumask_bits(dstp), nr_cpumask_bits);
952}
961 953
962static inline int __check_is_bitmap(const unsigned long *bitmap) 954/**
955 * cpulist_scnprintf - print a cpumask into a string as comma-separated list
956 * @buf: the buffer to sprintf into
957 * @len: the length of the buffer
958 * @srcp: the cpumask to print
959 *
960 * If len is zero, returns zero. Otherwise returns the length of the
961 * (nul-terminated) @buf string.
962 */
963static inline int cpulist_scnprintf(char *buf, int len,
964 const struct cpumask *srcp)
963{ 965{
964 return 1; 966 return bitmap_scnlistprintf(buf, len, cpumask_bits(srcp),
967 nr_cpumask_bits);
968}
969
970/**
971 * cpulist_parse_user - extract a cpumask from a user string of ranges
972 * @buf: the buffer to extract from
973 * @len: the length of the buffer
974 * @dstp: the cpumask to set.
975 *
976 * Returns -errno, or 0 for success.
977 */
978static inline int cpulist_parse(const char *buf, struct cpumask *dstp)
979{
980 return bitmap_parselist(buf, cpumask_bits(dstp), nr_cpumask_bits);
965} 981}
966 982
967/** 983/**
@@ -995,6 +1011,7 @@ static inline size_t cpumask_size(void)
995#ifdef CONFIG_CPUMASK_OFFSTACK 1011#ifdef CONFIG_CPUMASK_OFFSTACK
996typedef struct cpumask *cpumask_var_t; 1012typedef struct cpumask *cpumask_var_t;
997 1013
1014bool alloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags, int node);
998bool alloc_cpumask_var(cpumask_var_t *mask, gfp_t flags); 1015bool alloc_cpumask_var(cpumask_var_t *mask, gfp_t flags);
999void alloc_bootmem_cpumask_var(cpumask_var_t *mask); 1016void alloc_bootmem_cpumask_var(cpumask_var_t *mask);
1000void free_cpumask_var(cpumask_var_t mask); 1017void free_cpumask_var(cpumask_var_t mask);
@@ -1008,6 +1025,12 @@ static inline bool alloc_cpumask_var(cpumask_var_t *mask, gfp_t flags)
1008 return true; 1025 return true;
1009} 1026}
1010 1027
1028static inline bool alloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags,
1029 int node)
1030{
1031 return true;
1032}
1033
1011static inline void alloc_bootmem_cpumask_var(cpumask_var_t *mask) 1034static inline void alloc_bootmem_cpumask_var(cpumask_var_t *mask)
1012{ 1035{
1013} 1036}
@@ -1021,12 +1044,6 @@ static inline void free_bootmem_cpumask_var(cpumask_var_t mask)
1021} 1044}
1022#endif /* CONFIG_CPUMASK_OFFSTACK */ 1045#endif /* CONFIG_CPUMASK_OFFSTACK */
1023 1046
1024/* The pointer versions of the maps, these will become the primary versions. */
1025#define cpu_possible_mask ((const struct cpumask *)&cpu_possible_map)
1026#define cpu_online_mask ((const struct cpumask *)&cpu_online_map)
1027#define cpu_present_mask ((const struct cpumask *)&cpu_present_map)
1028#define cpu_active_mask ((const struct cpumask *)&cpu_active_map)
1029
1030/* It's common to want to use cpu_all_mask in struct member initializers, 1047/* It's common to want to use cpu_all_mask in struct member initializers,
1031 * so it has to refer to an address rather than a pointer. */ 1048 * so it has to refer to an address rather than a pointer. */
1032extern const DECLARE_BITMAP(cpu_all_bits, NR_CPUS); 1049extern const DECLARE_BITMAP(cpu_all_bits, NR_CPUS);
@@ -1035,51 +1052,16 @@ extern const DECLARE_BITMAP(cpu_all_bits, NR_CPUS);
1035/* First bits of cpu_bit_bitmap are in fact unset. */ 1052/* First bits of cpu_bit_bitmap are in fact unset. */
1036#define cpu_none_mask to_cpumask(cpu_bit_bitmap[0]) 1053#define cpu_none_mask to_cpumask(cpu_bit_bitmap[0])
1037 1054
1038/* Wrappers for arch boot code to manipulate normally-constant masks */ 1055#define for_each_possible_cpu(cpu) for_each_cpu((cpu), cpu_possible_mask)
1039static inline void set_cpu_possible(unsigned int cpu, bool possible) 1056#define for_each_online_cpu(cpu) for_each_cpu((cpu), cpu_online_mask)
1040{ 1057#define for_each_present_cpu(cpu) for_each_cpu((cpu), cpu_present_mask)
1041 if (possible)
1042 cpumask_set_cpu(cpu, &cpu_possible_map);
1043 else
1044 cpumask_clear_cpu(cpu, &cpu_possible_map);
1045}
1046
1047static inline void set_cpu_present(unsigned int cpu, bool present)
1048{
1049 if (present)
1050 cpumask_set_cpu(cpu, &cpu_present_map);
1051 else
1052 cpumask_clear_cpu(cpu, &cpu_present_map);
1053}
1054
1055static inline void set_cpu_online(unsigned int cpu, bool online)
1056{
1057 if (online)
1058 cpumask_set_cpu(cpu, &cpu_online_map);
1059 else
1060 cpumask_clear_cpu(cpu, &cpu_online_map);
1061}
1062
1063static inline void set_cpu_active(unsigned int cpu, bool active)
1064{
1065 if (active)
1066 cpumask_set_cpu(cpu, &cpu_active_map);
1067 else
1068 cpumask_clear_cpu(cpu, &cpu_active_map);
1069}
1070
1071static inline void init_cpu_present(const struct cpumask *src)
1072{
1073 cpumask_copy(&cpu_present_map, src);
1074}
1075
1076static inline void init_cpu_possible(const struct cpumask *src)
1077{
1078 cpumask_copy(&cpu_possible_map, src);
1079}
1080 1058
1081static inline void init_cpu_online(const struct cpumask *src) 1059/* Wrappers for arch boot code to manipulate normally-constant masks */
1082{ 1060void set_cpu_possible(unsigned int cpu, bool possible);
1083 cpumask_copy(&cpu_online_map, src); 1061void set_cpu_present(unsigned int cpu, bool present);
1084} 1062void set_cpu_online(unsigned int cpu, bool online);
1063void set_cpu_active(unsigned int cpu, bool active);
1064void init_cpu_present(const struct cpumask *src);
1065void init_cpu_possible(const struct cpumask *src);
1066void init_cpu_online(const struct cpumask *src);
1085#endif /* __LINUX_CPUMASK_H */ 1067#endif /* __LINUX_CPUMASK_H */