All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch 0/3] xtensa generic time
@ 2009-03-03 15:30 Johannes Weiner
  2009-03-03 15:30 ` [patch 1/3] xtensa: use generic sched_clock() Johannes Weiner
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Johannes Weiner @ 2009-03-03 15:30 UTC (permalink / raw)
  To: Chris Zankel; +Cc: linux-kernel

Hi,

here are three patches that convert the xtensa arch code to make use
of the generic time implementation.

The first one just removes xtensa's sched_clock() in order to use the
default implementation as it is the same thing.

The second one removes the platform-specific rtc get/set callbacks,
the interface is not really feasible for the generic time
implementation.  Currently, no platform implements this callback.
Platforms that want to should implement a rtc driver and
read_persistent_clock().

The third one converts xtensa to use generic time code by implementing
ccount as a clocksource.  This lets us get rid of xtensa-specific
gtod/stod as now the generic time code is used for that.

	Hannes

 arch/xtensa/Kconfig                |    3 +
 arch/xtensa/include/asm/platform.h |   11 ---
 arch/xtensa/kernel/platform.c      |    2 -
 arch/xtensa/kernel/time.c          |  120 +++++-------------------------------
 4 files changed, 19 insertions(+), 117 deletions(-)


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [patch 1/3] xtensa: use generic sched_clock()
  2009-03-03 15:30 [patch 0/3] xtensa generic time Johannes Weiner
@ 2009-03-03 15:30 ` Johannes Weiner
  2009-03-03 15:30 ` [patch 2/3] xtensa: remove platform rtc hooks Johannes Weiner
  2009-03-03 15:30 ` [patch 3/3] xtensa: ccount clocksource Johannes Weiner
  2 siblings, 0 replies; 8+ messages in thread
From: Johannes Weiner @ 2009-03-03 15:30 UTC (permalink / raw)
  To: Chris Zankel; +Cc: linux-kernel, Johannes Weiner

[-- Attachment #1: xtensa-generic-sched_clock.patch --]
[-- Type: text/plain, Size: 814 bytes --]

From: Johannes Weiner <hannes@cmpxchg.org>

Current xtensa implementation of sched_clock() is the same as the
generic one.  Just remove it, the weak symbol in kernel/sched_clock.c
will be used instead.

Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
---
 arch/xtensa/kernel/time.c |    9 ---------
 1 file changed, 9 deletions(-)

--- a/arch/xtensa/kernel/time.c
+++ b/arch/xtensa/kernel/time.c
@@ -37,15 +37,6 @@ unsigned long nsec_per_ccount;		/* nsec 
 
 static long last_rtc_update = 0;
 
-/*
- * Scheduler clock - returns current tim in nanosec units.
- */
-
-unsigned long long sched_clock(void)
-{
-	return (unsigned long long)jiffies * (1000000000 / HZ);
-}
-
 static irqreturn_t timer_interrupt(int irq, void *dev_id);
 static struct irqaction timer_irqaction = {
 	.handler =	timer_interrupt,

-- 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [patch 2/3] xtensa: remove platform rtc hooks
  2009-03-03 15:30 [patch 0/3] xtensa generic time Johannes Weiner
  2009-03-03 15:30 ` [patch 1/3] xtensa: use generic sched_clock() Johannes Weiner
@ 2009-03-03 15:30 ` Johannes Weiner
  2009-03-03 15:30 ` [patch 3/3] xtensa: ccount clocksource Johannes Weiner
  2 siblings, 0 replies; 8+ messages in thread
From: Johannes Weiner @ 2009-03-03 15:30 UTC (permalink / raw)
  To: Chris Zankel; +Cc: linux-kernel, Johannes Weiner

[-- Attachment #1: xtensa-remove-platform-rtc.patch --]
[-- Type: text/plain, Size: 3480 bytes --]

From: Johannes Weiner <hannes@cmpxchg.org>

platform_get/set_rtc_time() is not implemented by any of the supported
xtensa platforms.  Remove the facility completely.

The initial seconds for xtime come from read_persistent_clock() which
returns just 0 in the generic implementation.  Platforms that sport a
persistent clock can implement this function.

This is needed to implement the ccount register as a clock source.

Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
---
 arch/xtensa/include/asm/platform.h |   11 -----------
 arch/xtensa/kernel/platform.c      |    2 --
 arch/xtensa/kernel/time.c          |   29 +----------------------------
 3 files changed, 1 insertion(+), 41 deletions(-)

--- a/arch/xtensa/kernel/time.c
+++ b/arch/xtensa/kernel/time.c
@@ -14,7 +14,6 @@
 
 #include <linux/errno.h>
 #include <linux/time.h>
-#include <linux/timex.h>
 #include <linux/interrupt.h>
 #include <linux/module.h>
 #include <linux/init.h>
@@ -25,18 +24,11 @@
 #include <asm/timex.h>
 #include <asm/platform.h>
 
-
-DEFINE_SPINLOCK(rtc_lock);
-EXPORT_SYMBOL(rtc_lock);
-
-
 #ifdef CONFIG_XTENSA_CALIBRATE_CCOUNT
 unsigned long ccount_per_jiffy;		/* per 1/HZ */
 unsigned long nsec_per_ccount;		/* nsec per ccount increment */
 #endif
 
-static long last_rtc_update = 0;
-
 static irqreturn_t timer_interrupt(int irq, void *dev_id);
 static struct irqaction timer_irqaction = {
 	.handler =	timer_interrupt,
@@ -46,8 +38,6 @@ static struct irqaction timer_irqaction 
 
 void __init time_init(void)
 {
-	time_t sec_o, sec_n = 0;
-
 	/* The platform must provide a function to calibrate the processor
 	 * speed for the CALIBRATE.
 	 */
@@ -59,15 +49,8 @@ void __init time_init(void)
 			(int)(ccount_per_jiffy/(10000/HZ))%100);
 #endif
 
-	/* Set time from RTC (if provided) */
-
-	if (platform_get_rtc_time(&sec_o) == 0)
-		while (platform_get_rtc_time(&sec_n))
-			if (sec_o != sec_n)
-				break;
-
 	xtime.tv_nsec = 0;
-	last_rtc_update = xtime.tv_sec = sec_n;
+	xtime.tv_sec = read_persistent_clock();
 
 	set_normalized_timespec(&wall_to_monotonic,
 		-xtime.tv_sec, -xtime.tv_nsec);
@@ -169,16 +152,6 @@ again:
 		next += CCOUNT_PER_JIFFY;
 		set_linux_timer(next);
 
-		if (ntp_synced() &&
-		    xtime.tv_sec - last_rtc_update >= 659 &&
-		    abs((xtime.tv_nsec/1000)-(1000000-1000000/HZ))<5000000/HZ) {
-
-			if (platform_set_rtc_time(xtime.tv_sec+1) == 0)
-				last_rtc_update = xtime.tv_sec+1;
-			else
-				/* Do it again in 60 s */
-				last_rtc_update += 60;
-		}
 		write_sequnlock(&xtime_lock);
 	}
 
--- a/arch/xtensa/include/asm/platform.h
+++ b/arch/xtensa/include/asm/platform.h
@@ -74,16 +74,5 @@ extern int platform_pcibios_fixup (void)
  */
 extern void platform_calibrate_ccount (void);
 
-/*
- * platform_get_rtc_time returns RTC seconds (returns 0 for no error)
- */
-extern int platform_get_rtc_time(time_t*);
-
-/*
- * platform_set_rtc_time set RTC seconds (returns 0 for no error)
- */
-extern int platform_set_rtc_time(time_t);
-
-
 #endif	/* _XTENSA_PLATFORM_H */
 
--- a/arch/xtensa/kernel/platform.c
+++ b/arch/xtensa/kernel/platform.c
@@ -36,8 +36,6 @@ _F(void, power_off, (void), { while(1); 
 _F(void, idle, (void), { __asm__ __volatile__ ("waiti 0" ::: "memory"); });
 _F(void, heartbeat, (void), { });
 _F(int,  pcibios_fixup, (void), { return 0; });
-_F(int, get_rtc_time, (time_t* t), { return 0; });
-_F(int, set_rtc_time, (time_t t), { return 0; });
 
 #ifdef CONFIG_XTENSA_CALIBRATE_CCOUNT
 _F(void, calibrate_ccount, (void),

-- 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [patch 3/3] xtensa: ccount clocksource
  2009-03-03 15:30 [patch 0/3] xtensa generic time Johannes Weiner
  2009-03-03 15:30 ` [patch 1/3] xtensa: use generic sched_clock() Johannes Weiner
  2009-03-03 15:30 ` [patch 2/3] xtensa: remove platform rtc hooks Johannes Weiner
@ 2009-03-03 15:30 ` Johannes Weiner
  2009-03-03 17:55   ` Daniel Walker
  2 siblings, 1 reply; 8+ messages in thread
From: Johannes Weiner @ 2009-03-03 15:30 UTC (permalink / raw)
  To: Chris Zankel; +Cc: linux-kernel, Johannes Weiner

[-- Attachment #1: xtensa-ccount-clocksource.patch --]
[-- Type: text/plain, Size: 3877 bytes --]

From: Johannes Weiner <hannes@cmpxchg.org>

Switch to GENERIC_TIME by using the ccount register as a clock source.

Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
---
 arch/xtensa/Kconfig       |    3 +
 arch/xtensa/kernel/time.c |   92 ++++++++++------------------------------------
 2 files changed, 23 insertions(+), 72 deletions(-)

--- a/arch/xtensa/Kconfig
+++ b/arch/xtensa/Kconfig
@@ -45,6 +45,9 @@ config HZ
 	int
 	default 100
 
+config GENERIC_TIME
+	def_bool y
+
 source "init/Kconfig"
 source "kernel/Kconfig.freezer"
 
--- a/arch/xtensa/kernel/time.c
+++ b/arch/xtensa/kernel/time.c
@@ -14,6 +14,7 @@
 
 #include <linux/errno.h>
 #include <linux/time.h>
+#include <linux/clocksource.h>
 #include <linux/interrupt.h>
 #include <linux/module.h>
 #include <linux/init.h>
@@ -29,6 +30,19 @@ unsigned long ccount_per_jiffy;		/* per 
 unsigned long nsec_per_ccount;		/* nsec per ccount increment */
 #endif
 
+static cycle_t ccount_read(void)
+{
+	return (cycle_t)get_ccount();
+}
+
+static struct clocksource ccount_clocksource = {
+	.name = "ccount",
+	.rating = 200,
+	.read = ccount_read,
+	.mask = CLOCKSOURCE_MASK(32),
+	.mult = NSEC_PER_CCOUNT,
+};
+
 static irqreturn_t timer_interrupt(int irq, void *dev_id);
 static struct irqaction timer_irqaction = {
 	.handler =	timer_interrupt,
@@ -38,9 +52,11 @@ static struct irqaction timer_irqaction 
 
 void __init time_init(void)
 {
-	/* The platform must provide a function to calibrate the processor
-	 * speed for the CALIBRATE.
-	 */
+	xtime.tv_nsec = 0;
+	xtime.tv_sec = read_persistent_clock();
+
+	set_normalized_timespec(&wall_to_monotonic,
+		-xtime.tv_sec, -xtime.tv_nsec);
 
 #ifdef CONFIG_XTENSA_CALIBRATE_CCOUNT
 	printk("Calibrating CPU frequency ");
@@ -48,12 +64,7 @@ void __init time_init(void)
 	printk("%d.%02d MHz\n", (int)ccount_per_jiffy/(1000000/HZ),
 			(int)(ccount_per_jiffy/(10000/HZ))%100);
 #endif
-
-	xtime.tv_nsec = 0;
-	xtime.tv_sec = read_persistent_clock();
-
-	set_normalized_timespec(&wall_to_monotonic,
-		-xtime.tv_sec, -xtime.tv_nsec);
+	clocksource_register(&ccount_clocksource);
 
 	/* Initialize the linux timer interrupt. */
 
@@ -61,69 +72,6 @@ void __init time_init(void)
 	set_linux_timer(get_ccount() + CCOUNT_PER_JIFFY);
 }
 
-
-int do_settimeofday(struct timespec *tv)
-{
-	time_t wtm_sec, sec = tv->tv_sec;
-	long wtm_nsec, nsec = tv->tv_nsec;
-	unsigned long delta;
-
-	if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
-		return -EINVAL;
-
-	write_seqlock_irq(&xtime_lock);
-
-	/* This is revolting. We need to set "xtime" correctly. However, the
-	 * value in this location is the value at the most recent update of
-	 * wall time.  Discover what correction gettimeofday() would have
-	 * made, and then undo it!
-	 */
-
-	delta = CCOUNT_PER_JIFFY;
-	delta += get_ccount() - get_linux_timer();
-	nsec -= delta * NSEC_PER_CCOUNT;
-
-	wtm_sec  = wall_to_monotonic.tv_sec + (xtime.tv_sec - sec);
-	wtm_nsec = wall_to_monotonic.tv_nsec + (xtime.tv_nsec - nsec);
-
-	set_normalized_timespec(&xtime, sec, nsec);
-	set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
-
-	ntp_clear();
-	write_sequnlock_irq(&xtime_lock);
-	return 0;
-}
-
-EXPORT_SYMBOL(do_settimeofday);
-
-
-void do_gettimeofday(struct timeval *tv)
-{
-	unsigned long flags;
-	unsigned long volatile sec, usec, delta, seq;
-
-	do {
-		seq = read_seqbegin_irqsave(&xtime_lock, flags);
-
-		sec = xtime.tv_sec;
-		usec = (xtime.tv_nsec / NSEC_PER_USEC);
-
-		delta = get_linux_timer() - get_ccount();
-
-	} while (read_seqretry_irqrestore(&xtime_lock, seq, flags));
-
-	usec += (((unsigned long) CCOUNT_PER_JIFFY - delta)
-		 * (unsigned long) NSEC_PER_CCOUNT) / NSEC_PER_USEC;
-
-	for (; usec >= 1000000; sec++, usec -= 1000000)
-		;
-
-	tv->tv_sec = sec;
-	tv->tv_usec = usec;
-}
-
-EXPORT_SYMBOL(do_gettimeofday);
-
 /*
  * The timer interrupt is called HZ times per second.
  */

-- 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch 3/3] xtensa: ccount clocksource
  2009-03-03 15:30 ` [patch 3/3] xtensa: ccount clocksource Johannes Weiner
@ 2009-03-03 17:55   ` Daniel Walker
  2009-03-03 19:54     ` Johannes Weiner
  0 siblings, 1 reply; 8+ messages in thread
From: Daniel Walker @ 2009-03-03 17:55 UTC (permalink / raw)
  To: Johannes Weiner; +Cc: Chris Zankel, linux-kernel, Johannes Weiner

On Tue, 2009-03-03 at 16:30 +0100, Johannes Weiner wrote:
> @ -29,6 +30,19 @@ unsigned long ccount_per_jiffy;              /* per 
>  unsigned long nsec_per_ccount;         /* nsec per ccount increment
> */
>  #endif
>  
> +static cycle_t ccount_read(void)
> +{
> +       return (cycle_t)get_ccount();
> +}
> +
> +static struct clocksource ccount_clocksource = {
> +       .name = "ccount",
> +       .rating = 200,
> +       .read = ccount_read,
> +       .mask = CLOCKSOURCE_MASK(32),
> +       .mult = NSEC_PER_CCOUNT,
> +};

You don't want to use the shift field?

Daniel


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch 3/3] xtensa: ccount clocksource
  2009-03-03 17:55   ` Daniel Walker
@ 2009-03-03 19:54     ` Johannes Weiner
  2009-03-03 21:36       ` Daniel Walker
  0 siblings, 1 reply; 8+ messages in thread
From: Johannes Weiner @ 2009-03-03 19:54 UTC (permalink / raw)
  To: Daniel Walker; +Cc: Johannes Weiner, Chris Zankel, linux-kernel

On Tue, Mar 03, 2009 at 09:55:45AM -0800, Daniel Walker wrote:
> On Tue, 2009-03-03 at 16:30 +0100, Johannes Weiner wrote:
> > @ -29,6 +30,19 @@ unsigned long ccount_per_jiffy;              /* per 
> >  unsigned long nsec_per_ccount;         /* nsec per ccount increment
> > */
> >  #endif
> >  
> > +static cycle_t ccount_read(void)
> > +{
> > +       return (cycle_t)get_ccount();
> > +}
> > +
> > +static struct clocksource ccount_clocksource = {
> > +       .name = "ccount",
> > +       .rating = 200,
> > +       .read = ccount_read,
> > +       .mask = CLOCKSOURCE_MASK(32),
> > +       .mult = NSEC_PER_CCOUNT,
> > +};
> 
> You don't want to use the shift field?

Thanks for pointing it out.

To make sure I understood this:

If shift is 0, then a walltime adjustment would be done in 1/2^0
steps, meaning an adjustment of counting one nanosecond more or less
per ccount.

To give this a finer granularity and smooth out adjustments, the shift
should be a trade-off between too much adjustment and no adjustment
progress in a sane amount of time (and, of course, to stay within
bounds of the used type).

Does that make sense?

I found a patch of yours that introduced clocksource_hz2shift() but it
seems it hasn't been merged (yet).  Is it yet to get integrated?

Thanks in advance,

	Hannes

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch 3/3] xtensa: ccount clocksource
  2009-03-03 19:54     ` Johannes Weiner
@ 2009-03-03 21:36       ` Daniel Walker
  2009-03-04 20:26         ` Johannes Weiner
  0 siblings, 1 reply; 8+ messages in thread
From: Daniel Walker @ 2009-03-03 21:36 UTC (permalink / raw)
  To: Johannes Weiner; +Cc: Johannes Weiner, Chris Zankel, linux-kernel, John Stultz

On Tue, 2009-03-03 at 20:54 +0100, Johannes Weiner wrote:
> On Tue, Mar 03, 2009 at 09:55:45AM -0800, Daniel Walker wrote:
> > On Tue, 2009-03-03 at 16:30 +0100, Johannes Weiner wrote:
> > > @ -29,6 +30,19 @@ unsigned long ccount_per_jiffy;              /* per 
> > >  unsigned long nsec_per_ccount;         /* nsec per ccount increment
> > > */
> > >  #endif
> > >  
> > > +static cycle_t ccount_read(void)
> > > +{
> > > +       return (cycle_t)get_ccount();
> > > +}
> > > +
> > > +static struct clocksource ccount_clocksource = {
> > > +       .name = "ccount",
> > > +       .rating = 200,
> > > +       .read = ccount_read,
> > > +       .mask = CLOCKSOURCE_MASK(32),
> > > +       .mult = NSEC_PER_CCOUNT,
> > > +};
> > 
> > You don't want to use the shift field?
> 
> Thanks for pointing it out.
> 
> To make sure I understood this:
> 
> If shift is 0, then a walltime adjustment would be done in 1/2^0
> steps, meaning an adjustment of counting one nanosecond more or less
> per ccount.

The shift and mult are just used to convert your cycle counters current
count into nanoseconds .. I'm not sure how much a zero shift would
degrade the conversion to nanoseconds for your cycles counter tho. So it
could be along the lines of what your suggesting above.

> To give this a finer granularity and smooth out adjustments, the shift
> should be a trade-off between too much adjustment and no adjustment
> progress in a sane amount of time (and, of course, to stay within
> bounds of the used type).
> 
> Does that make sense?

I don't really look at it in terms of walltime adjustments. The actual
frequency of kernel time adjustments isn't defined in the clocksource
structure AFAIK. From my experience you just want the clocksource to
produce the most accurate nanosecond value your hardware can provide ,
which would mean setting the shift as high as is safe for your hardware.

I added John Stultz to the CC so he could comment further if he cares
too.

> I found a patch of yours that introduced clocksource_hz2shift() but it
> seems it hasn't been merged (yet).  Is it yet to get integrated?

I've been meaning to update it, but haven't gotten around to it. If you
know the input values you can run that function once just to produce a
shift which you define statically in the clocksource structure. Then use
that shift value with the other helper clocksource_hz2mult() to produce
a mult value.

Daniel


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch 3/3] xtensa: ccount clocksource
  2009-03-03 21:36       ` Daniel Walker
@ 2009-03-04 20:26         ` Johannes Weiner
  0 siblings, 0 replies; 8+ messages in thread
From: Johannes Weiner @ 2009-03-04 20:26 UTC (permalink / raw)
  To: Daniel Walker; +Cc: Johannes Weiner, Chris Zankel, linux-kernel, John Stultz

On Tue, Mar 03, 2009 at 01:36:04PM -0800, Daniel Walker wrote:
> On Tue, 2009-03-03 at 20:54 +0100, Johannes Weiner wrote:
> > On Tue, Mar 03, 2009 at 09:55:45AM -0800, Daniel Walker wrote:
> > > On Tue, 2009-03-03 at 16:30 +0100, Johannes Weiner wrote:
> > > > @ -29,6 +30,19 @@ unsigned long ccount_per_jiffy;              /* per 
> > > >  unsigned long nsec_per_ccount;         /* nsec per ccount increment
> > > > */
> > > >  #endif
> > > >  
> > > > +static cycle_t ccount_read(void)
> > > > +{
> > > > +       return (cycle_t)get_ccount();
> > > > +}
> > > > +
> > > > +static struct clocksource ccount_clocksource = {
> > > > +       .name = "ccount",
> > > > +       .rating = 200,
> > > > +       .read = ccount_read,
> > > > +       .mask = CLOCKSOURCE_MASK(32),
> > > > +       .mult = NSEC_PER_CCOUNT,
> > > > +};
> > > 
> > > You don't want to use the shift field?
> > 
> > Thanks for pointing it out.
> > 
> > To make sure I understood this:
> > 
> > If shift is 0, then a walltime adjustment would be done in 1/2^0
> > steps, meaning an adjustment of counting one nanosecond more or less
> > per ccount.
> 
> The shift and mult are just used to convert your cycle counters current
> count into nanoseconds .. I'm not sure how much a zero shift would
> degrade the conversion to nanoseconds for your cycles counter tho. So it
> could be along the lines of what your suggesting above.
> 
> > To give this a finer granularity and smooth out adjustments, the shift
> > should be a trade-off between too much adjustment and no adjustment
> > progress in a sane amount of time (and, of course, to stay within
> > bounds of the used type).
> > 
> > Does that make sense?
> 
> I don't really look at it in terms of walltime adjustments. The actual
> frequency of kernel time adjustments isn't defined in the clocksource
> structure AFAIK. From my experience you just want the clocksource to
> produce the most accurate nanosecond value your hardware can provide ,
> which would mean setting the shift as high as is safe for your hardware.
> 
> I added John Stultz to the CC so he could comment further if he cares
> too.
> 
> > I found a patch of yours that introduced clocksource_hz2shift() but it
> > seems it hasn't been merged (yet).  Is it yet to get integrated?
> 
> I've been meaning to update it, but haven't gotten around to it. If you
> know the input values you can run that function once just to produce a
> shift which you define statically in the clocksource structure. Then use
> that shift value with the other helper clocksource_hz2mult() to produce
> a mult value.

Ok, here is version 2.  The shift now limits the CPU clock to a
minimum of 1 MHz, comment in the code.  I think the trade-off should
be okay.  John?  Chris?

---
Subject: xtensa: ccount clocksource

From: Johannes Weiner <hannes@cmpxchg.org>

Switch to GENERIC_TIME by using the ccount register as a clock source.

Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
---
 arch/xtensa/Kconfig       |    3 +
 arch/xtensa/kernel/time.c |  103 +++++++++++++---------------------------------
 2 files changed, 33 insertions(+), 73 deletions(-)

--- a/arch/xtensa/Kconfig
+++ b/arch/xtensa/Kconfig
@@ -48,6 +48,9 @@ config HZ
 	int
 	default 100
 
+config GENERIC_TIME
+	def_bool y
+
 source "init/Kconfig"
 source "kernel/Kconfig.freezer"
 
--- a/arch/xtensa/kernel/time.c
+++ b/arch/xtensa/kernel/time.c
@@ -14,6 +14,7 @@
 
 #include <linux/errno.h>
 #include <linux/time.h>
+#include <linux/clocksource.h>
 #include <linux/interrupt.h>
 #include <linux/module.h>
 #include <linux/init.h>
@@ -29,6 +30,26 @@ unsigned long ccount_per_jiffy;		/* per 
 unsigned long nsec_per_ccount;		/* nsec per ccount increment */
 #endif
 
+static cycle_t ccount_read(void)
+{
+	return (cycle_t)get_ccount();
+}
+
+static struct clocksource ccount_clocksource = {
+	.name = "ccount",
+	.rating = 200,
+	.read = ccount_read,
+	.mask = CLOCKSOURCE_MASK(32),
+	/*
+	 * With a shift of 22 the lower limit of the cpu clock is
+	 * 1MHz, where NSEC_PER_CCOUNT is 1000 or a bit less than
+	 * 2^10: Since we have 32 bits and the multiplicator can
+	 * already take up as much as 10 bits, this leaves us with
+	 * remaining upper 22 bits.
+	 */
+	.shift = 22,
+};
+
 static irqreturn_t timer_interrupt(int irq, void *dev_id);
 static struct irqaction timer_irqaction = {
 	.handler =	timer_interrupt,
@@ -38,9 +59,11 @@ static struct irqaction timer_irqaction 
 
 void __init time_init(void)
 {
-	/* The platform must provide a function to calibrate the processor
-	 * speed for the CALIBRATE.
-	 */
+	xtime.tv_nsec = 0;
+	xtime.tv_sec = read_persistent_clock();
+
+	set_normalized_timespec(&wall_to_monotonic,
+		-xtime.tv_sec, -xtime.tv_nsec);
 
 #ifdef CONFIG_XTENSA_CALIBRATE_CCOUNT
 	printk("Calibrating CPU frequency ");
@@ -48,12 +71,10 @@ void __init time_init(void)
 	printk("%d.%02d MHz\n", (int)ccount_per_jiffy/(1000000/HZ),
 			(int)(ccount_per_jiffy/(10000/HZ))%100);
 #endif
-
-	xtime.tv_nsec = 0;
-	xtime.tv_sec = read_persistent_clock();
-
-	set_normalized_timespec(&wall_to_monotonic,
-		-xtime.tv_sec, -xtime.tv_nsec);
+	ccount_clocksource.mult =
+		clocksource_hz2mult(CCOUNT_PER_JIFFY * HZ,
+				ccount_clocksource.shift);
+	clocksource_register(&ccount_clocksource);
 
 	/* Initialize the linux timer interrupt. */
 
@@ -61,69 +82,6 @@ void __init time_init(void)
 	set_linux_timer(get_ccount() + CCOUNT_PER_JIFFY);
 }
 
-
-int do_settimeofday(struct timespec *tv)
-{
-	time_t wtm_sec, sec = tv->tv_sec;
-	long wtm_nsec, nsec = tv->tv_nsec;
-	unsigned long delta;
-
-	if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
-		return -EINVAL;
-
-	write_seqlock_irq(&xtime_lock);
-
-	/* This is revolting. We need to set "xtime" correctly. However, the
-	 * value in this location is the value at the most recent update of
-	 * wall time.  Discover what correction gettimeofday() would have
-	 * made, and then undo it!
-	 */
-
-	delta = CCOUNT_PER_JIFFY;
-	delta += get_ccount() - get_linux_timer();
-	nsec -= delta * NSEC_PER_CCOUNT;
-
-	wtm_sec  = wall_to_monotonic.tv_sec + (xtime.tv_sec - sec);
-	wtm_nsec = wall_to_monotonic.tv_nsec + (xtime.tv_nsec - nsec);
-
-	set_normalized_timespec(&xtime, sec, nsec);
-	set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
-
-	ntp_clear();
-	write_sequnlock_irq(&xtime_lock);
-	return 0;
-}
-
-EXPORT_SYMBOL(do_settimeofday);
-
-
-void do_gettimeofday(struct timeval *tv)
-{
-	unsigned long flags;
-	unsigned long volatile sec, usec, delta, seq;
-
-	do {
-		seq = read_seqbegin_irqsave(&xtime_lock, flags);
-
-		sec = xtime.tv_sec;
-		usec = (xtime.tv_nsec / NSEC_PER_USEC);
-
-		delta = get_linux_timer() - get_ccount();
-
-	} while (read_seqretry_irqrestore(&xtime_lock, seq, flags));
-
-	usec += (((unsigned long) CCOUNT_PER_JIFFY - delta)
-		 * (unsigned long) NSEC_PER_CCOUNT) / NSEC_PER_USEC;
-
-	for (; usec >= 1000000; sec++, usec -= 1000000)
-		;
-
-	tv->tv_sec = sec;
-	tv->tv_usec = usec;
-}
-
-EXPORT_SYMBOL(do_gettimeofday);
-
 /*
  * The timer interrupt is called HZ times per second.
  */
@@ -177,4 +135,3 @@ void __cpuinit calibrate_delay(void)
 	       (loops_per_jiffy/(10000/HZ)) % 100);
 }
 #endif
-

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2009-03-04 20:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-03 15:30 [patch 0/3] xtensa generic time Johannes Weiner
2009-03-03 15:30 ` [patch 1/3] xtensa: use generic sched_clock() Johannes Weiner
2009-03-03 15:30 ` [patch 2/3] xtensa: remove platform rtc hooks Johannes Weiner
2009-03-03 15:30 ` [patch 3/3] xtensa: ccount clocksource Johannes Weiner
2009-03-03 17:55   ` Daniel Walker
2009-03-03 19:54     ` Johannes Weiner
2009-03-03 21:36       ` Daniel Walker
2009-03-04 20:26         ` Johannes Weiner

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.