Commit 2a0883a3 authored by Joanne Hugé's avatar Joanne Hugé

Use absolute time to wake up the real time thread at a regular interval

parent 37b601b6
...@@ -46,7 +46,7 @@ static inline uint64_t min(uint64_t a, uint64_t b); ...@@ -46,7 +46,7 @@ static inline uint64_t min(uint64_t a, uint64_t b);
// Real-time thread // Real-time thread
static void *timerthread(void *p) { static void *timerthread(void *p) {
struct timespec previous, current; struct timespec previous, current, next;
struct sched_param priority; struct sched_param priority;
cpu_set_t mask; cpu_set_t mask;
uint64_t diff; uint64_t diff;
...@@ -74,6 +74,8 @@ static void *timerthread(void *p) { ...@@ -74,6 +74,8 @@ static void *timerthread(void *p) {
// Start tracing // Start tracing
if (param->enable_tracing) tracing(1); if (param->enable_tracing) tracing(1);
clock_gettime(CLOCK_ID, &next);
// Measurement loop // Measurement loop
for (stat->nb_cycles = 0;; stat->nb_cycles++) { for (stat->nb_cycles = 0;; stat->nb_cycles++) {
if (param->max_cycles && (stat->nb_cycles >= param->max_cycles)) break; if (param->max_cycles && (stat->nb_cycles >= param->max_cycles)) break;
...@@ -101,7 +103,14 @@ static void *timerthread(void *p) { ...@@ -101,7 +103,14 @@ static void *timerthread(void *p) {
stat->max_res = max(stat->max_res, diff); stat->max_res = max(stat->max_res, diff);
stat->min_res = min(stat->min_res, diff); stat->min_res = min(stat->min_res, diff);
usleep(param->interval); next.tv_nsec += 10000000;
if(next.tv_nsec >= NSEC_PER_SEC) {
next.tv_sec += 1;
next.tv_nsec -= NSEC_PER_SEC;
}
clock_nanosleep(CLOCK_ID, TIMER_ABSTIME, &next, NULL);
} }
if (param->enable_tracing) tracing(0); if (param->enable_tracing) tracing(0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment