linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / include / linux / cpumask.h
index b268a3c..a47ad70 100644 (file)
@@ -67,7 +67,7 @@
  *
  * int any_online_cpu(mask)            First online cpu in mask
  *
- * for_each_possible_cpu(cpu)          for-loop cpu over cpu_possible_map
+ * for_each_cpu(cpu)                   for-loop cpu over cpu_possible_map
  * for_each_online_cpu(cpu)            for-loop cpu over cpu_online_map
  * for_each_present_cpu(cpu)           for-loop cpu over cpu_present_map
  *
@@ -212,15 +212,17 @@ static inline void __cpus_shift_left(cpumask_t *dstp,
        bitmap_shift_left(dstp->bits, srcp->bits, n, nbits);
 }
 
-#ifdef CONFIG_SMP
-int __first_cpu(const cpumask_t *srcp);
-#define first_cpu(src) __first_cpu(&(src))
-int __next_cpu(int n, const cpumask_t *srcp);
-#define next_cpu(n, src) __next_cpu((n), &(src))
-#else
-#define first_cpu(src)         0
-#define next_cpu(n, src)       1
-#endif
+#define first_cpu(src) __first_cpu(&(src), NR_CPUS)
+static inline int __first_cpu(const cpumask_t *srcp, int nbits)
+{
+       return min_t(int, nbits, find_first_bit(srcp->bits, nbits));
+}
+
+#define next_cpu(n, src) __next_cpu((n), &(src), NR_CPUS)
+static inline int __next_cpu(int n, const cpumask_t *srcp, int nbits)
+{
+       return min_t(int, nbits, find_next_bit(srcp->bits, nbits, n+1));
+}
 
 #define cpumask_of_cpu(cpu)                                            \
 ({                                                                     \
@@ -317,8 +319,7 @@ static inline void __cpus_remap(cpumask_t *dstp, const cpumask_t *srcp,
                (cpu) < NR_CPUS;                \
                (cpu) = next_cpu((cpu), (mask)))
 #else /* NR_CPUS == 1 */
-#define for_each_cpu_mask(cpu, mask)           \
-       for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask)
+#define for_each_cpu_mask(cpu, mask) for ((cpu) = 0; (cpu) < 1; (cpu)++)
 #endif /* NR_CPUS */
 
 /*
@@ -397,17 +398,28 @@ extern cpumask_t cpu_present_map;
 #define cpu_present(cpu)       ((cpu) == 0)
 #endif
 
-#ifdef CONFIG_SMP
-int highest_possible_processor_id(void);
-#define any_online_cpu(mask) __any_online_cpu(&(mask))
-int __any_online_cpu(const cpumask_t *mask);
-#else
-#define highest_possible_processor_id()        0
-#define any_online_cpu(mask)           0
-#endif
+#define any_online_cpu(mask)                   \
+({                                             \
+       int cpu;                                \
+       for_each_cpu_mask(cpu, (mask))          \
+               if (cpu_online(cpu))            \
+                       break;                  \
+       cpu;                                    \
+})
 
+#define for_each_cpu(cpu)        for_each_cpu_mask((cpu), cpu_possible_map)
 #define for_each_possible_cpu(cpu)  for_each_cpu_mask((cpu), cpu_possible_map)
 #define for_each_online_cpu(cpu)  for_each_cpu_mask((cpu), cpu_online_map)
 #define for_each_present_cpu(cpu) for_each_cpu_mask((cpu), cpu_present_map)
 
+/* Find the highest possible smp_processor_id() */
+#define highest_possible_processor_id() \
+({ \
+       unsigned int cpu, highest = 0; \
+       for_each_cpu_mask(cpu, cpu_possible_map) \
+               highest = cpu; \
+       highest; \
+})
+
+
 #endif /* __LINUX_CPUMASK_H */