diff options
author | Eric Dumazet <edumazet@google.com> | 2016-11-16 17:54:50 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2016-11-16 18:32:02 -0500 |
commit | 89c4b442b78bdba388337cc746fe63caba85f46c (patch) | |
tree | 825a8d6e04cdc937950e9d8a79b52eeb249236c3 | |
parent | 1629dd4f763cc15ac3b2711ac65dab153b738c6d (diff) |
netpoll: more efficient locking
Callers of netpoll_poll_lock() own NAPI_STATE_SCHED
Callers of netpoll_poll_unlock() have BH blocked between
the NAPI_STATE_SCHED being cleared and poll_lock is released.
We can avoid the spinlock which has no contention, and use cmpxchg()
on poll_owner which we need to set anyway.
This removes a possible lockdep violation after the cited commit,
since sk_busy_loop() re-enables BH before calling busy_poll_stop()
Fixes: 217f69743681 ("net: busy-poll: allow preemption in sk_busy_loop()")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | include/linux/netdevice.h | 1 | ||||
-rw-r--r-- | include/linux/netpoll.h | 13 | ||||
-rw-r--r-- | net/core/dev.c | 1 | ||||
-rw-r--r-- | net/core/netpoll.c | 6 |
4 files changed, 10 insertions, 11 deletions
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index bcddf951ccee..e84800edd249 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h | |||
@@ -316,7 +316,6 @@ struct napi_struct { | |||
316 | unsigned int gro_count; | 316 | unsigned int gro_count; |
317 | int (*poll)(struct napi_struct *, int); | 317 | int (*poll)(struct napi_struct *, int); |
318 | #ifdef CONFIG_NETPOLL | 318 | #ifdef CONFIG_NETPOLL |
319 | spinlock_t poll_lock; | ||
320 | int poll_owner; | 319 | int poll_owner; |
321 | #endif | 320 | #endif |
322 | struct net_device *dev; | 321 | struct net_device *dev; |
diff --git a/include/linux/netpoll.h b/include/linux/netpoll.h index b25ee9ffdbe6..1828900c9411 100644 --- a/include/linux/netpoll.h +++ b/include/linux/netpoll.h | |||
@@ -78,8 +78,11 @@ static inline void *netpoll_poll_lock(struct napi_struct *napi) | |||
78 | struct net_device *dev = napi->dev; | 78 | struct net_device *dev = napi->dev; |
79 | 79 | ||
80 | if (dev && dev->npinfo) { | 80 | if (dev && dev->npinfo) { |
81 | spin_lock(&napi->poll_lock); | 81 | int owner = smp_processor_id(); |
82 | napi->poll_owner = smp_processor_id(); | 82 | |
83 | while (cmpxchg(&napi->poll_owner, -1, owner) != -1) | ||
84 | cpu_relax(); | ||
85 | |||
83 | return napi; | 86 | return napi; |
84 | } | 87 | } |
85 | return NULL; | 88 | return NULL; |
@@ -89,10 +92,8 @@ static inline void netpoll_poll_unlock(void *have) | |||
89 | { | 92 | { |
90 | struct napi_struct *napi = have; | 93 | struct napi_struct *napi = have; |
91 | 94 | ||
92 | if (napi) { | 95 | if (napi) |
93 | napi->poll_owner = -1; | 96 | smp_store_release(&napi->poll_owner, -1); |
94 | spin_unlock(&napi->poll_lock); | ||
95 | } | ||
96 | } | 97 | } |
97 | 98 | ||
98 | static inline bool netpoll_tx_running(struct net_device *dev) | 99 | static inline bool netpoll_tx_running(struct net_device *dev) |
diff --git a/net/core/dev.c b/net/core/dev.c index edba9efeb2e9..f71b34ab57a5 100644 --- a/net/core/dev.c +++ b/net/core/dev.c | |||
@@ -5143,7 +5143,6 @@ void netif_napi_add(struct net_device *dev, struct napi_struct *napi, | |||
5143 | list_add(&napi->dev_list, &dev->napi_list); | 5143 | list_add(&napi->dev_list, &dev->napi_list); |
5144 | napi->dev = dev; | 5144 | napi->dev = dev; |
5145 | #ifdef CONFIG_NETPOLL | 5145 | #ifdef CONFIG_NETPOLL |
5146 | spin_lock_init(&napi->poll_lock); | ||
5147 | napi->poll_owner = -1; | 5146 | napi->poll_owner = -1; |
5148 | #endif | 5147 | #endif |
5149 | set_bit(NAPI_STATE_SCHED, &napi->state); | 5148 | set_bit(NAPI_STATE_SCHED, &napi->state); |
diff --git a/net/core/netpoll.c b/net/core/netpoll.c index 53599bd0c82d..9424673009c1 100644 --- a/net/core/netpoll.c +++ b/net/core/netpoll.c | |||
@@ -171,12 +171,12 @@ static void poll_one_napi(struct napi_struct *napi) | |||
171 | static void poll_napi(struct net_device *dev) | 171 | static void poll_napi(struct net_device *dev) |
172 | { | 172 | { |
173 | struct napi_struct *napi; | 173 | struct napi_struct *napi; |
174 | int cpu = smp_processor_id(); | ||
174 | 175 | ||
175 | list_for_each_entry(napi, &dev->napi_list, dev_list) { | 176 | list_for_each_entry(napi, &dev->napi_list, dev_list) { |
176 | if (napi->poll_owner != smp_processor_id() && | 177 | if (cmpxchg(&napi->poll_owner, -1, cpu) == -1) { |
177 | spin_trylock(&napi->poll_lock)) { | ||
178 | poll_one_napi(napi); | 178 | poll_one_napi(napi); |
179 | spin_unlock(&napi->poll_lock); | 179 | smp_store_release(&napi->poll_owner, -1); |
180 | } | 180 | } |
181 | } | 181 | } |
182 | } | 182 | } |