Skip to contentSkip to conversation

Testing vlapic timer

PATCH New Anthony PERARD 1 participant 4 messages Jul 18, 2017 x86

lore
Share & tools
lore
#0 lore raw

v2 cover Testing vlapic timer

Hi,

Check the behavior of the vLAPIC timer emulation.

This list of check works on baremetal if one managed to runned it (I did manual testing by coping this xtf tests into xen), but Xen emulation vlapic does not behave like baremetal, so this XTF tests would fail at first, until a fix for Xen that I'm working on is pushed [1].

[1] https://lists.xenproject.org/archives/html/xen-devel/2017-07/msg01726.html

Thanks,

Anthony PERARD (3):
vlapic-timer: Introduce vLAPIC Timer tests
vlapic-timer: Test divide register configuration
vlapic-timer: Testing TSC-deadline timer mode

 arch/x86/include/arch/apic.h      |  12 ++
 arch/x86/include/arch/cpuid.h     |   1 +
 arch/x86/include/arch/lib.h       |   9 ++
 arch/x86/include/arch/msr-index.h |   1 +
 tests/vlapic-timer/Makefile       |   9 ++
 tests/vlapic-timer/main.c         | 258 ++++++++++++++++++++++++++++++++++++++
 6 files changed, 290 insertions(+)
 create mode 100644 tests/vlapic-timer/Makefile
 create mode 100644 tests/vlapic-timer/main.c
Signature · 7 lines
Anthony PERARD


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw

PATCH v2 1/3 vlapic-timer: Introduce vLAPIC Timer tests

Start by testing one-shot and periodic timer modes.

The behavior of TMICT and TMCCT while switching between periodic and one-shot timer modes check in this test is mostly base on observation of baremetal. Intel SDM gives little details about it.

---
 arch/x86/include/arch/apic.h |   8 +++
 tests/vlapic-timer/Makefile  |   9 +++
 tests/vlapic-timer/main.c    | 151 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 168 insertions(+)
 create mode 100644 tests/vlapic-timer/Makefile
 create mode 100644 tests/vlapic-timer/main.c
arch/x86/include/arch/apic.h +8 -0
index 1389f70..4cb262d 100644
@@ -24,6 +24,14 @@
 #define   APIC_DEST_SELF          0x40000
 
 #define APIC_ICR2       0x310
+#define APIC_LVTT       0x320
+#define   APIC_TIMER_MODE_MASK          (0x3<<17)
+#define   APIC_TIMER_MODE_ONESHOT       (0x0<<17)
+#define   APIC_TIMER_MODE_PERIODIC      (0x1<<17)
+
+#define APIC_TMICT      0x380
+#define APIC_TMCCT      0x390
+
 
 #define APIC_DEFAULT_BASE 0xfee00000ul
 
tests/vlapic-timer/Makefile new file +9 -0
new file mode 100644
index 0000000..f2a61cb
@@ -0,0 +1,9 @@
+include $(ROOT)/build/common.mk
+
+NAME      := vlapic-timer
+CATEGORY  := functional
+TEST-ENVS := hvm64
+
+obj-perenv += main.o
+
+include $(ROOT)/build/gen.mk
tests/vlapic-timer/main.c new file +151 -0

151 lines not on this page · raw message

Signature · 7 lines
Anthony PERARD


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#2 lore raw

PATCH v2 2/3 vlapic-timer: Test divide register configuration

In reply to Anthony PERARD
---
 arch/x86/include/arch/apic.h |  3 +++
 tests/vlapic-timer/main.c    | 40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+)
arch/x86/include/arch/apic.h +3 -0
index 4cb262d..0f48df1 100644
@@ -31,6 +31,9 @@
 
 #define APIC_TMICT      0x380
 #define APIC_TMCCT      0x390
+#define APIC_TDCR       0x3e0
+#define   APIC_TDR_DIV_1          0xb
+#define   APIC_TDR_DIV_16         0x3
 
 
 #define APIC_DEFAULT_BASE 0xfee00000ul
tests/vlapic-timer/main.c +40 -0
index 47836a8..19f47d7 100644
@@ -130,6 +130,44 @@ void testing_oneshot_and_periodic_mode(void)
         xtf_failure("Fail: TMCCT should stay at zero\n");
 }
 
+/*
+ * Testing change of divide configuration
+ */
+void testing_divide_configuration(void)
+{
+    uint32_t tmict = 0x49999999;
+
+    printk("Testing change of divide configuration register\n");
+
+    change_mode(APIC_TIMER_MODE_PERIODIC);
+
+    apic_write(APIC_TDCR, APIC_TDR_DIV_16);
+    apic_write(APIC_TMICT, tmict);
+
+    wait_until_tmcct_is_half_down(tmict);
+
+    apic_write(APIC_TDCR, APIC_TDR_DIV_1);
+
+    /*
+     * Checking that changing divide configuration value does not cause the
+     * current counter register to have a different value, it should continue
+     * to count down, but at a different rate.
+     */
+
+    if ( apic_read(APIC_TMCCT) > (tmict / 2) )
+        xtf_failure("Fail: TMCCT may have gone back in time\n");
+    if ( apic_read(APIC_TMCCT) == 0 )
+        xtf_failure("Fail: TMCCT should not be 0\n");
+
+    wait_until_tmcct_is_half_down(tmict);
+
+    apic_write(APIC_TDCR, APIC_TDR_DIV_16);
+    if ( apic_read(APIC_TMCCT) > (tmict / 2) )
+        xtf_failure("Fail: TMCCT may have gone back in time\n");
+    if ( apic_read(APIC_TMCCT) == 0 )
+        xtf_failure("Fail: TMCCT should not be 0\n");
+}
+
 void test_main(void)
 {
     if ( apic_init(APIC_MODE_XAPIC) )
@@ -137,6 +175,8 @@ void test_main(void)
 
     testing_oneshot_and_periodic_mode();
 
+    testing_divide_configuration();
+
     xtf_success(NULL);
 }
 
Signature · 7 lines
Anthony PERARD


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#3 lore raw

PATCH v2 3/3 vlapic-timer: Testing TSC-deadline timer mode

In reply to Anthony PERARD
---
 arch/x86/include/arch/apic.h      |  1 +
 arch/x86/include/arch/cpuid.h     |  1 +
 arch/x86/include/arch/lib.h       |  9 ++++++
 arch/x86/include/arch/msr-index.h |  1 +
 tests/vlapic-timer/main.c         | 67 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 79 insertions(+)
arch/x86/include/arch/apic.h +1 -0
index 0f48df1..b9cf0d7 100644
@@ -28,6 +28,7 @@
 #define   APIC_TIMER_MODE_MASK          (0x3<<17)
 #define   APIC_TIMER_MODE_ONESHOT       (0x0<<17)
 #define   APIC_TIMER_MODE_PERIODIC      (0x1<<17)
+#define   APIC_TIMER_MODE_TSC_DEADLINE  (0x2<<17)
 
 #define APIC_TMICT      0x380
 #define APIC_TMCCT      0x390
arch/x86/include/arch/cpuid.h +1 -0
index a51a829..ad2443a 100644
@@ -77,6 +77,7 @@ static inline bool cpu_has(unsigned int feature)
 #define cpu_has_smx             cpu_has(X86_FEATURE_SMX)
 #define cpu_has_pcid            cpu_has(X86_FEATURE_PCID)
 #define cpu_has_x2apic          cpu_has(X86_FEATURE_X2APIC)
+#define cpu_has_tsc_deadline    cpu_has(X86_FEATURE_TSC_DEADLINE)
 #define cpu_has_xsave           cpu_has(X86_FEATURE_XSAVE)
 #define cpu_has_avx             cpu_has(X86_FEATURE_AVX)
 
arch/x86/include/arch/lib.h +9 -0
index f608af9..513587d 100644
@@ -425,6 +425,15 @@ static inline void write_xcr0(uint64_t xcr0)
     xsetbv(0, xcr0);
 }
 
+static inline uint64_t rdtsc(void)
+{
+    uint32_t lo, hi;
+
+    asm volatile("rdtsc": "=a" (lo), "=d" (hi));
+
+    return (((uint64_t)hi) << 32) | lo;
+}
+
 #endif /* XTF_X86_LIB_H */
 
 /*
arch/x86/include/arch/msr-index.h +1 -0
index d5cf57f..80d8d4e 100644
@@ -37,6 +37,7 @@
 
 #define MSR_A_PMC(n)                   (0x000004c1 + (n))
 
+#define MSR_TSC_DEADLINE                0x000006e0
 #define MSR_X2APIC_REGS                 0x00000800
 
 #define MSR_EFER                        0xc0000080 /* Extended Feature register. */
tests/vlapic-timer/main.c +67 -0

88 lines not on this page · raw message

Signature · 7 lines
Anthony PERARD


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel