From: Peter Zijlstra <peterz@infradead.org>
To: Suren Baghdasaryan <surenb@google.com>
Cc: "Johannes Weiner" <hannes@cmpxchg.org>,
"Ingo Molnar" <mingo@redhat.com>,
"Juri Lelli" <juri.lelli@redhat.com>,
"Vincent Guittot" <vincent.guittot@linaro.org>,
"Dietmar Eggemann" <dietmar.eggemann@arm.com>,
"Steven Rostedt" <rostedt@goodmis.org>,
"Benjamin Segall" <bsegall@google.com>,
"Mel Gorman" <mgorman@suse.de>,
"Daniel Bristot de Oliveira" <bristot@redhat.com>,
matthias.bgg@gmail.com, "Minchan Kim" <minchan@google.com>,
"Tim Murray" <timmurray@google.com>,
"YT Chang" <yt.chang@mediatek.com>,
"Wenju Xu (许文举)" <wenju.xu@mediatek.com>,
"Jonathan JMChen (陳家明)" <jonathan.jmchen@mediatek.com>,
LKML <linux-kernel@vger.kernel.org>,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org,
kernel-team <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: Fri, 2 Jul 2021 11:28:05 +0200 [thread overview]
Message-ID: <YN7cJZOZzjYJFClR@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <CAJuCfpFKDhcgjU=MGsz+JuetrWvYCe0EL3FMp91zopH+8T=mMQ@mail.gmail.com>
On Thu, Jul 01, 2021 at 09:28:04AM -0700, Suren Baghdasaryan wrote:
> On Thu, Jul 1, 2021 at 9:12 AM Peter Zijlstra <peterz@infradead.org> wrote:
> >
> > On Thu, Jul 01, 2021 at 09:09:25AM -0700, Suren Baghdasaryan wrote:
> > > On Thu, Jul 1, 2021 at 1:59 AM Peter Zijlstra <peterz@infradead.org> 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() ?
> > >
> > > We want to set poll_scheduled and proceed with rescheduling the timer
> > > unless it's already scheduled, so cmpxchg helps us to make that
> > > decision atomically. Or did I misunderstand your question?
> >
> > What's wrong with: atomic_xchg(&group->poll_scheduled, 1) ?
>
> Yes, since poll_scheduled can be only 0 or 1 atomic_xchg should work
> fine here. Functionally equivalent but I assume atomic_xchg() is more
> efficient due to no comparison.
Mostly conceptually simpler; the cmpxchg-on-0 makes that you have to
check if there's ever any state outside of {0,1}. The xchg() thing is
the classical test-and-set pattern.
On top of all that, the cmpxchg() can fail, which brings ordering
issues.
Typically, I think, you want to ensure that everything that happens
before psi_schedule_poll_work() is visible to the work when it runs
(also see Johannes' email). In case poll_scheduled is already 1, the
cmpxchg will fail and *NOT* provide that ordering. Meaning the work
might not observe the latest changes. xchg() doesn't have this subtlety.
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek
WARNING: multiple messages have this Message-ID (diff)
From: Peter Zijlstra <peterz@infradead.org>
To: Suren Baghdasaryan <surenb@google.com>
Cc: "Johannes Weiner" <hannes@cmpxchg.org>,
"Ingo Molnar" <mingo@redhat.com>,
"Juri Lelli" <juri.lelli@redhat.com>,
"Vincent Guittot" <vincent.guittot@linaro.org>,
"Dietmar Eggemann" <dietmar.eggemann@arm.com>,
"Steven Rostedt" <rostedt@goodmis.org>,
"Benjamin Segall" <bsegall@google.com>,
"Mel Gorman" <mgorman@suse.de>,
"Daniel Bristot de Oliveira" <bristot@redhat.com>,
matthias.bgg@gmail.com, "Minchan Kim" <minchan@google.com>,
"Tim Murray" <timmurray@google.com>,
"YT Chang" <yt.chang@mediatek.com>,
"Wenju Xu (许文举)" <wenju.xu@mediatek.com>,
"Jonathan JMChen (陳家明)" <jonathan.jmchen@mediatek.com>,
LKML <linux-kernel@vger.kernel.org>,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org,
kernel-team <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: Fri, 2 Jul 2021 11:28:05 +0200 [thread overview]
Message-ID: <YN7cJZOZzjYJFClR@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <CAJuCfpFKDhcgjU=MGsz+JuetrWvYCe0EL3FMp91zopH+8T=mMQ@mail.gmail.com>
On Thu, Jul 01, 2021 at 09:28:04AM -0700, Suren Baghdasaryan wrote:
> On Thu, Jul 1, 2021 at 9:12 AM Peter Zijlstra <peterz@infradead.org> wrote:
> >
> > On Thu, Jul 01, 2021 at 09:09:25AM -0700, Suren Baghdasaryan wrote:
> > > On Thu, Jul 1, 2021 at 1:59 AM Peter Zijlstra <peterz@infradead.org> 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() ?
> > >
> > > We want to set poll_scheduled and proceed with rescheduling the timer
> > > unless it's already scheduled, so cmpxchg helps us to make that
> > > decision atomically. Or did I misunderstand your question?
> >
> > What's wrong with: atomic_xchg(&group->poll_scheduled, 1) ?
>
> Yes, since poll_scheduled can be only 0 or 1 atomic_xchg should work
> fine here. Functionally equivalent but I assume atomic_xchg() is more
> efficient due to no comparison.
Mostly conceptually simpler; the cmpxchg-on-0 makes that you have to
check if there's ever any state outside of {0,1}. The xchg() thing is
the classical test-and-set pattern.
On top of all that, the cmpxchg() can fail, which brings ordering
issues.
Typically, I think, you want to ensure that everything that happens
before psi_schedule_poll_work() is visible to the work when it runs
(also see Johannes' email). In case poll_scheduled is already 1, the
cmpxchg will fail and *NOT* provide that ordering. Meaning the work
might not observe the latest changes. xchg() doesn't have this subtlety.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
WARNING: multiple messages have this Message-ID (diff)
From: Peter Zijlstra <peterz@infradead.org>
To: Suren Baghdasaryan <surenb@google.com>
Cc: "Johannes Weiner" <hannes@cmpxchg.org>,
"Ingo Molnar" <mingo@redhat.com>,
"Juri Lelli" <juri.lelli@redhat.com>,
"Vincent Guittot" <vincent.guittot@linaro.org>,
"Dietmar Eggemann" <dietmar.eggemann@arm.com>,
"Steven Rostedt" <rostedt@goodmis.org>,
"Benjamin Segall" <bsegall@google.com>,
"Mel Gorman" <mgorman@suse.de>,
"Daniel Bristot de Oliveira" <bristot@redhat.com>,
matthias.bgg@gmail.com, "Minchan Kim" <minchan@google.com>,
"Tim Murray" <timmurray@google.com>,
"YT Chang" <yt.chang@mediatek.com>,
"Wenju Xu (许文举)" <wenju.xu@mediatek.com>,
"Jonathan JMChen (陳家明)" <jonathan.jmchen@mediatek.com>,
LKML <linux-kernel@vger.kernel.org>,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org,
kernel-team <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: Fri, 2 Jul 2021 11:28:05 +0200 [thread overview]
Message-ID: <YN7cJZOZzjYJFClR@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <CAJuCfpFKDhcgjU=MGsz+JuetrWvYCe0EL3FMp91zopH+8T=mMQ@mail.gmail.com>
On Thu, Jul 01, 2021 at 09:28:04AM -0700, Suren Baghdasaryan wrote:
> On Thu, Jul 1, 2021 at 9:12 AM Peter Zijlstra <peterz@infradead.org> wrote:
> >
> > On Thu, Jul 01, 2021 at 09:09:25AM -0700, Suren Baghdasaryan wrote:
> > > On Thu, Jul 1, 2021 at 1:59 AM Peter Zijlstra <peterz@infradead.org> 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() ?
> > >
> > > We want to set poll_scheduled and proceed with rescheduling the timer
> > > unless it's already scheduled, so cmpxchg helps us to make that
> > > decision atomically. Or did I misunderstand your question?
> >
> > What's wrong with: atomic_xchg(&group->poll_scheduled, 1) ?
>
> Yes, since poll_scheduled can be only 0 or 1 atomic_xchg should work
> fine here. Functionally equivalent but I assume atomic_xchg() is more
> efficient due to no comparison.
Mostly conceptually simpler; the cmpxchg-on-0 makes that you have to
check if there's ever any state outside of {0,1}. The xchg() thing is
the classical test-and-set pattern.
On top of all that, the cmpxchg() can fail, which brings ordering
issues.
Typically, I think, you want to ensure that everything that happens
before psi_schedule_poll_work() is visible to the work when it runs
(also see Johannes' email). In case poll_scheduled is already 1, the
cmpxchg will fail and *NOT* provide that ordering. Meaning the work
might not observe the latest changes. xchg() doesn't have this subtlety.
next prev parent reply other threads:[~2021-07-02 9:28 UTC|newest]
Thread overview: 33+ 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 20:51 ` Suren Baghdasaryan
2021-06-30 20:51 ` Suren Baghdasaryan
2021-06-30 22:04 ` Johannes Weiner
2021-06-30 22:04 ` Johannes Weiner
2021-06-30 22:04 ` Johannes Weiner
2021-07-01 8:58 ` Peter Zijlstra
2021-07-01 8:58 ` Peter Zijlstra
2021-07-01 8:58 ` Peter Zijlstra
2021-07-01 16:09 ` Suren Baghdasaryan
2021-07-01 16:09 ` Suren Baghdasaryan
2021-07-01 16:09 ` Suren Baghdasaryan
2021-07-01 16:12 ` Peter Zijlstra
2021-07-01 16:12 ` Peter Zijlstra
2021-07-01 16:12 ` Peter Zijlstra
2021-07-01 16:28 ` Suren Baghdasaryan
2021-07-01 16:28 ` Suren Baghdasaryan
2021-07-01 16:28 ` Suren Baghdasaryan
2021-07-02 9:28 ` Peter Zijlstra [this message]
2021-07-02 9:28 ` Peter Zijlstra
2021-07-02 9:28 ` Peter Zijlstra
2021-07-02 15:49 ` Suren Baghdasaryan
2021-07-02 15:49 ` Suren Baghdasaryan
2021-07-02 15:49 ` Suren Baghdasaryan
2021-07-07 2:42 ` Suren Baghdasaryan
2021-07-07 2:42 ` Suren Baghdasaryan
2021-07-07 2:42 ` Suren Baghdasaryan
2021-07-01 16:39 ` Johannes Weiner
2021-07-01 16:39 ` Johannes Weiner
2021-07-01 16:39 ` Johannes Weiner
2021-07-01 17:46 ` Suren Baghdasaryan
2021-07-01 17:46 ` Suren Baghdasaryan
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=YN7cJZOZzjYJFClR@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=bristot@redhat.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=hannes@cmpxchg.org \
--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=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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.