[PATCH kvm-unit-tests 6/7] x86/kvmclock_test: apply on_cpus

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

 



Signed-off-by: Andrew Jones <drjones@xxxxxxxxxx>
---
 x86/kvmclock.c      |  4 ++--
 x86/kvmclock.h      |  4 ++--
 x86/kvmclock_test.c | 38 ++++++++++++++------------------------
 3 files changed, 18 insertions(+), 28 deletions(-)

diff --git a/x86/kvmclock.c b/x86/kvmclock.c
index bad078495a4a..abfbd4272ef0 100644
--- a/x86/kvmclock.c
+++ b/x86/kvmclock.c
@@ -232,7 +232,7 @@ cycle_t kvm_clock_read()
         return ret;
 }
 
-void kvm_clock_init(void *data)
+void kvm_clock_init(void)
 {
         int index = smp_id();
         struct pvclock_vcpu_time_info *hvc = &hv_clock[index];
@@ -241,7 +241,7 @@ void kvm_clock_init(void *data)
         wrmsr(MSR_KVM_SYSTEM_TIME_NEW, (unsigned long)hvc | 1);
 }
 
-void kvm_clock_clear(void *data)
+void kvm_clock_clear(void)
 {
         wrmsr(MSR_KVM_SYSTEM_TIME_NEW, 0LL);
 }
diff --git a/x86/kvmclock.h b/x86/kvmclock.h
index dff680212758..a9e470a70af6 100644
--- a/x86/kvmclock.h
+++ b/x86/kvmclock.h
@@ -38,7 +38,7 @@ struct timespec {
 void pvclock_set_flags(unsigned char flags);
 cycle_t kvm_clock_read();
 void kvm_get_wallclock(struct timespec *ts);
-void kvm_clock_init(void *data);
-void kvm_clock_clear(void *data);
+void kvm_clock_init(void);
+void kvm_clock_clear(void);
 
 #endif
diff --git a/x86/kvmclock_test.c b/x86/kvmclock_test.c
index b90203e0f624..19e4cacfe75e 100644
--- a/x86/kvmclock_test.c
+++ b/x86/kvmclock_test.c
@@ -17,11 +17,11 @@ struct test_info {
         u64 stalls;               /* stall count */
         long long worst;          /* worst warp */
         volatile cycle_t last;    /* last cycle seen by test */
-        atomic_t ncpus;           /* number of cpu in the test*/
         int check;                /* check cycle ? */
 };
 
 struct test_info ti[4];
+struct test_info *hv_test_info;
 
 static void wallclock_test(void *data)
 {
@@ -42,9 +42,8 @@ static void wallclock_test(void *data)
         }
 }
 
-static void kvm_clock_test(void *data)
+static void kvm_clock_test(void)
 {
-        struct test_info *hv_test_info = (struct test_info *)data;
         long i, check = hv_test_info->check;
 
         for (i = 0; i < loops; i++){
@@ -78,29 +77,21 @@ static void kvm_clock_test(void *data)
                 if (!((unsigned long)i & 31))
                         asm volatile("rep; nop");
         }
-
-        atomic_dec(&hv_test_info->ncpus);
 }
 
-static int cycle_test(int ncpus, int check, struct test_info *ti)
+static int cycle_test(int check, struct test_info *ti)
 {
-        int i;
         unsigned long long begin, end;
 
         begin = rdtsc();
 
-        atomic_set(&ti->ncpus, ncpus);
         ti->check = check;
-        for (i = ncpus - 1; i >= 0; i--)
-                on_cpu_async(i, kvm_clock_test, (void *)ti);
-
-        /* Wait for the end of other vcpu */
-        while(atomic_read(&ti->ncpus))
-                ;
+        hv_test_info = ti;
+        on_cpus(kvm_clock_test);
 
         end = rdtsc();
 
-        printf("Total vcpus: %d\n", ncpus);
+        printf("Total vcpus: %d\n", cpu_count());
         printf("Test  loops: %ld\n", loops);
         if (check == 1) {
                 printf("Total warps:  %" PRId64 "\n", ti->warps);
@@ -129,9 +120,9 @@ int main(int ac, char **av)
 
         ncpus = cpu_count();
         if (ncpus > MAX_CPU)
-                ncpus = MAX_CPU;
-        for (i = 0; i < ncpus; ++i)
-                on_cpu(i, kvm_clock_init, (void *)0);
+                report_abort("number cpus exceeds %d", MAX_CPU);
+
+        on_cpus(kvm_clock_init);
 
         if (ac > 2) {
                 printf("Wallclock test, threshold %ld\n", threshold);
@@ -143,26 +134,25 @@ int main(int ac, char **av)
         printf("Check the stability of raw cycle ...\n");
         pvclock_set_flags(PVCLOCK_TSC_STABLE_BIT
                           | PVCLOCK_RAW_CYCLE_BIT);
-        if (cycle_test(ncpus, 1, &ti[0]))
+        if (cycle_test(1, &ti[0]))
                 printf("Raw cycle is not stable\n");
         else
                 printf("Raw cycle is stable\n");
 
         pvclock_set_flags(PVCLOCK_TSC_STABLE_BIT);
         printf("Monotonic cycle test:\n");
-        nerr += cycle_test(ncpus, 1, &ti[1]);
+        nerr += cycle_test(1, &ti[1]);
 
         printf("Measure the performance of raw cycle ...\n");
         pvclock_set_flags(PVCLOCK_TSC_STABLE_BIT
                           | PVCLOCK_RAW_CYCLE_BIT);
-        cycle_test(ncpus, 0, &ti[2]);
+        cycle_test(0, &ti[2]);
 
         printf("Measure the performance of adjusted cycle ...\n");
         pvclock_set_flags(PVCLOCK_TSC_STABLE_BIT);
-        cycle_test(ncpus, 0, &ti[3]);
+        cycle_test(0, &ti[3]);
 
-        for (i = 0; i < ncpus; ++i)
-                on_cpu(i, kvm_clock_clear, (void *)0);
+        on_cpus(kvm_clock_clear);
 
         return nerr > 0 ? 1 : 0;
 }
-- 
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