Skip to contentSkip to conversation

Initial ARM generic-timeofday support

PATCH In review [email protected] 3 participants 9 messages Jun 5, 2006 – Jun 6, 2006

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover Initial ARM generic-timeofday support

Hi,

This patchset (against -rt26, but should apply to newer patch) adds initial support for generic TOD on ARM. It is fairly simple and copletely rips out the existing TOD code in ARM, assuming that each sub-arch will either provide a clocksource or enable CONFIG_IS_TICK_BASED. Currently only Versatile is supported.

Please apply so folks can start testing or provide comments.

Tnx,
~Deepak

--
Deepak Saxena - [email protected] - http://www.plexity.net

In the end, they will not say, "those were dark times," they will ask "why were their poets silent?" - Bertold Brecht

#1 lore raw

PATCH 1/2 Remove existing time code from ARM architecture

This patch removes do_gettimeofday(), do_setttimeofday() and associated time functions from ARM so that it can use the generic time-of-day code. Each sub-arch must explicitly enable CONFIG_IS_TICK_BASED if it does not have continous timer source.

arch/arm/Kconfig +4 -0
Index: linux-2.6-rt/arch/arm/Kconfig
===================================================================
@@ -46,6 +46,10 @@ config MCA
 	  <file:Documentation/mca.txt> (and especially the web page given
 	  there) before attempting to build an MCA bus kernel.
 
+config GENERIC_TIME
+	bool
+	default y
+
 config GENERIC_HARDIRQS
 	bool
 	default y
arch/arm/kernel/time.c +13 -87

148 lines not on this page · raw message

include/asm-arm/timeofday.h new file +4 -0
Index: linux-2.6-rt/include/asm-arm/timeofday.h
===================================================================
@@ -0,0 +1,4 @@
+#ifndef _ASM_ARM_TIMEOFDAY_H
+#define _ASM_ARM_TIMEOFDAY_H
+#include <asm-generic/timeofday.h>
+#endif
include/asm-arm/mach/time.h +3 -0
Index: linux-2.6-rt/include/asm-arm/mach/time.h
===================================================================
@@ -38,7 +38,10 @@ struct sys_timer {
 	void			(*init)(void);
 	void			(*suspend)(void);
 	void			(*resume)(void);
+
+#ifdef CONFIG_IS_TICK_BASED
 	unsigned long		(*offset)(void);
+#endif
 
 #ifdef CONFIG_NO_IDLE_HZ
 	struct dyn_tick_timer	*dyn_tick;

--
Deepak Saxena - [email protected] - http://www.plexity.net

In the end, they will not say, "those were dark times," they will ask "why were their poets silent?" - Bertold Brecht

#2 lore raw

Re: [patch-rt 1/2] Remove existing time code from ARM architecture

Quoted 5 lines · On Mon, 2006-06-05 at 15:29 -0700, [email protected] wrote:

plain text document attachment (arm-generic-timeofday.patch) This patch removes do_gettimeofday(), do_setttimeofday() and associated time functions from ARM so that it can use the generic time-of-day code. Each sub-arch must explicitly enable CONFIG_IS_TICK_BASED if it does not have continous timer source.

It might be good to define CONFIG_IS_TICK_BASED for the other ARM arches so they continue to build after your changes. Otherwise it looks good to me.

Another aside: CONFIG_IS_TICK_BASED also goes away w/ the Cx series. So there you will want to conditionally enable GENERIC_TIME if you have a clocksources defined and just wrap the old get/set_timeofday() w/ ifndef CONFIG_GENERIC_TIME until all the sub-arches have been converted. Don't worry too much, I'll lend a hand here when the time comes to update -rt, so it shouldn't be much of an issue.

thanks
-john

#3 lore raw

PATCH 2/2 Add clocksource driver for Versatile board

In reply to [email protected]

This patch adds a clocksource driver for the ARM versatile board, allowing it to use the generic time-of-day code.

arch/arm/mach-versatile/core.c +33 -41
Index: linux-2.6-rt/arch/arm/mach-versatile/core.c
===================================================================
@@ -27,6 +27,7 @@
 #include <linux/interrupt.h>
 #include <linux/amba/bus.h>
 #include <linux/amba/clcd.h>
+#include <linux/clockchips.h>
 
 #include <asm/system.h>
 #include <asm/hardware.h>
@@ -815,46 +816,6 @@ void __init versatile_init(void)
 #endif
 
 /*
- * Returns number of ms since last clock interrupt.  Note that interrupts
- * will have been disabled by do_gettimeoffset()
- */
-static unsigned long versatile_gettimeoffset(void)
-{
-	unsigned long ticks1, ticks2, status;
-
-	/*
-	 * Get the current number of ticks.  Note that there is a race
-	 * condition between us reading the timer and checking for
-	 * an interrupt.  We get around this by ensuring that the
-	 * counter has not reloaded between our two reads.
-	 */
-	ticks2 = readl(TIMER0_VA_BASE + TIMER_VALUE) & 0xffff;
-	do {
-		ticks1 = ticks2;
-		status = __raw_readl(VA_IC_BASE + VIC_RAW_STATUS);
-		ticks2 = readl(TIMER0_VA_BASE + TIMER_VALUE) & 0xffff;
-	} while (ticks2 > ticks1);
-
-	/*
-	 * Number of ticks since last interrupt.
-	 */
-	ticks1 = TIMER_RELOAD - ticks2;
-
-	/*
-	 * Interrupt pending?  If so, we've reloaded once already.
-	 *
-	 * FIXME: Need to check this is effectively timer 0 that expires
-	 */
-	if (status & IRQMASK_TIMERINT0_1)
-		ticks1 += TIMER_RELOAD;
-
-	/*
-	 * Convert the ticks to usecs
-	 */
-	return TICKS2USECS(ticks1);
-}
-
-/*
  * IRQ handler for the timer
  */
 static irqreturn_t versatile_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
@@ -917,5 +878,36 @@ static void __init versatile_timer_init(
 
 struct sys_timer versatile_timer = {
 	.init		= versatile_timer_init,
-	.offset		= versatile_gettimeoffset,
 };
+
+cycle_t versatile_get_cycles(void)
+{
+	return ~readl(TIMER3_VA_BASE + TIMER_VALUE);
+}
+
+static struct clocksource clocksource_versatile = {
+	.name 		= "timer3",
+	.rating		= 200,
+	.read		= versatile_get_cycles,
+	.mask		= 0xFFFFFFFF,
+	.shift 		= 10,
+	.is_continuous 	= 1,
+};
+
+static int __init versatile_clocksource_init(void)
+{
+	writel(0, TIMER3_VA_BASE + TIMER_CTRL);
+	writel(0xffffffff, TIMER3_VA_BASE + TIMER_LOAD);
+	writel(0xffffffff, TIMER3_VA_BASE + TIMER_VALUE);
+	writel(TIMER_CTRL_32BIT | TIMER_CTRL_ENABLE | TIMER_CTRL_PERIODIC,
+	       TIMER3_VA_BASE + TIMER_CTRL);
+
+	clocksource_versatile.mult =
+		clocksource_khz2mult(1000, clocksource_versatile.shift);
+	register_clocksource(&clocksource_versatile);
+
+	return 0;
+}
+
+device_initcall(versatile_clocksource_init);
+

--
Deepak Saxena - [email protected] - http://www.plexity.net

In the end, they will not say, "those were dark times," they will ask "why were their poets silent?" - Bertold Brecht

#4 lore raw

Re: [patch-rt 2/2] Add clocksource driver for Versatile board

Quoted 3 lines · On Mon, 2006-06-05 at 15:29 -0700, [email protected] wrote:

plain text document attachment (arm-versatile-hrt.patch) This patch adds a clocksource driver for the ARM versatile board, allowing it to use the generic time-of-day code.

Code looks good to me!

thanks
-john

#5 lore raw
In reply to [email protected]
Quoted 7 lines · On Mon, 2006-06-05 at 15:29 -0700, [email protected] wrote:

Hi,

This patchset (against -rt26, but should apply to newer patch) adds initial support for generic TOD on ARM. It is fairly simple and copletely rips out the existing TOD code in ARM, assuming that each sub-arch will either provide a clocksource or enable CONFIG_IS_TICK_BASED. Currently only Versatile is supported.

Ah! Looks cool! As a warning, -rt is still running w/ an older version of the TOD code (B20), so some changes will be needed when -rt moves to the current version (C2, right now).

The main change is that the read/sync persistent clock bits got cut, so the clock syncing is still necessary in timer_tick(). There might be a few other differences but most of the changes were arch-generic so it shouldn't be too much of an issue.

thanks
-john

#6 lore raw

On Jun 05 2006, at 16:06, john stultz was caught saying:

Quoted 9 lines · On Mon, 2006-06-05 at 15:29 -0700, [email protected] wrote:
Quoted 7 lines

Hi,

This patchset (against -rt26, but should apply to newer patch) adds initial support for generic TOD on ARM. It is fairly simple and copletely rips out the existing TOD code in ARM, assuming that each sub-arch will either provide a clocksource or enable CONFIG_IS_TICK_BASED. Currently only Versatile is supported.

Quoted 8 lines

Ah! Looks cool! As a warning, -rt is still running w/ an older version of the TOD code (B20), so some changes will be needed when -rt moves to the current version (C2, right now).

The main change is that the read/sync persistent clock bits got cut, so the clock syncing is still necessary in timer_tick(). There might be a few other differences but most of the changes were arch-generic so it shouldn't be too much of an issue.

OK, I'll keep my out for that. Actually, maybe I should send you a patch for latest TOD code. Are there any plans to just sync the persistent time updates with the generic RTC layer? It would require moving stuff like the CMOS clock code to drivers/rtc, but it would provide a generic solution.

Tnx,
~Deepak

Signature · 4 lines
Deepak Saxena - [email protected] - http://www.plexity.net

In the end, they will not say, "those were dark times,"  they will ask
"why were their poets silent?" - Bertold Brecht
#7 lore raw
Quoted 19 lines · Deepak Saxena

On Jun 05 2006, at 16:06, john stultz was caught saying:

Quoted 9 lines · On Mon, 2006-06-05 at 15:29 -0700, [email protected] wrote:
Quoted 7 lines

Hi,

This patchset (against -rt26, but should apply to newer patch) adds initial support for generic TOD on ARM. It is fairly simple and copletely rips out the existing TOD code in ARM, assuming that each sub-arch will either provide a clocksource or enable CONFIG_IS_TICK_BASED. Currently only Versatile is supported.

Quoted 8 lines

Ah! Looks cool! As a warning, -rt is still running w/ an older version of the TOD code (B20), so some changes will be needed when -rt moves to the current version (C2, right now).

The main change is that the read/sync persistent clock bits got cut, so the clock syncing is still necessary in timer_tick(). There might be a few other differences but most of the changes were arch-generic so it shouldn't be too much of an issue.

Quoted 5 lines

OK, I'll keep my out for that. Actually, maybe I should send you a patch for latest TOD code. Are there any plans to just sync the persistent time updates with the generic RTC layer? It would require moving stuff like the CMOS clock code to drivers/rtc, but it would provide a generic solution.

Hmmmm. I like that idea! I've been a bit too busy to look at the RTC changes in detail, but yes, it sounds like the way to go.

thanks!
-john

#8 lore raw
In reply to [email protected]
Quoted 5 lines · On Mon, 2006-06-05 at 15:29 -0700, [email protected] wrote:

patchset (against -rt26, but should apply to newer patch) adds initial support for generic TOD on ARM. It is fairly simple and copletely rips out the existing TOD code in ARM, assuming that each sub-arch will either provide a clocksource or enable CONFIG_IS_TICK_BASED. Currently only Versatile is supported.

And here's a patch on top of the ARM support which adds a clocksource for the ixp4xx platform.

Kevin

Add a clocksource driver for the Intel IXP4xx platform allowing it to use the generic time-of-day code.

arch/arm/mach-ixp4xx/common.c +28 -13
Index: ixp4xx/arch/arm/mach-ixp4xx/common.c
===================================================================
@@ -27,6 +27,7 @@
 #include <linux/bitops.h>
 #include <linux/time.h>
 #include <linux/timex.h>
+#include <linux/clocksource.h>
 
 #include <asm/hardware.h>
 #include <asm/uaccess.h>
@@ -253,16 +254,6 @@ static unsigned volatile last_jiffy_time
 
 #define CLOCK_TICKS_PER_USEC	((CLOCK_TICK_RATE + USEC_PER_SEC/2) / USEC_PER_SEC)
 
-/* IRQs are disabled before entering here from do_gettimeofday() */
-static unsigned long ixp4xx_gettimeoffset(void)
-{
-	u32 elapsed;
-
-	elapsed = *IXP4XX_OSTS - last_jiffy_time;
-
-	return elapsed / CLOCK_TICKS_PER_USEC;
-}
-
 static irqreturn_t ixp4xx_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
 {
 	write_seqlock(&xtime_lock);
@@ -297,8 +288,6 @@ static void __init ixp4xx_timer_init(voi
 	/* Setup the Timer counter value */
 	*IXP4XX_OSRT1 = (LATCH & ~IXP4XX_OST_RELOAD_MASK) | IXP4XX_OST_ENABLE;
 
-	/* Reset time-stamp counter */
-	*IXP4XX_OSTS = 0;
 	last_jiffy_time = 0;
 
 	/* Connect the interrupt handler and enable the interrupt */
@@ -307,7 +296,6 @@ static void __init ixp4xx_timer_init(voi
 
 struct sys_timer ixp4xx_timer = {
 	.init		= ixp4xx_timer_init,
-	.offset		= ixp4xx_gettimeoffset,
 };
 
 static struct resource ixp46x_i2c_resources[] = {
@@ -363,3 +351,30 @@ void __init ixp4xx_sys_init(void)
 			ixp4xx_exp_bus_size >> 20);
 }
 
+cycle_t ixp4xx_get_cycles(void)
+{
+	return *IXP4XX_OSTS;
+}
+
+static struct clocksource clocksource_ixp4xx = {
+	.name 		= "OSTS",
+	.rating		= 200,
+	.read		= ixp4xx_get_cycles,
+	.mask		= 0xFFFFFFFF,
+	.shift 		= 10,
+	.is_continuous 	= 1,
+};
+
+static int __init ixp4xx_clocksource_init(void)
+{
+	/* Reset time-stamp counter */
+	*IXP4XX_OSTS = 0;
+
+	clocksource_ixp4xx.mult =
+		clocksource_khz2mult(66660, clocksource_ixp4xx.shift);
+	register_clocksource(&clocksource_ixp4xx);
+
+	return 0;
+}
+
+device_initcall(ixp4xx_clocksource_init);