linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Huangzhaoyang <huangzhaoyang@gmail.com>
To: Johannes Weiner <hannes@cmpxchg.org>,
	Zhaoyang Huang <zhaoyang.huang@unisoc.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: [RFC PATCH] psi: introduce rt property for trigger
Date: Wed, 15 Dec 2021 18:49:59 +0800	[thread overview]
Message-ID: <1639565399-15629-1-git-send-email-huangzhaoyang@gmail.com> (raw)

From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>

There are several pratical reasons to introduce such a rt flag to let the
trigger wake up within the window,

1. WINDOW_MIN_US=500ms is too big for some scenarios where the trigger is
expected to launch some behavious on the resource under pressure.

2. Window size works as both of average factor and wakeup timing value.
However, user could expect seperate value on this two roles. eg, we expect
to watch the pressure as 'SOME 100/1000ms' and got triggered whenever it
reached.

Signed-off-by: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
---
 include/linux/psi_types.h |  3 +++
 kernel/sched/psi.c        | 21 +++++++++++++++++++--
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/include/linux/psi_types.h b/include/linux/psi_types.h
index 0a23300..6c83c75 100644
--- a/include/linux/psi_types.h
+++ b/include/linux/psi_types.h
@@ -124,6 +124,9 @@ struct psi_trigger {
 	/* Tracking window */
 	struct psi_window win;
 
+	/*real time trigger flag*/
+	u32 rt;
+
 	/*
 	 * Time last event was generated. Used for rate-limiting
 	 * events to one per window
diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
index 1652f2b..e1f08aa 100644
--- a/kernel/sched/psi.c
+++ b/kernel/sched/psi.c
@@ -145,6 +145,7 @@
 #include <linux/psi.h>
 #include "sched.h"
 
+extern unsigned int sysctl_sched_latency;
 static int psi_bug __read_mostly;
 
 DEFINE_STATIC_KEY_FALSE(psi_disabled);
@@ -458,9 +459,12 @@ static void psi_avgs_work(struct work_struct *work)
 static void window_reset(struct psi_window *win, u64 now, u64 value,
 			 u64 prev_growth)
 {
+	struct psi_trigger *t = container_of(win, struct psi_trigger, win);
+
 	win->start_time = now;
 	win->start_value = value;
 	win->prev_growth = prev_growth;
+	t->rt = t->rt ? 5 : 0;
 }
 
 /*
@@ -542,6 +546,17 @@ static u64 update_triggers(struct psi_group *group, u64 now)
 		if (growth < t->threshold)
 			continue;
 
+		/* wakeup if trigger has rt and at least 5 sched_latency surpassed*/
+		if (t->rt && growth >= t->threshold) {
+			u64 rt_trigger_time = min(t->last_event_time + t->win.size,
+				sysctl_sched_latency * t->rt + t->last_event_time);
+			if (now < rt_trigger_time)
+				continue;
+			if (cmpxchg(&t->event, 0, 1) == 0)
+				wake_up_interruptible(&t->event_wait);
+			t->rt += 5;
+		}
+
 		/* Limit event signaling to once per window */
 		if (now < t->last_event_time + t->win.size)
 			continue;
@@ -1116,13 +1131,14 @@ struct psi_trigger *psi_trigger_create(struct psi_group *group,
 	enum psi_states state;
 	u32 threshold_us;
 	u32 window_us;
+	u32 rt = 0;
 
 	if (static_branch_likely(&psi_disabled))
 		return ERR_PTR(-EOPNOTSUPP);
 
-	if (sscanf(buf, "some %u %u", &threshold_us, &window_us) == 2)
+	if (sscanf(buf, "some %u %u %u", &threshold_us, &window_us, &rt) >= 2)
 		state = PSI_IO_SOME + res * 2;
-	else if (sscanf(buf, "full %u %u", &threshold_us, &window_us) == 2)
+	else if (sscanf(buf, "full %u %u %u", &threshold_us, &window_us, &rt) >= 2)
 		state = PSI_IO_FULL + res * 2;
 	else
 		return ERR_PTR(-EINVAL);
@@ -1152,6 +1168,7 @@ struct psi_trigger *psi_trigger_create(struct psi_group *group,
 	t->last_event_time = 0;
 	init_waitqueue_head(&t->event_wait);
 	kref_init(&t->refcount);
+	t->rt = rt ? 5 : 0;
 
 	mutex_lock(&group->trigger_lock);
 
-- 
1.9.1



                 reply	other threads:[~2021-12-15 10:50 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1639565399-15629-1-git-send-email-huangzhaoyang@gmail.com \
    --to=huangzhaoyang@gmail.com \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=zhaoyang.huang@unisoc.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;
as well as URLs for NNTP newsgroup(s).