From: Andrew Theurer <habanero@us.ibm.com>

This patch makes nr_running o(1) for non NUMA and o(n) n=num_nodes for NUMA
systems instead of o(n) n=nr_cpus (in both cases).

We were already doing 90% of this by keeping track of nr_running per node,
so we simply do the same for a nonNUMA system (1 node) and we sum up the
node_nr_running[nodes] for nr_running().  An added bonus, we removed nasty
ifdefs from sched.c.  Actually, I this patch removes more code than it
adds!

I tested the patch on a dual node x440 with kernel compiles.  With NUMA
support enabled, I didn't see any performance difference, but when running
with out NUMA support I did see a consistent 2% reduction on kernel compile
times.



 include/linux/sched.h |    5 ++---
 kernel/sched.c        |   18 +++---------------
 2 files changed, 5 insertions(+), 18 deletions(-)

diff -puN kernel/sched.c~nr_running-speedup kernel/sched.c
--- 25/kernel/sched.c~nr_running-speedup	2003-06-23 23:02:19.000000000 -0700
+++ 25-akpm/kernel/sched.c	2003-06-23 23:02:19.000000000 -0700
@@ -162,10 +162,8 @@ struct runqueue {
 	struct mm_struct *prev_mm;
 	prio_array_t *active, *expired, arrays[2];
 	int prev_cpu_load[NR_CPUS];
-#ifdef CONFIG_NUMA
 	atomic_t *node_nr_running;
 	int prev_node_load[MAX_NUMNODES];
-#endif
 	task_t *migration_thread;
 	struct list_head migration_queue;
 
@@ -189,8 +187,6 @@ static struct runqueue runqueues[NR_CPUS
 # define task_running(rq, p)		((rq)->curr == (p))
 #endif
 
-#ifdef CONFIG_NUMA
-
 /*
  * Keep track of running tasks.
  */
@@ -215,7 +211,7 @@ static inline void nr_running_dec(runque
 	rq->nr_running--;
 }
 
-__init void node_nr_running_init(void)
+void __init node_nr_running_init(void)
 {
 	int i;
 
@@ -226,14 +222,6 @@ __init void node_nr_running_init(void)
 	}
 }
 
-#else /* !CONFIG_NUMA */
-
-# define nr_running_init(rq)   do { } while (0)
-# define nr_running_inc(rq)    do { (rq)->nr_running++; } while (0)
-# define nr_running_dec(rq)    do { (rq)->nr_running--; } while (0)
-
-#endif /* CONFIG_NUMA */
-
 /*
  * task_rq_lock - lock the runqueue a given task resides on and disable
  * interrupts.  Note the ordering: we can safely lookup the task_rq without
@@ -672,8 +660,8 @@ unsigned long nr_running(void)
 {
 	unsigned long i, sum = 0;
 
-	for (i = 0; i < NR_CPUS; i++)
-		sum += cpu_rq(i)->nr_running;
+	for (i = 0; i < MAX_NUMNODES; i++)
+		sum += atomic_read(&node_nr_running[i]);
 
 	return sum;
 }
diff -puN include/linux/sched.h~nr_running-speedup include/linux/sched.h
--- 25/include/linux/sched.h~nr_running-speedup	2003-06-23 23:02:19.000000000 -0700
+++ 25-akpm/include/linux/sched.h	2003-06-23 23:02:19.000000000 -0700
@@ -521,11 +521,10 @@ static inline int set_cpus_allowed(task_
 
 #ifdef CONFIG_NUMA
 extern void sched_balance_exec(void);
-extern void node_nr_running_init(void);
 #else
-#define sched_balance_exec()   {}
-#define node_nr_running_init() {}
+#define sched_balance_exec()   do {} while (0)
 #endif
+extern void node_nr_running_init(void);
 
 extern void set_user_nice(task_t *p, long nice);
 extern int task_prio(task_t *p);

_