softirq: Introduce SOFTIRQ_FORCED_THREADING
PATCH 1/1 softirq: Introduce SOFTIRQ_FORCED_THREADING
At present, whether the softirq is executed when the interrupt exits is controlled by IRQ_FORCED_THREADING. This is unreasonable. It should be split and allowed to take effect separately.
At the same time, we should increase the priority of ksoftirqd when forbidden to execute in interrupt exits. I refer to the implementation of PREEMPT_RT and think it is reasonable.
Signed-off-by Wang Qing <[email protected]>
--- kernel/Kconfig.preempt | 10 ++++++++++ kernel/irq/Kconfig | 3 ++- kernel/softirq.c | 21 ++++++++++++++++++++- 3 files changed, 32 insertions(+), 2 deletions(-)
kernel/Kconfig.preempt +10 -0
@@ -60,6 +60,7 @@ config PREEMPT_RT bool "Fully Preemptible Kernel (Real-Time)" depends on EXPERT && ARCH_SUPPORTS_RT select PREEMPTION + select SOFTIRQ_FORCED_THREADING help This option turns the kernel into a real-time kernel by replacing various locking primitives (spinlocks, rwlocks, etc.) with
@@ -118,4 +119,13 @@ config SCHED_CORE which is the likely usage by Linux distributions, there should be no measurable impact on performance. +config SOFTIRQ_FORCED_THREADING + bool "Balance softirq execute" + help + This option will force the softirq to be executed in ksoftirqd, + cancel its execution timing when the interrupt exits, and change + ksoftirqd to a real-time process. + In this way, the execution of softirq can be executed more balanced, + and the maximum scheduling delay caused by the execution of softirq + in the RT process can be reduced.
kernel/irq/Kconfig +2 -1
@@ -111,7 +111,8 @@ config GENERIC_IRQ_RESERVATION_MODE # Support forced irq threading config IRQ_FORCED_THREADING - bool + bool + select SOFTIRQ_FORCED_THREADING config SPARSE_IRQ bool "Support sparse irq numbering" if MAY_HAVE_SPARSE_IRQ
kernel/softirq.c +20 -1
@@ -29,6 +29,7 @@#include <linux/wait_bit.h> #include <asm/softirq_stack.h> +#include <uapi/linux/sched/types.h> #define CREATE_TRACE_POINTS #include <trace/events/irq.h>
@@ -417,12 +418,18 @@ static inline bool should_wake_ksoftirqd(void)return true; } +#ifdef CONFIG_SOFTIRQ_FORCED_THREADING +static inline void invoke_softirq (void ) +{ +wakeup_softirqd (); +} +#else static inline void invoke_softirq (void ) {if (ksoftirqd_running (local_softirq_pending ()))return ; -if (!force_irqthreads || !__this_cpu_read (ksoftirqd)) { +if (!__this_cpu_read (ksoftirqd)) {#ifdef CONFIG_HAVE_IRQ_EXIT_ON_IRQ_STACK /* * We can safely execute softirq on the current stack if
@@ -442,6 +449,7 @@ static inline void invoke_softirq(void) wakeup_softirqd(); } } +#endif asmlinkage __visible void do_softirq(void) {
@@ -909,6 +917,14 @@ static int ksoftirqd_should_run(unsigned int cpu)return local_softirq_pending (); } +#ifndef CONFIG_SOFTIRQ_FORCED_THREADING +static void ksoftirqd_set_sched_params (unsigned int cpu) +{ +struct sched_param param = { .sched_priority =1 }; +sched_setscheduler (current,SCHED_FIFO , ¶m); +} +#endif +static void run_ksoftirqd (unsigned int cpu) {ksoftirqd_run_begin ();
@@ -957,6 +973,9 @@ static int takeover_tasklets(unsigned int cpu)static struct smp_hotplug_thread softirq_threads = { .store = &ksoftirqd, +#ifndef CONFIG_SOFTIRQ_FORCED_THREADING + .setup = ksoftirqd_set_sched_params, +#endif .thread_should_run = ksoftirqd_should_run, .thread_fn = run_ksoftirqd, .thread_comm ="ksoftirqd/%u" ,
Signature · 1 line
2.7.4