Skip to contentSkip to conversation

Add support to process rx packets in thread

RFC In review Rakesh Pillai 13 participants 51 messages Jul 21, 2020 – Mar 25, 2021

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover Add support to process rx packets in thread

NAPI gets scheduled on the CPU core which got the interrupt. The linux scheduler cannot move it to a different core, even if the CPU on which NAPI is running is heavily loaded. This can lead to degraded wifi performance when running traffic at peak data rates.

A thread on the other hand can be moved to different CPU cores, if the one on which its running is heavily loaded. During high incoming data traffic, this gives better performance, since the thread can be moved to a less loaded or sometimes even a more powerful CPU core to account for the required CPU performance in order to process the incoming packets.

This patch series adds the support to use a high priority thread to process the incoming packets, as opposed to everything being done in NAPI context.

The rx thread can be enabled by using a module parameter when loading the ath10k_snoc module.

---
This patch series is dependent on the below patch series
https://patchwork.kernel.org/project/ath10k/list/?series=315759

Rakesh Pillai (7):
mac80211: Add check for napi handle before WARN_ON
ath10k: Add support to process rx packet in thread
ath10k: Add module param to enable rx thread
ath10k: Do not exhaust budget on process tx completion
ath10k: Handle the rx packet processing in thread
ath10k: Add deliver to stack from thread context
ath10k: Handle rx thread suspend and resume

 drivers/net/wireless/ath/ath10k/core.c   |  64 +++++++++++++++++++
 drivers/net/wireless/ath/ath10k/core.h   |  33 ++++++++++
 drivers/net/wireless/ath/ath10k/htt.h    |   2 +
 drivers/net/wireless/ath/ath10k/htt_rx.c |  66 ++++++++++++++-----
 drivers/net/wireless/ath/ath10k/snoc.c   | 105 ++++++++++++++++++++++++++++++-
 net/mac80211/rx.c                        |   2 +-
 6 files changed, 253 insertions(+), 19 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

RFC 1/7 mac80211: Add check for napi handle before WARN_ON

The function ieee80211_rx_napi can be now called
from a thread context as well, with napi context
being NULL.

Hence add the napi context check before giving out a warning for softirq count being 0.

Tested-on: WCN3990 hw1.0 SNOC WLAN.HL.3.1-01040-QCAHLSWMTPLZ-1

---
 net/mac80211/rx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/mac80211/rx.c +1 -1
index a88ab6f..1e703f1 100644
@@ -4652,7 +4652,7 @@ void ieee80211_rx_napi(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta,
 	struct ieee80211_supported_band *sband;
 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
 
-	WARN_ON_ONCE(softirq_count() == 0);
+	WARN_ON_ONCE(napi && softirq_count() == 0);
 
 	if (WARN_ON(status->band >= NUM_NL80211_BANDS))
 		goto drop;
Signature · 1 line
2.7.4
maintainer
#2 lore raw

Re: [RFC 1/7] mac80211: Add check for napi handle before WARN_ON

Quoted 19 lines · Rakesh Pillai

The function ieee80211_rx_napi can be now called
from a thread context as well, with napi context
being NULL.

Hence add the napi context check before giving out a warning for softirq count being 0.

Tested-on: WCN3990 hw1.0 SNOC WLAN.HL.3.1-01040-QCAHLSWMTPLZ-1

---
 net/mac80211/rx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/mac80211/rx.c +0 -0
index a88ab6f..1e703f1 100644

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

Quoted 5 lines
net/mac80211/rx.c +1 -1
@@ -4652,7 +4652,7 @@ void ieee80211_rx_napi(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta,
 	struct ieee80211_supported_band *sband;
 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
 
-	WARN_ON_ONCE(softirq_count() == 0);
+	WARN_ON_ONCE(napi && softirq_count() == 0);

FWIW, I'm pretty sure this is incorrect - we make assumptions on softirqs being disabled in mac80211 for serialization and in place of some locking, I believe.

johannes

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k

#3 lore raw

RE: [RFC 1/7] mac80211: Add check for napi handle before WARN_ON

Quoted 36 lines

-----Original Message-----
From: Johannes Berg <[email protected]>
Sent: Wednesday, July 22, 2020 6:26 PM
To: Rakesh Pillai <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC 1/7] mac80211: Add check for napi handle before WARN_ON

net/mac80211/rx.c void ieee80211_rx_napi(struct ieee80211_hw

Quoted 19 lines · Rakesh Pillai

The function ieee80211_rx_napi can be now called
from a thread context as well, with napi context
being NULL.

Hence add the napi context check before giving out a warning for softirq count being 0.

Tested-on: WCN3990 hw1.0 SNOC WLAN.HL.3.1-01040-QCAHLSWMTPLZ-1

---
 net/mac80211/rx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/mac80211/rx.c +0 -0
index a88ab6f..1e703f1 100644
@@ -4652,7 +4652,7 @@ void ieee80211_rx_napi(struct ieee80211_hw

*hw, struct ieee80211_sta *pubsta,

Quoted 3 lines
net/mac80211/rx.c +0 -0
 	struct ieee80211_supported_band *sband;
 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
 
Quoted 7 lines

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

Quoted 2 lines
net/mac80211/rx.c +1 -1
-	WARN_ON_ONCE(softirq_count() == 0);
+	WARN_ON_ONCE(napi && softirq_count() == 0);

FWIW, I'm pretty sure this is incorrect - we make assumptions on softirqs being disabled in mac80211 for serialization and in place of some locking, I believe.

I checked this, but let me double confirm.
But after this change, no packet is submitted from driver in a softirq context. So ideally this should take care of serialization.

Quoted 1 line

johannes

maintainer
#4 lore raw

Re: [RFC 1/7] mac80211: Add check for napi handle before WARN_ON

Quoted 11 lines · Rakesh Pillai
Quoted 7 lines

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

Quoted 2 lines
net/mac80211/rx.c +1 -1
-	WARN_ON_ONCE(softirq_count() == 0);
+	WARN_ON_ONCE(napi && softirq_count() == 0);

FWIW, I'm pretty sure this is incorrect - we make assumptions on softirqs being disabled in mac80211 for serialization and in place of some locking, I believe.

I checked this, but let me double confirm.
But after this change, no packet is submitted from driver in a softirq context. So ideally this should take care of serialization.

I'd guess that we have some reliance on BHs already being disabled, for things like u64 sync updates, or whatnot. I mean, we did "rx_ni()" for a reason ... Maybe lockdep can help catch some of the issues.

But couldn't you be in a thread and have BHs disabled too?

johannes

#5 lore raw

RE: [RFC 1/7] mac80211: Add check for napi handle before WARN_ON

Quoted 24 lines

-----Original Message-----
From: Johannes Berg <[email protected]>
Sent: Friday, July 24, 2020 1:37 AM
To: Rakesh Pillai <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC 1/7] mac80211: Add check for napi handle before WARN_ON

Quoted 10 lines · Rakesh Pillai
Quoted 7 lines

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

Quoted 2 lines
net/mac80211/rx.c +1 -1
-	WARN_ON_ONCE(softirq_count() == 0);
+	WARN_ON_ONCE(napi && softirq_count() == 0);

FWIW, I'm pretty sure this is incorrect - we make assumptions on softirqs being disabled in mac80211 for serialization and in place of some locking, I believe.

I checked this, but let me double confirm.
But after this change, no packet is submitted from driver in a softirq

Quoted 8 lines

context.

Quoted 1 line

So ideally this should take care of serialization.

I'd guess that we have some reliance on BHs already being disabled, for things like u64 sync updates, or whatnot. I mean, we did "rx_ni()" for a reason ... Maybe lockdep can help catch some of the issues.

But couldn't you be in a thread and have BHs disabled too?

This would ideally beat the purpose and possibly hurt the other subsystems running on the same core.

Quoted 2 lines

johannes

#6 lore raw

RE: [RFC 1/7] mac80211: Add check for napi handle before WARN_ON

In reply to Johannes Berg
Quoted 45 lines

-----Original Message-----
From: Rakesh Pillai <[email protected]>
Sent: Friday, July 24, 2020 11:51 AM
To: 'Johannes Berg' <[email protected]>; '[email protected]' <[email protected]>
Cc: '[email protected]' <[email protected]>; '[email protected]' <[email protected]>; '[email protected]' <[email protected]>; '[email protected]' <[email protected]>; '[email protected]' <[email protected]>; '[email protected]' <[email protected]>; '[email protected]' <[email protected]>; '[email protected]' <[email protected]>
Subject: RE: [RFC 1/7] mac80211: Add check for napi handle before WARN_ON

Quoted 7 lines

-----Original Message-----
From: Johannes Berg <[email protected]>
Sent: Friday, July 24, 2020 1:37 AM
To: Rakesh Pillai <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected];

[email protected]

Quoted 18 lines

Subject: Re: [RFC 1/7] mac80211: Add check for napi handle before WARN_ON

Quoted 10 lines · Rakesh Pillai
Quoted 7 lines

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

Quoted 2 lines
net/mac80211/rx.c +1 -1
-	WARN_ON_ONCE(softirq_count() == 0);
+	WARN_ON_ONCE(napi && softirq_count() == 0);

FWIW, I'm pretty sure this is incorrect - we make assumptions on softirqs being disabled in mac80211 for serialization and in place of some locking, I believe.

I checked this, but let me double confirm.
But after this change, no packet is submitted from driver in a softirq

context.

Quoted 1 line

So ideally this should take care of serialization.

Quoted 9 lines
Quoted 5 lines

I'd guess that we have some reliance on BHs already being disabled, for things like u64 sync updates, or whatnot. I mean, we did "rx_ni()" for a reason ... Maybe lockdep can help catch some of the issues.

But couldn't you be in a thread and have BHs disabled too?

This would ideally beat the purpose and possibly hurt the other subsystems running on the same core.

Hi Johannes,

We do have the usage of napi_gro_receive and netif_receive_skb in mac80211.

                /* deliver to local stack */
                if (rx->napi)
                        napi_gro_receive(rx->napi, skb);
                else
                        netif_receive_skb(skb);

Also all the rx_handlers are called under the " rx->local->rx_path_lock" lock. Is the BH disable still required ?

Quoted 2 lines
Quoted 2 lines

johannes

maintainer
#7 lore raw

Re: [RFC 1/7] mac80211: Add check for napi handle before WARN_ON

Quoted 10 lines · Rakesh Pillai

We do have the usage of napi_gro_receive and netif_receive_skb in mac80211.

                /* deliver to local stack */
                if (rx->napi)
                        napi_gro_receive(rx->napi, skb);
                else
                        netif_receive_skb(skb);

Also all the rx_handlers are called under the " rx->local->rx_path_lock" lock. Is the BH disable still required ?

I tend to think so, but you're welcome to show that it's not. The lock serves a different purpose.

TBH, I don't have all of this in my head at all times either, so please do your own work and analyse why it may or may not be necessary. But without any such analysis I'm not going to take patches that change it.

johannes

#8 lore raw

RFC 2/7 ath10k: Add support to process rx packet in thread

In reply to Rakesh Pillai

NAPI instance gets scheduled on a CPU core on which the IRQ was triggered. The processing of rx packets can be CPU intensive and since NAPI cannot be moved to a different CPU core, to get better performance, its better to move the gist of rx packet processing in a high priority thread.

Add the init/deinit part for a thread to process the receive packets.

Tested-on: WCN3990 hw1.0 SNOC WLAN.HL.3.1-01040-QCAHLSWMTPLZ-1

---
 drivers/net/wireless/ath/ath10k/core.c | 33 +++++++++++++++++++++++++++
 drivers/net/wireless/ath/ath10k/core.h | 23 +++++++++++++++++++
 drivers/net/wireless/ath/ath10k/snoc.c | 41 ++++++++++++++++++++++++++++++++++
 3 files changed, 97 insertions(+)
drivers/net/wireless/ath/ath10k/core.c +33 -0
index 9104496..2b520a0 100644
@@ -668,6 +668,39 @@ static unsigned int ath10k_core_get_fw_feature_str(char *buf,
 	return scnprintf(buf, buf_len, "%s", ath10k_core_fw_feature_str[feat]);
 }
 
+int ath10k_core_thread_shutdown(struct ath10k *ar,
+				struct ath10k_thread *thread)
+{
+	ath10k_dbg(ar, ATH10K_DBG_BOOT, "shutting down %s\n", thread->name);
+	set_bit(ATH10K_THREAD_EVENT_SHUTDOWN, thread->event_flags);
+	wake_up_process(thread->task);
+	wait_for_completion(&thread->shutdown);
+	ath10k_info(ar, "thread %s exited\n", thread->name);
+
+	return 0;
+}
+EXPORT_SYMBOL(ath10k_core_thread_shutdown);
+
+int ath10k_core_thread_init(struct ath10k *ar,
+			    struct ath10k_thread *thread,
+			    int (*handler)(void *data),
+			    char *thread_name)
+{
+	thread->task = kthread_create(handler, thread, thread_name);
+	if (IS_ERR(thread->task))
+		return -EINVAL;
+
+	init_waitqueue_head(&thread->wait_q);
+	init_completion(&thread->shutdown);
+	memcpy(thread->name, thread_name, ATH10K_THREAD_NAME_SIZE_MAX);
+	clear_bit(ATH10K_THREAD_EVENT_SHUTDOWN, thread->event_flags);
+	ath10k_info(ar, "Starting thread %s\n", thread_name);
+	wake_up_process(thread->task);
+
+	return 0;
+}
+EXPORT_SYMBOL(ath10k_core_thread_init);
+
 void ath10k_core_get_fw_features_str(struct ath10k *ar,
 				     char *buf,
 				     size_t buf_len)
drivers/net/wireless/ath/ath10k/core.h +23 -0
index 5c18f6c..96919e8 100644
@@ -970,6 +970,22 @@ struct ath10k_bus_params {
 	bool hl_msdu_ids;
 };
 
+#define ATH10K_THREAD_NAME_SIZE_MAX	32
+
+enum ath10k_thread_events {
+	ATH10K_THREAD_EVENT_SHUTDOWN,
+	ATH10K_THREAD_EVENT_MAX,
+};
+
+struct ath10k_thread {
+	struct ath10k *ar;
+	struct task_struct *task;
+	struct completion shutdown;
+	wait_queue_head_t wait_q;
+	DECLARE_BITMAP(event_flags, ATH10K_THREAD_EVENT_MAX);
+	char name[ATH10K_THREAD_NAME_SIZE_MAX];
+};
+
 struct ath10k {
 	struct ath_common ath_common;
 	struct ieee80211_hw *hw;
@@ -982,6 +998,7 @@ struct ath10k {
 	} msa;
 	u8 mac_addr[ETH_ALEN];
 
+	struct ath10k_thread rx_thread;
 	enum ath10k_hw_rev hw_rev;
 	u16 dev_id;
 	u32 chip_id;
@@ -1276,6 +1293,12 @@ static inline bool ath10k_peer_stats_enabled(struct ath10k *ar)
 
 extern unsigned long ath10k_coredump_mask;
 
+int ath10k_core_thread_shutdown(struct ath10k *ar,
+				struct ath10k_thread *thread);
+int ath10k_core_thread_init(struct ath10k *ar,
+			    struct ath10k_thread *thread,
+			    int (*handler)(void *data),
+			    char *thread_name);
 struct ath10k *ath10k_core_create(size_t priv_size, struct device *dev,
 				  enum ath10k_bus bus,
 				  enum ath10k_hw_rev hw_rev,
drivers/net/wireless/ath/ath10k/snoc.c +41 -0

74 lines not on this page · raw message

Signature · 7 lines
2.7.4


_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k
#9 lore raw

Re: [RFC 2/7] ath10k: Add support to process rx packet in thread

Quoted 10 lines · Rakesh Pillai

NAPI instance gets scheduled on a CPU core on which the IRQ was triggered. The processing of rx packets can be CPU intensive and since NAPI cannot be moved to a different CPU core, to get better performance, its better to move the gist of rx packet processing in a high priority thread.

Add the init/deinit part for a thread to process the receive packets.

IMHO this defeat the whole purpose of NAPI. Originally in ath10k irq processing happened in tasklet (high priority) context which in turn push more data to net core even though net is unable to process driver data as both happen in different context (fast producer - slow consumer) issue. Why can't CPU governor schedule the interrupts in less loaded CPU core? Otherwise you can play with different RPS and affinity settings to meet your requirement.

IMO introducing high priority tasklets/threads is not viable solution.

-Rajkumar

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k

#10 lore raw

Re: [RFC 2/7] ath10k: Add support to process rx packet in thread

Quoted 22 lines · Rajkumar Manoharan
Quoted 10 lines · Rakesh Pillai

NAPI instance gets scheduled on a CPU core on which the IRQ was triggered. The processing of rx packets can be CPU intensive and since NAPI cannot be moved to a different CPU core, to get better performance, its better to move the gist of rx packet processing in a high priority thread.

Add the init/deinit part for a thread to process the receive packets.

IMHO this defeat the whole purpose of NAPI. Originally in ath10k irq processing happened in tasklet (high priority) context which in turn push more data to net core even though net is unable to process driver data as both happen in different context (fast producer - slow consumer)
issue. Why can't CPU governor schedule the interrupts in less loaded CPU core?
Otherwise you can play with different RPS and affinity settings to meet your
requirement.

Quoted 1 line

IMO introducing high priority tasklets/threads is not viable solution.

I'm beginning to think that the main problem with NAPI here is that the work done by poll functions on 802.11 drivers is significantly more CPU intensive compared to ethernet drivers, possibly more than what NAPI was designed for.

I'm considering testing a different approach (with mt76 initially):
- Add a mac80211 rx function that puts processed skbs into a list instead of handing them to the network stack directly.
- Move all rx processing to a high priority thread, keep a driver internal queue for fully processed packets.
- Schedule NAPI poll on completion.
- NAPI poll function pulls from the internal queue and passes to the network stack.

With this approach, the network stack retains some control over the processing rate of rx packets, while the scheduler can move the CPU intensive processing around to where it fits best.

What do you think?

- Felix

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k

maintainer
#11 lore raw

Re: [RFC 2/7] ath10k: Add support to process rx packet in thread

Quoted 3 lines · Felix Fietkau

I'm considering testing a different approach (with mt76 initially):
- Add a mac80211 rx function that puts processed skbs into a list instead of handing them to the network stack directly.

Would this be *after* all the mac80211 processing, i.e. in place of the rx-up-to-stack?

johannes

#12 lore raw

Re: [RFC 2/7] ath10k: Add support to process rx packet in thread

Quoted 8 lines · Johannes Berg
Quoted 3 lines · Felix Fietkau

I'm considering testing a different approach (with mt76 initially):
- Add a mac80211 rx function that puts processed skbs into a list instead of handing them to the network stack directly.

Would this be *after* all the mac80211 processing, i.e. in place of the rx-up-to-stack?

Yes, it would run all the rx handlers normally and then put the resulting skbs into a list instead of calling netif_receive_skb or napi_gro_frags.

- Felix

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k

#13 lore raw

Re: [RFC 2/7] ath10k: Add support to process rx packet in thread

Quoted 7 lines · Felix Fietkau
Quoted 6 lines · Johannes Berg
Quoted 3 lines · Felix Fietkau

I'm considering testing a different approach (with mt76 initially):
- Add a mac80211 rx function that puts processed skbs into a list instead of handing them to the network stack directly.

Quoted 6 lines
Quoted 2 lines

Would this be *after* all the mac80211 processing, i.e. in place of the rx-up-to-stack?

Yes, it would run all the rx handlers normally and then put the resulting skbs into a list instead of calling netif_receive_skb or napi_gro_frags.

Felix,

This seems like split & batch processing. In past (ath9k), we observed some behavioral differences between netif_rx and netif_receive_skb. The intermediate queue in netif_rx changed not just performance but also time sensitive application data. Agree that wireless stack processing might be heavier than ethernet packet processing. If the hardware supports rx decap offload, NAPI processing shouldn't be an issue. right?

-Rajkumar

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k

#14 lore raw

Re: [RFC 2/7] ath10k: Add support to process rx packet in thread

In reply to Felix Fietkau
Quoted 7 lines · Felix Fietkau
Quoted 6 lines · Johannes Berg
Quoted 3 lines · Felix Fietkau

I'm considering testing a different approach (with mt76 initially):
- Add a mac80211 rx function that puts processed skbs into a list instead of handing them to the network stack directly.

Quoted 5 lines
Quoted 2 lines

Would this be *after* all the mac80211 processing, i.e. in place of the rx-up-to-stack?

Yes, it would run all the rx handlers normally and then put the resulting skbs into a list instead of calling netif_receive_skb or napi_gro_frags.

Whatever came of this? I realized I'm running Felix's patch since his mt76 driver needs it. Any chance it will go upstream?

Thanks,
Ben

Quoted 3 lines

- Felix

Signature · 7 lines
Ben Greear <[email protected]>
Candela Technologies Inc  http://www.candelatech.com

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k
#15 lore raw

Re: [RFC 2/7] ath10k: Add support to process rx packet in thread

Quoted 8 lines · Ben Greear
Quoted 7 lines · Felix Fietkau
Quoted 6 lines · Johannes Berg
Quoted 3 lines · Felix Fietkau

I'm considering testing a different approach (with mt76 initially):
- Add a mac80211 rx function that puts processed skbs into a list instead of handing them to the network stack directly.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Would this be *after* all the mac80211 processing, i.e. in place of the rx-up-to-stack?

Yes, it would run all the rx handlers normally and then put the resulting skbs into a list instead of calling netif_receive_skb or napi_gro_frags.

Whatever came of this? I realized I'm running Felix's patch since his mt76 driver needs it. Any chance it will go upstream?

If you're asking about $subject (moving NAPI/RX to a thread), this landed upstream recently:
http://git.kernel.org/linus/adbb4fb028452b1b0488a1a7b66ab856cdf20715

It needs a bit of coaxing to work on a WiFi driver (including: WiFi drivers tend to have a different netdev for NAPI than they expose to /sys/class/net/), but it's there.

I'm not sure if people had something else in mind in the stuff you're quoting though.

Brian

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k

#16 lore raw

Re: [RFC 2/7] ath10k: Add support to process rx packet in thread

Quoted 22 lines · Brian Norris
Quoted 8 lines · Ben Greear
Quoted 7 lines · Felix Fietkau
Quoted 6 lines · Johannes Berg
Quoted 3 lines · Felix Fietkau

I'm considering testing a different approach (with mt76 initially):
- Add a mac80211 rx function that puts processed skbs into a list instead of handing them to the network stack directly.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Would this be *after* all the mac80211 processing, i.e. in place of the rx-up-to-stack?

Yes, it would run all the rx handlers normally and then put the resulting skbs into a list instead of calling netif_receive_skb or napi_gro_frags.

Whatever came of this? I realized I'm running Felix's patch since his mt76 driver needs it. Any chance it will go upstream?

If you're asking about $subject (moving NAPI/RX to a thread), this landed upstream recently:
http://git.kernel.org/linus/adbb4fb028452b1b0488a1a7b66ab856cdf20715

Quoted 6 lines

It needs a bit of coaxing to work on a WiFi driver (including: WiFi drivers tend to have a different netdev for NAPI than they expose to /sys/class/net/), but it's there.

I'm not sure if people had something else in mind in the stuff you're quoting though.

No, I got it confused with something Felix did:

https://github.com/greearb/mt76/blob/master/patches/0001-net-add-support-for-threaded-NAPI-polling.patch

Maybe the NAPI/RX to a thread thing superceded Felix's patch?

Thanks,
Ben

Quoted 3 lines

Brian

Signature · 2 lines
Ben Greear <[email protected]>
Candela Technologies Inc  http://www.candelatech.com
#17 lore raw

Re: [RFC 2/7] ath10k: Add support to process rx packet in thread

Quoted 27 lines · Ben Greear
Quoted 26 lines · Brian Norris
Quoted 8 lines · Ben Greear
Quoted 7 lines · Felix Fietkau
Quoted 6 lines · Johannes Berg
Quoted 3 lines · Felix Fietkau

I'm considering testing a different approach (with mt76 initially):
- Add a mac80211 rx function that puts processed skbs into a list instead of handing them to the network stack directly.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Would this be *after* all the mac80211 processing, i.e. in place of the rx-up-to-stack?

Yes, it would run all the rx handlers normally and then put the resulting skbs into a list instead of calling netif_receive_skb or napi_gro_frags.

Whatever came of this? I realized I'm running Felix's patch since his mt76 driver needs it. Any chance it will go upstream?

If you're asking about $subject (moving NAPI/RX to a thread), this landed upstream recently:
http://git.kernel.org/linus/adbb4fb028452b1b0488a1a7b66ab856cdf20715

It needs a bit of coaxing to work on a WiFi driver (including: WiFi drivers tend to have a different netdev for NAPI than they expose to /sys/class/net/), but it's there.

Quoted 8 lines
Quoted 2 lines

I'm not sure if people had something else in mind in the stuff you're quoting though.

No, I got it confused with something Felix did:

https://github.com/greearb/mt76/blob/master/patches/0001-net-add-support-for-threaded-NAPI-polling.patch

Maybe the NAPI/RX to a thread thing superceded Felix's patch?

Yes, it did and it's in linux-next already.
I sent the following change to make mt76 use it:
https://github.com/nbd168/wireless/commit/1d4ff31437e5aaa999bd7a

- Felix

#18 lore raw

RE: [RFC 2/7] ath10k: Add support to process rx packet in thread

Quoted 52 lines

-----Original Message-----
From: Felix Fietkau <[email protected]>
Sent: Tuesday, March 23, 2021 1:16 PM
To: Ben Greear <[email protected]>; Brian Norris <[email protected]>
Cc: Johannes Berg <[email protected]>; Rajkumar Manoharan <[email protected]>; Rakesh Pillai <[email protected]>; ath10k <[email protected]>; linux-wireless <linux- [email protected]>; Linux Kernel <[email protected]>; Kalle Valo <[email protected]>; David S. Miller <[email protected]>; Jakub Kicinski <[email protected]>; [email protected]; Doug Anderson <[email protected]>; Evan Green <[email protected]>
Subject: Re: [RFC 2/7] ath10k: Add support to process rx packet in thread

Quoted 2 lines · Ben Greear
Quoted 1 line · Brian Norris

On Mon, Mar 22, 2021 at 4:58 PM Ben Greear

Quoted 30 lines · <[email protected]> wrote:
Quoted 21 lines
Quoted 8 lines · Felix Fietkau
Quoted 7 lines · Johannes Berg
Quoted 6 lines · Felix Fietkau
Quoted 4 lines

I'm considering testing a different approach (with mt76 initially):
- Add a mac80211 rx function that puts processed skbs into a list instead of handing them to the network stack directly.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Would this be *after* all the mac80211 processing, i.e. in place of the rx-up-to-stack?

Yes, it would run all the rx handlers normally and then put the resulting skbs into a list instead of calling netif_receive_skb or napi_gro_frags.

Whatever came of this? I realized I'm running Felix's patch since his mt76 driver needs it. Any chance it will go upstream?

If you're asking about $subject (moving NAPI/RX to a thread), this landed upstream recently:
http://git.kernel.org/linus/adbb4fb028452b1b0488a1a7b66ab856cdf20715

Quoted 6 lines

It needs a bit of coaxing to work on a WiFi driver (including: WiFi drivers tend to have a different netdev for NAPI than they expose to /sys/class/net/), but it's there.

I'm not sure if people had something else in mind in the stuff you're quoting though.

No, I got it confused with something Felix did:

Quoted 7 lines
Quoted 1 line

https://github.com/greearb/mt76/blob/master/patches/0001-net-add-

support-for-threaded-NAPI-polling.patch

Quoted 2 lines

Maybe the NAPI/RX to a thread thing superceded Felix's patch?

Yes, it did and it's in linux-next already.
I sent the following change to make mt76 use it:
https://github.com/nbd168/wireless/commit/1d4ff31437e5aaa999bd7a

Hi Felix / Ben,

In case of ath10k (snoc based targets), we have a lot of processing in the NAPI context. Even moving this to threaded NAPI is not helping much due to the load.

Breaking the tasks into multiple context (with the patch series I posted) is helping in improving the throughput. With the current rx_thread based approach, the rx processing is broken into two parallel contexts
1) reaping the packets from the HW
2) processing these packets list and handing it over to mac80211 (and later to the network stack)

This is the primary reason for choosing the rx thread approach.

Thanks,
Rakesh.

Quoted 2 lines

- Felix

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k

#19 lore raw

Re: [RFC 2/7] ath10k: Add support to process rx packet in thread

Quoted 11 lines · Rakesh Pillai

Hi Felix / Ben,

In case of ath10k (snoc based targets), we have a lot of processing in the NAPI context. Even moving this to threaded NAPI is not helping much due to the load.

Breaking the tasks into multiple context (with the patch series I posted) is helping in improving the throughput. With the current rx_thread based approach, the rx processing is broken into two parallel contexts
1) reaping the packets from the HW
2) processing these packets list and handing it over to mac80211 (and later to the network stack)

This is the primary reason for choosing the rx thread approach.

Have you considered the possibility that maybe the problem is that the driver doing too much work?
One example is that you could take advantage of the new 802.3 decap offload to simplify rx processing. Worked for me on mt76 where a dual-core 1.3 GHz A64 can easily handle >1.8 Gbps local TCP rx on a single card, without the rx NAPI thread being the biggest consumer of CPU cycles.

And if you can't do that and still consider all of the metric tons of processing work necessary, you could still do this:
On interrupts, spawn a processing thread that traverses the ring and does the preparation work (instead of NAPI).
From that thread you schedule the threaded NAPI handler that processes these packets further and hands them to mac80211.
To keep the load somewhat balanced, you can limit the number of pre-processed packets in the ring.

- Felix

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k

#20 lore raw

RE: [RFC 2/7] ath10k: Add support to process rx packet in thread

In reply to Rajkumar Manoharan
Quoted 35 lines

-----Original Message-----
From: Rajkumar Manoharan <[email protected]>
Sent: Wednesday, July 22, 2020 3:23 AM
To: Rakesh Pillai <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux-wireless- [email protected]
Subject: Re: [RFC 2/7] ath10k: Add support to process rx packet in thread

Quoted 10 lines · Rakesh Pillai

NAPI instance gets scheduled on a CPU core on which the IRQ was triggered. The processing of rx packets can be CPU intensive and since NAPI cannot be moved to a different CPU core, to get better performance, its better to move the gist of rx packet processing in a high priority thread.

Add the init/deinit part for a thread to process the receive packets.

IMHO this defeat the whole purpose of NAPI. Originally in ath10k irq processing happened in tasklet (high priority) context which in turn push more data to net core even though net is unable to process driver data as both happen in different context (fast producer - slow consumer)
issue. Why can't CPU governor schedule the interrupts in less loaded CPU core?
Otherwise you can play with different RPS and affinity settings to meet your
requirement.

Quoted 1 line

IMO introducing high priority tasklets/threads is not viable solution.

Hi Rajkumar,
In linux, the IRQs are directed to the first core which is booted. I see that all the IRQs are getting routed to CORE0 even if its heavily loaded.

IRQ and NAPI are not under the scheduler's control, since it cannot be moved.
NAPI is scheduled only on the same core as IRQ. But a thread can be moved around by the scheduler based on the CPU load.
This is the reason I went ahead with using thread.

Affinity settings are static, and cannot be done runtime without any downstream userspace entity.

Quoted 2 lines

-Rajkumar

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k

#21 lore raw

Re: [RFC 2/7] ath10k: Add support to process rx packet in thread

Quoted 5 lines · Rakesh Pillai

Hi Rajkumar,
In linux, the IRQs are directed to the first core which is booted. I see that all the IRQs are getting routed to CORE0 even if its heavily loaded.

You should be able to configure the initial IRQ setup so that they don't all go on CPU 0 when you create the IRQ. That obviously doesn't help the case of wanting scheduler to dynamically move the processing around to other CPUs though.

#22 lore raw

RFC 3/7 ath10k: Add module param to enable rx thread

In reply to Rakesh Pillai

Add a module parameter to enable or disable
the processing of received packets in rx thread.

To enable rx packet processing in a thread
context, use the belo command to load driver:
insmod ath10k_snoc.ko rx_thread_enable=1

Tested-on: WCN3990 hw1.0 SNOC WLAN.HL.3.1-01040-QCAHLSWMTPLZ-1

---
 drivers/net/wireless/ath/ath10k/core.h |  1 +
 drivers/net/wireless/ath/ath10k/snoc.c | 24 +++++++++++++++++-------
 2 files changed, 18 insertions(+), 7 deletions(-)
drivers/net/wireless/ath/ath10k/core.h +1 -0
index 96919e8..59bdf11 100644
@@ -998,6 +998,7 @@ struct ath10k {
 	} msa;
 	u8 mac_addr[ETH_ALEN];
 
+	bool rx_thread_enable;
 	struct ath10k_thread rx_thread;
 	enum ath10k_hw_rev hw_rev;
 	u16 dev_id;
drivers/net/wireless/ath/ath10k/snoc.c +17 -7
index 463c34e..f01725b 100644
@@ -26,6 +26,12 @@
 #define CE_POLL_PIPE 4
 #define ATH10K_SNOC_WAKE_IRQ 2
 
+static bool ath10k_rx_thread_enable;
+
+module_param_named(rx_thread_enable, ath10k_rx_thread_enable, bool, 0644);
+
+MODULE_PARM_DESC(rx_thread_enable, "Receive packet processing in thread");
+
 static char *const ce_name[] = {
 	"WLAN_CE_0",
 	"WLAN_CE_1",
@@ -941,7 +947,8 @@ static void ath10k_snoc_hif_stop(struct ath10k *ar)
 
 	napi_synchronize(&ar->napi);
 	napi_disable(&ar->napi);
-	ath10k_core_thread_shutdown(ar, &ar->rx_thread);
+	if (ar->rx_thread_enable)
+		ath10k_core_thread_shutdown(ar, &ar->rx_thread);
 	ath10k_snoc_buffer_cleanup(ar);
 	ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif stop\n");
 }
@@ -954,12 +961,14 @@ static int ath10k_snoc_hif_start(struct ath10k *ar)
 	bitmap_clear(ar_snoc->pending_ce_irqs, 0, CE_COUNT_MAX);
 	napi_enable(&ar->napi);
 
-	ret = ath10k_core_thread_init(ar, &ar->rx_thread,
-				      ath10k_snoc_rx_thread_loop,
-				      "ath10k_rx_thread");
-	if (ret) {
-		ath10k_err(ar, "failed to start rx thread\n");
-		goto rx_thread_fail;
+	if (ar->rx_thread_enable) {
+		ret = ath10k_core_thread_init(ar, &ar->rx_thread,
+					      ath10k_snoc_rx_thread_loop,
+					      "ath10k_rx_thread");
+		if (ret) {
+			ath10k_err(ar, "failed to start rx thread\n");
+			goto rx_thread_fail;
+		}
 	}
 
 	ath10k_snoc_irq_enable(ar);
@@ -1693,6 +1702,7 @@ static int ath10k_snoc_probe(struct platform_device *pdev)
 	}
 
 	ar->rx_thread.ar = ar;
+	ar->rx_thread_enable = ath10k_rx_thread_enable;
 	ar_snoc = ath10k_snoc_priv(ar);
 	ar_snoc->dev = pdev;
 	platform_set_drvdata(pdev, ar);
Signature · 1 line
2.7.4
#23 lore raw

RFC 4/7 ath10k: Do not exhaust budget on process tx completion

In reply to Rakesh Pillai

Currently the entire NAPI budget is marked as exhausted if any tx completion is processed.
In scenarios of bi-directional traffic, this leads to a situation where the irqs are never enabled and the NAPI is rescheuled again and again.

Increase the work done quota by the number of tx completions which are processed in the NAPI context.

Tested-on: WCN3990 hw1.0 SNOC WLAN.HL.3.1-01040-QCAHLSWMTPLZ-1

---
 drivers/net/wireless/ath/ath10k/htt_rx.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
drivers/net/wireless/ath/ath10k/htt_rx.c +6 -9
index cac05e7..a4a6618 100644
@@ -4077,21 +4077,18 @@ int ath10k_htt_txrx_compl_task(struct ath10k *ar, int budget)
 	/* Deliver received data after processing data from hardware */
 	quota = ath10k_htt_rx_deliver_msdu(ar, quota, budget);
 
-	/* From NAPI documentation:
-	 *  The napi poll() function may also process TX completions, in which
-	 *  case if it processes the entire TX ring then it should count that
-	 *  work as the rest of the budget.
-	 */
-	if ((quota < budget) && !kfifo_is_empty(&htt->txdone_fifo))
-		quota = budget;
-
 	/* kfifo_get: called only within txrx_tasklet so it's neatly serialized.
 	 * From kfifo_get() documentation:
 	 *  Note that with only one concurrent reader and one concurrent writer,
 	 *  you don't need extra locking to use these macro.
 	 */
-	while (kfifo_get(&htt->txdone_fifo, &tx_done))
+	while (kfifo_get(&htt->txdone_fifo, &tx_done)) {
 		ath10k_txrx_tx_unref(htt, &tx_done);
+		quota++;
+	}
+
+	if (quota > budget)
+		resched_napi = true;
 
 	ath10k_mac_tx_push_pending(ar);
 
Signature · 7 lines
2.7.4


_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k
#24 lore raw

RFC 5/7 ath10k: Handle the rx packet processing in thread

In reply to Rakesh Pillai

Add the support to handle the receive packet and the tx completion processing in a thread context if the feature has been enabled via module parameter.

Tested-on: WCN3990 hw1.0 SNOC WLAN.HL.3.1-01040-QCAHLSWMTPLZ-1

---
 drivers/net/wireless/ath/ath10k/core.c   |  8 ++++++
 drivers/net/wireless/ath/ath10k/core.h   |  4 +++
 drivers/net/wireless/ath/ath10k/htt.h    |  2 ++
 drivers/net/wireless/ath/ath10k/htt_rx.c | 46 +++++++++++++++++++++++++++-----
 drivers/net/wireless/ath/ath10k/snoc.c   | 12 +++++++--
 5 files changed, 64 insertions(+), 8 deletions(-)
drivers/net/wireless/ath/ath10k/core.c +8 -0
index 2b520a0..4064fa2 100644
@@ -668,6 +668,14 @@ static unsigned int ath10k_core_get_fw_feature_str(char *buf,
 	return scnprintf(buf, buf_len, "%s", ath10k_core_fw_feature_str[feat]);
 }
 
+void ath10k_core_thread_post_event(struct ath10k_thread *thread,
+				   enum ath10k_thread_events event)
+{
+	set_bit(event, thread->event_flags);
+	wake_up(&thread->wait_q);
+}
+EXPORT_SYMBOL(ath10k_core_thread_post_event);
+
 int ath10k_core_thread_shutdown(struct ath10k *ar,
 				struct ath10k_thread *thread)
 {
drivers/net/wireless/ath/ath10k/core.h +4 -0
index 59bdf11..596d31b 100644
@@ -974,6 +974,8 @@ struct ath10k_bus_params {
 
 enum ath10k_thread_events {
 	ATH10K_THREAD_EVENT_SHUTDOWN,
+	ATH10K_THREAD_EVENT_RX_POST,
+	ATH10K_THREAD_EVENT_TX_POST,
 	ATH10K_THREAD_EVENT_MAX,
 };
 
@@ -1294,6 +1296,8 @@ static inline bool ath10k_peer_stats_enabled(struct ath10k *ar)
 
 extern unsigned long ath10k_coredump_mask;
 
+void ath10k_core_thread_post_event(struct ath10k_thread *thread,
+				   enum ath10k_thread_events event);
 int ath10k_core_thread_shutdown(struct ath10k *ar,
 				struct ath10k_thread *thread);
 int ath10k_core_thread_init(struct ath10k *ar,
drivers/net/wireless/ath/ath10k/htt.h +2 -0
index cad5949..e3cb723 100644
@@ -1970,6 +1970,8 @@ struct ath10k_htt {
 		spinlock_t lock;
 	} rx_ring;
 
+	/* Protects access to in order indication queue */
+	spinlock_t rx_in_ord_q_lock;
 	unsigned int prefetch_len;
 
 	/* Protects access to pending_tx, num_pending_tx */
drivers/net/wireless/ath/ath10k/htt_rx.c +40 -6

76 lines not on this page · raw message

drivers/net/wireless/ath/ath10k/snoc.c +10 -2
index f01725b..3eb5eac 100644
@@ -920,6 +920,7 @@ int ath10k_snoc_rx_thread_loop(void *data)
 	struct ath10k_thread *rx_thread = data;
 	struct ath10k *ar = rx_thread->ar;
 	bool shutdown = false;
+	u32 thread_budget = 8192;
 
 	ath10k_dbg(ar, ATH10K_DBG_SNOC, "rx thread started\n");
 	set_user_nice(current, -1);
@@ -927,8 +928,14 @@ int ath10k_snoc_rx_thread_loop(void *data)
 	while (!shutdown) {
 		wait_event_interruptible(
 			rx_thread->wait_q,
-			(test_bit(ATH10K_THREAD_EVENT_SHUTDOWN,
+			(test_and_clear_bit(ATH10K_THREAD_EVENT_RX_POST,
+					    rx_thread->event_flags) ||
+			 test_and_clear_bit(ATH10K_THREAD_EVENT_TX_POST,
+					    rx_thread->event_flags) ||
+			 test_bit(ATH10K_THREAD_EVENT_SHUTDOWN,
 				  rx_thread->event_flags)));
+
+		ath10k_htt_txrx_compl_task(ar, thread_budget);
 		if (test_and_clear_bit(ATH10K_THREAD_EVENT_SHUTDOWN,
 				       rx_thread->event_flags))
 			shutdown = true;
@@ -1235,7 +1242,8 @@ static int ath10k_snoc_napi_poll(struct napi_struct *ctx, int budget)
 			ath10k_ce_enable_interrupt(ar, ce_id);
 		}
 
-	done = ath10k_htt_txrx_compl_task(ar, budget);
+	if (!ar->rx_thread_enable)
+		done = ath10k_htt_txrx_compl_task(ar, budget);
 
 	if (done < budget)
 		napi_complete(ctx);
Signature · 1 line
2.7.4
#25 lore raw

RFC 6/7 ath10k: Add deliver to stack from thread context

In reply to Rakesh Pillai

When the receive packets are submitted to the stack from a thread context, the NAPI handle should be passed as NULL to the function ieee80211_rx_napi. This will make sure that the packets are submitted to stack via non-napi method

Tested-on: WCN3990 hw1.0 SNOC WLAN.HL.3.1-01040-QCAHLSWMTPLZ-1

---
 drivers/net/wireless/ath/ath10k/htt_rx.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/wireless/ath/ath10k/htt_rx.c +4 -1
index becbd56..85c169c 100644
@@ -1321,7 +1321,10 @@ static void ath10k_process_rx(struct ath10k *ar, struct sk_buff *skb)
 	trace_ath10k_rx_hdr(ar, skb->data, skb->len);
 	trace_ath10k_rx_payload(ar, skb->data, skb->len);
 
-	ieee80211_rx_napi(ar->hw, NULL, skb, &ar->napi);
+	if (in_serving_softirq())
+		ieee80211_rx_napi(ar->hw, NULL, skb, &ar->napi);
+	else
+		ieee80211_rx_napi(ar->hw, NULL, skb, NULL);
 }
 
 static int ath10k_htt_rx_nwifi_hdrlen(struct ath10k *ar,
Signature · 1 line
2.7.4
#26 lore raw

RFC 7/7 ath10k: Handle rx thread suspend and resume

In reply to Rakesh Pillai

During the system suspend or resume, the rx thread also needs to be suspended or resume respectively.

Handle the rx thread as well during the system
suspend and resume.

Tested-on: WCN3990 hw1.0 SNOC WLAN.HL.3.1-01040-QCAHLSWMTPLZ-1

---
 drivers/net/wireless/ath/ath10k/core.c | 23 ++++++++++++++++++
 drivers/net/wireless/ath/ath10k/core.h |  5 ++++
 drivers/net/wireless/ath/ath10k/snoc.c | 44 +++++++++++++++++++++++++++++++++-
 3 files changed, 71 insertions(+), 1 deletion(-)
drivers/net/wireless/ath/ath10k/core.c +23 -0
index 4064fa2..b82b355 100644
@@ -668,6 +668,27 @@ static unsigned int ath10k_core_get_fw_feature_str(char *buf,
 	return scnprintf(buf, buf_len, "%s", ath10k_core_fw_feature_str[feat]);
 }
 
+int ath10k_core_thread_suspend(struct ath10k_thread *thread)
+{
+	ath10k_dbg(thread->ar, ATH10K_DBG_BOOT, "Suspending thread %s\n",
+		   thread->name);
+	set_bit(ATH10K_THREAD_EVENT_SUSPEND, thread->event_flags);
+	wait_for_completion(&thread->suspend);
+
+	return 0;
+}
+EXPORT_SYMBOL(ath10k_core_thread_suspend);
+
+int ath10k_core_thread_resume(struct ath10k_thread *thread)
+{
+	ath10k_dbg(thread->ar, ATH10K_DBG_BOOT, "Resuming thread %s\n",
+		   thread->name);
+	complete(&thread->resume);
+
+	return 0;
+}
+EXPORT_SYMBOL(ath10k_core_thread_resume);
+
 void ath10k_core_thread_post_event(struct ath10k_thread *thread,
 				   enum ath10k_thread_events event)
 {
@@ -700,6 +721,8 @@ int ath10k_core_thread_init(struct ath10k *ar,
 
 	init_waitqueue_head(&thread->wait_q);
 	init_completion(&thread->shutdown);
+	init_completion(&thread->suspend);
+	init_completion(&thread->resume);
 	memcpy(thread->name, thread_name, ATH10K_THREAD_NAME_SIZE_MAX);
 	clear_bit(ATH10K_THREAD_EVENT_SHUTDOWN, thread->event_flags);
 	ath10k_info(ar, "Starting thread %s\n", thread_name);
drivers/net/wireless/ath/ath10k/core.h +5 -0
index 596d31b..df65e75 100644
@@ -976,6 +976,7 @@ enum ath10k_thread_events {
 	ATH10K_THREAD_EVENT_SHUTDOWN,
 	ATH10K_THREAD_EVENT_RX_POST,
 	ATH10K_THREAD_EVENT_TX_POST,
+	ATH10K_THREAD_EVENT_SUSPEND,
 	ATH10K_THREAD_EVENT_MAX,
 };
 
@@ -983,6 +984,8 @@ struct ath10k_thread {
 	struct ath10k *ar;
 	struct task_struct *task;
 	struct completion shutdown;
+	struct completion suspend;
+	struct completion resume;
 	wait_queue_head_t wait_q;
 	DECLARE_BITMAP(event_flags, ATH10K_THREAD_EVENT_MAX);
 	char name[ATH10K_THREAD_NAME_SIZE_MAX];
@@ -1296,6 +1299,8 @@ static inline bool ath10k_peer_stats_enabled(struct ath10k *ar)
 
 extern unsigned long ath10k_coredump_mask;
 
+int ath10k_core_thread_suspend(struct ath10k_thread *thread);
+int ath10k_core_thread_resume(struct ath10k_thread *thread);
 void ath10k_core_thread_post_event(struct ath10k_thread *thread,
 				   enum ath10k_thread_events event);
 int ath10k_core_thread_shutdown(struct ath10k *ar,
drivers/net/wireless/ath/ath10k/snoc.c +43 -1

77 lines not on this page · raw message

Signature · 1 line
2.7.4
#27 lore raw

Re: [RFC 7/7] ath10k: Handle rx thread suspend and resume

your patch seem to only affect the WCN3990 chipset. all other ath10k supported chipset are not supported here. so you see a chance to implement this more generic?

Sebastian

Am 21.07.2020 um 19:14 schrieb Rakesh Pillai:

Quoted 170 lines

During the system suspend or resume, the rx thread also needs to be suspended or resume respectively.

Handle the rx thread as well during the system
suspend and resume.

Tested-on: WCN3990 hw1.0 SNOC WLAN.HL.3.1-01040-QCAHLSWMTPLZ-1

---
  drivers/net/wireless/ath/ath10k/core.c | 23 ++++++++++++++++++
  drivers/net/wireless/ath/ath10k/core.h |  5 ++++
  drivers/net/wireless/ath/ath10k/snoc.c | 44 +++++++++++++++++++++++++++++++++-
  3 files changed, 71 insertions(+), 1 deletion(-)
drivers/net/wireless/ath/ath10k/core.c +23 -0
index 4064fa2..b82b355 100644
@@ -668,6 +668,27 @@ static unsigned int ath10k_core_get_fw_feature_str(char *buf,
  	return scnprintf(buf, buf_len, "%s", ath10k_core_fw_feature_str[feat]);
  }
 
+int ath10k_core_thread_suspend(struct ath10k_thread *thread)
+{
+	ath10k_dbg(thread->ar, ATH10K_DBG_BOOT, "Suspending thread %s\n",
+		   thread->name);
+	set_bit(ATH10K_THREAD_EVENT_SUSPEND, thread->event_flags);
+	wait_for_completion(&thread->suspend);
+
+	return 0;
+}
+EXPORT_SYMBOL(ath10k_core_thread_suspend);
+
+int ath10k_core_thread_resume(struct ath10k_thread *thread)
+{
+	ath10k_dbg(thread->ar, ATH10K_DBG_BOOT, "Resuming thread %s\n",
+		   thread->name);
+	complete(&thread->resume);
+
+	return 0;
+}
+EXPORT_SYMBOL(ath10k_core_thread_resume);
+
  void ath10k_core_thread_post_event(struct ath10k_thread *thread,
  				   enum ath10k_thread_events event)
  {
@@ -700,6 +721,8 @@ int ath10k_core_thread_init(struct ath10k *ar,
 
  	init_waitqueue_head(&thread->wait_q);
  	init_completion(&thread->shutdown);
+	init_completion(&thread->suspend);
+	init_completion(&thread->resume);
  	memcpy(thread->name, thread_name, ATH10K_THREAD_NAME_SIZE_MAX);
  	clear_bit(ATH10K_THREAD_EVENT_SHUTDOWN, thread->event_flags);
  	ath10k_info(ar, "Starting thread %s\n", thread_name);
drivers/net/wireless/ath/ath10k/core.h +5 -0
index 596d31b..df65e75 100644
@@ -976,6 +976,7 @@ enum ath10k_thread_events {
  	ATH10K_THREAD_EVENT_SHUTDOWN,
  	ATH10K_THREAD_EVENT_RX_POST,
  	ATH10K_THREAD_EVENT_TX_POST,
+	ATH10K_THREAD_EVENT_SUSPEND,
  	ATH10K_THREAD_EVENT_MAX,
  };
 
@@ -983,6 +984,8 @@ struct ath10k_thread {
  	struct ath10k *ar;
  	struct task_struct *task;
  	struct completion shutdown;
+	struct completion suspend;
+	struct completion resume;
  	wait_queue_head_t wait_q;
  	DECLARE_BITMAP(event_flags, ATH10K_THREAD_EVENT_MAX);
  	char name[ATH10K_THREAD_NAME_SIZE_MAX];
@@ -1296,6 +1299,8 @@ static inline bool ath10k_peer_stats_enabled(struct ath10k *ar)
 
  extern unsigned long ath10k_coredump_mask;
 
+int ath10k_core_thread_suspend(struct ath10k_thread *thread);
+int ath10k_core_thread_resume(struct ath10k_thread *thread);
  void ath10k_core_thread_post_event(struct ath10k_thread *thread,
  				   enum ath10k_thread_events event);
  int ath10k_core_thread_shutdown(struct ath10k *ar,
drivers/net/wireless/ath/ath10k/snoc.c +43 -1
index 3eb5eac..a373b2b 100644
@@ -932,13 +932,31 @@ int ath10k_snoc_rx_thread_loop(void *data)
  					    rx_thread->event_flags) ||
  			 test_and_clear_bit(ATH10K_THREAD_EVENT_TX_POST,
  					    rx_thread->event_flags) ||
+			 test_bit(ATH10K_THREAD_EVENT_SUSPEND,
+				  rx_thread->event_flags) ||
  			 test_bit(ATH10K_THREAD_EVENT_SHUTDOWN,
  				  rx_thread->event_flags)));
 
+		if (test_and_clear_bit(ATH10K_THREAD_EVENT_SUSPEND,
+				       rx_thread->event_flags)) {
+			complete(&rx_thread->suspend);
+			ath10k_info(ar, "rx thread suspend\n");
+			wait_for_completion(&rx_thread->resume);
+			ath10k_info(ar, "rx thread resume\n");
+		}
+
  		ath10k_htt_txrx_compl_task(ar, thread_budget);
  		if (test_and_clear_bit(ATH10K_THREAD_EVENT_SHUTDOWN,
  				       rx_thread->event_flags))
  			shutdown = true;
+
+		if (test_and_clear_bit(ATH10K_THREAD_EVENT_SUSPEND,
+				       rx_thread->event_flags)) {
+			complete(&rx_thread->suspend);
+			ath10k_info(ar, "rx thread suspend\n");
+			wait_for_completion(&rx_thread->resume);
+			ath10k_info(ar, "rx thread resume\n");
+		}
  	}
 
  	ath10k_dbg(ar, ATH10K_DBG_SNOC, "rx thread exiting\n");
@@ -1133,15 +1151,30 @@ static int ath10k_snoc_hif_suspend(struct ath10k *ar)
  	if (!device_may_wakeup(ar->dev))
  		return -EPERM;
 
+	if (ar->rx_thread_enable) {
+		ret = ath10k_core_thread_suspend(&ar->rx_thread);
+		if (ret) {
+			ath10k_err(ar, "failed to suspend rx_thread, %d\n",
+				   ret);
+			return ret;
+		}
+	}
+
  	ret = enable_irq_wake(ar_snoc->ce_irqs[ATH10K_SNOC_WAKE_IRQ].irq_line);
  	if (ret) {
  		ath10k_err(ar, "failed to enable wakeup irq :%d\n", ret);
-		return ret;
+		goto fail;
  	}
 
  	ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc device suspended\n");
 
  	return ret;
+
+fail:
+	if (ar->rx_thread_enable)
+		ath10k_core_thread_resume(&ar->rx_thread);
+
+	return ret;
  }
 
  static int ath10k_snoc_hif_resume(struct ath10k *ar)
@@ -1158,6 +1191,15 @@ static int ath10k_snoc_hif_resume(struct ath10k *ar)
  		return ret;
  	}
 
+	if (ar->rx_thread_enable) {
+		ret = ath10k_core_thread_resume(&ar->rx_thread);
+		if (ret) {
+			ath10k_err(ar, "failed to suspend rx_thread, %d\n",
+				   ret);
+			return ret;
+		}
+	}
+
  	ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc device resumed\n");
 
  	return ret;
#28 lore raw

RE: [RFC 7/7] ath10k: Handle rx thread suspend and resume

Quoted 12 lines

-----Original Message-----
From: Sebastian Gottschall <[email protected]>
Sent: Friday, July 24, 2020 4:36 AM
To: Rakesh Pillai <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC 7/7] ath10k: Handle rx thread suspend and resume

Quoted 5 lines

your patch seem to only affect the WCN3990 chipset. all other ath10k supported chipset are not supported here. so you see a chance to implement this more generic?

Sebastian

Hi Sebastian,

A generic core for handling threads is added with this patchset.
So the handling of rx packet processing in thread can always be extended to other targets, if they wish so.

The thread related APIs are in core.c which gives all the other targets access to these APIs for using them.

Thanks,
Rakesh Pillai.

Quoted 187 lines

Am 21.07.2020 um 19:14 schrieb Rakesh Pillai:

Quoted 6 lines

During the system suspend or resume, the rx thread also needs to be suspended or resume respectively.

Handle the rx thread as well during the system
suspend and resume.

Quoted 7 lines

Tested-on: WCN3990 hw1.0 SNOC WLAN.HL.3.1-01040-QCAHLSWMTPLZ-1

---
  drivers/net/wireless/ath/ath10k/core.c | 23 ++++++++++++++++++
  drivers/net/wireless/ath/ath10k/core.h |  5 ++++
  drivers/net/wireless/ath/ath10k/snoc.c | 44

+++++++++++++++++++++++++++++++++-

Review

Quoted 3 lines
  3 files changed, 71 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

b/drivers/net/wireless/ath/ath10k/core.c

drivers/net/wireless/ath/ath10k/core.c static unsigned int

Quoted 4 lines

index 4064fa2..b82b355 100644

drivers/net/wireless/ath/ath10k/core.c +0 -0
@@ -668,6 +668,27 @@ static unsigned int

ath10k_core_get_fw_feature_str(char *buf,

drivers/net/wireless/ath/ath10k/core.c static unsigned int · line 668

Quoted 1 line
drivers/net/wireless/ath/ath10k/core.c +0 -0
  	return scnprintf(buf, buf_len, "%s",

ath10k_core_fw_feature_str[feat]);

drivers/net/wireless/ath/ath10k/core.c static unsigned int ath10k_core_get_fw_feature_str(char *buf,

Quoted 5 lines
drivers/net/wireless/ath/ath10k/core.c +3 -0
  }
 
+int ath10k_core_thread_suspend(struct ath10k_thread *thread)
+{
+	ath10k_dbg(thread->ar, ATH10K_DBG_BOOT, "Suspending thread

%s\n",

drivers/net/wireless/ath/ath10k/core.c static unsigned int ath10k_core_get_fw_feature_str(char *buf,

Quoted 11 lines
drivers/net/wireless/ath/ath10k/core.c +11 -0
+		   thread->name);
+	set_bit(ATH10K_THREAD_EVENT_SUSPEND, thread->event_flags);
+	wait_for_completion(&thread->suspend);
+
+	return 0;
+}
+EXPORT_SYMBOL(ath10k_core_thread_suspend);
+
+int ath10k_core_thread_resume(struct ath10k_thread *thread)
+{
+	ath10k_dbg(thread->ar, ATH10K_DBG_BOOT, "Resuming thread

%s\n",

Quoted 11 lines
drivers/net/wireless/ath/ath10k/core.c +7 -0
+		   thread->name);
+	complete(&thread->resume);
+
+	return 0;
+}
+EXPORT_SYMBOL(ath10k_core_thread_resume);
+
  void ath10k_core_thread_post_event(struct ath10k_thread *thread,
  				   enum ath10k_thread_events event)
  {

drivers/net/wireless/ath/ath10k/core.c int ath10k_core_thread_init(struct ath10k *ar, · line 726

Quoted 6 lines
drivers/net/wireless/ath/ath10k/core.c +2 -0
@@ -700,6 +721,8 @@ int ath10k_core_thread_init(struct ath10k *ar,
 
  	init_waitqueue_head(&thread->wait_q);
  	init_completion(&thread->shutdown);
+	init_completion(&thread->suspend);
+	init_completion(&thread->resume);
  	memcpy(thread->name, thread_name,

ATH10K_THREAD_NAME_SIZE_MAX);

Review

Quoted 4 lines
drivers/net/wireless/ath/ath10k/core.c +0 -0
  	clear_bit(ATH10K_THREAD_EVENT_SHUTDOWN, thread-
 event_flags);

ath10k_info(ar, "Starting thread %s\n", thread_name);

(quoted diff) +0 -0

b/drivers/net/wireless/ath/ath10k/core.h

drivers/net/wireless/ath/ath10k/core.h static inline bool

Quoted 21 lines

index 596d31b..df65e75 100644

drivers/net/wireless/ath/ath10k/core.h +3 -0
@@ -976,6 +976,7 @@ enum ath10k_thread_events {
  	ATH10K_THREAD_EVENT_SHUTDOWN,
  	ATH10K_THREAD_EVENT_RX_POST,
  	ATH10K_THREAD_EVENT_TX_POST,
+	ATH10K_THREAD_EVENT_SUSPEND,
  	ATH10K_THREAD_EVENT_MAX,
  };
 
@@ -983,6 +984,8 @@ struct ath10k_thread {
  	struct ath10k *ar;
  	struct task_struct *task;
  	struct completion shutdown;
+	struct completion suspend;
+	struct completion resume;
  	wait_queue_head_t wait_q;
  	DECLARE_BITMAP(event_flags, ATH10K_THREAD_EVENT_MAX);
  	char name[ATH10K_THREAD_NAME_SIZE_MAX];
@@ -1296,6 +1299,8 @@ static inline bool

ath10k_peer_stats_enabled(struct ath10k *ar)

Review

Quoted 9 lines
drivers/net/wireless/ath/ath10k/core.h +2 -0
  extern unsigned long ath10k_coredump_mask;
 
+int ath10k_core_thread_suspend(struct ath10k_thread *thread);
+int ath10k_core_thread_resume(struct ath10k_thread *thread);
  void ath10k_core_thread_post_event(struct ath10k_thread *thread,
  				   enum ath10k_thread_events event);
  int ath10k_core_thread_shutdown(struct ath10k *ar,
(quoted diff) +0 -0

b/drivers/net/wireless/ath/ath10k/snoc.c

drivers/net/wireless/ath/ath10k/snoc.c int ath10k_snoc_rx_thread_loop(void *data) · line 933

Quoted 6 lines

index 3eb5eac..a373b2b 100644

drivers/net/wireless/ath/ath10k/snoc.c +0 -0
@@ -932,13 +932,31 @@ int ath10k_snoc_rx_thread_loop(void *data)
  					    rx_thread->event_flags) ||
 

test_and_clear_bit(ATH10K_THREAD_EVENT_TX_POST,

Quoted 6 lines
drivers/net/wireless/ath/ath10k/snoc.c +2 -0
  					    rx_thread->event_flags) ||
+			 test_bit(ATH10K_THREAD_EVENT_SUSPEND,
+				  rx_thread->event_flags) ||
  			 test_bit(ATH10K_THREAD_EVENT_SHUTDOWN,
  				  rx_thread->event_flags)));
 

drivers/net/wireless/ath/ath10k/snoc.c int ath10k_snoc_rx_thread_loop(void *data)

Quoted 10 lines
drivers/net/wireless/ath/ath10k/snoc.c +8 -0
+		if (test_and_clear_bit(ATH10K_THREAD_EVENT_SUSPEND,
+				       rx_thread->event_flags)) {
+			complete(&rx_thread->suspend);
+			ath10k_info(ar, "rx thread suspend\n");
+			wait_for_completion(&rx_thread->resume);
+			ath10k_info(ar, "rx thread resume\n");
+		}
+
  		ath10k_htt_txrx_compl_task(ar, thread_budget);
  		if

(test_and_clear_bit(ATH10K_THREAD_EVENT_SHUTDOWN,

drivers/net/wireless/ath/ath10k/snoc.c static int ath10k_snoc_hif_suspend(struct

Quoted 14 lines
drivers/net/wireless/ath/ath10k/snoc.c +8 -0
  				       rx_thread->event_flags))
  			shutdown = true;
+
+		if (test_and_clear_bit(ATH10K_THREAD_EVENT_SUSPEND,
+				       rx_thread->event_flags)) {
+			complete(&rx_thread->suspend);
+			ath10k_info(ar, "rx thread suspend\n");
+			wait_for_completion(&rx_thread->resume);
+			ath10k_info(ar, "rx thread resume\n");
+		}
  	}
 
  	ath10k_dbg(ar, ATH10K_DBG_SNOC, "rx thread exiting\n");
@@ -1133,15 +1151,30 @@ static int ath10k_snoc_hif_suspend(struct

ath10k *ar)

drivers/net/wireless/ath/ath10k/snoc.c static int ath10k_snoc_hif_resume(struct ath10k

Quoted 33 lines
drivers/net/wireless/ath/ath10k/snoc.c +16 -1
  	if (!device_may_wakeup(ar->dev))
  		return -EPERM;
 
+	if (ar->rx_thread_enable) {
+		ret = ath10k_core_thread_suspend(&ar->rx_thread);
+		if (ret) {
+			ath10k_err(ar, "failed to suspend rx_thread, %d\n",
+				   ret);
+			return ret;
+		}
+	}
+
  	ret = enable_irq_wake(ar_snoc-
 ce_irqs[ATH10K_SNOC_WAKE_IRQ].irq_line);
  	if (ret) {
  		ath10k_err(ar, "failed to enable wakeup irq :%d\n", ret);
-		return ret;
+		goto fail;
  	}
 
  	ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc device suspended\n");
 
  	return ret;
+
+fail:
+	if (ar->rx_thread_enable)
+		ath10k_core_thread_resume(&ar->rx_thread);
+
+	return ret;
  }
 

static int ath10k_snoc_hif_resume(struct ath10k *ar)

drivers/net/wireless/ath/ath10k/snoc.c +0 -0
@@ -1158,6 +1191,15 @@ static int ath10k_snoc_hif_resume(struct ath10k

*ar)

Quoted 14 lines
drivers/net/wireless/ath/ath10k/snoc.c +9 -0
  		return ret;
  	}
 
+	if (ar->rx_thread_enable) {
+		ret = ath10k_core_thread_resume(&ar->rx_thread);
+		if (ret) {
+			ath10k_err(ar, "failed to suspend rx_thread, %d\n",
+				   ret);
+			return ret;
+		}
+	}
+
  	ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc device resumed\n");
 
Quoted 1 line

drivers/net/wireless/ath/ath10k/snoc.c static int ath10k_snoc_hif_resume(struct ath10k · line 1205

Quoted 1 line
drivers/net/wireless/ath/ath10k/snoc.c +0 -0
  	return ret;

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k

#29 lore raw
In reply to Rakesh Pillai
Quoted 14 lines · Rakesh Pillai

NAPI gets scheduled on the CPU core which got the interrupt. The linux scheduler cannot move it to a different core, even if the CPU on which NAPI is running is heavily loaded. This can lead to degraded wifi performance when running traffic at peak data rates.

A thread on the other hand can be moved to different CPU cores, if the one on which its running is heavily loaded. During high incoming data traffic, this gives better performance, since the thread can be moved to a less loaded or sometimes even a more powerful CPU core to account for the required CPU performance in order to process the incoming packets.

Quoted 3 lines

This patch series adds the support to use a high priority thread to process the incoming packets, as opposed to everything being done in NAPI context.

I don't see why this problem is limited to the ath10k driver. I expect it applies to all drivers using NAPI. So shouldn't you be solving this in the NAPI core? Allow a driver to request the NAPI core uses a thread?

Andrew

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k

#30 lore raw
Quoted 15 lines · Andrew Lunn
Quoted 14 lines · Rakesh Pillai

NAPI gets scheduled on the CPU core which got the interrupt. The linux scheduler cannot move it to a different core, even if the CPU on which NAPI is running is heavily loaded. This can lead to degraded wifi performance when running traffic at peak data rates.

A thread on the other hand can be moved to different CPU cores, if the one on which its running is heavily loaded. During high incoming data traffic, this gives better performance, since the thread can be moved to a less loaded or sometimes even a more powerful CPU core to account for the required CPU performance in order to process the incoming packets.

Quoted 8 lines
Quoted 3 lines

This patch series adds the support to use a high priority thread to process the incoming packets, as opposed to everything being done in NAPI context.

I don't see why this problem is limited to the ath10k driver. I expect it applies to all drivers using NAPI. So shouldn't you be solving this in the NAPI core? Allow a driver to request the NAPI core uses a thread?

What's more, you should be able to configure interrupt affinity to steer RX processing onto a desired CPU core, is not that working for you somehow?

Signature · 6 lines
Florian

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k
#31 lore raw
Quoted 32 lines

-----Original Message-----
From: Florian Fainelli <[email protected]>
Sent: Tuesday, July 21, 2020 11:35 PM
To: Andrew Lunn <[email protected]>; Rakesh Pillai <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC 0/7] Add support to process rx packets in thread

Quoted 19 lines · Andrew Lunn
Quoted 17 lines · Rakesh Pillai

NAPI gets scheduled on the CPU core which got the interrupt. The linux scheduler cannot move it to a different core, even if the CPU on which NAPI is running is heavily loaded. This can lead to degraded wifi performance when running traffic at peak data rates.

A thread on the other hand can be moved to different CPU cores, if the one on which its running is heavily loaded. During high incoming data traffic, this gives better performance, since the thread can be moved to a less loaded or sometimes even a more powerful CPU core to account for the required CPU performance in order to process the incoming packets.

This patch series adds the support to use a high priority thread to process the incoming packets, as opposed to everything being done in NAPI context.

Quoted 8 lines
Quoted 4 lines

I don't see why this problem is limited to the ath10k driver. I expect it applies to all drivers using NAPI. So shouldn't you be solving this in the NAPI core? Allow a driver to request the NAPI core uses a thread?

What's more, you should be able to configure interrupt affinity to steer RX processing onto a desired CPU core, is not that working for you somehow?

Hi Florian,
Yes, the affinity of IRQ does work for me.
But the affinity of IRQ does not happen runtime based on load.

Quoted 2 lines

--
Florian

#32 lore raw
Quoted 37 lines · Rakesh Pillai
Quoted 37 lines

-----Original Message-----
From: Florian Fainelli <[email protected]>
Sent: Tuesday, July 21, 2020 11:35 PM
To: Andrew Lunn <[email protected]>; Rakesh Pillai <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC 0/7] Add support to process rx packets in thread

Quoted 23 lines · Andrew Lunn
Quoted 14 lines · Rakesh Pillai

NAPI gets scheduled on the CPU core which got the interrupt. The linux scheduler cannot move it to a different core, even if the CPU on which NAPI is running is heavily loaded. This can lead to degraded wifi performance when running traffic at peak data rates.

A thread on the other hand can be moved to different CPU cores, if the one on which its running is heavily loaded. During high incoming data traffic, this gives better performance, since the thread can be moved to a less loaded or sometimes even a more powerful CPU core to account for the required CPU performance in order to process the incoming packets.

Quoted 3 lines

This patch series adds the support to use a high priority thread to process the incoming packets, as opposed to everything being done in NAPI context.

I don't see why this problem is limited to the ath10k driver. I expect it applies to all drivers using NAPI. So shouldn't you be solving this in the NAPI core? Allow a driver to request the NAPI core uses a thread?

Quoted 7 lines
Quoted 3 lines

What's more, you should be able to configure interrupt affinity to steer RX processing onto a desired CPU core, is not that working for you somehow?

Hi Florian,
Yes, the affinity of IRQ does work for me.
But the affinity of IRQ does not happen runtime based on load.

It can if you also run irqbalance.

Signature · 6 lines
Florian

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k
#33 lore raw
Quoted 57 lines

-----Original Message-----
From: Florian Fainelli <[email protected]>
Sent: Friday, July 24, 2020 12:33 AM
To: Rakesh Pillai <[email protected]>; 'Andrew Lunn' <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC 0/7] Add support to process rx packets in thread

Quoted 6 lines · Rakesh Pillai
Quoted 6 lines

-----Original Message-----
From: Florian Fainelli <[email protected]>
Sent: Tuesday, July 21, 2020 11:35 PM
To: Andrew Lunn <[email protected]>; Rakesh Pillai

<[email protected]>

Quoted 2 lines
Quoted 2 lines

Cc: [email protected]; [email protected]; linux- [email protected]; [email protected];

[email protected];

Quoted 33 lines
Quoted 32 lines

[email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC 0/7] Add support to process rx packets in thread

Quoted 15 lines · Andrew Lunn
Quoted 14 lines · Rakesh Pillai

NAPI gets scheduled on the CPU core which got the interrupt. The linux scheduler cannot move it to a different core, even if the CPU on which NAPI is running is heavily loaded. This can lead to degraded wifi performance when running traffic at peak data rates.

A thread on the other hand can be moved to different CPU cores, if the one on which its running is heavily loaded. During high incoming data traffic, this gives better performance, since the thread can be moved to a less loaded or sometimes even a more powerful CPU core to account for the required CPU performance in order to process the incoming packets.

Quoted 8 lines
Quoted 3 lines

This patch series adds the support to use a high priority thread to process the incoming packets, as opposed to everything being done in NAPI context.

I don't see why this problem is limited to the ath10k driver. I expect it applies to all drivers using NAPI. So shouldn't you be solving this in the NAPI core? Allow a driver to request the NAPI core uses a thread?

What's more, you should be able to configure interrupt affinity to steer RX processing onto a desired CPU core, is not that working for you somehow?

Quoted 5 lines
Quoted 3 lines

Hi Florian,
Yes, the affinity of IRQ does work for me.
But the affinity of IRQ does not happen runtime based on load.

It can if you also run irqbalance.

Hi Florian,

Is it some kernel feature ? Sorry I am not aware of this ? I know it can be done in userspace.

Quoted 2 lines

--
Florian

#34 lore raw
Quoted 61 lines · Rakesh Pillai
Quoted 61 lines

-----Original Message-----
From: Florian Fainelli <[email protected]>
Sent: Friday, July 24, 2020 12:33 AM
To: Rakesh Pillai <[email protected]>; 'Andrew Lunn' <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC 0/7] Add support to process rx packets in thread

Quoted 6 lines · Rakesh Pillai
Quoted 6 lines

-----Original Message-----
From: Florian Fainelli <[email protected]>
Sent: Tuesday, July 21, 2020 11:35 PM
To: Andrew Lunn <[email protected]>; Rakesh Pillai

<[email protected]>

Quoted 2 lines
Quoted 2 lines

Cc: [email protected]; [email protected]; linux- [email protected]; [email protected];

[email protected];

Quoted 36 lines
Quoted 24 lines

[email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC 0/7] Add support to process rx packets in thread

Quoted 19 lines · Andrew Lunn
Quoted 17 lines · Rakesh Pillai

NAPI gets scheduled on the CPU core which got the interrupt. The linux scheduler cannot move it to a different core, even if the CPU on which NAPI is running is heavily loaded. This can lead to degraded wifi performance when running traffic at peak data rates.

A thread on the other hand can be moved to different CPU cores, if the one on which its running is heavily loaded. During high incoming data traffic, this gives better performance, since the thread can be moved to a less loaded or sometimes even a more powerful CPU core to account for the required CPU performance in order to process the incoming packets.

This patch series adds the support to use a high priority thread to process the incoming packets, as opposed to everything being done in NAPI context.

Quoted 8 lines
Quoted 4 lines

I don't see why this problem is limited to the ath10k driver. I expect it applies to all drivers using NAPI. So shouldn't you be solving this in the NAPI core? Allow a driver to request the NAPI core uses a thread?

What's more, you should be able to configure interrupt affinity to steer RX processing onto a desired CPU core, is not that working for you somehow?

Hi Florian,
Yes, the affinity of IRQ does work for me.
But the affinity of IRQ does not happen runtime based on load.

Quoted 7 lines
Quoted 1 line

It can if you also run irqbalance.

Hi Florian,

Is it some kernel feature ? Sorry I am not aware of this ? I know it can be done in userspace.

The kernel interface is /proc/<irq>/smp_affinity and the users-space implementation resides here:

https://github.com/Irqbalance/irqbalance

Signature · 6 lines
Florian

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k
#35 lore raw
In reply to Andrew Lunn

From: Andrew Lunn

Quoted 17 lines

Sent: 21 July 2020 18:25

Quoted 14 lines · Rakesh Pillai

NAPI gets scheduled on the CPU core which got the interrupt. The linux scheduler cannot move it to a different core, even if the CPU on which NAPI is running is heavily loaded. This can lead to degraded wifi performance when running traffic at peak data rates.

A thread on the other hand can be moved to different CPU cores, if the one on which its running is heavily loaded. During high incoming data traffic, this gives better performance, since the thread can be moved to a less loaded or sometimes even a more powerful CPU core to account for the required CPU performance in order to process the incoming packets.

Quoted 8 lines
Quoted 3 lines

This patch series adds the support to use a high priority thread to process the incoming packets, as opposed to everything being done in NAPI context.

I don't see why this problem is limited to the ath10k driver. I expect it applies to all drivers using NAPI. So shouldn't you be solving this in the NAPI core? Allow a driver to request the NAPI core uses a thread?

It's not just NAPI the problem is with the softint processing. I suspect a lot of systems would work better if it ran as a (highish priority) kernel thread.

I've had to remove the main locks from a multi-threaded application and replace them with atomic counters.
Consider what happens when the threads remove items from a shared work list.
The code looks like:

	mutex_enter();
	remove_item_from_list();
	mutex_exit().

The mutex is only held for a few instructions, so while you'd expect the cache line to be 'hot' you wouldn't get real contention. However the following scenarios happen:
1) An ethernet interrupt happens while the mutex is held. This stops the other threads until all the softint processing has finished.
2) An ethernet interrupt (and softint) runs on a thread that is waiting for the mutex.
(Or on the cpu that the thread's processor affinity ties it to.) In this case the 'fair' (ticket) mutex code won't let any other thread acquire the mutex.
So again everything stops until the softints all complete.

The second one is also a problem when trying to wake up all the threads (eg after adding a lot of items to the list). The ticket locks force them to wake in order, but sometimes the 'thundering herd' would work better.

IIRC this is actually worse for processes running under the RT scheduler (without CONFIG_PREEMPT) because the they are almost always scheduled on the same cpu they ran on last. If it is busy, but cannot be pre-empted, they are not moved to an idle cpu.

To confound things there is a very broken workaround for broken hardware in the driver for the e1000 interface on (at least) Ivy Bridge cpu that can cause the driver to spin for a very long time (IIRC milliseconds) whenever it has to write to a MAC register (ie on every transmit setup).

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k

#36 lore raw
Quoted 21 lines · On Wed, 22 Jul 2020 09:12:42 +0000 David Laight wrote:
Quoted 21 lines · On 21 July 2020 18:25 Andrew Lunn wrote:
Quoted 17 lines · Rakesh Pillai

NAPI gets scheduled on the CPU core which got the interrupt. The linux scheduler cannot move it to a different core, even if the CPU on which NAPI is running is heavily loaded. This can lead to degraded wifi performance when running traffic at peak data rates.

A thread on the other hand can be moved to different CPU cores, if the one on which its running is heavily loaded. During high incoming data traffic, this gives better performance, since the thread can be moved to a less loaded or sometimes even a more powerful CPU core to account for the required CPU performance in order to process the incoming packets.

This patch series adds the support to use a high priority thread to process the incoming packets, as opposed to everything being done in NAPI context.

Quoted 8 lines
Quoted 4 lines

I don't see why this problem is limited to the ath10k driver. I expect it applies to all drivers using NAPI. So shouldn't you be solving this in the NAPI core? Allow a driver to request the NAPI core uses a thread?

It's not just NAPI the problem is with the softint processing. I suspect a lot of systems would work better if it ran as a (highish priority) kernel thread.

Hi folks

Below is a minimunm poc implementation I can imagine on top of workqueue to make napi threaded. Thoughts are appreciated.

Quoted 38 lines

I've had to remove the main locks from a multi-threaded application and replace them with atomic counters.
Consider what happens when the threads remove items from a shared work list.
The code looks like:

	mutex_enter();
	remove_item_from_list();
	mutex_exit().

The mutex is only held for a few instructions, so while you'd expect the cache line to be 'hot' you wouldn't get real contention. However the following scenarios happen:
1) An ethernet interrupt happens while the mutex is held. This stops the other threads until all the softint processing has finished.
2) An ethernet interrupt (and softint) runs on a thread that is waiting for the mutex.
(Or on the cpu that the thread's processor affinity ties it to.) In this case the 'fair' (ticket) mutex code won't let any other thread acquire the mutex.
So again everything stops until the softints all complete.

The second one is also a problem when trying to wake up all the threads (eg after adding a lot of items to the list). The ticket locks force them to wake in order, but sometimes the 'thundering herd' would work better.

IIRC this is actually worse for processes running under the RT scheduler (without CONFIG_PREEMPT) because the they are almost always scheduled on the same cpu they ran on last. If it is busy, but cannot be pre-empted, they are not moved to an idle cpu.

To confound things there is a very broken workaround for broken hardware in the driver for the e1000 interface on (at least) Ivy Bridge cpu that can cause the driver to spin for a very long time (IIRC milliseconds) whenever it has to write to a MAC register (ie on every transmit setup).

Quoted 5 lines

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

To make napi threaded, if either irq or softirq thread is entirely ruled out, add napi::work that will be queued on a highpri workqueue. It is actually a unbound one to facilitate scheduler to catter napi loads on to idle CPU cores. What users need to do with the threaded napi is s/netif_napi_add/netif_threaded_napi_add/ and no more.

include/linux/netdevice.h +16 -0
@@ -338,6 +338,9 @@ struct napi_struct {
 	struct list_head	dev_list;
 	struct hlist_node	napi_hash_node;
 	unsigned int		napi_id;
+#ifdef CONFIG_THREADED_NAPI
+	struct work_struct	work;
+#endif
 };
 
 enum {
@@ -2234,6 +2237,19 @@ static inline void *netdev_priv(const st
 void netif_napi_add(struct net_device *dev, struct napi_struct *napi,
 		    int (*poll)(struct napi_struct *, int), int weight);
 
+#ifdef CONFIG_THREADED_NAPI
+void netif_threaded_napi_add(struct net_device *dev, struct napi_struct *napi,
+		    int (*poll)(struct napi_struct *, int), int weight);
+#else
+static inline void netif_threaded_napi_add(struct net_device *dev,
+					struct napi_struct *napi,
+					int (*poll)(struct napi_struct *, int),
+					int weight)
+{
+	netif_napi_add(dev, napi, poll, weight);
+}
+#endif
+
 /**
  *	netif_tx_napi_add - initialize a NAPI context
  *	@dev:  network device
net/core/dev.c +61 -2

87 lines not on this page · raw message

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k

#37 lore raw

you may consider this

https://www.mail-archive.com/[email protected]/msg1142611.html <https://www.mail-archive.com/[email protected]/msg1142611.html>

years ago someone already wanted to bring this feature upstream, but it was denied. i already tested this patch the last 2 days and it worked so far (with some little modifications) so such a solution existed already and may be considered here

Sebastian

someone

Am 25.07.2020 um 10:16 schrieb Hillf Danton:

Quoted 209 lines · On Wed, 22 Jul 2020 09:12:42 +0000 David Laight wrote:
Quoted 20 lines
Quoted 20 lines · On 21 July 2020 18:25 Andrew Lunn wrote:
Quoted 17 lines · Rakesh Pillai

NAPI gets scheduled on the CPU core which got the interrupt. The linux scheduler cannot move it to a different core, even if the CPU on which NAPI is running is heavily loaded. This can lead to degraded wifi performance when running traffic at peak data rates.

A thread on the other hand can be moved to different CPU cores, if the one on which its running is heavily loaded. During high incoming data traffic, this gives better performance, since the thread can be moved to a less loaded or sometimes even a more powerful CPU core to account for the required CPU performance in order to process the incoming packets.

This patch series adds the support to use a high priority thread to process the incoming packets, as opposed to everything being done in NAPI context.

Quoted 7 lines
Quoted 4 lines

I don't see why this problem is limited to the ath10k driver. I expect it applies to all drivers using NAPI. So shouldn't you be solving this in the NAPI core? Allow a driver to request the NAPI core uses a thread?

It's not just NAPI the problem is with the softint processing. I suspect a lot of systems would work better if it ran as a (highish priority) kernel thread.

Hi folks

Below is a minimunm poc implementation I can imagine on top of workqueue to make napi threaded. Thoughts are appreciated.

Quoted 38 lines

I've had to remove the main locks from a multi-threaded application and replace them with atomic counters.
Consider what happens when the threads remove items from a shared work list.
The code looks like:

	mutex_enter();
	remove_item_from_list();
	mutex_exit().

The mutex is only held for a few instructions, so while you'd expect the cache line to be 'hot' you wouldn't get real contention. However the following scenarios happen:
1) An ethernet interrupt happens while the mutex is held. This stops the other threads until all the softint processing has finished.
2) An ethernet interrupt (and softint) runs on a thread that is waiting for the mutex.
(Or on the cpu that the thread's processor affinity ties it to.) In this case the 'fair' (ticket) mutex code won't let any other thread acquire the mutex.
So again everything stops until the softints all complete.

The second one is also a problem when trying to wake up all the threads (eg after adding a lot of items to the list). The ticket locks force them to wake in order, but sometimes the 'thundering herd' would work better.

IIRC this is actually worse for processes running under the RT scheduler (without CONFIG_PREEMPT) because the they are almost always scheduled on the same cpu they ran on last. If it is busy, but cannot be pre-empted, they are not moved to an idle cpu.

To confound things there is a very broken workaround for broken hardware in the driver for the e1000 interface on (at least) Ivy Bridge cpu that can cause the driver to spin for a very long time (IIRC milliseconds) whenever it has to write to a MAC register (ie on every transmit setup).

Quoted 5 lines

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

To make napi threaded, if either irq or softirq thread is entirely ruled out, add napi::work that will be queued on a highpri workqueue. It is actually a unbound one to facilitate scheduler to catter napi loads on to idle CPU cores. What users need to do with the threaded napi is s/netif_napi_add/netif_threaded_napi_add/ and no more.

include/linux/netdevice.h +16 -0
@@ -338,6 +338,9 @@ struct napi_struct {
  	struct list_head	dev_list;
  	struct hlist_node	napi_hash_node;
  	unsigned int		napi_id;
+#ifdef CONFIG_THREADED_NAPI
+	struct work_struct	work;
+#endif
  };
 
  enum {
@@ -2234,6 +2237,19 @@ static inline void *netdev_priv(const st
  void netif_napi_add(struct net_device *dev, struct napi_struct *napi,
  		    int (*poll)(struct napi_struct *, int), int weight);
 
+#ifdef CONFIG_THREADED_NAPI
+void netif_threaded_napi_add(struct net_device *dev, struct napi_struct *napi,
+		    int (*poll)(struct napi_struct *, int), int weight);
+#else
+static inline void netif_threaded_napi_add(struct net_device *dev,
+					struct napi_struct *napi,
+					int (*poll)(struct napi_struct *, int),
+					int weight)
+{
+	netif_napi_add(dev, napi, poll, weight);
+}
+#endif
+
  /**
   *	netif_tx_napi_add - initialize a NAPI context
   *	@dev:  network device
net/core/dev.c +61 -2
@@ -6277,6 +6277,61 @@ static int process_backlog(struct napi_s
  	return work;
  }
 
+#ifdef CONFIG_THREADED_NAPI
+/* unbound highpri workqueue for threaded napi */
+static struct workqueue_struct *napi_workq;
+
+static void napi_workfn(struct work_struct *work)
+{
+	struct napi_struct *n = container_of(work, struct napi_struct, work);
+
+	for (;;) {
+		if (!test_bit(NAPI_STATE_SCHED, &n->state))
+			return;
+
+		if (n->poll(n, n->weight) < n->weight)
+			return;
+
+		if (need_resched()) {
+			/*
+			 * have to pay for the latency of task switch even if
+			 * napi is scheduled
+			 */
+			if (test_bit(NAPI_STATE_SCHED, &n->state))
+				queue_work(napi_workq, work);
+			return;
+		}
+	}
+}
+
+void netif_threaded_napi_add(struct net_device *dev,
+				struct napi_struct *napi,
+				int (*poll)(struct napi_struct *, int),
+				int weight)
+{
+	netif_napi_add(dev, napi, poll, weight);
+	INIT_WORK(&napi->work, napi_workfn);
+}
+
+static inline bool is_threaded_napi(struct napi_struct *n)
+{
+	return n->work.func == napi_workfn;
+}
+
+static inline void threaded_napi_sched(struct napi_struct *n)
+{
+	if (is_threaded_napi(n))
+		queue_work(napi_workq, &n->work);
+	else
+		____napi_schedule(this_cpu_ptr(&softnet_data), n);
+}
+#else
+static inline void threaded_napi_sched(struct napi_struct *n)
+{
+	____napi_schedule(this_cpu_ptr(&softnet_data), n);
+}
+#endif
+
  /**
   * __napi_schedule - schedule for receive
   * @n: entry to schedule
@@ -6289,7 +6344,7 @@ void __napi_schedule(struct napi_struct
  	unsigned long flags;
 
  	local_irq_save(flags);
-	____napi_schedule(this_cpu_ptr(&softnet_data), n);
+	threaded_napi_sched(n);
  	local_irq_restore(flags);
  }
  EXPORT_SYMBOL(__napi_schedule);
@@ -6335,7 +6390,7 @@ EXPORT_SYMBOL(napi_schedule_prep);
   */
  void __napi_schedule_irqoff(struct napi_struct *n)
  {
-	____napi_schedule(this_cpu_ptr(&softnet_data), n);
+	threaded_napi_sched(n);
  }
  EXPORT_SYMBOL(__napi_schedule_irqoff);
 
@@ -10685,6 +10740,10 @@ static int __init net_dev_init(void)
  		sd->backlog.weight = weight_p;
  	}
 
+#ifdef CONFIG_THREADED_NAPI
+	napi_workq = alloc_workqueue("napi_workq", WQ_UNBOUND | WQ_HIGHPRI,
+					    WQ_UNBOUND_MAX_ACTIVE);
+#endif
  	dev_boot_phase = 0;
 
  	/* The loopback device is special if any other network devices
Quoted 5 lines

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k

#38 lore raw
Quoted 4 lines · On Sat, 25 Jul 2020 12:38:00 +0200 Sebastian Gottschall wrote:

you may consider this

https://www.mail-archive.com/[email protected]/msg1142611.html
<https://www.mail-archive.com/[email protected]/msg1142611.html>

Thanks very much for your link.

Quoted 4 lines

years ago someone already wanted to bring this feature upstream, but it was denied. i already tested this patch the last 2 days and it worked so far (with some little modifications)
so such a solution existed already and may be considered here

I don't see outstanding difference in principle from Paolo's work in 2016 except for the use of kthread_create() and friends because kworker made use of them even before 2016. This is a simpler one as shown by the diff stat in his cover letter.

Paolo, feel free to correct me if I misread anything.

Finally I don't see the need to add sysfs attr, given CONFIG_THREADED_NAPI in this work.

BTW let us know if anyone has plans to pick up the 2016 RFC.

Hillf

Paolo Abeni (2):
net: implement threaded-able napi poll loop support
net: add sysfs attribute to control napi threaded mode

 include/linux/netdevice.h |   4 ++
 net/core/dev.c            | 113 ++++++++++++++++++++++++++++++++++++++++++++++
 net/core/net-sysfs.c      | 102 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 219 insertions(+)
Quoted 215 lines

Sebastian

someone

Am 25.07.2020 um 10:16 schrieb Hillf Danton:

Quoted 208 lines · On Wed, 22 Jul 2020 09:12:42 +0000 David Laight wrote:
Quoted 20 lines
Quoted 20 lines · On 21 July 2020 18:25 Andrew Lunn wrote:
Quoted 17 lines · Rakesh Pillai

NAPI gets scheduled on the CPU core which got the interrupt. The linux scheduler cannot move it to a different core, even if the CPU on which NAPI is running is heavily loaded. This can lead to degraded wifi performance when running traffic at peak data rates.

A thread on the other hand can be moved to different CPU cores, if the one on which its running is heavily loaded. During high incoming data traffic, this gives better performance, since the thread can be moved to a less loaded or sometimes even a more powerful CPU core to account for the required CPU performance in order to process the incoming packets.

This patch series adds the support to use a high priority thread to process the incoming packets, as opposed to everything being done in NAPI context.

Quoted 7 lines
Quoted 4 lines

I don't see why this problem is limited to the ath10k driver. I expect it applies to all drivers using NAPI. So shouldn't you be solving this in the NAPI core? Allow a driver to request the NAPI core uses a thread?

It's not just NAPI the problem is with the softint processing. I suspect a lot of systems would work better if it ran as a (highish priority) kernel thread.

Hi folks

Below is a minimunm poc implementation I can imagine on top of workqueue to make napi threaded. Thoughts are appreciated.

Quoted 38 lines

I've had to remove the main locks from a multi-threaded application and replace them with atomic counters.
Consider what happens when the threads remove items from a shared work list.
The code looks like:

	mutex_enter();
	remove_item_from_list();
	mutex_exit().

The mutex is only held for a few instructions, so while you'd expect the cache line to be 'hot' you wouldn't get real contention. However the following scenarios happen:
1) An ethernet interrupt happens while the mutex is held. This stops the other threads until all the softint processing has finished.
2) An ethernet interrupt (and softint) runs on a thread that is waiting for the mutex.
(Or on the cpu that the thread's processor affinity ties it to.) In this case the 'fair' (ticket) mutex code won't let any other thread acquire the mutex.
So again everything stops until the softints all complete.

The second one is also a problem when trying to wake up all the threads (eg after adding a lot of items to the list). The ticket locks force them to wake in order, but sometimes the 'thundering herd' would work better.

IIRC this is actually worse for processes running under the RT scheduler (without CONFIG_PREEMPT) because the they are almost always scheduled on the same cpu they ran on last. If it is busy, but cannot be pre-empted, they are not moved to an idle cpu.

To confound things there is a very broken workaround for broken hardware in the driver for the e1000 interface on (at least) Ivy Bridge cpu that can cause the driver to spin for a very long time (IIRC milliseconds) whenever it has to write to a MAC register (ie on every transmit setup).

Quoted 7 lines

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

To make napi threaded, if either irq or softirq thread is entirely ruled out, add napi::work that will be queued on a highpri workqueue. It is actually a unbound one to facilitate scheduler to catter napi loads on to idle CPU cores. What users need to do with the threaded napi is s/netif_napi_add/netif_threaded_napi_add/ and no more.

include/linux/netdevice.h +16 -0
@@ -338,6 +338,9 @@ struct napi_struct {
  	struct list_head	dev_list;
  	struct hlist_node	napi_hash_node;
  	unsigned int		napi_id;
+#ifdef CONFIG_THREADED_NAPI
+	struct work_struct	work;
+#endif
  };
 
  enum {
@@ -2234,6 +2237,19 @@ static inline void *netdev_priv(const st
  void netif_napi_add(struct net_device *dev, struct napi_struct *napi,
  		    int (*poll)(struct napi_struct *, int), int weight);
 
+#ifdef CONFIG_THREADED_NAPI
+void netif_threaded_napi_add(struct net_device *dev, struct napi_struct *napi,
+		    int (*poll)(struct napi_struct *, int), int weight);
+#else
+static inline void netif_threaded_napi_add(struct net_device *dev,
+					struct napi_struct *napi,
+					int (*poll)(struct napi_struct *, int),
+					int weight)
+{
+	netif_napi_add(dev, napi, poll, weight);
+}
+#endif
+
  /**
   *	netif_tx_napi_add - initialize a NAPI context
   *	@dev:  network device
net/core/dev.c +61 -2
@@ -6277,6 +6277,61 @@ static int process_backlog(struct napi_s
  	return work;
  }
 
+#ifdef CONFIG_THREADED_NAPI
+/* unbound highpri workqueue for threaded napi */
+static struct workqueue_struct *napi_workq;
+
+static void napi_workfn(struct work_struct *work)
+{
+	struct napi_struct *n = container_of(work, struct napi_struct, work);
+
+	for (;;) {
+		if (!test_bit(NAPI_STATE_SCHED, &n->state))
+			return;
+
+		if (n->poll(n, n->weight) < n->weight)
+			return;
+
+		if (need_resched()) {
+			/*
+			 * have to pay for the latency of task switch even if
+			 * napi is scheduled
+			 */
+			if (test_bit(NAPI_STATE_SCHED, &n->state))
+				queue_work(napi_workq, work);
+			return;
+		}
+	}
+}
+
+void netif_threaded_napi_add(struct net_device *dev,
+				struct napi_struct *napi,
+				int (*poll)(struct napi_struct *, int),
+				int weight)
+{
+	netif_napi_add(dev, napi, poll, weight);
+	INIT_WORK(&napi->work, napi_workfn);
+}
+
+static inline bool is_threaded_napi(struct napi_struct *n)
+{
+	return n->work.func == napi_workfn;
+}
+
+static inline void threaded_napi_sched(struct napi_struct *n)
+{
+	if (is_threaded_napi(n))
+		queue_work(napi_workq, &n->work);
+	else
+		____napi_schedule(this_cpu_ptr(&softnet_data), n);
+}
+#else
+static inline void threaded_napi_sched(struct napi_struct *n)
+{
+	____napi_schedule(this_cpu_ptr(&softnet_data), n);
+}
+#endif
+
  /**
   * __napi_schedule - schedule for receive
   * @n: entry to schedule
@@ -6289,7 +6344,7 @@ void __napi_schedule(struct napi_struct
  	unsigned long flags;
 
  	local_irq_save(flags);
-	____napi_schedule(this_cpu_ptr(&softnet_data), n);
+	threaded_napi_sched(n);
  	local_irq_restore(flags);
  }
  EXPORT_SYMBOL(__napi_schedule);
@@ -6335,7 +6390,7 @@ EXPORT_SYMBOL(napi_schedule_prep);
   */
  void __napi_schedule_irqoff(struct napi_struct *n)
  {
-	____napi_schedule(this_cpu_ptr(&softnet_data), n);
+	threaded_napi_sched(n);
  }
  EXPORT_SYMBOL(__napi_schedule_irqoff);
 
@@ -10685,6 +10740,10 @@ static int __init net_dev_init(void)
  		sd->backlog.weight = weight_p;
  	}
 
+#ifdef CONFIG_THREADED_NAPI
+	napi_workq = alloc_workqueue("napi_workq", WQ_UNBOUND | WQ_HIGHPRI,
+					    WQ_UNBOUND_MAX_ACTIVE);
+#endif
  	dev_boot_phase = 0;
 
Quoted 7 lines
Quoted 7 lines
net/core/dev.c +0 -0
  	/* The loopback device is special if any other network devices

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k

#39 lore raw
In reply to Sebastian Gottschall

Am 25.07.2020 um 14:25 schrieb Hillf Danton:

Quoted 9 lines · On Sat, 25 Jul 2020 12:38:00 +0200 Sebastian Gottschall wrote:
Quoted 6 lines

you may consider this

https://www.mail-archive.com/[email protected]/msg1142611.html

<https://www.mail-archive.com/[email protected]/msg1142611.html>

Thanks very much for your link.

Quoted 8 lines
Quoted 4 lines

years ago someone already wanted to bring this feature upstream, but it was denied. i already tested this patch the last 2 days and it worked so far (with some little modifications)
so such a solution existed already and may be considered here

I don't see outstanding difference in principle from Paolo's work in 2016 except for the use of kthread_create() and friends because kworker made use of them even before 2016. This is a simpler one as shown by the diff stat in his cover letter.

i agree. i just can say that i tested this patch recently due this discussion here. and it can be changed by sysfs. but it doesnt work for
wifi drivers which are mainly using dummy netdev devices. for this i made a small patch to get them working using napi_set_threaded manually hardcoded in the drivers. (see patch bellow) i also tested various networking drivers. one thing i notice doesnt work. some napi code is used for tx polling. so from my experience this concept just works good for rx with the most drivers. so far i tested mt76, ath10k and some soc ethernet chipsets with good success. on ath10k i had about 10 - 20% performance gain on multicore systems. using standard iperf3 with 4 parallel streams.

-5439,7 +5441,7 @@ int napi_set_threaded(struct napi_struct *n, bool clear_bit(NAPI_STATE_THREADED, &n->state);

        /* if the device is initializing, nothing todo */
-       if (test_bit(__LINK_STATE_START, &n->dev->state))
+       if (test_bit(__LINK_STATE_START, &n->dev->state) && n->dev->reg_state != NETREG_DUMMY) return 0;

        napi_thread_stop(n)
;

Quoted 232 lines

Paolo, feel free to correct me if I misread anything.

Finally I don't see the need to add sysfs attr, given CONFIG_THREADED_NAPI in this work.

BTW let us know if anyone has plans to pick up the 2016 RFC.

Hillf

Paolo Abeni (2):
   net: implement threaded-able napi poll loop support
   net: add sysfs attribute to control napi threaded mode

  include/linux/netdevice.h |   4 ++
  net/core/dev.c            | 113
++++++++++++++++++++++++++++++++++++++++++++++
  net/core/net-sysfs.c      | 102
+++++++++++++++++++++++++++++++++++++++++

  3 files changed, 219 insertions(+)
Quoted 212 lines

Sebastian

someone

Am 25.07.2020 um 10:16 schrieb Hillf Danton:

Quoted 206 lines · On Wed, 22 Jul 2020 09:12:42 +0000 David Laight wrote:
Quoted 20 lines
Quoted 20 lines · On 21 July 2020 18:25 Andrew Lunn wrote:
Quoted 17 lines · Rakesh Pillai

NAPI gets scheduled on the CPU core which got the interrupt. The linux scheduler cannot move it to a different core, even if the CPU on which NAPI is running is heavily loaded. This can lead to degraded wifi performance when running traffic at peak data rates.

A thread on the other hand can be moved to different CPU cores, if the one on which its running is heavily loaded. During high incoming data traffic, this gives better performance, since the thread can be moved to a less loaded or sometimes even a more powerful CPU core to account for the required CPU performance in order to process the incoming packets.

This patch series adds the support to use a high priority thread to process the incoming packets, as opposed to everything being done in NAPI context.

Quoted 7 lines
Quoted 4 lines

I don't see why this problem is limited to the ath10k driver. I expect it applies to all drivers using NAPI. So shouldn't you be solving this in the NAPI core? Allow a driver to request the NAPI core uses a thread?

It's not just NAPI the problem is with the softint processing. I suspect a lot of systems would work better if it ran as a (highish priority) kernel thread.

Hi folks

Below is a minimunm poc implementation I can imagine on top of workqueue to make napi threaded. Thoughts are appreciated.

Quoted 37 lines

I've had to remove the main locks from a multi-threaded application and replace them with atomic counters.
Consider what happens when the threads remove items from a shared work list.
The code looks like:
    mutex_enter();
    remove_item_from_list();
    mutex_exit().
The mutex is only held for a few instructions, so while you'd expect the cache line to be 'hot' you wouldn't get real contention. However the following scenarios happen:
1) An ethernet interrupt happens while the mutex is held. This stops the other threads until all the softint processing has finished.
2) An ethernet interrupt (and softint) runs on a thread that is waiting for the mutex.
     (Or on the cpu that the thread's processor affinity ties it to.) In this case the 'fair' (ticket) mutex code won't let any other thread acquire the mutex.
     So again everything stops until the softints all complete.

The second one is also a problem when trying to wake up all the threads (eg after adding a lot of items to the list). The ticket locks force them to wake in order, but sometimes the 'thundering herd' would work better.

IIRC this is actually worse for processes running under the RT scheduler (without CONFIG_PREEMPT) because the they are almost always scheduled on the same cpu they ran on last.
If it is busy, but cannot be pre-empted, they are not moved to an idle cpu.
     To confound things there is a very broken workaround for broken hardware in the driver for the e1000 interface on (at least) Ivy Bridge cpu that can cause the driver to spin for a very long time (IIRC milliseconds) whenever it has to write to a MAC register (ie on every transmit setup).

Quoted 7 lines

    David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

To make napi threaded, if either irq or softirq thread is entirely ruled out, add napi::work that will be queued on a highpri workqueue. It is actually a unbound one to facilitate scheduler to catter napi loads on to idle CPU cores. What users need to do with the threaded napi is s/netif_napi_add/netif_threaded_napi_add/ and no more.

include/linux/netdevice.h +3 -0
@@ -338,6 +338,9 @@ struct napi_struct {
        struct list_head    dev_list;
        struct hlist_node    napi_hash_node;
        unsigned int        napi_id;
+#ifdef CONFIG_THREADED_NAPI
+    struct work_struct    work;
+#endif
    };
       enum {
@@ -2234,6 +2237,19 @@ static inline void *netdev_priv(const st
    void netif_napi_add(struct net_device *dev, struct napi_struct *napi,
                int (*poll)(struct napi_struct *, int), int weight);

   +#ifdef CONFIG_THREADED_NAPI
+void netif_threaded_napi_add(struct net_device *dev, struct napi_struct *napi,
+            int (*poll)(struct napi_struct *, int), int weight);

include/linux/netdevice.h +10 -0
+#else
+static inline void netif_threaded_napi_add(struct net_device *dev,
+                    struct napi_struct *napi,
+                    int (*poll)(struct napi_struct *, int),
+                    int weight)
+{
+    netif_napi_add(dev, napi, poll, weight);
+}
+#endif
+

   /**
    *    netif_tx_napi_add - initialize a NAPI context *    @dev:  network device

net/core/dev.c +0 -0
@@ -6277,6 +6277,61 @@ static int process_backlog(struct napi_s
        return work;
    }

   +#ifdef CONFIG_THREADED_NAPI

net/core/dev.c +6 -0
+/* unbound highpri workqueue for threaded napi */
+static struct workqueue_struct *napi_workq;
+
+static void napi_workfn(struct work_struct *work)
+{
+    struct napi_struct *n = container_of(work, struct napi_struct, 

work);

net/core/dev.c +48 -0
+
+    for (;;) {
+        if (!test_bit(NAPI_STATE_SCHED, &n->state))
+            return;
+
+        if (n->poll(n, n->weight) < n->weight)
+            return;
+
+        if (need_resched()) {
+            /*
+             * have to pay for the latency of task switch even if
+             * napi is scheduled
+             */
+            if (test_bit(NAPI_STATE_SCHED, &n->state))
+                queue_work(napi_workq, work);
+            return;
+        }
+    }
+}
+
+void netif_threaded_napi_add(struct net_device *dev,
+                struct napi_struct *napi,
+                int (*poll)(struct napi_struct *, int),
+                int weight)
+{
+    netif_napi_add(dev, napi, poll, weight);
+    INIT_WORK(&napi->work, napi_workfn);
+}
+
+static inline bool is_threaded_napi(struct napi_struct *n)
+{
+    return n->work.func == napi_workfn;
+}
+
+static inline void threaded_napi_sched(struct napi_struct *n)
+{
+    if (is_threaded_napi(n))
+        queue_work(napi_workq, &n->work);
+    else
+        ____napi_schedule(this_cpu_ptr(&softnet_data), n);
+}
+#else
+static inline void threaded_napi_sched(struct napi_struct *n)
+{
+    ____napi_schedule(this_cpu_ptr(&softnet_data), n);
+}
+#endif
+

   /**
    * __napi_schedule - schedule for receive
    * @n: entry to schedule

net/core/dev.c +2 -2
@@ -6289,7 +6344,7 @@ void __napi_schedule(struct napi_struct
        unsigned long flags;
           local_irq_save(flags);
-    ____napi_schedule(this_cpu_ptr(&softnet_data), n);
+    threaded_napi_sched(n);
        local_irq_restore(flags);
    }
    EXPORT_SYMBOL(__napi_schedule);
@@ -6335,7 +6390,7 @@ EXPORT_SYMBOL(napi_schedule_prep);
     */
    void __napi_schedule_irqoff(struct napi_struct *n)
    {
-    ____napi_schedule(this_cpu_ptr(&softnet_data), n);
+    threaded_napi_sched(n);
    }
    EXPORT_SYMBOL(__napi_schedule_irqoff);
    @@ -10685,6 +10740,10 @@ static int __init net_dev_init(void)

           sd->backlog.weight = weight_p;
       }
   +#ifdef CONFIG_THREADED_NAPI
+    napi_workq = alloc_workqueue("napi_workq", WQ_UNBOUND | WQ_HIGHPRI,
+                        WQ_UNBOUND_MAX_ACTIVE);
+#endif
       dev_boot_phase = 0;
          /* The loopback device is special if any other network devices

Quoted 5 lines
Quoted 4 lines
Quoted 4 lines

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k

#40 lore raw
Quoted 20 lines · On Sat, 25 Jul 2020 16:08:41 +0200 Sebastian Gottschall wrote:

Am 25.07.2020 um 14:25 schrieb Hillf Danton:

Quoted 14 lines · On Sat, 25 Jul 2020 12:38:00 +0200 Sebastian Gottschall wrote:
Quoted 6 lines

you may consider this

https://www.mail-archive.com/[email protected]/msg1142611.html

<https://www.mail-archive.com/[email protected]/msg1142611.html>

Thanks very much for your link.

Quoted 4 lines

years ago someone already wanted to bring this feature upstream, but it was denied. i already tested this patch the last 2 days and it worked so far (with some little modifications)
so such a solution existed already and may be considered here

Quoted 5 lines

I don't see outstanding difference in principle from Paolo's work in 2016 except for the use of kthread_create() and friends because kworker made use of them even before 2016. This is a simpler one as shown by the diff stat in his cover letter.

Quoted 5 lines

i agree. i just can say that i tested this patch recently due this discussion here. and it can be changed by sysfs. but it doesnt work for wifi drivers which are mainly using dummy netdev devices. for this i made a small patch to get them working using napi_set_threaded manually hardcoded in the drivers. (see patch bellow)

By CONFIG_THREADED_NAPI, there is no need to consider what you did here in the napi core because device drivers know better and are responsible for it before calling napi_schedule(n).

Quoted 3 lines

i also tested various networking drivers. one thing i notice doesnt work. some napi code is used for tx polling. so from my experience this concept just works good for rx with the most drivers.

Drivers are also taking care of the napi::poll cb before calling netif_threaded_napi_add(), while the core offers napi threads. But these are the trivial differences from the 2016 RFC AFAICS.

Quoted 3 lines

so far i tested mt76, ath10k and some soc ethernet chipsets with good success. on ath10k i had about 10 - 20% performance gain on multicore systems. using standard iperf3 with 4 parallel streams.

Thanks for sharing the tests.

Quoted 11 lines

-5439,7 +5441,7 @@ int napi_set_threaded(struct napi_struct *n, bool
                clear_bit(NAPI_STATE_THREADED, &n->state);

        /* if the device is initializing, nothing todo */
-       if (test_bit(__LINK_STATE_START, &n->dev->state)) +       if (test_bit(__LINK_STATE_START, &n->dev->state) && n->dev->reg_state != NETREG_DUMMY)
                return 0;

        napi_thread_stop(n);

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k

#41 lore raw
Quoted 9 lines
Quoted 6 lines

i agree. i just can say that i tested this patch recently due this discussion here. and it can be changed by sysfs. but it doesnt work for wifi drivers which are mainly using dummy netdev devices. for this i made a small patch to get them working using napi_set_threaded manually hardcoded in the drivers. (see patch bellow)

By CONFIG_THREADED_NAPI, there is no need to consider what you did here in the napi core because device drivers know better and are responsible for it before calling napi_schedule(n).

yeah. but that approach will not work for some cases. some stupid drivers are using locking context in the napi poll function. in that case the performance will runto shit. i discovered this with the mvneta eth driver (marvell) and mt76 tx polling (rx  works) for mvneta is will cause very high latencies and packet drops. for mt76 it causes packet stop. doesnt work simply (on all cases no crashes) so the threading will only work for drivers which are compatible with that approach. it cannot be used as drop in replacement from my point of view. its all a question of the driver design

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k

#42 lore raw

From: Sebastian Gottschall <[email protected]>

Quoted 11 lines

Sent: 25 July 2020 16:42

Quoted 9 lines
Quoted 5 lines

i agree. i just can say that i tested this patch recently due this discussion here. and it can be changed by sysfs. but it doesnt work for wifi drivers which are mainly using dummy netdev devices. for this i made a small patch to get them working using napi_set_threaded manually hardcoded in the drivers. (see patch bellow)

By CONFIG_THREADED_NAPI, there is no need to consider what you did here in the napi core because device drivers know better and are responsible for it before calling napi_schedule(n).

Quoted 10 lines

yeah. but that approach will not work for some cases. some stupid drivers are using locking context in the napi poll function. in that case the performance will runto shit. i discovered this with the mvneta eth driver (marvell) and mt76 tx polling (rx  works) for mvneta is will cause very high latencies and packet drops. for mt76 it causes packet stop. doesnt work simply (on all cases no crashes) so the threading will only work for drivers which are compatible with that approach. it cannot be used as drop in replacement from my point of view.
its all a question of the driver design

Why should it make (much) difference whether the napi callbacks (etc) are done in the context of the interrupted process or that of a specific kernel thread.
The process flags (or whatever) can even be set so that it appears to be the expected 'softint' context.

In any case running NAPI from a thread will just show up the next piece of code that runs for ages in softint context.
I think I've seen the tail end of memory being freed under rcu finally happening under softint and taking absolutely ages.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

#43 lore raw
Quoted 46 lines

-----Original Message-----
From: David Laight <[email protected]>
Sent: Sunday, July 26, 2020 4:46 PM
To: 'Sebastian Gottschall' <[email protected]>; Hillf Danton <[email protected]>
Cc: Andrew Lunn <[email protected]>; Rakesh Pillai <[email protected]>; [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; Markus Elfring <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [RFC 0/7] Add support to process rx packets in thread

From: Sebastian Gottschall <[email protected]>

Quoted 5 lines

Sent: 25 July 2020 16:42

Quoted 4 lines
Quoted 4 lines

i agree. i just can say that i tested this patch recently due this discussion here. and it can be changed by sysfs. but it doesnt work for wifi drivers which are mainly using dummy netdev devices. for this i made a small patch to get them working using napi_set_threaded

manually

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

hardcoded in the drivers. (see patch bellow)

By CONFIG_THREADED_NAPI, there is no need to consider what you did

here

Quoted 13 lines
Quoted 2 lines

in the napi core because device drivers know better and are responsible for it before calling napi_schedule(n).

yeah. but that approach will not work for some cases. some stupid drivers are using locking context in the napi poll function. in that case the performance will runto shit. i discovered this with the mvneta eth driver (marvell) and mt76 tx polling (rx works) for mvneta is will cause very high latencies and packet drops. for mt76 it causes packet stop. doesnt work simply (on all cases no crashes) so the threading will only work for drivers which are compatible with that approach. it cannot be used as drop in replacement from my point of view.
its all a question of the driver design

Why should it make (much) difference whether the napi callbacks (etc) are done in the context of the interrupted process or that of a specific kernel thread.
The process flags (or whatever) can even be set so that it appears to be the expected 'softint' context.

Quoted 7 lines

In any case running NAPI from a thread will just show up the next piece of code that runs for ages in softint context.
I think I've seen the tail end of memory being freed under rcu finally happening under softint and taking absolutely ages.

David

Hi All,

Is the threaded NAPI change posted to kernel ?
Is the conclusion of this discussion that " we cannot use threads for processing packets " ??

Quoted 4 lines

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k

#44 lore raw
Quoted 61 lines · On Tue, 28 Jul 2020 22:29:02 +0530 Rakesh Pillai wrote:
Quoted 6 lines

-----Original Message-----
From: David Laight <[email protected]>
Sent: Sunday, July 26, 2020 4:46 PM
To: 'Sebastian Gottschall' <[email protected]>; Hillf Danton <[email protected]>
Cc: Andrew Lunn <[email protected]>; Rakesh Pillai =

<[email protected]>;

Quoted 10 lines

[email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; Markus Elfring <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [RFC 0/7] Add support to process rx packets in thread =20
From: Sebastian Gottschall <[email protected]>

Quoted 2 lines

Sent: 25 July 2020 16:42

Quoted 1 line
Quoted 1 line

i agree. i just can say that i tested this patch recently due =

this

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

discussion here. and it can be changed by sysfs. but it doesnt =

work for

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

wifi drivers which are mainly using dummy netdev devices. for =

this i

Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

made a small patch to get them working using napi_set_threaded

manually

Quoted 1 line
Quoted 1 line
Quoted 1 line

hardcoded in the drivers. (see patch bellow)

=20

Quoted 1 line
Quoted 1 line

By CONFIG_THREADED_NAPI, there is no need to consider what you did

here

Quoted 1 line
Quoted 1 line

in the napi core because device drivers know better and are =

responsible

Quoted 5 lines
Quoted 1 line
Quoted 1 line

for it before calling napi_schedule(n).

=20

Quoted 3 lines

yeah. but that approach will not work for some cases. some stupid drivers are using locking context in the napi poll function. in that case the performance will runto shit. i discovered this with =

the

Quoted 2 lines
Quoted 2 lines

mvneta eth driver (marvell) and mt76 tx polling (rx works) for mvneta is will cause very high latencies and packet drops. for =

mt76

Quoted 2 lines
Quoted 2 lines

it causes packet stop. doesnt work simply (on all cases no crashes) so the threading will only work for drivers which are compatible =

with

Quoted 1 line
Quoted 1 line

that approach. it cannot be used as drop in replacement from my =

point of

Quoted 16 lines
Quoted 2 lines

view.
its all a question of the driver design

=20
Why should it make (much) difference whether the napi callbacks (etc) are done in the context of the interrupted process or that of a specific kernel thread.
The process flags (or whatever) can even be set so that it appears to be the expected 'softint' context.
=20
In any case running NAPI from a thread will just show up the next piece of code that runs for ages in softint context.
I think I've seen the tail end of memory being freed under rcu finally happening under softint and taking absolutely ages. =20
David
=20

Quoted 3 lines

Hi All,

Is the threaded NAPI change posted to kernel ?

https://lore.kernel.org/netdev/[email protected]/
https://lore.kernel.org/netdev/[email protected]/

Quoted 2 lines

Is the conclusion of this discussion that " we cannot use threads for processing packets " ??

That isn't it if any conclusion reached. Hard to answer your question TBH, and OTOH I'm wondering in which context device driver developer prefers to handle tx/rx, IRQ or BH or user context on available idle CPUs, what is preventing them from doing that? Is it likely making ant-antenna-size sense to set the napi::weight to 3 and turn to 30 kworkers for processing the ten-minute packet flood hitting the hardware for instance on a system with 32 CPU cores or more?

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k

#45 lore raw
In reply to Hillf Danton
Quoted 4 lines · Hillf Danton

Hi folks

Below is a minimunm poc implementation I can imagine on top of workqueue to make napi threaded. Thoughts are appreciated.

Hi Hillf,

For some reason I don't see your mails on linux-wireless/netdev. I've cleaned up your implementation a bit and I ran some tests with mt76 on an mt7621 embedded board. The results look pretty nice, performance is a lot more consistent in my tests now.

Here are the changes that I've made compared to your version:

- remove the #ifdef, I think it's unnecessary
- add a state bit for threaded NAPI
- make netif_threaded_napi_add inline
- run queue_work outside of local_irq_save/restore (it does that internally already)

If you don't mind, I'd like to propose this to netdev soon. Can I have your Signed-off-by for that?

Thanks,

- Felix

---

include/linux/netdevice.h +23 -0
@@ -347,6 +347,7 @@ struct napi_struct {
 	struct list_head	dev_list;
 	struct hlist_node	napi_hash_node;
 	unsigned int		napi_id;
+	struct work_struct	work;
 };
 
 enum {
@@ -357,6 +358,7 @@ enum {
 	NAPI_STATE_HASHED,	/* In NAPI hash (busy polling possible) */
 	NAPI_STATE_NO_BUSY_POLL,/* Do not add in napi_hash, no busy polling */
 	NAPI_STATE_IN_BUSY_POLL,/* sk_busy_loop() owns this NAPI */
+	NAPI_STATE_THREADED,	/* Use threaded NAPI */
 };
 
 enum {
@@ -367,6 +369,7 @@ enum {
 	NAPIF_STATE_HASHED	 = BIT(NAPI_STATE_HASHED),
 	NAPIF_STATE_NO_BUSY_POLL = BIT(NAPI_STATE_NO_BUSY_POLL),
 	NAPIF_STATE_IN_BUSY_POLL = BIT(NAPI_STATE_IN_BUSY_POLL),
+	NAPIF_STATE_THREADED	 = BIT(NAPI_STATE_THREADED),
 };
 
 enum gro_result {
@@ -2315,6 +2318,26 @@ static inline void *netdev_priv(const struct net_device *dev)
 void netif_napi_add(struct net_device *dev, struct napi_struct *napi,
 		    int (*poll)(struct napi_struct *, int), int weight);
 
+/**
+ *	netif_threaded_napi_add - initialize a NAPI context
+ *	@dev:  network device
+ *	@napi: NAPI context
+ *	@poll: polling function
+ *	@weight: default weight
+ *
+ * This variant of netif_napi_add() should be used from drivers using NAPI
+ * with CPU intensive poll functions.
+ * This will schedule polling from a high priority workqueue that
+ */
+static inline void netif_threaded_napi_add(struct net_device *dev,
+					   struct napi_struct *napi,
+					   int (*poll)(struct napi_struct *, int),
+					   int weight)
+{
+	set_bit(NAPI_STATE_THREADED, &napi->state);
+	netif_napi_add(dev, napi, poll, weight);
+}
+
 /**
  *	netif_tx_napi_add - initialize a NAPI context
  *	@dev:  network device
net/core/dev.c +39 -0
@@ -158,6 +158,7 @@ static DEFINE_SPINLOCK(offload_lock);
 struct list_head ptype_base[PTYPE_HASH_SIZE] __read_mostly;
 struct list_head ptype_all __read_mostly;	/* Taps */
 static struct list_head offload_base __read_mostly;
+static struct workqueue_struct *napi_workq;
 
 static int netif_rx_internal(struct sk_buff *skb);
 static int call_netdevice_notifiers_info(unsigned long val,
@@ -6286,6 +6287,11 @@ void __napi_schedule(struct napi_struct *n)
 {
 	unsigned long flags;
 
+	if (test_bit(NAPI_STATE_THREADED, &n->state)) {
+		queue_work(napi_workq, &n->work);
+		return;
+	}
+
 	local_irq_save(flags);
 	____napi_schedule(this_cpu_ptr(&softnet_data), n);
 	local_irq_restore(flags);
@@ -6333,6 +6339,11 @@ EXPORT_SYMBOL(napi_schedule_prep);
  */
 void __napi_schedule_irqoff(struct napi_struct *n)
 {
+	if (test_bit(NAPI_STATE_THREADED, &n->state)) {
+		queue_work(napi_workq, &n->work);
+		return;
+	}
+
 	____napi_schedule(this_cpu_ptr(&softnet_data), n);
 }
 EXPORT_SYMBOL(__napi_schedule_irqoff);
@@ -6601,6 +6612,29 @@ static void init_gro_hash(struct napi_struct *napi)
 	napi->gro_bitmask = 0;
 }
 
+static void napi_workfn(struct work_struct *work)
+{
+	struct napi_struct *n = container_of(work, struct napi_struct, work);
+
+	for (;;) {
+		if (!test_bit(NAPI_STATE_SCHED, &n->state))
+			return;
+
+		if (n->poll(n, n->weight) < n->weight)
+			return;
+
+		if (need_resched()) {
+			/*
+			 * have to pay for the latency of task switch even if
+			 * napi is scheduled
+			 */
+			if (test_bit(NAPI_STATE_SCHED, &n->state))
+				queue_work(napi_workq, work);
+			return;
+		}
+	}
+}
+
 void netif_napi_add(struct net_device *dev, struct napi_struct *napi,
 		    int (*poll)(struct napi_struct *, int), int weight)
 {
@@ -6621,6 +6655,7 @@ void netif_napi_add(struct net_device *dev, struct napi_struct *napi,
 #ifdef CONFIG_NETPOLL
 	napi->poll_owner = -1;
 #endif
+	INIT_WORK(&napi->work, napi_workfn);
 	set_bit(NAPI_STATE_SCHED, &napi->state);
 	napi_hash_add(napi);
 }
@@ -10676,6 +10711,10 @@ static int __init net_dev_init(void)
 		sd->backlog.weight = weight_p;
 	}
 
+	napi_workq = alloc_workqueue("napi_workq", WQ_UNBOUND | WQ_HIGHPRI,
+				     WQ_UNBOUND_MAX_ACTIVE);
+	BUG_ON(!napi_workq);
+
 	dev_boot_phase = 0;
 
 	/* The loopback device is special if any other network devices

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k

#46 lore raw

Hi Felix,

Quoted 9 lines · On Sat, 25 Jul 2020 19:57:23 +0200 Felix Fietkau wrote:
Quoted 5 lines · Hillf Danton

Hi folks

Below is a minimunm poc implementation I can imagine on top of workqueue to make napi threaded. Thoughts are appreciated.

Hi Hillf,

For some reason I don't see your mails on linux-wireless/netdev.

All is down to my inbox ...

Quoted 3 lines

I've cleaned up your implementation a bit and I ran some tests with mt76 on an mt7621 embedded board. The results look pretty nice, performance is a lot more consistent in my tests now.

Thanks very much for your cleanup and testing.

Quoted 3 lines

Here are the changes that I've made compared to your version:

- remove the #ifdef, I think it's unnecessary

This makes the code a mile nicer and perhaps I fear pulls some questions from EricD.

Quoted 7 lines

- add a state bit for threaded NAPI
- make netif_threaded_napi_add inline
- run queue_work outside of local_irq_save/restore (it does that internally already)

If you don't mind, I'd like to propose this to netdev soon. Can I have your Signed-off-by for that?

Feel free to do that. Is it likely for me to select a Cc?

Thanks
Hillf

Quoted 61 lines

Thanks,

- Felix

---

include/linux/netdevice.h +23 -0
@@ -347,6 +347,7 @@ struct napi_struct {
 	struct list_head	dev_list;
 	struct hlist_node	napi_hash_node;
 	unsigned int		napi_id;
+	struct work_struct	work;
 };
 
 enum {
@@ -357,6 +358,7 @@ enum {
 	NAPI_STATE_HASHED,	/* In NAPI hash (busy polling possible) */
 	NAPI_STATE_NO_BUSY_POLL,/* Do not add in napi_hash, no busy polling */
 	NAPI_STATE_IN_BUSY_POLL,/* sk_busy_loop() owns this NAPI */
+	NAPI_STATE_THREADED,	/* Use threaded NAPI */
 };
 
 enum {
@@ -367,6 +369,7 @@ enum {
 	NAPIF_STATE_HASHED	 = BIT(NAPI_STATE_HASHED),
 	NAPIF_STATE_NO_BUSY_POLL = BIT(NAPI_STATE_NO_BUSY_POLL),
 	NAPIF_STATE_IN_BUSY_POLL = BIT(NAPI_STATE_IN_BUSY_POLL),
+	NAPIF_STATE_THREADED	 = BIT(NAPI_STATE_THREADED),
 };
 
 enum gro_result {
@@ -2315,6 +2318,26 @@ static inline void *netdev_priv(const struct net_device *dev)
 void netif_napi_add(struct net_device *dev, struct napi_struct *napi,
 		    int (*poll)(struct napi_struct *, int), int weight);
 
+/**
+ *	netif_threaded_napi_add - initialize a NAPI context
+ *	@dev:  network device
+ *	@napi: NAPI context
+ *	@poll: polling function
+ *	@weight: default weight
+ *
+ * This variant of netif_napi_add() should be used from drivers using NAPI
+ * with CPU intensive poll functions.
+ * This will schedule polling from a high priority workqueue that
+ */
+static inline void netif_threaded_napi_add(struct net_device *dev,
+					   struct napi_struct *napi,
+					   int (*poll)(struct napi_struct *, int),
+					   int weight)
+{
+	set_bit(NAPI_STATE_THREADED, &napi->state);
+	netif_napi_add(dev, napi, poll, weight);
+}
+
 /**
  *	netif_tx_napi_add - initialize a NAPI context
  *	@dev:  network device

net/core/dev.c static DEFINE_SPINLOCK(offload_lock); · line 161

Quoted 4 lines
net/core/dev.c +1 -0
@@ -158,6 +158,7 @@ static DEFINE_SPINLOCK(offload_lock);
 struct list_head ptype_base[PTYPE_HASH_SIZE] __read_mostly;
 struct list_head ptype_all __read_mostly;	/* Taps */
 static struct list_head offload_base __read_mostly;
+static struct workqueue_struct *napi_workq;

Is __read_mostly missing?

Quoted 66 lines
net/core/dev.c +34 -0
 static int netif_rx_internal(struct sk_buff *skb);
 static int call_netdevice_notifiers_info(unsigned long val,
@@ -6286,6 +6287,11 @@ void __napi_schedule(struct napi_struct *n)
 {
 	unsigned long flags;
 
+	if (test_bit(NAPI_STATE_THREADED, &n->state)) {
+		queue_work(napi_workq, &n->work);
+		return;
+	}
+
 	local_irq_save(flags);
 	____napi_schedule(this_cpu_ptr(&softnet_data), n);
 	local_irq_restore(flags);
@@ -6333,6 +6339,11 @@ EXPORT_SYMBOL(napi_schedule_prep);
  */
 void __napi_schedule_irqoff(struct napi_struct *n)
 {
+	if (test_bit(NAPI_STATE_THREADED, &n->state)) {
+		queue_work(napi_workq, &n->work);
+		return;
+	}
+
 	____napi_schedule(this_cpu_ptr(&softnet_data), n);
 }
 EXPORT_SYMBOL(__napi_schedule_irqoff);
@@ -6601,6 +6612,29 @@ static void init_gro_hash(struct napi_struct *napi)
 	napi->gro_bitmask = 0;
 }
 
+static void napi_workfn(struct work_struct *work)
+{
+	struct napi_struct *n = container_of(work, struct napi_struct, work);
+
+	for (;;) {
+		if (!test_bit(NAPI_STATE_SCHED, &n->state))
+			return;
+
+		if (n->poll(n, n->weight) < n->weight)
+			return;
+
+		if (need_resched()) {
+			/*
+			 * have to pay for the latency of task switch even if
+			 * napi is scheduled
+			 */
+			if (test_bit(NAPI_STATE_SCHED, &n->state))
+				queue_work(napi_workq, work);
+			return;
+		}
+	}
+}
+
 void netif_napi_add(struct net_device *dev, struct napi_struct *napi,
 		    int (*poll)(struct napi_struct *, int), int weight)
 {
@@ -6621,6 +6655,7 @@ void netif_napi_add(struct net_device *dev, struct napi_struct *napi,
 #ifdef CONFIG_NETPOLL
 	napi->poll_owner = -1;
 #endif
+	INIT_WORK(&napi->work, napi_workfn);
 	set_bit(NAPI_STATE_SCHED, &napi->state);
 	napi_hash_add(napi);
 }

net/core/dev.c static int __init net_dev_init(void) · line 10720

Quoted 10 lines
net/core/dev.c +4 -0
@@ -10676,6 +10711,10 @@ static int __init net_dev_init(void)
 		sd->backlog.weight = weight_p;
 	}
 
+	napi_workq = alloc_workqueue("napi_workq", WQ_UNBOUND | WQ_HIGHPRI,
+				     WQ_UNBOUND_MAX_ACTIVE);
+	BUG_ON(!napi_workq);
+
 	dev_boot_phase = 0;
 
 	/* The loopback device is special if any other network devices

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k

#47 lore raw
Quoted 9 lines · Hillf Danton
Quoted 7 lines

- add a state bit for threaded NAPI
- make netif_threaded_napi_add inline
- run queue_work outside of local_irq_save/restore (it does that internally already)

If you don't mind, I'd like to propose this to netdev soon. Can I have your Signed-off-by for that?

Feel free to do that. Is it likely for me to select a Cc?

Shall I use Signed-off-by: Hillf Danton <[email protected]>? What Cc do you want me to add?

Quoted 55 lines
Quoted 55 lines

---

include/linux/netdevice.h +23 -1
@@ -347,6 +347,7 @@ struct napi_struct {
 	struct list_head	dev_list;
 	struct hlist_node	napi_hash_node;
 	unsigned int		napi_id;
+	struct work_struct	work;
 };
 
 enum {
@@ -357,6 +358,7 @@ enum {
 	NAPI_STATE_HASHED,	/* In NAPI hash (busy polling possible) */
 	NAPI_STATE_NO_BUSY_POLL,/* Do not add in napi_hash, no busy polling */
 	NAPI_STATE_IN_BUSY_POLL,/* sk_busy_loop() owns this NAPI */
+	NAPI_STATE_THREADED,	/* Use threaded NAPI */
 };
 
 enum {
@@ -367,6 +369,7 @@ enum {
 	NAPIF_STATE_HASHED	 = BIT(NAPI_STATE_HASHED),
 	NAPIF_STATE_NO_BUSY_POLL = BIT(NAPI_STATE_NO_BUSY_POLL),
 	NAPIF_STATE_IN_BUSY_POLL = BIT(NAPI_STATE_IN_BUSY_POLL),
+	NAPIF_STATE_THREADED	 = BIT(NAPI_STATE_THREADED),
 };
 
 enum gro_result {
@@ -2315,6 +2318,26 @@ static inline void *netdev_priv(const struct net_device *dev)
 void netif_napi_add(struct net_device *dev, struct napi_struct *napi,
 		    int (*poll)(struct napi_struct *, int), int weight);
 
+/**
+ *	netif_threaded_napi_add - initialize a NAPI context
+ *	@dev:  network device
+ *	@napi: NAPI context
+ *	@poll: polling function
+ *	@weight: default weight
+ *
+ * This variant of netif_napi_add() should be used from drivers using NAPI
+ * with CPU intensive poll functions.
+ * This will schedule polling from a high priority workqueue that
+ */
+static inline void netif_threaded_napi_add(struct net_device *dev,
+					   struct napi_struct *napi,
+					   int (*poll)(struct napi_struct *, int),
+					   int weight)
+{
+	set_bit(NAPI_STATE_THREADED, &napi->state);
+	netif_napi_add(dev, napi, poll, weight);
+}
+
 /**
  *	netif_tx_napi_add - initialize a NAPI context
  *	@dev:  network device
--- a/net/core/dev.c
Quoted 8 lines

include/linux/netdevice.h static DEFINE_SPINLOCK(offload_lock); · line 161

Quoted 6 lines

+++ b/net/core/dev.c

include/linux/netdevice.h +1 -0
@@ -158,6 +158,7 @@ static DEFINE_SPINLOCK(offload_lock);
 struct list_head ptype_base[PTYPE_HASH_SIZE] __read_mostly;
 struct list_head ptype_all __read_mostly;	/* Taps */
 static struct list_head offload_base __read_mostly;
+static struct workqueue_struct *napi_workq;

Is __read_mostly missing?

Yes, thanks. I will add that before sending the patch.

- Felix

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k

#49 lore raw
Quoted 6 lines · Hillf Danton
Quoted 4 lines · On Sun, 26 Jul 2020 10:10:15 +0200 Felix Fietkau wrote:
Quoted 3 lines · Hillf Danton

Feel free to do that. Is it likely for me to select a Cc?

Quoted 7 lines
Quoted 1 line

Shall I use Signed-off-by: Hillf Danton <[email protected]>?

s/Signed-off-by/Cc/

Quoted 1 line

What Cc do you want me to add?

I prefer Cc over other tags.

Ah, okay. I was planning on adding you as the author of the patch, since you did most of the work on it. If you want to be attributed as author (or in Co-developed-by), I'd need your Signed-off-by.

If you don't want that, I can submit it under my name and leave you in as Cc only.

- Felix

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k

maintainer
#50 lore raw
In reply to Andrew Lunn
Quoted 15 lines · On Tue, 21 Jul 2020 19:25:14 +0200 Andrew Lunn wrote:
Quoted 14 lines · Rakesh Pillai

NAPI gets scheduled on the CPU core which got the interrupt. The linux scheduler cannot move it to a different core, even if the CPU on which NAPI is running is heavily loaded. This can lead to degraded wifi performance when running traffic at peak data rates.

A thread on the other hand can be moved to different CPU cores, if the one on which its running is heavily loaded. During high incoming data traffic, this gives better performance, since the thread can be moved to a less loaded or sometimes even a more powerful CPU core to account for the required CPU performance in order to process the incoming packets.

Quoted 8 lines
Quoted 3 lines

This patch series adds the support to use a high priority thread to process the incoming packets, as opposed to everything being done in NAPI context.

I don't see why this problem is limited to the ath10k driver. I expect it applies to all drivers using NAPI. So shouldn't you be solving this in the NAPI core? Allow a driver to request the NAPI core uses a thread?

Agreed, this is a problem we have with all drivers today. We see seriously sub-optimal behavior in data center workloads, because kernel overloads the cores doing packet processing.

I think the fix may actually be in the scheduler. AFAIU the scheduler counts the softIRQ time towards the interrupted process, and on top of that tries to move processes to the cores handling their IO. In the end the configuration which works somewhat okay is when each core has its own IRQ and queues, which is seriously sub-optimal.

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k