diff mbox series

[v3,net-next,3/4] net: Use backlog-NAPI to clean up the defer_list.

Message ID 20240228121000.526645-4-bigeasy@linutronix.de (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series net: Provide SMP threads for backlog NAPI | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next, async
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 5045 this patch: 5045
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 4 of 4 maintainers
netdev/build_clang success Errors and warnings before: 1071 this patch: 1071
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 5347 this patch: 5347
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 75 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Sebastian Andrzej Siewior Feb. 28, 2024, 12:05 p.m. UTC
The defer_list is a per-CPU list which is used to free skbs outside of
the socket lock and on the CPU on which they have been allocated.
The list is processed during NAPI callbacks so ideally the list is
cleaned up.
Should the amount of skbs on the list exceed a certain water mark then
the softirq is triggered remotely on the target CPU by invoking a remote
function call. The raise of the softirqs via a remote function call
leads to waking the ksoftirqd on PREEMPT_RT which is undesired.
The backlog-NAPI threads already provide the infrastructure which can be
utilized to perform the cleanup of the defer_list.

The NAPI state is updated with the input_pkt_queue.lock acquired. It
order not to break the state, it is needed to also wake the backlog-NAPI
thread with the lock held. This requires to acquire the use the lock in
rps_lock_irq*() if the backlog-NAPI threads are used even with RPS
disabled.

Move the logic of remotely starting softirqs to clean up the defer_list
into kick_defer_list_purge(). Make sure a lock is held in
rps_lock_irq*() if backlog-NAPI threads are used. Schedule backlog-NAPI
for defer_list cleanup if backlog-NAPI is available.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 include/linux/netdevice.h |  1 +
 net/core/dev.c            | 28 ++++++++++++++++++++++++----
 net/core/skbuff.c         |  4 ++--
 3 files changed, 27 insertions(+), 6 deletions(-)

Comments

Paolo Abeni March 5, 2024, 9:55 a.m. UTC | #1
On Wed, 2024-02-28 at 13:05 +0100, Sebastian Andrzej Siewior wrote:
> @@ -4736,6 +4736,26 @@ static void napi_schedule_rps(struct softnet_data *sd)
>  	__napi_schedule_irqoff(&mysd->backlog);
>  }
>  
> +void kick_defer_list_purge(unsigned int cpu)
> +{

Minor nit: I guess passing directly 'sd' as an argument here would be
better, but that could be a follow-up.

Cheers,

Paolo
Sebastian Andrzej Siewior March 5, 2024, 10:25 a.m. UTC | #2
On 2024-03-05 10:55:45 [+0100], Paolo Abeni wrote:
> On Wed, 2024-02-28 at 13:05 +0100, Sebastian Andrzej Siewior wrote:
> > @@ -4736,6 +4736,26 @@ static void napi_schedule_rps(struct softnet_data *sd)
> >  	__napi_schedule_irqoff(&mysd->backlog);
> >  }
> >  
> > +void kick_defer_list_purge(unsigned int cpu)
> > +{
> 
> Minor nit: I guess passing directly 'sd' as an argument here would be
> better, but that could be a follow-up.

I need the CPU number in the "non-backlog threaded" case for
smp_call_function_single_async(cpu, ). sd->cpu has the CPU stored but
only in the CONFIG_RPS case. In the theoretical case +SMP -SYSFS we
wouldn't have RPS but would need this CPU member.

> Cheers,
> 
> Paolo

Sebastian
Paolo Abeni March 5, 2024, 10:36 a.m. UTC | #3
On Tue, 2024-03-05 at 11:25 +0100, Sebastian Andrzej Siewior wrote:
> On 2024-03-05 10:55:45 [+0100], Paolo Abeni wrote:
> > On Wed, 2024-02-28 at 13:05 +0100, Sebastian Andrzej Siewior wrote:
> > > @@ -4736,6 +4736,26 @@ static void napi_schedule_rps(struct softnet_data *sd)
> > >  	__napi_schedule_irqoff(&mysd->backlog);
> > >  }
> > >  
> > > +void kick_defer_list_purge(unsigned int cpu)
> > > +{
> > 
> > Minor nit: I guess passing directly 'sd' as an argument here would be
> > better, but that could be a follow-up.
> 
> I need the CPU number in the "non-backlog threaded" case for
> smp_call_function_single_async(cpu, ). sd->cpu has the CPU stored but
> only in the CONFIG_RPS case. In the theoretical case +SMP -SYSFS we
> wouldn't have RPS but would need this CPU member.

To clarify: I'm suggesting passing both arguments.

Cheers,

Paolo
Sebastian Andrzej Siewior March 5, 2024, 10:40 a.m. UTC | #4
On 2024-03-05 11:36:39 [+0100], Paolo Abeni wrote:
> To clarify: I'm suggesting passing both arguments.

Ah. Okay. That would work. I am rebasing it so let me sneak that in.

> Cheers,
> 
> Paolo

Sebastian
diff mbox series

Patch

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 09023e44db4e2..fe5f4d7d397e2 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -3368,6 +3368,7 @@  static inline void dev_xmit_recursion_dec(void)
 	__this_cpu_dec(softnet_data.xmit.recursion);
 }
 
+void kick_defer_list_purge(unsigned int cpu);
 void __netif_schedule(struct Qdisc *q);
 void netif_schedule_queue(struct netdev_queue *txq);
 
diff --git a/net/core/dev.c b/net/core/dev.c
index b449b60546554..aa831d40a1f54 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -225,7 +225,7 @@  static bool use_backlog_threads(void)
 static inline void rps_lock_irqsave(struct softnet_data *sd,
 				    unsigned long *flags)
 {
-	if (IS_ENABLED(CONFIG_RPS))
+	if (IS_ENABLED(CONFIG_RPS) || use_backlog_threads())
 		spin_lock_irqsave(&sd->input_pkt_queue.lock, *flags);
 	else if (!IS_ENABLED(CONFIG_PREEMPT_RT))
 		local_irq_save(*flags);
@@ -233,7 +233,7 @@  static inline void rps_lock_irqsave(struct softnet_data *sd,
 
 static inline void rps_lock_irq_disable(struct softnet_data *sd)
 {
-	if (IS_ENABLED(CONFIG_RPS))
+	if (IS_ENABLED(CONFIG_RPS) || use_backlog_threads())
 		spin_lock_irq(&sd->input_pkt_queue.lock);
 	else if (!IS_ENABLED(CONFIG_PREEMPT_RT))
 		local_irq_disable();
@@ -242,7 +242,7 @@  static inline void rps_lock_irq_disable(struct softnet_data *sd)
 static inline void rps_unlock_irq_restore(struct softnet_data *sd,
 					  unsigned long *flags)
 {
-	if (IS_ENABLED(CONFIG_RPS))
+	if (IS_ENABLED(CONFIG_RPS) || use_backlog_threads())
 		spin_unlock_irqrestore(&sd->input_pkt_queue.lock, *flags);
 	else if (!IS_ENABLED(CONFIG_PREEMPT_RT))
 		local_irq_restore(*flags);
@@ -250,7 +250,7 @@  static inline void rps_unlock_irq_restore(struct softnet_data *sd,
 
 static inline void rps_unlock_irq_enable(struct softnet_data *sd)
 {
-	if (IS_ENABLED(CONFIG_RPS))
+	if (IS_ENABLED(CONFIG_RPS) || use_backlog_threads())
 		spin_unlock_irq(&sd->input_pkt_queue.lock);
 	else if (!IS_ENABLED(CONFIG_PREEMPT_RT))
 		local_irq_enable();
@@ -4736,6 +4736,26 @@  static void napi_schedule_rps(struct softnet_data *sd)
 	__napi_schedule_irqoff(&mysd->backlog);
 }
 
+void kick_defer_list_purge(unsigned int cpu)
+{
+	struct softnet_data *sd;
+	unsigned long flags;
+
+	sd = &per_cpu(softnet_data, cpu);
+
+	if (use_backlog_threads()) {
+		rps_lock_irqsave(sd, &flags);
+
+		if (!__test_and_set_bit(NAPI_STATE_SCHED, &sd->backlog.state))
+			__napi_schedule_irqoff(&sd->backlog);
+
+		rps_unlock_irq_restore(sd, &flags);
+
+	} else if (!cmpxchg(&sd->defer_ipi_scheduled, 0, 1)) {
+		smp_call_function_single_async(cpu, &sd->defer_csd);
+	}
+}
+
 #ifdef CONFIG_NET_FLOW_LIMIT
 int netdev_flow_limit_table_len __read_mostly = (1 << 12);
 #endif
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 1f918e602bc4f..0c9676157a2c1 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -7042,8 +7042,8 @@  nodefer:	__kfree_skb(skb);
 	/* Make sure to trigger NET_RX_SOFTIRQ on the remote CPU
 	 * if we are unlucky enough (this seems very unlikely).
 	 */
-	if (unlikely(kick) && !cmpxchg(&sd->defer_ipi_scheduled, 0, 1))
-		smp_call_function_single_async(cpu, &sd->defer_csd);
+	if (unlikely(kick))
+		kick_defer_list_purge(cpu);
 }
 
 static void skb_splice_csum_page(struct sk_buff *skb, struct page *page,