Skip to contentSkip to conversation

check cpu_online() in nr_running()

PATCH William Lee Irwin III 2 participants 3 messages Feb 25, 2003

lore
Share & tools
lore
#0 lore raw

nr_uninterruptible() and nr_iowait() both check cpu_online(cpu) as cpu ranges from 0 to NR_CPUS-1; so should nr_running().

-- wli

sched.c renamed from kernel/sched.c +2 -0
diff -urpN linux-2.5.63/kernel/sched.c nr_running-2.5.63-1/kernel/sched.c
@@ -637,6 +637,8 @@
 	unsigned long i, sum = 0;
 
 	for (i = 0; i < NR_CPUS; i++)
+		if (!cpu_online(i))
+			continue;
 		sum += cpu_rq(i)->nr_running;
 
 	return sum;
#1 lore raw

sched.c line 642

Quoted 4 lines · William Lee Irwin III
sched.c renamed from kernel/sched.c +2 -0
 	for (i = 0; i < NR_CPUS; i++)
+		if (!cpu_online(i))
+			continue;
 		sum += cpu_rq(i)->nr_running;

I smell donkey poo 8)

If the change is right, which seems reasonable then I think you need some { } 's too. Its also a hot path so it may be a lot cleaner to keep the jump out of this by just letting nr_running be zero for other processors ?

#2 lore raw
Quoted 4 lines · William Lee Irwin III
Quoted 4 lines
sched.c renamed from kernel/sched.c +2 -0
 	for (i = 0; i < NR_CPUS; i++)
+		if (!cpu_online(i))
+			continue;
 		sum += cpu_rq(i)->nr_running;
Quoted 1 line · Alan Cox

I smell donkey poo 8)

I don't really like how this stuff got arranged either.

Quoted 4 lines · Alan Cox

If the change is right, which seems reasonable then I think you need some { } 's too. Its also a hot path so it may be a lot cleaner to keep the jump out of this by just letting nr_running be zero for other processors ?

AFAICT its only usages are in /proc/ reporting and loadavg calculation, which aren't hotpaths per-se, but shouldn't explode in complexity. Similar things could be said for nr_uninterruptible() and nr_iowait(), but some kind of unusual constraint is involved wrt. hotplug.

-- wli