Skip to contentSkip to conversation

x86/acrn: Set up timekeeping

PATCH Applied Fei Li 3 participants 4 messages Aug 4, 2022 – Sep 1, 2022 x86

lore
Share & tools
lore

Fei Li

author
#0 lore raw

PATCH 1/1 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.

---
 arch/x86/include/asm/acrn.h | 14 ++++++++++++++
 arch/x86/kernel/cpu/acrn.c  |  3 +++
 2 files changed, 17 insertions(+)
arch/x86/include/asm/acrn.h +14 -0
index e003a01b7c67..1dd14381bcb6 100644
@@ -10,6 +10,15 @@
 /* Bit 0 indicates whether guest VM is privileged */
 #define	ACRN_FEATURE_PRIVILEGED_VM	BIT(0)
 
+/*
+ * Timing Information.
+ * This leaf returns the current TSC frequency in kHz.
+ *
+ * EAX: (Virtual) TSC frequency in kHz.
+ * EBX, ECX, EDX: RESERVED (reserved fields are set to zero).
+ */
+#define ACRN_CPUID_TIMING_INFO		0x40000010
+
 void acrn_setup_intr_handler(void (*handler)(void));
 void acrn_remove_intr_handler(void);
 
@@ -21,6 +30,11 @@ static inline u32 acrn_cpuid_base(void)
 	return 0;
 }
 
+static inline unsigned long acrn_get_tsc_khz(void)
+{
+	return cpuid_eax(ACRN_CPUID_TIMING_INFO);
+}
+
 /*
  * Hypercalls for ACRN
  *
arch/x86/kernel/cpu/acrn.c +3 -0
index 23f5f27b5a02..485441b7f030 100644
@@ -28,6 +28,9 @@ static void __init acrn_init_platform(void)
 {
 	/* Setup the IDT for ACRN hypervisor callback */
 	alloc_intr_gate(HYPERVISOR_CALLBACK_VECTOR, asm_sysvec_acrn_hv_callback);
+
+	x86_platform.calibrate_tsc = acrn_get_tsc_khz;
+	x86_platform.calibrate_cpu = acrn_get_tsc_khz;
 }
 
 static bool acrn_x2apic_available(void)

base-commit: e0dccc3b76fb35bb257b4118367a883073d7390e

Signature · 1 line
2.34.1
merge bot Applied
#1 lore raw
The following commit has been merged into the x86/platform branch of tip:

The following commit has been merged into the x86/platform branch of tip:

Commit-ID:     81a71f51b89e84f39df2a3b1daf4274ae6b7b194
Gitweb:        https://git.kernel.org/tip/81a71f51b89e84f39df2a3b1daf4274ae6b7b194
Author:        Fei Li <[email protected]>
AuthorDate:    Thu, 04 Aug 2022 13:59:03 +08:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Thu, 04 Aug 2022 11:11:59 +02:00

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.

---
 arch/x86/include/asm/acrn.h | 14 ++++++++++++++
 arch/x86/kernel/cpu/acrn.c  |  3 +++
 2 files changed, 17 insertions(+)
arch/x86/include/asm/acrn.h +14 -0
index e003a01..1dd1438 100644
@@ -10,6 +10,15 @@
 /* Bit 0 indicates whether guest VM is privileged */
 #define	ACRN_FEATURE_PRIVILEGED_VM	BIT(0)
 
+/*
+ * Timing Information.
+ * This leaf returns the current TSC frequency in kHz.
+ *
+ * EAX: (Virtual) TSC frequency in kHz.
+ * EBX, ECX, EDX: RESERVED (reserved fields are set to zero).
+ */
+#define ACRN_CPUID_TIMING_INFO		0x40000010
+
 void acrn_setup_intr_handler(void (*handler)(void));
 void acrn_remove_intr_handler(void);
 
@@ -21,6 +30,11 @@ static inline u32 acrn_cpuid_base(void)
 	return 0;
 }
 
+static inline unsigned long acrn_get_tsc_khz(void)
+{
+	return cpuid_eax(ACRN_CPUID_TIMING_INFO);
+}
+
 /*
  * Hypercalls for ACRN
  *
arch/x86/kernel/cpu/acrn.c +3 -0
index 23f5f27..485441b 100644
@@ -28,6 +28,9 @@ static void __init acrn_init_platform(void)
 {
 	/* Setup the IDT for ACRN hypervisor callback */
 	alloc_intr_gate(HYPERVISOR_CALLBACK_VECTOR, asm_sysvec_acrn_hv_callback);
+
+	x86_platform.calibrate_tsc = acrn_get_tsc_khz;
+	x86_platform.calibrate_cpu = acrn_get_tsc_khz;
 }
 
 static bool acrn_x2apic_available(void)
#2 lore raw
In reply to Fei Li
Quoted 13 lines · Fei Li
arch/x86/include/asm/acrn.h +5 -0
+static inline unsigned long acrn_get_tsc_khz(void)
+{
+	return cpuid_eax(ACRN_CPUID_TIMING_INFO);
+}
+
 /*
  * Hypercalls for ACRN
  *
arch/x86/kernel/cpu/acrn.c +0 -0
index 23f5f27b5a02..485441b7f030 100644

arch/x86/kernel/cpu/acrn.c static void __init acrn_init_platform(void) · line 34

Quoted 7 lines
arch/x86/kernel/cpu/acrn.c +3 -0
@@ -28,6 +28,9 @@ static void __init acrn_init_platform(void)
 {
 	/* Setup the IDT for ACRN hypervisor callback */
 	alloc_intr_gate(HYPERVISOR_CALLBACK_VECTOR, asm_sysvec_acrn_hv_callback);
+
+	x86_platform.calibrate_tsc = acrn_get_tsc_khz;
+	x86_platform.calibrate_cpu = acrn_get_tsc_khz;
 }

Could you take a sec and consider what 'static inline' does and means and also what setting:

	x86_platform.calibrate_cpu = acrn_get_tsc_khz;

does?

Using 'static inline' might compile, but it doesn't make sense.

author
#3 lore raw
Quoted 23 lines · Fei Li
Quoted 12 lines
arch/x86/include/asm/acrn.h +4 -0
+static inline unsigned long acrn_get_tsc_khz(void) {
+   return cpuid_eax(ACRN_CPUID_TIMING_INFO);
+}
+
 /*
  * Hypercalls for ACRN
  *
arch/x86/kernel/cpu/acrn.c +0 -0
index 23f5f27b5a02..485441b7f030 100644

arch/x86/kernel/cpu/acrn.c static void __init acrn_init_platform(void) { · line 34

Quoted 7 lines
arch/x86/kernel/cpu/acrn.c +3 -0
@@ -28,6 +28,9 @@ static void __init acrn_init_platform(void)  {
    /* Setup the IDT for ACRN hypervisor callback */
    alloc_intr_gate(HYPERVISOR_CALLBACK_VECTOR,
 asm_sysvec_acrn_hv_callback);
+
+   x86_platform.calibrate_tsc = acrn_get_tsc_khz;
+   x86_platform.calibrate_cpu = acrn_get_tsc_khz;
 }

Could you take a sec and consider what 'static inline' does and means and also what setting:

Quoted 6 lines
      x86_platform.calibrate_cpu = acrn_get_tsc_khz;

does?

Using 'static inline' might compile, but it doesn't make sense.

Hi Dave

Thanks for your reply.
Yes, 'inline' doesn't make sense here.
Now this commit has been merged into the x86/platform branch of tip, I will send a patch to remove 'inline' once this commit has been merged into the master branch.

Thanks again.