LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [patch] sched: optimize siblings status check logic in wake_idle()
@ 2007-03-03  4:23 Siddha, Suresh B
  2007-03-05  2:35 ` Nick Piggin
  0 siblings, 1 reply; 5+ messages in thread
From: Siddha, Suresh B @ 2007-03-03  4:23 UTC (permalink / raw)
  To: akpm; +Cc: mingo, linux-kernel, npiggin

When a logical cpu 'x' already has more than one process running, then most likely
the siblings of that cpu 'x' must be busy. Otherwise the idle siblings
would have likely(in most of the scenarios) picked up the extra load making
the load on 'x' atmost one.

Use this logic to eliminate the siblings status check and minimize the cache
misses encountered on a heavily loaded system.

Signed-off-by: Suresh Siddha <suresh.b.siddha@intel.com>
---

diff --git a/kernel/sched.c b/kernel/sched.c
index 0dc7572..d1ecc56 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -1368,7 +1368,16 @@ static int wake_idle(int cpu, struct task_struct *p)
 	struct sched_domain *sd;
 	int i;
 
-	if (idle_cpu(cpu))
+	/*
+	 * If it is idle, then it is the best cpu to run this task.
+	 *
+	 * This cpu is also the best, if it has more than one task already.
+	 * Siblings must be also busy(in most cases) as they didn't already
+	 * pickup the extra load from this cpu and hence we need not check
+	 * sibling runqueue info. This will avoid the checks and cache miss
+	 * penalities associated with that.
+	 */
+	if (idle_cpu(cpu) || cpu_rq(cpu)->nr_running > 1)
 		return cpu;
 
 	for_each_domain(cpu, sd) {

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [patch] sched: optimize siblings status check logic in wake_idle()
  2007-03-03  4:23 [patch] sched: optimize siblings status check logic in wake_idle() Siddha, Suresh B
@ 2007-03-05  2:35 ` Nick Piggin
  2007-03-05  4:13   ` Siddha, Suresh B
  0 siblings, 1 reply; 5+ messages in thread
From: Nick Piggin @ 2007-03-05  2:35 UTC (permalink / raw)
  To: Siddha, Suresh B; +Cc: akpm, mingo, linux-kernel

On Fri, Mar 02, 2007 at 08:23:32PM -0800, Suresh B wrote:
> When a logical cpu 'x' already has more than one process running, then most likely
> the siblings of that cpu 'x' must be busy. Otherwise the idle siblings
> would have likely(in most of the scenarios) picked up the extra load making
> the load on 'x' atmost one.

Do you have any stats on this?

> Use this logic to eliminate the siblings status check and minimize the cache
> misses encountered on a heavily loaded system.

Well it does increase the cacheline footprint a bit, but all cachelines
should be local to our L1 cache, presuming you don't have any CPUs where
threads have seperate caches.

What sort of numbers do you have?

> 
> Signed-off-by: Suresh Siddha <suresh.b.siddha@intel.com>
> ---
> 
> diff --git a/kernel/sched.c b/kernel/sched.c
> index 0dc7572..d1ecc56 100644
> --- a/kernel/sched.c
> +++ b/kernel/sched.c
> @@ -1368,7 +1368,16 @@ static int wake_idle(int cpu, struct task_struct *p)
>  	struct sched_domain *sd;
>  	int i;
>  
> -	if (idle_cpu(cpu))
> +	/*
> +	 * If it is idle, then it is the best cpu to run this task.
> +	 *
> +	 * This cpu is also the best, if it has more than one task already.
> +	 * Siblings must be also busy(in most cases) as they didn't already
> +	 * pickup the extra load from this cpu and hence we need not check
> +	 * sibling runqueue info. This will avoid the checks and cache miss
> +	 * penalities associated with that.
> +	 */
> +	if (idle_cpu(cpu) || cpu_rq(cpu)->nr_running > 1)
>  		return cpu;
>  
>  	for_each_domain(cpu, sd) {

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [patch] sched: optimize siblings status check logic in wake_idle()
  2007-03-05  2:35 ` Nick Piggin
@ 2007-03-05  4:13   ` Siddha, Suresh B
  2007-03-05  4:58     ` Nick Piggin
  0 siblings, 1 reply; 5+ messages in thread
From: Siddha, Suresh B @ 2007-03-05  4:13 UTC (permalink / raw)
  To: Nick Piggin; +Cc: Siddha, Suresh B, akpm, mingo, linux-kernel

On Mon, Mar 05, 2007 at 03:35:34AM +0100, Nick Piggin wrote:
> On Fri, Mar 02, 2007 at 08:23:32PM -0800, Suresh B wrote:
> > When a logical cpu 'x' already has more than one process running, then most likely
> > the siblings of that cpu 'x' must be busy. Otherwise the idle siblings
> > would have likely(in most of the scenarios) picked up the extra load making
> > the load on 'x' atmost one.
> 
> Do you have any stats on this?

Its more of a theory. There will be some conditions that this won't be true but
IMO those won't be common cases.

> > Use this logic to eliminate the siblings status check and minimize the cache
> > misses encountered on a heavily loaded system.
> 
> Well it does increase the cacheline footprint a bit, but all cachelines
> should be local to our L1 cache, presuming you don't have any CPUs where
> threads have seperate caches.

These wakeup's can happen across SMP and NUMA domains. In those cases, most likely
the sibling runqueue lines won't be in the caches. This has nothing to do with
siblings sharing caches or not.

> 
> What sort of numbers do you have?

On a 16 node system, we have seen ~1.25% perf improvement on a database workload
when we completely short circuited wake_idle(). This patch is trying to comeup
with a best compromise to avoid the cache misses and also minimize the latenices,
perf impact.

thanks,
suresh

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [patch] sched: optimize siblings status check logic in wake_idle()
  2007-03-05  4:58     ` Nick Piggin
@ 2007-03-05  4:24       ` Siddha, Suresh B
  0 siblings, 0 replies; 5+ messages in thread
From: Siddha, Suresh B @ 2007-03-05  4:24 UTC (permalink / raw)
  To: Nick Piggin; +Cc: Siddha, Suresh B, akpm, mingo, linux-kernel

On Mon, Mar 05, 2007 at 05:58:31AM +0100, Nick Piggin wrote:
> On Sun, Mar 04, 2007 at 08:13:09PM -0800, Suresh B wrote:
> > On a 16 node system, we have seen ~1.25% perf improvement on a database workload
> > when we completely short circuited wake_idle(). This patch is trying to comeup
> > with a best compromise to avoid the cache misses and also minimize the latenices,
> > perf impact.
> 
> Hmm, I wonder what if we only wake_idle if the wakeup comes from this
> CPU or a sibling? That's probably going to have downsides in some
> workloads as well, though.

yep. I thought about it and thought this patch is a decent solution.

thanks,
suresh

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [patch] sched: optimize siblings status check logic in wake_idle()
  2007-03-05  4:13   ` Siddha, Suresh B
@ 2007-03-05  4:58     ` Nick Piggin
  2007-03-05  4:24       ` Siddha, Suresh B
  0 siblings, 1 reply; 5+ messages in thread
From: Nick Piggin @ 2007-03-05  4:58 UTC (permalink / raw)
  To: Siddha, Suresh B; +Cc: akpm, mingo, linux-kernel

On Sun, Mar 04, 2007 at 08:13:09PM -0800, Suresh B wrote:
> On Mon, Mar 05, 2007 at 03:35:34AM +0100, Nick Piggin wrote:
> > On Fri, Mar 02, 2007 at 08:23:32PM -0800, Suresh B wrote:
> > > When a logical cpu 'x' already has more than one process running, then most likely
> > > the siblings of that cpu 'x' must be busy. Otherwise the idle siblings
> > > would have likely(in most of the scenarios) picked up the extra load making
> > > the load on 'x' atmost one.
> > 
> > Do you have any stats on this?
> 
> Its more of a theory. There will be some conditions that this won't be true but
> IMO those won't be common cases.
> 
> > > Use this logic to eliminate the siblings status check and minimize the cache
> > > misses encountered on a heavily loaded system.
> > 
> > Well it does increase the cacheline footprint a bit, but all cachelines
> > should be local to our L1 cache, presuming you don't have any CPUs where
> > threads have seperate caches.
> 
> These wakeup's can happen across SMP and NUMA domains. In those cases, most likely
> the sibling runqueue lines won't be in the caches. This has nothing to do with
> siblings sharing caches or not.

Oh that's true.

> > 
> > What sort of numbers do you have?
> 
> On a 16 node system, we have seen ~1.25% perf improvement on a database workload
> when we completely short circuited wake_idle(). This patch is trying to comeup
> with a best compromise to avoid the cache misses and also minimize the latenices,
> perf impact.

Hmm, I wonder what if we only wake_idle if the wakeup comes from this
CPU or a sibling? That's probably going to have downsides in some
workloads as well, though.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-03-05  5:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-03  4:23 [patch] sched: optimize siblings status check logic in wake_idle() Siddha, Suresh B
2007-03-05  2:35 ` Nick Piggin
2007-03-05  4:13   ` Siddha, Suresh B
2007-03-05  4:58     ` Nick Piggin
2007-03-05  4:24       ` Siddha, Suresh B

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).