All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH MANUALSEL 4.9 1/3] time/sched_clock: Round the frequency reported to nearest rather than down
@ 2022-06-05 13:55 Sasha Levin
  2022-06-05 13:55 ` [PATCH MANUALSEL 4.9 2/3] lib/irq_poll: Prevent softirq pending leak in irq_poll_cpu_dead() Sasha Levin
  2022-06-05 13:55 ` [PATCH MANUALSEL 4.9 3/3] x86/PCI: Add PIRQ routing table range checks Sasha Levin
  0 siblings, 2 replies; 3+ messages in thread
From: Sasha Levin @ 2022-06-05 13:55 UTC (permalink / raw)
  To: linux-kernel, stable
  Cc: Maciej W. Rozycki, Thomas Gleixner, John Stultz, Sasha Levin

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 382b159d8592..0a828ba65c0b 100644
--- a/kernel/time/sched_clock.c
+++ b/kernel/time/sched_clock.c
@@ -11,6 +11,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/syscore_ops.h>
@@ -212,11 +213,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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-06-05 13:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-05 13:55 [PATCH MANUALSEL 4.9 1/3] time/sched_clock: Round the frequency reported to nearest rather than down Sasha Levin
2022-06-05 13:55 ` [PATCH MANUALSEL 4.9 2/3] lib/irq_poll: Prevent softirq pending leak in irq_poll_cpu_dead() Sasha Levin
2022-06-05 13:55 ` [PATCH MANUALSEL 4.9 3/3] x86/PCI: Add PIRQ routing table range checks Sasha Levin

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.