Skip to contentSkip to conversation

Use macro to walk through online cpus

PATCH In review Amos Waterland 2 participants 2 messages Aug 22, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Use macro to walk through online cpus

There are two cases that I know of in xen/common where we waste cycles walking through a list from zero to NR_CPUS. This patch makes them use for_each_online_cpu instead.

---

 schedule.c |    2 +-
 timer.c    |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
xen/common/schedule.c +1 -1
diff -r 326e6736d92b xen/common/schedule.c
@@ -633,7 +633,7 @@ void __init scheduler_init(void)
 
     open_softirq(SCHEDULE_SOFTIRQ, __enter_scheduler);
 
-    for ( i = 0; i < NR_CPUS; i++ )
+    for_each_online_cpu( i )
     {
         spin_lock_init(&per_cpu(schedule_data, i).schedule_lock);
         init_timer(&per_cpu(schedule_data, i).s_timer, s_timer_fn, NULL, i);
xen/common/timer.c +1 -1
diff -r 326e6736d92b xen/common/timer.c
@@ -382,7 +382,7 @@ void __init timer_init(void)
     SET_HEAP_SIZE(&dummy_heap, 0);
     SET_HEAP_LIMIT(&dummy_heap, 0);
 
-    for ( i = 0; i < NR_CPUS; i++ )
+    for_each_online_cpu( i )
     {
         spin_lock_init(&per_cpu(timers, i).lock);
         per_cpu(timers, i).heap = &dummy_heap;
#1 lore raw
Quoted 5 lines · Amos Waterland

There are two cases that I know of in xen/common where we waste cycles walking through a list from zero to NR_CPUS. This patch makes them use for_each_online_cpu instead.

Better to use for_each_cpu() in case any arch supports CPU hotplug in future. The wasted cycles are unimportant since these loops run only once, at boot time.

-- Keir