Skip to contentSkip to conversation

get time right for SMP machines

PATCH New Jun Sun 1 participant 1 message Jun 10, 2003 MIPS

lore
Share & tools
lore

Jun Sun

author
#0 lore raw

PATCH 1/1 get time right for SMP machines

Fixes a couple of things:

1) extend xtime_lock protection to cover do_timer() call (the same as in i386 arch). This enables other CPUs to use jiffie in a sane way.

2) It was not quite right to deliver ll_timer_interrupt() and ll_local_timer_interrupt() as two separate interrupts, because it may cause bottom half to execute ahead of the second interrupt.

3) for bcm1250, we now use zb bus counter for intra-jiffie offset. No more time running backward problem.

(TODO, I think I probably need to check the chip revision to make sure zb bus counter is there. Otherwise we can use null_gettimeoffset())

The patch should apply to 64bit and 2.5 as well. Comments?

Jun

arch/mips/kernel/time.c renamed from arch/mips/kernel/time.c.orig +10 -15
diff -Nru linux/arch/mips/kernel/time.c.orig linux/arch/mips/kernel/time.c
@@ -17,6 +17,7 @@
 #include <linux/sched.h>
 #include <linux/param.h>
 #include <linux/time.h>
+#include <linux/timer.h>
 #include <linux/smp.h>
 #include <linux/kernel_stat.h>
 #include <linux/spinlock.h>
@@ -79,7 +80,7 @@
 	 * is nonzero if the timer bottom half hasnt executed yet.
 	 */
 	if (jiffies - wall_jiffies)
-		tv->tv_usec += USECS_PER_JIFFY;
+		tv->tv_usec += USECS_PER_JIFFY * (jiffies - wall_jiffies);
 
 	read_unlock_irqrestore (&xtime_lock, flags);
 
@@ -344,7 +345,7 @@
 		count = read_c0_count();
 
 		/* check to see if we have missed any timer interrupts */
-		if ((count - expirelo) < 0x7fffffff) {
+		if (time_after(count, expirelo)) {
 			/* missed_timer_count ++; */
 			expirelo = count + cycles_per_jiffy;
 			write_c0_compare(expirelo);
@@ -355,6 +356,8 @@
 		timerlo = count;
 	}
 
+	write_lock (&xtime_lock);
+
 	/*
 	 * call the generic timer interrupt handling
 	 */
@@ -365,7 +368,6 @@
 	 * CMOS clock accordingly every ~11 minutes. rtc_set_time() has to be
 	 * called as close as possible to 500 ms before the new second starts.
 	 */
-	read_lock (&xtime_lock);
 	if ((time_status & STA_UNSYNC) == 0 &&
 	    xtime.tv_sec > last_rtc_update + 660 &&
 	    xtime.tv_usec >= 500000 - ((unsigned) tick) / 2 &&
@@ -377,7 +379,6 @@
 			/* do it again in 60 s */
 		}
 	}
-	read_unlock (&xtime_lock);
 
 	/*
 	 * If jiffies has overflowed in this timer_interrupt we must
@@ -388,26 +389,20 @@
 		timerhi = timerlo = 0;
 	}
 
-#if !defined(CONFIG_SMP)
+	write_unlock (&xtime_lock);
+
 	/*
-	 * In UP mode, we call local_timer_interrupt() to do profiling
-	 * and process accouting.
-	 *
-	 * In SMP mode, local_timer_interrupt() is invoked by appropriate
-	 * low-level local timer interrupt handler.
+	 * We call local_timer_interrupt() to do profiling and 
+	 * process accouting.
 	 */
 	local_timer_interrupt(0, NULL, regs);
 
-#else	/* CONFIG_SMP */
-
+#if defined(CONFIG_SMP)
 	if (emulate_local_timer_interrupt) {
 		/*
 		 * this is the place where we send out inter-process
 		 * interrupts and let each CPU do its own profiling
 		 * and process accouting.
-		 *
-		 * Obviously we need to call local_timer_interrupt() for
-		 * the current CPU too.
 		 */
 		panic("Not implemented yet!!!");
 	}
arch/mips/sibyte/sb1250/time.c renamed from arch/mips/sibyte/sb1250/time.c.orig +81 -14

143 lines not on this page · raw message