[Xenomai-git] Philippe Gerum : copperplate/clockobj, alchemy: sanitize clockobj_get_time () interface
Module: xenomai-forge Branch: master Commit: 3d43735528324673626b306f6bb40b42cd5abed6 URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=3d43735528324673626b306f6bb40b42cd5abed6 Author: Philippe Gerum Date: Wed Sep 24 12:10:08 2014 +0200 copperplate/clockobj, alchemy: sanitize clockobj_get_time() interface --- include/alchemy/timer.h| 19 + include/copperplate/clockobj.h |3 +-- lib/alchemy/task.c |2 +- lib/alchemy/timer.c| 26 ++- lib/copperplate/clockobj.c | 46 5 files changed, 37 insertions(+), 59 deletions(-) diff --git a/include/alchemy/timer.h b/include/alchemy/timer.h index c85d80f..fc33db9 100644 --- a/include/alchemy/timer.h +++ b/include/alchemy/timer.h @@ -99,6 +99,25 @@ int alchemy_poll_mode(const struct timespec *abs_timeout) extern "C" { #endif +/** + * @fn RTIME rt_timer_read(void) + * @brief Return the current system time. + * + * Return the current time maintained by the Xenomai core clock. + * + * @return The current time expressed in clock ticks (see note). + * + * @apitags{unrestricted} + * + * @note The @a time value is a multiple of the Alchemy clock + * resolution (see --alchemy-clock-resolution option, defaults to 1 + * nanosecond). + */ +static inline RTIME rt_timer_read(void) +{ + return clockobj_get_time(&alchemy_clock); +} + static inline RTIME rt_timer_tsc(void) { return clockobj_get_tsc(); diff --git a/include/copperplate/clockobj.h b/include/copperplate/clockobj.h index 1543589..f480214 100644 --- a/include/copperplate/clockobj.h +++ b/include/copperplate/clockobj.h @@ -71,8 +71,7 @@ void clockobj_set_date(struct clockobj *clkobj, ticks_t ticks); void clockobj_get_date(struct clockobj *clkobj, ticks_t *pticks); -void clockobj_get_time(struct clockobj *clkobj, - ticks_t *pticks, ticks_t *ptsc); +ticks_t clockobj_get_time(struct clockobj *clkobj); void clockobj_get_distance(struct clockobj *clkobj, const struct itimerspec *itm, diff --git a/lib/alchemy/task.c b/lib/alchemy/task.c index bd309c9..c9ec272 100644 --- a/lib/alchemy/task.c +++ b/lib/alchemy/task.c @@ -959,7 +959,7 @@ int rt_task_sleep_until(RTIME date) if (date == TM_INFINITE) ts = zero_time; else { - clockobj_get_time(&alchemy_clock, &now, NULL); + now = clockobj_get_time(&alchemy_clock); if (date <= now) return -ETIMEDOUT; CANCEL_DEFER(svc); diff --git a/lib/alchemy/timer.c b/lib/alchemy/timer.c index dfe4f6d..323273c 100644 --- a/lib/alchemy/timer.c +++ b/lib/alchemy/timer.c @@ -31,29 +31,6 @@ struct clockobj alchemy_clock; /** - * @fn RTIME rt_timer_read(void) - * @brief Return the current system time. - * - * Return the current time maintained by the Xenomai core clock. - * - * @return The current time expressed in clock ticks (see note). - * - * @apitags{unrestricted} - * - * @note The @a time value is a multiple of the Alchemy clock - * resolution (see --alchemy-clock-resolution option, defaults to 1 - * nanosecond). - */ -RTIME rt_timer_read(void) -{ - ticks_t ticks; - - clockobj_get_time(&alchemy_clock, &ticks, NULL); - - return ticks; -} - -/** * @fn RTIME rt_timer_ns2ticks(SRTIME ns) * @brief Convert nanoseconds to Alchemy clock ticks. * @@ -113,7 +90,8 @@ SRTIME rt_timer_ticks2ns(SRTIME ticks) int rt_timer_inquire(RT_TIMER_INFO *info) { info->period = clockobj_get_resolution(&alchemy_clock); - clockobj_get_time(&alchemy_clock, &info->date, &info->tsc); + info->date = clockobj_get_time(&alchemy_clock); + info->tsc = clockobj_get_tsc(); return 0; } diff --git a/lib/copperplate/clockobj.c b/lib/copperplate/clockobj.c index 1b6f5f6..8ee3ed7 100644 --- a/lib/copperplate/clockobj.c +++ b/lib/copperplate/clockobj.c @@ -237,21 +237,18 @@ ticks_t clockobj_get_tsc(void) { struct timespec now; - /* Rare case with legacy uClibc+linuxthreads combo. */ + /* +* Rare case with legacy uClibc+linuxthreads combo over +* Cobalt, we actually return nanoseconds just like in the +* Mercury case. +*/ __RT(clock_gettime(CLOCK_REALTIME, &now)); return xnarch_ullmul(now.tv_sec, 10) + now.tv_nsec; } -void clockobj_get_time(struct clockobj *clkobj, - ticks_t *pticks, ticks_t *ptsc) +ticks_t clockobj_get_time(struct clockobj *clkobj) { - ticks_t ns; - - ns = clockobj_get_tsc(); - if (ptsc) - *ptsc = ns; - - *pticks = clockobj_ns_to_ticks(clkobj, ns); + return clockobj_ns_to_ticks(clkobj, clockobj_get_tsc()); } #else /* !CONFIG_XENO_COPPERPLATE_CLOCK_RESTRICTED */ @@ -266,17 +263,10 @@ ticks_t clockobj_get_tsc(void) return cobalt_read_tsc(); } -void clockobj_get_time(struc
[Xenomai-git] Philippe Gerum : copperplate/clockobj, alchemy: sanitize clockobj_get_time () interface
Module: xenomai-forge Branch: next Commit: 3d43735528324673626b306f6bb40b42cd5abed6 URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=3d43735528324673626b306f6bb40b42cd5abed6 Author: Philippe Gerum Date: Wed Sep 24 12:10:08 2014 +0200 copperplate/clockobj, alchemy: sanitize clockobj_get_time() interface --- include/alchemy/timer.h| 19 + include/copperplate/clockobj.h |3 +-- lib/alchemy/task.c |2 +- lib/alchemy/timer.c| 26 ++- lib/copperplate/clockobj.c | 46 5 files changed, 37 insertions(+), 59 deletions(-) diff --git a/include/alchemy/timer.h b/include/alchemy/timer.h index c85d80f..fc33db9 100644 --- a/include/alchemy/timer.h +++ b/include/alchemy/timer.h @@ -99,6 +99,25 @@ int alchemy_poll_mode(const struct timespec *abs_timeout) extern "C" { #endif +/** + * @fn RTIME rt_timer_read(void) + * @brief Return the current system time. + * + * Return the current time maintained by the Xenomai core clock. + * + * @return The current time expressed in clock ticks (see note). + * + * @apitags{unrestricted} + * + * @note The @a time value is a multiple of the Alchemy clock + * resolution (see --alchemy-clock-resolution option, defaults to 1 + * nanosecond). + */ +static inline RTIME rt_timer_read(void) +{ + return clockobj_get_time(&alchemy_clock); +} + static inline RTIME rt_timer_tsc(void) { return clockobj_get_tsc(); diff --git a/include/copperplate/clockobj.h b/include/copperplate/clockobj.h index 1543589..f480214 100644 --- a/include/copperplate/clockobj.h +++ b/include/copperplate/clockobj.h @@ -71,8 +71,7 @@ void clockobj_set_date(struct clockobj *clkobj, ticks_t ticks); void clockobj_get_date(struct clockobj *clkobj, ticks_t *pticks); -void clockobj_get_time(struct clockobj *clkobj, - ticks_t *pticks, ticks_t *ptsc); +ticks_t clockobj_get_time(struct clockobj *clkobj); void clockobj_get_distance(struct clockobj *clkobj, const struct itimerspec *itm, diff --git a/lib/alchemy/task.c b/lib/alchemy/task.c index bd309c9..c9ec272 100644 --- a/lib/alchemy/task.c +++ b/lib/alchemy/task.c @@ -959,7 +959,7 @@ int rt_task_sleep_until(RTIME date) if (date == TM_INFINITE) ts = zero_time; else { - clockobj_get_time(&alchemy_clock, &now, NULL); + now = clockobj_get_time(&alchemy_clock); if (date <= now) return -ETIMEDOUT; CANCEL_DEFER(svc); diff --git a/lib/alchemy/timer.c b/lib/alchemy/timer.c index dfe4f6d..323273c 100644 --- a/lib/alchemy/timer.c +++ b/lib/alchemy/timer.c @@ -31,29 +31,6 @@ struct clockobj alchemy_clock; /** - * @fn RTIME rt_timer_read(void) - * @brief Return the current system time. - * - * Return the current time maintained by the Xenomai core clock. - * - * @return The current time expressed in clock ticks (see note). - * - * @apitags{unrestricted} - * - * @note The @a time value is a multiple of the Alchemy clock - * resolution (see --alchemy-clock-resolution option, defaults to 1 - * nanosecond). - */ -RTIME rt_timer_read(void) -{ - ticks_t ticks; - - clockobj_get_time(&alchemy_clock, &ticks, NULL); - - return ticks; -} - -/** * @fn RTIME rt_timer_ns2ticks(SRTIME ns) * @brief Convert nanoseconds to Alchemy clock ticks. * @@ -113,7 +90,8 @@ SRTIME rt_timer_ticks2ns(SRTIME ticks) int rt_timer_inquire(RT_TIMER_INFO *info) { info->period = clockobj_get_resolution(&alchemy_clock); - clockobj_get_time(&alchemy_clock, &info->date, &info->tsc); + info->date = clockobj_get_time(&alchemy_clock); + info->tsc = clockobj_get_tsc(); return 0; } diff --git a/lib/copperplate/clockobj.c b/lib/copperplate/clockobj.c index 1b6f5f6..8ee3ed7 100644 --- a/lib/copperplate/clockobj.c +++ b/lib/copperplate/clockobj.c @@ -237,21 +237,18 @@ ticks_t clockobj_get_tsc(void) { struct timespec now; - /* Rare case with legacy uClibc+linuxthreads combo. */ + /* +* Rare case with legacy uClibc+linuxthreads combo over +* Cobalt, we actually return nanoseconds just like in the +* Mercury case. +*/ __RT(clock_gettime(CLOCK_REALTIME, &now)); return xnarch_ullmul(now.tv_sec, 10) + now.tv_nsec; } -void clockobj_get_time(struct clockobj *clkobj, - ticks_t *pticks, ticks_t *ptsc) +ticks_t clockobj_get_time(struct clockobj *clkobj) { - ticks_t ns; - - ns = clockobj_get_tsc(); - if (ptsc) - *ptsc = ns; - - *pticks = clockobj_ns_to_ticks(clkobj, ns); + return clockobj_ns_to_ticks(clkobj, clockobj_get_tsc()); } #else /* !CONFIG_XENO_COPPERPLATE_CLOCK_RESTRICTED */ @@ -266,17 +263,10 @@ ticks_t clockobj_get_tsc(void) return cobalt_read_tsc(); } -void clockobj_get_time(struct