Skip to contentSkip to conversation

sched/deadline: Use task_on_rq_migrating() helper

PATCH Superseded [email protected] 4 participants 6 messages Jun 8 – Jun 9 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sched/deadline: Use task_on_rq_migrating() helper

From: Liang Luo <[email protected]>

Replace the open-coded "p->on_rq == TASK_ON_RQ_MIGRATING" comparisons in enqueue_task_dl() and dequeue_task_dl() with the existing task_on_rq_migrating() helper, consistent with the rest of the scheduler code.

The helper uses READ_ONCE() when loading ->on_rq, which was added by commit c546951d9c93 ("sched/core: Use READ_ONCE()/WRITE_ONCE() in move_queued_task()/task_rq_lock()") for LKMM compliance. As documented in that commit, move_queued_task() synchronizes with task_rq_lock():

move_queued_task() task_rq_lock()

  [S] ->on_rq = MIGRATING          [L] rq = task_rq()
  WMB (__set_task_cpu())           ACQUIRE (rq->lock)
  [S] ->cpu = new_cpu              [L] ->on_rq

The READ_ONCE() on the ->on_rq load ensures proper pairing with the WRITE_ONCE() on the writer side. The open-coded checks in deadline.c lack this annotation.

No functional change.

---
 kernel/sched/deadline.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/sched/deadline.c +2 -2
index 7db4c87df83b..9d2c42b8661f 100644
@@ -2335,7 +2335,7 @@ static void enqueue_task_dl(struct rq *rq, struct task_struct *p, int flags)
 	check_schedstat_required();
 	update_stats_wait_start_dl(dl_rq_of_se(&p->dl), &p->dl);
 
-	if (p->on_rq == TASK_ON_RQ_MIGRATING)
+	if (task_on_rq_migrating(p))
 		flags |= ENQUEUE_MIGRATING;
 
 	enqueue_dl_entity(&p->dl, flags);
@@ -2354,7 +2354,7 @@ static bool dequeue_task_dl(struct rq *rq, struct task_struct *p, int flags)
 {
 	update_curr_dl(rq);
 
-	if (p->on_rq == TASK_ON_RQ_MIGRATING)
+	if (task_on_rq_migrating(p))
 		flags |= DEQUEUE_MIGRATING;
 
 	dequeue_dl_entity(&p->dl, flags);
Signature · 1 line
2.25.1
reviewer Reviewed-by on v1 1/1
#1 lore raw

Hello Liang,

Quoted 6 lines · On 6/8/2026 12:23 PM, [email protected] wrote:

From: Liang Luo <[email protected]>

Replace the open-coded "p->on_rq == TASK_ON_RQ_MIGRATING" comparisons in enqueue_task_dl() and dequeue_task_dl() with the existing task_on_rq_migrating() helper, consistent with the rest of the scheduler code.

Good cleanup but ...

Quoted 6 lines

The helper uses READ_ONCE() when loading ->on_rq, which was added by commit c546951d9c93 ("sched/core: Use READ_ONCE()/WRITE_ONCE() in move_queued_task()/task_rq_lock()") for LKMM compliance. As documented in that commit, move_queued_task() synchronizes with task_rq_lock():

Quoted 8 lines

move_queued_task() task_rq_lock()

  [S] ->on_rq = MIGRATING          [L] rq = task_rq()
  WMB (__set_task_cpu())           ACQUIRE (rq->lock)
  [S] ->cpu = new_cpu              [L] ->on_rq

The READ_ONCE() on the ->on_rq load ensures proper pairing with the WRITE_ONCE() on the writer side. The open-coded checks in deadline.c lack this annotation.

... this extra context feels unnecessary since the p->on_rq indicator is always stable at the time of dequeue / enqueue.

The calling context already holds the rq_lock() (and sometimes, also the p->pi_lock) so there are no concurrent writers for it to pair with
- in fact this same context will set p->on_rq back to TASK_ON_RQ_QUEUED after it is done enqueuing and before dropping the rq_lock().

Quoted 4 lines

No functional change.

For the change itself, feel free to include:

Quoted 29 lines
---
 kernel/sched/deadline.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/sched/deadline.c +2 -3
index 7db4c87df83b..9d2c42b8661f 100644
@@ -2335,7 +2335,7 @@ static void enqueue_task_dl(struct rq *rq, struct task_struct *p, int flags)
        check_schedstat_required();
        update_stats_wait_start_dl(dl_rq_of_se(&p->dl), &p->dl);
 
-       if (p->on_rq == TASK_ON_RQ_MIGRATING)
+       if (task_on_rq_migrating(p))
                flags |= ENQUEUE_MIGRATING;
 
        enqueue_dl_entity(&p->dl, flags);
@@ -2354,7 +2354,7 @@ static bool dequeue_task_dl(struct rq *rq, struct task_struct *p, int flags)
 {
        update_curr_dl(rq);
 
-       if (p->on_rq == TASK_ON_RQ_MIGRATING)
+       if (task_on_rq_migrating(p))
                flags |= DEQUEUE_MIGRATING;
 
        dequeue_dl_entity(&p->dl, flags);
--

2.25.1

Signature · 2 lines
Thanks and Regards,
Prateek
#2 lore raw

PATCH v2 1/1 sched/deadline: Use task_on_rq_migrating() helper

In reply to [email protected]

From: Liang Luo <[email protected]>

Replace the open-coded "p->on_rq == TASK_ON_RQ_MIGRATING" comparisons in enqueue_task_dl() and dequeue_task_dl() with the existing task_on_rq_migrating() helper, consistent with the rest of the scheduler code.

No functional change.

---
(no changes since v1)

 kernel/sched/deadline.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/sched/deadline.c +2 -2
index 7db4c87df83b..9d2c42b8661f 100644
@@ -2335,7 +2335,7 @@ static void enqueue_task_dl(struct rq *rq, struct task_struct *p, int flags)
 	check_schedstat_required();
 	update_stats_wait_start_dl(dl_rq_of_se(&p->dl), &p->dl);
 
-	if (p->on_rq == TASK_ON_RQ_MIGRATING)
+	if (task_on_rq_migrating(p))
 		flags |= ENQUEUE_MIGRATING;
 
 	enqueue_dl_entity(&p->dl, flags);
@@ -2354,7 +2354,7 @@ static bool dequeue_task_dl(struct rq *rq, struct task_struct *p, int flags)
 {
 	update_curr_dl(rq);
 
-	if (p->on_rq == TASK_ON_RQ_MIGRATING)
+	if (task_on_rq_migrating(p))
 		flags |= DEQUEUE_MIGRATING;
 
 	dequeue_dl_entity(&p->dl, flags);
Signature · 1 line
2.25.1
merge bot Applied
#3 lore raw
The following commit has been merged into the sched/core branch of tip:

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

Commit-ID:     9ebe5c3c29f6217412ff256134516d4dff0e5624
Gitweb:        https://git.kernel.org/tip/9ebe5c3c29f6217412ff256134516d4dff0e5624
Author:        Liang Luo <[email protected]>
AuthorDate:    Mon, 08 Jun 2026 15:55:00 +08:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Tue, 09 Jun 2026 10:28:08 +02:00

sched/deadline: Use task_on_rq_migrating() helper

Replace the open-coded "p->on_rq == TASK_ON_RQ_MIGRATING" comparisons in enqueue_task_dl() and dequeue_task_dl() with the existing task_on_rq_migrating() helper, consistent with the rest of the scheduler code.

No functional change.

---
 kernel/sched/deadline.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/sched/deadline.c +2 -2
index 4754dbe..5ccb06e 100644
@@ -2530,7 +2530,7 @@ static void enqueue_task_dl(struct rq *rq, struct task_struct *p, int flags)
 	check_schedstat_required();
 	update_stats_wait_start_dl(dl_rq, dl_se);
 
-	if (p->on_rq == TASK_ON_RQ_MIGRATING)
+	if (task_on_rq_migrating(p))
 		flags |= ENQUEUE_MIGRATING;
 
 	enqueue_dl_entity(dl_se, flags);
@@ -2552,7 +2552,7 @@ static bool dequeue_task_dl(struct rq *rq, struct task_struct *p, int flags)
 {
 	update_curr_dl(rq);
 
-	if (p->on_rq == TASK_ON_RQ_MIGRATING)
+	if (task_on_rq_migrating(p))
 		flags |= DEQUEUE_MIGRATING;
 
 	dequeue_dl_entity(&p->dl, flags);
maintainer
#4 lore raw
In reply to [email protected]
Quoted 17 lines · On Mon, Jun 08, 2026 at 02:53:07PM +0800, [email protected] wrote:

From: Liang Luo <[email protected]>

Replace the open-coded "p->on_rq == TASK_ON_RQ_MIGRATING" comparisons in enqueue_task_dl() and dequeue_task_dl() with the existing task_on_rq_migrating() helper, consistent with the rest of the scheduler code.

The helper uses READ_ONCE() when loading ->on_rq, which was added by commit c546951d9c93 ("sched/core: Use READ_ONCE()/WRITE_ONCE() in move_queued_task()/task_rq_lock()") for LKMM compliance. As documented in that commit, move_queued_task() synchronizes with task_rq_lock():

move_queued_task() task_rq_lock()

  [S] ->on_rq = MIGRATING          [L] rq = task_rq()
  WMB (__set_task_cpu())           ACQUIRE (rq->lock)
  [S] ->cpu = new_cpu              [L] ->on_rq
Quoted 5 lines

The READ_ONCE() on the ->on_rq load ensures proper pairing with the WRITE_ONCE() on the writer side. The open-coded checks in deadline.c lack this annotation.

No functional change.

This is completely irrelevant here. p->on_rq is set with rq->lock held, and tasks are {en,de}queued with rq->lock held. There is no concurrency.

#5 lore raw
Quoted 2 lines · Peter Zijlstra

This is completely irrelevant here. p->on_rq is set with rq->lock held, and tasks are {en,de}queued with rq->lock held. There is no concurrency.

You are right, my mistake. The READ_ONCE() explanation was incorrect. I've already sent v2 with the commit message fixed:

https://lore.kernel.org/all/[email protected]/

Thanks.