microsoft / microsoft/WSL

CLOCK_MONOTONIC frequency inaccurate

Open
#12,583 8 comments 9 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
33.7k
Forks
1.8k
Avg merge
3d 17h
Merged PRs (30d)
116

Description

### Windows Version

Microsoft Windows [Version 10.0.26100.3194]

### WSL Version

2.3.24.0

### Are you using WSL 1 or WSL 2?

- [x] WSL 2
- [ ] WSL 1

### Kernel Version

5.15.153.1-2

### Distro Version

Ubuntu 24.04

### Other Software

_No response_

### Repro Steps

[test-clock.c.txt](https://github.com/user-attachments/files/18787913/test-clock.c.txt)

Compile and run with `gcc test-clock.c && ./a.out`

### Expected Behavior

> Realtime clock elapsed 60 seconds. Monotonic clock elapsed 60.... seconds.

Note that CLOCK_MONOTONIC is supposed to be affected by frequency adjustments, so that it tracks one second per second. The realtime clock and monotonic clocks should have the same frequency.

From `man clock_gettime`
```
CLOCK_MONOTONIC
A nonsettable system-wide clock that represents monotonic time since—as described by POSIX—"some unspecified point in the past". On
Linux, that point corresponds to the number of seconds that the system has been running since it was booted.

The CLOCK_MONOTONIC clock is not affected by discontinuous jumps in the system time (e.g., if the system administrator manually changes
the clock), but is affected by frequency adjustments. This clock does not count time that the system is suspended. All CLOCK_MONOTONIC
variants guarantee that the time returned by consecutive calls will not go backwards, but successive calls may—depending on the architec‐
ture—return identical (not-increased) time values.
```

### Actual Behavior

> Realtime clock elapsed 65 seconds. Monotonic clock elapsed 60.000146 seconds.

Note that this test took 65s as timed by a stopwatch, so the usleep call actually took longer than expected.

### Diagnostic Logs

[strace-time-test.txt](https://github.com/user-attachments/files/18787978/strace-time-test.txt)

Contributor guide

Open the contributing guide

Research direction

Start by compiling and running the attached test-clock.c.txt under WSL 2 on Ubuntu 24.04, then compare its CLOCK_REALTIME and CLOCK_MONOTONIC measurements around usleep. Read the attached strace-time-test.txt for timing details; done means the reported clocks track the expected elapsed frequency without the observed discrepancy.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, linux, ubuntu
Domain
operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.