Skip to content

Commit c530a3c

Browse files
Chengming ZhouPeter Zijlstra
authored andcommitted
sched/psi: Fix periodic aggregation shut off
We don't want to wake periodic aggregation work back up if the task change is the aggregation worker itself going to sleep, or we'll ping-pong forever. Previously, we would use psi_task_change() in psi_dequeue() when task going to sleep, so this check was put in psi_task_change(). But commit 4117ceb ("psi: Optimize task switch inside shared cgroups") defer task sleep handling to psi_task_switch(), won't go through psi_task_change() anymore. So this patch move this check to psi_task_switch(). Fixes: 4117ceb ("psi: Optimize task switch inside shared cgroups") 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 0fb7b6f commit c530a3c

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

kernel/sched/psi.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,6 @@ void psi_task_change(struct task_struct *task, int clear, int set)
796796
{
797797
int cpu = task_cpu(task);
798798
struct psi_group *group;
799-
bool wake_clock = true;
800799
void *iter = NULL;
801800
u64 now;
802801

@@ -806,19 +805,9 @@ void psi_task_change(struct task_struct *task, int clear, int set)
806805
psi_flags_change(task, clear, set);
807806

808807
now = cpu_clock(cpu);
809-
/*
810-
* Periodic aggregation shuts off if there is a period of no
811-
* task changes, so we wake it back up if necessary. However,
812-
* don't do this if the task change is the aggregation worker
813-
* itself going to sleep, or we'll ping-pong forever.
814-
*/
815-
if (unlikely((clear & TSK_RUNNING) &&
816-
(task->flags & PF_WQ_WORKER) &&
817-
wq_worker_last_func(task) == psi_avgs_work))
818-
wake_clock = false;
819808

820809
while ((group = iterate_groups(task, &iter)))
821-
psi_group_change(group, cpu, clear, set, now, wake_clock);
810+
psi_group_change(group, cpu, clear, set, now, true);
822811
}
823812

824813
void psi_task_switch(struct task_struct *prev, struct task_struct *next,
@@ -854,6 +843,7 @@ void psi_task_switch(struct task_struct *prev, struct task_struct *next,
854843

855844
if (prev->pid) {
856845
int clear = TSK_ONCPU, set = 0;
846+
bool wake_clock = true;
857847

858848
/*
859849
* When we're going to sleep, psi_dequeue() lets us
@@ -867,13 +857,23 @@ void psi_task_switch(struct task_struct *prev, struct task_struct *next,
867857
clear |= TSK_MEMSTALL_RUNNING;
868858
if (prev->in_iowait)
869859
set |= TSK_IOWAIT;
860+
861+
/*
862+
* Periodic aggregation shuts off if there is a period of no
863+
* task changes, so we wake it back up if necessary. However,
864+
* don't do this if the task change is the aggregation worker
865+
* itself going to sleep, or we'll ping-pong forever.
866+
*/
867+
if (unlikely((prev->flags & PF_WQ_WORKER) &&
868+
wq_worker_last_func(prev) == psi_avgs_work))
869+
wake_clock = false;
870870
}
871871

872872
psi_flags_change(prev, clear, set);
873873

874874
iter = NULL;
875875
while ((group = iterate_groups(prev, &iter)) && group != common)
876-
psi_group_change(group, cpu, clear, set, now, true);
876+
psi_group_change(group, cpu, clear, set, now, wake_clock);
877877

878878
/*
879879
* TSK_ONCPU is handled up to the common ancestor. If we're tasked
@@ -882,7 +882,7 @@ void psi_task_switch(struct task_struct *prev, struct task_struct *next,
882882
if (sleep) {
883883
clear &= ~TSK_ONCPU;
884884
for (; group; group = iterate_groups(prev, &iter))
885-
psi_group_change(group, cpu, clear, set, now, true);
885+
psi_group_change(group, cpu, clear, set, now, wake_clock);
886886
}
887887
}
888888
}

0 commit comments

Comments
 (0)