Module: xenomai-3 Branch: master Commit: 5aabd25240c6dbb9e147210acdc3c3b2ae141388 URL: http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=5aabd25240c6dbb9e147210acdc3c3b2ae141388
Author: Philippe Gerum <[email protected]> Date: Fri Oct 23 18:49:36 2015 +0200 cobalt/timer: allow for changing the underlying clock source --- include/cobalt/kernel/timer.h | 10 +++++++++ kernel/cobalt/timer.c | 50 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 54 insertions(+), 6 deletions(-) diff --git a/include/cobalt/kernel/timer.h b/include/cobalt/kernel/timer.h index de35380..00aa411 100644 --- a/include/cobalt/kernel/timer.h +++ b/include/cobalt/kernel/timer.h @@ -23,6 +23,7 @@ #include <cobalt/kernel/clock.h> #include <cobalt/kernel/stat.h> #include <cobalt/kernel/list.h> +#include <cobalt/kernel/assert.h> #include <cobalt/kernel/ancillaries.h> #include <asm/xenomai/wrappers.h> @@ -257,6 +258,9 @@ static inline struct xnclock *xntimer_clock(struct xntimer *timer) return timer->clock; } +void xntimer_set_clock(struct xntimer *timer, + struct xnclock *newclock); + #else /* !CONFIG_XENO_OPT_EXTCLOCK */ static inline struct xnclock *xntimer_clock(struct xntimer *timer) @@ -264,6 +268,12 @@ static inline struct xnclock *xntimer_clock(struct xntimer *timer) return &nkclock; } +static inline void xntimer_set_clock(struct xntimer *timer, + struct xnclock *newclock) +{ + XENO_BUG_ON(COBALT, newclock != &nkclock); +} + #endif /* !CONFIG_XENO_OPT_EXTCLOCK */ #ifdef CONFIG_SMP diff --git a/kernel/cobalt/timer.c b/kernel/cobalt/timer.c index 9149730..bd986b6 100644 --- a/kernel/cobalt/timer.c +++ b/kernel/cobalt/timer.c @@ -391,15 +391,15 @@ void xntimer_set_gravity(struct xntimer *timer, int gravity) } EXPORT_SYMBOL_GPL(xntimer_set_gravity); -#if defined(CONFIG_XENO_OPT_EXTCLOCK) && defined(CONFIG_XENO_OPT_STATS) +#ifdef CONFIG_XENO_OPT_EXTCLOCK -void xntimer_switch_tracking(struct xntimer *timer, - struct xnclock *newclock) +#ifdef CONFIG_XENO_OPT_STATS + +static void __xntimer_switch_tracking(struct xntimer *timer, + struct xnclock *newclock) { struct xnclock *oldclock = timer->tracker; - spl_t s; - xnlock_get_irqsave(&nklock, s); list_del(&timer->next_stat); oldclock->nrtimers--; xnvfile_touch(&oldclock->timer_vfile); @@ -407,11 +407,49 @@ void xntimer_switch_tracking(struct xntimer *timer, newclock->nrtimers++; xnvfile_touch(&newclock->timer_vfile); timer->tracker = newclock; +} + +void xntimer_switch_tracking(struct xntimer *timer, + struct xnclock *newclock) +{ + spl_t s; + + xnlock_get_irqsave(&nklock, s); + __xntimer_switch_tracking(timer, newclock); xnlock_put_irqrestore(&nklock, s); } EXPORT_SYMBOL_GPL(xntimer_switch_tracking); -#endif /* CONFIG_XENO_OPT_EXTCLOCK && CONFIG_XENO_OPT_STATS */ +#else + +static inline +void __xntimer_switch_tracking(struct xntimer *timer, + struct xnclock *newclock) +{ } + +#endif /* CONFIG_XENO_OPT_STATS */ + +/** + * @brief Set the reference clock of a timer. + * + * This service changes the reference clock pacing a timer. If the + * clock timers are tracked, the tracking information is updated too. + * + * @param timer The address of a valid timer descriptor. + * + * @param newclock The address of a valid clock descriptor. + * + * @coretags{unrestricted, atomic-entry} + */ +void xntimer_set_clock(struct xntimer *timer, + struct xnclock *newclock) +{ + xntimer_stop(timer); + timer->clock = newclock; + __xntimer_switch_tracking(timer, newclock); +} + +#endif /* CONFIG_XENO_OPT_EXTCLOCK */ /** * @fn void xntimer_destroy(struct xntimer *timer) _______________________________________________ Xenomai-git mailing list [email protected] http://xenomai.org/mailman/listinfo/xenomai-git
