This simplified code and ensures that after a subtest used apic timer, it won't affect next subtests which are run after it. Signed-off-by: Maxim Levitsky <mlevitsk@xxxxxxxxxx> --- x86/svm_tests.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/x86/svm_tests.c b/x86/svm_tests.c index d734e5f7..19b35e95 100644 --- a/x86/svm_tests.c +++ b/x86/svm_tests.c @@ -1147,9 +1147,10 @@ static void interrupt_test(struct svm_test *test) { long long start, loops; - apic_write(APIC_LVTT, TIMER_VECTOR); + apic_setup_timer(TIMER_VECTOR, false); + irq_enable(); - apic_write(APIC_TMICT, 1); //Timer Initial Count Register 0x380 one-shot + apic_start_timer(1); for (loops = 0; loops < 10000000 && !timer_fired; loops++) asm volatile ("nop"); @@ -1160,12 +1161,12 @@ static void interrupt_test(struct svm_test *test) vmmcall(); } - apic_write(APIC_TMICT, 0); + apic_stop_timer(); irq_disable(); vmmcall(); timer_fired = false; - apic_write(APIC_TMICT, 1); + apic_start_timer(1); for (loops = 0; loops < 10000000 && !timer_fired; loops++) asm volatile ("nop"); @@ -1177,12 +1178,12 @@ static void interrupt_test(struct svm_test *test) } irq_enable(); - apic_write(APIC_TMICT, 0); + apic_stop_timer(); irq_disable(); timer_fired = false; start = rdtsc(); - apic_write(APIC_TMICT, 1000000); + apic_start_timer(1000000); safe_halt(); report(rdtsc() - start > 10000 && timer_fired, @@ -1193,13 +1194,13 @@ static void interrupt_test(struct svm_test *test) vmmcall(); } - apic_write(APIC_TMICT, 0); + apic_stop_timer(); irq_disable(); vmmcall(); timer_fired = false; start = rdtsc(); - apic_write(APIC_TMICT, 1000000); + apic_start_timer(1000000); asm volatile ("hlt"); report(rdtsc() - start > 10000 && timer_fired, @@ -1210,7 +1211,7 @@ static void interrupt_test(struct svm_test *test) vmmcall(); } - apic_write(APIC_TMICT, 0); + apic_cleanup_timer(); irq_disable(); } @@ -1693,10 +1694,8 @@ static void reg_corruption_prepare(struct svm_test *test) handle_irq(TIMER_VECTOR, reg_corruption_isr); /* set local APIC to inject external interrupts */ - apic_write(APIC_TMICT, 0); - apic_write(APIC_TDCR, 0); - apic_write(APIC_LVTT, TIMER_VECTOR | APIC_LVT_TIMER_PERIODIC); - apic_write(APIC_TMICT, 1000); + apic_setup_timer(TIMER_VECTOR, true); + apic_start_timer(1000); } static void reg_corruption_test(struct svm_test *test) @@ -1742,8 +1741,7 @@ static bool reg_corruption_finished(struct svm_test *test) } return false; cleanup: - apic_write(APIC_LVTT, APIC_LVT_TIMER_MASK); - apic_write(APIC_TMICT, 0); + apic_cleanup_timer(); return true; } -- 2.26.3