Re: [PATCH v2 2/4] Implement generic time of day clocksource for powerpc machines.

2007-09-21 Thread Tony Breeds
On Fri, Sep 21, 2007 at 02:52:12PM +1000, Stephen Rothwell wrote:
> Small comments.

Thanks.

> I think this is redundant as if __USE_RTC() is true, you register
> clocksource_rtc below.

Yup you're right.

> The #ifdef is redundant since if CONFIG_ISERIES is not set,
> firmware_has_feature(FW_FEATURE_ISERIES) is constant 0.

Ahh okay.  I got too fancy for my own good.

patch comming.

Yours Tony

  linux.conf.auhttp://linux.conf.au/ || http://lca2008.linux.org.au/
  Jan 28 - Feb 02 2008 The Australian Linux Technical Conference!

___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev


Re: [PATCH v2 2/4] Implement generic time of day clocksource for powerpc machines.

2007-09-20 Thread David Gibson
On Fri, Sep 21, 2007 at 02:59:31PM +1000, Paul Mackerras wrote:
> Daniel Walker writes:
> 
> > I don't think the RTC frequency isn't the same as the timebase? Seems
> > like the RTC only case about seconds at the lowest level. If that's the
> > case then the jiffies clock might be better to use .. The other thing I
> > wonder is if the __USE_RTC boards might have lower level clocks that
> > could be used instead ..
> 
> It's OK, the RTC isn't what you think it is, it's a pair of
> CPU-internal registers which count seconds and nanoseconds.  On
> processors with the RTC, tb_ticks_per_sec is initialized to
> 10.  Trust me, this code is OK. :)

Indeed..  I'm wondering if we should do a s/rtc/ppc601rtc/ or
something.  Otherwise people will keep making this mistake and be
confused.

-- 
David Gibson| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev


Re: [PATCH v2 2/4] Implement generic time of day clocksource for powerpc machines.

2007-09-20 Thread Paul Mackerras
Daniel Walker writes:

> I don't think the RTC frequency isn't the same as the timebase? Seems
> like the RTC only case about seconds at the lowest level. If that's the
> case then the jiffies clock might be better to use .. The other thing I
> wonder is if the __USE_RTC boards might have lower level clocks that
> could be used instead ..

It's OK, the RTC isn't what you think it is, it's a pair of
CPU-internal registers which count seconds and nanoseconds.  On
processors with the RTC, tb_ticks_per_sec is initialized to
10.  Trust me, this code is OK. :)

Paul.
___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev


Re: [PATCH v2 2/4] Implement generic time of day clocksource for powerpc machines.

2007-09-20 Thread Stephen Rothwell
Small comments.

On Fri, 21 Sep 2007 13:26:02 +1000 Tony Breeds <[EMAIL PROTECTED]> wrote:
>
> +void update_vsyscall(struct timespec *wall_time, struct clocksource *clock)
> +{
> + u64 t2x, stamp_xsec;
> +
> + if (__USE_RTC() || clock != &clocksource_timebase)
^^^
I think this is redundant as if __USE_RTC() is true, you register
clocksource_rtc below.

> +#ifdef CONFIG_ISERIES
> + if (!firmware_has_feature(FW_FEATURE_ISERIES))
> +#endif

The #ifdef is redundant since if CONFIG_ISERIES is not set,
firmware_has_feature(FW_FEATURE_ISERIES) is constant 0.

-- 
Cheers,
Stephen Rothwell[EMAIL PROTECTED]
http://www.canb.auug.org.au/~sfr/


pgpOMZm3Ny9ey.pgp
Description: PGP signature
___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev

Re: [PATCH v2 2/4] Implement generic time of day clocksource for powerpc machines.

2007-09-20 Thread Daniel Walker
On Fri, 2007-09-21 at 13:26 +1000, Tony Breeds wrote:
> +
> +   if (__USE_RTC())
> +   clock = &clocksource_rtc;
> +   else
> +   clock = &clocksource_timebase;
> +
> +   clock->mult = clocksource_hz2mult(tb_ticks_per_sec,
> clock->shift);

I don't think the RTC frequency isn't the same as the timebase? Seems
like the RTC only case about seconds at the lowest level. If that's the
case then the jiffies clock might be better to use .. The other thing I
wonder is if the __USE_RTC boards might have lower level clocks that
could be used instead ..

Daniel

___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev


[PATCH v2 2/4] Implement generic time of day clocksource for powerpc machines.

2007-09-20 Thread Tony Breeds
Signed-off-by: Tony Breeds <[EMAIL PROTECTED]>

---

Updated to create a clocksource driver specific to the 601

 arch/powerpc/Kconfig   |6 
 arch/powerpc/kernel/time.c |  255 -
 2 files changed, 91 insertions(+), 170 deletions(-)

Index: working/arch/powerpc/Kconfig
===
--- working.orig/arch/powerpc/Kconfig
+++ working/arch/powerpc/Kconfig
@@ -24,6 +24,12 @@ config MMU
 config GENERIC_CMOS_UPDATE
def_bool y
 
+config GENERIC_TIME
+   def_bool y
+
+config GENERIC_TIME_VSYSCALL
+   def_bool y
+
 config GENERIC_HARDIRQS
bool
default y
Index: working/arch/powerpc/kernel/time.c
===
--- working.orig/arch/powerpc/kernel/time.c
+++ working/arch/powerpc/kernel/time.c
@@ -73,9 +73,38 @@
 #include 
 #endif
 
+/* powerpc clocksource/clockevent code */
+
+#include 
+
+static cycle_t rtc_read(void);
+static struct clocksource clocksource_rtc = {
+   .name = "rtc",
+   .rating   = 400,
+   .flags= CLOCK_SOURCE_IS_CONTINUOUS,
+   .mask = CLOCKSOURCE_MASK(64),
+   .shift= 22,
+   .mult = 0,  /* To be filled in */
+   .read = rtc_read,
+};
+
+static cycle_t timebase_read(void);
+static struct clocksource clocksource_timebase = {
+   .name = "timebase",
+   .rating   = 400,
+   .flags= CLOCK_SOURCE_IS_CONTINUOUS,
+   .mask = CLOCKSOURCE_MASK(64),
+   .shift= 22,
+   .mult = 0,  /* To be filled in */
+   .read = timebase_read,
+};
+
 #ifdef CONFIG_PPC_ISERIES
 static unsigned long __initdata iSeries_recal_titan;
 static signed long __initdata iSeries_recal_tb;
+
+/* Forward declaration is only needed for iSereis compiles */
+void __init clocksource_init(void);
 #endif
 
 #define XSEC_PER_SEC (1024*1024)
@@ -343,65 +372,6 @@ void udelay(unsigned long usecs)
 }
 EXPORT_SYMBOL(udelay);
 
-/*
- * This version of gettimeofday has microsecond resolution.
- */
-static inline void __do_gettimeofday(struct timeval *tv)
-{
-   unsigned long sec, usec;
-   u64 tb_ticks, xsec;
-   struct gettimeofday_vars *temp_varp;
-   u64 temp_tb_to_xs, temp_stamp_xsec;
-
-   /*
-* These calculations are faster (gets rid of divides)
-* if done in units of 1/2^20 rather than microseconds.
-* The conversion to microseconds at the end is done
-* without a divide (and in fact, without a multiply)
-*/
-   temp_varp = do_gtod.varp;
-
-   /* Sampling the time base must be done after loading
-* do_gtod.varp in order to avoid racing with update_gtod.
-*/
-   data_barrier(temp_varp);
-   tb_ticks = get_tb() - temp_varp->tb_orig_stamp;
-   temp_tb_to_xs = temp_varp->tb_to_xs;
-   temp_stamp_xsec = temp_varp->stamp_xsec;
-   xsec = temp_stamp_xsec + mulhdu(tb_ticks, temp_tb_to_xs);
-   sec = xsec / XSEC_PER_SEC;
-   usec = (unsigned long)xsec & (XSEC_PER_SEC - 1);
-   usec = SCALE_XSEC(usec, 100);
-
-   tv->tv_sec = sec;
-   tv->tv_usec = usec;
-}
-
-void do_gettimeofday(struct timeval *tv)
-{
-   if (__USE_RTC()) {
-   /* do this the old way */
-   unsigned long flags, seq;
-   unsigned int sec, nsec, usec;
-
-   do {
-   seq = read_seqbegin_irqsave(&xtime_lock, flags);
-   sec = xtime.tv_sec;
-   nsec = xtime.tv_nsec + tb_ticks_since(tb_last_jiffy);
-   } while (read_seqretry_irqrestore(&xtime_lock, seq, flags));
-   usec = nsec / 1000;
-   while (usec >= 100) {
-   usec -= 100;
-   ++sec;
-   }
-   tv->tv_sec = sec;
-   tv->tv_usec = usec;
-   return;
-   }
-   __do_gettimeofday(tv);
-}
-
-EXPORT_SYMBOL(do_gettimeofday);
 
 /*
  * There are two copies of tb_to_xs and stamp_xsec so that no
@@ -447,56 +417,6 @@ static inline void update_gtod(u64 new_t
++(vdso_data->tb_update_count);
 }
 
-/*
- * When the timebase - tb_orig_stamp gets too big, we do a manipulation
- * between tb_orig_stamp and stamp_xsec. The goal here is to keep the
- * difference tb - tb_orig_stamp small enough to always fit inside a
- * 32 bits number. This is a requirement of our fast 32 bits userland
- * implementation in the vdso. If we "miss" a call to this function
- * (interrupt latency, CPU locked in a spinlock, ...) and we end up
- * with a too big difference, then the vdso will fallback to calling
- * the syscall
- */
-static __inline__ void timer_recalc_offset(u64 cur_tb)
-{
-   unsigned long offset;
-   u64 new_stamp_xsec;
-   u64 tlen, t2x;
-   u64 tb, xsec_old, xsec_new;
-   struct gettimeofday_vars *varp;
-
-