diff mbox

[v2,3/3] ARM: arch_timer: use full 64-bit counter for sched_clock

Message ID 1364849914-26420-4-git-send-email-robherring2@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Rob Herring April 1, 2013, 8:58 p.m. UTC
From: Rob Herring <rob.herring@calxeda.com>

Only 32-bits of the arch timer were being used and wrapping was needlessly
being done in s/w. By using the full counter (56-64 bits), we don't need
to deal with wrapping and can simplify the implementation when using
arch timer.

Signed-off-by: Rob Herring <rob.herring@calxeda.com>
---
 arch/arm/kernel/arch_timer.c |   15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

Comments

Russell King - ARM Linux April 19, 2013, 4:27 p.m. UTC | #1
On Mon, Apr 01, 2013 at 03:58:34PM -0500, Rob Herring wrote:
> From: Rob Herring <rob.herring@calxeda.com>
> 
> Only 32-bits of the arch timer were being used and wrapping was needlessly
> being done in s/w. By using the full counter (56-64 bits), we don't need
> to deal with wrapping and can simplify the implementation when using
> arch timer.

Remember that you _must_ provide the full 64-bit nsec value to the
scheduler.  A 56-bit value will not do, it has to be the full 64-bits
of nsecs.  So:

> +static unsigned long long notrace arch_timer_sched_clock(void)
>  {
> -	return arch_timer_read_counter();
> +	return arch_timer_read_counter() * sched_clock_mult;
...
> +	/* Cache the sched_clock multiplier to save a divide in the hot path. */
> +	sched_clock_mult = NSEC_PER_SEC / arch_timer_rate;

If the counter is 56-bit and the multiplier is not larger than 255,
then you have a potential problem here.  That basically translates
into a clock rate of no more than 3.9MHz for the architected timer
if it is 56-bit.
diff mbox

Patch

diff --git a/arch/arm/kernel/arch_timer.c b/arch/arm/kernel/arch_timer.c
index d957a51..a7536d4 100644
--- a/arch/arm/kernel/arch_timer.c
+++ b/arch/arm/kernel/arch_timer.c
@@ -22,9 +22,11 @@  static unsigned long arch_timer_read_counter_long(void)
 	return arch_timer_read_counter();
 }
 
-static u32 arch_timer_read_counter_u32(void)
+static u32 sched_clock_mult __read_mostly;
+
+static unsigned long long notrace arch_timer_sched_clock(void)
 {
-	return arch_timer_read_counter();
+	return arch_timer_read_counter() * sched_clock_mult;
 }
 
 static struct delay_timer arch_delay_timer;
@@ -52,10 +54,13 @@  int __init arch_timer_of_register(void)
 
 int __init arch_timer_sched_clock_init(void)
 {
-	if (arch_timer_get_rate() == 0)
+        u32 arch_timer_rate = arch_timer_get_rate();
+
+	if (arch_timer_rate == 0)
 		return -ENXIO;
 
-	setup_sched_clock(arch_timer_read_counter_u32,
-			  32, arch_timer_get_rate());
+	/* Cache the sched_clock multiplier to save a divide in the hot path. */
+	sched_clock_mult = NSEC_PER_SEC / arch_timer_rate;
+	sched_clock_func = arch_timer_sched_clock;
 	return 0;
 }