Use monotonic time, which represents time since some point: http://linux.die.net/man/3/clock_gettime
int64_t get_monotonic_timestamp(void)
{
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return (int64_t)ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
}