On Thu, May 21, 2026, David Woodhouse wrote:
> On Thu, 2026-05-21 at 13:53 -0700, Sean Christopherson wrote:
> > 
> > E.g. this is what I've got for the early flow.  Testing now. 
> > 
> >   void __init tsc_early_init(void)
> >   {
> >     unsigned int known_cpu_khz = 0, known_tsc_khz = 0;
> > 
> >     if (!boot_cpu_has(X86_FEATURE_TSC))
> >             return;
> >     /* Don't change UV TSC multi-chassis synchronization */
> >     if (is_early_uv_system())
> >             return;
> > 
> >     if (x86_init.hyper.get_cpu_khz)
> >             known_cpu_khz = x86_init.hyper.get_cpu_khz();
> > 
> >     if (tsc_early_khz)
> >             known_tsc_khz = tsc_early_khz;
> >     else if (cc_platform_has(CC_ATTR_GUEST_SNP_SECURE_TSC))
> >             known_tsc_khz = snp_secure_tsc_init();
> >     else if (boot_cpu_has(X86_FEATURE_TDX_GUEST))
> >             known_tsc_khz = tdx_tsc_init();
> > 
> >     /*
> >      * If the TSC frequency is still unknown, i.e. not provided by the user
> >      * or by trusted firmware, try to get it from the hypervisor (which is
> >      * untrusted when running as a CoCo guest).
> >      */
> >     if (!known_tsc_khz && x86_init.hyper.get_tsc_khz)
> >             known_tsc_khz = x86_init.hyper.get_tsc_khz();
> > 
> >     if (known_tsc_khz)
> >             setup_force_cpu_cap(X86_FEATURE_TSC_KNOWN_FREQ);
> > 
> >     if (!determine_cpu_tsc_frequencies(true, known_cpu_khz, known_tsc_khz))
> >             return;
> >     tsc_enable_sched_clock();
> >   }
> 
> That seems reasonable. Where does the call to native_calibrate_tsc()
> happen; is that from determine_cpu_tsc_frequencies()? 

Yep.

static bool __init determine_cpu_tsc_frequencies(bool early,
                                                 unsigned int known_cpu_khz,
                                                 unsigned int known_tsc_khz)
{
        /* Make sure that cpu and tsc are not already calibrated */
        WARN_ON(cpu_khz || tsc_khz);

        if (early) {
                /*
                 * Early CPU calibration can only use methods that are available
                 * early in boot (obviously).
                 */
                if (known_cpu_khz)
                        cpu_khz = known_cpu_khz;
                else
                        cpu_khz = native_calibrate_cpu_early();
                if (known_tsc_khz)
                        tsc_khz = known_tsc_khz;
                else
                        tsc_khz = native_calibrate_tsc();
        } else {
                cpu_khz = pit_hpet_ptimer_calibrate_cpu();
        }

        ...

Reply via email to