mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Julian Stecklina <js@alien8.de>
To: x86@kernel.org
Cc: linux-kernel@vger.kernel.org,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	hpa@zytor.com,
	Julian Stecklina <julian.stecklina@cyberus-technology.de>,
	Markus Napierkowski <markus.napierkowski@cyberus-technology.de>
Subject: [PATCH] x86/apic: fix frequency in apic=verbose log output
Date: Sat, 30 Oct 2021 16:21:48 +0200	[thread overview]
Message-ID: <20211030142148.143261-1-js@alien8.de> (raw)

From: Julian Stecklina <julian.stecklina@cyberus-technology.de>

When apic=verbose is specified, the LAPIC timer calibration prints its
results to the console. While debugging virtualization code, we
noticed that the CPU and bus frequencies are printed incorrectly.

Specifically, for a 1.7 GHz CPU with 1 GHz bus frequency and HZ=1000,
the log includes a superfluous 0 after the period:

..... calibration result: 999978
..... CPU clock speed is 1696.0783 MHz.
..... host bus clock speed is 999.0978 MHz.

Looking at the code, this only worked as intended for HZ=100. After
the fix, we now see the correct frequency in the log:

..... calibration result: 999828
..... CPU clock speed is 1696.507 MHz.
..... host bus clock speed is 999.828 MHz.

There is no functional change to the LAPIC calibration here, beyond
the printf changes.

Suggested-by: Markus Napierkowski <markus.napierkowski@cyberus-technology.de>
Signed-off-by: Julian Stecklina <julian.stecklina@cyberus-technology.de>
---
 arch/x86/kernel/apic/apic.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index b70344bf6600..925becaac12a 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -198,6 +198,7 @@ static struct resource lapic_resource = {
 	.flags = IORESOURCE_MEM | IORESOURCE_BUSY,
 };
 
+/* Measured in ticks per HZ. */
 unsigned int lapic_timer_period = 0;
 
 static void apic_pm_activate(void);
@@ -835,6 +836,7 @@ static int __init calibrate_APIC_clock(void)
 	unsigned long jif_start;
 	unsigned long deltaj;
 	long delta, deltatsc;
+	long tsc_khz, bus_khz;
 	int pm_referenced = 0;
 
 	if (boot_cpu_has(X86_FEATURE_TSC_DEADLINE_TIMER))
@@ -937,16 +939,16 @@ static int __init calibrate_APIC_clock(void)
 		    lapic_timer_period);
 
 	if (boot_cpu_has(X86_FEATURE_TSC)) {
+		tsc_khz = (deltatsc * HZ) / (1000 * LAPIC_CAL_LOOPS);
 		apic_printk(APIC_VERBOSE, "..... CPU clock speed is "
-			    "%ld.%04ld MHz.\n",
-			    (deltatsc / LAPIC_CAL_LOOPS) / (1000000 / HZ),
-			    (deltatsc / LAPIC_CAL_LOOPS) % (1000000 / HZ));
+			    "%ld.%03ld MHz.\n",
+			    tsc_khz / 1000, tsc_khz % 1000);
 	}
 
+	bus_khz = (long)lapic_timer_period * HZ / 1000;
 	apic_printk(APIC_VERBOSE, "..... host bus clock speed is "
-		    "%u.%04u MHz.\n",
-		    lapic_timer_period / (1000000 / HZ),
-		    lapic_timer_period % (1000000 / HZ));
+		    "%ld.%03ld MHz.\n",
+		    bus_khz / 1000, bus_khz % 1000);
 
 	/*
 	 * Do a sanity check on the APIC calibration result
-- 
2.31.1


             reply	other threads:[~2021-10-30 14:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-30 14:21 Julian Stecklina [this message]
2025-11-07 16:55 ` [tip: x86/apic] x86/apic: Fix " tip-bot2 for Julian Stecklina

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=20211030142148.143261-1-js@alien8.de \
    --to=js@alien8.de \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=julian.stecklina@cyberus-technology.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=markus.napierkowski@cyberus-technology.de \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --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

all inboxes | Powered by JetHome®