Skip to contentSkip to conversation

RFC [PATCH net-2.6 1/6] net: Scheduling softirqs between CPUSs

PATCH Tom Herbert 5 participants 12 messages Mar 5, 2008 – Mar 13, 2008

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

This patch implements kernel changes to allow scheduling of softirq's between processors.

---

include/linux/interrupt.h +10 -0
diff -uprN -X /tmp/donts/si_1 net-2.6/include/linux/interrupt.h net-2.6.patch/include/linux/interrupt.h
@@ -247,6 +247,9 @@ static inline void __deprecated save_and
 enum
 {
 	HI_SOFTIRQ=0,
+#ifdef CONFIG_SMP
+	SEND_CPU_SOFTIRQ,
+#endif
 	TIMER_SOFTIRQ,
 	NET_TX_SOFTIRQ,
 	NET_RX_SOFTIRQ,
@@ -276,6 +279,13 @@ extern void softirq_init(void);
 extern void raise_softirq_irqoff(unsigned int nr);
 extern void raise_softirq(unsigned int nr);
 
+#ifdef CONFIG_SMP
+DECLARE_PER_CPU(atomic_t, alt_softirqs);
+
+extern void raise_softirq_oncpu(int cpu, unsigned int nr);
+extern void or_alt_softirqs_pending_irqoff(void);
+extern void or_alt_softirqs_pending(void);
+#endif
 
 /* Tasklets --- multithreaded analogue of BHs.
 
include/linux/smp.h +15 -0
diff -uprN -X /tmp/donts/si_1 net-2.6/include/linux/smp.h net-2.6.patch/include/linux/smp.h
@@ -33,6 +33,21 @@ extern void smp_send_stop(void);
  */
 extern void smp_send_reschedule(int cpu);
 
+/*
+ * sends a 'reschedule' event to multiple CPUs in mask:
+ */
+#ifdef ARCH_HAS_SEND_RESCHEDULE_MASK
+extern void smp_send_reschedule_mask(cpumask_t mask);
+#else
+static inline void smp_send_reschedule_mask(cpumask_t mask)
+{
+	int cpu;
+
+	for_each_cpu_mask(cpu, mask) {
+		smp_send_reschedule(cpu);
+	}
+}
+#endif
 
 /*
  * Prepare machine for booting other CPUs.
kernel/softirq.c +60 -0

78 lines not on this page · raw message

maintainer
#1 lore raw

From: [email protected] (Tom Herbert)
Date: Wed, 5 Mar 2008 12:51:16 -0800 (PST)

Quoted 3 lines

This patch implements kernel changes to allow scheduling of softirq's between processors.

I've stated this in the past and I still feel that it is foolish to put all of this code into the kernel when every single piece of networking hardware will be doing this for us transparently.

Maybe if someone had proposed this 4 or 5 years ago, but right now this code will be irrelevant by the time it ships to any real users.

#2 lore raw
Quoted 5 lines · David Miller

From: [email protected] (Tom Herbert)
Date: Wed, 5 Mar 2008 12:51:16 -0800 (PST)

Quoted 2 lines

This patch implements kernel changes to allow scheduling of softirq's between processors.

Quoted 8 lines
Quoted 1 line

I've stated this in the past and I still feel that it is foolish to put all of this code into the kernel when every single piece of networking hardware will be doing this for us transparently.

Maybe if someone had proposed this 4 or 5 years ago, but right now this code will be irrelevant by the time it ships to any real users.

Plus it seems that for this kind of stuff it be better to replace network softirq with kthreads (like in -rt kernel) and let the scheduler take care of the load balancing. More flexible and scalable. I'd suggest for your to play with -rt kernel and see if it already does what you need.

Max

#3 lore raw
Quoted 5 lines

Plus it seems that for this kind of stuff it be better to replace network softirq with kthreads (like in -rt kernel) and let the scheduler take care of the load balancing. More flexible and scalable.
I'd suggest for your to play with -rt kernel and see if it already does what you need.

We looked a bit at using the ksoftirqd thread for that, but that seemed to have more complexity and overhead as a solution.

I didn't look at -r kernel though, thanks for the pointer to that.

Tom

#4 lore raw
In reply to Max Krasnyanskiy
Quoted 13 lines · Max Krasnyanskiy
Quoted 12 lines · David Miller

From: [email protected] (Tom Herbert)
Date: Wed, 5 Mar 2008 12:51:16 -0800 (PST)

Quoted 4 lines

This patch implements kernel changes to allow scheduling of softirq's between processors.

I've stated this in the past and I still feel that it is foolish to put all of this code into the kernel when every single piece of networking hardware will be doing this for us transparently.

Quoted 8 lines
Quoted 2 lines

Maybe if someone had proposed this 4 or 5 years ago, but right now this code will be irrelevant by the time it ships to any real users.

Plus it seems that for this kind of stuff it be better to replace network softirq with kthreads (like in -rt kernel) and let the scheduler take care of the load balancing. More flexible and scalable. I'd suggest for your to play with -rt kernel and see if it already does what you need.

Could we use something like this to reschedule NAPI onto other processors? If we get unlucky enough to have multiple napi routines polling on a single CPU, and one or more completely idle CPUs (idle at least for softirq) then we could really use one or the other of these solutions.

anyone know how -rt kernels work for high I/O load environments like 10 Gigabit Ethernet?

Jesse

#5 lore raw
Quoted 5 lines

Could we use something like this to reschedule NAPI onto other processors? If we get unlucky enough to have multiple napi routines polling on a single CPU, and one or more completely idle CPUs (idle at least for softirq) then we could really use one or the other of these solutions.

Jesse,

This patch does provide a general mechanism to schedule (or reschedule) NAPI to other CPUs. We implemented two scheduling
algorithms: 1) round robin scheduling of NAPI poll function across a set of CPUs on a per device basis 2) scheduling stack processing by directing packets to a CPU (using backlog queue); a hash is done on the 4-tuple to direct the packets for a connection to same CPU thus emulating HW RSS (we will add support for those devices that can provide the computed hash per packet).

An algorithm that reschedules NAPI based on load is possible. In the case you described, maybe the scheduling could take into account the number of devices in the poll list for the CPU.

Tom

#6 lore raw
Quoted 8 lines · Tom Herbert
Quoted 5 lines

Could we use something like this to reschedule NAPI onto other processors? If we get unlucky enough to have multiple napi routines polling on a single CPU, and one or more completely idle CPUs (idle at least for softirq) then we could really use one or the other of these solutions.

Jesse,

Quoted 8 lines

This patch does provide a general mechanism to schedule (or reschedule) NAPI to other CPUs. We implemented two scheduling
algorithms: 1) round robin scheduling of NAPI poll function across a set of CPUs on a per device basis 2) scheduling stack processing by directing packets to a CPU (using backlog queue); a hash is done on the 4-tuple to direct the packets for a connection to same CPU thus emulating HW RSS (we will add support for those devices that can provide the computed hash per packet).

Recent versions of Windows that are aware of RSS will instruct network drivers to update their RSS indirection tables so that received packets are handled on the same CPU as the thread likely to use the received data. This requires that the network stack knows the hash function, so Microsoft specified a "Toeplitz hash" for IPv4 and IPv6. You can expect that most hardware RSS implementations will use this function and not a simple XOR.

Ben.

Signature · 2 lines
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
#7 lore raw
Quoted 8 lines

Recent versions of Windows that are aware of RSS will instruct network drivers to update their RSS indirection tables so that received packets are handled on the same CPU as the thread likely to use the received data. This requires that the network stack knows the hash function, so Microsoft specified a "Toeplitz hash" for IPv4 and IPv6. You can expect that most hardware RSS implementations will use this function and not a simple XOR.

Thanks. I am planning to do the Toeplitz hash in the softRSS. Also, I was planning to add support for devices that provide the Toeplitz hash but don't do full RSS.

One nice feature about Microsoft RSS seems to be the ability for the stack to dynamically re-balance networking load of a device using an indirection table that is set up in the device. I was wondering if this is supported in Linux stack or if anyone is working on that?

Tom

#8 lore raw
Quoted 9 lines · Tom Herbert
Quoted 8 lines

Recent versions of Windows that are aware of RSS will instruct network drivers to update their RSS indirection tables so that received packets are handled on the same CPU as the thread likely to use the received data. This requires that the network stack knows the hash function, so Microsoft specified a "Toeplitz hash" for IPv4 and IPv6. You can expect that most hardware RSS implementations will use this function and not a simple XOR.

Quoted 8 lines

Thanks. I am planning to do the Toeplitz hash in the softRSS. Also, I was planning to add support for devices that provide the Toeplitz hash but don't do full RSS.

One nice feature about Microsoft RSS seems to be the ability for the stack to dynamically re-balance networking load of a device using an indirection table that is set up in the device. I was wondering if this is supported in Linux stack or if anyone is working on that?

It's not supported, but it's on David Miller's to-do list[1].

By the way, Microsoft suddenly decided that RSS is too problematic to enable by default[2] because software and hardware can disagree about hash values in the presence of some local NAT implementations. Hopefully we can avoid that particular pitfall in Linux.

Ben.

1. http://vger.kernel.org/~davem/net_todo.html
2. http://support.microsoft.com/kb/948496

Signature · 2 lines
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
#10 lore raw
Quoted 10 lines · David Miller

From: Ben Hutchings <[email protected]>
Date: Wed, 12 Mar 2008 15:10:52 +0000

Quoted 1 line

It's not supported, but it's on David Miller's to-do list[1].

...

Quoted 1 line

1. http://vger.kernel.org/~davem/net_todo.html

That copy of the TODO list is out of date, and we fully support multiqueue RX devices, it's a device driver level issue at this point.

The specific part I was referring to was:

"This scheme can be further improved upon, if the host tells the driver what
CPU it wished to run a particular session on. With this information, the driver can steer a session to the same CPU that the scheduler runs the socket reads on, and achieve the best cache locality for both kernel and user level rx processing."

So far as I'm aware, this hasn't been done. If it has, I would love to know how to work with it.

Ben.

Signature · 2 lines
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
maintainer
#11 lore raw

From: Ben Hutchings <[email protected]>
Date: Thu, 13 Mar 2008 11:47:19 +0000

Quoted 10 lines

The specific part I was referring to was:

"This scheme can be further improved upon, if the host tells the driver what
CPU it wished to run a particular session on. With this information, the driver can steer a session to the same CPU that the scheduler runs the socket reads on, and achieve the best cache locality for both kernel and user level rx processing."

So far as I'm aware, this hasn't been done. If it has, I would love to know how to work with it.

That bit is not implemented, no.