From 36c3161fa8f00e01cefe1d3fc12dc8240a7453a7 Mon Sep 17 00:00:00 2001 From: Dennis Potter Date: Thu, 9 Aug 2018 17:35:39 +0200 Subject: [PATCH] Initialized next and set frequency to right value --- lib/task.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/task.c b/lib/task.c index 6ef118f36..6b83a72b8 100644 --- a/lib/task.c +++ b/lib/task.c @@ -73,7 +73,6 @@ int task_set_next(struct task *t, struct timespec *next) { #if PERIODIC_TASK_IMPL == RDTSC - #else t->next = *next; @@ -97,7 +96,8 @@ int task_set_rate(struct task *t, double rate) { #if PERIODIC_TASK_IMPL == RDTSC - t->period = t->frequency / rate; + t->period = t->frequency / rate * 1000; + t->next = rdtscp() + t->period; #else /* A rate of 0 will disarm the timer */ t->period = rate ? time_from_double(1.0 / rate) : (struct timespec) { 0, 0 }; @@ -192,6 +192,7 @@ uint64_t task_wait(struct task *t) now = rdtscp(); } while (now < t->next); + for (runs = 0; t->next < now; runs++) t->next += t->period; #else