Skip to contentSkip to conversation

export clocksource resolution (experimental)

RFC PATCH New john stultz 1 participant 1 message Mar 4, 2006

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 export clocksource resolution (experimental)

Hey Thomas,
Earlier there was some discussion of trying to export the clocksource
resolution so it could be used to make sure we don't expire hrtimers early. I scratched out this first pass patch to provide an interface to do so. Let me know if this was similar to what you were thinking of.

thanks
-john

 include/linux/timeofday.h |    1 +
 kernel/time/timeofday.c   |   18 ++++++++++++++++++
 2 files changed, 19 insertions(+)

linux-2.6.16-rc5_timeofday-clocksource-resolution_B20.patch
============================================

include/linux/timeofday.h +1 -0
index 5222c4c..fb47e82 100644
@@ -30,6 +30,7 @@ extern int do_settimeofday(struct timesp
 
 /* Internal functions */
 extern int timeofday_is_continuous(void);
+extern u32 timeofday_get_clockres(void);
 extern void timeofday_init(void);
 
 #ifndef CONFIG_IS_TICK_BASED
kernel/time/timeofday.c +18 -0
index 8085b86..5d1d6e4 100644
@@ -650,6 +650,24 @@ int timeofday_is_continuous(void)
 }
 
 /**
+ * timeofday_get_clockres - returns the underlying clocksource's resolution
+ */
+u32 timeofday_get_clockres(void)
+{
+	unsigned long seq;
+	u32 res;
+	do {
+		seq = read_seqbegin(&system_time_lock);
+
+		/* take one cycle -> N+1 nsecs */
+		res = cyc2ns(clock, 0, 1) + 1;
+
+	} while (read_seqretry(&system_time_lock, seq));
+
+	return res;
+}
+
+/**
  * timeofday_init - Initializes time variables
  */
 void __init timeofday_init(void)