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 @@
#include <linux/oprofile.h>
#include <linux/smp.h>
#include <linux/cpumask.h>
#include <linux/threads.h>
#include "oprofile_stats.h"
......
......@@ -2940,10 +2940,8 @@ static void recalc_bh_state(void)
if (__get_cpu_var(bh_accounting).ratelimit++ < 4096)
return;
__get_cpu_var(bh_accounting).ratelimit = 0;
for (i = 0; i < NR_CPUS; i++) {
if (cpu_online(i))
tot += per_cpu(bh_accounting, i).nr;
}
for_each_cpu(i)
tot += per_cpu(bh_accounting, i).nr;
buffer_heads_over_limit = (tot > max_buffer_heads);
}
......
......@@ -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;
do_div(jif, HZ);
for (i = 0; i < NR_CPUS; i++) {
for_each_cpu(i) {
int j;
if (!cpu_online(i)) continue;
user += kstat_cpu(i).cpustat.user;
nice += kstat_cpu(i).cpustat.nice;
system += kstat_cpu(i).cpustat.system;
......@@ -401,8 +400,7 @@ int show_stat(struct seq_file *p, void *v)
jiffies_to_clock_t(iowait),
jiffies_to_clock_t(irq),
jiffies_to_clock_t(softirq));
for (i = 0; i < NR_CPUS; i++){
if (!cpu_online(i)) continue;
for_each_online_cpu(i) {
seq_printf(p, "cpu%d %u %u %u %u %u %u %u\n",
i,
jiffies_to_clock_t(kstat_cpu(i).cpustat.user),
......
......@@ -60,10 +60,9 @@ int nr_processes(void)
int cpu;
int total = 0;
for (cpu = 0; cpu < NR_CPUS; cpu++) {
if (cpu_online(cpu))
total += per_cpu(process_counts, cpu);
}
for_each_cpu(cpu)
total += per_cpu(process_counts, cpu);
return total;
}
......
......@@ -902,11 +902,9 @@ unsigned long nr_uninterruptible(void)
{
unsigned long i, sum = 0;
for (i = 0; i < NR_CPUS; i++) {
if (!cpu_online(i))
continue;
for_each_cpu(i)
sum += cpu_rq(i)->nr_uninterruptible;
}
return sum;
}
......@@ -914,11 +912,9 @@ unsigned long nr_context_switches(void)
{
unsigned long i, sum = 0;
for (i = 0; i < NR_CPUS; i++) {
if (!cpu_online(i))
continue;
for_each_cpu(i)
sum += cpu_rq(i)->nr_switches;
}
return sum;
}
......@@ -926,11 +922,9 @@ unsigned long nr_iowait(void)
{
unsigned long i, sum = 0;
for (i = 0; i < NR_CPUS; ++i) {
if (!cpu_online(i))
continue;
for_each_cpu(i)
sum += atomic_read(&cpu_rq(i)->nr_iowait);
}
return sum;
}
......
......@@ -332,10 +332,7 @@ int del_timer_sync(struct timer_list *timer)
del_again:
ret += del_timer(timer);
for (i = 0; i < NR_CPUS; i++) {
if (!cpu_online(i))
continue;
for_each_cpu(i) {
base = &per_cpu(tvec_bases, i);
if (base->running_timer == timer) {
while (base->running_timer == timer) {
......
......@@ -366,9 +366,7 @@ int current_is_keventd(void)
BUG_ON(!keventd_wq);
for (cpu = 0; cpu < NR_CPUS; cpu++) {
if (!cpu_online(cpu))
continue;
for_each_cpu(cpu) {
cwq = keventd_wq->cpu_wq + cpu;
if (current == cwq->thread)
return 1;
......
......@@ -868,14 +868,14 @@ void __get_page_state(struct page_state *ret, int nr)
while (cpu < NR_CPUS) {
unsigned long *in, *out, off;
if (!cpu_online(cpu)) {
if (!cpu_possible(cpu)) {
cpu++;
continue;
}
in = (unsigned long *)&per_cpu(page_states, cpu);
cpu++;
if (cpu < NR_CPUS && cpu_online(cpu))
if (cpu < NR_CPUS && cpu_possible(cpu))
prefetch(&per_cpu(page_states, cpu));
out = (unsigned long *)ret;
for (off = 0; off < nr; off++)
......
......@@ -2703,12 +2703,9 @@ static int ip_rt_acct_read(char *buffer, char **start, off_t offset,
memcpy(dst, src, length);
/* Add the other cpus in, one int at a time */
for (i = 1; i < NR_CPUS; i++) {
for_each_cpu(i) {
unsigned int j;
if (!cpu_online(i))
continue;
src = ((u32 *) IP_RT_ACCT_CPU(i)) + offset;
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