From: William Lee Irwin III On Fri, May 09, 2003 at 11:15:35AM -0700, William Lee Irwin III wrote: +{ + do + ++node; + while (!nr_cpus_node(node) && node < numnodes); + return node; +} GRRR, neither seems to hurt my booting it or cause warnings but there are two mistakes: (1) not checking node < numnodes before !nr_cpus_node() (2) casting the arg of generic_hweight32() to unsigned long is wrong 25-akpm/include/linux/bitops.h | 29 ++++++++++------------------- 25-akpm/include/linux/topology.h | 14 ++++++++++++-- 2 files changed, 22 insertions(+), 21 deletions(-) diff -puN include/linux/bitops.h~sched_best_cpu_fix-4 include/linux/bitops.h --- 25/include/linux/bitops.h~sched_best_cpu_fix-4 Fri May 9 18:43:26 2003 +++ 25-akpm/include/linux/bitops.h Fri May 9 18:43:26 2003 @@ -1,5 +1,6 @@ #ifndef _LINUX_BITOPS_H #define _LINUX_BITOPS_H +#include #include /* @@ -107,11 +108,14 @@ static inline unsigned int generic_hweig return (res & 0x0F) + ((res >> 4) & 0x0F); } -#if (BITS_PER_LONG == 64) - -static inline u64 generic_hweight64(u64 w) +static inline unsigned long generic_hweight64(u64 w) { - u64 res = (w & 0x5555555555555555) + ((w >> 1) & 0x5555555555555555); + u64 res; + if (sizeof(unsigned long) == 4) + return generic_hweight32((unsigned int)(w >> 32)) + + generic_hweight32((unsigned int)w); + + res = (w & 0x5555555555555555) + ((w >> 1) & 0x5555555555555555); res = (res & 0x3333333333333333) + ((res >> 2) & 0x3333333333333333); res = (res & 0x0F0F0F0F0F0F0F0F) + ((res >> 4) & 0x0F0F0F0F0F0F0F0F); res = (res & 0x00FF00FF00FF00FF) + ((res >> 8) & 0x00FF00FF00FF00FF); @@ -119,22 +123,9 @@ static inline u64 generic_hweight64(u64 return (res & 0x00000000FFFFFFFF) + ((res >> 32) & 0x00000000FFFFFFFF); } -#define hweight_long(w) generic_hweight64(w) - -#endif /* BITS_PER_LONG == 64 */ - -#if (BITS_PER_LONG == 32) - -static inline unsigned int generic_hweight64(unsigned int *w) +static inline unsigned long hweight_long(unsigned long x) { - return generic_hweight32(w[0]) + generic_hweight32(w[1]); + return sizeof(x) == 4 ? generic_hweight32(x) : generic_hweight64(x); } -#define hweight_long(w) generic_hweight32(w) - -#endif /* BITS_PER_LONG == 32 */ - -#include - - #endif diff -puN include/linux/topology.h~sched_best_cpu_fix-4 include/linux/topology.h --- 25/include/linux/topology.h~sched_best_cpu_fix-4 Fri May 9 18:43:26 2003 +++ 25-akpm/include/linux/topology.h Fri May 9 18:43:26 2003 @@ -28,12 +28,22 @@ #define _LINUX_TOPOLOGY_H #include +#include /* for cpu_online_map */ #include +extern int numnodes; /* header ordering issues */ + #define nr_cpus_node(node) (hweight_long(node_to_cpumask(node))) +static inline int __next_node_with_cpus(int node) +{ + do + ++node; + while (node < numnodes && !nr_cpus_node(node)); + return node; +} + #define for_each_node_with_cpus(node) \ - for (node = 0; node < numnodes; node++) \ - if (nr_cpus_node(node) + for (node = 0; node < numnodes; node = __next_node_with_cpus(node)) #endif /* _LINUX_TOPOLOGY_H */ _