lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Tue, 23 Nov 2021 22:07:05 +0100
From:   Peter Zijlstra <peterz@...radead.org>
To:     Barry Song <21cnbao@...il.com>
Cc:     mingo@...hat.com, juri.lelli@...hat.com,
        vincent.guittot@...aro.org, rostedt@...dmis.org,
        linux-kernel@...r.kernel.org, dietmar.eggemann@....com,
        bsegall@...gle.com, mgorman@...e.de, bristot@...hat.com,
        Barry Song <song.bao.hua@...ilicon.com>
Subject: Re: [PATCH] sched/fair: Remove the cost of a redundant
 cpumask_next_wrap in select_idle_cpu

On Tue, Nov 23, 2021 at 07:22:29PM +0800, Barry Song wrote:
> From: Barry Song <song.bao.hua@...ilicon.com>
> 
> This patch keeps the same scanning amount, but drops a redundant loop
> of cpumask_next_wrap.
> The original code did for_each_cpu_wrap(cpu, cpus, target + 1), then
> checked --nr; this patch does --nr before doing the next loop, thus,
> it can remove a cpumask_next_wrap() which costs a little bit.
> 
> Signed-off-by: Barry Song <song.bao.hua@...ilicon.com>
> ---
>  kernel/sched/fair.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index ff69f24..e2fb3e0 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -6298,9 +6298,9 @@ static int select_idle_cpu(struct task_struct *p, struct sched_domain *sd, bool
>  
>  		span_avg = sd->span_weight * avg_idle;
>  		if (span_avg > 4*avg_cost)
> -			nr = div_u64(span_avg, avg_cost);
> +			nr = div_u64(span_avg, avg_cost) - 1;
>  		else
> -			nr = 4;
> +			nr = 3;
>  
>  		time = cpu_clock(this);
>  	}
> @@ -6312,11 +6312,11 @@ static int select_idle_cpu(struct task_struct *p, struct sched_domain *sd, bool
>  				return i;
>  
>  		} else {
> -			if (!--nr)
> -				return -1;
>  			idle_cpu = __select_idle_cpu(cpu, p);
>  			if ((unsigned int)idle_cpu < nr_cpumask_bits)
>  				break;
> +			if (!--nr)
> +				return -1;
>  		}
>  	}

That's just confusing code. Isn't it much clearer to write the whole
thing like so ?

	nr--;
	for_each_cpu_wrap(cpu, cpus, target+1) {
		...
		if (!nr--)
			return -1;
	}

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ