Skip to content

Commit feb4a51

Browse files
Frederic WeisbeckerIngo Molnar
authored andcommitted
irq_work: Slightly simplify IRQ_WORK_PENDING clearing
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 <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Paul E . McKenney <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 2526987 commit feb4a51

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

kernel/irq_work.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ static bool irq_work_claim(struct irq_work *work)
3434
oflags = atomic_fetch_or(IRQ_WORK_CLAIMED, &work->flags);
3535
/*
3636
* If the work is already pending, no need to raise the IPI.
37-
* The pairing atomic_xchg() in irq_work_run() makes sure
37+
* The pairing atomic_fetch_andnot() in irq_work_run() makes sure
3838
* everything we did before is visible.
3939
*/
4040
if (oflags & IRQ_WORK_PENDING)
@@ -135,7 +135,6 @@ static void irq_work_run_list(struct llist_head *list)
135135
{
136136
struct irq_work *work, *tmp;
137137
struct llist_node *llnode;
138-
int flags;
139138

140139
BUG_ON(!irqs_disabled());
141140

@@ -144,15 +143,15 @@ static void irq_work_run_list(struct llist_head *list)
144143

145144
llnode = llist_del_all(list);
146145
llist_for_each_entry_safe(work, tmp, llnode, llnode) {
146+
int flags;
147147
/*
148148
* Clear the PENDING bit, after this point the @work
149149
* can be re-used.
150150
* Make it immediately visible so that other CPUs trying
151151
* to claim that work don't rely on us to handle their data
152152
* while we are in the middle of the func.
153153
*/
154-
flags = atomic_read(&work->flags) & ~IRQ_WORK_PENDING;
155-
atomic_xchg(&work->flags, flags);
154+
flags = atomic_fetch_andnot(IRQ_WORK_PENDING, &work->flags);
156155

157156
work->func(work);
158157
/*

0 commit comments

Comments
 (0)