Skip to contentSkip to conversation

mitigate-resched-interrupt-floods

PATCH In review Joe Korty 3 participants 3 messages Jul 25, 2007 – Jul 26, 2007

lore
Share & tools
lore

Joe Korty

author
#0 lore raw

PATCH 1/3 mitigate-resched-interrupt-floods

Mitigate rescheduling interrupt floods.

Background: preempt-rt sends a resched interrupt to all other cpus whenever some realtime task gets preempted. This is to give that task a chance to continue running on some other cpu. Unfortunately this can cause 'resched interrupt floods' when there are large numbers of realtime tasks on the system that are continually being preempted.

This patch reduces such interrupts by noting that it is not necessary to send rescheduling interrupts to every cpu in the system, just to those cpus in the affinity mask of the task to be migrated.

This works well in the real world, as traditionally realtime tasks are carefully targeted to specific cpus or sets of cpus, meaning users often give such tasks reduced affinity masks.

arch/i386/kernel/smp.c +9 -0
Index: 2.6.22.1-rt8/arch/i386/kernel/smp.c
===================================================================
@@ -18,6 +18,7 @@
 #include <linux/cache.h>
 #include <linux/interrupt.h>
 #include <linux/cpu.h>
+#include <linux/cpumask.h>
 #include <linux/module.h>
 
 #include <asm/mtrr.h>
@@ -483,6 +484,14 @@
 	send_IPI_allbutself(RESCHEDULE_VECTOR);
 }
 
+void smp_send_reschedule_allbutself_cpumask(cpumask_t mask)
+{
+	cpu_clear(smp_processor_id(), mask);
+	cpus_and(mask, mask, cpu_online_map);
+	if (!cpus_empty(mask))
+		send_IPI_mask(mask, RESCHEDULE_VECTOR);
+}
+
 /*
  * Structure and data for smp_call_function(). This is designed to minimise
  * static memory requirements. It also looks cleaner.
arch/x86_64/kernel/smp.c +9 -0
Index: 2.6.22.1-rt8/arch/x86_64/kernel/smp.c
===================================================================
@@ -15,6 +15,7 @@
 #include <linux/delay.h>
 #include <linux/spinlock.h>
 #include <linux/smp.h>
+#include <linux/cpumask.h>
 #include <linux/kernel_stat.h>
 #include <linux/mc146818rtc.h>
 #include <linux/interrupt.h>
@@ -304,6 +305,14 @@
 	send_IPI_allbutself(RESCHEDULE_VECTOR);
 }
 
+void smp_send_reschedule_allbutself_cpumask(cpumask_t mask)
+{
+	cpu_clear(smp_processor_id(), mask);
+	cpus_and(mask, mask, cpu_online_map);
+	if (!cpus_empty(mask))
+		send_IPI_mask(mask, RESCHEDULE_VECTOR);
+}
+
 /*
  * Structure and data for smp_call_function(). This is designed to minimise
  * static memory requirements. It also looks cleaner.
include/linux/smp.h +9 -0
Index: 2.6.22.1-rt8/include/linux/smp.h
===================================================================
@@ -43,6 +43,14 @@
  */
 extern void smp_send_reschedule_allbutself(void);
 
+#ifdef HAVE_RESCHEDULE_ALLBUTSELF_CPUMASK
+extern void smp_send_reschedule_allbutself_cpumask(cpumask_t);
+#else
+static inline void smp_send_reschedule_allbutself_cpumask(cpumask_t mask) {
+	smp_send_reschedule_allbutself();
+}
+#endif
+
 
 /*
  * Prepare machine for booting other CPUs.
@@ -108,6 +116,7 @@
 	})
 static inline void smp_send_reschedule(int cpu) { }
 static inline void smp_send_reschedule_allbutself(void) { }
+static inline void smp_send_reschedule_allbutself_cpumask(cpumask_t) { }
 #define num_booting_cpus()			1
 #define smp_prepare_boot_cpu()			do {} while (0)
 static inline int smp_call_function_single(int cpuid, void (*func) (void *info),
kernel/sched.c +2 -2
Index: 2.6.22.1-rt8/kernel/sched.c
===================================================================
@@ -1858,7 +1858,7 @@
 			 * nevertheless, maybe one of them can take
 			 * this task:
 			 */
-			smp_send_reschedule_allbutself();
+			smp_send_reschedule_allbutself_cpumask(p->cpus_allowed);
 
 		schedstat_inc(this_rq, rto_wakeup);
 	}
@@ -2116,7 +2116,7 @@
 	 */
 	if (unlikely(rt_task(current) && prev->se.on_rq && rt_task(prev))) {
 		schedstat_inc(rq, rto_schedule);
-		smp_send_reschedule_allbutself();
+		smp_send_reschedule_allbutself_cpumask(current->cpus_allowed);
 	}
 #endif
 	prev_state = prev->state;
include/asm-i386/smp.h +2 -0
Index: 2.6.22.1-rt8/include/asm-i386/smp.h
===================================================================
@@ -174,4 +174,6 @@
 #endif
 #endif
 
+#define HAVE_RESCHEDULE_ALLBUTSELF_CPUMASK 1
+
 #endif
include/asm-x86_64/smp.h +3 -0
Index: 2.6.22.1-rt8/include/asm-x86_64/smp.h
===================================================================
@@ -113,5 +113,8 @@
 #else
 #define cpu_physical_id(cpu)		boot_cpu_id
 #endif /* !CONFIG_SMP */
+
+#define HAVE_RESCHEDULE_ALLBUTSELF_CPUMASK 1
+
 #endif
 
#1 lore raw
Quoted 1 line · Joe Korty

Mitigate rescheduling interrupt floods.

makes sense - i've applied it. (please Cc: lkml too for -rt patch submissions in the future - thanks!)

Ingo

#2 lore raw
Quoted 9 lines · Ingo Molnar
Quoted 1 line · Joe Korty

Mitigate rescheduling interrupt floods.

makes sense - i've applied it.

(please Cc: lkml too for -rt patch
submissions in the future - thanks!)

Especially in this case, where the patch is relevant to Linus's tree as well.

Thanks,

Sven

Quoted 1 line

Ingo

Signature · 3 lines
Sven-Thorsten Dietrich
+1 415 694-2930
( www.novell.com/linux )