net: adopt try_cmpxchg() in napi_{enable|disable}()

This makes code a bit cleaner.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Eric Dumazet 2022-11-15 09:11:00 +00:00 committed by David S. Miller
parent 1462160c74
commit 4ffa1d1c68

View File

@ -6397,8 +6397,8 @@ void napi_disable(struct napi_struct *n)
might_sleep(); might_sleep();
set_bit(NAPI_STATE_DISABLE, &n->state); 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)) { if (val & (NAPIF_STATE_SCHED | NAPIF_STATE_NPSVC)) {
usleep_range(20, 200); usleep_range(20, 200);
continue; continue;
@ -6406,10 +6406,7 @@ void napi_disable(struct napi_struct *n)
new = val | NAPIF_STATE_SCHED | NAPIF_STATE_NPSVC; new = val | NAPIF_STATE_SCHED | NAPIF_STATE_NPSVC;
new &= ~(NAPIF_STATE_THREADED | NAPIF_STATE_PREFER_BUSY_POLL); new &= ~(NAPIF_STATE_THREADED | NAPIF_STATE_PREFER_BUSY_POLL);
} while (!try_cmpxchg(&n->state, &val, new));
if (cmpxchg(&n->state, val, new) == val)
break;
}
hrtimer_cancel(&n->timer); hrtimer_cancel(&n->timer);
@ -6426,16 +6423,15 @@ EXPORT_SYMBOL(napi_disable);
*/ */
void napi_enable(struct napi_struct *n) void napi_enable(struct napi_struct *n)
{ {
unsigned long val, new; unsigned long new, val = READ_ONCE(n->state);
do { do {
val = READ_ONCE(n->state);
BUG_ON(!test_bit(NAPI_STATE_SCHED, &val)); BUG_ON(!test_bit(NAPI_STATE_SCHED, &val));
new = val & ~(NAPIF_STATE_SCHED | NAPIF_STATE_NPSVC); new = val & ~(NAPIF_STATE_SCHED | NAPIF_STATE_NPSVC);
if (n->dev->threaded && n->thread) if (n->dev->threaded && n->thread)
new |= NAPIF_STATE_THREADED; new |= NAPIF_STATE_THREADED;
} while (cmpxchg(&n->state, val, new) != val); } while (!try_cmpxchg(&n->state, &val, new));
} }
EXPORT_SYMBOL(napi_enable); EXPORT_SYMBOL(napi_enable);