Skip to contentSkip to conversation

gettimeoffset for swarm

PATCH In review Jun Sun 2 participants 2 messages May 14, 2002 MIPS

lore
Share & tools
lore

Jun Sun

author
#0 lore raw

PATCH 1/1 gettimeoffset for swarm

By default, swarm will use calibrate_div64_gettimeoffset(). That does not work in SMP mode because the two cores have different counter register value. This patch gives swarm its own and accurate gettimeoffset().

The symptom without this patch is that cpu core 1 does not have micro-second resolution of gettimeofday().

It applies to 2.4 branch with 1 or 2 line offset warnings. It does not apply to 2.5 branch. 2.5 branch appears to be outdated.

http://linux.junsun.net/patches/oss.sgi.com/submitted/020515.swarm-own-gettimeoffset.patch

Jun

By default, swarm will use calibrate_div64_gettimeoffset(). That does not work in SMP mode because the two cores have different counter register value. This patch gives swarm its own and accurate gettimeoffset().

The symptom without this patch is that cpu core 1 does not have micro-second resolution of gettimeofday().

Jun

arch/mips/sibyte/sb1250/time.c renamed from arch/mips/sibyte/sb1250/time.c.orig +17 -0
diff -Nru linux/arch/mips/sibyte/sb1250/time.c.orig linux/arch/mips/sibyte/sb1250/time.c
@@ -34,6 +34,7 @@
 #include <asm/ptrace.h>
 #include <asm/addrspace.h>
 #include <asm/time.h>
+#include <asm/debug.h>
 
 #include <asm/sibyte/sb1250.h>
 #include <asm/sibyte/sb1250_regs.h>
@@ -107,3 +108,19 @@
 	 */
 	ll_local_timer_interrupt(0, regs);
 }
+
+/*
+ * We use our own do_gettimeoffset() instead of the generic one,
+ * because the generic one does not work for SMP case.
+ * In addition, since we use general timer 0 for system time,
+ * we can get accurate intra-jiffy offset without calibration.
+ */
+unsigned long sb1250_gettimeoffset(void)
+{
+	unsigned long count =
+		in64(KSEG1 + A_SCD_TIMER_REGISTER(0, R_SCD_TIMER_CNT));
+
+	db_assert(count <= 1000000 / HZ);
+	return 1000000/HZ - count;
+}
+
arch/mips/sibyte/swarm/setup.c renamed from arch/mips/sibyte/swarm/setup.c.orig +4 -1
diff -Nru linux/arch/mips/sibyte/swarm/setup.c.orig linux/arch/mips/sibyte/swarm/setup.c
@@ -237,12 +237,15 @@
          * interrupts through low-level (direct) meachanism.
          */
 
+	/* Use our own gettimeoffset() routine */
+	do_gettimeoffset = sb1250_gettimeoffset;
+
         /* We only need to setup the generic timer */
         sb1250_time_init();
 }
 
 extern int xicor_set_time(unsigned long);
-extern unsigned int xicor_get_time(void);
+extern unsigned long xicor_get_time(void);
 
 void __init swarm_setup(void)
 {
include/asm-mips/sibyte/sb1250.h renamed from include/asm-mips/sibyte/sb1250.h.orig +1 -0
diff -Nru linux/include/asm-mips/sibyte/sb1250.h.orig linux/include/asm-mips/sibyte/sb1250.h
@@ -20,6 +20,7 @@
 #define _ASM_SIBYTE_SB1250_H
 
 extern void sb1250_time_init(void);
+extern unsigned long sb1250_gettimeoffset(void);
 extern void sb1250_mask_irq(int cpu, int irq);
 extern void sb1250_unmask_irq(int cpu, int irq);
 extern void sb1250_smp_finish(void);
include/asm-mips64/sibyte/sb1250.h renamed from include/asm-mips64/sibyte/sb1250.h.orig +1 -0
diff -Nru linux/include/asm-mips64/sibyte/sb1250.h.orig linux/include/asm-mips64/sibyte/sb1250.h
@@ -20,6 +20,7 @@
 #define _ASM_SIBYTE_SB1250_H
 
 extern void sb1250_time_init(void);
+extern unsigned long sb1250_gettimeoffset(void);
 extern void sb1250_mask_irq(int cpu, int irq);
 extern void sb1250_unmask_irq(int cpu, int irq);
 extern void sb1250_smp_finish(void);
#1 lore raw
Quoted 3 lines · Jun Sun

By default, swarm will use calibrate_div64_gettimeoffset(). That does not work in SMP mode because the two cores have different counter register value. This patch gives swarm its own and accurate gettimeoffset().

You may consider synchronising the counters as it's done for the i386,
instead. See synchronize_tsc_ap(). It may be useful for other purposes as well.

Signature · 3 lines
+  Maciej W. Rozycki, Technical University of Gdansk, Poland   +
+--------------------------------------------------------------+
+        e-mail: [email protected], PGP key available        +