From: Johannes Weiner <hannes@cmpxchg.org>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Suren Baghdasaryan <surenb@google.com>,
mingo@redhat.com, juri.lelli@redhat.com,
vincent.guittot@linaro.org, dietmar.eggemann@arm.com,
rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de,
bristot@redhat.com, matthias.bgg@gmail.com, minchan@google.com,
timmurray@google.com, yt.chang@mediatek.com,
wenju.xu@mediatek.com, jonathan.jmchen@mediatek.com,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org, kernel-team@android.com,
SH Chen <show-hong.chen@mediatek.com>
Subject: Re: [PATCH v2 1/1] psi: stop relying on timer_pending for poll_work rescheduling
Date: Thu, 1 Jul 2021 12:39:38 -0400 [thread overview]
Message-ID: <YN3vyvoDwSUepM18@cmpxchg.org> (raw)
In-Reply-To: <YN2DsLlE+WtxK6K9@hirez.programming.kicks-ass.net>
On Thu, Jul 01, 2021 at 10:58:24AM +0200, Peter Zijlstra wrote:
> On Wed, Jun 30, 2021 at 01:51:51PM -0700, Suren Baghdasaryan wrote:
> > + /* cmpxchg should be called even when !force to set poll_scheduled */
> > + if (atomic_cmpxchg(&group->poll_scheduled, 0, 1) && !force)
> > return;
>
> Why is that a cmpxchg() ?
I now realize you had already pointed that out, but I dismissed it in
the context of poll_lock not being always taken after all.
But you're right, cmpxchg indeed seems inappropriate. xchg will do
just fine for this binary toggle.
When it comes to ordering, looking at it again, I think we actually
need ordering here that the seqcount doesn't provide. We have:
timer:
scheduled = 0
smp_rmb()
x = state
scheduler:
state = y
smp_wmb()
if xchg(scheduled, 1) == 0
mod_timer()
Again, the requirement is that when the scheduler sees the timer as
already or still pending, the timer must observe its state updates -
otherwise we miss poll events.
The seqcount provides the wmb and rmb, but the scheduler-side read of
@scheduled mustn't be reordered before the write to @state. Likewise,
the timer-side read of @state also mustn't occur before the write to
@scheduled.
AFAICS this is broken, not just in the patch, but also in the current
code when timer_pending() on the scheduler side gets reordered. (Not
sure if timer reading state can be reordered before the detach_timer()
of its own expiration, but I don't see full ordering between them.)
So it seems to me we need the ordered atomic_xchg() on the scheduler
side, and on the timer side an smp_mb() after we set scheduled to 0.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2021-07-01 16:41 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-30 20:51 [PATCH v2 1/1] psi: stop relying on timer_pending for poll_work rescheduling Suren Baghdasaryan
2021-06-30 22:04 ` Johannes Weiner
2021-07-01 8:58 ` Peter Zijlstra
2021-07-01 16:09 ` Suren Baghdasaryan
2021-07-01 16:12 ` Peter Zijlstra
2021-07-01 16:28 ` Suren Baghdasaryan
2021-07-02 9:28 ` Peter Zijlstra
2021-07-02 15:49 ` Suren Baghdasaryan
2021-07-07 2:42 ` Suren Baghdasaryan
2021-07-01 16:39 ` Johannes Weiner [this message]
2021-07-01 17:46 ` Suren Baghdasaryan
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=YN3vyvoDwSUepM18@cmpxchg.org \
--to=hannes@cmpxchg.org \
--cc=bristot@redhat.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=jonathan.jmchen@mediatek.com \
--cc=juri.lelli@redhat.com \
--cc=kernel-team@android.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=matthias.bgg@gmail.com \
--cc=mgorman@suse.de \
--cc=minchan@google.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=show-hong.chen@mediatek.com \
--cc=surenb@google.com \
--cc=timmurray@google.com \
--cc=vincent.guittot@linaro.org \
--cc=wenju.xu@mediatek.com \
--cc=yt.chang@mediatek.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;
as well as URLs for NNTP newsgroup(s).