time/sched_clock: Fix formatting of frequency reporting code
[linux-2.6-microblaze.git] / kernel / time / sched_clock.c
index b1b9b12..8464c5a 100644 (file)
@@ -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,15 +200,13 @@ 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 >= 4000) {
+               r = DIV_ROUND_CLOSEST(r, 1000);
+               r_unit = 'k';
        } else {
-               if (r >= 1000) {
-                       r /= 1000;
-                       r_unit = 'k';
-               } else {
-                       r_unit = ' ';
-               }
+               r_unit = ' ';
        }
 
        /* Calculate the ns resolution of this counter */