Advertisement
Guest User

Untitled

a guest
Dec 15th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. static inline void update_time(void) {
  2. static uint32_t count = 0;
  3. ++count;
  4.  
  5. /* now_real = initial realtime + monotonic shift */
  6. uint64_t curr_monotonic = gettime_nano(CLOCK_MONOTONIC);
  7. now_real = ns2sec(init_real + curr_monotonic - init_monotonic);
  8. now_monotonic = ns2sec(curr_monotonic);
  9.  
  10. if (count >= ADJTIME_PERIOD) {
  11. count = 0;
  12.  
  13. /* compare the fresh realtime and the old one, if the offset is
  14. * in safe range, re-init the init real/monotonic time */
  15. double offset = fabs(ns2sec(gettime_nano(CLOCK_REALTIME)) - now_real);
  16. if (offset > ADJTIME_OFFSET_MAX) {
  17. LogSysWarn("time offset too large %.3f/%.3f sec, won't adjust it",
  18. offset, ADJTIME_OFFSET_MAX);
  19. return;
  20. }
  21. else if (offset >= ADJTIME_OFFSET_MIN) {
  22. init_time();
  23. /* update adjusted now time */
  24. now_real = ns2sec(init_real);
  25. now_monotonic = ns2sec(init_monotonic);
  26. #if ADJTIME_DEBUG
  27. LogSysDebug("time offset %.3f sec adjusted", offset);
  28. #endif
  29. }
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement