From 90c7f71962cc5aa0bf128ce68b9a8607176558c4 Mon Sep 17 00:00:00 2001 From: Andrew Morton Date: Sun, 18 Jan 2004 18:30:46 -0800 Subject: [PATCH] [PATCH] Make for_each_cpu() Iterator More Friendly From: Rusty Russell Anton: breaks PPC64, as it needs cpu_possible_mask, but fix is already in Ameslab tree. The for_each_cpu() and for_each_online_cpu() iterators take a mask, and noone uses them that way (except for arch/i386/mach-voyager, which uses for_each_cpu(cpu_online_mask). Make them more usable iterators, by dropping the "mask" arg. This requires that archs provide a cpu_possible_mask: most do, but PPC64 doesn't, so it is broken by this patch. The other archs use a #define to define it in asm/smp.h. Most places doing loops over cpus testing for cpu_online() should use for_each_cpu: it is synonymous at the moment, but with the CPU hotplug patch the difference becomes important. Followup patches will convert users. --- arch/i386/mach-voyager/voyager_smp.c | 12 +++++------ include/asm-alpha/smp.h | 2 +- include/asm-i386/smp.h | 3 +-- include/asm-ia64/smp.h | 2 +- include/asm-mips/smp.h | 2 +- include/asm-parisc/smp.h | 2 +- include/asm-ppc/smp.h | 1 - include/asm-s390/smp.h | 1 - include/asm-sh/smp.h | 1 - include/asm-sparc64/smp.h | 2 +- include/asm-um/smp.h | 2 +- include/asm-x86_64/smp.h | 3 +-- include/linux/cpumask.h | 32 ++++++++++++---------------- include/linux/smp.h | 1 - 14 files changed, 28 insertions(+), 38 deletions(-) diff --git a/arch/i386/mach-voyager/voyager_smp.c b/arch/i386/mach-voyager/voyager_smp.c index 1401aa9130d38..1f1af175b6f63 100644 --- a/arch/i386/mach-voyager/voyager_smp.c +++ b/arch/i386/mach-voyager/voyager_smp.c @@ -130,7 +130,7 @@ send_QIC_CPI(__u32 cpuset, __u8 cpi) { int cpu; - for_each_cpu(cpu, cpu_online_map) { + for_each_online_cpu(cpu) { if(cpuset & (1<cpu) extern cpumask_t cpu_callout_map; - -#define cpu_possible(cpu) cpu_isset(cpu, cpu_callout_map) +#define cpu_possible_map cpu_callout_map /* We don't mark CPUs online until __cpu_up(), so we need another measure */ static inline int num_booting_cpus(void) diff --git a/include/asm-ia64/smp.h b/include/asm-ia64/smp.h index adb4716f352cb..deeccd4f8f35b 100644 --- a/include/asm-ia64/smp.h +++ b/include/asm-ia64/smp.h @@ -48,7 +48,7 @@ extern volatile int ia64_cpu_to_sapicid[]; extern unsigned long ap_wakeup_vector; -#define cpu_possible(cpu) cpu_isset(cpu, phys_cpu_present_map) +#define cpu_possible_map phys_cpu_present_map /* * Function to map hard smp processor id to logical id. Slow, so don't use this in diff --git a/include/asm-mips/smp.h b/include/asm-mips/smp.h index 1c7e4eea094d4..c8d1ed35c1cc7 100644 --- a/include/asm-mips/smp.h +++ b/include/asm-mips/smp.h @@ -48,8 +48,8 @@ extern struct call_data_struct *call_data; extern cpumask_t phys_cpu_present_map; extern cpumask_t cpu_online_map; +#define cpu_possible_map phys_cpu_present_map -#define cpu_possible(cpu) cpu_isset(cpu, phys_cpu_present_map) #define cpu_online(cpu) cpu_isset(cpu, cpu_online_map) static inline unsigned int num_online_cpus(void) diff --git a/include/asm-parisc/smp.h b/include/asm-parisc/smp.h index 0877e8c9bbf7b..83e720f79a6e5 100644 --- a/include/asm-parisc/smp.h +++ b/include/asm-parisc/smp.h @@ -54,7 +54,7 @@ extern unsigned long cpu_present_mask; #define smp_processor_id() (current_thread_info()->cpu) #define cpu_online(cpu) cpu_isset(cpu, cpu_online_map) -#define cpu_possible(cpu) cpu_isset(cpu, cpu_present_mask) +#define cpu_possible_map cpu_present_map #endif /* CONFIG_SMP */ diff --git a/include/asm-ppc/smp.h b/include/asm-ppc/smp.h index 8d27f08eeb6e7..803fdb5833487 100644 --- a/include/asm-ppc/smp.h +++ b/include/asm-ppc/smp.h @@ -48,7 +48,6 @@ extern void smp_local_timer_interrupt(struct pt_regs *); #define smp_processor_id() (current_thread_info()->cpu) #define cpu_online(cpu) cpu_isset(cpu, cpu_online_map) -#define cpu_possible(cpu) cpu_isset(cpu, cpu_possible_map) extern int __cpu_up(unsigned int cpu); diff --git a/include/asm-s390/smp.h b/include/asm-s390/smp.h index 8ce65892de97b..1b9e99a994ee5 100644 --- a/include/asm-s390/smp.h +++ b/include/asm-s390/smp.h @@ -49,7 +49,6 @@ extern cpumask_t cpu_possible_map; #define smp_processor_id() (S390_lowcore.cpu_data.cpu_nr) #define cpu_online(cpu) cpu_isset(cpu, cpu_online_map) -#define cpu_possible(cpu) cpu_isset(cpu, cpu_possible_map) extern __inline__ __u16 hard_smp_processor_id(void) { diff --git a/include/asm-sh/smp.h b/include/asm-sh/smp.h index ebb034453b200..38b54469d7d1a 100644 --- a/include/asm-sh/smp.h +++ b/include/asm-sh/smp.h @@ -24,7 +24,6 @@ extern cpumask_t cpu_online_map; extern cpumask_t cpu_possible_map; #define cpu_online(cpu) cpu_isset(cpu, cpu_online_map) -#define cpu_possible(cpu) cpu_isset(cpu, cpu_possible_map) #define smp_processor_id() (current_thread_info()->cpu) diff --git a/include/asm-sparc64/smp.h b/include/asm-sparc64/smp.h index 7d8378846e559..1ad4911ef0de3 100644 --- a/include/asm-sparc64/smp.h +++ b/include/asm-sparc64/smp.h @@ -33,7 +33,7 @@ extern unsigned char boot_cpu_id; extern cpumask_t phys_cpu_present_map; -#define cpu_possible(cpu) cpu_isset(cpu, phys_cpu_present_map) +#define cpu_possible_map phys_cpu_present_map #define cpu_online(cpu) cpu_isset(cpu, cpu_online_map) diff --git a/include/asm-um/smp.h b/include/asm-um/smp.h index 846461275b298..4629de8666a45 100644 --- a/include/asm-um/smp.h +++ b/include/asm-um/smp.h @@ -20,7 +20,7 @@ extern int hard_smp_processor_id(void); #define cpu_online(cpu) cpu_isset(cpu, cpu_online_map) extern int ncpus; -#define cpu_possible(cpu) (cpu < ncpus) + extern inline void smp_cpus_done(unsigned int maxcpus) { diff --git a/include/asm-x86_64/smp.h b/include/asm-x86_64/smp.h index 28c6f28fa54b3..41484cb03424f 100644 --- a/include/asm-x86_64/smp.h +++ b/include/asm-x86_64/smp.h @@ -57,8 +57,7 @@ void smp_stop_cpu(void); */ extern cpumask_t cpu_callout_map; - -#define cpu_possible(cpu) cpu_isset(cpu, cpu_callout_map) +#define cpu_possible_map cpu_callout_map #define cpu_online(cpu) cpu_isset(cpu, cpu_online_map) static inline int num_booting_cpus(void) diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h index 6aa67b15b76fa..6fa750a5b26ee 100644 --- a/include/linux/cpumask.h +++ b/include/linux/cpumask.h @@ -8,32 +8,28 @@ #ifdef CONFIG_SMP extern cpumask_t cpu_online_map; +extern cpumask_t cpu_possible_map; #define num_online_cpus() cpus_weight(cpu_online_map) #define cpu_online(cpu) cpu_isset(cpu, cpu_online_map) +#define cpu_possible(cpu) cpu_isset(cpu, cpu_possible_map) + +#define for_each_cpu_mask(cpu, mask) \ + for (cpu = first_cpu_const(mk_cpumask_const(mask)); \ + cpu < NR_CPUS; \ + cpu = next_cpu_const(cpu, mk_cpumask_const(mask))) + +#define for_each_cpu(cpu) for_each_cpu_mask(cpu, cpu_possible_map) +#define for_each_online_cpu(cpu) for_each_cpu_mask(cpu, cpu_online_map) #else #define cpu_online_map cpumask_of_cpu(0) #define num_online_cpus() 1 #define cpu_online(cpu) ({ BUG_ON((cpu) != 0); 1; }) -#endif - -static inline int next_online_cpu(int cpu, cpumask_t map) -{ - do - cpu = next_cpu_const(cpu, mk_cpumask_const(map)); - while (cpu < NR_CPUS && !cpu_online(cpu)); - return cpu; -} +#define cpu_possible(cpu) ({ BUG_ON((cpu) != 0); 1; }) -#define for_each_cpu(cpu, map) \ - for (cpu = first_cpu_const(mk_cpumask_const(map)); \ - cpu < NR_CPUS; \ - cpu = next_cpu_const(cpu,mk_cpumask_const(map))) - -#define for_each_online_cpu(cpu, map) \ - for (cpu = first_cpu_const(mk_cpumask_const(map)); \ - cpu < NR_CPUS; \ - cpu = next_online_cpu(cpu,map)) +#define for_each_cpu(cpu) for (cpu = 0; cpu < 1; cpu++) +#define for_each_online_cpu(cpu) for (cpu = 0; cpu < 1; cpu++) +#endif extern int __mask_snprintf_len(char *buf, unsigned int buflen, const unsigned long *maskp, unsigned int maskbytes); diff --git a/include/linux/smp.h b/include/linux/smp.h index c1a74b2345bc2..9f7feff3ee9e5 100644 --- a/include/linux/smp.h +++ b/include/linux/smp.h @@ -103,7 +103,6 @@ void smp_prepare_boot_cpu(void); #define on_each_cpu(func,info,retry,wait) ({ func(info); 0; }) static inline void smp_send_reschedule(int cpu) { } #define num_booting_cpus() 1 -#define cpu_possible(cpu) ({ BUG_ON((cpu) != 0); 1; }) #define smp_prepare_boot_cpu() do {} while (0) #endif /* !SMP */ -- 2.53.0