From: Petr Tesarik <ptesarik@suse.com>
To: Thorsten Blum <blum@kernel.org>,
Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
Hans Peter Anvin <hpa@zytor.com>,
Peter Zijlstra <peterz@infradead.org>,
Juergen Gross <jgross@suse.com>
Cc: linux-kernel@vger.kernel.org, x86@kernel.org,
Petr Tesarik <ptesarik@suse.com>
Subject: [PATCH v2 3/3] x86/tsc: Use TSC_CALIBRATE_MULT for the TSC multiplier
Date: Wed, 14 Oct 2026 15:29:32 +0200 [thread overview]
Message-ID: <20261014132932.1495303-4-ptesarik@suse.com> (raw)
In-Reply-To: <20261014132932.1495303-1-ptesarik@suse.com>
The TSC delta is multiplied by one million to improve precision. This
multiplication is later undone in calc_hpet_ref() and calc_pmtimer_ref(),
making it difficult to understand the meaning of the divisor value.
Replace the magic constants with a more descriptive macro or calculation.
No functional change intended.
Signed-off-by: Petr Tesarik <ptesarik@suse.com>
---
arch/x86/kernel/tsc.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
index 7e31acad2b055..b4815fdedf1b5 100644
--- a/arch/x86/kernel/tsc.c
+++ b/arch/x86/kernel/tsc.c
@@ -339,6 +339,7 @@ __setup("tsc=", tsc_setup);
#define MAX_RETRIES 5
#define TSC_DEFAULT_THRESHOLD 0x20000
+#define TSC_CALIBRATE_MULT 1000000LL
/*
* Read TSC and the reference counters. Take care of any disturbances
@@ -373,7 +374,7 @@ static unsigned long calc_hpet_ref(u64 deltatsc, u64 hpet1, u64 hpet2)
hpet2 += 0x100000000ULL;
hpet2 -= hpet1;
tmp = ((u64)hpet2 * hpet_readl(HPET_PERIOD));
- do_div(tmp, 1000000);
+ do_div(tmp, FSEC_PER_SEC / HZ_PER_KHZ / TSC_CALIBRATE_MULT);
deltatsc = div64_u64(deltatsc, tmp);
return (unsigned long) deltatsc;
@@ -392,7 +393,7 @@ static unsigned long calc_pmtimer_ref(u64 deltatsc, u64 pm1, u64 pm2)
if (pm2 < pm1)
pm2 += (u64)ACPI_PM_OVRRUN;
pm2 -= pm1;
- tmp = pm2 * 1000000LL * HZ_PER_KHZ;
+ tmp = pm2 * TSC_CALIBRATE_MULT * HZ_PER_KHZ;
do_div(tmp, PMTMR_TICKS_PER_SEC);
do_div(deltatsc, tmp);
@@ -806,7 +807,7 @@ static unsigned long pit_hpet_ptimer_calibrate_cpu(void)
if (tsc1 == ULLONG_MAX || tsc2 == ULLONG_MAX)
continue;
- tsc2 = (tsc2 - tsc1) * 1000000LL;
+ tsc2 = (tsc2 - tsc1) * TSC_CALIBRATE_MULT;
if (hpet)
tsc2 = calc_hpet_ref(tsc2, ref1, ref2);
else
@@ -1334,7 +1335,7 @@ static void tsc_refine_calibration_work(struct work_struct *work)
goto restart;
delta = tsc_stop - tsc_start;
- delta *= 1000000LL;
+ delta *= TSC_CALIBRATE_MULT;
if (hpet)
freq = calc_hpet_ref(delta, ref_start, ref_stop);
else
--
2.55.0
next prev parent reply other threads:[~2026-10-14 13:29 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-14 13:29 [PATCH v2 0/3] x86/tsc: Remove some magic constants Petr Tesarik
2026-10-14 13:29 ` [PATCH v2 1/3] x86/tsc: Replace magic constants with xxx_PER_SEC Petr Tesarik
2026-10-14 13:29 ` [PATCH v2 2/3] x86/tsc: Use HZ_PER_KHZ and KHZ_PER_MHZ Petr Tesarik
2026-10-14 13:29 ` Petr Tesarik [this message]
2026-10-27 12:37 ` [PATCH v2 0/3] x86/tsc: Remove some magic constants Petr Tesarik
2026-11-18 12:07 ` Petr Tesarik
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=20261014132932.1495303-4-ptesarik@suse.com \
--to=ptesarik@suse.com \
--cc=blum@kernel.org \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=jgross@suse.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=tglx@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.