Time Namespace youki-dev/youki #3265by CheatCodeSam

Time Namespace

A namespace that allows setting offsets for CLOCK_MONOTONIC and CLOCK_BOOTTIME.

$ man 7 time_namespaces
ClockWhat it representsNotes
CLOCK_MONOTONICMonotonically increasing elapsed time
Time since boot
Not affected by manual time changes
CLOCK_BOOTTIMEMonotonically increasing elapsed time
Time since boot + suspend time
Not affected by manual time changes
Continues counting during suspend
CLOCK_REALTIMEWall-clock timeCan jump due to manual time changes or NTP adjustments

Use Cases

  • Testing with different time settings
    • Can be used to speed up tests that wait for timeouts
  • Checkpoint with CRIU and restore on another node
    • Timeouts may occur when an application resumes at a future time
    • Reference: cri-o#8033

A similar feature called Virtual time was proposed in the past.

Usage

You can specify container time offsets using timeOffsets in OCI runtime-spec.

Write the offset from the initial time namespace to /proc/<pid>/timens_offsets.

Note
Applied from child processes onward
Warning
CLOCK_REALTIME cannot be changed

youki implementation