mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Valentin Schneider <vschneid@redhat.com>
To: Peter Zijlstra <peterz@infradead.org>, Yury Norov <yury.norov@gmail.com>
Cc: "Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
	"David Laight" <David.Laight@ACULAB.COM>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Joe Perches" <joe@perches.com>,
	"Julia Lawall" <Julia.Lawall@inria.fr>,
	"Michał Mirosław" <mirq-linux@rere.qmqm.pl>,
	"Nicholas Piggin" <npiggin@gmail.com>,
	"Nicolas Palix" <nicolas.palix@imag.fr>,
	"Rasmus Villemoes" <linux@rasmusvillemoes.dk>,
	"Matti Vaittinen" <Matti.Vaittinen@fi.rohmeurope.com>,
	linux-kernel@vger.kernel.org, "Ben Segall" <bsegall@google.com>,
	"Daniel Bristot de Oliveira" <bristot@redhat.com>,
	"Dietmar Eggemann" <dietmar.eggemann@arm.com>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Juri Lelli" <juri.lelli@redhat.com>,
	"Mel Gorman" <mgorman@suse.de>,
	"Steven Rostedt" <rostedt@goodmis.org>,
	"Vincent Guittot" <vincent.guittot@linaro.org>
Subject: Re: [PATCH 17/22] sched/core: fix opencoded cpumask_any_but()
Date: Tue, 10 May 2022 18:21:18 +0100	[thread overview]
Message-ID: <xhsmhv8ud1ey9.mognet@vschneid.remote.csb> (raw)
In-Reply-To: <20220510163707.GO76023@worktop.programming.kicks-ass.net>

On 10/05/22 18:37, Peter Zijlstra wrote:
> On Tue, May 10, 2022 at 08:47:45AM -0700, Yury Norov wrote:
>> sched_core_cpu_starting() and sched_core_cpu_deactivate() implement
>> opencoded cpumask_any_but(). Fix it.
>>
>> CC: Ben Segall <bsegall@google.com>
>> CC: Daniel Bristot de Oliveira <bristot@redhat.com>
>> CC: Dietmar Eggemann <dietmar.eggemann@arm.com>
>> CC: Ingo Molnar <mingo@redhat.com>
>> CC: Juri Lelli <juri.lelli@redhat.com>
>> CC: Mel Gorman <mgorman@suse.de>
>> CC: Peter Zijlstra <peterz@infradead.org>
>> CC: Steven Rostedt <rostedt@goodmis.org>
>> CC: Valentin Schneider <vschneid@redhat.com>
>> CC: Vincent Guittot <vincent.guittot@linaro.org>
>> CC: linux-kernel@vger.kernel.org
>> Signed-off-by: Yury Norov <yury.norov@gmail.com>
>> ---
>>  kernel/sched/core.c | 33 +++++++++++++--------------------
>>  1 file changed, 13 insertions(+), 20 deletions(-)
>>
>> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
>> index f5ebc392493d..9700001948d0 100644
>> --- a/kernel/sched/core.c
>> +++ b/kernel/sched/core.c
>> @@ -6125,7 +6125,7 @@ static void queue_core_balance(struct rq *rq)
>>  static void sched_core_cpu_starting(unsigned int cpu)
>>  {
>>      const struct cpumask *smt_mask = cpu_smt_mask(cpu);
>> -	struct rq *rq = cpu_rq(cpu), *core_rq = NULL;
>> +	struct rq *rq = cpu_rq(cpu), *core_rq;
>>      unsigned long flags;
>>      int t;
>>
>> @@ -6138,19 +6138,16 @@ static void sched_core_cpu_starting(unsigned int cpu)
>>              goto unlock;
>>
>>      /* find the leader */
>> -	for_each_cpu(t, smt_mask) {
>> -		if (t == cpu)
>> -			continue;
>> -		rq = cpu_rq(t);
>> -		if (rq->core == rq) {
>> -			core_rq = rq;
>> -			break;
>> -		}
>> -	}
>> +	t = cpumask_any_but(smt_mask, cpu);
>> +	if (t >= nr_cpu_ids)
>> +		goto unlock;
>>
>> -	if (WARN_ON_ONCE(!core_rq)) /* whoopsie */
>> +	rq = cpu_rq(t);
>> +	if (WARN_ON_ONCE(rq->core != rq)) /* whoopsie */
>>              goto unlock;
>>
>> +	core_rq = rq;
>> +
>>      /* install and validate core_rq */
>>      for_each_cpu(t, smt_mask) {
>>              rq = cpu_rq(t);
>
> I don't think this is equivalent. Imagine SMT4, with:
>
>   rqN->core_rq = rq0
>
> Now, further suppose smt0-2 are online and we're about to online smt3.
> Then t above is free to be smt2, which then results in insta triggering:
>
> +	if (WARN_ON_ONCE(rq->core != rq)) /* whoopsie */
>
> You seem to have lost how the first loop searches for rq->core.
>

cpumask_any() is actually cpumask_first(), so t should be smt0 in that
case. However, if for some reason rq->core isn't the first online CPU in
smt_mask \ {cpu} (which I think can happen if you offline smt0-1 then
re-online smt0), then yes that splats.

> Please, be more careful. Also, all of this is super cold path don't
> bother with optimizations. Much of the patches you have in this series
> fall under that.

I tend to agree, I do like the cpumask_weight_eq() stuff because it's a low
hanging fruit and can even be autopatched with coccinelle, but the
open-coded stuff in cold paths isn't as relevant (nor as obvious as it may
look :)).


  reply	other threads:[~2022-05-10 17:21 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-10 15:47 [PATCH 00/21] add coccinelle scripts for {bitmap,cpumask,nodes}_empty() Yury Norov
2022-05-10 15:47 ` [PATCH 01/22] introduce bitmap.cocci Yury Norov
2022-05-10 15:47 ` [PATCH 02/22] introduce cpumask.cocci Yury Norov
2022-05-10 15:47 ` [PATCH 03/22] introduce nodemask.cocci Yury Norov
2022-05-10 15:47 ` [PATCH 04/22] ice: use bitmap_empty() in ice_vf_has_no_qs_ena() Yury Norov
2022-05-10 15:47 ` [PATCH 05/22] iio: replace bitmap_weight with bitmap_weitght_{eq,le} where appropriate Yury Norov
2022-05-14 15:53   ` Jonathan Cameron
2022-05-14 16:31     ` Joe Perches
2022-05-15 16:40       ` Jonathan Cameron
2022-05-10 15:47 ` [PATCH 06/22] octeontx2: use bitmap_empty() instead of bitmap_weight() Yury Norov
2022-05-10 21:31   ` Jakub Kicinski
2022-05-10 15:47 ` [PATCH 07/22] risc-v: replace bitmap_weight with bitmap_empty in riscv_fill_hwcap() Yury Norov
2022-05-10 16:31   ` Anup Patel
2022-05-10 15:47 ` [PATCH 08/22] bitops: introduce MANY_BITS() macro Yury Norov
2022-05-10 16:50   ` Alexei Starovoitov
2022-05-10 17:54     ` David Laight
2022-05-10 19:11       ` Yury Norov
2022-05-11 10:59         ` Rasmus Villemoes
2022-05-10 17:57   ` Max Filippov
2022-05-10 19:16     ` Yury Norov
2022-05-11  4:55       ` Max Filippov
2022-05-10 15:47 ` [PATCH 09/22] qed: replace bitmap_weight() with MANY_BITS() Yury Norov
2022-05-10 15:47 ` [PATCH 10/22] net/mlx5e: simplify mlx5e_set_fecparam() Yury Norov
2022-05-10 15:47 ` [PATCH 11/22] KVM: x86: hyper-v: replace bitmap_weight() with hweight64() Yury Norov
2022-05-16 13:08   ` Vitaly Kuznetsov
2022-05-22 14:53   ` Guenter Roeck
2022-05-22 17:39     ` Yury Norov
2022-05-10 15:47 ` [PATCH 12/22] ia64: cleanup remove_siblinginfo() Yury Norov
2022-05-10 22:33   ` Andrew Morton
2022-05-10 15:47 ` [PATCH 13/22] x86: smp: move cpumask_weight() out of for-loop in remove_siblinginfo Yury Norov
2022-05-11  9:47   ` Thomas Gleixner
2022-05-10 15:47 ` [PATCH 14/22] x86: smp: use cpumask_weight_eq() " Yury Norov
2022-05-10 15:47 ` [PATCH 15/22] net/mlx5: use cpumask_weight_gt() in irq_pool_request_irq() Yury Norov
2022-05-10 15:47 ` [PATCH 16/22] x86/tsc: use cpumask_weight_gt() in loop_timeout() Yury Norov
2022-05-10 15:47 ` [PATCH 17/22] sched/core: fix opencoded cpumask_any_but() Yury Norov
2022-05-10 16:37   ` Peter Zijlstra
2022-05-10 17:21     ` Valentin Schneider [this message]
2022-05-10 15:47 ` [PATCH 18/22] sched/core: remove unneeded cpumask_weight() in sched_core_cpu_{starting,deactivate} Yury Norov
2022-05-10 15:47 ` [PATCH 19/22] sched/core: replace cpumask_weight() with cpumask_weight_eq() where appropriate Yury Norov
2022-05-10 15:47 ` [PATCH 20/22] sched/topology: " Yury Norov
2022-05-10 15:47 ` [PATCH 21/22] cpufreq: use cpumask_weight_gt() in policy_is_shared() Yury Norov
2022-05-11  3:16   ` Viresh Kumar
2022-05-10 15:47 ` [PATCH 22/22] clockevents: use cpumask_weight_eq() in tick_cleanup_dead_cpu() Yury Norov
2022-05-11  8:18   ` Thomas Gleixner

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=xhsmhv8ud1ey9.mognet@vschneid.remote.csb \
    --to=vschneid@redhat.com \
    --cc=David.Laight@ACULAB.COM \
    --cc=Julia.Lawall@inria.fr \
    --cc=Matti.Vaittinen@fi.rohmeurope.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=bristot@redhat.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=joe@perches.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=mirq-linux@rere.qmqm.pl \
    --cc=nicolas.palix@imag.fr \
    --cc=npiggin@gmail.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=vincent.guittot@linaro.org \
    --cc=yury.norov@gmail.com \
    /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®