linux-mips
[Top] [All Lists]

[PATCH] fix clocksource parameter for low frequency timer.

To: linux-mips@linux-mips.org
Subject: [PATCH] fix clocksource parameter for low frequency timer.
From: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
Date: Thu, 26 Oct 2006 23:09:37 +0900 (JST)
Cc: ralf@linux-mips.org, m_lachwani@yahoo.com, creideiki+linux-mips@ferretporn.se
Original-recipient: rfc822;linux-mips@linux-mips.org
Sender: linux-mips-bounce@linux-mips.org
The current shift value in clocksource was not suitable for low
frequency timer.  Find the shift value in runtime to avoid undesirable
overflow.  Also calculate a somewhat reasonable rating value based on
its frequency.

Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>

diff --git a/arch/mips/kernel/time.c b/arch/mips/kernel/time.c
index 2c6d52b..e535f86 100644
--- a/arch/mips/kernel/time.c
+++ b/arch/mips/kernel/time.c
@@ -324,22 +324,29 @@ static cycle_t read_mips_hpt(void)
 
 static struct clocksource clocksource_mips = {
        .name           = "MIPS",
-       .rating         = 250,
        .read           = read_mips_hpt,
-       .shift          = 24,
        .is_continuous  = 1,
 };
 
 static void __init init_mips_clocksource(void)
 {
        u64 temp;
+       u32 shift;
 
        if (!mips_hpt_frequency || mips_hpt_read == null_hpt_read)
                return;
 
-       temp = (u64) NSEC_PER_SEC << clocksource_mips.shift;
-       do_div(temp, mips_hpt_frequency);
-       clocksource_mips.mult = (unsigned)temp;
+       /* Calclate a somewhat reasonable rating value */
+       clocksource_mips.rating = 200 + mips_hpt_frequency / 10000000;
+       /* Find a shift value */
+       for (shift = 32; shift > 0; shift--) {
+               temp = (u64) NSEC_PER_SEC << shift;
+               do_div(temp, mips_hpt_frequency);
+               if ((temp >> 32) == 0)
+                       break;
+       }
+       clocksource_mips.shift = shift;
+       clocksource_mips.mult = (u32)temp;
        clocksource_mips.mask = mips_hpt_mask;
 
        clocksource_register(&clocksource_mips);

<Prev in Thread] Current Thread [Next in Thread>