Skip to content

Commit 9206744

Browse files
maciej-w-rozyckiKAGA-KOKO
authored andcommitted
time/sched_clock: Round the frequency reported to nearest rather than down
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 <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Acked-by: John Stultz <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 90be8d6 commit 9206744

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

kernel/time/sched_clock.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/jiffies.h>
99
#include <linux/ktime.h>
1010
#include <linux/kernel.h>
11+
#include <linux/math.h>
1112
#include <linux/moduleparam.h>
1213
#include <linux/sched.h>
1314
#include <linux/sched/clock.h>
@@ -199,11 +200,11 @@ sched_clock_register(u64 (*read)(void), int bits, unsigned long rate)
199200

200201
r = rate;
201202
if (r >= 4000000) {
202-
r /= 1000000;
203+
r = DIV_ROUND_CLOSEST(r, 1000000);
203204
r_unit = 'M';
204205
} else {
205206
if (r >= 1000) {
206-
r /= 1000;
207+
r = DIV_ROUND_CLOSEST(r, 1000);
207208
r_unit = 'k';
208209
} else {
209210
r_unit = ' ';

0 commit comments

Comments
 (0)