The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] cpufreq: schedutil: Run irq_work in hardirq context on PREEMPT_RT
@ 2026-11-25  8:06 Zhongqiu Han
  2026-11-25  8:12 ` sashiko-bot
  2026-11-25  8:26 ` Christian Loehle
  0 siblings, 2 replies; 3+ messages in thread
From: Zhongqiu Han @ 2026-11-25  8:06 UTC (permalink / raw)
  To: rafael, viresh.kumar, mingo, peterz, juri.lelli, vincent.guittot,
	dietmar.eggemann, rostedt, bsegall, mgorman, vschneid,
	kprateek.nayak, bigeasy, clrkwllms
  Cc: linux-pm, linux-kernel, linux-rt-devel, zhongqiu.han

On PREEMPT_RT, an irq_work not marked IRQ_WORK_HARD_IRQ runs in the
per-CPU irq_work/N thread at SCHED_FIFO priority 1. The schedutil slow
path queues its irq_work on the local CPU, so the wakeup of the
SCHED_DEADLINE sugov thread is delayed until no other RT or DL task is
runnable on that CPU.

Meanwhile work_in_progress stays set, so no new frequency update is
queued for any CPU of the policy: one busy RT task can freeze the
frequency of its whole policy.

sugov_irq_work() only calls kthread_queue_work(), which only takes raw
spinlocks and is safe in hard interrupt context on PREEMPT_RT, so mark
the irq_work IRQ_WORK_HARD_IRQ, as commit f8d958880933 ("srcu: Use
IRQ_WORK_INIT_HARD for srcu's irq_work") did for srcu.

Tested on a Qualcomm SM8850 board running PREEMPT_RT, with SCMI cpufreq
forced into the slow path. With a SCHED_FIFO 10 stress-ng worker on CPU1
(30% load, 50 ms slices, 15 runs of 5 s each), sugov_irq_work() now runs
within 15 us of irq_work_queue() instead of waiting for the RT burst to
end (up to 212 ms), and the policy frequency is no longer frozen. The
irq_work latency below is measured from irq_work_queue() to the entry of
sugov_irq_work(). The cost is that the kthread wakeup now runs in the
irq_work IPI handler, as it does on !PREEMPT_RT. In a separate cpufreq
stress test with cyclictest (SCHED_FIFO 90) on all CPUs, this raises the
average IRQ work IPI time from ~0.5 us to ~1.3 us, with no change in the
number of IPIs, and the cyclictest per-CPU worst case by ~2 us.

  PREEMPT_RT                           before              after
  ---------------------------------    -------------       ----------
  irq_work latency on CPU1, max        130 - 212 ms        <= 14.5 us
  policy0 frozen, total per 5 s run    0.57 - 1.25 s       none
  cyclictest max, CPU1-5               13 - 16 us          14 - 18 us

On !PREEMPT_RT, cyclictest and IRQ work IPI duration are unchanged. No
lockdep or DEBUG_ATOMIC_SLEEP splat on either PREEMPT_RT or !PREEMPT_RT.

Signed-off-by: Zhongqiu Han <zhongqiu.han@oss.qualcomm.com>
---
 kernel/sched/cpufreq_schedutil.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c
index 14405a614991..b2e9ac7e3517 100644
--- a/kernel/sched/cpufreq_schedutil.c
+++ b/kernel/sched/cpufreq_schedutil.c
@@ -726,7 +726,7 @@ static int sugov_kthread_create(struct sugov_policy *sg_policy)
 	else
 		kthread_bind_mask(thread, policy->related_cpus);
 
-	init_irq_work(&sg_policy->irq_work, sugov_irq_work);
+	sg_policy->irq_work = IRQ_WORK_INIT_HARD(sugov_irq_work);
 	mutex_init(&sg_policy->work_lock);
 
 	wake_up_process(thread);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] cpufreq: schedutil: Run irq_work in hardirq context on PREEMPT_RT
  2026-11-25  8:06 [PATCH] cpufreq: schedutil: Run irq_work in hardirq context on PREEMPT_RT Zhongqiu Han
@ 2026-11-25  8:12 ` sashiko-bot
  2026-11-25  8:26 ` Christian Loehle
  1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-25  8:12 UTC (permalink / raw)
  To: Zhongqiu Han; +Cc: linux-rt-devel, linux-kernel

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] sched/deadline: unallocated bandwidth subtraction in
  dl_task_needs_bw_move() [1]
--

commit 6dbfa989b510ecc8b3f76fbbc75d3d06fb5180f2
Author: Zhongqiu Han <zhongqiu.han@oss.qualcomm.com>

cpufreq: schedutil: Run irq_work in hardirq context on PREEMPT_RT

This commit initializes sg_policy->irq_work with IRQ_WORK_INIT_HARD() so
that sugov_irq_work() runs in hardirq context on PREEMPT_RT instead of
being delayed behind runnable RT tasks.

> diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c
> index 14405a6149911..b2e9ac7e35172 100644
> --- a/kernel/sched/cpufreq_schedutil.c
> +++ b/kernel/sched/cpufreq_schedutil.c
> @@ -726,7 +726,7 @@ static int sugov_kthread_create(struct sugov_policy *sg_policy)
>  	else
>  		kthread_bind_mask(thread, policy->related_cpus);
>  
> -	init_irq_work(&sg_policy->irq_work, sugov_irq_work);
> +	sg_policy->irq_work = IRQ_WORK_INIT_HARD(sugov_irq_work);
>  	mutex_init(&sg_policy->work_lock);
>  
>  	wake_up_process(thread);

[Severity: High]
This problem wasn't introduced by this patch, but can binding the sugov
thread across exclusive cpuset partitions (root domains) here underflow
the source root domain's deadline bandwidth [1]?

sched_setattr_nocheck() configures the sugov thread with SCHED_DEADLINE
and SCHED_FLAG_SUGOV, which sets a non-zero p->dl.dl_bw while skipping
root domain bandwidth allocation because dl_entity_is_special(&p->dl) is
true.  If policy->related_cpus lies in a different root domain from the
kthread's initial CPU mask, set_cpus_allowed_ptr() or kthread_bind_mask()
calls set_cpus_allowed_dl(), which subtracts p->dl.dl_bw from the source
root domain whenever dl_task_needs_bw_move() returns true.

Unlike dl_add_task_root_domain() and dl_task_check_affinity(),
dl_task_needs_bw_move() does not exclude dl_entity_is_special(&p->dl)
tasks, so __dl_sub() subtracts bandwidth that was never added, triggering
a warning in __dl_sub() and corrupting SCHED_DEADLINE admission control
on the source root domain.

[1] https://sashiko.dev/#/bug/linux-a604bbac-776b-419e-820b-f5a41a07ff1c

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261125080613.1138573-1-zhongqiu.han@oss.qualcomm.com?part=1

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] cpufreq: schedutil: Run irq_work in hardirq context on PREEMPT_RT
  2026-11-25  8:06 [PATCH] cpufreq: schedutil: Run irq_work in hardirq context on PREEMPT_RT Zhongqiu Han
  2026-11-25  8:12 ` sashiko-bot
@ 2026-11-25  8:26 ` Christian Loehle
  1 sibling, 0 replies; 3+ messages in thread
From: Christian Loehle @ 2026-11-25  8:26 UTC (permalink / raw)
  To: Zhongqiu Han, rafael, viresh.kumar, mingo, peterz, juri.lelli,
	vincent.guittot, dietmar.eggemann, rostedt, bsegall, mgorman,
	vschneid, kprateek.nayak, bigeasy, clrkwllms
  Cc: linux-pm, linux-kernel, linux-rt-devel

On 11/25/26 08:06, Zhongqiu Han wrote:
> On PREEMPT_RT, an irq_work not marked IRQ_WORK_HARD_IRQ runs in the
> per-CPU irq_work/N thread at SCHED_FIFO priority 1. The schedutil slow
> path queues its irq_work on the local CPU, so the wakeup of the
> SCHED_DEADLINE sugov thread is delayed until no other RT or DL task is
> runnable on that CPU.
> 
> Meanwhile work_in_progress stays set, so no new frequency update is
> queued for any CPU of the policy: one busy RT task can freeze the
> frequency of its whole policy.
> 
> sugov_irq_work() only calls kthread_queue_work(), which only takes raw
> spinlocks and is safe in hard interrupt context on PREEMPT_RT, so mark
> the irq_work IRQ_WORK_HARD_IRQ, as commit f8d958880933 ("srcu: Use
> IRQ_WORK_INIT_HARD for srcu's irq_work") did for srcu.
> 
> Tested on a Qualcomm SM8850 board running PREEMPT_RT, with SCMI cpufreq
> forced into the slow path. With a SCHED_FIFO 10 stress-ng worker on CPU1
> (30% load, 50 ms slices, 15 runs of 5 s each), sugov_irq_work() now runs
> within 15 us of irq_work_queue() instead of waiting for the RT burst to
> end (up to 212 ms), and the policy frequency is no longer frozen. The
> irq_work latency below is measured from irq_work_queue() to the entry of
> sugov_irq_work(). The cost is that the kthread wakeup now runs in the
> irq_work IPI handler, as it does on !PREEMPT_RT. In a separate cpufreq
> stress test with cyclictest (SCHED_FIFO 90) on all CPUs, this raises the
> average IRQ work IPI time from ~0.5 us to ~1.3 us, with no change in the
> number of IPIs, and the cyclictest per-CPU worst case by ~2 us.
> 
>   PREEMPT_RT                           before              after
>   ---------------------------------    -------------       ----------
>   irq_work latency on CPU1, max        130 - 212 ms        <= 14.5 us
>   policy0 frozen, total per 5 s run    0.57 - 1.25 s       none
>   cyclictest max, CPU1-5               13 - 16 us          14 - 18 us
> 
> On !PREEMPT_RT, cyclictest and IRQ work IPI duration are unchanged. No
> lockdep or DEBUG_ATOMIC_SLEEP splat on either PREEMPT_RT or !PREEMPT_RT.
> 
> Signed-off-by: Zhongqiu Han <zhongqiu.han@oss.qualcomm.com>

Missing a fixes tag then?
FWIW
Reviewed-by: Christian Loehle <christian.loehle@arm.com>

> ---
>  kernel/sched/cpufreq_schedutil.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c
> index 14405a614991..b2e9ac7e3517 100644
> --- a/kernel/sched/cpufreq_schedutil.c
> +++ b/kernel/sched/cpufreq_schedutil.c
> @@ -726,7 +726,7 @@ static int sugov_kthread_create(struct sugov_policy *sg_policy)
>  	else
>  		kthread_bind_mask(thread, policy->related_cpus);
>  
> -	init_irq_work(&sg_policy->irq_work, sugov_irq_work);
> +	sg_policy->irq_work = IRQ_WORK_INIT_HARD(sugov_irq_work);
>  	mutex_init(&sg_policy->work_lock);
>  
>  	wake_up_process(thread);


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-25  8:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25  8:06 [PATCH] cpufreq: schedutil: Run irq_work in hardirq context on PREEMPT_RT Zhongqiu Han
2026-11-25  8:12 ` sashiko-bot
2026-11-25  8:26 ` Christian Loehle

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox