Skip to content

Commit

Permalink
net: adopt try_cmpxchg() in napi_{enable|disable}()
Browse files Browse the repository at this point in the history
This makes code a bit cleaner.

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 1462160 commit 4ffa1d1
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions net/core/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -6397,19 +6397,16 @@ void napi_disable(struct napi_struct *n)
might_sleep();
set_bit(NAPI_STATE_DISABLE, &n->state);

for ( ; ; ) {
val = READ_ONCE(n->state);
val = READ_ONCE(n->state);
do {
if (val & (NAPIF_STATE_SCHED | NAPIF_STATE_NPSVC)) {
usleep_range(20, 200);
continue;
}

new = val | NAPIF_STATE_SCHED | NAPIF_STATE_NPSVC;
new &= ~(NAPIF_STATE_THREADED | NAPIF_STATE_PREFER_BUSY_POLL);

if (cmpxchg(&n->state, val, new) == val)
break;
}
} while (!try_cmpxchg(&n->state, &val, new));

hrtimer_cancel(&n->timer);

Expand All @@ -6426,16 +6423,15 @@ EXPORT_SYMBOL(napi_disable);
*/
void napi_enable(struct napi_struct *n)
{
unsigned long val, new;
unsigned long new, val = READ_ONCE(n->state);

do {
val = READ_ONCE(n->state);
BUG_ON(!test_bit(NAPI_STATE_SCHED, &val));

new = val & ~(NAPIF_STATE_SCHED | NAPIF_STATE_NPSVC);
if (n->dev->threaded && n->thread)
new |= NAPIF_STATE_THREADED;
} while (cmpxchg(&n->state, val, new) != val);
} while (!try_cmpxchg(&n->state, &val, new));
}
EXPORT_SYMBOL(napi_enable);

Expand Down

0 comments on commit 4ffa1d1

Please sign in to comment.