The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Domenico Cerasuolo <cerasuolodomenico@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: peterz@infradead.org, surenb@google.com, brauner@kernel.org,
	chris@chrisdown.name, hannes@cmpxchg.org,
	Domenico Cerasuolo <cerasuolodomenico@gmail.com>
Subject: [PATCH v2 2/3] sched/psi: extract update_triggers side effect
Date: Thu, 23 Mar 2023 11:33:49 +0100	[thread overview]
Message-ID: <20230323103350.40569-3-cerasuolodomenico@gmail.com> (raw)
In-Reply-To: <20230323103350.40569-1-cerasuolodomenico@gmail.com>

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 <hannes@cmpxchg.org>
Signed-off-by: Domenico Cerasuolo <cerasuolodomenico@gmail.com>
---
 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 fe9269f1d2a4..17d71ef07751 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->polling_total, total,
-				sizeof(group->polling_total));
-
 	return now + group->poll_min_period;
 }
 
@@ -622,6 +618,7 @@ static void psi_poll_work(struct psi_group *group)
 {
 	bool force_reschedule = false;
 	u32 changed_states;
+	bool update_total;
 	u64 now;
 
 	mutex_lock(&group->trigger_lock);
@@ -686,8 +683,12 @@ static void psi_poll_work(struct psi_group *group)
 		goto out;
 	}
 
-	if (now >= group->polling_next_update)
-		group->polling_next_update = update_triggers(group, now);
+	if (now >= group->polling_next_update) {
+		group->polling_next_update = update_triggers(group, now, &update_total);
+		if (update_total)
+			memcpy(group->polling_total, group->total[PSI_POLL],
+				   sizeof(group->polling_total));
+	}
 
 	psi_schedule_poll_work(group,
 		nsecs_to_jiffies(group->polling_next_update - now) + 1,
-- 
2.34.1


  parent reply	other threads:[~2023-03-23 10:38 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-23 10:33 [PATCH v2 0/3] sched/psi: Allow unprivileged PSI polling Domenico Cerasuolo
2023-03-23 10:33 ` [PATCH v2 1/3] sched/psi: rearrange polling code in preparation Domenico Cerasuolo
2023-03-23 10:33 ` Domenico Cerasuolo [this message]
2023-03-23 10:33 ` [PATCH v2 3/3] sched/psi: allow unprivileged polling of N*2s period Domenico Cerasuolo
2023-03-23 15:09   ` Johannes Weiner
2023-03-23 16:43     ` Suren Baghdasaryan
2023-03-23 17:40       ` Johannes Weiner
2023-03-23 16:55   ` Suren Baghdasaryan
2023-03-23 17:44     ` Johannes Weiner
2023-03-23 18:07       ` Suren Baghdasaryan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230323103350.40569-3-cerasuolodomenico@gmail.com \
    --to=cerasuolodomenico@gmail.com \
    --cc=brauner@kernel.org \
    --cc=chris@chrisdown.name \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=surenb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox