Skip to contentSkip to conversation

mac80211: add a function for running rx without passing skbs to the stack

RFC In review Felix Fietkau 4 participants 5 messages Jul 25, 2020 – Jul 30, 2020 mac80211

lore
Share & tools
lore
#0 lore raw

RFC 1/1 mac80211: add a function for running rx without passing skbs to the stack

This can be used to run mac80211 rx processing on a batch of frames in NAPI poll before passing them to the network stack in a large batch. This can improve icache footprint, or it can be used to pass frames via netif_receive_skb_list.

---
 include/net/mac80211.h     | 25 +++++++++++++++++
 net/mac80211/ieee80211_i.h |  2 +-
 net/mac80211/rx.c          | 56 +++++++++++++++++++++++---------------
 3 files changed, 60 insertions(+), 23 deletions(-)
include/net/mac80211.h +25 -0
index 11d5610d2ad5..cc9c477184a4 100644
@@ -4357,6 +4357,31 @@ void ieee80211_free_hw(struct ieee80211_hw *hw);
  */
 void ieee80211_restart_hw(struct ieee80211_hw *hw);
 
+/**
+ * ieee80211_rx_list - receive frame and store processed skbs in a list
+ *
+ * Use this function to hand received frames to mac80211. The receive
+ * buffer in @skb must start with an IEEE 802.11 header. In case of a
+ * paged @skb is used, the driver is recommended to put the ieee80211
+ * header of the frame on the linear part of the @skb to avoid memory
+ * allocation and/or memcpy by the stack.
+ *
+ * This function may not be called in IRQ context. Calls to this function
+ * for a single hardware must be synchronized against each other. Calls to
+ * this function, ieee80211_rx_ni() and ieee80211_rx_irqsafe() may not be
+ * mixed for a single hardware. Must not run concurrently with
+ * ieee80211_tx_status() or ieee80211_tx_status_ni().
+ *
+ * This function must be called with BHs disabled and RCU read lock
+ *
+ * @hw: the hardware this frame came in on
+ * @sta: the station the frame was received from, or %NULL
+ * @skb: the buffer to receive, owned by mac80211 after this call
+ * @list: the destination list
+ */
+void ieee80211_rx_list(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
+		       struct sk_buff *skb, struct sk_buff_head *list);
+
 /**
  * ieee80211_rx_napi - receive frame from NAPI context
  *
net/mac80211/ieee80211_i.h +1 -1
index 28b154c6e72d..13aad8c3a16f 100644
@@ -218,7 +218,7 @@ enum ieee80211_rx_flags {
 };
 
 struct ieee80211_rx_data {
-	struct napi_struct *napi;
+	struct sk_buff_head *list;
 	struct sk_buff *skb;
 	struct ieee80211_local *local;
 	struct ieee80211_sub_if_data *sdata;
net/mac80211/rx.c +34 -22

115 lines not on this page · raw message

Signature · 1 line
2.24.0
maintainer
#1 lore raw
Quoted 8 lines
net/mac80211/rx.c +7 -0
+void ieee80211_rx_napi(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta,
+		       struct sk_buff *skb, struct napi_struct *napi)
+{
+	struct sk_buff_head list;
+
+	__skb_queue_head_init(&list);
+

net/mac80211/rx.c void ieee80211_rx_napi(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta, · line 4802

Quoted 10 lines
net/mac80211/rx.c +10 -0
+	/*
+	 * key references and virtual interfaces are protected using RCU
+	 * and this requires that we are in a read-side RCU section during
+	 * receive processing
+	 */
+	rcu_read_lock();
+	ieee80211_rx_list(hw, pubsta, skb, &list);
+	rcu_read_unlock();
+
+	while ((skb = __skb_dequeue(&list)) != NULL)

I'd drop the != NULL, but no strong feelings :)

net/mac80211/rx.c void ieee80211_rx_napi(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta, · line 4806

Quoted 4 lines
net/mac80211/rx.c +4 -0
+		if (napi)
+			napi_gro_receive(napi, skb);
+		else
+			netif_receive_skb(skb);

Nit: I'd prefer braces on the loop, just makes it nicer to read IMHO.

OTOH, the !napi case should use netif_receive_skb_list(), no?

Given the discussion, it also seems a bit odd to add more work for NAPI poll where we process one by one ... But I see why you did that, and I guess it's not actually that much more work.

johannes

#2 lore raw
Quoted 28 lines · Johannes Berg
Quoted 8 lines

+void ieee80211_rx_napi(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta,

net/mac80211/rx.c +6 -0
+		       struct sk_buff *skb, struct napi_struct *napi)
+{
+	struct sk_buff_head list;
+
+	__skb_queue_head_init(&list);
+

net/mac80211/rx.c void ieee80211_rx_napi(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta, · line 4802

Quoted 10 lines
net/mac80211/rx.c +10 -0
+	/*
+	 * key references and virtual interfaces are protected using RCU
+	 * and this requires that we are in a read-side RCU section during
+	 * receive processing
+	 */
+	rcu_read_lock();
+	ieee80211_rx_list(hw, pubsta, skb, &list);
+	rcu_read_unlock();
+
+	while ((skb = __skb_dequeue(&list)) != NULL)

I'd drop the != NULL, but no strong feelings :)

net/mac80211/rx.c void ieee80211_rx_napi(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta, · line 4806

Quoted 4 lines
net/mac80211/rx.c +4 -0
+		if (napi)
+			napi_gro_receive(napi, skb);
+		else
+			netif_receive_skb(skb);

Nit: I'd prefer braces on the loop, just makes it nicer to read IMHO.

Quoted 6 lines

OTOH, the !napi case should use netif_receive_skb_list(), no?

Given the discussion, it also seems a bit odd to add more work for NAPI poll where we process one by one ... But I see why you did that, and I guess it's not actually that much more work.

IIUC Sebastian mentioned that threadable NAPI approach is helping in load balancing with minor check for dummy netdev for wireless drivers. Does this change improve the latency in both threaded and non-threaded modes?

-Rajkumar

#3 lore raw
Quoted 31 lines · Rajkumar Manoharan
Quoted 30 lines · Johannes Berg
Quoted 8 lines

+void ieee80211_rx_napi(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta,

net/mac80211/rx.c +6 -0
+		       struct sk_buff *skb, struct napi_struct *napi)
+{
+	struct sk_buff_head list;
+
+	__skb_queue_head_init(&list);
+

net/mac80211/rx.c void ieee80211_rx_napi(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta, · line 4802

Quoted 10 lines
net/mac80211/rx.c +10 -0
+	/*
+	 * key references and virtual interfaces are protected using RCU
+	 * and this requires that we are in a read-side RCU section during
+	 * receive processing
+	 */
+	rcu_read_lock();
+	ieee80211_rx_list(hw, pubsta, skb, &list);
+	rcu_read_unlock();
+
+	while ((skb = __skb_dequeue(&list)) != NULL)

I'd drop the != NULL, but no strong feelings :)

net/mac80211/rx.c void ieee80211_rx_napi(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta, · line 4806

Quoted 4 lines
net/mac80211/rx.c +4 -0
+		if (napi)
+			napi_gro_receive(napi, skb);
+		else
+			netif_receive_skb(skb);

Nit: I'd prefer braces on the loop, just makes it nicer to read IMHO.

OTOH, the !napi case should use netif_receive_skb_list(), no?

Quoted 9 lines
Quoted 4 lines

Given the discussion, it also seems a bit odd to add more work for NAPI poll where we process one by one ... But I see why you did that, and I guess it's not actually that much more work.

IIUC Sebastian mentioned that threadable NAPI approach is helping in load balancing
with minor check for dummy netdev for wireless drivers. Does this change improve the latency in both threaded and non-threaded modes?

Also I was thinking of introducing threaded irq in athX driver. I was concerned about more threaded levels and intermediate lists might increase sojourn which will impact latency. no?

-Rajkumar

#4 lore raw
In reply to Rajkumar Manoharan

Am 29.07.2020 um 03:47 schrieb Rajkumar Manoharan:

Quoted 31 lines · Johannes Berg
Quoted 30 lines
Quoted 8 lines

+void ieee80211_rx_napi(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta,
+               struct sk_buff *skb, struct napi_struct *napi)

net/mac80211/rx.c +5 -0
+{
+    struct sk_buff_head list;
+
+    __skb_queue_head_init(&list);
+

net/mac80211/rx.c void ieee80211_rx_napi(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta, · line 4802

Quoted 10 lines
net/mac80211/rx.c +10 -0
+    /*
+     * key references and virtual interfaces are protected using RCU
+     * and this requires that we are in a read-side RCU section during
+     * receive processing
+     */
+    rcu_read_lock();
+    ieee80211_rx_list(hw, pubsta, skb, &list);
+    rcu_read_unlock();
+
+    while ((skb = __skb_dequeue(&list)) != NULL)

I'd drop the != NULL, but no strong feelings :)

Quoted 4 lines

+        if (napi)
+            napi_gro_receive(napi, skb);
+        else
+            netif_receive_skb(skb);

Nit: I'd prefer braces on the loop, just makes it nicer to read IMHO.

OTOH, the !napi case should use netif_receive_skb_list(), no?

Quoted 7 lines
Quoted 4 lines

Given the discussion, it also seems a bit odd to add more work for NAPI poll where we process one by one ... But I see why you did that, and I guess it's not actually that much more work.

IIUC Sebastian mentioned that threadable NAPI approach is helping in load balancing with minor check for dummy netdev for wireless drivers. Does this change improve the latency in both threaded and non-threaded modes?

check also for felix's last variant. he made a different patch based on workq's
i'm testing this variant now on various platforms including a patched ath10k driver
next step would be just to change other wifi drivers for the same concept. just a few are using napi at all (mt76, ath10k and iwlwifi)

Quoted 3 lines

-Rajkumar