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

Message ID 202309132044261713252@zte.com.cn
State New
Headers
Series [linux-next] sched/psi: Avoid update triggers and rtpoll_total when it is unnecessary |

Commit Message

Yang Yang Sept. 13, 2023, 12:44 p.m. UTC
  From: Yang Yang <yang.yang29@zte.com.cn>

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@zte.com.cn>
---
 kernel/sched/psi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Suren Baghdasaryan Sept. 13, 2023, 11:01 p.m. UTC | #1
On Wed, Sep 13, 2023 at 12:44 PM <yang.yang29@zte.com.cn> wrote:
>
> From: Yang Yang <yang.yang29@zte.com.cn>
>
> 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@zte.com.cn>
> ---
>  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
  

Patch

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)) {
 		group->rtpoll_next_update = update_triggers(group, now, &update_total, PSI_POLL);
 		if (update_total)
 			memcpy(group->rtpoll_total, group->total[PSI_POLL],