Re: [PATCH 01/16] x86/tsc: Add a standalone helpers for getting TSC info from CPUID.0x15

From: Sean Christopherson
Date: Tue Feb 11 2025 - 12:25:59 EST


On Tue, Feb 11, 2025, Borislav Petkov wrote:
> On Fri, Jan 31, 2025 at 06:17:03PM -0800, Sean Christopherson wrote:
> > Extract retrieval of TSC frequency information from CPUID into standalone
> > helpers so that TDX guest support and kvmlock can reuse the logic. Provide
> > a version that includes the multiplier math as TDX in particular does NOT
> > want to use native_calibrate_tsc()'s fallback logic that derives the TSC
> > frequency based on CPUID.0x16 when the core crystal frequency isn't known.
> >
> > No functional change intended.
> >
> > Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
> > ---
> > arch/x86/include/asm/tsc.h | 41 ++++++++++++++++++++++++++++++++++++++
> > arch/x86/kernel/tsc.c | 14 ++-----------
> > 2 files changed, 43 insertions(+), 12 deletions(-)
> >
> > diff --git a/arch/x86/include/asm/tsc.h b/arch/x86/include/asm/tsc.h
> > index 94408a784c8e..14a81a66b37c 100644
> > --- a/arch/x86/include/asm/tsc.h
> > +++ b/arch/x86/include/asm/tsc.h
>
> Bah, why in the header as inlines?

Because obviously optimizing code that's called once during boot is super
critical?

> Just leave them in tsc.c and call them...
>
> > @@ -28,6 +28,47 @@ static inline cycles_t get_cycles(void)
> > }
> > #define get_cycles get_cycles
> >
> > +static inline int cpuid_get_tsc_info(unsigned int *crystal_khz,
> > + unsigned int *denominator,
> > + unsigned int *numerator)
>
> Can we pls do a
>
> struct cpuid_tsc_info {
> unsigned int denominator;
> unsigned int numerator;
> unsigned int crystal_khz;
> unsigned int tsc_khz;
> }
>
> and hand that around instead of those I/O pointers?

Ah, yeah, that's way better.