Skip to contentSkip to conversation

softirq: Allow to drop the softirq-BKL lock on PREEMPT_RT

RFC PATCH Superseded Sebastian Andrzej Siewior 1 participant 2 messages Jun 13, 2025 Real-time Linux (PREEMPT_RT)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Sebastian Andrzej Siewior

author maintainer
#0 lore raw

cover softirq: Allow to drop the softirq-BKL lock on PREEMPT_RT

After auditing the tree most of the local-BH locks are in tree now or the code has been changed to avoid the per-CPU ressource.

There are still a few places missing. While those are worked on, this patch allows to test the unlocked behaviour. Without the explicit softirq synchronisation, one softirq can interrupt and nest within.

This is what the behaviour can look like:

|     ktimers/20-204  [020] ..s.1   33.291036: softirq_entry: vec=1 [action=TIMER]
|     ktimers/20-204  [020] d.s42   33.291054: sched_wakeup: comm=kworker/u133:3 pid=1215 prio=120 target_cpu=020
|     ktimers/20-204  [020] d.H22   33.291146: irq_handler_entry: irq=37 name=ahci[0000:00:1f.2]
|     ktimers/20-204  [020] d.H22   33.291147: irq_handler_exit: irq=37 ret=handled
|     ktimers/20-204  [020] dNH52   33.291152: sched_wakeup: comm=irq/37-ahci[000 pid=810 prio=49 target_cpu=020
|     ktimers/20-204  [020] d.s22   33.291162: sched_switch: prev_comm=ktimers/20 prev_pid=204 prev_prio=98 prev_state=R+ ==> next_comm=irq/37-ahci[000 next_pid=810 next_prio=49
|irq/37-ahci[000-810  [020] D..12   33.291177: softirq_raise: vec=4 [action=BLOCK]
|irq/37-ahci[000-810  [020] ..s.1   33.291179: softirq_entry: vec=4 [action=BLOCK]
^^
|irq/37-ahci[000-810  [020] ..s.1   33.291187: softirq_exit: vec=4 [action=BLOCK]
|irq/37-ahci[000-810  [020] d..2.   33.291195: sched_switch: prev_comm=irq/37-ahci[000 prev_pid=810 prev_prio=49 prev_state=S ==> next_comm=ktimers/20 next_pid=204 next_prio=98
|     ktimers/20-204  [020] ..s.1   33.291227: softirq_exit: vec=1 [action=TIMER]

Sebastian Andrzej Siewior (1):
softirq: Allow to drop the softirq-BKL lock on PREEMPT_RT

 kernel/Kconfig.preempt | 13 +++++++
 kernel/softirq.c       | 83 ++++++++++++++++++++++++++++++++----------
 2 files changed, 76 insertions(+), 20 deletions(-)
Signature · 1 line
2.49.0
author maintainer
#1 lore raw

RFC PATCH 1/1 softirq: Allow to drop the softirq-BKL lock on PREEMPT_RT

softirqs are preemptible on PREEMPT_RT. There is synchronisation between individual sections which disable bottom halves. This in turn means that a forced threaded interrupt can not preempt another forced threaded interrupt. Instead it will PI-boost the other handler and wait for its completion.

This is required because code within a softirq section is assumed to be non-preemptible and may expect exclusive access to per-CPU resources such as variables or pinned timers.
Code with such expectation has been identified and updated to use local_lock_nested_bh() for locking of the per-CPU resource. This means the lock can be removed.

Add CONFIG_PREEMPT_RT_NEEDS_BH_LOCK which keeps the old behaviour if selected. Otherwise the softirq synchronising is lifted. The softirq_ctrl.cnt accounting remains to let NOHZ code if softirqs are currently handled.

---
 kernel/Kconfig.preempt | 13 +++++++
 kernel/softirq.c       | 83 ++++++++++++++++++++++++++++++++----------
 2 files changed, 76 insertions(+), 20 deletions(-)
kernel/Kconfig.preempt +13 -0
index 54ea59ff8fbeb..da326800c1c9b 100644
@@ -103,6 +103,19 @@ config PREEMPT_RT
 	  Select this if you are building a kernel for systems which
 	  require real-time guarantees.
 
+config PREEMPT_RT_NEEDS_BH_LOCK
+	bool "Enforce softirq synchronisation on PREEMPT_RT"
+	depends on PREEMPT_RT
+	help
+	  Enforce synchronisation across the softirqs context. On PREEMPT_RT
+	  the softirq is preemptible. This enforces the same per-CPU BLK
+	  semantic non-PREEMPT_RT builds have. This should not be needed
+	  because per-CPU locks were added to avoid the per-CPU BKL.
+
+	  This switch provides the old behaviour for testing reasons. Select
+	  this if you suspect an error with preemptible softirq and want test
+	  the old synchronized behaviour.
+
 config PREEMPT_COUNT
        bool
 
kernel/softirq.c +63 -20

117 lines not on this page · raw message

Signature · 1 line
2.49.0