[Xenomai-git] Philippe Gerum : cobalt/clock: use proper reference clock for periodic timings
Module: xenomai-3 Branch: stable-3.0.x Commit: 0130549f352ee49c7c975653b6d6c53abaeb2b2a URL: http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=0130549f352ee49c7c975653b6d6c53abaeb2b2a Author: Philippe GerumDate: Mon Feb 1 15:14:16 2016 +0100 cobalt/clock: use proper reference clock for periodic timings Threads may be paced by an external clock instead of the core clock. In such a case, make sure to base delays and offsets on the reference time maintained by the proper clock. --- kernel/cobalt/thread.c | 22 +++--- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c index b7e3e38..a8edece 100644 --- a/kernel/cobalt/thread.c +++ b/kernel/cobalt/thread.c @@ -1320,15 +1320,13 @@ int xnthread_set_periodic(struct xnthread *thread, xnticks_t idate, goto unlock_and_exit; } + /* +* LART: detect periods which are shorter than the core clock +* gravity for kernel thread timers. This can't work, caller +* must have messed up arguments. +*/ if (period < xnclock_ticks_to_ns(, -xnclock_get_gravity(, -kernel))) { - /* -* LART: detect periods which are shorter than the -* core clock gravity for kernel thread timers. This -* can't work, caller must have messed up with -* arguments. -*/ +xnclock_get_gravity(, kernel))) { ret = -EINVAL; goto unlock_and_exit; } @@ -1348,7 +1346,7 @@ int xnthread_set_periodic(struct xnthread *thread, xnticks_t idate, xntimer_start(>ptimer, period, period, XN_RELATIVE); else { if (timeout_mode == XN_REALTIME) - idate -= xnclock_get_offset(); + idate -= xnclock_get_offset(xntimer_clock(>ptimer)); else if (timeout_mode != XN_ABSOLUTE) { ret = -EINVAL; goto unlock_and_exit; @@ -1399,6 +1397,7 @@ int xnthread_wait_period(unsigned long *overruns_r) { unsigned long overruns = 0; struct xnthread *thread; + struct xnclock *clock; xnticks_t now; int ret = 0; spl_t s; @@ -1414,7 +1413,8 @@ int xnthread_wait_period(unsigned long *overruns_r) trace_cobalt_thread_wait_period(thread); - now = xnclock_read_raw(); + clock = xntimer_clock(>ptimer); + now = xnclock_read_raw(clock); if (likely((xnsticks_t)(now - xntimer_pexpect(>ptimer)) < 0)) { xnthread_suspend(thread, XNDELAY, XN_INFINITE, XN_RELATIVE, NULL); if (unlikely(xnthread_test_info(thread, XNBREAK))) { @@ -1422,7 +1422,7 @@ int xnthread_wait_period(unsigned long *overruns_r) goto out; } - now = xnclock_read_raw(); + now = xnclock_read_raw(clock); } overruns = xntimer_get_overruns(>ptimer, now); ___ Xenomai-git mailing list Xenomai-git@xenomai.org http://xenomai.org/mailman/listinfo/xenomai-git
[Xenomai-git] Philippe Gerum : cobalt/clock: use proper reference clock for periodic timings
Module: xenomai-3 Branch: next Commit: d540d7c6c112b7ff151f5e8a207baa2701499323 URL: http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=d540d7c6c112b7ff151f5e8a207baa2701499323 Author: Philippe GerumDate: Mon Feb 1 15:14:16 2016 +0100 cobalt/clock: use proper reference clock for periodic timings Threads may be paced by an external clock instead of the core clock. In such a case, make sure to base delays and offsets on the reference time maintained by the proper clock. --- kernel/cobalt/thread.c | 22 +++--- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c index 435e902..26ce90f 100644 --- a/kernel/cobalt/thread.c +++ b/kernel/cobalt/thread.c @@ -1316,15 +1316,13 @@ int xnthread_set_periodic(struct xnthread *thread, xnticks_t idate, goto unlock_and_exit; } + /* +* LART: detect periods which are shorter than the core clock +* gravity for kernel thread timers. This can't work, caller +* must have messed up arguments. +*/ if (period < xnclock_ticks_to_ns(, -xnclock_get_gravity(, -kernel))) { - /* -* LART: detect periods which are shorter than the -* core clock gravity for kernel thread timers. This -* can't work, caller must have messed up with -* arguments. -*/ +xnclock_get_gravity(, kernel))) { ret = -EINVAL; goto unlock_and_exit; } @@ -1344,7 +1342,7 @@ int xnthread_set_periodic(struct xnthread *thread, xnticks_t idate, xntimer_start(>ptimer, period, period, XN_RELATIVE); else { if (timeout_mode == XN_REALTIME) - idate -= xnclock_get_offset(); + idate -= xnclock_get_offset(xntimer_clock(>ptimer)); else if (timeout_mode != XN_ABSOLUTE) { ret = -EINVAL; goto unlock_and_exit; @@ -1395,6 +1393,7 @@ int xnthread_wait_period(unsigned long *overruns_r) { unsigned long overruns = 0; struct xnthread *thread; + struct xnclock *clock; xnticks_t now; int ret = 0; spl_t s; @@ -1410,7 +1409,8 @@ int xnthread_wait_period(unsigned long *overruns_r) trace_cobalt_thread_wait_period(thread); - now = xnclock_read_raw(); + clock = xntimer_clock(>ptimer); + now = xnclock_read_raw(clock); if (likely((xnsticks_t)(now - xntimer_pexpect(>ptimer)) < 0)) { xnthread_suspend(thread, XNDELAY, XN_INFINITE, XN_RELATIVE, NULL); if (unlikely(xnthread_test_info(thread, XNBREAK))) { @@ -1418,7 +1418,7 @@ int xnthread_wait_period(unsigned long *overruns_r) goto out; } - now = xnclock_read_raw(); + now = xnclock_read_raw(clock); } overruns = xntimer_get_overruns(>ptimer, now); ___ Xenomai-git mailing list Xenomai-git@xenomai.org http://xenomai.org/mailman/listinfo/xenomai-git