void tsc2timespec(uint64_t tsc_time, struct timespec *ts) { ts->tv_sec = tsc2sec(tsc_time); /* subtract off everything but the remainder */ tsc_time -= sec2tsc(ts->tv_sec); ts->tv_nsec = tsc2nsec(tsc_time); }
/* * read binary time info. all numbers are little endian. * ticks and nsec are syncronized. */ static int readbintime(char *buf, int n) { int i; int64_t nsec, ticks; uint8_t *b = (uint8_t *) buf; i = 0; if (fasthz == 0LL) fasthz = system_timing.tsc_freq; #if 0 fastticks((uint64_t *) & fasthz); nsec = todget(&ticks); #endif ticks = read_tsc(); nsec = tsc2nsec(ticks); if (n >= 3 * sizeof(uint64_t)) { int64_t2le(b + 2 * sizeof(uint64_t), fasthz); i += sizeof(uint64_t); } if (n >= 2 * sizeof(uint64_t)) { int64_t2le(b + sizeof(uint64_t), ticks); i += sizeof(uint64_t); } if (n >= 8) { int64_t2le(b, nsec); i += sizeof(int64_t); } return i; }
static void tsc2timespec(uint64_t tsc, struct timespec *ts) { uint64_t nsec = tsc2nsec(tsc); ts->tv_sec = nsec / 1000000000; ts->tv_nsec = nsec % 1000000000; }
/* * like the old #c/time but with added info. Return * * secs nanosecs fastticks fasthz */ static int readtime(uint32_t off, char *buf, int n) { int64_t nsec, ticks; long sec; char str[7 * NUMSIZE]; if (fasthz == 0LL) fasthz = system_timing.tsc_freq; #if 0 fastticks((uint64_t *) & fasthz); nsec = todget(&ticks); #endif ticks = read_tsc(); nsec = tsc2nsec(ticks); sec = nsec / 1000000000ULL; snprintf(str, sizeof(str), "%*lud %*llud %*llud %*llud ", NUMSIZE - 1, sec, VLNUMSIZE - 1, nsec, VLNUMSIZE - 1, ticks, VLNUMSIZE - 1, fasthz); return consreadstr(off, buf, n, str); }
uint64_t epoch_nsec(void) { return tsc2nsec(epoch_tsc()); }