Skip to content

Commit 91caa5a

Browse files
Cruz ZhaoPeter Zijlstra
authored andcommitted
sched/core: Fix the bug that task won't enqueue into core tree when update cookie
In function sched_core_update_cookie(), a task will enqueue into the core tree only when it enqueued before, that is, if an uncookied task is cookied, it will not enqueue into the core tree until it enqueue again, which will result in unnecessary force idle. Here follows the scenario: CPU x and CPU y are a pair of SMT siblings. 1. Start task a running on CPU x without sleeping, and task b and task c running on CPU y without sleeping. 2. We create a cookie and share it to task a and task b, and then we create another cookie and share it to task c. 3. Simpling core_forceidle_sum of task a and b from /proc/PID/sched And we will find out that core_forceidle_sum of task a takes 30% time of the sampling period, which shouldn't happen as task a and b have the same cookie. Then we migrate task a to CPU x', migrate task b and c to CPU y', where CPU x' and CPU y' are a pair of SMT siblings, and sampling again, we will found out that core_forceidle_sum of task a and b are almost zero. To solve this problem, we enqueue the task into the core tree if it's on rq. Fixes: 6e33cad("sched: Trivial core scheduling cookie management") Signed-off-by: Cruz Zhao <CruzZhao@linux.alibaba.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lkml.kernel.org/r/1656403045-100840-2-git-send-email-CruzZhao@linux.alibaba.com
1 parent 5c66d1b commit 91caa5a

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

kernel/sched/core_sched.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ static unsigned long sched_core_update_cookie(struct task_struct *p,
5656
unsigned long old_cookie;
5757
struct rq_flags rf;
5858
struct rq *rq;
59-
bool enqueued;
6059

6160
rq = task_rq_lock(p, &rf);
6261

@@ -68,14 +67,16 @@ static unsigned long sched_core_update_cookie(struct task_struct *p,
6867
*/
6968
SCHED_WARN_ON((p->core_cookie || cookie) && !sched_core_enabled(rq));
7069

71-
enqueued = sched_core_enqueued(p);
72-
if (enqueued)
70+
if (sched_core_enqueued(p))
7371
sched_core_dequeue(rq, p, DEQUEUE_SAVE);
7472

7573
old_cookie = p->core_cookie;
7674
p->core_cookie = cookie;
7775

78-
if (enqueued)
76+
/*
77+
* Consider the cases: !prev_cookie and !cookie.
78+
*/
79+
if (cookie && task_on_rq_queued(p))
7980
sched_core_enqueue(rq, p);
8081

8182
/*

0 commit comments

Comments
 (0)