From: Peter Zijlstra <peterz@infradead.org>
To: Patrick Bellasi <patrick.bellasi@matbug.net>
Cc: Yun Hsiang <hsiang023167@gmail.com>,
dietmar.eggemann@arm.com, linux-kernel@vger.kernel.org,
qais.yousef@arm.com, kernel test robot <lkp@intel.com>
Subject: Re: [PATCH v5 1/1] sched/uclamp: add SCHED_FLAG_UTIL_CLAMP_RESET flag to reset uclamp
Date: Tue, 10 Nov 2020 13:18:17 +0100 [thread overview]
Message-ID: <20201110121817.GF2594@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <87blgag4an.derkling@matbug.net>
On Fri, Nov 06, 2020 at 11:36:48AM +0100, Patrick Bellasi wrote:
> > +static int uclamp_reset(enum uclamp_id clamp_id, unsigned long flags)
> > +{
> > + /* No _UCLAMP_RESET flag set: do not reset */
> > + if (!(flags & SCHED_FLAG_UTIL_CLAMP_RESET))
> > + return false;
> > +
> > + /* Only _UCLAMP_RESET flag set: reset both clamps */
> > + if (!(flags & (SCHED_FLAG_UTIL_CLAMP_MIN | SCHED_FLAG_UTIL_CLAMP_MAX)))
> > + return true;
> > +
> > + /* Both _UCLAMP_RESET and _UCLAMP_MIN flags are set: reset only min */
> > + if ((flags & SCHED_FLAG_UTIL_CLAMP_MIN) && clamp_id == UCLAMP_MIN)
> > + return true;
> > +
> > + /* Both _UCLAMP_RESET and _UCLAMP_MAX flags are set: reset only max */
> > + if ((flags & SCHED_FLAG_UTIL_CLAMP_MAX) && clamp_id == UCLAMP_MAX)
> > + return true;
> > +
> > + return false;
>
> I was suggesting maybe we need READ_ONCE() in the if above but did not
> addressed previous Dietmar's question [2] on why.
>
> The function above has a correct semantics only when the ordering of the
> if statement is strictly observed.
>
> Now, since we don't have any data dependency on the multiple if cases,
> are we sure an overzealous compiler will never come up with some
> "optimized reordering" of the checks required?
>
> IOW, if the compiler could scramble the checks on an optimization, we
> would get a wrong semantics which is also very difficult do debug.
> Hence the idea to use READ_ONCE, to both tell the compiler to not
> even attempt reordering those checks and also to better document the
> code about the importance of the ordering on those checks.
>
> Is now more clear? Does that makes sense?
I don't think the compiler is allowed to do as you fear. Specifically it
cannot move the first branch down because that would change the meaning
of this function and affect observable behaviour even in the traditional
single-threaded environment.
next prev parent reply other threads:[~2020-11-10 12:18 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-03 2:37 [PATCH v5 1/1] sched/uclamp: add SCHED_FLAG_UTIL_CLAMP_RESET flag to reset uclamp Yun Hsiang
2020-11-03 13:46 ` Qais Yousef
2020-11-03 13:48 ` Qais Yousef
2020-11-04 9:45 ` Dietmar Eggemann
2020-11-07 18:24 ` Yun Hsiang
2020-11-06 10:36 ` Patrick Bellasi
2020-11-07 19:15 ` Yun Hsiang
2020-11-09 13:41 ` Qais Yousef
2020-11-10 12:18 ` Peter Zijlstra [this message]
2020-11-10 12:21 ` Peter Zijlstra
2020-11-11 17:41 ` Dietmar Eggemann
2020-11-11 18:04 ` Peter Zijlstra
2020-11-12 5:44 ` Yun Hsiang
2020-11-12 13:05 ` Dietmar Eggemann
2020-11-12 14:41 ` Qais Yousef
2020-11-12 16:01 ` Dietmar Eggemann
2020-11-13 11:45 ` Dietmar Eggemann
2020-11-13 12:26 ` Qais Yousef
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=20201110121817.GF2594@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=dietmar.eggemann@arm.com \
--cc=hsiang023167@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lkp@intel.com \
--cc=patrick.bellasi@matbug.net \
--cc=qais.yousef@arm.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