All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: linux-kernel@vger.kernel.org, Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [PATCH v2 3/4] irq_work: Handle some irq_work in a per-CPU thread on PREEMPT_RT
Date: Thu, 7 Oct 2021 10:50:23 +0200	[thread overview]
Message-ID: <20211007085023.GP174703@worktop.programming.kicks-ass.net> (raw)
In-Reply-To: <20211006111852.1514359-4-bigeasy@linutronix.de>

On Wed, Oct 06, 2021 at 01:18:51PM +0200, Sebastian Andrzej Siewior wrote:
> @@ -104,7 +141,24 @@ bool irq_work_queue_on(struct irq_work *work, int cpu)
>  	if (cpu != smp_processor_id()) {
>  		/* Arch remote IPI send/receive backend aren't NMI safe */
>  		WARN_ON_ONCE(in_nmi());
> -		__smp_call_single_queue(cpu, &work->node.llist);
> +
> +		/*
> +		 * On PREEMPT_RT the items which are not marked as
> +		 * IRQ_WORK_HARD_IRQ are added to the lazy list and a HARD work
> +		 * item is used on the remote CPU to wake the thread.
> +		 */
> +		if (IS_ENABLED(CONFIG_PREEMPT_RT) &&
> +		    !(atomic_read(&work->node.a_flags) & IRQ_WORK_HARD_IRQ) &&
> +		    llist_add(&work->node.llist, &per_cpu(lazy_list, cpu))) {

So if the llist not empty, we'll fail here, and go to the else branch

> +			struct irq_work *wake_work;
> +
> +			wake_work = &per_cpu(irq_work_pending, cpu);
> +			if (irq_work_claim(wake_work))
> +				__smp_call_single_queue(cpu,
> +							&wake_work->node.llist);
> +		} else {

And do this,.. that seems wrong.

> +			__smp_call_single_queue(cpu, &work->node.llist);
> +		}
>  	} else {
>  		__irq_work_queue_local(work);
>  	}

How's this instead?

(work rename due to there already being a percpu variable of that same
name on a number or archs, per 0day)


Index: linux-2.6/kernel/irq_work.c
===================================================================
--- linux-2.6.orig/kernel/irq_work.c
+++ linux-2.6/kernel/irq_work.c
@@ -39,7 +39,7 @@ static void irq_work_wake(struct irq_wor
 	wake_irq_workd();
 }
 
-static DEFINE_PER_CPU(struct irq_work, irq_work_pending) =
+static DEFINE_PER_CPU(struct irq_work, irq_work_wakeup) =
 	IRQ_WORK_INIT_HARD(irq_work_wake);
 
 static int irq_workd_should_run(unsigned int cpu)
@@ -148,20 +148,21 @@ bool irq_work_queue_on(struct irq_work *
 		 * item is used on the remote CPU to wake the thread.
 		 */
 		if (IS_ENABLED(CONFIG_PREEMPT_RT) &&
-		    !(atomic_read(&work->node.a_flags) & IRQ_WORK_HARD_IRQ) &&
-		    llist_add(&work->node.llist, &per_cpu(lazy_list, cpu))) {
-			struct irq_work *wake_work;
-
-			wake_work = &per_cpu(irq_work_pending, cpu);
-			if (irq_work_claim(wake_work))
-				__smp_call_single_queue(cpu,
-							&wake_work->node.llist);
-		} else {
-			__smp_call_single_queue(cpu, &work->node.llist);
+		    !(atomic_read(&work->node.a_flags) & IRQ_WORK_HARD_IRQ)) {
+
+			if (!llist_add(&work->node.llist, &per_cpu(lazy_list, cpu)))
+				goto out;
+
+			work = &per_cpu(irq_work_wakeup, cpu);
+			if (!irq_work_claim(wake_work))
+				goto out;
 		}
+
+		__smp_call_single_queue(cpu, &work->node.llist);
 	} else {
 		__irq_work_queue_local(work);
 	}
+out:
 	preempt_enable();
 
 	return true;

  parent reply	other threads:[~2021-10-07  8:50 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-06 11:18 [PATCH v2 0/4] irq_work: PREEMPT_RT bits Sebastian Andrzej Siewior
2021-10-06 11:18 ` [PATCH v2 1/4] sched/rt: Annotate the RT balancing logic irqwork as IRQ_WORK_HARD_IRQ Sebastian Andrzej Siewior
2021-10-13 22:13   ` Steven Rostedt
2021-10-15  9:44   ` [tip: sched/core] " tip-bot2 for Sebastian Andrzej Siewior
2021-10-06 11:18 ` [PATCH v2 2/4] irq_work: Allow irq_work_sync() to sleep if irq_work() no IRQ support Sebastian Andrzej Siewior
2021-10-15  9:44   ` [tip: sched/core] " tip-bot2 for Sebastian Andrzej Siewior
2021-10-06 11:18 ` [PATCH v2 3/4] irq_work: Handle some irq_work in a per-CPU thread on PREEMPT_RT Sebastian Andrzej Siewior
2021-10-06 11:35   ` Sebastian Andrzej Siewior
2021-10-06 16:26   ` kernel test robot
2021-10-06 16:26     ` kernel test robot
2021-10-07  8:50   ` Peter Zijlstra [this message]
2021-10-07  9:08     ` Sebastian Andrzej Siewior
2021-10-07  9:26       ` [PATCH v3 " Sebastian Andrzej Siewior
2021-10-15  9:44         ` [tip: sched/core] " tip-bot2 for Sebastian Andrzej Siewior
2021-10-06 11:18 ` [PATCH v2 4/4] irq_work: Also rcuwait for !IRQ_WORK_HARD_IRQ " Sebastian Andrzej Siewior
2021-10-15  9:44   ` [tip: sched/core] " tip-bot2 for Sebastian Andrzej Siewior

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=20211007085023.GP174703@worktop.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=bigeasy@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tglx@linutronix.de \
    /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.