[linux-next,v2,1/4] sched/psi: Change update_triggers() to a 'void' function

Message ID 202310101109350209198@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, 3:09 a.m. UTC
  From: Yang Yang <yang.yang29@zte.com.cn>

Update_triggers() always returns now + group->rtpoll_min_period, and the
return value is only used by psi_rtpoll_work(), so change update_triggers()
to a void function, let group->rtpoll_next_update = now +
group->rtpoll_min_period directly.

This will avoid unnecessary function return value passing & simplifies
the function.

Suggested-by: Suren Baghdasaryan <surenb@google.com>
Signed-off-by: Yang Yang <yang.yang29@zte.com.cn>
---
 kernel/sched/psi.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
  

Comments

Ingo Molnar Oct. 10, 2023, 7:38 a.m. UTC | #1
* yang.yang29@zte.com.cn <yang.yang29@zte.com.cn> wrote:

> From: Yang Yang <yang.yang29@zte.com.cn>
> 
> Update_triggers() always returns now + group->rtpoll_min_period, and the
> return value is only used by psi_rtpoll_work(), so change update_triggers()
> to a void function, let group->rtpoll_next_update = now +
> group->rtpoll_min_period directly.
> 
> This will avoid unnecessary function return value passing & simplifies
> the function.
> 
> Suggested-by: Suren Baghdasaryan <surenb@google.com>
> Signed-off-by: Yang Yang <yang.yang29@zte.com.cn>
> ---
>  kernel/sched/psi.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
> index 1d0f634725a6..fec8aab096a8 100644
> --- a/kernel/sched/psi.c
> +++ b/kernel/sched/psi.c
> @@ -434,7 +434,7 @@ static u64 window_update(struct psi_window *win, u64 now, u64 value)
>  	return growth;
>  }
> 
> -static u64 update_triggers(struct psi_group *group, u64 now, bool *update_total,
> +static void update_triggers(struct psi_group *group, u64 now, bool *update_total,
>  						   enum psi_aggregators aggregator)
>  {
>  	struct psi_trigger *t;
> @@ -503,8 +503,6 @@ static u64 update_triggers(struct psi_group *group, u64 now, bool *update_total,
>  		/* Reset threshold breach flag once event got generated */
>  		t->pending_event = false;
>  	}
> -
> -	return now + group->rtpoll_min_period;
>  }
> 
>  static u64 update_averages(struct psi_group *group, u64 now)
> @@ -706,7 +704,8 @@ static void psi_rtpoll_work(struct psi_group *group)
>  	}
> 
>  	if (now >= group->rtpoll_next_update) {
> -		group->rtpoll_next_update = update_triggers(group, now, &update_total, PSI_POLL);
> +		group->rtpoll_next_update = now + group->rtpoll_min_period;
> +		update_triggers(group, now, &update_total, PSI_POLL);

This step is wrong. The equivalent transformation when removing a return value is:

	x = fn(y); // fn(y) returns 'z'

to:

	fn(y);
	x = z;

not:

	x = z;
	fn(y);

...

Furthermore, I already applied the correct #1 patch to the scheduler tree, see:

  e03dc9fa0663 ("sched/psi: Change update_triggers() to a 'void' function")

... which tree is at:

  git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git sched/core

So please send the remaining patch on top of that.

Thanks,

	Ingo
  

Patch

diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
index 1d0f634725a6..fec8aab096a8 100644
--- a/kernel/sched/psi.c
+++ b/kernel/sched/psi.c
@@ -434,7 +434,7 @@  static u64 window_update(struct psi_window *win, u64 now, u64 value)
 	return growth;
 }

-static u64 update_triggers(struct psi_group *group, u64 now, bool *update_total,
+static void update_triggers(struct psi_group *group, u64 now, bool *update_total,
 						   enum psi_aggregators aggregator)
 {
 	struct psi_trigger *t;
@@ -503,8 +503,6 @@  static u64 update_triggers(struct psi_group *group, u64 now, bool *update_total,
 		/* Reset threshold breach flag once event got generated */
 		t->pending_event = false;
 	}
-
-	return now + group->rtpoll_min_period;
 }

 static u64 update_averages(struct psi_group *group, u64 now)
@@ -706,7 +704,8 @@  static void psi_rtpoll_work(struct psi_group *group)
 	}

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