From: Redha Gouicem <redha.gouicem@gmail.com>
To: unlisted-recipients:; (no To-header on input)
Cc: julien.sopena@lip6.fr, julia.lawall@inria.fr,
gilles.muller@inria.fr, carverdamien@gmail.com,
jean-pierre.lozi@oracle.com, baptiste.lepers@sydney.edu.au,
nicolas.palix@univ-grenoble-alpes.fr,
willy.zwaenepoel@sydney.edu.au,
Redha Gouicem <redha.gouicem@gmail.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
"Rafael J. Wysocki" <rjw@rjwysocki.net>,
Viresh Kumar <viresh.kumar@linaro.org>,
Peter Zijlstra <peterz@infradead.org>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
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>,
Luis Chamberlain <mcgrof@kernel.org>,
Kees Cook <keescook@chromium.org>,
Iurii Zaikin <yzaikin@google.com>,
Andrew Morton <akpm@linux-foundation.org>,
Qais Yousef <qais.yousef@arm.com>,
Al Viro <viro@zeniv.linux.org.uk>,
"Guilherme G. Piccoli" <gpiccoli@canonical.com>,
linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org,
linux-fsdevel@vger.kernel.org
Subject: [PATCH 2/3] sched: core: x86: query frequency at each tick
Date: Tue, 20 Oct 2020 17:44:40 +0200 [thread overview]
Message-ID: <20201020154445.119701-3-redha.gouicem@gmail.com> (raw)
In-Reply-To: <20201020154445.119701-1-redha.gouicem@gmail.com>
Query the current frequency of the core during the scheduler tick.
The scheduler subsystem maintains its own copies of the aperf/mperf
structure because it will query the frequency more frequently than what
the cpufreq subsystem does. This can lead to inaccurate measurements,
but it is not problematic here.
Co-developed-by: Damien Carver <carverdamien@gmail.com>
Signed-off-by: Damien Carver <carverdamien@gmail.com>
Signed-off-by: Redha Gouicem <redha.gouicem@gmail.com>
---
kernel/sched/core.c | 11 +++++++++++
kernel/sched/sched.h | 4 ++++
2 files changed, 15 insertions(+)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index c36dc1ae58be..d6d27a6fc23c 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -3976,6 +3976,15 @@ unsigned long long task_sched_runtime(struct task_struct *p)
return ns;
}
+struct freq_sample {
+ unsigned int khz;
+ ktime_t time;
+ u64 aperf;
+ u64 mperf;
+};
+
+DEFINE_PER_CPU(struct freq_sample, freq_sample);
+
/*
* This function gets called by the timer code, with HZ frequency.
* We call it with interrupts disabled.
@@ -3996,6 +4005,8 @@ void scheduler_tick(void)
update_rq_clock(rq);
thermal_pressure = arch_scale_thermal_pressure(cpu_of(rq));
update_thermal_load_avg(rq_clock_thermal(rq), rq, thermal_pressure);
+ rq->freq = arch_freq_get_on_cpu_from_sample(cpu,
+ this_cpu_ptr(&freq_sample));
curr->sched_class->task_tick(rq, curr, 0);
calc_global_load_tick(rq);
psi_task_tick(rq);
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 28709f6b0975..7d794ab756d2 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -1048,6 +1048,10 @@ struct rq {
/* Must be inspected within a rcu lock section */
struct cpuidle_state *idle_state;
#endif
+
+ /* Frequency measured at the last tick */
+ unsigned int freq;
+
};
#ifdef CONFIG_FAIR_GROUP_SCHED
--
2.28.0
next prev parent reply other threads:[~2020-10-20 15:45 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-20 15:44 [RFC PATCH 0/3] sched: delayed thread migration Redha Gouicem
2020-10-20 15:44 ` [PATCH 1/3] cpufreq: x86: allow external frequency measures Redha Gouicem
2020-10-20 15:44 ` Redha Gouicem [this message]
2020-10-20 15:44 ` [PATCH 3/3] sched/fair: delay thread migration on fork/wakeup/exec Redha Gouicem
2020-10-21 7:26 ` [RFC PATCH 0/3] sched: delayed thread migration Peter Zijlstra
2020-10-21 10:40 ` Redha
2020-10-21 11:48 ` Peter Zijlstra
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=20201020154445.119701-3-redha.gouicem@gmail.com \
--to=redha.gouicem@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=baptiste.lepers@sydney.edu.au \
--cc=bp@alien8.de \
--cc=bristot@redhat.com \
--cc=bsegall@google.com \
--cc=carverdamien@gmail.com \
--cc=dietmar.eggemann@arm.com \
--cc=gilles.muller@inria.fr \
--cc=gpiccoli@canonical.com \
--cc=hpa@zytor.com \
--cc=jean-pierre.lozi@oracle.com \
--cc=julia.lawall@inria.fr \
--cc=julien.sopena@lip6.fr \
--cc=juri.lelli@redhat.com \
--cc=keescook@chromium.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mcgrof@kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=nicolas.palix@univ-grenoble-alpes.fr \
--cc=peterz@infradead.org \
--cc=qais.yousef@arm.com \
--cc=rjw@rjwysocki.net \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--cc=vincent.guittot@linaro.org \
--cc=viresh.kumar@linaro.org \
--cc=viro@zeniv.linux.org.uk \
--cc=willy.zwaenepoel@sydney.edu.au \
--cc=x86@kernel.org \
--cc=yzaikin@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;
as well as URLs for NNTP newsgroup(s).