Skip to contentSkip to conversation

sched: cpuidle: Do not fetch current cpu in loop in idle thread

PATCH New Gaurav Jindal (Gaurav Jindal) 1 participant 1 message Apr 27, 2016 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sched: cpuidle: Do not fetch current cpu in loop in idle thread

Currently in idle thread loop, smp_processor_id() fetches the cpu id every time it runs thus taking more cpu cycles.

Instead, save the cpu id as local varaible while entering the idle thread and use it in the loop. Since it is local variable, it will be correct for each core. It will also save cycles consumed while fetching cpu id using smp_proceesor_id() in loop.

Patch:
------------------------------------------------------------------------------

kernel/sched/idle.c +0 -0
index 1214f0a..9696f9e 100644
@@ -185,6 +185,9 @@ exit_idle:

*/
static void cpu_idle_loop(void)
{
+ int cpu_id;
+

+       cpu_id = smp_processor_id();
        while(1) {
            /*
            *If the arch has a polling bit, we maintain an invariant:
    @@ -202,7 +205,7 @@ static void cpu_idle_loop(void)
            check_pgt_cache();
            rmb();

- if (cpu_is_offline(smp_processor_id()))
+ if(cpu_is_offline(cpu_id))

                arch_cpu_idle_dead();

                local_irq_disable();

------------------------------------------------------------------------------

Regards
Gaurav Jindal