diff options
author | Peter Zijlstra <peterz@infradead.org> | 2016-05-23 05:19:07 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2016-05-25 02:35:18 -0400 |
commit | b7e7ade34e6188bee2e3b0d42b51d25137d9e2a5 (patch) | |
tree | 7cb4526b1902a93c7197a3c11150e616d565f0d5 | |
parent | 2e636d5e66c35dfcbaf617aa8fa963f6847478fe (diff) |
sched/core: Fix remote wakeups
Commit:
b5179ac70de8 ("sched/fair: Prepare to fix fairness problems on migration")
... introduced a bug: Mike Galbraith found that it introduced a
performance regression, while Paul E. McKenney reported lost
wakeups and bisected it to this commit.
The reason is that I mis-read ttwu_queue() such that I assumed any
wakeup that got a remote queue must have had the task migrated.
Since this is not so; we need to transfer this information between
queueing the wakeup and actually doing the wakeup. Use a new
task_struct::sched_flag for this, we already write to
sched_contributes_to_load in the wakeup path so this is a hot and
modified cacheline.
Reported-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Reported-by: Mike Galbraith <umgwanakikbuti@gmail.com>
Tested-by: Mike Galbraith <umgwanakikbuti@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Andrew Hunter <ahh@google.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Ben Segall <bsegall@google.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Matt Fleming <matt@codeblueprint.co.uk>
Cc: Morten Rasmussen <morten.rasmussen@arm.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Paul Turner <pjt@google.com>
Cc: Pavan Kondeti <pkondeti@codeaurora.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Quentin Casasnovas <quentin.casasnovas@oracle.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: byungchul.park@lge.com
Fixes: b5179ac70de8 ("sched/fair: Prepare to fix fairness problems on migration")
Link: http://lkml.kernel.org/r/20160523091907.GD15728@worktop.ger.corp.intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r-- | include/linux/sched.h | 1 | ||||
-rw-r--r-- | kernel/sched/core.c | 18 |
2 files changed, 12 insertions, 7 deletions
diff --git a/include/linux/sched.h b/include/linux/sched.h index 6cc0df970f1a..e053517a88b6 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h | |||
@@ -1533,6 +1533,7 @@ struct task_struct { | |||
1533 | unsigned sched_reset_on_fork:1; | 1533 | unsigned sched_reset_on_fork:1; |
1534 | unsigned sched_contributes_to_load:1; | 1534 | unsigned sched_contributes_to_load:1; |
1535 | unsigned sched_migrated:1; | 1535 | unsigned sched_migrated:1; |
1536 | unsigned sched_remote_wakeup:1; | ||
1536 | unsigned :0; /* force alignment to the next boundary */ | 1537 | unsigned :0; /* force alignment to the next boundary */ |
1537 | 1538 | ||
1538 | /* unserialized, strictly 'current' */ | 1539 | /* unserialized, strictly 'current' */ |
diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 404c0784b1fc..7f2cae4620c7 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c | |||
@@ -1768,13 +1768,15 @@ void sched_ttwu_pending(void) | |||
1768 | cookie = lockdep_pin_lock(&rq->lock); | 1768 | cookie = lockdep_pin_lock(&rq->lock); |
1769 | 1769 | ||
1770 | while (llist) { | 1770 | while (llist) { |
1771 | int wake_flags = 0; | ||
1772 | |||
1771 | p = llist_entry(llist, struct task_struct, wake_entry); | 1773 | p = llist_entry(llist, struct task_struct, wake_entry); |
1772 | llist = llist_next(llist); | 1774 | llist = llist_next(llist); |
1773 | /* | 1775 | |
1774 | * See ttwu_queue(); we only call ttwu_queue_remote() when | 1776 | if (p->sched_remote_wakeup) |
1775 | * its a x-cpu wakeup. | 1777 | wake_flags = WF_MIGRATED; |
1776 | */ | 1778 | |
1777 | ttwu_do_activate(rq, p, WF_MIGRATED, cookie); | 1779 | ttwu_do_activate(rq, p, wake_flags, cookie); |
1778 | } | 1780 | } |
1779 | 1781 | ||
1780 | lockdep_unpin_lock(&rq->lock, cookie); | 1782 | lockdep_unpin_lock(&rq->lock, cookie); |
@@ -1819,10 +1821,12 @@ void scheduler_ipi(void) | |||
1819 | irq_exit(); | 1821 | irq_exit(); |
1820 | } | 1822 | } |
1821 | 1823 | ||
1822 | static void ttwu_queue_remote(struct task_struct *p, int cpu) | 1824 | static void ttwu_queue_remote(struct task_struct *p, int cpu, int wake_flags) |
1823 | { | 1825 | { |
1824 | struct rq *rq = cpu_rq(cpu); | 1826 | struct rq *rq = cpu_rq(cpu); |
1825 | 1827 | ||
1828 | p->sched_remote_wakeup = !!(wake_flags & WF_MIGRATED); | ||
1829 | |||
1826 | if (llist_add(&p->wake_entry, &cpu_rq(cpu)->wake_list)) { | 1830 | if (llist_add(&p->wake_entry, &cpu_rq(cpu)->wake_list)) { |
1827 | if (!set_nr_if_polling(rq->idle)) | 1831 | if (!set_nr_if_polling(rq->idle)) |
1828 | smp_send_reschedule(cpu); | 1832 | smp_send_reschedule(cpu); |
@@ -1869,7 +1873,7 @@ static void ttwu_queue(struct task_struct *p, int cpu, int wake_flags) | |||
1869 | #if defined(CONFIG_SMP) | 1873 | #if defined(CONFIG_SMP) |
1870 | if (sched_feat(TTWU_QUEUE) && !cpus_share_cache(smp_processor_id(), cpu)) { | 1874 | if (sched_feat(TTWU_QUEUE) && !cpus_share_cache(smp_processor_id(), cpu)) { |
1871 | sched_clock_cpu(cpu); /* sync clocks x-cpu */ | 1875 | sched_clock_cpu(cpu); /* sync clocks x-cpu */ |
1872 | ttwu_queue_remote(p, cpu); | 1876 | ttwu_queue_remote(p, cpu, wake_flags); |
1873 | return; | 1877 | return; |
1874 | } | 1878 | } |
1875 | #endif | 1879 | #endif |