Skip to contentSkip to conversation

sched_ext: Use IRQ_WORK_INIT_HARD() to initialize sch->disable_irq_work

PATCH Applied Zqiang 3 participants 3 messages May 8

Subsystems (2)
lore
Share & tools
lore

Zqiang

author
#0 lore raw

PATCH 1/1 sched_ext: Use IRQ_WORK_INIT_HARD() to initialize sch->disable_irq_work

For built with PREEMPT_RT kernels, the scx_disable_irq_workfn() is called from per-cpu irq_work kthreads context, this means that when call the scx_dump_state() in the scx_disable_irq_workfn() to output current->comm/pid, it always output current irq_work kthread's comm/pid. this commit therefore use the IRQ_WORK_INIT_HARD() to initialize sch->disable_irq_work to make scx_disable_irq_workfn() is called from hardirq context.

---
 kernel/sched/ext.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/ext.c +1 -1
index d5be34e7b8ae..ef4e8e6addd1 100644
@@ -6770,7 +6770,7 @@ static struct scx_sched *scx_alloc_and_add_sched(struct scx_enable_cmd *cmd,
 
 	sch->slice_dfl = SCX_SLICE_DFL;
 	atomic_set(&sch->exit_kind, SCX_EXIT_NONE);
-	init_irq_work(&sch->disable_irq_work, scx_disable_irq_workfn);
+	sch->disable_irq_work = IRQ_WORK_INIT_HARD(scx_disable_irq_workfn);
 	kthread_init_work(&sch->disable_work, scx_disable_workfn);
 	timer_setup(&sch->bypass_lb_timer, scx_bypass_lb_timerfn, 0);
 
Signature · 1 line
2.17.1
reviewer Applied
#1 lore raw

Hello,

Applied to sched_ext/for-7.1-fixes with the following Fixes: tag added:

Fixes f4a6c506d118 ("sched_ext: Always bounce scx_disable() through irq_work")

Thanks.

--
tejun

#2 lore raw
In reply to Zqiang
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] The patch forces scx_disable_irq_workfn to run in hardirq context, causing unbounded execution…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The patch forces scx_disable_irq_workfn to run in hardirq context, causing unbounded execution time with interrupts disabled, which severely breaks PREEMPT_RT latency guarantees. --

commit 3f0e90ad5f7a3132810aa08d6137cba68235020c
Author: Zqiang <[email protected]>

sched_ext: Use IRQ_WORK_INIT_HARD() to initialize sch->disable_irq_work

This commit changes the initialization of the disable_irq_work in sched_ext to use IRQ_WORK_INIT_HARD(). The intention is to force scx_disable_irq_workfn() to run in hardirq context rather than a threaded kthread on PREEMPT_RT, so that scx_dump_state() captures the expected comm and pid.

Quoted 4 lines
kernel/sched/ext.c +0 -0
index 345aa11b84b28..c6b6038a97010 100644

[ ... ]

kernel/sched/ext.c static struct scx_sched *scx_alloc_and_add_sched(struct sched_ext_ops *ops, · line 6562

Quoted 6 lines
kernel/sched/ext.c +1 -1
@@ -6559,7 +6559,7 @@ static struct scx_sched *scx_alloc_and_add_sched(struct sched_ext_ops *ops,
 
 	sch->slice_dfl = SCX_SLICE_DFL;
 	atomic_set(&sch->exit_kind, SCX_EXIT_NONE);
-	init_irq_work(&sch->disable_irq_work, scx_disable_irq_workfn);
+	sch->disable_irq_work = IRQ_WORK_INIT_HARD(scx_disable_irq_workfn);

Will executing this in hardirq context cause severe latency spikes or hard lockups on PREEMPT_RT?

scx_disable_irq_workfn() calls scx_dump_state(), which performs a heavy workload. It iterates over all possible CPUs, takes their raw_spinlock_t runqueue locks, formats sequence buffers, saves stack traces, and executes BPF dump callbacks.

Performing this work with interrupts entirely disabled can break PREEMPT_RT latency guarantees.

Instead of moving the entire dump to hardirq context, could the original task's comm and pid be captured and stored in scx_exit_info during scx_vexit()?

This would allow the heavy dump workload to remain safely deferred to the threaded kthread execution.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1