Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static inline void update_time(void) {
- static uint32_t count = 0;
- ++count;
- /* now_real = initial realtime + monotonic shift */
- uint64_t curr_monotonic = gettime_nano(CLOCK_MONOTONIC);
- now_real = ns2sec(init_real + curr_monotonic - init_monotonic);
- now_monotonic = ns2sec(curr_monotonic);
- if (count >= ADJTIME_PERIOD) {
- count = 0;
- /* compare the fresh realtime and the old one, if the offset is
- * in safe range, re-init the init real/monotonic time */
- double offset = fabs(ns2sec(gettime_nano(CLOCK_REALTIME)) - now_real);
- if (offset > ADJTIME_OFFSET_MAX) {
- LogSysWarn("time offset too large %.3f/%.3f sec, won't adjust it",
- offset, ADJTIME_OFFSET_MAX);
- return;
- }
- else if (offset >= ADJTIME_OFFSET_MIN) {
- init_time();
- /* update adjusted now time */
- now_real = ns2sec(init_real);
- now_monotonic = ns2sec(init_monotonic);
- #if ADJTIME_DEBUG
- LogSysDebug("time offset %.3f sec adjusted", offset);
- #endif
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement