diff options
author | Thomas Gleixner <tglx@linutronix.de> | 2016-07-12 12:33:56 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2016-07-13 08:58:20 -0400 |
commit | d60585c5766e9620d5d83e2b25dc042c7bdada2c (patch) | |
tree | ace0971cf7c7dcab339997d82ed635b8486dcb28 /kernel/sched | |
parent | 92d21ac74a9e3c09b0b01c764e530657e4c85c49 (diff) |
sched/core: Correct off by one bug in load migration calculation
The move of calc_load_migrate() from CPU_DEAD to CPU_DYING did not take into
account that the function is now called from a thread running on the outgoing
CPU. As a result a cpu unplug leakes a load of 1 into the global load
accounting mechanism.
Fix it by adjusting for the currently running thread which calls
calc_load_migrate().
Reported-by: Anton Blanchard <anton@samba.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Peter Zijlstra <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Vaidyanathan Srinivasan <svaidy@linux.vnet.ibm.com>
Cc: rt@linutronix.de
Cc: shreyas@linux.vnet.ibm.com
Fixes: e9cd8fa4fcfd: ("sched/migration: Move calc_load_migrate() into CPU_DYING")
Link: http://lkml.kernel.org/r/alpine.DEB.2.11.1607121744350.4083@nanos
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'kernel/sched')
-rw-r--r-- | kernel/sched/core.c | 6 | ||||
-rw-r--r-- | kernel/sched/loadavg.c | 8 | ||||
-rw-r--r-- | kernel/sched/sched.h | 2 |
3 files changed, 9 insertions, 7 deletions
diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 51d7105f529a..97ee9ac7e97c 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c | |||
@@ -5394,13 +5394,15 @@ void idle_task_exit(void) | |||
5394 | /* | 5394 | /* |
5395 | * Since this CPU is going 'away' for a while, fold any nr_active delta | 5395 | * Since this CPU is going 'away' for a while, fold any nr_active delta |
5396 | * we might have. Assumes we're called after migrate_tasks() so that the | 5396 | * we might have. Assumes we're called after migrate_tasks() so that the |
5397 | * nr_active count is stable. | 5397 | * nr_active count is stable. We need to take the teardown thread which |
5398 | * is calling this into account, so we hand in adjust = 1 to the load | ||
5399 | * calculation. | ||
5398 | * | 5400 | * |
5399 | * Also see the comment "Global load-average calculations". | 5401 | * Also see the comment "Global load-average calculations". |
5400 | */ | 5402 | */ |
5401 | static void calc_load_migrate(struct rq *rq) | 5403 | static void calc_load_migrate(struct rq *rq) |
5402 | { | 5404 | { |
5403 | long delta = calc_load_fold_active(rq); | 5405 | long delta = calc_load_fold_active(rq, 1); |
5404 | if (delta) | 5406 | if (delta) |
5405 | atomic_long_add(delta, &calc_load_tasks); | 5407 | atomic_long_add(delta, &calc_load_tasks); |
5406 | } | 5408 | } |
diff --git a/kernel/sched/loadavg.c b/kernel/sched/loadavg.c index b0b93fd33af9..a2d6eb71f06b 100644 --- a/kernel/sched/loadavg.c +++ b/kernel/sched/loadavg.c | |||
@@ -78,11 +78,11 @@ void get_avenrun(unsigned long *loads, unsigned long offset, int shift) | |||
78 | loads[2] = (avenrun[2] + offset) << shift; | 78 | loads[2] = (avenrun[2] + offset) << shift; |
79 | } | 79 | } |
80 | 80 | ||
81 | long calc_load_fold_active(struct rq *this_rq) | 81 | long calc_load_fold_active(struct rq *this_rq, long adjust) |
82 | { | 82 | { |
83 | long nr_active, delta = 0; | 83 | long nr_active, delta = 0; |
84 | 84 | ||
85 | nr_active = this_rq->nr_running; | 85 | nr_active = this_rq->nr_running - adjust; |
86 | nr_active += (long)this_rq->nr_uninterruptible; | 86 | nr_active += (long)this_rq->nr_uninterruptible; |
87 | 87 | ||
88 | if (nr_active != this_rq->calc_load_active) { | 88 | if (nr_active != this_rq->calc_load_active) { |
@@ -188,7 +188,7 @@ void calc_load_enter_idle(void) | |||
188 | * We're going into NOHZ mode, if there's any pending delta, fold it | 188 | * We're going into NOHZ mode, if there's any pending delta, fold it |
189 | * into the pending idle delta. | 189 | * into the pending idle delta. |
190 | */ | 190 | */ |
191 | delta = calc_load_fold_active(this_rq); | 191 | delta = calc_load_fold_active(this_rq, 0); |
192 | if (delta) { | 192 | if (delta) { |
193 | int idx = calc_load_write_idx(); | 193 | int idx = calc_load_write_idx(); |
194 | 194 | ||
@@ -389,7 +389,7 @@ void calc_global_load_tick(struct rq *this_rq) | |||
389 | if (time_before(jiffies, this_rq->calc_load_update)) | 389 | if (time_before(jiffies, this_rq->calc_load_update)) |
390 | return; | 390 | return; |
391 | 391 | ||
392 | delta = calc_load_fold_active(this_rq); | 392 | delta = calc_load_fold_active(this_rq, 0); |
393 | if (delta) | 393 | if (delta) |
394 | atomic_long_add(delta, &calc_load_tasks); | 394 | atomic_long_add(delta, &calc_load_tasks); |
395 | 395 | ||
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 7cbeb92a1cb9..898c0d2f18fe 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h | |||
@@ -28,7 +28,7 @@ extern unsigned long calc_load_update; | |||
28 | extern atomic_long_t calc_load_tasks; | 28 | extern atomic_long_t calc_load_tasks; |
29 | 29 | ||
30 | extern void calc_global_load_tick(struct rq *this_rq); | 30 | extern void calc_global_load_tick(struct rq *this_rq); |
31 | extern long calc_load_fold_active(struct rq *this_rq); | 31 | extern long calc_load_fold_active(struct rq *this_rq, long adjust); |
32 | 32 | ||
33 | #ifdef CONFIG_SMP | 33 | #ifdef CONFIG_SMP |
34 | extern void cpu_load_update_active(struct rq *this_rq); | 34 | extern void cpu_load_update_active(struct rq *this_rq); |