Skip to contentSkip to conversation

Add clocksource_register_hz/khz interface (take3)

PATCH In review John Stultz 1 participant 2 messages May 8, 2010 – May 10, 2010 Timekeeping, clocksource core, NTP, alarmtimer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add clocksource_register_hz/khz interface (take3)

Thomas,

Ok, got rid of the code duplication. Let me know if you see any other issues with the interface.

thanks
-john

How to pick good mult/shif pairs has always been difficult to describe to folks writing clocksource drivers, since it requires careful tradeoffs in adjustment accuracy vs overflow limits.

Now, with the clocks_calc_mult_shift function, its much easier. However, not many clocksources have converted to using that function, and there is still the issue of the max interval length assumption being made by each clocksource driver independently.

So this patch simplifies the registration process by having clocksources be registered with a hz/khz value and the the registration function taking care of setting mult/shift.

This should take most of the confusion out of writing a clocksource driver.

Additionally it also keeps the shift size tradeoff (more accuracy vs longer possible nohz times) centralized so the timekeeping core can keep track of the assumptions being made.

CC Thomas Gleixner <[email protected]>
---
 include/linux/clocksource.h |   17 ++++++++++++++-
 kernel/time/clocksource.c   |   49 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 65 insertions(+), 1 deletions(-)
include/linux/clocksource.h +16 -1
index 4bca8b6..b6d80f0 100644
@@ -273,7 +273,6 @@ static inline s64 clocksource_cyc2ns(cycle_t cycles, u32 mult, u32 shift)
 }
 
 
-/* used to install a new clocksource */
 extern int clocksource_register(struct clocksource*);
 extern void clocksource_unregister(struct clocksource*);
 extern void clocksource_touch_watchdog(void);
@@ -287,6 +286,22 @@ extern void clocksource_mark_unstable(struct clocksource *cs);
 extern void
 clocks_calc_mult_shift(u32 *mult, u32 *shift, u32 from, u32 to, u32 minsec);
 
+/*
+ * Don't call __clocksource_register_scale directly, use
+ * clocksource_register_hz/khz
+ */
+extern int __clocksource_register_scale(struct clocksource *cs, u32 scale, u32 freq);
+static inline int clocksource_register_hz(struct clocksource* cs, u32 hz)
+{
+	return __clocksource_register_scale(cs, 1, hz);
+}
+
+static inline int clocksource_register_khz(struct clocksource* cs, u32 khz)
+{
+	return __clocksource_register_scale(cs, 1000, khz);
+}
+
+
 static inline void
 clocksource_calc_mult_shift(struct clocksource *cs, u32 freq, u32 minsec)
 {
kernel/time/clocksource.c +49 -0

55 lines not on this page · raw message

Signature · 1 line
1.6.0.4
#1 lore raw

[tip:timers/core] clocksource: Add clocksource_register_hz/khz interface

Commit-ID:  d7e81c269db899b800e0963dc4aceece1f82a680
Gitweb:     http://git.kernel.org/tip/d7e81c269db899b800e0963dc4aceece1f82a680
Author:     John Stultz <[email protected]>
AuthorDate: Fri, 7 May 2010 18:07:38 -0700
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Mon, 10 May 2010 14:24:26 +0200

clocksource: Add clocksource_register_hz/khz interface

How to pick good mult/shift pairs has always been difficult to describe to folks writing clocksource drivers, since it requires careful tradeoffs in adjustment accuracy vs overflow limits.

Now, with the clocks_calc_mult_shift function, its much easier. However, not many clocksources have converted to using that function, and there is still the issue of the max interval length assumption being made by each clocksource driver independently.

So this patch simplifies the registration process by having clocksources be registered with a hz/khz value and the registration function taking care of setting mult/shift.

This should take most of the confusion out of writing a clocksource driver.

Additionally it also keeps the shift size tradeoff (more accuracy vs longer possible nohz times) centralized so the timekeeping core can keep track of the assumptions being made.

[ tglx: Coding style and comments fixed ]

LKML-Reference: <[email protected]>

---
 include/linux/clocksource.h |   19 ++++++++++++++++-
 kernel/time/clocksource.c   |   48 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+), 1 deletions(-)
include/linux/clocksource.h +18 -1
index 4bca8b6..5ea3c60 100644
@@ -273,7 +273,6 @@ static inline s64 clocksource_cyc2ns(cycle_t cycles, u32 mult, u32 shift)
 }
 
 
-/* used to install a new clocksource */
 extern int clocksource_register(struct clocksource*);
 extern void clocksource_unregister(struct clocksource*);
 extern void clocksource_touch_watchdog(void);
@@ -287,6 +286,24 @@ extern void clocksource_mark_unstable(struct clocksource *cs);
 extern void
 clocks_calc_mult_shift(u32 *mult, u32 *shift, u32 from, u32 to, u32 minsec);
 
+/*
+ * Don't call __clocksource_register_scale directly, use
+ * clocksource_register_hz/khz
+ */
+extern int
+__clocksource_register_scale(struct clocksource *cs, u32 scale, u32 freq);
+
+static inline int clocksource_register_hz(struct clocksource *cs, u32 hz)
+{
+	return __clocksource_register_scale(cs, 1, hz);
+}
+
+static inline int clocksource_register_khz(struct clocksource *cs, u32 khz)
+{
+	return __clocksource_register_scale(cs, 1000, khz);
+}
+
+
 static inline void
 clocksource_calc_mult_shift(struct clocksource *cs, u32 freq, u32 minsec)
 {
kernel/time/clocksource.c +48 -0

54 lines not on this page · raw message