* Re: [PATCH 3/4] irq_work: Slightly simplify IRQ_WORK_PENDING clearing [not found] ` <20191108160858.31665-4-frederic@kernel.org> @ 2019-11-12 20:27 ` Leonard Crestez 2019-11-13 0:22 ` Frederic Weisbecker 0 siblings, 1 reply; 2+ messages in thread From: Leonard Crestez @ 2019-11-12 20:27 UTC (permalink / raw) To: Frederic Weisbecker Cc: Peter Zijlstra, Ingo Molnar, LKML, Paul E . McKenney, Thomas Gleixner, Viresh Kumar, linux-pm@vger.kernel.org, Stephen Rothwell On 08.11.2019 18:09, Frederic Weisbecker wrote: > Instead of fetching the value of flags and perform an xchg() to clear > a bit, just use atomic_fetch_andnot() that is more suitable to do that > job in one operation while keeping the full ordering. > > Signed-off-by: Frederic Weisbecker <frederic@kernel.org> > Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com> > Cc: Thomas Gleixner <tglx@linutronix.de> > Cc: Peter Zijlstra <peterz@infradead.org> > Cc: Ingo Molnar <mingo@kernel.org> > --- > kernel/irq_work.c | 7 +++---- > 1 file changed, 3 insertions(+), 4 deletions(-) > > diff --git a/kernel/irq_work.c b/kernel/irq_work.c > index 255454a48346..49c53f80a13a 100644 > --- a/kernel/irq_work.c > +++ b/kernel/irq_work.c > @@ -34,7 +34,7 @@ static bool irq_work_claim(struct irq_work *work) > oflags = atomic_fetch_or(IRQ_WORK_CLAIMED, &work->flags); > /* > * If the work is already pending, no need to raise the IPI. > - * The pairing atomic_xchg() in irq_work_run() makes sure > + * The pairing atomic_fetch_andnot() in irq_work_run() makes sure > * everything we did before is visible. > */ > if (oflags & IRQ_WORK_PENDING) > @@ -135,7 +135,6 @@ static void irq_work_run_list(struct llist_head *list) > { > struct irq_work *work, *tmp; > struct llist_node *llnode; > - int flags; > > BUG_ON(!irqs_disabled()); > > @@ -144,6 +143,7 @@ static void irq_work_run_list(struct llist_head *list) > > llnode = llist_del_all(list); > llist_for_each_entry_safe(work, tmp, llnode, llnode) { > + int flags; > /* > * Clear the PENDING bit, after this point the @work > * can be re-used. > @@ -151,8 +151,7 @@ static void irq_work_run_list(struct llist_head *list) > * to claim that work don't rely on us to handle their data > * while we are in the middle of the func. > */ > - flags = atomic_read(&work->flags) & ~IRQ_WORK_PENDING; > - atomic_xchg(&work->flags, flags); > + flags = atomic_fetch_andnot(IRQ_WORK_PENDING, &work->flags); > > work->func(work); > /* This breaks switching between cpufreq governors in linux-next on arm64 and various other stuff. The fix in this email doesn't compile: https://lkml.org/lkml/2019/11/12/622 I assume you meant "&= ~" instead of "~=", this seems to work: diff --git a/kernel/irq_work.c b/kernel/irq_work.c index 49c53f80a13a..828cc30774bc 100644 --- a/kernel/irq_work.c +++ b/kernel/irq_work.c @@ -156,10 +156,11 @@ static void irq_work_run_list(struct llist_head *list) work->func(work); /* * Clear the BUSY bit and return to the free state if * no-one else claimed it meanwhile. */ + flags &= ~IRQ_WORK_PENDING; (void)atomic_cmpxchg(&work->flags, flags, flags & ~IRQ_WORK_BUSY); } } ^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 3/4] irq_work: Slightly simplify IRQ_WORK_PENDING clearing 2019-11-12 20:27 ` [PATCH 3/4] irq_work: Slightly simplify IRQ_WORK_PENDING clearing Leonard Crestez @ 2019-11-13 0:22 ` Frederic Weisbecker 0 siblings, 0 replies; 2+ messages in thread From: Frederic Weisbecker @ 2019-11-13 0:22 UTC (permalink / raw) To: Leonard Crestez Cc: Peter Zijlstra, Ingo Molnar, LKML, Paul E . McKenney, Thomas Gleixner, Viresh Kumar, linux-pm@vger.kernel.org, Stephen Rothwell On Tue, Nov 12, 2019 at 08:27:05PM +0000, Leonard Crestez wrote: > On 08.11.2019 18:09, Frederic Weisbecker wrote: > > Instead of fetching the value of flags and perform an xchg() to clear > > a bit, just use atomic_fetch_andnot() that is more suitable to do that > > job in one operation while keeping the full ordering. > > > > Signed-off-by: Frederic Weisbecker <frederic@kernel.org> > > Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com> > > Cc: Thomas Gleixner <tglx@linutronix.de> > > Cc: Peter Zijlstra <peterz@infradead.org> > > Cc: Ingo Molnar <mingo@kernel.org> > > --- > > kernel/irq_work.c | 7 +++---- > > 1 file changed, 3 insertions(+), 4 deletions(-) > > > > diff --git a/kernel/irq_work.c b/kernel/irq_work.c > > index 255454a48346..49c53f80a13a 100644 > > --- a/kernel/irq_work.c > > +++ b/kernel/irq_work.c > > @@ -34,7 +34,7 @@ static bool irq_work_claim(struct irq_work *work) > > oflags = atomic_fetch_or(IRQ_WORK_CLAIMED, &work->flags); > > /* > > * If the work is already pending, no need to raise the IPI. > > - * The pairing atomic_xchg() in irq_work_run() makes sure > > + * The pairing atomic_fetch_andnot() in irq_work_run() makes sure > > * everything we did before is visible. > > */ > > if (oflags & IRQ_WORK_PENDING) > > @@ -135,7 +135,6 @@ static void irq_work_run_list(struct llist_head *list) > > { > > struct irq_work *work, *tmp; > > struct llist_node *llnode; > > - int flags; > > > > BUG_ON(!irqs_disabled()); > > > > @@ -144,6 +143,7 @@ static void irq_work_run_list(struct llist_head *list) > > > > llnode = llist_del_all(list); > > llist_for_each_entry_safe(work, tmp, llnode, llnode) { > > + int flags; > > /* > > * Clear the PENDING bit, after this point the @work > > * can be re-used. > > @@ -151,8 +151,7 @@ static void irq_work_run_list(struct llist_head *list) > > * to claim that work don't rely on us to handle their data > > * while we are in the middle of the func. > > */ > > - flags = atomic_read(&work->flags) & ~IRQ_WORK_PENDING; > > - atomic_xchg(&work->flags, flags); > > + flags = atomic_fetch_andnot(IRQ_WORK_PENDING, &work->flags); > > > > work->func(work); > > /* > > This breaks switching between cpufreq governors in linux-next on arm64 > and various other stuff. The fix in this email doesn't compile: > > https://lkml.org/lkml/2019/11/12/622 > > I assume you meant "&= ~" instead of "~=", this seems to work: Indeed, duh again! I still think that ~= would be nice to have though... Thanks! > > diff --git a/kernel/irq_work.c b/kernel/irq_work.c > index 49c53f80a13a..828cc30774bc 100644 > --- a/kernel/irq_work.c > +++ b/kernel/irq_work.c > @@ -156,10 +156,11 @@ static void irq_work_run_list(struct llist_head *list) > work->func(work); > /* > * Clear the BUSY bit and return to the free state if > * no-one else claimed it meanwhile. > */ > + flags &= ~IRQ_WORK_PENDING; > (void)atomic_cmpxchg(&work->flags, flags, flags & > ~IRQ_WORK_BUSY); > } > } ^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-11-13 0:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20191108160858.31665-1-frederic@kernel.org>
[not found] ` <20191108160858.31665-4-frederic@kernel.org>
2019-11-12 20:27 ` [PATCH 3/4] irq_work: Slightly simplify IRQ_WORK_PENDING clearing Leonard Crestez
2019-11-13 0:22 ` Frederic Weisbecker
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).