Skip to content

Commit 52b33d8

Browse files
Chengming ZhouPeter Zijlstra
authored andcommitted
sched/psi: Use task->psi_flags to clear in CPU migration
The commit d583d36 ("psi: Fix psi state corruption when schedule() races with cgroup move") fixed a race problem by making cgroup_move_task() use task->psi_flags instead of looking at the scheduler state. We can extend task->psi_flags usage to CPU migration, which should be a minor optimization for performance and code simplicity. Signed-off-by: Chengming Zhou <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Acked-by: Johannes Weiner <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 710ffe6 commit 52b33d8

File tree

3 files changed

+5
-22
lines changed

3 files changed

+5
-22
lines changed

include/linux/sched.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -888,9 +888,6 @@ struct task_struct {
888888
unsigned sched_reset_on_fork:1;
889889
unsigned sched_contributes_to_load:1;
890890
unsigned sched_migrated:1;
891-
#ifdef CONFIG_PSI
892-
unsigned sched_psi_wake_requeue:1;
893-
#endif
894891

895892
/* Force alignment to the next boundary: */
896893
unsigned :0;

kernel/sched/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2053,7 +2053,7 @@ static inline void enqueue_task(struct rq *rq, struct task_struct *p, int flags)
20532053

20542054
if (!(flags & ENQUEUE_RESTORE)) {
20552055
sched_info_enqueue(rq, p);
2056-
psi_enqueue(p, flags & ENQUEUE_WAKEUP);
2056+
psi_enqueue(p, (flags & ENQUEUE_WAKEUP) && !(flags & ENQUEUE_MIGRATED));
20572057
}
20582058

20592059
uclamp_rq_inc(rq, p);

kernel/sched/stats.h

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,9 @@ static inline void psi_enqueue(struct task_struct *p, bool wakeup)
128128
if (p->in_memstall)
129129
set |= TSK_MEMSTALL_RUNNING;
130130

131-
if (!wakeup || p->sched_psi_wake_requeue) {
131+
if (!wakeup) {
132132
if (p->in_memstall)
133133
set |= TSK_MEMSTALL;
134-
if (p->sched_psi_wake_requeue)
135-
p->sched_psi_wake_requeue = 0;
136134
} else {
137135
if (p->in_iowait)
138136
clear |= TSK_IOWAIT;
@@ -143,8 +141,6 @@ static inline void psi_enqueue(struct task_struct *p, bool wakeup)
143141

144142
static inline void psi_dequeue(struct task_struct *p, bool sleep)
145143
{
146-
int clear = TSK_RUNNING;
147-
148144
if (static_branch_likely(&psi_disabled))
149145
return;
150146

@@ -157,10 +153,7 @@ static inline void psi_dequeue(struct task_struct *p, bool sleep)
157153
if (sleep)
158154
return;
159155

160-
if (p->in_memstall)
161-
clear |= (TSK_MEMSTALL | TSK_MEMSTALL_RUNNING);
162-
163-
psi_task_change(p, clear, 0);
156+
psi_task_change(p, p->psi_flags, 0);
164157
}
165158

166159
static inline void psi_ttwu_dequeue(struct task_struct *p)
@@ -172,19 +165,12 @@ static inline void psi_ttwu_dequeue(struct task_struct *p)
172165
* deregister its sleep-persistent psi states from the old
173166
* queue, and let psi_enqueue() know it has to requeue.
174167
*/
175-
if (unlikely(p->in_iowait || p->in_memstall)) {
168+
if (unlikely(p->psi_flags)) {
176169
struct rq_flags rf;
177170
struct rq *rq;
178-
int clear = 0;
179-
180-
if (p->in_iowait)
181-
clear |= TSK_IOWAIT;
182-
if (p->in_memstall)
183-
clear |= TSK_MEMSTALL;
184171

185172
rq = __task_rq_lock(p, &rf);
186-
psi_task_change(p, clear, 0);
187-
p->sched_psi_wake_requeue = 1;
173+
psi_task_change(p, p->psi_flags, 0);
188174
__task_rq_unlock(rq, &rf);
189175
}
190176
}

0 commit comments

Comments
 (0)