Skip to content

Commit 81a71f5

Browse files
lifeixIngo Molnar
authored andcommitted
x86/acrn: Set up timekeeping
ACRN Hypervisor reports timing information via CPUID leaf 0x40000010. Get the TSC and CPU frequency via CPUID leaf 0x40000010 and set the kernel values accordingly. Signed-off-by: Fei Li <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Reviewed-by: Conghui <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 9de1f9c commit 81a71f5

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

arch/x86/include/asm/acrn.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@
1010
/* Bit 0 indicates whether guest VM is privileged */
1111
#define ACRN_FEATURE_PRIVILEGED_VM BIT(0)
1212

13+
/*
14+
* Timing Information.
15+
* This leaf returns the current TSC frequency in kHz.
16+
*
17+
* EAX: (Virtual) TSC frequency in kHz.
18+
* EBX, ECX, EDX: RESERVED (reserved fields are set to zero).
19+
*/
20+
#define ACRN_CPUID_TIMING_INFO 0x40000010
21+
1322
void acrn_setup_intr_handler(void (*handler)(void));
1423
void acrn_remove_intr_handler(void);
1524

@@ -21,6 +30,11 @@ static inline u32 acrn_cpuid_base(void)
2130
return 0;
2231
}
2332

33+
static inline unsigned long acrn_get_tsc_khz(void)
34+
{
35+
return cpuid_eax(ACRN_CPUID_TIMING_INFO);
36+
}
37+
2438
/*
2539
* Hypercalls for ACRN
2640
*

arch/x86/kernel/cpu/acrn.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ static void __init acrn_init_platform(void)
2828
{
2929
/* Setup the IDT for ACRN hypervisor callback */
3030
alloc_intr_gate(HYPERVISOR_CALLBACK_VECTOR, asm_sysvec_acrn_hv_callback);
31+
32+
x86_platform.calibrate_tsc = acrn_get_tsc_khz;
33+
x86_platform.calibrate_cpu = acrn_get_tsc_khz;
3134
}
3235

3336
static bool acrn_x2apic_available(void)

0 commit comments

Comments
 (0)