Skip to contentSkip to conversation

linux-2.5.66_monotonic-clock_A2

RFC PATCH New john stultz 1 participant 1 message Mar 26, 2003 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 linux-2.5.66_monotonic-clock_A2

All,
Here is the next rev of my monotonic-clock patch. Adds fixes to
insure atomicity when reading the cyclone register, as well as minor cleanups to the scaled math code. I plan on submitting this later this week if no major complaints are raised.

This patch, written with the advice of Joel Becker, addresses a
problem with the hangcheck-timer. The basic problem is that the hangcheck-timer code (Required for Oracle) needs a accurate hard clock which can be used to detect OS stalls (due to udelay() or pci bus hangs) that would cause system time to skew (its sort of a sanity check that insures the system's notion of time is accurate). However, currently they are using get_cycles() to fetch the cpu's TSC register, thus this does not work on systems w/o a synced TSC. As suggested by Andi Kleen (see thread here:
http://www.uwsg.iu.edu/hypermail/linux/kernel/0302.0/1234.html ) I've worked with Joel and others to implement the monotonic_clock() interface. Some of the major considerations made when writing this patch were:
o Needs to be able to return accurate time in the absence of multiple timer interrupts
o Needs to be abstracted out from the hardware
o Avoids impacting gettimeofday() performance

This interface returns a unsigned long long representing the number of nanoseconds that has passed since time_init().

Future plans to the interface include properly handling cpu_freq changes and porting to the different arches.

Comments, suggestions and flames welcome.

thanks
-john

arch/i386/kernel/time.c +13 -0
diff -Nru a/arch/i386/kernel/time.c b/arch/i386/kernel/time.c
@@ -138,6 +138,19 @@
 	clock_was_set();
 }
 
+unsigned long long monotonic_clock(void)
+{
+	unsigned long long ret;
+	unsigned long seq;
+	do {
+		seq = read_seqbegin(&xtime_lock);
+		ret = timer->monotonic_clock();
+	} while (read_seqretry(&xtime_lock, seq));
+	return ret;
+}
+EXPORT_SYMBOL(monotonic_clock);
+
+
 /*
  * In order to set the CMOS clock precisely, set_rtc_mmss has to be
  * called 500 ms after the second nowtime has started, because when
arch/i386/kernel/timers/timer_cyclone.c +36 -5

79 lines not on this page · raw message

arch/i386/kernel/timers/timer_none.c +6 -0
diff -Nru a/arch/i386/kernel/timers/timer_none.c b/arch/i386/kernel/timers/timer_none.c
@@ -15,6 +15,11 @@
 	return 0;
 }
 
+static unsigned long long monotonic_clock_none(void)
+{
+	return 0;
+}
+
 static void delay_none(unsigned long loops)
 {
 	int d0;
@@ -33,5 +38,6 @@
 	.init =		init_none, 
 	.mark_offset =	mark_offset_none, 
 	.get_offset =	get_offset_none,
+	.monotonic_clock =	monotonic_clock_none,
 	.delay = delay_none,
 };
arch/i386/kernel/timers/timer_pit.c +6 -0
diff -Nru a/arch/i386/kernel/timers/timer_pit.c b/arch/i386/kernel/timers/timer_pit.c
@@ -27,6 +27,11 @@
 	/* nothing needed */
 }
 
+static unsigned long long monotonic_clock_pit(void)
+{
+	return 0;
+}
+
 static void delay_pit(unsigned long loops)
 {
 	int d0;
@@ -141,5 +146,6 @@
 	.init =		init_pit, 
 	.mark_offset =	mark_offset_pit, 
 	.get_offset =	get_offset_pit,
+	.monotonic_clock = monotonic_clock_pit,
 	.delay = delay_pit,
 };
arch/i386/kernel/timers/timer_tsc.c +54 -1

95 lines not on this page · raw message

drivers/char/hangcheck-timer.c +7 -5
diff -Nru a/drivers/char/hangcheck-timer.c b/drivers/char/hangcheck-timer.c
@@ -78,11 +78,13 @@
 static struct timer_list hangcheck_ticktock =
 		TIMER_INITIALIZER(hangcheck_fire, 0, 0);
 
+extern unsigned long long monotonic_clock(void);
+
 static void hangcheck_fire(unsigned long data)
 {
 	unsigned long long cur_tsc, tsc_diff;
 
-	cur_tsc = get_cycles();
+	cur_tsc = monotonic_clock();
 
 	if (cur_tsc > hangcheck_tsc)
 		tsc_diff = cur_tsc - hangcheck_tsc;
@@ -98,7 +100,7 @@
 		}
 	}
 	mod_timer(&hangcheck_ticktock, jiffies + (hangcheck_tick*HZ));
-	hangcheck_tsc = get_cycles();
+	hangcheck_tsc = monotonic_clock();
 }
 
 
@@ -108,10 +110,10 @@
 	       VERSION_STR, hangcheck_tick, hangcheck_margin);
 
 	hangcheck_tsc_margin = hangcheck_margin + hangcheck_tick;
-	hangcheck_tsc_margin *= HZ;
-	hangcheck_tsc_margin *= current_cpu_data.loops_per_jiffy;
+	hangcheck_tsc_margin *= 1000000000;
+
 
-	hangcheck_tsc = get_cycles();
+	hangcheck_tsc = monotonic_clock();
 	mod_timer(&hangcheck_ticktock, jiffies + (hangcheck_tick*HZ));
 
 	return 0;
include/asm-i386/timer.h +1 -0
diff -Nru a/include/asm-i386/timer.h b/include/asm-i386/timer.h
@@ -14,6 +14,7 @@
 	int (*init)(void);
 	void (*mark_offset)(void);
 	unsigned long (*get_offset)(void);
+	unsigned long long (*monotonic_clock)(void);
 	void (*delay)(unsigned long);
 };