WSL: Clock sources are slow to read and imprecise

On a normal bare metal Linux system:

Name          Cost(ns)      +/-    Resol  Mono  Fail  Warp  Stal  Regr
tsc              10.97    0.21%     ----   Yes     0     0     0     0
gettimeofday     17.60    0.01%  1000KHz    No     0     0  1000     0
                 17.60    0.01%
realtime         17.60    0.07%     ----   Yes     0     0     0     0
realtime_crs      4.66    0.06%    100Hz    No   999     0     0     0
                  3.33  142.09%
monotonic        17.20    0.06%     ----   Yes     0     0     0     0
monotonic_crs     4.52    0.02%    100Hz    No   999     0     0     0
                  3.34  142.09%
monotonic_raw    69.76    0.10%     ----   Yes     0     0     0     0
boottime         73.53    0.05%     ----   Yes     0     0     0     0
process         115.67    0.08%     ----   Yes     0     0     0     0
thread          109.64    0.07%     ----   Yes     0     0     0     0
clock           116.93    0.04%  1000KHz    No     0     0  1000     0
getrusage       181.32    0.05%    100Hz    No   996     3     3     0
ftime            20.78    0.04%   1000Hz    No   995     0     4     0
time              2.84    0.03%      1Hz    No  1000     0     0     0

On “Bash on Windows”, the clock behavior isn’t as nice:

Name          Cost(ns)      +/-    Resol  Mono  Fail  Warp  Stal  Regr
tsc              12.53   86.77%     ----   Yes     0     0     0     0
gettimeofday    166.10    0.72%   1032Hz    No   943     5    55     0
realtime        182.39    1.02%  3333KHz    No     0     0   131     0
realtime_crs    168.97    0.83%   2144Hz    No   934     0    65     0
monotonic       186.90    0.38%  1000KHz    No     0     0   998     0
monotonic_crs   188.76    0.33%  1000KHz    No     0     0   998     0
Failed to read from monotonic_raw clock (1, 4)
boottime        186.66    0.37%  1000KHz    No     0     0   998     0
process         272.19    0.81%     64Hz    No   996     3     3     0
thread          229.25    0.84%     64Hz    No   997     2     2     0
clock           278.50    1.23%     64Hz    No   996     3     3     0
getrusage       385.45    0.78%     64Hz    No   995     4     4     0
ftime           207.14    0.81%   1000Hz    No   959     0    40     0
time            156.06    0.86%      1Hz    No  1000     0     0     0

To explain the columns a bit:

The Cost(ns) column is the time cost to read that clock in nanoseconds, as measured by the TSC (except when measuring the cost of reading the TSC itself, which is measured by looking at gettimeofday).

Resol is the observable tick rate of the clock.

Mono indicates whether the clock source is monotonic, with an additional restriction. Not only must the clock only move forward, it must never return the same value (i.e. high frequency).

Fail indicates the number of times the clock source failed to advance in >= 200 reads.

Warp indicates the number of times the clock jumped forward by an unexpectedly large span (threshold for this is currently 1ms).

Stal indicates the number of times the clock source failed to advance in more than 1, but less than 200 reads.

Regr indicates the number of times the clock moved backwards. This can happen due to hypervisor behavior, NTP adjustments, and other clock changes. It’s extremely bad behavior if you use the clock source for timespan measurement (e.g. profiling, benchmarks, etc).

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Reactions: 4
  • Comments: 18 (2 by maintainers)

Most upvoted comments

@russalex Understood. Just wanted to post an update with the latest build. Not trying to force a change ahead of schedule. 😄