From 4cb63ee2c5b6e760686e550cd17872bb18eee53d Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Fri, 22 Nov 2013 19:54:53 +0100 Subject: [PATCH 1/4] fix the bloody longterm vtimer bug You know who you are, I'm looking at you! --- sys/vtimer/vtimer.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/sys/vtimer/vtimer.c b/sys/vtimer/vtimer.c index 92fb3b38bc88..c6f8207f0faf 100644 --- a/sys/vtimer/vtimer.c +++ b/sys/vtimer/vtimer.c @@ -53,6 +53,10 @@ static int set_longterm(vtimer_t *timer) static int update_shortterm(void) { + if (shortterm_queue_root.next == NULL) { + DEBUG("update_shortterm: shortterm_queue_root.next == NULL - dont know what to do here\n"); + return 0; + } if (hwtimer_id != -1) { if (hwtimer_next_absolute != shortterm_queue_root.next->priority) { hwtimer_remove(hwtimer_id); @@ -64,10 +68,16 @@ static int update_shortterm(void) hwtimer_next_absolute = shortterm_queue_root.next->priority; - uint32_t next = hwtimer_next_absolute + longterm_tick_start; + uint32_t next = hwtimer_next_absolute; uint32_t now = HWTIMER_TICKS_TO_US(hwtimer_now()); + /* make sure the longterm_tick_timer does not get truncated */ + if (((vtimer_t*)shortterm_queue_root.next)->action != vtimer_tick) { + next += longterm_tick_start; + } + if((next - HWTIMER_TICKS_TO_US(VTIMER_THRESHOLD) - now) > MICROSECONDS_PER_TICK ) { + DEBUG("truncating next (next - HWTIMER_TICKS_TO_US(VTIMER_THRESHOLD) - now): %i\n", (next - HWTIMER_TICKS_TO_US(VTIMER_THRESHOLD) - now)); next = now + HWTIMER_TICKS_TO_US(VTIMER_BACKOFF); } @@ -80,11 +90,11 @@ static int update_shortterm(void) void vtimer_tick(void *ptr) { (void) ptr; - DEBUG("vtimer_tick()."); + DEBUG("vtimer_tick().\n"); seconds += SECONDS_PER_TICK; longterm_tick_start = longterm_tick_timer.absolute.microseconds; - longterm_tick_timer.absolute.microseconds = longterm_tick_timer.absolute.microseconds + MICROSECONDS_PER_TICK; + longterm_tick_timer.absolute.microseconds += MICROSECONDS_PER_TICK; set_shortterm(&longterm_tick_timer); while (longterm_queue_root.next) { @@ -98,8 +108,6 @@ void vtimer_tick(void *ptr) break; } } - - update_shortterm(); } static int set_shortterm(vtimer_t *timer) @@ -134,6 +142,9 @@ void vtimer_callback(void *ptr) else if (timer->action == (void (*)(void *)) thread_wakeup){ timer->action(timer->arg); } + else if (timer->action == vtimer_tick) { + vtimer_tick(NULL); + } else { DEBUG("Timer was poisoned.\n"); } From 1c8e9a4ef5e4fea71ea8c9d56a844d3f54ae092b Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Fri, 22 Nov 2013 20:41:09 +0100 Subject: [PATCH 2/4] add license header --- sys/vtimer/vtimer.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/sys/vtimer/vtimer.c b/sys/vtimer/vtimer.c index c6f8207f0faf..d884081f9c29 100644 --- a/sys/vtimer/vtimer.c +++ b/sys/vtimer/vtimer.c @@ -1,3 +1,21 @@ +/** + * virtual timer + * + * Copyright (C) 2013 Freie Universität Berlin + * + * This file subject to the terms and conditions of the GNU Lesser General + * Public License. See the file LICENSE in the top level directory for more + * details. + * + * @ingroup vtimer + * @{ + * @file + * @author Kaspar Schleiser (author) + * @author Oliver Hahm (modifications) + * @author Ludwig Ortmann (cleaning up the mess) + * @} + */ + #include #include #include From 92f4aa32c9b64c3ae211d9d3e263d1c885f251ca Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Fri, 22 Nov 2013 20:43:24 +0100 Subject: [PATCH 3/4] fix grammar in license header --- sys/vtimer/vtimer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/vtimer/vtimer.c b/sys/vtimer/vtimer.c index d884081f9c29..7ce397aae7e2 100644 --- a/sys/vtimer/vtimer.c +++ b/sys/vtimer/vtimer.c @@ -3,7 +3,7 @@ * * Copyright (C) 2013 Freie Universität Berlin * - * This file subject to the terms and conditions of the GNU Lesser General + * This file is subject to the terms and conditions of the GNU Lesser General * Public License. See the file LICENSE in the top level directory for more * details. * From c6073762fabe8a20d42bb325150a9aa7df7101ac Mon Sep 17 00:00:00 2001 From: Christian Mehlis Date: Tue, 3 Dec 2013 23:27:07 +0100 Subject: [PATCH 4/4] fixed warnings in vtimer --- sys/vtimer/vtimer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys/vtimer/vtimer.c b/sys/vtimer/vtimer.c index 7ce397aae7e2..0994706e7534 100644 --- a/sys/vtimer/vtimer.c +++ b/sys/vtimer/vtimer.c @@ -272,7 +272,7 @@ int vtimer_init() int vtimer_set_wakeup(vtimer_t *t, timex_t interval, int pid) { int ret; - t->action = (void *) thread_wakeup; + t->action = (void(*)(void *)) thread_wakeup; t->arg = (void *) pid; t->absolute = interval; t->pid = 0; @@ -311,7 +311,7 @@ int vtimer_remove(vtimer_t *t) int vtimer_set_msg(vtimer_t *t, timex_t interval, unsigned int pid, void *ptr) { - t->action = (void *) msg_send_int; + t->action = (void(*)(void *)) msg_send_int; t->arg = ptr; t->absolute = interval; t->pid = pid;