Skip to contentSkip to conversation

sched/core: Call wq_worker_tick() for the execution context

PATCH Applied Hui Su 4 participants 4 messages Sep 2 – Sep 10 Scheduler

lore
Share & tools
lore

Hui Su

author
#0 lore raw

PATCH 1/1 sched/core: Call wq_worker_tick() for the execution context

wq_worker_tick() accounts CPU time and detects CPU-intensive work for the kworker that is actually running. With proxy execution, rq->donor is the scheduling context while rq->curr is the execution context.

Calling the hook with rq->donor can skip workqueue accounting when a kworker is executing on behalf of a donor task. It can also account a blocked kworker when the donor is a worker but rq->curr is the task actually executing. The former can delay WORKER_CPU_INTENSIVE handling and pool concurrency management, which can delay pending kernel work and userspace operations depending on it.

Use rq->curr for the workqueue tick hook while retaining rq->donor for scheduler accounting.

Fixes af0c8b2bf67b ("sched: Split scheduler and execution contexts")
---
 kernel/sched/core.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
kernel/sched/core.c +5 -4
index f78275192036..a86fd3d88714 100644
@@ -5770,8 +5770,8 @@ void sched_tick(void)
 {
 	int cpu = smp_processor_id();
 	struct rq *rq = cpu_rq(cpu);
-	/* accounting goes to the donor task */
-	struct task_struct *donor;
+	/* scheduler accounting goes to the donor task */
+	struct task_struct *curr, *donor;
 	struct rq_flags rf;
 	unsigned long hw_pressure;
 	u64 resched_latency;
@@ -5782,6 +5782,7 @@ void sched_tick(void)
 	sched_clock_tick();
 
 	rq_lock(rq, &rf);
+	curr = rq->curr;
 	donor = rq->donor;
 
 	psi_account_irqtime(rq, donor, NULL);
@@ -5807,8 +5808,8 @@ void sched_tick(void)
 
 	perf_event_task_tick();
 
-	if (donor->flags & PF_WQ_WORKER)
-		wq_worker_tick(donor);
+	if (curr->flags & PF_WQ_WORKER)
+		wq_worker_tick(curr);
 
 	if (!scx_switched_all()) {
 		rq->idle_balance = idle_cpu(cpu);

base-commit: 89a312991dc6e638a36adc43ccb91dbc25504c04

Signature · 1 line
2.54.0
Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Hui Su

wq_worker_tick() accounts CPU time and detects CPU-intensive work for the kworker that is actually running. With proxy execution, rq->donor is the scheduling context while rq->curr is the execution context.

Calling the hook with rq->donor can skip workqueue accounting when a kworker is executing on behalf of a donor task. It can also account a blocked kworker when the donor is a worker but rq->curr is the task actually executing. The former can delay WORKER_CPU_INTENSIVE handling and pool concurrency management, which can delay pending kernel work and userspace operations depending on it.

Quoted 5 lines

Use rq->curr for the workqueue tick hook while retaining rq->donor for scheduler accounting.

Fixes af0c8b2bf67b ("sched: Split scheduler and execution contexts")

Peter, how do you want to route this patch? It can go through either sched or wq.

Thanks.

Signature · 1 line
tejun
maintainer
#2 lore raw
Quoted 15 lines · Tejun Heo
Quoted 14 lines · Hui Su

wq_worker_tick() accounts CPU time and detects CPU-intensive work for the kworker that is actually running. With proxy execution, rq->donor is the scheduling context while rq->curr is the execution context.

Calling the hook with rq->donor can skip workqueue accounting when a kworker is executing on behalf of a donor task. It can also account a blocked kworker when the donor is a worker but rq->curr is the task actually executing. The former can delay WORKER_CPU_INTENSIVE handling and pool concurrency management, which can delay pending kernel work and userspace operations depending on it.

Use rq->curr for the workqueue tick hook while retaining rq->donor for scheduler accounting.

Quoted 7 lines
Quoted 2 lines
Fixes af0c8b2bf67b ("sched: Split scheduler and execution contexts")

Peter, how do you want to route this patch? It can go through either sched or wq.

Sorry, seems this got lost in the email deluge :/ I can take it through sched/urgent.

merge bot Applied
#3 lore raw
In reply to Hui Su
The following commit has been merged into the sched/urgent branch of tip:

The following commit has been merged into the sched/urgent branch of tip:

Commit-ID:     f5741d2b34519d387edf6e9798fc7030c20a35f3
Gitweb:        https://git.kernel.org/tip/f5741d2b34519d387edf6e9798fc7030c20a35f3
Author:        Hui Su <[email protected]>
AuthorDate:    Wed, 02 Sep 2026 23:02:09 +08:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Thu, 10 Sep 2026 10:22:52 +02:00

sched/core: Call wq_worker_tick() for the execution context

wq_worker_tick() accounts CPU time and detects CPU-intensive work for the kworker that is actually running. With proxy execution, rq->donor is the scheduling context while rq->curr is the execution context.

Calling the hook with rq->donor can skip workqueue accounting when a kworker is executing on behalf of a donor task. It can also account a blocked kworker when the donor is a worker but rq->curr is the task actually executing. The former can delay WORKER_CPU_INTENSIVE handling and pool concurrency management, which can delay pending kernel work and userspace operations depending on it.

Use rq->curr for the workqueue tick hook while retaining rq->donor for scheduler accounting.

Fixes af0c8b2bf67b ("sched: Split scheduler and execution contexts")
---
 kernel/sched/core.c |  9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
kernel/sched/core.c +5 -4
index b998ef6..7885ff7 100644
@@ -5776,8 +5776,8 @@ void sched_tick(void)
 {
 	int cpu = smp_processor_id();
 	struct rq *rq = cpu_rq(cpu);
-	/* accounting goes to the donor task */
-	struct task_struct *donor;
+	/* scheduler accounting goes to the donor task */
+	struct task_struct *curr, *donor;
 	struct rq_flags rf;
 	unsigned long hw_pressure;
 	u64 resched_latency;
@@ -5788,6 +5788,7 @@ void sched_tick(void)
 	sched_clock_tick();
 
 	rq_lock(rq, &rf);
+	curr = rq->curr;
 	donor = rq->donor;
 
 	psi_account_irqtime(rq, donor, NULL);
@@ -5813,8 +5814,8 @@ void sched_tick(void)
 
 	perf_event_task_tick();
 
-	if (donor->flags & PF_WQ_WORKER)
-		wq_worker_tick(donor);
+	if (curr->flags & PF_WQ_WORKER)
+		wq_worker_tick(curr);
 
 	if (!scx_switched_all()) {
 		rq->idle_balance = idle_cpu(cpu);