sched: Untangle cpu-load and timekeeping code
Commit-ID: 18a57c3b43781ea83c3bb21c3add84ba890d5fb3 Gitweb: http://git.kernel.org/tip/18a57c3b43781ea83c3bb21c3add84ba890d5fb3 Author: Peter Zijlstra <[email protected]> AuthorDate: Tue, 25 Jan 2011 11:30:35 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 26 Jan 2011 12:33:23 +0100
sched: Untangle cpu-load and timekeeping code
Remove the calc_global_load() call from the timekeeping code and make it local to the scheduler.
LKML-Reference: <new-submission>
--- include/linux/sched.h | 2 -- kernel/sched.c | 22 ++++++++++++++++------ kernel/timer.c | 1 - 3 files changed, 16 insertions(+), 9 deletions(-)
include/linux/sched.h +0 -2
@@ -142,8 +142,6 @@ extern unsigned long nr_iowait_cpu(int cpu);extern unsigned long this_cpu_load (void ); -extern void calc_global_load (unsigned long ticks); -extern unsigned long get_parent_ip (unsigned long addr);struct seq_file ;
kernel/sched.c +16 -6
@@ -3192,7 +3192,7 @@ calc_load_n(unsigned long load, unsigned long exp,* Once we've updated the global active value, we need to apply the exponential * weights adjusted to the number of cycles missed. */ -static void calc_global_nohz (unsigned long ticks) +static void calc_global_nohz (void ) {long delta, active, n;
@@ -3212,8 +3212,9 @@ static void calc_global_nohz(unsigned long ticks)/* * If we were idle for multiple load cycles, apply them. */ -if (ticks >=LOAD_FREQ ) { - n = ticks /LOAD_FREQ ; + delta = jiffies - calc_load_update -10 ; +if (delta >=LOAD_FREQ ) { + n = delta /LOAD_FREQ ; active =atomic_long_read (&calc_load_tasks); active = active >0 ? active *FIXED_1 :0 ;
@@ -3246,7 +3247,7 @@ static inline long calc_load_fold_idle(void) return 0; } -static void calc_global_nohz (unsigned long ticks) +static void calc_global_nohz (void ) { }#endif
@@ -3266,15 +3267,20 @@ void get_avenrun(unsigned long *loads, unsigned long offset, int shift) loads[2 ] = (avenrun[2 ] + offset) << shift; } +static void calc_global_load (unsigned long __data); + +static struct timer_list global_load_timer = +TIMER_DEFERRED_INITIALIZER (calc_global_load,0 ,0 ); +/* * calc_load - update the avenrun load estimates 10 ticks after the * CPUs have updated calc_load_tasks. */ -void calc_global_load (unsigned long ticks) +static void calc_global_load (unsigned long __data) {long active; -calc_global_nohz (ticks); +calc_global_nohz ();if (time_before (jiffies, calc_load_update +10 ))return ;
@@ -3287,6 +3293,7 @@ void calc_global_load(unsigned long ticks) avenrun[2 ] =calc_load (avenrun[2 ],EXP_15 , active); calc_load_update +=LOAD_FREQ ; +mod_timer (&global_load_timer, calc_load_update +10 ); }/*
@@ -7898,11 +7905,13 @@ void __init sched_init_smp(void)free_cpumask_var (non_isolated_cpus);init_sched_rt_class (); + mod_timer(&global_load_timer, calc_load_update + 10); }#else void __init sched_init_smp (void ) {sched_init_granularity (); +mod_timer (&global_load_timer, calc_load_update +10 ); }#endif /* CONFIG_SMP */
@@ -8172,6 +8181,7 @@ void __init sched_init(void)init_idle (current,smp_processor_id ()); calc_load_update = jiffies +LOAD_FREQ ; +set_timer_slack (&global_load_timer,0 );/* * During early bootup we pretend to be a normal task:
kernel/timer.c +0 -1
@@ -1303,7 +1303,6 @@ void do_timer(unsigned long ticks) { jiffies_64 += ticks;update_wall_time (); -calc_global_load (ticks); }#ifdef __ARCH_WANT_SYS_ALARM
Quoted 16 lines · tip-bot for Peter Zijlstra
Commit-ID: 18a57c3b43781ea83c3bb21c3add84ba890d5fb3 Gitweb: http://git.kernel.org/tip/18a57c3b43781ea83c3bb21c3add84ba890d5fb3 Author: Peter Zijlstra <[email protected]> AuthorDate: Tue, 25 Jan 2011 11:30:35 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 26 Jan 2011 12:33:23 +0100sched: Untangle cpu-load and timekeeping code
Remove the
calc_global_load()call from the timekeeping code and make it local to the scheduler.Signed-off-by Peter Zijlstra <[email protected]>LKML-Reference: <new-submission>
Signed-off-by Ingo Molnar <[email protected]>---
kernel/sched.c void get_avenrun(unsigned long *loads, unsigned long offset, int shift) · line 3286
Quoted 9 lines
kernel/sched.c +2
-1+static void calc_global_load (unsigned long __data) {long active; -calc_global_nohz (ticks); +calc_global_nohz ();if (time_before (jiffies, calc_load_update +10 ))return ;
We should not do this checking any more. In normal case, it will always return false.
If it indeed returns true for some reason, we will lose the timer forever.
Thanks,
Yong
Quoted 24 lines · Yong Zhang
Quoted 23 lines · tip-bot for Peter Zijlstra
Commit-ID: 18a57c3b43781ea83c3bb21c3add84ba890d5fb3 Gitweb: http://git.kernel.org/tip/18a57c3b43781ea83c3bb21c3add84ba890d5fb3 Author: Peter Zijlstra <[email protected]> AuthorDate: Tue, 25 Jan 2011 11:30:35 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 26 Jan 2011 12:33:23 +0100sched: Untangle cpu-load and timekeeping code
Remove the
calc_global_load()call from the timekeeping code and make it local to the scheduler.Signed-off-by Peter Zijlstra <[email protected]>LKML-Reference: <new-submission>
Signed-off-by Ingo Molnar <[email protected]>---
kernel/sched.c +2
-1+static void calc_global_load (unsigned long __data) {long active; -calc_global_nohz (ticks); +calc_global_nohz ();
Quoted 7 lines
kernel/sched.c void get_avenrun(unsigned long *loads, unsigned long offset, int shift) · line 3286
Quoted 2 lines
kernel/sched.c +0
-0if (time_before (jiffies, calc_load_update +10 ))return ;We should not do this checking any more. In normal case, it will always return false.
If it indeed returns true for some reason, we will lose the timer forever.
Its needed for the nohz case, arguably we could move it inside calc_global_nohz().
Quoted 7 lines · Peter Zijlstra
Quoted 4 lines
We should not do this checking any more. In normal case, it will always return false.
If it indeed returns true for some reason, we will lose the timer forever.Its needed for the nohz case, arguably we could move it inside
calc_global_nohz().
I have no idea why we need that checking in calc_global_nohz().
Before this patch, time_before(jiffies, calc_load_update) is needed in calc_global_nohz() because it will reduce the ovehead on dealing with calc_load_fold_idle if we have idle dance in one LOAD_FREQ.
Now we have calc_global_load() called at every LOAD_FREQ instead of every tick, that problem is gone.
But maybe I have missed something ;)
Thanks,
Yong
Signature · 1 line
Only stand for myself
Quoted 7 lines · tip-bot for Peter Zijlstra
Commit-ID: 18a57c3b43781ea83c3bb21c3add84ba890d5fb3
Gitweb: http://git.kernel.org/tip/18a57c3b43781ea83c3bb21c3add84ba890d5fb3
Author: Peter Zijlstra <[email protected]>
AuthorDate: Tue, 25 Jan 2011 11:30:35 +0100
Committer: Ingo Molnar <[email protected]>
CommitDate: Wed, 26 Jan 2011 12:33:23 +0100
Quoted 8 lines
sched: Untangle cpu-load and timekeeping code
Remove the
calc_global_load()call from the timekeeping code and make it local to the scheduler.Signed-off-by Peter Zijlstra <[email protected]>LKML-Reference: <new-submission>
Signed-off-by Ingo Molnar <[email protected]>
Now another question comes into my head:
Previous we stop load calculation only when we goes to full idle, say every CPU goes to idle. tick_do_timer_cpu is jumping to the no-idle one so we can always get the real load.
But now, if the CPU on which the global_load_timer resident goes to idle and there is still no-idle cpu in system, the load calculation stops. So it's not reflecting the real load after that.
Thanks,
Yong
Signature · 1 line
Only stand for myself
Quoted 20 lines · Yong Zhang
Quoted 7 lines · tip-bot for Peter Zijlstra
Commit-ID: 18a57c3b43781ea83c3bb21c3add84ba890d5fb3 Gitweb: http://git.kernel.org/tip/18a57c3b43781ea83c3bb21c3add84ba890d5fb3 Author: Peter Zijlstra <[email protected]> AuthorDate: Tue, 25 Jan 2011 11:30:35 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 26 Jan 2011 12:33:23 +0100Quoted 8 lines
sched: Untangle cpu-load and timekeeping code
Remove the
calc_global_load()call from the timekeeping code and make it local to the scheduler.Signed-off-by Peter Zijlstra <[email protected]>LKML-Reference: <new-submission>
Signed-off-by Ingo Molnar <[email protected]>Now another question comes into my head:
Quoted 8 lines
Previous we stop load calculation only when we goes to full idle, say every CPU goes to idle.
tick_do_timer_cpuis jumping to the no-idle one so we can always get the real load.But now, if the CPU on which the
global_load_timerresident goes to idle and there is still no-idle cpu in system, the load calculation stops. So it's not reflecting the real load after that.
Hmm, good point, Thomas is there any way we can make this timer stay on an active cpu for as long as there is one?
Quoted 11 lines · Yong Zhang
Quoted 7 lines · Peter Zijlstra
Quoted 4 lines
We should not do this checking any more. In normal case, it will always return false.
If it indeed returns true for some reason, we will lose the timer forever.Its needed for the nohz case, arguably we could move it inside
calc_global_nohz().I have no idea why we need that checking in
calc_global_nohz().
Quoted 7 lines
Before this patch,
time_before(jiffies, calc_load_update)is needed incalc_global_nohz()because it will reduce the ovehead on dealing withcalc_load_fold_idleif we have idle dance in oneLOAD_FREQ.Now we have
calc_global_load()called at everyLOAD_FREQinstead of every tick, that problem is gone.
It was (the patch has been killed due to the nohz problem you pointed out) because it could hit at an arbitrary long interval due to it being a deferred timer.
----|---------|---------|-----
^ ^ ^
t0 t1 t2Suppose the cpu goes into nohz at t0, and wakes up at t{1,2}, spanning {2,3} LOAD_FREQ boundaries, then the code in calc_global_nohz does:
n := (t{1,2}-t0)/LOAD_FREQ and finds 2, the check you refer to will make the difference between t1 and t2 and will for t2 apply the 3rd period.
But you were right in pointing out that missing the mod_timer() call in that case would have been disastrous.
Anyway, its all moot since the patch is gone now.