Skip to content

Commit 127b903

Browse files
Fernand SieberPeter Zijlstra
authored andcommitted
sched/proxy: Yield the donor task
When executing a task in proxy context, handle yields as if they were requested by the donor task. This matches the traditional PI semantics of yield() as well. This avoids scenario like proxy task yielding, pick next task selecting the same previous blocked donor, running the proxy task again, etc. Reported-by: kernel test robot <oliver.sang@intel.com> Closes: https://lore.kernel.org/oe-lkp/202510211205.1e0f5223-lkp@intel.com Suggested-by: Peter Zijlstra <peterz@infradead.org> Signed-off-by: Fernand Sieber <sieberf@amazon.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://patch.msgid.link/20251106104022.195157-1-sieberf@amazon.com
1 parent 977b9a0 commit 127b903

5 files changed

Lines changed: 8 additions & 7 deletions

File tree

kernel/sched/deadline.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2143,7 +2143,7 @@ static void yield_task_dl(struct rq *rq)
21432143
* it and the bandwidth timer will wake it up and will give it
21442144
* new scheduling parameters (thanks to dl_yielded=1).
21452145
*/
2146-
rq->curr->dl.dl_yielded = 1;
2146+
rq->donor->dl.dl_yielded = 1;
21472147

21482148
update_rq_clock(rq);
21492149
update_curr_dl(rq);

kernel/sched/ext.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,7 @@ static bool dequeue_task_scx(struct rq *rq, struct task_struct *p, int deq_flags
14741474
static void yield_task_scx(struct rq *rq)
14751475
{
14761476
struct scx_sched *sch = scx_root;
1477-
struct task_struct *p = rq->curr;
1477+
struct task_struct *p = rq->donor;
14781478

14791479
if (SCX_HAS_OP(sch, yield))
14801480
SCX_CALL_OP_2TASKS_RET(sch, SCX_KF_REST, yield, rq, p, NULL);
@@ -1485,7 +1485,7 @@ static void yield_task_scx(struct rq *rq)
14851485
static bool yield_to_task_scx(struct rq *rq, struct task_struct *to)
14861486
{
14871487
struct scx_sched *sch = scx_root;
1488-
struct task_struct *from = rq->curr;
1488+
struct task_struct *from = rq->donor;
14891489

14901490
if (SCX_HAS_OP(sch, yield))
14911491
return SCX_CALL_OP_2TASKS_RET(sch, SCX_KF_REST, yield, rq,

kernel/sched/fair.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8980,7 +8980,7 @@ static void put_prev_task_fair(struct rq *rq, struct task_struct *prev, struct t
89808980
*/
89818981
static void yield_task_fair(struct rq *rq)
89828982
{
8983-
struct task_struct *curr = rq->curr;
8983+
struct task_struct *curr = rq->donor;
89848984
struct cfs_rq *cfs_rq = task_cfs_rq(curr);
89858985
struct sched_entity *se = &curr->se;
89868986

kernel/sched/rt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1490,7 +1490,7 @@ static void requeue_task_rt(struct rq *rq, struct task_struct *p, int head)
14901490

14911491
static void yield_task_rt(struct rq *rq)
14921492
{
1493-
requeue_task_rt(rq, rq->curr, 0);
1493+
requeue_task_rt(rq, rq->donor, 0);
14941494
}
14951495

14961496
static int find_lowest_rq(struct task_struct *task);

kernel/sched/syscalls.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,7 +1319,7 @@ static void do_sched_yield(void)
13191319
rq = this_rq_lock_irq(&rf);
13201320

13211321
schedstat_inc(rq->yld_count);
1322-
current->sched_class->yield_task(rq);
1322+
rq->donor->sched_class->yield_task(rq);
13231323

13241324
preempt_disable();
13251325
rq_unlock_irq(rq, &rf);
@@ -1388,12 +1388,13 @@ EXPORT_SYMBOL(yield);
13881388
*/
13891389
int __sched yield_to(struct task_struct *p, bool preempt)
13901390
{
1391-
struct task_struct *curr = current;
1391+
struct task_struct *curr;
13921392
struct rq *rq, *p_rq;
13931393
int yielded = 0;
13941394

13951395
scoped_guard (raw_spinlock_irqsave, &p->pi_lock) {
13961396
rq = this_rq();
1397+
curr = rq->donor;
13971398

13981399
again:
13991400
p_rq = task_rq(p);

0 commit comments

Comments
 (0)