Skip to content

Commit 518cd62

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
sched: Only queue remote wakeups when crossing cache boundaries
Mike reported a 13% drop in netperf TCP_RR performance due to the new remote wakeup code. Suresh too noticed some performance issues with it. Reducing the IPIs to only cross cache domains solves the observed performance issues. Reported-by: Suresh Siddha <suresh.b.siddha@intel.com> Reported-by: Mike Galbraith <efault@gmx.de> Acked-by: Suresh Siddha <suresh.b.siddha@intel.com> Acked-by: Mike Galbraith <efault@gmx.de> Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Chris Mason <chris.mason@oracle.com> Cc: Dave Kleikamp <dave.kleikamp@oracle.com> Link: http://lkml.kernel.org/r/1323338531.17673.7.camel@twins Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent 612ef28 commit 518cd62

3 files changed

Lines changed: 70 additions & 30 deletions

File tree

‎kernel/sched/core.c‎

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1511,14 +1511,19 @@ static int ttwu_activate_remote(struct task_struct *p, int wake_flags)
15111511

15121512
}
15131513
#endif /* __ARCH_WANT_INTERRUPTS_ON_CTXSW */
1514+
1515+
static inline int ttwu_share_cache(int this_cpu, int that_cpu)
1516+
{
1517+
return per_cpu(sd_llc_id, this_cpu) == per_cpu(sd_llc_id, that_cpu);
1518+
}
15141519
#endif /* CONFIG_SMP */
15151520

15161521
static void ttwu_queue(struct task_struct *p, int cpu)
15171522
{
15181523
struct rq *rq = cpu_rq(cpu);
15191524

15201525
#if defined(CONFIG_SMP)
1521-
if (sched_feat(TTWU_QUEUE) && cpu != smp_processor_id()) {
1526+
if (sched_feat(TTWU_QUEUE) && !ttwu_share_cache(smp_processor_id(), cpu)) {
15221527
sched_clock_cpu(cpu); /* sync clocks x-cpu */
15231528
ttwu_queue_remote(p, cpu);
15241529
return;
@@ -5743,6 +5748,31 @@ static void destroy_sched_domains(struct sched_domain *sd, int cpu)
57435748
destroy_sched_domain(sd, cpu);
57445749
}
57455750

5751+
/*
5752+
* Keep a special pointer to the highest sched_domain that has
5753+
* SD_SHARE_PKG_RESOURCE set (Last Level Cache Domain) for this
5754+
* allows us to avoid some pointer chasing select_idle_sibling().
5755+
*
5756+
* Also keep a unique ID per domain (we use the first cpu number in
5757+
* the cpumask of the domain), this allows us to quickly tell if
5758+
* two cpus are in the same cache domain, see ttwu_share_cache().
5759+
*/
5760+
DEFINE_PER_CPU(struct sched_domain *, sd_llc);
5761+
DEFINE_PER_CPU(int, sd_llc_id);
5762+
5763+
static void update_top_cache_domain(int cpu)
5764+
{
5765+
struct sched_domain *sd;
5766+
int id = cpu;
5767+
5768+
sd = highest_flag_domain(cpu, SD_SHARE_PKG_RESOURCES);
5769+
if (sd)
5770+
id = cpumask_first(sched_domain_span(sd));
5771+
5772+
rcu_assign_pointer(per_cpu(sd_llc, cpu), sd);
5773+
per_cpu(sd_llc_id, cpu) = id;
5774+
}
5775+
57465776
/*
57475777
* Attach the domain 'sd' to 'cpu' as its base domain. Callers must
57485778
* hold the hotplug lock.
@@ -5782,6 +5812,8 @@ cpu_attach_domain(struct sched_domain *sd, struct root_domain *rd, int cpu)
57825812
tmp = rq->sd;
57835813
rcu_assign_pointer(rq->sd, sd);
57845814
destroy_sched_domains(tmp, cpu);
5815+
5816+
update_top_cache_domain(cpu);
57855817
}
57865818

57875819
/* cpus with isolated domains */

‎kernel/sched/fair.c‎

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2644,28 +2644,6 @@ find_idlest_cpu(struct sched_group *group, struct task_struct *p, int this_cpu)
26442644
return idlest;
26452645
}
26462646

2647-
/**
2648-
* highest_flag_domain - Return highest sched_domain containing flag.
2649-
* @cpu: The cpu whose highest level of sched domain is to
2650-
* be returned.
2651-
* @flag: The flag to check for the highest sched_domain
2652-
* for the given cpu.
2653-
*
2654-
* Returns the highest sched_domain of a cpu which contains the given flag.
2655-
*/
2656-
static inline struct sched_domain *highest_flag_domain(int cpu, int flag)
2657-
{
2658-
struct sched_domain *sd, *hsd = NULL;
2659-
2660-
for_each_domain(cpu, sd) {
2661-
if (!(sd->flags & flag))
2662-
break;
2663-
hsd = sd;
2664-
}
2665-
2666-
return hsd;
2667-
}
2668-
26692647
/*
26702648
* Try and locate an idle CPU in the sched_domain.
26712649
*/
@@ -2696,7 +2674,7 @@ static int select_idle_sibling(struct task_struct *p, int target)
26962674
*/
26972675
rcu_read_lock();
26982676

2699-
sd = highest_flag_domain(target, SD_SHARE_PKG_RESOURCES);
2677+
sd = rcu_dereference(per_cpu(sd_llc, target));
27002678
for_each_lower_domain(sd) {
27012679
sg = sd->groups;
27022680
do {

‎kernel/sched/sched.h‎

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,14 @@ static inline int cpu_of(struct rq *rq)
487487

488488
DECLARE_PER_CPU(struct rq, runqueues);
489489

490+
#define cpu_rq(cpu) (&per_cpu(runqueues, (cpu)))
491+
#define this_rq() (&__get_cpu_var(runqueues))
492+
#define task_rq(p) cpu_rq(task_cpu(p))
493+
#define cpu_curr(cpu) (cpu_rq(cpu)->curr)
494+
#define raw_rq() (&__raw_get_cpu_var(runqueues))
495+
496+
#ifdef CONFIG_SMP
497+
490498
#define rcu_dereference_check_sched_domain(p) \
491499
rcu_dereference_check((p), \
492500
lockdep_is_held(&sched_domains_mutex))
@@ -499,15 +507,37 @@ DECLARE_PER_CPU(struct rq, runqueues);
499507
* preempt-disabled sections.
500508
*/
501509
#define for_each_domain(cpu, __sd) \
502-
for (__sd = rcu_dereference_check_sched_domain(cpu_rq(cpu)->sd); __sd; __sd = __sd->parent)
510+
for (__sd = rcu_dereference_check_sched_domain(cpu_rq(cpu)->sd); \
511+
__sd; __sd = __sd->parent)
503512

504513
#define for_each_lower_domain(sd) for (; sd; sd = sd->child)
505514

506-
#define cpu_rq(cpu) (&per_cpu(runqueues, (cpu)))
507-
#define this_rq() (&__get_cpu_var(runqueues))
508-
#define task_rq(p) cpu_rq(task_cpu(p))
509-
#define cpu_curr(cpu) (cpu_rq(cpu)->curr)
510-
#define raw_rq() (&__raw_get_cpu_var(runqueues))
515+
/**
516+
* highest_flag_domain - Return highest sched_domain containing flag.
517+
* @cpu: The cpu whose highest level of sched domain is to
518+
* be returned.
519+
* @flag: The flag to check for the highest sched_domain
520+
* for the given cpu.
521+
*
522+
* Returns the highest sched_domain of a cpu which contains the given flag.
523+
*/
524+
static inline struct sched_domain *highest_flag_domain(int cpu, int flag)
525+
{
526+
struct sched_domain *sd, *hsd = NULL;
527+
528+
for_each_domain(cpu, sd) {
529+
if (!(sd->flags & flag))
530+
break;
531+
hsd = sd;
532+
}
533+
534+
return hsd;
535+
}
536+
537+
DECLARE_PER_CPU(struct sched_domain *, sd_llc);
538+
DECLARE_PER_CPU(int, sd_llc_id);
539+
540+
#endif /* CONFIG_SMP */
511541

512542
#include "stats.h"
513543
#include "auto_group.h"

0 commit comments

Comments
 (0)