From: Chen Yu <yu.c.chen@intel.com>
To: Peter Zijlstra <peterz@infradead.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Ingo Molnar <mingo@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Juri Lelli <juri.lelli@redhat.com>
Cc: Tim Chen <tim.c.chen@intel.com>, Aaron Lu <aaron.lu@intel.com>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Daniel Bristot de Oliveira <bristot@redhat.com>,
Valentin Schneider <vschneid@redhat.com>,
K Prateek Nayak <kprateek.nayak@amd.com>,
"Gautham R . Shenoy" <gautham.shenoy@amd.com>,
linux-kernel@vger.kernel.org, Chen Yu <yu.c.chen@intel.com>
Subject: [RFC PATCH 1/2] sched/fair: Record the average sleep time of a task
Date: Mon, 11 Sep 2023 10:49:41 +0800 [thread overview]
Message-ID: <d4cf4b5d8d166f66695748405a449797b514610e.1694397335.git.yu.c.chen@intel.com> (raw)
In-Reply-To: <cover.1694397335.git.yu.c.chen@intel.com>
There is a requirement to have the information on how
long a task sleeps. This information can be used for
better task placement that, the short sleeping task
can be woken up on its previous idle easier. The
optimization will be introduced in the next patch.
Define the sleep time of the task as:
The time delta between this task was dequeued and enqueued.
Signed-off-by: Chen Yu <yu.c.chen@intel.com>
---
include/linux/sched.h | 3 +++
kernel/sched/fair.c | 17 +++++++++++++++++
2 files changed, 20 insertions(+)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 177b3f3676ef..c11879468027 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -561,6 +561,9 @@ struct sched_entity {
u64 vruntime;
s64 vlag;
u64 slice;
+ u64 prev_sleep_time;
+ /* average sleep duration of a task */
+ u64 sleep_avg;
u64 nr_migrations;
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 0b7445cd5af9..e20f50726ab8 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -6457,6 +6457,20 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags)
struct sched_entity *se = &p->se;
int idle_h_nr_running = task_has_idle_policy(p);
int task_new = !(flags & ENQUEUE_WAKEUP);
+ u64 last_sleep = p->se.prev_sleep_time;
+
+ /*
+ * Calculate the average sleep time of the wakee.
+ * Use wakee's previous CPU's clock to get the
+ * delta. The previous CPU should be online, otherwise
+ * the sleep time could be larger than expected(the clock
+ * of the offline previous CPU is paused). Check if there
+ * is a sched_clock() reset on previous CPU due to suspend/resume.
+ */
+ if ((flags & ENQUEUE_WAKEUP) && last_sleep && cpu_online(task_cpu(p)) &&
+ sched_clock_cpu(task_cpu(p)) > last_sleep)
+ update_avg(&p->se.sleep_avg,
+ sched_clock_cpu(task_cpu(p)) - last_sleep);
/*
* The code below (indirectly) updates schedutil which looks at
@@ -6551,6 +6565,7 @@ static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags)
int task_sleep = flags & DEQUEUE_SLEEP;
int idle_h_nr_running = task_has_idle_policy(p);
bool was_sched_idle = sched_idle_rq(rq);
+ u64 now;
util_est_dequeue(&rq->cfs, p);
@@ -6612,6 +6627,8 @@ static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags)
dequeue_throttle:
util_est_update(&rq->cfs, p, task_sleep);
hrtick_update(rq);
+ now = sched_clock_cpu(cpu_of(rq));
+ p->se.prev_sleep_time = task_sleep ? now : 0;
}
#ifdef CONFIG_SMP
--
2.25.1
next prev parent reply other threads:[~2023-09-11 2:50 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-11 2:49 [RFC PATCH 0/2] Makes it easier for the wakee to choose previous CPU Chen Yu
2023-09-11 2:49 ` Chen Yu [this message]
2023-09-11 2:50 ` [RFC PATCH 2/2] sched/fair: skip the cache hot CPU in select_idle_cpu() Chen Yu
2023-09-11 7:26 ` Aaron Lu
2023-09-11 8:40 ` Chen Yu
2023-09-13 6:22 ` Gautham R. Shenoy
2023-09-13 7:25 ` Chen Yu
2023-09-14 7:06 ` Gautham R. Shenoy
2023-09-14 12:09 ` Chen Yu
2023-09-15 15:18 ` Gautham R. Shenoy
2023-09-19 9:01 ` Chen Yu
2023-09-11 8:29 ` K Prateek Nayak
2023-09-11 10:19 ` Chen Yu
2023-09-12 3:05 ` K Prateek Nayak
2023-09-12 12:32 ` Chen Yu
2023-09-12 14:26 ` K Prateek Nayak
2023-09-13 2:57 ` Chen Yu
2023-09-14 4:13 ` K Prateek Nayak
2023-09-14 11:01 ` Chen Yu
2023-09-15 3:21 ` K Prateek Nayak
2023-09-12 9:39 ` Mike Galbraith
2023-09-12 14:51 ` Chen Yu
2023-09-12 6:32 ` Mike Galbraith
2023-09-11 15:26 ` Mathieu Desnoyers
2023-09-11 15:43 ` Mathieu Desnoyers
2023-09-12 11:53 ` Chen Yu
2023-09-12 14:06 ` Mathieu Desnoyers
2023-09-12 14:14 ` Chen Yu
2023-09-12 15:18 ` Mathieu Desnoyers
2023-09-13 3:02 ` Chen Yu
2023-09-20 12:34 ` Chen Yu
2023-09-14 5:30 ` K Prateek Nayak
2023-09-14 10:43 ` Chen Yu
2023-09-15 3:37 ` K Prateek Nayak
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=d4cf4b5d8d166f66695748405a449797b514610e.1694397335.git.yu.c.chen@intel.com \
--to=yu.c.chen@intel.com \
--cc=aaron.lu@intel.com \
--cc=bristot@redhat.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=gautham.shenoy@amd.com \
--cc=juri.lelli@redhat.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tim.c.chen@intel.com \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.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
all inboxes | Powered by JetHome®