* [PATCH] psi: Fix avg trigger being fired unexpectedly.
@ 2024-02-26 19:46 Levi Yun
2024-02-26 20:07 ` Suren Baghdasaryan
0 siblings, 1 reply; 3+ messages in thread
From: Levi Yun @ 2024-02-26 19:46 UTC (permalink / raw)
To: hannes, surenb, peterz, mingo, juri.lelli, vincent.guittot,
dietmar.eggemann, rostedt, bsegall, mgorman, bristot, vschneid
Cc: linux-kernel, Levi Yun
commit 915a087e4c473("psi: Fix trigger being fired unexpectedly at initial")
fixes unexpected event fired when group->total accumlated for PSI_POLL.
But, for PSI_AVGS, win->value should be initialized with group->total[PSI_AVGS].
Moreover, to get exact initial value for win->value, it should be set
under each trigger lock to synchronize each rtpoll/avgs_works.
Signed-off-by: Levi Yun <ppbuk5246@gmail.com>
---
kernel/sched/psi.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
index 7b4aa5809c0f..e7f66ab2ad3e 100644
--- a/kernel/sched/psi.c
+++ b/kernel/sched/psi.c
@@ -1323,9 +1323,6 @@ struct psi_trigger *psi_trigger_create(struct psi_group *group, char *buf,
t->state = state;
t->threshold = threshold_us * NSEC_PER_USEC;
t->win.size = window_us * NSEC_PER_USEC;
- window_reset(&t->win, sched_clock(),
- group->total[PSI_POLL][t->state], 0);
-
t->event = 0;
t->last_event_time = 0;
t->of = of;
@@ -1336,6 +1333,8 @@ struct psi_trigger *psi_trigger_create(struct psi_group *group, char *buf,
if (privileged) {
mutex_lock(&group->rtpoll_trigger_lock);
+ window_reset(&t->win, sched_clock(),
+ group->total[PSI_POLL][t->state], 0);
if (!rcu_access_pointer(group->rtpoll_task)) {
struct task_struct *task;
@@ -1361,6 +1360,9 @@ struct psi_trigger *psi_trigger_create(struct psi_group *group, char *buf,
} else {
mutex_lock(&group->avgs_lock);
+ window_reset(&t->win, sched_clock(),
+ group->total[PSI_AVGS][t->state], 0);
+
list_add(&t->node, &group->avg_triggers);
group->avg_nr_triggers[t->state]++;
--
2.39.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] psi: Fix avg trigger being fired unexpectedly.
2024-02-26 19:46 [PATCH] psi: Fix avg trigger being fired unexpectedly Levi Yun
@ 2024-02-26 20:07 ` Suren Baghdasaryan
2024-02-26 21:07 ` Yun Levi
0 siblings, 1 reply; 3+ messages in thread
From: Suren Baghdasaryan @ 2024-02-26 20:07 UTC (permalink / raw)
To: Levi Yun
Cc: hannes, peterz, mingo, juri.lelli, vincent.guittot,
dietmar.eggemann, rostedt, bsegall, mgorman, bristot, vschneid,
linux-kernel
On Mon, Feb 26, 2024 at 11:46 AM Levi Yun <ppbuk5246@gmail.com> wrote:
>
> commit 915a087e4c473("psi: Fix trigger being fired unexpectedly at initial")
> fixes unexpected event fired when group->total accumlated for PSI_POLL.
s/accumlated/accumulated
> But, for PSI_AVGS, win->value should be initialized with group->total[PSI_AVGS].
> Moreover, to get exact initial value for win->value, it should be set
> under each trigger lock to synchronize each rtpoll/avgs_works.
That last "to synchronize each rtpoll/avgs_works." part I would
replace with "to avoid concurrent changes to group->total[]."
Other than these nits LGTM. After fixing them feel free to add:
Acked-by: Suren Baghdasaryan <surenb@google.com>
>
> Signed-off-by: Levi Yun <ppbuk5246@gmail.com>
> ---
> kernel/sched/psi.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
> index 7b4aa5809c0f..e7f66ab2ad3e 100644
> --- a/kernel/sched/psi.c
> +++ b/kernel/sched/psi.c
> @@ -1323,9 +1323,6 @@ struct psi_trigger *psi_trigger_create(struct psi_group *group, char *buf,
> t->state = state;
> t->threshold = threshold_us * NSEC_PER_USEC;
> t->win.size = window_us * NSEC_PER_USEC;
> - window_reset(&t->win, sched_clock(),
> - group->total[PSI_POLL][t->state], 0);
> -
> t->event = 0;
> t->last_event_time = 0;
> t->of = of;
> @@ -1336,6 +1333,8 @@ struct psi_trigger *psi_trigger_create(struct psi_group *group, char *buf,
>
> if (privileged) {
> mutex_lock(&group->rtpoll_trigger_lock);
> + window_reset(&t->win, sched_clock(),
> + group->total[PSI_POLL][t->state], 0);
>
> if (!rcu_access_pointer(group->rtpoll_task)) {
> struct task_struct *task;
> @@ -1361,6 +1360,9 @@ struct psi_trigger *psi_trigger_create(struct psi_group *group, char *buf,
> } else {
> mutex_lock(&group->avgs_lock);
>
> + window_reset(&t->win, sched_clock(),
> + group->total[PSI_AVGS][t->state], 0);
> +
> list_add(&t->node, &group->avg_triggers);
> group->avg_nr_triggers[t->state]++;
>
> --
> 2.39.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] psi: Fix avg trigger being fired unexpectedly.
2024-02-26 20:07 ` Suren Baghdasaryan
@ 2024-02-26 21:07 ` Yun Levi
0 siblings, 0 replies; 3+ messages in thread
From: Yun Levi @ 2024-02-26 21:07 UTC (permalink / raw)
To: Suren Baghdasaryan
Cc: hannes, peterz, mingo, juri.lelli, vincent.guittot,
dietmar.eggemann, rostedt, bsegall, mgorman, bristot, vschneid,
linux-kernel
Hi Suren.
> s/accumlated/accumulated
>
> > But, for PSI_AVGS, win->value should be initialized with group->total[PSI_AVGS].
> > Moreover, to get exact initial value for win->value, it should be set
> > under each trigger lock to synchronize each rtpoll/avgs_works.
>
> That last "to synchronize each rtpoll/avgs_works." part I would
> replace with "to avoid concurrent changes to group->total[]."
>
> Other than these nits LGTM. After fixing them feel free to add:
>
> Acked-by: Suren Baghdasaryan <surenb@google.com>
Thanks. I'll fix my commit message ;)
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-02-26 21:08 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-26 19:46 [PATCH] psi: Fix avg trigger being fired unexpectedly Levi Yun
2024-02-26 20:07 ` Suren Baghdasaryan
2024-02-26 21:07 ` Yun Levi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox