mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Valentin Schneider <valentin.schneider@arm.com>
To: Viresh Kumar <viresh.kumar@linaro.org>,
	Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>
Cc: Vincent Guittot <vincent.guittot@linaro.org>,
	Rohit Jain <rohit.k.jain@oracle.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH V2 1/2] sched/fair: Rearrange select_task_rq_fair() to optimize it
Date: Thu, 26 Apr 2018 15:35:17 +0100	[thread overview]
Message-ID: <f2904cf7-c41f-e064-d374-9a5bee0ca967@arm.com> (raw)
In-Reply-To: <20831b8d237bf3a20e4e328286f678b425ff04c9.1524738578.git.viresh.kumar@linaro.org>

Hi,

LGTM. Tiny inline comment but TBH might not be worth it.

FWIW: Reviewed-by: Valentin Schneider <valentin.schneider@arm.com>

On 26/04/18 11:30, Viresh Kumar wrote:
> Rearrange select_task_rq_fair() a bit to avoid executing some
> conditional statements in few specific code-paths. That gets rid of the
> goto as well.
> 
> This shouldn't result in any functional changes.
> 
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> Tested-by: Rohit Jain <rohit.k.jain@oracle.com>
> 
> ---
> V1->V2:
> - Optimize a bit more and get rid of affine_sd variable (Valentin)
> - Add unlikely while checking for non-NULL sd and add fast/slow path
>   comments (Joel)
> - Add tested-by from Rohit.
> 
>  kernel/sched/fair.c | 37 ++++++++++++++++---------------------
>  1 file changed, 16 insertions(+), 21 deletions(-)
> 
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 54dc31e7ab9b..84fc74ddbd4b 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -6613,7 +6613,7 @@ static int wake_cap(struct task_struct *p, int cpu, int prev_cpu)
>  static int
>  select_task_rq_fair(struct task_struct *p, int prev_cpu, int sd_flag, int wake_flags)
>  {
> -	struct sched_domain *tmp, *affine_sd = NULL, *sd = NULL;
> +	struct sched_domain *tmp, *sd = NULL;
>  	int cpu = smp_processor_id();
>  	int new_cpu = prev_cpu;
>  	int want_affine = 0;
> @@ -6636,7 +6636,10 @@ select_task_rq_fair(struct task_struct *p, int prev_cpu, int sd_flag, int wake_f
>  		 */
>  		if (want_affine && (tmp->flags & SD_WAKE_AFFINE) &&
>  		    cpumask_test_cpu(prev_cpu, sched_domain_span(tmp))) {
> -			affine_sd = tmp;
> +			if (cpu != prev_cpu)
> +				new_cpu = wake_affine(tmp, p, cpu, prev_cpu, sync);

This cpu != prev_cpu check could be folded into wake_affine() to make this
look a little neater, but we might want to keep things as is to avoid a
function call (it's only ever called once so it might get inlined, but AFAIK
that's not guaranteed).

> +
> +			sd = NULL; /* Prefer wake_affine over balance flags */
>  			break;
>  		}
>  
> @@ -6646,33 +6649,25 @@ select_task_rq_fair(struct task_struct *p, int prev_cpu, int sd_flag, int wake_f
>  			break;
>  	}
>  
> -	if (affine_sd) {
> -		sd = NULL; /* Prefer wake_affine over balance flags */
> -		if (cpu == prev_cpu)
> -			goto pick_cpu;
> -
> -		new_cpu = wake_affine(affine_sd, p, cpu, prev_cpu, sync);
> -	}
> +	if (unlikely(sd)) {
> +		/* Slow path */
>  
> -	if (sd && !(sd_flag & SD_BALANCE_FORK)) {
>  		/*
>  		 * We're going to need the task's util for capacity_spare_wake
>  		 * in find_idlest_group. Sync it up to prev_cpu's
>  		 * last_update_time.
>  		 */
> -		sync_entity_load_avg(&p->se);
> -	}
> -
> -	if (!sd) {
> -pick_cpu:
> -		if (sd_flag & SD_BALANCE_WAKE) { /* XXX always ? */
> -			new_cpu = select_idle_sibling(p, prev_cpu, new_cpu);
> +		if (!(sd_flag & SD_BALANCE_FORK))
> +			sync_entity_load_avg(&p->se);
>  
> -			if (want_affine)
> -				current->recent_used_cpu = cpu;
> -		}
> -	} else {
>  		new_cpu = find_idlest_cpu(sd, p, cpu, prev_cpu, sd_flag);
> +	} else if (sd_flag & SD_BALANCE_WAKE) { /* XXX always ? */
> +		/* Fast path */
> +
> +		new_cpu = select_idle_sibling(p, prev_cpu, new_cpu);
> +
> +		if (want_affine)
> +			current->recent_used_cpu = cpu;
>  	}
>  	rcu_read_unlock();
>  
> 

  parent reply	other threads:[~2018-04-26 14:35 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-26 10:30 Viresh Kumar
2018-04-26 10:30 ` [PATCH 2/2] sched/fair: Avoid calling sync_entity_load_avg() unnecessarily Viresh Kumar
2018-04-27  8:30   ` Dietmar Eggemann
2018-04-27  9:30     ` Viresh Kumar
2018-04-27 11:25     ` Quentin Perret
2018-05-04  9:37   ` [tip:sched/core] " tip-bot for Viresh Kumar
2018-04-26 14:35 ` Valentin Schneider [this message]
2018-05-04  9:36 ` [tip:sched/core] sched/fair: Rearrange select_task_rq_fair() to optimize it tip-bot for Viresh Kumar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f2904cf7-c41f-e064-d374-9a5bee0ca967@arm.com \
    --to=valentin.schneider@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rohit.k.jain@oracle.com \
    --cc=vincent.guittot@linaro.org \
    --cc=viresh.kumar@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®