diff options
| author | Rusty Russell <rusty@rustcorp.com.au> | 2008-12-29 17:35:15 -0500 |
|---|---|---|
| committer | Rusty Russell <rusty@rustcorp.com.au> | 2008-12-29 17:35:15 -0500 |
| commit | ae7a47e72e1a0b5e2b46d1596bc2c22942a73023 (patch) | |
| tree | 7cfbed58940f2feb9e2405d81a6688c6bce237b4 | |
| parent | b3199c025d1646e25e7d1d640dd605db251dccf8 (diff) | |
cpumask: make cpumask.h eat its own dogfood.
Changes:
1) cpumask_t to struct cpumask,
2) cpus_weight_nr to cpumask_weight,
3) cpu_isset to cpumask_test_cpu,
4) ->bits to cpumask_bits()
5) cpu_*_map to cpu_*_mask.
6) for_each_cpu_mask_nr to for_each_cpu
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
| -rw-r--r-- | include/linux/cpumask.h | 75 |
1 files changed, 38 insertions, 37 deletions
diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h index db2341beca45..e62a67156c53 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 | |||
| 285 | static 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, | |||
| 278 | extern const unsigned long | 297 | extern 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 | ||
| 281 | static inline const cpumask_t *get_cpu_mask(unsigned int cpu) | 300 | static 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 | /* |
| @@ -466,13 +485,13 @@ extern const struct cpumask *const cpu_active_mask; | |||
| 466 | #define cpu_active_map (*(cpumask_t *)cpu_active_mask) | 485 | #define cpu_active_map (*(cpumask_t *)cpu_active_mask) |
| 467 | 486 | ||
| 468 | #if NR_CPUS > 1 | 487 | #if NR_CPUS > 1 |
| 469 | #define num_online_cpus() cpus_weight_nr(cpu_online_map) | 488 | #define num_online_cpus() cpumask_weight(cpu_online_mask) |
| 470 | #define num_possible_cpus() cpus_weight_nr(cpu_possible_map) | 489 | #define num_possible_cpus() cpumask_weight(cpu_possible_mask) |
| 471 | #define num_present_cpus() cpus_weight_nr(cpu_present_map) | 490 | #define num_present_cpus() cpumask_weight(cpu_present_mask) |
| 472 | #define cpu_online(cpu) cpu_isset((cpu), cpu_online_map) | 491 | #define cpu_online(cpu) cpumask_test_cpu((cpu), cpu_online_mask) |
| 473 | #define cpu_possible(cpu) cpu_isset((cpu), cpu_possible_map) | 492 | #define cpu_possible(cpu) cpumask_test_cpu((cpu), cpu_possible_mask) |
| 474 | #define cpu_present(cpu) cpu_isset((cpu), cpu_present_map) | 493 | #define cpu_present(cpu) cpumask_test_cpu((cpu), cpu_present_mask) |
| 475 | #define cpu_active(cpu) cpu_isset((cpu), cpu_active_map) | 494 | #define cpu_active(cpu) cpumask_test_cpu((cpu), cpu_active_mask) |
| 476 | #else | 495 | #else |
| 477 | #define num_online_cpus() 1 | 496 | #define num_online_cpus() 1 |
| 478 | #define num_possible_cpus() 1 | 497 | #define num_possible_cpus() 1 |
| @@ -485,10 +504,6 @@ extern const struct cpumask *const cpu_active_mask; | |||
| 485 | 504 | ||
| 486 | #define cpu_is_offline(cpu) unlikely(!cpu_online(cpu)) | 505 | #define cpu_is_offline(cpu) unlikely(!cpu_online(cpu)) |
| 487 | 506 | ||
| 488 | #define for_each_possible_cpu(cpu) for_each_cpu_mask_nr((cpu), cpu_possible_map) | ||
| 489 | #define for_each_online_cpu(cpu) for_each_cpu_mask_nr((cpu), cpu_online_map) | ||
| 490 | #define for_each_present_cpu(cpu) for_each_cpu_mask_nr((cpu), cpu_present_map) | ||
| 491 | |||
| 492 | /* 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. |
| 493 | * 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. */ |
| 494 | #define cpumask_bits(maskp) ((maskp)->bits) | 509 | #define cpumask_bits(maskp) ((maskp)->bits) |
| @@ -676,7 +691,7 @@ static inline void cpumask_clear_cpu(int cpu, struct cpumask *dstp) | |||
| 676 | * No static inline type checking - see Subtlety (1) above. | 691 | * No static inline type checking - see Subtlety (1) above. |
| 677 | */ | 692 | */ |
| 678 | #define cpumask_test_cpu(cpu, cpumask) \ | 693 | #define cpumask_test_cpu(cpu, cpumask) \ |
| 679 | test_bit(cpumask_check(cpu), (cpumask)->bits) | 694 | test_bit(cpumask_check(cpu), cpumask_bits((cpumask))) |
| 680 | 695 | ||
| 681 | /** | 696 | /** |
| 682 | * 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 |
| @@ -919,7 +934,7 @@ static inline void cpumask_copy(struct cpumask *dstp, | |||
| 919 | static inline int cpumask_scnprintf(char *buf, int len, | 934 | static inline int cpumask_scnprintf(char *buf, int len, |
| 920 | const struct cpumask *srcp) | 935 | const struct cpumask *srcp) |
| 921 | { | 936 | { |
| 922 | return bitmap_scnprintf(buf, len, srcp->bits, nr_cpumask_bits); | 937 | return bitmap_scnprintf(buf, len, cpumask_bits(srcp), nr_cpumask_bits); |
| 923 | } | 938 | } |
| 924 | 939 | ||
| 925 | /** | 940 | /** |
| @@ -933,7 +948,7 @@ static inline int cpumask_scnprintf(char *buf, int len, | |||
| 933 | static inline int cpumask_parse_user(const char __user *buf, int len, | 948 | static inline int cpumask_parse_user(const char __user *buf, int len, |
| 934 | struct cpumask *dstp) | 949 | struct cpumask *dstp) |
| 935 | { | 950 | { |
| 936 | return bitmap_parse_user(buf, len, dstp->bits, nr_cpumask_bits); | 951 | return bitmap_parse_user(buf, len, cpumask_bits(dstp), nr_cpumask_bits); |
| 937 | } | 952 | } |
| 938 | 953 | ||
| 939 | /** | 954 | /** |
| @@ -948,7 +963,8 @@ static inline int cpumask_parse_user(const char __user *buf, int len, | |||
| 948 | static inline int cpulist_scnprintf(char *buf, int len, | 963 | static inline int cpulist_scnprintf(char *buf, int len, |
| 949 | const struct cpumask *srcp) | 964 | const struct cpumask *srcp) |
| 950 | { | 965 | { |
| 951 | return bitmap_scnlistprintf(buf, len, srcp->bits, nr_cpumask_bits); | 966 | return bitmap_scnlistprintf(buf, len, cpumask_bits(srcp), |
| 967 | nr_cpumask_bits); | ||
| 952 | } | 968 | } |
| 953 | 969 | ||
| 954 | /** | 970 | /** |
| @@ -961,26 +977,7 @@ static inline int cpulist_scnprintf(char *buf, int len, | |||
| 961 | */ | 977 | */ |
| 962 | static inline int cpulist_parse(const char *buf, struct cpumask *dstp) | 978 | static inline int cpulist_parse(const char *buf, struct cpumask *dstp) |
| 963 | { | 979 | { |
| 964 | return bitmap_parselist(buf, dstp->bits, nr_cpumask_bits); | 980 | return bitmap_parselist(buf, cpumask_bits(dstp), nr_cpumask_bits); |
| 965 | } | ||
| 966 | |||
| 967 | /** | ||
| 968 | * to_cpumask - convert an NR_CPUS bitmap to a struct cpumask * | ||
| 969 | * @bitmap: the bitmap | ||
| 970 | * | ||
| 971 | * There are a few places where cpumask_var_t isn't appropriate and | ||
| 972 | * static cpumasks must be used (eg. very early boot), yet we don't | ||
| 973 | * expose the definition of 'struct cpumask'. | ||
| 974 | * | ||
| 975 | * This does the conversion, and can be used as a constant initializer. | ||
| 976 | */ | ||
| 977 | #define to_cpumask(bitmap) \ | ||
| 978 | ((struct cpumask *)(1 ? (bitmap) \ | ||
| 979 | : (void *)sizeof(__check_is_bitmap(bitmap)))) | ||
| 980 | |||
| 981 | static inline int __check_is_bitmap(const unsigned long *bitmap) | ||
| 982 | { | ||
| 983 | return 1; | ||
| 984 | } | 981 | } |
| 985 | 982 | ||
| 986 | /** | 983 | /** |
| @@ -1055,6 +1052,10 @@ extern const DECLARE_BITMAP(cpu_all_bits, NR_CPUS); | |||
| 1055 | /* First bits of cpu_bit_bitmap are in fact unset. */ | 1052 | /* First bits of cpu_bit_bitmap are in fact unset. */ |
| 1056 | #define cpu_none_mask to_cpumask(cpu_bit_bitmap[0]) | 1053 | #define cpu_none_mask to_cpumask(cpu_bit_bitmap[0]) |
| 1057 | 1054 | ||
| 1055 | #define for_each_possible_cpu(cpu) for_each_cpu((cpu), cpu_possible_mask) | ||
| 1056 | #define for_each_online_cpu(cpu) for_each_cpu((cpu), cpu_online_mask) | ||
| 1057 | #define for_each_present_cpu(cpu) for_each_cpu((cpu), cpu_present_mask) | ||
| 1058 | |||
| 1058 | /* Wrappers for arch boot code to manipulate normally-constant masks */ | 1059 | /* Wrappers for arch boot code to manipulate normally-constant masks */ |
| 1059 | static inline void set_cpu_possible(unsigned int cpu, bool possible) | 1060 | static inline void set_cpu_possible(unsigned int cpu, bool possible) |
| 1060 | { | 1061 | { |
