Re: [PATCH linux-next] sched/psi: Avoid update triggers and rtpoll_total when it is unnecessary

From: Suren Baghdasaryan
Date: Wed Sep 13 2023 - 19:01:19 EST


On Wed, Sep 13, 2023 at 12:44 PM <yang.yang29@xxxxxxxxxx> wrote:
>
> From: Yang Yang <yang.yang29@xxxxxxxxxx>
>
> When psimon wakes up and there are no state changes for rtpoll_states,
> it's unnecessary to update triggers and rtpoll_total because the pressures
> being monitored by user have not changed.
>
> Signed-off-by: Yang Yang <yang.yang29@xxxxxxxxxx>
> ---
> kernel/sched/psi.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
> index 81fca77397f6..e4463bb267c3 100644
> --- a/kernel/sched/psi.c
> +++ b/kernel/sched/psi.c
> @@ -701,7 +701,7 @@ static void psi_rtpoll_work(struct psi_group *group)
> goto out;
> }
>
> - if (now >= group->rtpoll_next_update) {
> + if ((changed_states & group->rtpoll_states) && (now >= group->rtpoll_next_update)) {

With this additional condition group->rtpoll_next_update will not be
updated if states do not change and later on we will have a call to
psi_schedule_rtpoll_work() with the delay calculated as
"nsecs_to_jiffies(group->rtpoll_next_update - now) + 1". With
group->rtpoll_next_update not updated, we can end up with a negative
delay. I don't think that's your intention here, it is?

> group->rtpoll_next_update = update_triggers(group, now, &update_total, PSI_POLL);
> if (update_total)
> memcpy(group->rtpoll_total, group->total[PSI_POLL],
> --
> 2.25.1