From: Andrew Jones Subject: [PATCH kvm-unit-tests 4/7] x86/hyperv_stimer: apply on_cpus Date: Thu, 1 Jun 2017 17:48:16 +0200 Message-ID: <20170601154819.18831-5-drjones@redhat.com> References: <20170601154819.18831-1-drjones@redhat.com> Cc: pbonzini@redhat.com, rkrcmar@redhat.com To: kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:40316 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752404AbdFAPs3 (ORCPT ); Thu, 1 Jun 2017 11:48:29 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 511A883F42 for ; Thu, 1 Jun 2017 15:48:29 +0000 (UTC) In-Reply-To: <20170601154819.18831-1-drjones@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: Signed-off-by: Andrew Jones --- 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