2023-03-30 11:06:08

by Domenico Cerasuolo

[permalink] [raw]
Subject: [PATCH v6 3/4] sched/psi: extract update_triggers side effect

This change moves update_total flag out of update_triggers function,
currently called only in psi_poll_work.
In the next patch, update_triggers will be called also in psi_avgs_work,
but the total update information is specific to psi_poll_work.
Returning update_total value to the caller let us avoid differentiating
the implementation of update_triggers for different aggregators.

Suggested-by: Johannes Weiner <[email protected]>
Signed-off-by: Domenico Cerasuolo <[email protected]>
Acked-by: Johannes Weiner <[email protected]>
---
kernel/sched/psi.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
index a3d0b5cf797a..f3df6a8ff493 100644
--- a/kernel/sched/psi.c
+++ b/kernel/sched/psi.c
@@ -430,11 +430,11 @@ static u64 window_update(struct psi_window *win, u64 now, u64 value)
return growth;
}

-static u64 update_triggers(struct psi_group *group, u64 now)
+static u64 update_triggers(struct psi_group *group, u64 now, bool *update_total)
{
struct psi_trigger *t;
- bool update_total = false;
u64 *total = group->total[PSI_POLL];
+ *update_total = false;

/*
* On subsequent updates, calculate growth deltas and let
@@ -462,7 +462,7 @@ static u64 update_triggers(struct psi_group *group, u64 now)
* been through all of them. Also remember to extend the
* polling time if we see new stall activity.
*/
- update_total = true;
+ *update_total = true;

/* Calculate growth since last update */
growth = window_update(&t->win, now, total[t->state]);
@@ -485,10 +485,6 @@ static u64 update_triggers(struct psi_group *group, u64 now)
t->pending_event = false;
}

- if (update_total)
- memcpy(group->rtpoll_total, total,
- sizeof(group->rtpoll_total));
-
return now + group->rtpoll_min_period;
}

@@ -622,6 +618,7 @@ static void psi_rtpoll_work(struct psi_group *group)
{
bool force_reschedule = false;
u32 changed_states;
+ bool update_total;
u64 now;

mutex_lock(&group->rtpoll_trigger_lock);
@@ -686,8 +683,12 @@ static void psi_rtpoll_work(struct psi_group *group)
goto out;
}

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

psi_schedule_rtpoll_work(group,
nsecs_to_jiffies(group->rtpoll_next_update - now) + 1,
--
2.34.1


2023-03-30 18:44:10

by Suren Baghdasaryan

[permalink] [raw]
Subject: Re: [PATCH v6 3/4] sched/psi: extract update_triggers side effect

On Thu, Mar 30, 2023 at 3:54 AM Domenico Cerasuolo
<[email protected]> wrote:
>
> This change moves update_total flag out of update_triggers function,
> currently called only in psi_poll_work.
> In the next patch, update_triggers will be called also in psi_avgs_work,
> but the total update information is specific to psi_poll_work.
> Returning update_total value to the caller let us avoid differentiating
> the implementation of update_triggers for different aggregators.
>
> Suggested-by: Johannes Weiner <[email protected]>
> Signed-off-by: Domenico Cerasuolo <[email protected]>
> Acked-by: Johannes Weiner <[email protected]>

Acked-by: Suren Baghdasaryan <[email protected]>

> ---
> kernel/sched/psi.c | 19 ++++++++++---------
> 1 file changed, 10 insertions(+), 9 deletions(-)
>
> diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
> index a3d0b5cf797a..f3df6a8ff493 100644
> --- a/kernel/sched/psi.c
> +++ b/kernel/sched/psi.c
> @@ -430,11 +430,11 @@ static u64 window_update(struct psi_window *win, u64 now, u64 value)
> return growth;
> }
>
> -static u64 update_triggers(struct psi_group *group, u64 now)
> +static u64 update_triggers(struct psi_group *group, u64 now, bool *update_total)
> {
> struct psi_trigger *t;
> - bool update_total = false;
> u64 *total = group->total[PSI_POLL];
> + *update_total = false;
>
> /*
> * On subsequent updates, calculate growth deltas and let
> @@ -462,7 +462,7 @@ static u64 update_triggers(struct psi_group *group, u64 now)
> * been through all of them. Also remember to extend the
> * polling time if we see new stall activity.
> */
> - update_total = true;
> + *update_total = true;
>
> /* Calculate growth since last update */
> growth = window_update(&t->win, now, total[t->state]);
> @@ -485,10 +485,6 @@ static u64 update_triggers(struct psi_group *group, u64 now)
> t->pending_event = false;
> }
>
> - if (update_total)
> - memcpy(group->rtpoll_total, total,
> - sizeof(group->rtpoll_total));
> -
> return now + group->rtpoll_min_period;
> }
>
> @@ -622,6 +618,7 @@ static void psi_rtpoll_work(struct psi_group *group)
> {
> bool force_reschedule = false;
> u32 changed_states;
> + bool update_total;
> u64 now;
>
> mutex_lock(&group->rtpoll_trigger_lock);
> @@ -686,8 +683,12 @@ static void psi_rtpoll_work(struct psi_group *group)
> goto out;
> }
>
> - if (now >= group->rtpoll_next_update)
> - group->rtpoll_next_update = update_triggers(group, now);
> + if (now >= group->rtpoll_next_update) {
> + group->rtpoll_next_update = update_triggers(group, now, &update_total);
> + if (update_total)
> + memcpy(group->rtpoll_total, group->total[PSI_POLL],
> + sizeof(group->rtpoll_total));
> + }
>
> psi_schedule_rtpoll_work(group,
> nsecs_to_jiffies(group->rtpoll_next_update - now) + 1,
> --
> 2.34.1
>

Subject: [tip: sched/core] sched/psi: Extract update_triggers side effect

The following commit has been merged into the sched/core branch of tip:

Commit-ID: 4468fcae49f08e88fbbffe05b29496192df89991
Gitweb: https://git.kernel.org/tip/4468fcae49f08e88fbbffe05b29496192df89991
Author: Domenico Cerasuolo <[email protected]>
AuthorDate: Thu, 30 Mar 2023 12:54:17 +02:00
Committer: Peter Zijlstra <[email protected]>
CommitterDate: Wed, 05 Apr 2023 09:58:49 +02:00

sched/psi: Extract update_triggers side effect

This change moves update_total flag out of update_triggers function,
currently called only in psi_poll_work.
In the next patch, update_triggers will be called also in psi_avgs_work,
but the total update information is specific to psi_poll_work.
Returning update_total value to the caller let us avoid differentiating
the implementation of update_triggers for different aggregators.

Suggested-by: Johannes Weiner <[email protected]>
Signed-off-by: Domenico Cerasuolo <[email protected]>
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Acked-by: Johannes Weiner <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
---
kernel/sched/psi.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
index a3d0b5c..f3df6a8 100644
--- a/kernel/sched/psi.c
+++ b/kernel/sched/psi.c
@@ -430,11 +430,11 @@ static u64 window_update(struct psi_window *win, u64 now, u64 value)
return growth;
}

-static u64 update_triggers(struct psi_group *group, u64 now)
+static u64 update_triggers(struct psi_group *group, u64 now, bool *update_total)
{
struct psi_trigger *t;
- bool update_total = false;
u64 *total = group->total[PSI_POLL];
+ *update_total = false;

/*
* On subsequent updates, calculate growth deltas and let
@@ -462,7 +462,7 @@ static u64 update_triggers(struct psi_group *group, u64 now)
* been through all of them. Also remember to extend the
* polling time if we see new stall activity.
*/
- update_total = true;
+ *update_total = true;

/* Calculate growth since last update */
growth = window_update(&t->win, now, total[t->state]);
@@ -485,10 +485,6 @@ static u64 update_triggers(struct psi_group *group, u64 now)
t->pending_event = false;
}

- if (update_total)
- memcpy(group->rtpoll_total, total,
- sizeof(group->rtpoll_total));
-
return now + group->rtpoll_min_period;
}

@@ -622,6 +618,7 @@ static void psi_rtpoll_work(struct psi_group *group)
{
bool force_reschedule = false;
u32 changed_states;
+ bool update_total;
u64 now;

mutex_lock(&group->rtpoll_trigger_lock);
@@ -686,8 +683,12 @@ static void psi_rtpoll_work(struct psi_group *group)
goto out;
}

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

psi_schedule_rtpoll_work(group,
nsecs_to_jiffies(group->rtpoll_next_update - now) + 1,