Skip to contentSkip to conversation

psi: Fix avg trigger being fired unexpectedly.

PATCH Superseded Levi Yun 2 participants 3 messages Feb 26, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Levi Yun

author
#0 lore raw

PATCH 1/1 psi: Fix avg trigger being fired unexpectedly.

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.

---
 kernel/sched/psi.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
kernel/sched/psi.c +5 -3
index 7b4aa5809c0f..e7f66ab2ad3e 100644
@@ -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

maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 3 lines · Levi Yun

commit 915a087e4c473("psi: Fix trigger being fired unexpectedly at initial") fixes unexpected event fired when group->total accumlated for PSI_POLL.

s/accumlated/accumulated

Quoted 3 lines

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:

Quoted 41 lines
---
 kernel/sched/psi.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
kernel/sched/psi.c +5 -4
index 7b4aa5809c0f..e7f66ab2ad3e 100644
@@ -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

author
#2 lore raw

Hi Suren.

Quoted 6 lines

s/accumlated/accumulated

Quoted 3 lines

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.

Quoted 6 lines

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:

Thanks. I'll fix my commit message ;)