]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
net: add napi_if_scheduled_mark_missed
authorMagnus Karlsson <magnus.karlsson@intel.com>
Tue, 28 Aug 2018 12:44:28 +0000 (14:44 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 29 Aug 2018 19:25:53 +0000 (12:25 -0700)
The function napi_if_scheduled_mark_missed is used to check if the
NAPI context is scheduled, if so set NAPIF_STATE_MISSED and return
true. Used by the AF_XDP zero-copy i40e Tx code implementation in
order to make sure that irq affinity is honored by the napi context.

Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
include/linux/netdevice.h

index ca5ab98053c8d48312d9f479a861c6c426b33e54..4271f6b4e4197afbb9eed2aafdcfccdbdc08819c 100644 (file)
@@ -535,6 +535,32 @@ static inline void napi_synchronize(const struct napi_struct *n)
                barrier();
 }
 
+/**
+ *     napi_if_scheduled_mark_missed - if napi is running, set the
+ *     NAPIF_STATE_MISSED
+ *     @n: NAPI context
+ *
+ * If napi is running, set the NAPIF_STATE_MISSED, and return true if
+ * NAPI is scheduled.
+ **/
+static inline bool napi_if_scheduled_mark_missed(struct napi_struct *n)
+{
+       unsigned long val, new;
+
+       do {
+               val = READ_ONCE(n->state);
+               if (val & NAPIF_STATE_DISABLE)
+                       return true;
+
+               if (!(val & NAPIF_STATE_SCHED))
+                       return false;
+
+               new = val | NAPIF_STATE_MISSED;
+       } while (cmpxchg(&n->state, val, new) != val);
+
+       return true;
+}
+
 enum netdev_queue_state_t {
        __QUEUE_STATE_DRV_XOFF,
        __QUEUE_STATE_STACK_XOFF,