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

Message ID 202310101641075436843@zte.com.cn
State New
Headers
Series sched/psi: Optimize the process of updating triggers and rtpoll_total |

Commit Message

Yang Yang Oct. 10, 2023, 8:41 a.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 had not changed.
This will help to slightly reduce unnecessary computations of psi.

Signed-off-by: Yang Yang <yang.yang29@zte.com.cn>
Cc: Zhang Yunkai <zhang.yunkai@zte.com.cn>
Cc: Ran Xiaokai <ran.xiaokai@zte.com.cn>
---
 kernel/sched/psi.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
  

Comments

Ingo Molnar Oct. 11, 2023, 9:15 p.m. UTC | #1
* yang.yang29@zte.com.cn <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 had not changed.
> This will help to slightly reduce unnecessary computations of psi.
> 
> Signed-off-by: Yang Yang <yang.yang29@zte.com.cn>
> Cc: Zhang Yunkai <zhang.yunkai@zte.com.cn>
> Cc: Ran Xiaokai <ran.xiaokai@zte.com.cn>
> ---
>  kernel/sched/psi.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
> index be853f227e40..143f8eb34f9d 100644
> --- a/kernel/sched/psi.c
> +++ b/kernel/sched/psi.c
> @@ -704,11 +704,12 @@ static void psi_rtpoll_work(struct psi_group *group)
>  	}
> 
>  	if (now >= group->rtpoll_next_update) {
> -		update_triggers(group, now, &update_total, PSI_POLL);
>  		group->rtpoll_next_update = now + group->rtpoll_min_period;
> -		if (update_total)
> +		if (changed_states & group->rtpoll_states) {
> +			update_triggers(group, now, &update_total, PSI_POLL);
>  			memcpy(group->rtpoll_total, group->total[PSI_POLL],
>  				   sizeof(group->rtpoll_total));
> +		}

Yeah, so I believe we may have been talking past each other for past 
versions of this patch: why is this patch modifying the order of the 
modification to group->rtpoll_next_update?

It should do the below sequence, nothing more - see the patch attached 
below. This is basically a combination of patches #2 and #3.

And then the final patch removes the now superfluous 'update_total' 
parameter, which is always true.

Here are the commits I applied to tip:sched/core:

  e03dc9fa0663 sched/psi: Change update_triggers() to a 'void' function
  ...
  80cc1d1d5ee3 sched/psi: Avoid updating PSI triggers and ->rtpoll_total when there are no state changes
  3657680f38cd sched/psi: Delete the 'update_total' function parameter from update_triggers()

I rewrote the changelogs for readability.

Thanks,

	Ingo

===================>
From: Yang Yang <yang.yang29@zte.com.cn>
Date: Tue, 10 Oct 2023 16:41:07 +0800
Subject: [PATCH] sched/psi: Avoid updating PSI triggers and ->rtpoll_total when there are no state changes

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 the user have not changed.

This will help to slightly reduce unnecessary computations of PSI.

[ mingo: Changelog updates ]

Signed-off-by: Yang Yang <yang.yang29@zte.com.cn>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Peter Ziljstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/202310101641075436843@zte.com.cn
---
 kernel/sched/psi.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
index be853f227e40..79f8db0c6150 100644
--- a/kernel/sched/psi.c
+++ b/kernel/sched/psi.c
@@ -704,11 +704,12 @@ static void psi_rtpoll_work(struct psi_group *group)
 	}
 
 	if (now >= group->rtpoll_next_update) {
-		update_triggers(group, now, &update_total, PSI_POLL);
-		group->rtpoll_next_update = now + group->rtpoll_min_period;
-		if (update_total)
+		if (changed_states & group->rtpoll_states) {
+			update_triggers(group, now, &update_total, PSI_POLL);
 			memcpy(group->rtpoll_total, group->total[PSI_POLL],
 				   sizeof(group->rtpoll_total));
+		}
+		group->rtpoll_next_update = now + group->rtpoll_min_period;
 	}
 
 	psi_schedule_rtpoll_work(group,
  
Yang Yang Oct. 12, 2023, 2:13 a.m. UTC | #2
> Yeah, so I believe we may have been talking past each other for past 
> versions of this patch: why is this patch modifying the order of the 
> modification to group->rtpoll_next_update?

Yes it is, I may not have fully expressed the reasons clearly before.

> I rewrote the changelogs for readability.

Much grateful for your guidance and work. Learned a lot.
  
Suren Baghdasaryan Oct. 19, 2023, 4:04 p.m. UTC | #3
On Wed, Oct 11, 2023 at 2:15 PM Ingo Molnar <mingo@kernel.org> wrote:
>
>
> * yang.yang29@zte.com.cn <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 had not changed.
> > This will help to slightly reduce unnecessary computations of psi.
> >
> > Signed-off-by: Yang Yang <yang.yang29@zte.com.cn>
> > Cc: Zhang Yunkai <zhang.yunkai@zte.com.cn>
> > Cc: Ran Xiaokai <ran.xiaokai@zte.com.cn>
> > ---
> >  kernel/sched/psi.c | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
> > index be853f227e40..143f8eb34f9d 100644
> > --- a/kernel/sched/psi.c
> > +++ b/kernel/sched/psi.c
> > @@ -704,11 +704,12 @@ static void psi_rtpoll_work(struct psi_group *group)
> >       }
> >
> >       if (now >= group->rtpoll_next_update) {
> > -             update_triggers(group, now, &update_total, PSI_POLL);
> >               group->rtpoll_next_update = now + group->rtpoll_min_period;
> > -             if (update_total)
> > +             if (changed_states & group->rtpoll_states) {
> > +                     update_triggers(group, now, &update_total, PSI_POLL);
> >                       memcpy(group->rtpoll_total, group->total[PSI_POLL],
> >                                  sizeof(group->rtpoll_total));
> > +             }
>
> Yeah, so I believe we may have been talking past each other for past
> versions of this patch: why is this patch modifying the order of the
> modification to group->rtpoll_next_update?
>
> It should do the below sequence, nothing more - see the patch attached
> below. This is basically a combination of patches #2 and #3.
>
> And then the final patch removes the now superfluous 'update_total'
> parameter, which is always true.
>
> Here are the commits I applied to tip:sched/core:
>
>   e03dc9fa0663 sched/psi: Change update_triggers() to a 'void' function
>   ...
>   80cc1d1d5ee3 sched/psi: Avoid updating PSI triggers and ->rtpoll_total when there are no state changes
>   3657680f38cd sched/psi: Delete the 'update_total' function parameter from update_triggers()
>
> I rewrote the changelogs for readability.
>
> Thanks,
>
>         Ingo
>
> ===================>
> From: Yang Yang <yang.yang29@zte.com.cn>
> Date: Tue, 10 Oct 2023 16:41:07 +0800
> Subject: [PATCH] sched/psi: Avoid updating PSI triggers and ->rtpoll_total when there are no state changes
>
> 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 the user have not changed.
>
> This will help to slightly reduce unnecessary computations of PSI.
>
> [ mingo: Changelog updates ]
>
> Signed-off-by: Yang Yang <yang.yang29@zte.com.cn>
> Signed-off-by: Ingo Molnar <mingo@kernel.org>
> Cc: Johannes Weiner <hannes@cmpxchg.org>
> Cc: Suren Baghdasaryan <surenb@google.com>
> Cc: Peter Ziljstra <peterz@infradead.org>
> Link: https://lore.kernel.org/r/202310101641075436843@zte.com.cn

This version looks correct to me.

Acked-by: Suren Baghdasaryan <surenb@google.com>

> ---
>  kernel/sched/psi.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
> index be853f227e40..79f8db0c6150 100644
> --- a/kernel/sched/psi.c
> +++ b/kernel/sched/psi.c
> @@ -704,11 +704,12 @@ static void psi_rtpoll_work(struct psi_group *group)
>         }
>
>         if (now >= group->rtpoll_next_update) {
> -               update_triggers(group, now, &update_total, PSI_POLL);
> -               group->rtpoll_next_update = now + group->rtpoll_min_period;
> -               if (update_total)
> +               if (changed_states & group->rtpoll_states) {
> +                       update_triggers(group, now, &update_total, PSI_POLL);
>                         memcpy(group->rtpoll_total, group->total[PSI_POLL],
>                                    sizeof(group->rtpoll_total));
> +               }
> +               group->rtpoll_next_update = now + group->rtpoll_min_period;
>         }
>
>         psi_schedule_rtpoll_work(group,
  

Patch

diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
index be853f227e40..143f8eb34f9d 100644
--- a/kernel/sched/psi.c
+++ b/kernel/sched/psi.c
@@ -704,11 +704,12 @@  static void psi_rtpoll_work(struct psi_group *group)
 	}

 	if (now >= group->rtpoll_next_update) {
-		update_triggers(group, now, &update_total, PSI_POLL);
 		group->rtpoll_next_update = now + group->rtpoll_min_period;
-		if (update_total)
+		if (changed_states & group->rtpoll_states) {
+			update_triggers(group, now, &update_total, PSI_POLL);
 			memcpy(group->rtpoll_total, group->total[PSI_POLL],
 				   sizeof(group->rtpoll_total));
+		}
 	}

 	psi_schedule_rtpoll_work(group,