Convert clocksource to High Res Timer
RFC PATCH 1/1 Convert clocksource to High Res Timer
Update the clocksource code to use (higher priority) high-res-timers instead of a (lower priority) jiffies based timer.
This addresses some of the problems seen in Real-Time environments where a high priority user-space application consumes CPU time such that the TSC clocksource is starved and ultimately disabled due to "unstable clocksource" conditions being met. Converting the clocksource code to use hrtimers moves the dependence on lower priority softirqs to higher priority hrtimers, allowing the clocksource better stability.
This patch has been tested against 2.6.33.7-rt* patch series.
Signed-off-by Will Schmidt <[email protected]>
CC John Stultz <[email protected]>
CC Thomas Gleixner <[email protected]>
CC Paul Clarke <[email protected]>
--
kernel/time/clocksource.c +16 -9
@@ -181,7 +181,7 @@ static void clocksource_watchdog_work(struct work_struct *work);static LIST_HEAD (watchdog_list);static struct clocksource *watchdog; -static struct timer_list watchdog_timer; +static struct hrtimer hr_watchdog_timer; static DECLARE_WORK(watchdog_work, clocksource_watchdog_work);static DEFINE_SPINLOCK (watchdog_lock);static cycle_t watchdog_last;
@@ -195,6 +195,7 @@ static void __clocksource_change_rating(struct clocksource *cs, int rating);*/ #define WATCHDOG_INTERVAL (HZ >> 1)#define WATCHDOG_THRESHOLD (NSEC_PER_SEC >> 4) +#define HR_WATCHDOG_INTERVAL (NSEC_PER_SEC/2)static void clocksource_watchdog_work (struct work_struct *work) {
@@ -242,8 +243,9 @@ void clocksource_mark_unstable(struct clocksource *cs)spin_unlock_irqrestore (&watchdog_lock, flags); } -static void clocksource_watchdog (unsigned long data) +static enum hrtimer_restart clocksource_watchdog (unsigned long data) { +enum hrtimer_restart ret =HRTIMER_NORESTART ;struct clocksource *cs;cycle_t csnow, wdnow;int64_t wd_nsec, cs_nsec;
@@ -305,21 +307,26 @@ static void clocksource_watchdog(unsigned long data) next_cpu =cpumask_next (raw_smp_processor_id (), cpu_online_mask);if (next_cpu >= nr_cpu_ids) next_cpu =cpumask_first (cpu_online_mask); - watchdog_timer.expires +=WATCHDOG_INTERVAL ; -add_timer_on (&watchdog_timer, next_cpu); +hrtimer_add_expires (&hr_watchdog_timer,ktime_set (0 ,HR_WATCHDOG_INTERVAL )); + ret =HRTIMER_RESTART ; out:spin_unlock (&watchdog_lock); +return ret; }static inline void clocksource_start_watchdog (void ) { +ktime_t delta; +if (watchdog_running || !watchdog ||list_empty (&watchdog_list))return ; -init_timer (&watchdog_timer); - watchdog_timer.function = clocksource_watchdog; +hrtimer_init (&hr_watchdog_timer, +CLOCK_MONOTONIC ,HRTIMER_MODE_ABS ); + hr_watchdog_timer.function = clocksource_watchdog; watchdog_last = watchdog->read (watchdog); - watchdog_timer.expires = jiffies +WATCHDOG_INTERVAL ; -add_timer_on (&watchdog_timer,cpumask_first (cpu_online_mask)); + delta =ktime_set (0 ,HR_WATCHDOG_INTERVAL ); +hrtimer_start (&hr_watchdog_timer,ktime_add ( +ktime_get (), delta),HRTIMER_MODE_ABS ); watchdog_running =1 ; }
@@ -327,7 +334,7 @@ static inline void clocksource_stop_watchdog(void) {if (!watchdog_running || (watchdog && !list_empty (&watchdog_list)))return ; -del_timer (&watchdog_timer); +hrtimer_cancel (&hr_watchdog_timer); watchdog_running =0 ; }