From: Luka Bai In psi_group_change, record_times is always called no matter whether the state_mask changes. Since it can cost some performance, we choose to not to do it unconditionally. If the state has not changed, we can keep the psi time unchanged. This will not make any difference to the final result since when we need to acquire the psi time, get_recent_times() will always calculate the remaining time into the final result. Signed-off-by: Luka Bai --- kernel/sched/psi.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c index 9b7a85d1bc28..4c4bd134c785 100644 --- a/kernel/sched/psi.c +++ b/kernel/sched/psi.c @@ -880,9 +880,15 @@ static void psi_group_change(struct psi_group *group, int cpu, if (unlikely((state_mask & PSI_ONCPU) && curr_in_memstall)) state_mask |= (1 << PSI_MEM_FULL); - record_times(groupc, now); - - groupc->state_mask = state_mask; + /* + * We only need to record times when the state changes. Or + * we can keep it unchanged and wait for get_recent_times() + * to handle the remaining time. + */ + if (state_mask != groupc->state_mask) { + record_times(groupc, now); + groupc->state_mask = state_mask; + } if (state_mask & group->rtpoll_states) psi_schedule_rtpoll_work(group, 1, false); -- 2.52.0