[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87eev67xkc.fsf@nanos.tec.linutronix.de>
Date: Sat, 08 Feb 2020 01:05:39 +0100
From: Thomas Gleixner <tglx@...utronix.de>
To: Hans de Goede <hdegoede@...hat.com>,
Andy Shevchenko <andy@...radead.org>,
Ingo Molnar <mingo@...hat.com>
Cc: Hans de Goede <hdegoede@...hat.com>,
Vipul Kumar <vipulk0511@...il.com>,
Vipul Kumar <vipul_kumar@...tor.com>,
Daniel Lezcano <daniel.lezcano@...aro.org>,
Srikanth Krishnakar <Srikanth_Krishnakar@...tor.com>,
Cedric Hombourger <Cedric_Hombourger@...tor.com>,
Len Brown <len.brown@...el.com>,
Rahul Tanwar <rahul.tanwar@...ux.intel.com>,
Tony Luck <tony.luck@...el.com>,
Gayatri Kammela <gayatri.kammela@...el.com>, x86@...nel.org,
linux-kernel@...r.kernel.org, stable@...r.kernel.org
Subject: Re: [PATCH v3 3/3] x86/tsc_msr: Make MSR derived TSC frequency more accurate
Hans,
Hans de Goede <hdegoede@...hat.com> writes:
> @@ -120,11 +180,23 @@ unsigned long cpu_khz_from_msr(void)
> rdmsr(MSR_FSB_FREQ, lo, hi);
> index = lo & freq_desc->mask;
>
> - /* Map CPU reference clock freq ID(0-7) to CPU reference clock freq(KHz) */
> - freq = freq_desc->freqs[index];
> -
> - /* TSC frequency = maximum resolved freq * maximum resolved bus ratio */
> - res = freq * ratio;
> + /*
> + * Note this also catches cases where the index points to an unpopulated
> + * part of muldiv, in that case the else will set freq and res to 0.
> + */
> + if (freq_desc->muldiv[index].divider) {
> + freq = DIV_ROUND_CLOSEST(TSC_REFERENCE_KHZ *
> + freq_desc->muldiv[index].multiplier,
> + freq_desc->muldiv[index].divider);
> + /* Multiply by ratio before the divide for better accuracy */
> + res = DIV_ROUND_CLOSEST(TSC_REFERENCE_KHZ *
> + freq_desc->muldiv[index].multiplier *
> + ratio,
> + freq_desc->muldiv[index].divider);
What about:
struct muldiv *md = &freq_desc->muldiv[index];
if (md->divider) {
tscref = TSC_REFERENCE_KHZ * md->multiplier;
freq = DIV_ROUND_CLOSEST(tscref, md->divider);
/*
* Multiplying by ratio before the division has better
* accuracy than just calculating freq * ratio
*/
res = DIV_ROUND_CLOSEST(tscref * ratio, md->divider);
Hmm?
Thanks,
tglx
Powered by blists - more mailing lists