Signed-off-by: Andrew Jones <drjones@xxxxxxxxxx> --- x86/hyperv_stimer.c | 51 ++++++++++++++------------------------------------- 1 file changed, 14 insertions(+), 37 deletions(-) diff --git a/x86/hyperv_stimer.c b/x86/hyperv_stimer.c index 5292523709ea..dcbe1363fe4e 100644 --- a/x86/hyperv_stimer.c +++ b/x86/hyperv_stimer.c @@ -19,9 +19,8 @@ #define SINT2_NUM 3 #define ONE_MS_IN_100NS 10000 -static atomic_t g_cpus_comp_count; -static int g_cpus_count; static struct spinlock g_synic_alloc_lock; +static ulong cr3; struct stimer { int sint; @@ -216,20 +215,15 @@ static void synic_disable(void) synic_free_page(svcpu->msg_page); } -static void cpu_comp(void) -{ - atomic_inc(&g_cpus_comp_count); -} -static void stimer_test_prepare(void *ctx) +static void stimer_test_prepare(void) { int vcpu = smp_id(); - write_cr3((ulong)ctx); + write_cr3(cr3); synic_enable(); synic_sint_create(vcpu, SINT1_NUM, SINT1_VEC, false); synic_sint_create(vcpu, SINT2_NUM, SINT2_VEC, true); - cpu_comp(); } static void stimer_test_periodic(int vcpu, struct stimer *timer1, @@ -280,7 +274,7 @@ static void stimer_test_auto_enable_periodic(int vcpu, struct stimer *timer) stimer_shutdown(timer); } -static void stimer_test(void *ctx) +static void stimer_test(void) { int vcpu = smp_id(); struct svcpu *svcpu = &g_synic_vcpu[vcpu]; @@ -297,10 +291,9 @@ static void stimer_test(void *ctx) stimer_test_auto_enable_periodic(vcpu, timer1); irq_disable(); - cpu_comp(); } -static void stimer_test_cleanup(void *ctx) +static void stimer_test_cleanup(void) { int vcpu = smp_id(); @@ -308,20 +301,6 @@ static void stimer_test_cleanup(void *ctx) synic_sint_destroy(vcpu, SINT1_NUM); synic_sint_destroy(vcpu, SINT2_NUM); synic_disable(); - cpu_comp(); -} - -static void on_each_cpu_async_wait(void (*func)(void *ctx), void *ctx) -{ - int i; - - atomic_set(&g_cpus_comp_count, 0); - for (i = 0; i < g_cpus_count; i++) { - on_cpu_async(i, func, ctx); - } - while (atomic_read(&g_cpus_comp_count) != g_cpus_count) { - pause(); - } } static void stimer_test_all(void) @@ -332,20 +311,18 @@ static void stimer_test_all(void) smp_init(); enable_apic(); - handle_irq(SINT1_VEC, stimer_isr); - handle_irq(SINT2_VEC, stimer_isr_auto_eoi); - ncpus = cpu_count(); - if (ncpus > MAX_CPUS) { - ncpus = MAX_CPUS; - } - + if (ncpus > MAX_CPUS) + report_abort("number cpus exceeds %d", MAX_CPUS); printf("cpus = %d\n", ncpus); - g_cpus_count = ncpus; - on_each_cpu_async_wait(stimer_test_prepare, (void *)read_cr3()); - on_each_cpu_async_wait(stimer_test, NULL); - on_each_cpu_async_wait(stimer_test_cleanup, NULL); + handle_irq(SINT1_VEC, stimer_isr); + handle_irq(SINT2_VEC, stimer_isr_auto_eoi); + + cr3 = read_cr3(); + on_cpus(stimer_test_prepare); + on_cpus(stimer_test); + on_cpus(stimer_test_cleanup); } int main(int ac, char **av) -- 2.9.4