From: Peter Zijlstra <peterz@infradead.org>
To: mingo@kernel.org
Cc: linux-kernel@vger.kernel.org, will@kernel.org,
paulmck@kernel.org, hch@lst.de, axboe@kernel.dk,
chris@chris-wilson.co.uk, davem@davemloft.net, kuba@kernel.org,
fweisbec@gmail.com, oleg@redhat.com, vincent.guittot@linaro.org,
peterz@infradead.org
Subject: [PATCH v3 3/6] irq_work: Optimize irq_work_single()
Date: Wed, 28 Oct 2020 12:07:10 +0100 [thread overview]
Message-ID: <20201028111221.405177398@infradead.org> (raw)
In-Reply-To: 20201028110707.971887448@infradead.org
Trade one atomic op for a full memory barrier.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
include/linux/irqflags.h | 8 ++++----
kernel/irq_work.c | 29 +++++++++++++++++------------
2 files changed, 21 insertions(+), 16 deletions(-)
--- a/include/linux/irqflags.h
+++ b/include/linux/irqflags.h
@@ -88,14 +88,14 @@ do { \
current->irq_config = 0; \
} while (0)
-# define lockdep_irq_work_enter(__work) \
+# define lockdep_irq_work_enter(_flags) \
do { \
- if (!(atomic_read(&__work->node.a_flags) & IRQ_WORK_HARD_IRQ))\
+ if (!((_flags) & IRQ_WORK_HARD_IRQ)) \
current->irq_config = 1; \
} while (0)
-# define lockdep_irq_work_exit(__work) \
+# define lockdep_irq_work_exit(_flags) \
do { \
- if (!(atomic_read(&__work->node.a_flags) & IRQ_WORK_HARD_IRQ))\
+ if (!((_flags) & IRQ_WORK_HARD_IRQ)) \
current->irq_config = 0; \
} while (0)
--- a/kernel/irq_work.c
+++ b/kernel/irq_work.c
@@ -34,7 +34,7 @@ static bool irq_work_claim(struct irq_wo
oflags = atomic_fetch_or(IRQ_WORK_CLAIMED | CSD_TYPE_IRQ_WORK, &work->node.a_flags);
/*
* If the work is already pending, no need to raise the IPI.
- * The pairing atomic_fetch_andnot() in irq_work_run() makes sure
+ * The pairing smp_mb() in irq_work_single() makes sure
* everything we did before is visible.
*/
if (oflags & IRQ_WORK_PENDING)
@@ -136,22 +136,27 @@ void irq_work_single(void *arg)
int flags;
/*
- * Clear the PENDING bit, after this point the @work
- * can be re-used.
- * Make it immediately visible so that other CPUs trying
- * to claim that work don't rely on us to handle their data
- * while we are in the middle of the func.
+ * Clear the PENDING bit, after this point the @work can be re-used.
+ * The PENDING bit acts as a lock, and we own it, so we can clear it
+ * without atomic ops.
*/
- flags = atomic_fetch_andnot(IRQ_WORK_PENDING, &work->node.a_flags);
+ flags = atomic_read(&work->node.a_flags);
+ flags &= ~IRQ_WORK_PENDING;
+ atomic_set(&work->node.a_flags, flags);
+
+ /*
+ * See irq_work_claim().
+ */
+ smp_mb();
- lockdep_irq_work_enter(work);
+ lockdep_irq_work_enter(flags);
work->func(work);
- lockdep_irq_work_exit(work);
+ lockdep_irq_work_exit(flags);
+
/*
- * Clear the BUSY bit and return to the free state if
- * no-one else claimed it meanwhile.
+ * Clear the BUSY bit, if set, and return to the free state if no-one
+ * else claimed it meanwhile.
*/
- flags &= ~IRQ_WORK_PENDING;
(void)atomic_cmpxchg(&work->node.a_flags, flags, flags & ~IRQ_WORK_BUSY);
}
next prev parent reply other threads:[~2020-10-29 2:00 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-28 11:07 [PATCH v3 0/6] smp: irq_work / smp_call_function rework Peter Zijlstra
2020-10-28 11:07 ` [PATCH v3 1/6] irq_work: Cleanup Peter Zijlstra
2020-10-28 13:01 ` Frederic Weisbecker
2020-10-28 11:07 ` [PATCH v3 2/6] smp: Cleanup smp_call_function*() Peter Zijlstra
2020-10-28 13:25 ` Frederic Weisbecker
2020-10-28 11:07 ` Peter Zijlstra [this message]
2020-10-28 12:06 ` [PATCH v3 3/6] irq_work: Optimize irq_work_single() Frederic Weisbecker
2020-10-28 11:07 ` [PATCH v3 4/6] irq_work: Unconditionally build on SMP Peter Zijlstra
2020-10-28 13:34 ` Frederic Weisbecker
2020-10-28 14:52 ` Peter Zijlstra
2020-10-28 11:07 ` [PATCH v3 5/6] irq_work: Provide irq_work_queue_remote() Peter Zijlstra
2020-10-28 13:40 ` Frederic Weisbecker
2020-10-28 14:38 ` Peter Zijlstra
2020-10-28 14:53 ` Peter Zijlstra
2020-10-28 14:56 ` Frederic Weisbecker
2020-10-28 11:07 ` [RFC][PATCH v3 6/6] rcu/tree: Use irq_work_queue_remote() Peter Zijlstra
2020-10-28 14:54 ` Peter Zijlstra
2020-10-28 20:02 ` Peter Zijlstra
2020-10-28 20:15 ` Paul E. McKenney
2020-10-29 9:10 ` Peter Zijlstra
2020-10-29 16:04 ` Paul E. McKenney
2020-10-29 16:14 ` Peter Zijlstra
2020-10-29 9:15 ` Peter Zijlstra
2020-10-29 16:06 ` Paul E. McKenney
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=20201028111221.405177398@infradead.org \
--to=peterz@infradead.org \
--cc=axboe@kernel.dk \
--cc=chris@chris-wilson.co.uk \
--cc=davem@davemloft.net \
--cc=fweisbec@gmail.com \
--cc=hch@lst.de \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=oleg@redhat.com \
--cc=paulmck@kernel.org \
--cc=vincent.guittot@linaro.org \
--cc=will@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox