Skip to content

Commit 852db46

Browse files
John StultzKAGA-KOKO
authored andcommitted
clocksource: Add __clocksource_updatefreq_hz/khz methods
To properly handle clocksources that change frequencies at the clocksource->enable() point, this patch adds a method that will update the clocksource's mult/shift and max_idle_ns values. Signed-off-by: John Stultz <johnstul@us.ibm.com> LKML-Reference: <1279068988-21864-12-git-send-email-johnstul@us.ibm.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
1 parent f12a15b commit 852db46

2 files changed

Lines changed: 35 additions & 5 deletions

File tree

‎include/linux/clocksource.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@ clocks_calc_mult_shift(u32 *mult, u32 *shift, u32 from, u32 to, u32 minsec);
292292
*/
293293
extern int
294294
__clocksource_register_scale(struct clocksource *cs, u32 scale, u32 freq);
295+
extern void
296+
__clocksource_updatefreq_scale(struct clocksource *cs, u32 scale, u32 freq);
295297

296298
static inline int clocksource_register_hz(struct clocksource *cs, u32 hz)
297299
{
@@ -303,6 +305,15 @@ static inline int clocksource_register_khz(struct clocksource *cs, u32 khz)
303305
return __clocksource_register_scale(cs, 1000, khz);
304306
}
305307

308+
static inline void __clocksource_updatefreq_hz(struct clocksource *cs, u32 hz)
309+
{
310+
__clocksource_updatefreq_scale(cs, 1, hz);
311+
}
312+
313+
static inline void __clocksource_updatefreq_khz(struct clocksource *cs, u32 khz)
314+
{
315+
__clocksource_updatefreq_scale(cs, 1000, khz);
316+
}
306317

307318
static inline void
308319
clocksource_calc_mult_shift(struct clocksource *cs, u32 freq, u32 minsec)

‎kernel/time/clocksource.c‎

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -639,19 +639,18 @@ static void clocksource_enqueue(struct clocksource *cs)
639639
#define MAX_UPDATE_LENGTH 5 /* Seconds */
640640

641641
/**
642-
* __clocksource_register_scale - Used to install new clocksources
642+
* __clocksource_updatefreq_scale - Used update clocksource with new freq
643643
* @t: clocksource to be registered
644644
* @scale: Scale factor multiplied against freq to get clocksource hz
645645
* @freq: clocksource frequency (cycles per second) divided by scale
646646
*
647-
* Returns -EBUSY if registration fails, zero otherwise.
647+
* This should only be called from the clocksource->enable() method.
648648
*
649649
* This *SHOULD NOT* be called directly! Please use the
650-
* clocksource_register_hz() or clocksource_register_khz helper functions.
650+
* clocksource_updatefreq_hz() or clocksource_updatefreq_khz helper functions.
651651
*/
652-
int __clocksource_register_scale(struct clocksource *cs, u32 scale, u32 freq)
652+
void __clocksource_updatefreq_scale(struct clocksource *cs, u32 scale, u32 freq)
653653
{
654-
655654
/*
656655
* Ideally we want to use some of the limits used in
657656
* clocksource_max_deferment, to provide a more informed
@@ -662,7 +661,27 @@ int __clocksource_register_scale(struct clocksource *cs, u32 scale, u32 freq)
662661
NSEC_PER_SEC/scale,
663662
MAX_UPDATE_LENGTH*scale);
664663
cs->max_idle_ns = clocksource_max_deferment(cs);
664+
}
665+
EXPORT_SYMBOL_GPL(__clocksource_updatefreq_scale);
666+
667+
/**
668+
* __clocksource_register_scale - Used to install new clocksources
669+
* @t: clocksource to be registered
670+
* @scale: Scale factor multiplied against freq to get clocksource hz
671+
* @freq: clocksource frequency (cycles per second) divided by scale
672+
*
673+
* Returns -EBUSY if registration fails, zero otherwise.
674+
*
675+
* This *SHOULD NOT* be called directly! Please use the
676+
* clocksource_register_hz() or clocksource_register_khz helper functions.
677+
*/
678+
int __clocksource_register_scale(struct clocksource *cs, u32 scale, u32 freq)
679+
{
680+
681+
/* Intialize mult/shift and max_idle_ns */
682+
__clocksource_updatefreq_scale(cs, scale, freq);
665683

684+
/* Add clocksource to the clcoksource list */
666685
mutex_lock(&clocksource_mutex);
667686
clocksource_enqueue(cs);
668687
clocksource_select();

0 commit comments

Comments
 (0)