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>,
"Guilherme G. Piccoli" <gpiccoli@canonical.com>,
Al Viro <viro@zeniv.linux.org.uk>,
Qais Yousef <qais.yousef@arm.com>,
linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org,
linux-fsdevel@vger.kernel.org
Subject: [PATCH 1/3] cpufreq: x86: allow external frequency measures
Date: Tue, 20 Oct 2020 17:44:39 +0200 [thread overview]
Message-ID: <20201020154445.119701-2-redha.gouicem@gmail.com> (raw)
In-Reply-To: <20201020154445.119701-1-redha.gouicem@gmail.com>
Allow other subsystems to query the current frequency from the CPU without
affecting the cached value of cpufreq. The subsystems doing this will need
to maintain their own version of struct aperfmperf_sample.
This is useful if you need to query frequency more frequently than
APERFMPERF_CACHE_THRESHOLD_MS but don't want to mess with the current
caching behavior.
Even though querying too frequently may render the measures inaccurate, it
is still useful if your subsystem tolerates this inaccuracy.
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>
---
arch/x86/kernel/cpu/aperfmperf.c | 31 +++++++++++++++++++++++++++----
drivers/cpufreq/cpufreq.c | 5 +++++
include/linux/cpufreq.h | 1 +
3 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kernel/cpu/aperfmperf.c b/arch/x86/kernel/cpu/aperfmperf.c
index e2f319dc992d..c3be81d689f4 100644
--- a/arch/x86/kernel/cpu/aperfmperf.c
+++ b/arch/x86/kernel/cpu/aperfmperf.c
@@ -36,11 +36,11 @@ static DEFINE_PER_CPU(struct aperfmperf_sample, samples);
* unless we already did it within 10ms
* calculate kHz, save snapshot
*/
-static void aperfmperf_snapshot_khz(void *dummy)
+static void aperfmperf_snapshot_khz(void *prev_sample)
{
u64 aperf, aperf_delta;
u64 mperf, mperf_delta;
- struct aperfmperf_sample *s = this_cpu_ptr(&samples);
+ struct aperfmperf_sample *s = prev_sample;
unsigned long flags;
local_irq_save(flags);
@@ -72,7 +72,8 @@ static bool aperfmperf_snapshot_cpu(int cpu, ktime_t now, bool wait)
if (time_delta < APERFMPERF_CACHE_THRESHOLD_MS)
return true;
- smp_call_function_single(cpu, aperfmperf_snapshot_khz, NULL, wait);
+ smp_call_function_single(cpu, aperfmperf_snapshot_khz,
+ per_cpu_ptr(&samples, cpu), wait);
/* Return false if the previous iteration was too long ago. */
return time_delta <= APERFMPERF_STALE_THRESHOLD_MS;
@@ -131,7 +132,29 @@ unsigned int arch_freq_get_on_cpu(int cpu)
return per_cpu(samples.khz, cpu);
msleep(APERFMPERF_REFRESH_DELAY_MS);
- smp_call_function_single(cpu, aperfmperf_snapshot_khz, NULL, 1);
+ smp_call_function_single(cpu, aperfmperf_snapshot_khz,
+ per_cpu_ptr(&samples, cpu), 1);
return per_cpu(samples.khz, cpu);
}
+
+unsigned int arch_freq_get_on_cpu_from_sample(int cpu, void *sample)
+{
+ struct aperfmperf_sample *s = sample;
+
+ if (!sample)
+ return 0;
+
+ if (!cpu_khz)
+ return 0;
+
+ if (!boot_cpu_has(X86_FEATURE_APERFMPERF))
+ return 0;
+
+ if (!housekeeping_cpu(cpu, HK_FLAG_MISC))
+ return 0;
+
+ smp_call_function_single(cpu, aperfmperf_snapshot_khz, s, 1);
+
+ return s->khz;
+}
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 02ab56b2a0d8..36e6dbd87317 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -695,6 +695,11 @@ __weak unsigned int arch_freq_get_on_cpu(int cpu)
return 0;
}
+__weak unsigned int arch_freq_get_on_cpu_from_sample(int cpu, void *sample)
+{
+ return 0;
+}
+
static ssize_t show_scaling_cur_freq(struct cpufreq_policy *policy, char *buf)
{
ssize_t ret;
diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
index 8f141d4c859c..129083684ca0 100644
--- a/include/linux/cpufreq.h
+++ b/include/linux/cpufreq.h
@@ -1005,6 +1005,7 @@ static inline void sched_cpufreq_governor_change(struct cpufreq_policy *policy,
extern void arch_freq_prepare_all(void);
extern unsigned int arch_freq_get_on_cpu(int cpu);
+extern unsigned int arch_freq_get_on_cpu_from_sample(int cpu, void *sample);
extern void arch_set_freq_scale(struct cpumask *cpus, unsigned long cur_freq,
unsigned long max_freq);
--
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 ` Redha Gouicem [this message]
2020-10-20 15:44 ` [PATCH 2/3] sched: core: x86: query frequency at each tick Redha Gouicem
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-2-redha.gouicem@gmail.com \
--to=redha.gouicem@gmail.com \
--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).