Eliminates inappropriate CLOCK_MONOTONIC from ntpfrob.
There are at least three reasons why it's inappropriate to use CLOCK_MONOTONIC in the resolution measurement: 1) It's ostensibly trying to measure the resolution of CLOCK_REALTIME, which is the clock actually managed by NTP, but is relying on the assumption that CLOCK_REALTIME and CLOCK_MONOTONIC have the same resolution. Although this may be true in some cases, it's not guaranteed. Note that the clock_getres() function, which is the intended method for obtaining the resolution, takes a clock_id argument precisely because the clocks may have different resolutions. However, actually using clock_getres() is problematic, since correct implementations seem to be the exception rather than the rule, hence the need for this code. 2) The stated purpose of using CLOCK_MONOTONIC is to decouple the result from NTP adjustments. But, although CLOCK_MONOTONIC is woefully underspecified, it's most commonly implemented as a variant of CLOCK_REALTIME that excludes step adjustments while including all slewing adjustments. Thus, it's not really decoupled from NTP adjustments at all. In fact, if one assumes that step adjustments are fairly rare, then CLOCK_MONOTONIC is almost equivalent to CLOCK_REALTIME, except for the differing epoch. 3) The only non-process clock guaranteed to be provided by clock_gettime() is CLOCK_REALTIME. Any use of CLOCK_MONOTONIC needs to include fallback to handle its absence, but the current code doesn't correctly handle failure of clock_gettime() at all. Fixing this with a proper fallback would only make sense if it weren't for #1 and #2 above. The bottom line is that it's best to use CLOCK_REALTIME for the resolution measurement, while being prepared for possible step adjustments. Given that this is just a special-purpose test tool, and that step adjustments are rare, it should be sufficient to rely on user retry for this. It should be noted that this code has various other issues as well, but this change only adddresses the CLOCK_MONOTONIC issue. TESTED: Observed plausible results on OSX 10.9, Ubuntu 14.04, CentOS 7, and Fedora 25.
Loading
Please register or sign in to comment