linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] sched/fair: Optimize select_idle_core
@ 2019-12-06 17:24 Srikar Dronamraju
  2020-01-22 13:55 ` Mel Gorman
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Srikar Dronamraju @ 2019-12-06 17:24 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra
  Cc: LKML, Mel Gorman, Rik van Riel, Srikar Dronamraju,
	Thomas Gleixner, Valentin Schneider, Vincent Guittot

Currently we loop through all threads of a core to evaluate if the core is
idle or not. This is unnecessary. If a thread of a core is not idle, skip
evaluating other threads of a core. Also while clearing the cpumask, bits
of all CPUs of a core can be cleared in one-shot.

Collecting ticks on a Power 9 SMT 8 system around select_idle_core
while running schbench shows us

(units are in ticks, hence lesser is better)
Without patch
    N        Min     Max     Median         Avg      Stddev
x 130        151    1083        284   322.72308   144.41494


With patch
    N        Min     Max     Median         Avg      Stddev   Improvement
x 164         88     610        201   225.79268   106.78943        30.03%


Reviewed-by: Valentin Schneider <valentin.schneider@arm.com>
Reviewed-by: Vincent Guittot <vincent.guittot@linaro.org>
Signed-off-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
---
Changelog v1->v2:
Updated patch description with measurements made from a debug patch.

 kernel/sched/fair.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 69a81a5709ff..b9d628128cfc 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -5872,10 +5872,12 @@ static int select_idle_core(struct task_struct *p, struct sched_domain *sd, int
 		bool idle = true;
 
 		for_each_cpu(cpu, cpu_smt_mask(core)) {
-			__cpumask_clear_cpu(cpu, cpus);
-			if (!available_idle_cpu(cpu))
+			if (!available_idle_cpu(cpu)) {
 				idle = false;
+				break;
+			}
 		}
+		cpumask_andnot(cpus, cpus, cpu_smt_mask(core));
 
 		if (idle)
 			return core;
-- 
2.18.1


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

* Re: [PATCH v2] sched/fair: Optimize select_idle_core
  2019-12-06 17:24 [PATCH v2] sched/fair: Optimize select_idle_core Srikar Dronamraju
@ 2020-01-22 13:55 ` Mel Gorman
  2020-01-22 14:22   ` Valentin Schneider
  2020-01-24 13:32 ` Srikar Dronamraju
  2020-01-29 11:32 ` [tip: sched/core] sched/fair: Optimize select_idle_core() tip-bot2 for Srikar Dronamraju
  2 siblings, 1 reply; 5+ messages in thread
From: Mel Gorman @ 2020-01-22 13:55 UTC (permalink / raw)
  To: Srikar Dronamraju
  Cc: Ingo Molnar, Peter Zijlstra, LKML, Rik van Riel, Thomas Gleixner,
	Valentin Schneider, Vincent Guittot

On Fri, Dec 06, 2019 at 10:54:22PM +0530, Srikar Dronamraju wrote:
> Currently we loop through all threads of a core to evaluate if the core is
> idle or not. This is unnecessary. If a thread of a core is not idle, skip
> evaluating other threads of a core. Also while clearing the cpumask, bits
> of all CPUs of a core can be cleared in one-shot.
> 
> Collecting ticks on a Power 9 SMT 8 system around select_idle_core
> while running schbench shows us
> 
> (units are in ticks, hence lesser is better)
> Without patch
>     N        Min     Max     Median         Avg      Stddev
> x 130        151    1083        284   322.72308   144.41494
> 
> 
> With patch
>     N        Min     Max     Median         Avg      Stddev   Improvement
> x 164         88     610        201   225.79268   106.78943        30.03%
> 
> 
> Reviewed-by: Valentin Schneider <valentin.schneider@arm.com>
> Reviewed-by: Vincent Guittot <vincent.guittot@linaro.org>
> Signed-off-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com>

Acked-by: Mel Gorman <mgorman@techsingularity.net>

I'm a bit surprised to not see this in linux-next or tip. Did this get
rejected or did it accidentally get overlooked because the subject is so
similar to 60588bfa223f ("sched/fair: Optimize select_idle_cpu") ?

-- 
Mel Gorman
SUSE Labs

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

* Re: [PATCH v2] sched/fair: Optimize select_idle_core
  2020-01-22 13:55 ` Mel Gorman
@ 2020-01-22 14:22   ` Valentin Schneider
  0 siblings, 0 replies; 5+ messages in thread
From: Valentin Schneider @ 2020-01-22 14:22 UTC (permalink / raw)
  To: Mel Gorman, Srikar Dronamraju
  Cc: Ingo Molnar, Peter Zijlstra, LKML, Rik van Riel, Thomas Gleixner,
	Vincent Guittot

On 22/01/2020 13:55, Mel Gorman wrote:
> 
> Acked-by: Mel Gorman <mgorman@techsingularity.net>
> 
> I'm a bit surprised to not see this in linux-next or tip. Did this get
> rejected or did it accidentally get overlooked because the subject is so
> similar to 60588bfa223f ("sched/fair: Optimize select_idle_cpu") ?
> 

Most likely the latter; I also had completely forgotten about it and had to
retrace where and when I reviewed that...

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

* Re: [PATCH v2] sched/fair: Optimize select_idle_core
  2019-12-06 17:24 [PATCH v2] sched/fair: Optimize select_idle_core Srikar Dronamraju
  2020-01-22 13:55 ` Mel Gorman
@ 2020-01-24 13:32 ` Srikar Dronamraju
  2020-01-29 11:32 ` [tip: sched/core] sched/fair: Optimize select_idle_core() tip-bot2 for Srikar Dronamraju
  2 siblings, 0 replies; 5+ messages in thread
From: Srikar Dronamraju @ 2020-01-24 13:32 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra
  Cc: LKML, Mel Gorman, Rik van Riel, Thomas Gleixner,
	Valentin Schneider, Vincent Guittot


Hey Peter, Ingo,

* Srikar Dronamraju <srikar@linux.vnet.ibm.com> [2019-12-06 22:54:22]:

> Currently we loop through all threads of a core to evaluate if the core is
> idle or not. This is unnecessary. If a thread of a core is not idle, skip
> evaluating other threads of a core. Also while clearing the cpumask, bits
> of all CPUs of a core can be cleared in one-shot.
> 
> Collecting ticks on a Power 9 SMT 8 system around select_idle_core
> while running schbench shows us
> 
> (units are in ticks, hence lesser is better)
> Without patch
>     N        Min     Max     Median         Avg      Stddev
> x 130        151    1083        284   322.72308   144.41494
> 
> 
> With patch
>     N        Min     Max     Median         Avg      Stddev   Improvement
> x 164         88     610        201   225.79268   106.78943        30.03%
> 
> 
> Reviewed-by: Valentin Schneider <valentin.schneider@arm.com>
> Reviewed-by: Vincent Guittot <vincent.guittot@linaro.org>
> Signed-off-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
> ---
> Changelog v1->v2:
> Updated patch description with measurements made from a debug patch.
> 
>  kernel/sched/fair.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)

Do you have any comments or improvements to be done for this patch?

-- 
Thanks and Regards
Srikar Dronamraju


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

* [tip: sched/core] sched/fair: Optimize select_idle_core()
  2019-12-06 17:24 [PATCH v2] sched/fair: Optimize select_idle_core Srikar Dronamraju
  2020-01-22 13:55 ` Mel Gorman
  2020-01-24 13:32 ` Srikar Dronamraju
@ 2020-01-29 11:32 ` tip-bot2 for Srikar Dronamraju
  2 siblings, 0 replies; 5+ messages in thread
From: tip-bot2 for Srikar Dronamraju @ 2020-01-29 11:32 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Srikar Dronamraju, Peter Zijlstra (Intel),
	Ingo Molnar, Valentin Schneider, Vincent Guittot, Mel Gorman,
	x86, LKML

The following commit has been merged into the sched/core branch of tip:

Commit-ID:     bec2860a2bd6cd38ea34434d04f4033eb32f0f31
Gitweb:        https://git.kernel.org/tip/bec2860a2bd6cd38ea34434d04f4033eb32f0f31
Author:        Srikar Dronamraju <srikar@linux.vnet.ibm.com>
AuthorDate:    Fri, 06 Dec 2019 22:54:22 +05:30
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Tue, 28 Jan 2020 21:37:08 +01:00

sched/fair: Optimize select_idle_core()

Currently we loop through all threads of a core to evaluate if the core is
idle or not. This is unnecessary. If a thread of a core is not idle, skip
evaluating other threads of a core. Also while clearing the cpumask, bits
of all CPUs of a core can be cleared in one-shot.

Collecting ticks on a Power 9 SMT 8 system around select_idle_core
while running schbench shows us

(units are in ticks, hence lesser is better)
Without patch
    N        Min     Max     Median         Avg      Stddev
x 130        151    1083        284   322.72308   144.41494

With patch
    N        Min     Max     Median         Avg      Stddev   Improvement
x 164         88     610        201   225.79268   106.78943        30.03%

Signed-off-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Valentin Schneider <valentin.schneider@arm.com>
Reviewed-by: Vincent Guittot <vincent.guittot@linaro.org>
Acked-by: Mel Gorman <mgorman@techsingularity.net>
Link: https://lkml.kernel.org/r/20191206172422.6578-1-srikar@linux.vnet.ibm.com
---
 kernel/sched/fair.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 25dffc0..1a0ce83 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -5787,10 +5787,12 @@ static int select_idle_core(struct task_struct *p, struct sched_domain *sd, int 
 		bool idle = true;
 
 		for_each_cpu(cpu, cpu_smt_mask(core)) {
-			__cpumask_clear_cpu(cpu, cpus);
-			if (!available_idle_cpu(cpu))
+			if (!available_idle_cpu(cpu)) {
 				idle = false;
+				break;
+			}
 		}
+		cpumask_andnot(cpus, cpus, cpu_smt_mask(core));
 
 		if (idle)
 			return core;

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

end of thread, other threads:[~2020-01-29 11:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-06 17:24 [PATCH v2] sched/fair: Optimize select_idle_core Srikar Dronamraju
2020-01-22 13:55 ` Mel Gorman
2020-01-22 14:22   ` Valentin Schneider
2020-01-24 13:32 ` Srikar Dronamraju
2020-01-29 11:32 ` [tip: sched/core] sched/fair: Optimize select_idle_core() tip-bot2 for Srikar Dronamraju

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).