Skip to contentSkip to conversation

AVR32: Switch to generic timekeeping framework

PATCH In review Haavard Skinnemoen 2 participants 2 messages Aug 8, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 AVR32: Switch to generic timekeeping framework

Define CONFIG_GENERIC_TIME and remove arch-specific versions of do_{get,set}timeofday(). Define and use a clocksource based on the AVR32 cycle counter.

Also clean up asm/timex.h a bit, including defining CLOCK_TICK_RATE to a "good cheat value" borrowed from MIPS instead of the i8254 value used by "everyone" else, which is really quite pointless on AVR32.

---
 arch/avr32/Kconfig        |    4 +
 arch/avr32/kernel/time.c  |  172 +++++++++-------------------------------------
 include/asm-avr32/timex.h |   26 ++++--
 3 files changed, 59 insertions(+), 143 deletions(-)
arch/avr32/Kconfig +4 -0
Index: linux-2.6.18-rc3-mm2/arch/avr32/Kconfig
===================================================================
@@ -38,6 +38,10 @@ config RWSEM_GENERIC_SPINLOCK
 	bool
 	default y
 
+config GENERIC_TIME
+	bool
+	default y
+
 config RWSEM_XCHGADD_ALGORITHM
 	bool
 
arch/avr32/kernel/time.c +37 -135

240 lines not on this page · raw message

include/asm-avr32/timex.h +18 -8
Index: linux-2.6.18-rc3-mm2/include/asm-avr32/timex.h
===================================================================
@@ -8,17 +8,27 @@
 #ifndef __ASM_AVR32_TIMEX_H
 #define __ASM_AVR32_TIMEX_H
 
-/* FIXME: I really have no idea... */
-#define CLOCK_TICK_RATE		1193180	/* Underlying HZ */
-#define CLOCK_TICK_FACTOR	20	/* Factor of both 1000000 and CLOCK_TICK_RATE */
-#define FINETUNE ((((((long)LATCH * HZ - CLOCK_TICK_RATE) << SHIFT_HZ) * \
-		   (1000000/CLOCK_TICK_FACTOR) / (CLOCK_TICK_RATE/CLOCK_TICK_FACTOR)) \
-		  << (SHIFT_SCALE-SHIFT_HZ)) / HZ)
+/*
+ * This is the frequency of the timer used for Linux's timer interrupt.
+ * The value should be defined as accurate as possible or under certain
+ * circumstances Linux timekeeping might become inaccurate or fail.
+ *
+ * For many system the exact clockrate of the timer isn't known but due to
+ * the way this value is used we can get away with a wrong value as long
+ * as this value is:
+ *
+ *  - a multiple of HZ
+ *  - a divisor of the actual rate
+ *
+ * 500000 is a good such cheat value.
+ *
+ * The obscure number 1193182 is the same as used by the original i8254
+ * time in legacy PC hardware; the chip is never found in AVR32 systems.
+ */
+#define CLOCK_TICK_RATE		500000	/* Underlying HZ */
 
 typedef unsigned long cycles_t;
 
-extern cycles_t cacheflush_time;
-
 static inline cycles_t get_cycles (void)
 {
 	return 0;
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Haavard Skinnemoen

Define CONFIG_GENERIC_TIME and remove arch-specific versions of do_{get,set}timeofday(). Define and use a clocksource based on the AVR32 cycle counter.

Also clean up asm/timex.h a bit, including defining CLOCK_TICK_RATE to a "good cheat value" borrowed from MIPS instead of the i8254 value used by "everyone" else, which is really quite pointless on AVR32.

Quoted 6 lines
---
 arch/avr32/Kconfig        |    4 +
 arch/avr32/kernel/time.c  |  172 +++++++++-------------------------------------
 include/asm-avr32/timex.h |   26 ++++--
 3 files changed, 59 insertions(+), 143 deletions(-)

Can't argue w/ a diffstat like that :)
Glad to see the code is working for you!

Quoted 25 lines
arch/avr32/kernel/time.c +14 -6
@@ -286,22 +183,22 @@ void __init time_init(void)
 	       (unsigned long)sysreg_read(COUNT),
 	       (unsigned long)sysreg_read(COMPARE));
 
-	if (!avr32_hpt_frequency && boot_cpu_data.clk)
-		avr32_hpt_frequency = clk_get_rate(boot_cpu_data.clk);
-
-	if (avr32_hpt_frequency) {
-		cycles_per_jiffy = (avr32_hpt_frequency + HZ / 2) / HZ;
+	count_hz = clk_get_rate(boot_cpu_data.clk);
+	shift = clocksource_avr32.shift;
+	mult = clocksource_hz2mult(count_hz, shift);
+	clocksource_avr32.mult = mult;
+
+	printk("Cycle counter: mult=%lu, shift=%lu\n", mult, shift);
+
+	{
+		u64 tmp;
+
+		tmp = TICK_NSEC;
+		tmp <<= shift;
+		tmp += mult / 2;
+		do_div(tmp, mult);
 
-		/* 10^6 * 2^32 / avr32_hpt_frequency */

arch/avr32/kernel/time.c void __init time_init(void) · line 201

Quoted 10 lines
arch/avr32/kernel/time.c +1 -9
-		{
-			u64 tmp = 1000000ULL << 32;
-			do_div(tmp, avr32_hpt_frequency);
-			sll32_usecs_per_cycle = tmp;
-		}
-
-		printk("Using %u.%03u MHz high precision timer.\n",
-		       ((avr32_hpt_frequency + 500) / 1000) / 1000,
-		       ((avr32_hpt_frequency + 500) / 1000) % 1000);
+		cycles_per_jiffy = tmp;

That looks redundant to the calculate_interval code in timer.c and points to a need for a generic nanosecond to cycles interface. I'll put that on my TODO list.

Quoted 9 lines
include/asm-avr32/timex.h +8 -0
+/*
+ * This is the frequency of the timer used for Linux's timer interrupt.
+ * The value should be defined as accurate as possible or under certain
+ * circumstances Linux timekeeping might become inaccurate or fail.
+ *
+ * For many system the exact clockrate of the timer isn't known but due to
+ * the way this value is used we can get away with a wrong value as long
+ * as this value is:

include/asm-avr32/timex.h line 28

Quoted 10 lines
include/asm-avr32/timex.h +10 -0
+ *
+ *  - a multiple of HZ
+ *  - a divisor of the actual rate
+ *
+ * 500000 is a good such cheat value.
+ *
+ * The obscure number 1193182 is the same as used by the original i8254
+ * time in legacy PC hardware; the chip is never found in AVR32 systems.
+ */
+#define CLOCK_TICK_RATE		500000	/* Underlying HZ */

Hmm.. Hopefully the future NTP cleanup will remove the need for these sorts of, uh.. tricks. :)

thanks
-john