Lines Matching +full:high +full:- +full:accuracy
2 * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
27 #include "event2/event-config.h"
28 #include "evconfig-private.h"
62 #include "util-internal.h"
63 #include "log-internal.h"
64 #include "mm-internal.h"
82 * an unaligned (!) 64-bit value containing the number of in evutil_gettimeofday()
83 * 100-nanosecond intervals since 1 January 1601 UTC. */ in evutil_gettimeofday()
94 return -1; in evutil_gettimeofday()
115 return -1; in evutil_gettimeofday()
117 ft.ft_64 -= EPOCH_BIAS; in evutil_gettimeofday()
118 tv->tv_sec = (long) (ft.ft_64 / UNITS_PER_SEC); in evutil_gettimeofday()
119 tv->tv_usec = (long) ((ft.ft_64 / UNITS_PER_USEC) % USEC_PER_SEC); in evutil_gettimeofday()
125 (((LONG_MAX) - 999) / 1000)
130 if (tv->tv_usec > 1000000 || tv->tv_sec > MAX_SECONDS_IN_MSEC_LONG) in evutil_tv_to_msec_()
131 return -1; in evutil_tv_to_msec_()
133 return (tv->tv_sec * 1000) + ((tv->tv_usec + 999) / 1000); in evutil_tv_to_msec_()
151 usec = tv->tv_sec * 1000000LL + tv->tv_usec; in evutil_usleep_()
155 li.QuadPart = -10LL * usec; in evutil_usleep_()
167 ts.tv_sec = tv->tv_sec; in evutil_usleep_()
168 ts.tv_nsec = tv->tv_usec*1000; in evutil_usleep_()
173 sleep(tv->tv_sec); in evutil_usleep_()
174 usleep(tv->tv_usec); in evutil_usleep_()
220 DAYS[tm->tm_wday], tm->tm_mday, MONTHS[tm->tm_mon], in evutil_date_rfc1123()
221 1900 + tm->tm_year, tm->tm_hour, tm->tm_min, tm->tm_sec); in evutil_date_rfc1123()
226 not-actually-so-monotonic time source whose outputs are in 'tv'. It
234 evutil_timeradd(tv, &base->adjust_monotonic_clock, tv); in adjust_monotonic_time()
236 if (evutil_timercmp(tv, &base->last_time, <)) { in adjust_monotonic_time()
239 evutil_timersub(&base->last_time, tv, &adjust); in adjust_monotonic_time()
240 evutil_timeradd(&adjust, &base->adjust_monotonic_clock, in adjust_monotonic_time()
241 &base->adjust_monotonic_clock); in adjust_monotonic_time()
242 *tv = base->last_time; in adjust_monotonic_time()
244 base->last_time = *tv; in adjust_monotonic_time()
300 provides a CLOCK_MONOTONIC_COARSE with accuracy of about 1-4 msec.
323 * make sure that it's safe for us to use -1 as an "unset" in evutil_configure_monotonic_time_()
329 base->monotonic_clock = CLOCK_MONOTONIC_COARSE; in evutil_configure_monotonic_time_()
335 base->monotonic_clock = CLOCK_MONOTONIC; in evutil_configure_monotonic_time_()
343 base->monotonic_clock = -1; in evutil_configure_monotonic_time_()
353 if (base->monotonic_clock < 0) { in evutil_gettime_monotonic_()
355 return -1; in evutil_gettime_monotonic_()
360 if (clock_gettime(base->monotonic_clock, &ts) == -1) in evutil_gettime_monotonic_()
361 return -1; in evutil_gettime_monotonic_()
362 tp->tv_sec = ts.tv_sec; in evutil_gettime_monotonic_()
363 tp->tv_usec = ts.tv_nsec / 1000; in evutil_gettime_monotonic_()
376 To all appearances, mach_absolute_time() seems to be honest-to-goodness
396 memcpy(&base->mach_timebase_units, &mi, sizeof(mi)); in evutil_configure_monotonic_time_()
398 base->mach_timebase_units.numer = 0; in evutil_configure_monotonic_time_()
408 if (base->mach_timebase_units.numer == 0) { in evutil_gettime_monotonic_()
410 return -1; in evutil_gettime_monotonic_()
416 usec = (abstime * base->mach_timebase_units.numer) in evutil_gettime_monotonic_()
417 / (base->mach_timebase_units.denom); in evutil_gettime_monotonic_()
418 tp->tv_sec = usec / 1000000; in evutil_gettime_monotonic_()
419 tp->tv_usec = usec % 1000000; in evutil_gettime_monotonic_()
429 Windows has QueryPerformanceCounter(), which gives time most high-
435 There's GetTickCount64() on Vista and later, which gives a number of 1-msec
436 ticks since startup. The accuracy here might be as bad as 10-20 msec, I
438 allegedly increases the accuracy. Good luck!
441 supported on pre-Vista versions of Windows. Apparently, you can coax
447 -- Lily Tomlin, SNL
454 [1] http://www.python.org/dev/peps/pep-0418
489 if (base->GetTickCount64_fn) { in evutil_GetTickCount_()
491 return base->GetTickCount64_fn(); in evutil_GetTickCount_()
492 } else if (base->GetTickCount_fn) { in evutil_GetTickCount_()
498 ev_uint64_t v = base->GetTickCount_fn(); in evutil_GetTickCount_()
506 if (ticks < base->last_tick_count) { in evutil_GetTickCount_()
507 base->adjust_tick_count += ((ev_uint64_t)1) << 32; in evutil_GetTickCount_()
509 base->last_tick_count = ticks; in evutil_GetTickCount_()
510 return ticks + base->adjust_tick_count; in evutil_GetTickCount_()
525 base->GetTickCount64_fn = (ev_GetTickCount_func)GetProcAddress(h, "GetTickCount64"); in evutil_configure_monotonic_time_()
526 base->GetTickCount_fn = (ev_GetTickCount_func)GetProcAddress(h, "GetTickCount"); in evutil_configure_monotonic_time_()
529 base->first_tick = base->last_tick_count = evutil_GetTickCount_(base); in evutil_configure_monotonic_time_()
535 base->first_counter = counter.QuadPart; in evutil_configure_monotonic_time_()
536 base->usec_per_count = 1.0e6 / freq.QuadPart; in evutil_configure_monotonic_time_()
537 base->use_performance_counter = 1; in evutil_configure_monotonic_time_()
547 return i < 0 ? -i : i; in abs64()
556 if (base->use_performance_counter) { in evutil_gettime_monotonic_()
559 * our high-resolution timer, but use GetTickCount*() to keep in evutil_gettime_monotonic_()
566 (counter.QuadPart - base->first_counter); in evutil_gettime_monotonic_()
567 ticks_elapsed = ticks - base->first_tick; in evutil_gettime_monotonic_()
571 (counter_elapsed * base->usec_per_count); in evutil_gettime_monotonic_()
573 if (abs64(ticks_elapsed*1000 - counter_usec_elapsed) > 1000000) { in evutil_gettime_monotonic_()
580 …base->first_counter = (ev_uint64_t) (counter.QuadPart - counter_usec_elapsed / base->usec_per_coun… in evutil_gettime_monotonic_()
582 tp->tv_sec = (time_t) (counter_usec_elapsed / 1000000); in evutil_gettime_monotonic_()
583 tp->tv_usec = counter_usec_elapsed % 1000000; in evutil_gettime_monotonic_()
587 tp->tv_sec = (time_t) (ticks / 1000); in evutil_gettime_monotonic_()
588 tp->tv_usec = (ticks % 1000) * 1000; in evutil_gettime_monotonic_()
616 return -1; in evutil_gettime_monotonic_()