Skip to content

Commit

Permalink
lkl tools: posix: switch to using a monotonic clock
Browse files Browse the repository at this point in the history
POSIX recomends to switch away from gettimeofday to
clock_gettime. clock_gettime also provides nanosecond resolution and
using a monotonic clock avoids potential issues with host changes.

Signed-off-by: Octavian Purdila <octavian.purdila@intel.com>
  • Loading branch information
Octavian Purdila committed Aug 31, 2016
1 parent 341d37b commit c14dc91
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions tools/lkl/lib/posix-host.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,11 @@ static void *tls_get(unsigned int key)

static unsigned long long time_ns(void)
{
struct timeval tv;
struct timespec ts;

gettimeofday(&tv, NULL);
clock_gettime(CLOCK_MONOTONIC, &ts);

return tv.tv_sec * 1000000000ULL + tv.tv_usec * 1000ULL;
return 1e9*ts.tv_sec + ts.tv_nsec;
}

static void *timer_alloc(void (*fn)(void *), void *arg)
Expand Down

0 comments on commit c14dc91

Please sign in to comment.