Commit 6af645a5 authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller

net: net_{enable|disable}_timestamp() optimizations

Adopting atomic_try_cmpxchg() makes the code cleaner.
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 30189806
...@@ -2073,13 +2073,10 @@ static DECLARE_WORK(netstamp_work, netstamp_clear); ...@@ -2073,13 +2073,10 @@ static DECLARE_WORK(netstamp_work, netstamp_clear);
void net_enable_timestamp(void) void net_enable_timestamp(void)
{ {
#ifdef CONFIG_JUMP_LABEL #ifdef CONFIG_JUMP_LABEL
int wanted; int wanted = atomic_read(&netstamp_wanted);
while (1) { while (wanted > 0) {
wanted = atomic_read(&netstamp_wanted); if (atomic_try_cmpxchg(&netstamp_wanted, &wanted, wanted + 1))
if (wanted <= 0)
break;
if (atomic_cmpxchg(&netstamp_wanted, wanted, wanted + 1) == wanted)
return; return;
} }
atomic_inc(&netstamp_needed_deferred); atomic_inc(&netstamp_needed_deferred);
...@@ -2093,13 +2090,10 @@ EXPORT_SYMBOL(net_enable_timestamp); ...@@ -2093,13 +2090,10 @@ EXPORT_SYMBOL(net_enable_timestamp);
void net_disable_timestamp(void) void net_disable_timestamp(void)
{ {
#ifdef CONFIG_JUMP_LABEL #ifdef CONFIG_JUMP_LABEL
int wanted; int wanted = atomic_read(&netstamp_wanted);
while (1) { while (wanted > 1) {
wanted = atomic_read(&netstamp_wanted); if (atomic_try_cmpxchg(&netstamp_wanted, &wanted, wanted - 1))
if (wanted <= 1)
break;
if (atomic_cmpxchg(&netstamp_wanted, wanted, wanted - 1) == wanted)
return; return;
} }
atomic_dec(&netstamp_needed_deferred); atomic_dec(&netstamp_needed_deferred);
......
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