mirror of
https://github.com/torvalds/linux.git
synced 2026-07-28 01:55:51 +02:00
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
This commit is contained in:
parent
cd8e62c858
commit
f0c1ecde64
|
|
@ -2236,8 +2236,29 @@ void deactivate_task(struct rq *rq, struct task_struct *p, int flags)
|
|||
dequeue_task(rq, p, flags);
|
||||
}
|
||||
|
||||
static void block_task(struct rq *rq, struct task_struct *p, int flags)
|
||||
static void block_task(struct rq *rq, struct task_struct *p, unsigned long task_state)
|
||||
{
|
||||
int flags = DEQUEUE_NOCLOCK;
|
||||
|
||||
p->sched_contributes_to_load =
|
||||
(task_state & TASK_UNINTERRUPTIBLE) &&
|
||||
!(task_state & TASK_NOLOAD) &&
|
||||
!(task_state & TASK_FROZEN);
|
||||
|
||||
if (unlikely(is_special_task_state(task_state)))
|
||||
flags |= DEQUEUE_SPECIAL;
|
||||
|
||||
/*
|
||||
* __schedule() ttwu()
|
||||
* prev_state = prev->state; if (p->on_rq && ...)
|
||||
* if (prev_state) goto out;
|
||||
* p->on_rq = 0; smp_acquire__after_ctrl_dep();
|
||||
* p->state = TASK_WAKING
|
||||
*
|
||||
* Where __schedule() and ttwu() have matching control dependencies.
|
||||
*
|
||||
* After this, schedule() must not care about p->state any more.
|
||||
*/
|
||||
if (dequeue_task(rq, p, DEQUEUE_SLEEP | flags))
|
||||
__block_task(rq, p);
|
||||
}
|
||||
|
|
@ -6587,7 +6608,6 @@ static bool try_to_block_task(struct rq *rq, struct task_struct *p,
|
|||
unsigned long *task_state_p, bool should_block)
|
||||
{
|
||||
unsigned long task_state = *task_state_p;
|
||||
int flags = DEQUEUE_NOCLOCK;
|
||||
|
||||
if (signal_pending_state(task_state, p)) {
|
||||
WRITE_ONCE(p->__state, TASK_RUNNING);
|
||||
|
|
@ -6607,26 +6627,7 @@ static bool try_to_block_task(struct rq *rq, struct task_struct *p,
|
|||
if (!should_block)
|
||||
return false;
|
||||
|
||||
p->sched_contributes_to_load =
|
||||
(task_state & TASK_UNINTERRUPTIBLE) &&
|
||||
!(task_state & TASK_NOLOAD) &&
|
||||
!(task_state & TASK_FROZEN);
|
||||
|
||||
if (unlikely(is_special_task_state(task_state)))
|
||||
flags |= DEQUEUE_SPECIAL;
|
||||
|
||||
/*
|
||||
* __schedule() ttwu()
|
||||
* prev_state = prev->state; if (p->on_rq && ...)
|
||||
* if (prev_state) goto out;
|
||||
* p->on_rq = 0; smp_acquire__after_ctrl_dep();
|
||||
* p->state = TASK_WAKING
|
||||
*
|
||||
* Where __schedule() and ttwu() have matching control dependencies.
|
||||
*
|
||||
* After this, schedule() must not care about p->state any more.
|
||||
*/
|
||||
block_task(rq, p, flags);
|
||||
block_task(rq, p, task_state);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user