Skip to content

Commit f0c1ecd

Browse files
johnstultz-workPeter Zijlstra
authored andcommitted
sched: Rework block_task so it can be directly called
Pull most of the logic out of try_to_block_task() and put it into block_task() directly, so that we can call block_task() and not have to worry about the failing cases in try_to_block_task() Suggested-by: Peter Zijlstra <peterz@infradead.org> Signed-off-by: John Stultz <jstultz@google.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://patch.msgid.link/20260512025635.2840817-5-jstultz@google.com
1 parent cd8e62c commit f0c1ecd

1 file changed

Lines changed: 23 additions & 22 deletions

File tree

kernel/sched/core.c

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2236,8 +2236,29 @@ void deactivate_task(struct rq *rq, struct task_struct *p, int flags)
22362236
dequeue_task(rq, p, flags);
22372237
}
22382238

2239-
static void block_task(struct rq *rq, struct task_struct *p, int flags)
2239+
static void block_task(struct rq *rq, struct task_struct *p, unsigned long task_state)
22402240
{
2241+
int flags = DEQUEUE_NOCLOCK;
2242+
2243+
p->sched_contributes_to_load =
2244+
(task_state & TASK_UNINTERRUPTIBLE) &&
2245+
!(task_state & TASK_NOLOAD) &&
2246+
!(task_state & TASK_FROZEN);
2247+
2248+
if (unlikely(is_special_task_state(task_state)))
2249+
flags |= DEQUEUE_SPECIAL;
2250+
2251+
/*
2252+
* __schedule() ttwu()
2253+
* prev_state = prev->state; if (p->on_rq && ...)
2254+
* if (prev_state) goto out;
2255+
* p->on_rq = 0; smp_acquire__after_ctrl_dep();
2256+
* p->state = TASK_WAKING
2257+
*
2258+
* Where __schedule() and ttwu() have matching control dependencies.
2259+
*
2260+
* After this, schedule() must not care about p->state any more.
2261+
*/
22412262
if (dequeue_task(rq, p, DEQUEUE_SLEEP | flags))
22422263
__block_task(rq, p);
22432264
}
@@ -6587,7 +6608,6 @@ static bool try_to_block_task(struct rq *rq, struct task_struct *p,
65876608
unsigned long *task_state_p, bool should_block)
65886609
{
65896610
unsigned long task_state = *task_state_p;
6590-
int flags = DEQUEUE_NOCLOCK;
65916611

65926612
if (signal_pending_state(task_state, p)) {
65936613
WRITE_ONCE(p->__state, TASK_RUNNING);
@@ -6607,26 +6627,7 @@ static bool try_to_block_task(struct rq *rq, struct task_struct *p,
66076627
if (!should_block)
66086628
return false;
66096629

6610-
p->sched_contributes_to_load =
6611-
(task_state & TASK_UNINTERRUPTIBLE) &&
6612-
!(task_state & TASK_NOLOAD) &&
6613-
!(task_state & TASK_FROZEN);
6614-
6615-
if (unlikely(is_special_task_state(task_state)))
6616-
flags |= DEQUEUE_SPECIAL;
6617-
6618-
/*
6619-
* __schedule() ttwu()
6620-
* prev_state = prev->state; if (p->on_rq && ...)
6621-
* if (prev_state) goto out;
6622-
* p->on_rq = 0; smp_acquire__after_ctrl_dep();
6623-
* p->state = TASK_WAKING
6624-
*
6625-
* Where __schedule() and ttwu() have matching control dependencies.
6626-
*
6627-
* After this, schedule() must not care about p->state any more.
6628-
*/
6629-
block_task(rq, p, flags);
6630+
block_task(rq, p, task_state);
66306631
return true;
66316632
}
66326633

0 commit comments

Comments
 (0)