From: Simon Arlott Whenever jiffies is started at a multiple of 5*HZ or wraps, calc_load is run exactly on the second which is when tasks using round_jiffies will be scheduled to run. This has a bad effect on the load average, making it tend towards 1.00 if a task happens to run every time the load is being calculated. This changes calc_load so that it updates load half a second after any tasks scheduled using round_jiffies. Without this change or an appropriate equivalent, my change to cxacru causes the load to stay around 1.00 even when mostly idle since it now runs every second using round_jiffies: > [ 332.416288] cxacru_poll_status(..), jiffies=5000 [start] > [ 332.417312] calc_load(1), count=-1, jiffies=5001 [start] > [ 332.417322] calc_load(1), count=4999, jiffies=5001 [finish] > [ 332.423382] cxacru_poll_status(..), jiffies=5007, next=993 [finish] Signed-off-by: Simon Arlott Cc: Arjan van de Ven Cc: Ingo Molnar Cc: Thomas Gleixner Signed-off-by: Andrew Morton --- kernel/timer.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-) diff -puN kernel/timer.c~timer-run-calc_load-halfway-through-each-round_jiffies kernel/timer.c --- a/kernel/timer.c~timer-run-calc_load-halfway-through-each-round_jiffies +++ a/kernel/timer.c @@ -1226,17 +1226,19 @@ EXPORT_SYMBOL(avenrun); static inline void calc_load(unsigned long ticks) { unsigned long active_tasks; /* fixed-point */ - static int count = LOAD_FREQ; + static int count = LOAD_FREQ + HZ/2; count -= ticks; - if (unlikely(count < 0)) { + if (unlikely(count <= 0)) { active_tasks = count_active_tasks(); do { CALC_LOAD(avenrun[0], EXP_1, active_tasks); CALC_LOAD(avenrun[1], EXP_5, active_tasks); CALC_LOAD(avenrun[2], EXP_15, active_tasks); count += LOAD_FREQ; - } while (count < 0); + } while (count <= 0); + + count = round_jiffies_relative(count + HZ/2) - HZ/2; } } _