[PATCH kvm-unit-tests 3/7] x86/hyperv_clock: apply on_cpus

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Andrew Jones <drjones@xxxxxxxxxx>
---
 x86/hyperv_clock.c | 31 ++++++++-----------------------
 1 file changed, 8 insertions(+), 23 deletions(-)

diff --git a/x86/hyperv_clock.c b/x86/hyperv_clock.c
index 6c4dd56f948d..83d653231c71 100644
--- a/x86/hyperv_clock.c
+++ b/x86/hyperv_clock.c
@@ -55,13 +55,12 @@ uint64_t hv_clock_read(void)
 	return hvclock_tsc_to_ticks(&shadow, rdtsc());
 }
 
-atomic_t cpus_left;
 bool ok[MAX_CPU];
 uint64_t loops[MAX_CPU];
 
 #define iabs(x)   ((x) < 0 ? -(x) : (x))
 
-static void hv_clock_test(void *data)
+static void hv_clock_test(void)
 {
 	int i = smp_id();
 	uint64_t t = rdmsr(HV_X64_MSR_TIME_REF_COUNT);
@@ -99,7 +98,6 @@ static void hv_clock_test(void *data)
 	if (!got_drift)
 		printf("delta on CPU %d was %d...%d\n", smp_id(), min_delta, max_delta);
 	barrier();
-	atomic_dec(&cpus_left);
 }
 
 static void check_test(int ncpus)
@@ -107,13 +105,7 @@ static void check_test(int ncpus)
 	int i;
 	bool pass;
 
-	atomic_set(&cpus_left, ncpus);
-	for (i = ncpus - 1; i >= 0; i--)
-		on_cpu_async(i, hv_clock_test, NULL);
-
-	/* Wait for the end of other vcpu */
-	while(atomic_read(&cpus_left))
-		;
+	on_cpus(hv_clock_test);
 
 	pass = true;
 	for (i = ncpus - 1; i >= 0; i--)
@@ -122,7 +114,7 @@ static void check_test(int ncpus)
 	report("TSC reference precision test", pass);
 }
 
-static void hv_perf_test(void *data)
+static void hv_perf_test(void)
 {
 	uint64_t t = hv_clock_read();
 	uint64_t end = t + 1000000000 / 100;
@@ -134,7 +126,6 @@ static void hv_perf_test(void *data)
 	} while(t < end);
 
 	loops[smp_id()] = local_loops;
-	atomic_dec(&cpus_left);
 }
 
 static void perf_test(int ncpus)
@@ -142,13 +133,7 @@ static void perf_test(int ncpus)
 	int i;
 	uint64_t total_loops;
 
-	atomic_set(&cpus_left, ncpus);
-	for (i = ncpus - 1; i >= 0; i--)
-		on_cpu_async(i, hv_perf_test, NULL);
-
-	/* Wait for the end of other vcpu */
-	while(atomic_read(&cpus_left))
-		;
+	on_cpus(hv_perf_test);
 
 	total_loops = 0;
 	for (i = ncpus - 1; i >= 0; i--)
@@ -167,6 +152,10 @@ int main(int ac, char **av)
 	setup_vm();
 	smp_init();
 
+	ncpus = cpu_count();
+	if (ncpus > MAX_CPU)
+		report_abort("number cpus exceeds %d", MAX_CPU);
+
 	hv_clock = alloc_page();
 	wrmsr(HV_X64_MSR_REFERENCE_TSC, (u64)(uintptr_t)hv_clock | 1);
 	report("MSR value after enabling",
@@ -195,10 +184,6 @@ int main(int ac, char **av)
 	       "TSC reference %" PRId64" (delta %" PRId64")\n",
 	       ref2, ref2 - ref1, tsc2, t2, t2 - t1);
 
-	ncpus = cpu_count();
-	if (ncpus > MAX_CPU)
-		ncpus = MAX_CPU;
-
 	check_test(ncpus);
 	perf_test(ncpus);
 
-- 
2.9.4




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux