[PATCH 3/5] um: time: use the host TSC as clocksource for the vDSO

Benjamin Berg benjamin at sipsolutions.net
Mon Nov 23 01:46:06 PST 2026


Hi,

On Sun, 2026-11-22 at 07:42 -0600, Haikal Firmansyah wrote:
> [SNIP]
> @@ -945,11 +1022,30 @@ static void __init um_timer_init(void)
>  		return;
>  	}
> 
> -	err = clocksource_register_hz(&timer_clocksource,
> NSEC_PER_SEC/TIMER_MULTIPLIER);

This patch is malformed, something incorrectly inserted a newline here.

> +	/*
> +	 * Calibrate the TSC before registering the clocksource, so the
> +	 * timekeeper (and the vDSO) use the TSC rate from the first tick.
> +	 * On failure keep the old os_nsecs() clocksource: timer_read()
> +	 * falls back to it and vdso_clock_mode stays NONE.
> +	 */

I expect that this fallback also needs to be done when UML is running
in time-travel mode. In that case, the clock is independent from the
host clock so this optimization cannot be used.

Benjamin

> +	um_tsc_hz = um_calibrate_tsc();
> +	if (um_tsc_hz) {
> +		um_tsc_ok = true;
> +		timer_clocksource.name = "tsc";
> +		timer_clocksource.vdso_clock_mode = VDSO_CLOCKMODE_TSC;
> +		pr_info("UML: TSC clocksource, frequency %llu Hz\n", um_tsc_hz);
> +		err = clocksource_register_hz(&timer_clocksource,
> +					      (u32)um_tsc_hz);
> +	} else {
> +		pr_info("UML: TSC calibration failed, keeping os_nsecs() (no vDSO)\n");
> +		err = clocksource_register_hz(&timer_clocksource,
> +					      NSEC_PER_SEC / TIMER_MULTIPLIER);
> +	}
>  	if (err) {
>  		printk(KERN_ERR "clocksource_register_hz returned
> %d\n", err);
>  		return;
>  	}
> +
>  }
> 
>  void read_persistent_clock64(struct timespec64 *ts)



More information about the linux-um mailing list