All of lore.kernel.org
 help / color / mirror / Atom feed
From: Leonard Crestez <leonard.crestez@nxp.com>
To: Frederic Weisbecker <frederic@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	"Paul E . McKenney" <paulmck@linux.vnet.ibm.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Viresh Kumar <viresh.kumar@linaro.org>,
	"linux-pm@vger.kernel.org" <linux-pm@vger.kernel.org>,
	Stephen Rothwell <sfr@canb.auug.org.au>
Subject: Re: [PATCH 3/4] irq_work: Slightly simplify IRQ_WORK_PENDING clearing
Date: Tue, 12 Nov 2019 20:27:05 +0000	[thread overview]
Message-ID: <VI1PR04MB70239C2E838B72C171CC62C7EE770@VI1PR04MB7023.eurprd04.prod.outlook.com> (raw)
In-Reply-To: 20191108160858.31665-4-frederic@kernel.org

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);
         }
  }

  parent reply	other threads:[~2019-11-12 20:27 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-08 16:08 [PATCH 0/4] irq_work: Fix ordering issue Frederic Weisbecker
2019-11-08 16:08 ` [PATCH 1/4] irq_work: Convert flags to atomic_t Frederic Weisbecker
2019-11-11  8:00   ` Ingo Molnar
2019-11-11 22:56     ` Frederic Weisbecker
2019-11-11  9:32   ` [tip: irq/core] " tip-bot2 for Frederic Weisbecker
2019-11-08 16:08 ` [PATCH 2/4] irq_work: Fix irq_work_claim() ordering Frederic Weisbecker
2019-11-11  7:20   ` Ingo Molnar
2019-11-11 23:17     ` Frederic Weisbecker
2019-11-11  9:32   ` [tip: irq/core] irq_work: Fix irq_work_claim() memory ordering tip-bot2 for Frederic Weisbecker
2019-11-08 16:08 ` [PATCH 3/4] irq_work: Slightly simplify IRQ_WORK_PENDING clearing Frederic Weisbecker
2019-11-11  9:32   ` [tip: irq/core] " tip-bot2 for Frederic Weisbecker
2019-11-12 20:27   ` Leonard Crestez [this message]
2019-11-13  0:22     ` [PATCH 3/4] " Frederic Weisbecker
2019-11-08 16:08 ` [RFC PATCH 4/4] irq_work: Weaken ordering in irq_work_run_list() Frederic Weisbecker
2019-11-11  8:43   ` Peter Zijlstra
2019-11-11 22:38     ` Frederic Weisbecker

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=VI1PR04MB70239C2E838B72C171CC62C7EE770@VI1PR04MB7023.eurprd04.prod.outlook.com \
    --to=leonard.crestez@nxp.com \
    --cc=frederic@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peterz@infradead.org \
    --cc=sfr@canb.auug.org.au \
    --cc=tglx@linutronix.de \
    --cc=viresh.kumar@linaro.org \
    /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.