Commit 4ffa1d1c authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller

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

This makes code a bit cleaner.
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 1462160c
...@@ -6397,8 +6397,8 @@ void napi_disable(struct napi_struct *n) ...@@ -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) ...@@ -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); ...@@ -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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment