Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

sched: Fix schedstat.nr_wakeups_migrate

While looking over the code I found that with the ttwu rework the
nr_wakeups_migrate test broke since we now switch cpus prior to
calling ttwu_stat(), hence the test is always true.

Cure this by passing the migration state in wake_flags. Also move the
whole test under CONFIG_SMP, its hard to migrate tasks on UP :-)

Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/n/tip-pwwxl7gdqs5676f1d4cx6pj7@git.kernel.org
Signed-off-by: Ingo Molnar <mingo@elte.hu>

authored by

Peter Zijlstra and committed by
Ingo Molnar
f339b9dc f01114cb

+8 -4
+1
include/linux/sched.h
··· 1063 1063 */ 1064 1064 #define WF_SYNC 0x01 /* waker goes to sleep after wakup */ 1065 1065 #define WF_FORK 0x02 /* child wakeup after fork */ 1066 + #define WF_MIGRATED 0x04 /* internal use, task got migrated */ 1066 1067 1067 1068 #define ENQUEUE_WAKEUP 1 1068 1069 #define ENQUEUE_HEAD 2
+7 -4
kernel/sched.c
··· 2447 2447 } 2448 2448 rcu_read_unlock(); 2449 2449 } 2450 + 2451 + if (wake_flags & WF_MIGRATED) 2452 + schedstat_inc(p, se.statistics.nr_wakeups_migrate); 2453 + 2450 2454 #endif /* CONFIG_SMP */ 2451 2455 2452 2456 schedstat_inc(rq, ttwu_count); ··· 2458 2454 2459 2455 if (wake_flags & WF_SYNC) 2460 2456 schedstat_inc(p, se.statistics.nr_wakeups_sync); 2461 - 2462 - if (cpu != task_cpu(p)) 2463 - schedstat_inc(p, se.statistics.nr_wakeups_migrate); 2464 2457 2465 2458 #endif /* CONFIG_SCHEDSTATS */ 2466 2459 } ··· 2676 2675 p->sched_class->task_waking(p); 2677 2676 2678 2677 cpu = select_task_rq(p, SD_BALANCE_WAKE, wake_flags); 2679 - if (task_cpu(p) != cpu) 2678 + if (task_cpu(p) != cpu) { 2679 + wake_flags |= WF_MIGRATED; 2680 2680 set_task_cpu(p, cpu); 2681 + } 2681 2682 #endif /* CONFIG_SMP */ 2682 2683 2683 2684 ttwu_queue(p, cpu);