arch/ppc/kernel/time.c |   25 +++++++++++++++++++++++++
 include/asm-ppc/time.h |    8 ++++++++
 2 files changed, 33 insertions(+)

diff -puN arch/ppc/kernel/time.c~ppc-sched_clock arch/ppc/kernel/time.c
--- 25/arch/ppc/kernel/time.c~ppc-sched_clock	2003-08-05 17:28:24.000000000 -0700
+++ 25-akpm/arch/ppc/kernel/time.c	2003-08-05 17:28:24.000000000 -0700
@@ -83,6 +83,7 @@ time_t last_rtc_update;
 unsigned tb_ticks_per_jiffy;
 unsigned tb_to_us;
 unsigned tb_last_stamp;
+unsigned long tb_to_ns_scale;
 
 extern unsigned long wall_jiffies;
 
@@ -309,6 +310,7 @@ void __init time_init(void)
 		tb_to_us = 0x418937;
         } else {
                 ppc_md.calibrate_decr();
+		tb_to_ns_scale = mulhwu(tb_to_us, 1000 << 10);
 	}
 
 	/* Now that the decrementer is calibrated, it can be used in case the 
@@ -432,3 +434,26 @@ unsigned mulhwu_scale_factor(unsigned in
 	return mlt;
 }
 
+unsigned long long sched_clock(void)
+{
+	unsigned long lo, hi, hi2;
+	unsigned long long tb;
+
+	if (!__USE_RTC()) {
+		do {
+			hi = get_tbu();
+			lo = get_tbl();
+			hi2 = get_tbu();
+		} while (hi2 != hi);
+		tb = ((unsigned long long) hi << 32) | lo;
+		tb = (tb * tb_to_ns_scale) >> 10;
+	} else {
+		do {
+			hi = get_rtcu();
+			lo = get_rtcl();
+			hi2 = get_rtcu();
+		} while (hi2 != hi);
+		tb = ((unsigned long long) hi) * 1000000000 + lo;
+	}
+	return tb;
+}
diff -puN include/asm-ppc/time.h~ppc-sched_clock include/asm-ppc/time.h
--- 25/include/asm-ppc/time.h~ppc-sched_clock	2003-08-05 17:28:24.000000000 -0700
+++ 25-akpm/include/asm-ppc/time.h	2003-08-05 17:28:24.000000000 -0700
@@ -97,6 +97,13 @@ extern __inline__ unsigned long get_rtcl
 	return rtcl;
 }
 
+extern __inline__ unsigned long get_rtcu(void)
+{
+	unsigned long rtcu;
+	asm volatile("mfrtcu %0" : "=r" (rtcu));
+	return rtcu;
+}
+
 extern __inline__ unsigned get_native_tbl(void) {
 	if (__USE_RTC())
 		return get_rtcl();
@@ -140,6 +147,7 @@ extern __inline__ unsigned binary_tbl(vo
 #endif
 
 /* Use mulhwu to scale processor timebase to timeval */
+/* Specifically, this computes (x * y) / 2^32.  -- paulus */
 #define mulhwu(x,y) \
 ({unsigned z; asm ("mulhwu %0,%1,%2" : "=r" (z) : "r" (x), "r" (y)); z;})
 

_