public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Hans de Goede <hdegoede@redhat.com>,
	Andy Shevchenko <andy@infradead.org>,
	Ingo Molnar <mingo@redhat.com>
Cc: Hans de Goede <hdegoede@redhat.com>,
	Vipul Kumar <vipulk0511@gmail.com>,
	Vipul Kumar <vipul_kumar@mentor.com>,
	Daniel Lezcano <daniel.lezcano@linaro.org>,
	Srikanth Krishnakar <Srikanth_Krishnakar@mentor.com>,
	Cedric Hombourger <Cedric_Hombourger@mentor.com>,
	Len Brown <len.brown@intel.com>,
	Rahul Tanwar <rahul.tanwar@linux.intel.com>,
	Tony Luck <tony.luck@intel.com>,
	Gayatri Kammela <gayatri.kammela@intel.com>,
	x86@kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH v3 3/3] x86/tsc_msr: Make MSR derived TSC frequency more accurate
Date: Sat, 08 Feb 2020 01:05:39 +0100	[thread overview]
Message-ID: <87eev67xkc.fsf@nanos.tec.linutronix.de> (raw)
In-Reply-To: <20200207205456.113758-3-hdegoede@redhat.com>

Hans,

Hans de Goede <hdegoede@redhat.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

  parent reply	other threads:[~2020-02-08  0:06 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-07 20:54 [PATCH v3 1/3] x86/tsc_msr: Use named struct initializers Hans de Goede
2020-02-07 20:54 ` [PATCH v3 2/3] x86/tsc_msr: Fix MSR_FSB_FREQ mask for Cherry Trail devices Hans de Goede
2020-02-07 20:54 ` [PATCH v3 3/3] x86/tsc_msr: Make MSR derived TSC frequency more accurate Hans de Goede
2020-02-07 22:11   ` Andy Shevchenko
2020-02-10 10:08     ` David Laight
2020-02-08  0:05   ` Thomas Gleixner [this message]
2020-02-23 13:55     ` Hans de Goede

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=87eev67xkc.fsf@nanos.tec.linutronix.de \
    --to=tglx@linutronix.de \
    --cc=Cedric_Hombourger@mentor.com \
    --cc=Srikanth_Krishnakar@mentor.com \
    --cc=andy@infradead.org \
    --cc=daniel.lezcano@linaro.org \
    --cc=gayatri.kammela@intel.com \
    --cc=hdegoede@redhat.com \
    --cc=len.brown@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=rahul.tanwar@linux.intel.com \
    --cc=stable@vger.kernel.org \
    --cc=tony.luck@intel.com \
    --cc=vipul_kumar@mentor.com \
    --cc=vipulk0511@gmail.com \
    --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