Skip to content

Commit e1459a5

Browse files
author
Peter Zijlstra
committed
sched: Teach dequeue_task() about special task states
Since special task states must not suffer spurious wakeups, and the proposed delayed dequeue can cause exactly these (under some boundary conditions), propagate this knowledge into dequeue_task() such that it can do the right thing. Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Valentin Schneider <[email protected]> Tested-by: Valentin Schneider <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent a1c4466 commit e1459a5

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

kernel/sched/core.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6530,11 +6530,16 @@ static void __sched notrace __schedule(unsigned int sched_mode)
65306530
if (signal_pending_state(prev_state, prev)) {
65316531
WRITE_ONCE(prev->__state, TASK_RUNNING);
65326532
} else {
6533+
int flags = DEQUEUE_NOCLOCK;
6534+
65336535
prev->sched_contributes_to_load =
65346536
(prev_state & TASK_UNINTERRUPTIBLE) &&
65356537
!(prev_state & TASK_NOLOAD) &&
65366538
!(prev_state & TASK_FROZEN);
65376539

6540+
if (unlikely(is_special_task_state(prev_state)))
6541+
flags |= DEQUEUE_SPECIAL;
6542+
65386543
/*
65396544
* __schedule() ttwu()
65406545
* prev_state = prev->state; if (p->on_rq && ...)
@@ -6546,7 +6551,7 @@ static void __sched notrace __schedule(unsigned int sched_mode)
65466551
*
65476552
* After this, schedule() must not care about p->state any more.
65486553
*/
6549-
block_task(rq, prev, DEQUEUE_NOCLOCK);
6554+
block_task(rq, prev, flags);
65506555
}
65516556
switch_count = &prev->nvcsw;
65526557
}

kernel/sched/sched.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2248,10 +2248,11 @@ extern const u32 sched_prio_to_wmult[40];
22482248
*
22492249
*/
22502250

2251-
#define DEQUEUE_SLEEP 0x01
2251+
#define DEQUEUE_SLEEP 0x01 /* Matches ENQUEUE_WAKEUP */
22522252
#define DEQUEUE_SAVE 0x02 /* Matches ENQUEUE_RESTORE */
22532253
#define DEQUEUE_MOVE 0x04 /* Matches ENQUEUE_MOVE */
22542254
#define DEQUEUE_NOCLOCK 0x08 /* Matches ENQUEUE_NOCLOCK */
2255+
#define DEQUEUE_SPECIAL 0x10
22552256
#define DEQUEUE_MIGRATING 0x100 /* Matches ENQUEUE_MIGRATING */
22562257
#define DEQUEUE_DELAYED 0x200 /* Matches ENQUEUE_DELAYED */
22572258

0 commit comments

Comments
 (0)