From: Peter Zijlstra <peterz@infradead.org>
To: Viresh Kumar <viresh.kumar@linaro.org>
Cc: "Vincent Guittot" <vincent.guittot@linaro.org>,
kvm@vger.kernel.org, "Radim Krčmář" <rkrcmar@redhat.com>,
linux-pm@vger.kernel.org, x86@kernel.org,
"Rafael Wysocki" <rjw@rjwysocki.net>,
"Russell King" <linux@armlinux.org.uk>,
linux-kernel@vger.kernel.org, "Ingo Molnar" <mingo@redhat.com>,
"Borislav Petkov" <bp@alien8.de>,
"H. Peter Anvin" <hpa@zytor.com>,
sparclinux@vger.kernel.org, "Paolo Bonzini" <pbonzini@redhat.com>,
"Thomas Gleixner" <tglx@linutronix.de>,
"David S. Miller" <davem@davemloft.net>,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH V2] cpufreq: Call transition notifier only once for each policy
Date: Mon, 18 Mar 2019 11:53:56 +0100 [thread overview]
Message-ID: <20190318105356.GM6058@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20190318023514.67gxypb4w7llcmha@vireshk-i7>
On Mon, Mar 18, 2019 at 08:05:14AM +0530, Viresh Kumar wrote:
> On 15-03-19, 13:29, Peter Zijlstra wrote:
> > On Fri, Mar 15, 2019 at 02:43:07PM +0530, Viresh Kumar wrote:
> > > diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
> > > index 3fae23834069..cff8779fc0d2 100644
> > > --- a/arch/x86/kernel/tsc.c
> > > +++ b/arch/x86/kernel/tsc.c
> > > @@ -956,28 +956,38 @@ static int time_cpufreq_notifier(struct notifier_block *nb, unsigned long val,
> > > void *data)
> > > {
> > > struct cpufreq_freqs *freq = data;
> > > - unsigned long *lpj;
> > > -
> > > - lpj = &boot_cpu_data.loops_per_jiffy;
> > > -#ifdef CONFIG_SMP
> > > - if (!(freq->flags & CPUFREQ_CONST_LOOPS))
> > > - lpj = &cpu_data(freq->cpu).loops_per_jiffy;
> > > -#endif
> > > + struct cpumask *cpus = freq->policy->cpus;
> > > + bool boot_cpu = !IS_ENABLED(CONFIG_SMP) || freq->flags & CPUFREQ_CONST_LOOPS;
> > > + unsigned long lpj;
> > > + int cpu;
> > >
> > > if (!ref_freq) {
> > > ref_freq = freq->old;
> > > - loops_per_jiffy_ref = *lpj;
> > > tsc_khz_ref = tsc_khz;
> > > +
> > > + if (boot_cpu)
> > > + loops_per_jiffy_ref = boot_cpu_data.loops_per_jiffy;
> > > + else
> > > + loops_per_jiffy_ref = cpu_data(cpumask_first(cpus)).loops_per_jiffy;
> > > }
> > > +
> > > if ((val == CPUFREQ_PRECHANGE && freq->old < freq->new) ||
> > > (val == CPUFREQ_POSTCHANGE && freq->old > freq->new)) {
> > > - *lpj = cpufreq_scale(loops_per_jiffy_ref, ref_freq, freq->new);
> > > -
> > > + lpj = cpufreq_scale(loops_per_jiffy_ref, ref_freq, freq->new);
> > > tsc_khz = cpufreq_scale(tsc_khz_ref, ref_freq, freq->new);
> > > +
> > > if (!(freq->flags & CPUFREQ_CONST_LOOPS))
> > > mark_tsc_unstable("cpufreq changes");
> > >
> > > - set_cyc2ns_scale(tsc_khz, freq->cpu, rdtsc());
> > > + if (boot_cpu) {
> > > + boot_cpu_data.loops_per_jiffy = lpj;
> > > + } else {
> > > + for_each_cpu(cpu, cpus)
> > > + cpu_data(cpu).loops_per_jiffy = lpj;
> > > + }
> > > +
> > > + for_each_cpu(cpu, cpus)
> > > + set_cyc2ns_scale(tsc_khz, cpu, rdtsc());
> >
> > This code doesn't make sense, the rdtsc() _must_ be called on the CPU in
> > question.
>
> You mean rdtsc() must be locally on that CPU? The cpufreq core never guaranteed
> that and it was left for the notifier to do. This patch doesn't change the
> behavior at all, just that it moves the for-loop to the notifier instead of the
> cpufreq core.
Yuck..
Rafael; how does this work in practise? Earlier you said that on x86 the
policies typically have a single cpu in them anyway. Is the freq change
also notified from _that_ cpu?
I don't think I have old enough hardware around anymore to test any of
this. This was truly ancient p6 era stuff IIRC.
Because in that case, I'm all for not doing the changes to this notifier
Viresh is proposing but simply adding something like:
WARN_ON_ONCE(cpumask_weight(cpuc) != 1);
WARN_ON_ONCE(cpumask_first(cpuc) != smp_processor_id());
And leave it at that.
next prev parent reply other threads:[~2019-03-18 10:53 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-15 9:13 [PATCH V2] cpufreq: Call transition notifier only once for each policy Viresh Kumar
2019-03-15 12:29 ` Peter Zijlstra
2019-03-18 2:35 ` Viresh Kumar
2019-03-18 10:53 ` Peter Zijlstra [this message]
2019-03-18 11:09 ` Rafael J. Wysocki
2019-03-18 11:20 ` Rafael J. Wysocki
2019-03-18 10:45 ` Rafael J. Wysocki
2019-03-18 11:01 ` Peter Zijlstra
2019-03-18 11:49 ` Rafael J. Wysocki
2019-03-19 5:50 ` Viresh Kumar
2019-03-19 9:41 ` Rafael J. Wysocki
2019-03-19 10:49 ` Viresh Kumar
2019-03-19 15:44 ` Rafael J. Wysocki
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=20190318105356.GM6058@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=bp@alien8.de \
--cc=davem@davemloft.net \
--cc=hpa@zytor.com \
--cc=kvm@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=rjw@rjwysocki.net \
--cc=rkrcmar@redhat.com \
--cc=sparclinux@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=vincent.guittot@linaro.org \
--cc=viresh.kumar@linaro.org \
--cc=x86@kernel.org \
/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