From: Steven Rostedt <rostedt@goodmis.org>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Dheeraj Reddy Jonnalagadda <dheeraj.linuxdev@gmail.com>,
mingo@redhat.com, juri.lelli@redhat.com,
vincent.guittot@linaro.org, linux-kernel@vger.kernel.org,
dietmar.eggemann@arm.com, bsegall@google.com, mgorman@suse.de,
vschneid@redhat.com
Subject: Re: [PATCH sched-next] sched/cputime: Fix unused value issue
Date: Tue, 19 Nov 2024 08:08:53 -0500 [thread overview]
Message-ID: <20241119080853.58cbca4f@gandalf.local.home> (raw)
In-Reply-To: <20241119083650.GD11903@noisy.programming.kicks-ass.net>
On Tue, 19 Nov 2024 09:36:50 +0100
Peter Zijlstra <peterz@infradead.org> wrote:
> > The above adds more branches than just having:
> >
> > if (stime == 0)
> > goto update;
> >
> > if (utime == 0) {
> > stime = rtime;
> > goto update;
> > }
> >
> > (or's "||" are branches)
> >
> > And the latter is much easier to read!
> >
> > Just fix the issue. Don't try to be clever about it.
>
> There is nothing to fix. Yes there is an unused assignment, but the
> compiler is free to elide it (and it does).
This has nothing to do with the compiler optimizing it.
>
> Keep the code as is, it is simple and straight-forward.
I disagree from a stability and understandability point of view. Why is
utime assigned? Here's the full context:
if (stime == 0) {
utime = rtime; <<<---- Assigns utime
goto update; <<<---- Jumps to "update"
}
if (utime == 0) {
stime = rtime;
goto update;
}
stime = mul_u64_u64_div_u64(stime, rtime, stime + utime);
/*
* Because mul_u64_u64_div_u64() can approximate on some
* achitectures; enforce the constraint that: a*b/(b+c) <= a.
*/
if (unlikely(stime > rtime))
stime = rtime;
update: <<<---- Jumped here
/*
* Make sure stime doesn't go backwards; this preserves monotonicity
* for utime because rtime is monotonic.
*
* utime_i+1 = rtime_i+1 - stime_i
* = rtime_i+1 - (rtime_i - utime_i)
* = (rtime_i+1 - rtime_i) + utime_i
* >= utime_i
*/
if (stime < prev->stime)
stime = prev->stime;
utime = rtime - stime; <<<---- reassigns utime
So the first assignment of "utime" is meaningless, or there's a bug here
that utime incorrectly had its value overwritten. If the first assignment
is meaningless, it leaves others still wondering if there is actually a bug
here, because they are wondering "why was utime assigned?".
-- Steve
prev parent reply other threads:[~2024-11-19 13:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-18 11:13 Dheeraj Reddy Jonnalagadda
2024-11-18 20:30 ` Steven Rostedt
2024-11-19 8:36 ` Peter Zijlstra
2024-11-19 13:08 ` Steven Rostedt [this message]
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=20241119080853.58cbca4f@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=bsegall@google.com \
--cc=dheeraj.linuxdev@gmail.com \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.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®