From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: "Maciej W. Rozycki" <macro@orcam.me.uk>,
Thomas Gleixner <tglx@linutronix.de>,
John Stultz <jstultz@google.com>, Sasha Levin <sashal@kernel.org>
Subject: [PATCH MANUALSEL 5.17 3/6] time/sched_clock: Round the frequency reported to nearest rather than down
Date: Sun, 5 Jun 2022 09:53:34 -0400 [thread overview]
Message-ID: <20220605135341.61427-3-sashal@kernel.org> (raw)
In-Reply-To: <20220605135341.61427-1-sashal@kernel.org>
From: "Maciej W. Rozycki" <macro@orcam.me.uk>
[ Upstream commit 92067440f1311dfa4d77b57a9da6b3706f5da32e ]
The frequency reported for clock sources are rounded down, which gives
misleading figures, e.g.:
I/O ASIC clock frequency 24999480Hz
sched_clock: 32 bits at 24MHz, resolution 40ns, wraps every 85901132779ns
MIPS counter frequency 59998512Hz
sched_clock: 32 bits at 59MHz, resolution 16ns, wraps every 35792281591ns
Rounding to nearest is more adequate:
I/O ASIC clock frequency 24999664Hz
sched_clock: 32 bits at 25MHz, resolution 40ns, wraps every 85900499947ns
MIPS counter frequency 59999728Hz
sched_clock: 32 bits at 60MHz, resolution 16ns, wraps every 35791556599ns
Signed-off-by: Maciej W. Rozycki <macro@orcam.me.uk>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: John Stultz <jstultz@google.com>
Link: https://lore.kernel.org/r/alpine.DEB.2.21.2204240055590.9383@angie.orcam.me.uk
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
kernel/time/sched_clock.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/kernel/time/sched_clock.c b/kernel/time/sched_clock.c
index b1b9b12899f5..ee07f3ac1e5b 100644
--- a/kernel/time/sched_clock.c
+++ b/kernel/time/sched_clock.c
@@ -8,6 +8,7 @@
#include <linux/jiffies.h>
#include <linux/ktime.h>
#include <linux/kernel.h>
+#include <linux/math.h>
#include <linux/moduleparam.h>
#include <linux/sched.h>
#include <linux/sched/clock.h>
@@ -199,11 +200,11 @@ sched_clock_register(u64 (*read)(void), int bits, unsigned long rate)
r = rate;
if (r >= 4000000) {
- r /= 1000000;
+ r = DIV_ROUND_CLOSEST(r, 1000000);
r_unit = 'M';
} else {
if (r >= 1000) {
- r /= 1000;
+ r = DIV_ROUND_CLOSEST(r, 1000);
r_unit = 'k';
} else {
r_unit = ' ';
--
2.35.1
next prev parent reply other threads:[~2022-06-05 13:54 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-05 13:53 [PATCH MANUALSEL 5.17 1/6] x86/nmi: Make register_nmi_handler() more robust Sasha Levin
2022-06-05 13:53 ` [PATCH MANUALSEL 5.17 2/6] genirq/irq_sim: Make the irq_work always run in hard irq context Sasha Levin
2022-06-05 13:53 ` Sasha Levin [this message]
2022-06-05 13:53 ` [PATCH MANUALSEL 5.17 4/6] lib/irq_poll: Prevent softirq pending leak in irq_poll_cpu_dead() Sasha Levin
2022-06-05 13:53 ` [PATCH MANUALSEL 5.17 5/6] genirq/msi: Shutdown managed interrupts with unsatifiable affinities Sasha Levin
2022-06-05 13:53 ` [PATCH MANUALSEL 5.17 6/6] x86/PCI: Add PIRQ routing table range checks Sasha Levin
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=20220605135341.61427-3-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=jstultz@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=macro@orcam.me.uk \
--cc=stable@vger.kernel.org \
--cc=tglx@linutronix.de \
/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;
as well as URLs for NNTP newsgroup(s).