Skip to content

Commit

Permalink
net: adopt try_cmpxchg() in napi_schedule_prep() and napi_complete_do…
Browse files Browse the repository at this point in the history
…ne()

This makes the code slightly more efficient.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Eric Dumazet authored and David S. Miller committed Nov 16, 2022
1 parent 6af645a commit 1462160
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions net/core/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -5979,10 +5979,9 @@ EXPORT_SYMBOL(__napi_schedule);
*/
bool napi_schedule_prep(struct napi_struct *n)
{
unsigned long val, new;
unsigned long new, val = READ_ONCE(n->state);

do {
val = READ_ONCE(n->state);
if (unlikely(val & NAPIF_STATE_DISABLE))
return false;
new = val | NAPIF_STATE_SCHED;
Expand All @@ -5995,7 +5994,7 @@ bool napi_schedule_prep(struct napi_struct *n)
*/
new |= (val & NAPIF_STATE_SCHED) / NAPIF_STATE_SCHED *
NAPIF_STATE_MISSED;
} while (cmpxchg(&n->state, val, new) != val);
} while (!try_cmpxchg(&n->state, &val, new));

return !(val & NAPIF_STATE_SCHED);
}
Expand Down Expand Up @@ -6063,9 +6062,8 @@ bool napi_complete_done(struct napi_struct *n, int work_done)
local_irq_restore(flags);
}

val = READ_ONCE(n->state);
do {
val = READ_ONCE(n->state);

WARN_ON_ONCE(!(val & NAPIF_STATE_SCHED));

new = val & ~(NAPIF_STATE_MISSED | NAPIF_STATE_SCHED |
Expand All @@ -6078,7 +6076,7 @@ bool napi_complete_done(struct napi_struct *n, int work_done)
*/
new |= (val & NAPIF_STATE_MISSED) / NAPIF_STATE_MISSED *
NAPIF_STATE_SCHED;
} while (cmpxchg(&n->state, val, new) != val);
} while (!try_cmpxchg(&n->state, &val, new));

if (unlikely(val & NAPIF_STATE_MISSED)) {
__napi_schedule(n);
Expand Down

0 comments on commit 1462160

Please sign in to comment.