Commit 012061cc authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] Use for_each_cpu() Where It's Meant To Be

From: Rusty Russell <rusty@rustcorp.com.au>

Some places use cpu_online() where they should be using cpu_possible, most
commonly for tallying statistics.  This makes no difference without hotplug
CPU.

Use the for_each_cpu() macro in those places, providing good examples (and
making the external hotplug CPU patch smaller).

Some places use cpu_online() where they should be using cpu_possible, most
commonly for tallying statistics.  This makes no difference without hotplug
CPU.

Use the for_each_cpu() macro in those places, providing good examples (and
making the external hotplug CPU patch smaller).
parent 90c7f719
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <linux/oprofile.h> #include <linux/oprofile.h>
#include <linux/smp.h> #include <linux/smp.h>
#include <linux/cpumask.h>
#include <linux/threads.h> #include <linux/threads.h>
#include "oprofile_stats.h" #include "oprofile_stats.h"
......
...@@ -2940,10 +2940,8 @@ static void recalc_bh_state(void) ...@@ -2940,10 +2940,8 @@ static void recalc_bh_state(void)
if (__get_cpu_var(bh_accounting).ratelimit++ < 4096) if (__get_cpu_var(bh_accounting).ratelimit++ < 4096)
return; return;
__get_cpu_var(bh_accounting).ratelimit = 0; __get_cpu_var(bh_accounting).ratelimit = 0;
for (i = 0; i < NR_CPUS; i++) { for_each_cpu(i)
if (cpu_online(i))
tot += per_cpu(bh_accounting, i).nr; tot += per_cpu(bh_accounting, i).nr;
}
buffer_heads_over_limit = (tot > max_buffer_heads); buffer_heads_over_limit = (tot > max_buffer_heads);
} }
......
...@@ -378,10 +378,9 @@ int show_stat(struct seq_file *p, void *v) ...@@ -378,10 +378,9 @@ int show_stat(struct seq_file *p, void *v)
jif = ((u64)now.tv_sec * HZ) + (now.tv_usec/(1000000/HZ)) - jif; jif = ((u64)now.tv_sec * HZ) + (now.tv_usec/(1000000/HZ)) - jif;
do_div(jif, HZ); do_div(jif, HZ);
for (i = 0; i < NR_CPUS; i++) { for_each_cpu(i) {
int j; int j;
if (!cpu_online(i)) continue;
user += kstat_cpu(i).cpustat.user; user += kstat_cpu(i).cpustat.user;
nice += kstat_cpu(i).cpustat.nice; nice += kstat_cpu(i).cpustat.nice;
system += kstat_cpu(i).cpustat.system; system += kstat_cpu(i).cpustat.system;
...@@ -401,8 +400,7 @@ int show_stat(struct seq_file *p, void *v) ...@@ -401,8 +400,7 @@ int show_stat(struct seq_file *p, void *v)
jiffies_to_clock_t(iowait), jiffies_to_clock_t(iowait),
jiffies_to_clock_t(irq), jiffies_to_clock_t(irq),
jiffies_to_clock_t(softirq)); jiffies_to_clock_t(softirq));
for (i = 0; i < NR_CPUS; i++){ for_each_online_cpu(i) {
if (!cpu_online(i)) continue;
seq_printf(p, "cpu%d %u %u %u %u %u %u %u\n", seq_printf(p, "cpu%d %u %u %u %u %u %u %u\n",
i, i,
jiffies_to_clock_t(kstat_cpu(i).cpustat.user), jiffies_to_clock_t(kstat_cpu(i).cpustat.user),
......
...@@ -60,10 +60,9 @@ int nr_processes(void) ...@@ -60,10 +60,9 @@ int nr_processes(void)
int cpu; int cpu;
int total = 0; int total = 0;
for (cpu = 0; cpu < NR_CPUS; cpu++) { for_each_cpu(cpu)
if (cpu_online(cpu))
total += per_cpu(process_counts, cpu); total += per_cpu(process_counts, cpu);
}
return total; return total;
} }
......
...@@ -902,11 +902,9 @@ unsigned long nr_uninterruptible(void) ...@@ -902,11 +902,9 @@ unsigned long nr_uninterruptible(void)
{ {
unsigned long i, sum = 0; unsigned long i, sum = 0;
for (i = 0; i < NR_CPUS; i++) { for_each_cpu(i)
if (!cpu_online(i))
continue;
sum += cpu_rq(i)->nr_uninterruptible; sum += cpu_rq(i)->nr_uninterruptible;
}
return sum; return sum;
} }
...@@ -914,11 +912,9 @@ unsigned long nr_context_switches(void) ...@@ -914,11 +912,9 @@ unsigned long nr_context_switches(void)
{ {
unsigned long i, sum = 0; unsigned long i, sum = 0;
for (i = 0; i < NR_CPUS; i++) { for_each_cpu(i)
if (!cpu_online(i))
continue;
sum += cpu_rq(i)->nr_switches; sum += cpu_rq(i)->nr_switches;
}
return sum; return sum;
} }
...@@ -926,11 +922,9 @@ unsigned long nr_iowait(void) ...@@ -926,11 +922,9 @@ unsigned long nr_iowait(void)
{ {
unsigned long i, sum = 0; unsigned long i, sum = 0;
for (i = 0; i < NR_CPUS; ++i) { for_each_cpu(i)
if (!cpu_online(i))
continue;
sum += atomic_read(&cpu_rq(i)->nr_iowait); sum += atomic_read(&cpu_rq(i)->nr_iowait);
}
return sum; return sum;
} }
......
...@@ -332,10 +332,7 @@ int del_timer_sync(struct timer_list *timer) ...@@ -332,10 +332,7 @@ int del_timer_sync(struct timer_list *timer)
del_again: del_again:
ret += del_timer(timer); ret += del_timer(timer);
for (i = 0; i < NR_CPUS; i++) { for_each_cpu(i) {
if (!cpu_online(i))
continue;
base = &per_cpu(tvec_bases, i); base = &per_cpu(tvec_bases, i);
if (base->running_timer == timer) { if (base->running_timer == timer) {
while (base->running_timer == timer) { while (base->running_timer == timer) {
......
...@@ -366,9 +366,7 @@ int current_is_keventd(void) ...@@ -366,9 +366,7 @@ int current_is_keventd(void)
BUG_ON(!keventd_wq); BUG_ON(!keventd_wq);
for (cpu = 0; cpu < NR_CPUS; cpu++) { for_each_cpu(cpu) {
if (!cpu_online(cpu))
continue;
cwq = keventd_wq->cpu_wq + cpu; cwq = keventd_wq->cpu_wq + cpu;
if (current == cwq->thread) if (current == cwq->thread)
return 1; return 1;
......
...@@ -868,14 +868,14 @@ void __get_page_state(struct page_state *ret, int nr) ...@@ -868,14 +868,14 @@ void __get_page_state(struct page_state *ret, int nr)
while (cpu < NR_CPUS) { while (cpu < NR_CPUS) {
unsigned long *in, *out, off; unsigned long *in, *out, off;
if (!cpu_online(cpu)) { if (!cpu_possible(cpu)) {
cpu++; cpu++;
continue; continue;
} }
in = (unsigned long *)&per_cpu(page_states, cpu); in = (unsigned long *)&per_cpu(page_states, cpu);
cpu++; cpu++;
if (cpu < NR_CPUS && cpu_online(cpu)) if (cpu < NR_CPUS && cpu_possible(cpu))
prefetch(&per_cpu(page_states, cpu)); prefetch(&per_cpu(page_states, cpu));
out = (unsigned long *)ret; out = (unsigned long *)ret;
for (off = 0; off < nr; off++) for (off = 0; off < nr; off++)
......
...@@ -2703,12 +2703,9 @@ static int ip_rt_acct_read(char *buffer, char **start, off_t offset, ...@@ -2703,12 +2703,9 @@ static int ip_rt_acct_read(char *buffer, char **start, off_t offset,
memcpy(dst, src, length); memcpy(dst, src, length);
/* Add the other cpus in, one int at a time */ /* Add the other cpus in, one int at a time */
for (i = 1; i < NR_CPUS; i++) { for_each_cpu(i) {
unsigned int j; unsigned int j;
if (!cpu_online(i))
continue;
src = ((u32 *) IP_RT_ACCT_CPU(i)) + offset; src = ((u32 *) IP_RT_ACCT_CPU(i)) + offset;
for (j = 0; j < length/4; j++) for (j = 0; j < length/4; j++)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment