* [PATCH kvm-unit-tests v2 0/8] x86: introduce and apply on_cpus
@ 2017-06-13 9:21 Andrew Jones
2017-06-13 9:21 ` [PATCH kvm-unit-tests v2 1/8] arm/arm64: smp: give on_cpus an argument Andrew Jones
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: Andrew Jones @ 2017-06-13 9:21 UTC (permalink / raw)
To: kvm; +Cc: rkrcmar, pbonzini
v2: give on_cpus() an argument [Radim], and add a patch to fixup ARM,
so it has the same API
Andrew Jones (8):
arm/arm64: smp: give on_cpus an argument
x86/unittests.cfg: create hyperv group
lib/x86/smp: introduce on_cpus and cpus_active
x86/hyperv_clock: apply on_cpus
x86/hyperv_stimer: apply on_cpus
x86/hyperv_synic: apply on_cpus
x86/kvmclock_test: apply on_cpus
x86/vmexit: apply on_cpus
arm/gic.c | 4 ++--
arm/selftest.c | 4 ++--
arm/spinlock-test.c | 4 ++--
lib/arm/asm/smp.h | 2 +-
lib/arm/smp.c | 9 ++++-----
lib/x86/smp.c | 21 +++++++++++++++++++++
lib/x86/smp.h | 2 ++
x86/hyperv_clock.c | 27 ++++++---------------------
x86/hyperv_stimer.c | 41 ++++++++---------------------------------
x86/hyperv_synic.c | 36 ++++++++----------------------------
x86/kvmclock_test.c | 33 +++++++++++----------------------
x86/unittests.cfg | 3 +++
x86/vmexit.c | 12 ++----------
13 files changed, 72 insertions(+), 126 deletions(-)
--
2.9.4
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH kvm-unit-tests v2 1/8] arm/arm64: smp: give on_cpus an argument
2017-06-13 9:21 [PATCH kvm-unit-tests v2 0/8] x86: introduce and apply on_cpus Andrew Jones
@ 2017-06-13 9:21 ` Andrew Jones
2017-06-13 9:21 ` [PATCH kvm-unit-tests v2 2/8] x86/unittests.cfg: create hyperv group Andrew Jones
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Andrew Jones @ 2017-06-13 9:21 UTC (permalink / raw)
To: kvm; +Cc: rkrcmar, pbonzini
Signed-off-by: Andrew Jones <drjones@redhat.com>
---
arm/gic.c | 4 ++--
arm/selftest.c | 4 ++--
arm/spinlock-test.c | 4 ++--
lib/arm/asm/smp.h | 2 +-
lib/arm/smp.c | 9 ++++-----
5 files changed, 11 insertions(+), 12 deletions(-)
diff --git a/arm/gic.c b/arm/gic.c
index 2c5832100e0e..a945f7ab8385 100644
--- a/arm/gic.c
+++ b/arm/gic.c
@@ -240,7 +240,7 @@ static void ipi_recv(void)
wfi();
}
-static void ipi_test(void)
+static void ipi_test(void *data __unused)
{
if (smp_processor_id() == IPI_SENDER)
ipi_send();
@@ -327,7 +327,7 @@ int main(int argc, char **argv)
if (strcmp(argv[1], "ipi") == 0) {
report_prefix_push(argv[1]);
nr_cpu_check(2);
- on_cpus(ipi_test);
+ on_cpus(ipi_test, NULL);
} else if (strcmp(argv[1], "active") == 0) {
run_active_clear_test();
} else {
diff --git a/arm/selftest.c b/arm/selftest.c
index 1ad2e7120248..ea5101ef7217 100644
--- a/arm/selftest.c
+++ b/arm/selftest.c
@@ -308,7 +308,7 @@ static bool psci_check(void)
return true;
}
-static void cpu_report(void)
+static void cpu_report(void *data __unused)
{
uint64_t mpidr = get_mpidr();
int cpu = smp_processor_id();
@@ -342,7 +342,7 @@ int main(int argc, char **argv)
} else if (strcmp(argv[1], "smp") == 0) {
report("PSCI version", psci_check());
- on_cpus(cpu_report);
+ on_cpus(cpu_report, NULL);
} else {
printf("Unknown subtest\n");
diff --git a/arm/spinlock-test.c b/arm/spinlock-test.c
index cd03f81c5fae..d55471bc0aa3 100644
--- a/arm/spinlock-test.c
+++ b/arm/spinlock-test.c
@@ -43,7 +43,7 @@ static void none_unlock(int *lock_var)
static int global_a, global_b;
static int global_lock;
-static void test_spinlock(void)
+static void test_spinlock(void *data __unused)
{
int i, errors = 0;
int cpu = smp_processor_id();
@@ -80,7 +80,7 @@ int main(int argc, char **argv)
lock_ops.unlock = none_unlock;
}
- on_cpus(test_spinlock);
+ on_cpus(test_spinlock, NULL);
return report_summary();
}
diff --git a/lib/arm/asm/smp.h b/lib/arm/asm/smp.h
index 62d14b07bc51..077afde85520 100644
--- a/lib/arm/asm/smp.h
+++ b/lib/arm/asm/smp.h
@@ -52,6 +52,6 @@ typedef void (*secondary_entry_fn)(void);
extern void smp_boot_secondary(int cpu, secondary_entry_fn entry);
extern void on_cpu_async(int cpu, void (*func)(void *data), void *data);
extern void on_cpu(int cpu, void (*func)(void *data), void *data);
-extern void on_cpus(void (*func)(void));
+extern void on_cpus(void (*func)(void *data), void *data);
#endif /* _ASMARM_SMP_H_ */
diff --git a/lib/arm/smp.c b/lib/arm/smp.c
index 5a6209ebcbfd..3c4e307489b2 100644
--- a/lib/arm/smp.c
+++ b/lib/arm/smp.c
@@ -72,9 +72,8 @@ void smp_boot_secondary(int cpu, secondary_entry_fn entry)
spin_unlock(&lock);
}
-typedef void (*on_cpu_func)(void *);
struct on_cpu_info {
- on_cpu_func func;
+ void (*func)(void *data);
void *data;
cpumask_t waiters;
};
@@ -180,16 +179,16 @@ void on_cpu(int cpu, void (*func)(void *data), void *data)
cpu_wait(cpu);
}
-void on_cpus(void (*func)(void))
+void on_cpus(void (*func)(void *data), void *data)
{
int cpu, me = smp_processor_id();
for_each_present_cpu(cpu) {
if (cpu == me)
continue;
- on_cpu_async(cpu, (on_cpu_func)func, NULL);
+ on_cpu_async(cpu, func, data);
}
- func();
+ func(data);
for_each_present_cpu(cpu) {
if (cpu == me)
--
2.9.4
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH kvm-unit-tests v2 2/8] x86/unittests.cfg: create hyperv group
2017-06-13 9:21 [PATCH kvm-unit-tests v2 0/8] x86: introduce and apply on_cpus Andrew Jones
2017-06-13 9:21 ` [PATCH kvm-unit-tests v2 1/8] arm/arm64: smp: give on_cpus an argument Andrew Jones
@ 2017-06-13 9:21 ` Andrew Jones
2017-06-13 9:21 ` [PATCH kvm-unit-tests v2 3/8] lib/x86/smp: introduce on_cpus and cpus_active Andrew Jones
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Andrew Jones @ 2017-06-13 9:21 UTC (permalink / raw)
To: kvm; +Cc: rkrcmar, pbonzini
Signed-off-by: Andrew Jones <drjones@redhat.com>
---
x86/unittests.cfg | 3 +++
1 file changed, 3 insertions(+)
diff --git a/x86/unittests.cfg b/x86/unittests.cfg
index 5ab46671d631..42f1ad454c6d 100644
--- a/x86/unittests.cfg
+++ b/x86/unittests.cfg
@@ -502,16 +502,19 @@ arch = x86_64
file = hyperv_synic.flat
smp = 2
extra_params = -cpu kvm64,hv_synic -device hyperv-testdev
+groups = hyperv
[hyperv_stimer]
file = hyperv_stimer.flat
smp = 2
extra_params = -cpu kvm64,hv_time,hv_synic,hv_stimer -device hyperv-testdev
+groups = hyperv
[hyperv_clock]
file = hyperv_clock.flat
smp = 2
extra_params = -cpu kvm64,hv_time
+groups = hyperv
[intel_iommu]
file = intel-iommu.flat
--
2.9.4
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH kvm-unit-tests v2 3/8] lib/x86/smp: introduce on_cpus and cpus_active
2017-06-13 9:21 [PATCH kvm-unit-tests v2 0/8] x86: introduce and apply on_cpus Andrew Jones
2017-06-13 9:21 ` [PATCH kvm-unit-tests v2 1/8] arm/arm64: smp: give on_cpus an argument Andrew Jones
2017-06-13 9:21 ` [PATCH kvm-unit-tests v2 2/8] x86/unittests.cfg: create hyperv group Andrew Jones
@ 2017-06-13 9:21 ` Andrew Jones
2017-06-13 9:21 ` [PATCH kvm-unit-tests v2 4/8] x86/hyperv_clock: apply on_cpus Andrew Jones
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Andrew Jones @ 2017-06-13 9:21 UTC (permalink / raw)
To: kvm; +Cc: rkrcmar, pbonzini
Signed-off-by: Andrew Jones <drjones@redhat.com>
---
lib/x86/smp.c | 21 +++++++++++++++++++++
lib/x86/smp.h | 2 ++
2 files changed, 23 insertions(+)
diff --git a/lib/x86/smp.c b/lib/x86/smp.c
index 4bdbeaeb8b68..bffb6dec0c65 100644
--- a/lib/x86/smp.c
+++ b/lib/x86/smp.c
@@ -1,5 +1,7 @@
#include <libcflat.h>
+#include "processor.h"
+#include "atomic.h"
#include "smp.h"
#include "apic.h"
#include "fwcfg.h"
@@ -15,6 +17,7 @@ static void *volatile ipi_data;
static volatile int ipi_done;
static volatile bool ipi_wait;
static int _cpu_count;
+static atomic_t active_cpus;
static __attribute__((used)) void ipi()
{
@@ -27,6 +30,7 @@ static __attribute__((used)) void ipi()
apic_write(APIC_EOI, 0);
}
function(data);
+ atomic_dec(&active_cpus);
if (wait) {
ipi_done = 1;
apic_write(APIC_EOI, 0);
@@ -68,6 +72,7 @@ static void __on_cpu(int cpu, void (*function)(void *data), void *data,
if (cpu == smp_id())
function(data);
else {
+ atomic_inc(&active_cpus);
ipi_done = 0;
ipi_function = function;
ipi_data = data;
@@ -91,6 +96,21 @@ void on_cpu_async(int cpu, void (*function)(void *data), void *data)
__on_cpu(cpu, function, data, 0);
}
+void on_cpus(void (*function)(void *data), void *data)
+{
+ int cpu;
+
+ for (cpu = cpu_count() - 1; cpu >= 0; --cpu)
+ on_cpu_async(cpu, function, data);
+
+ while (cpus_active() > 1)
+ pause();
+}
+
+int cpus_active(void)
+{
+ return atomic_read(&active_cpus);
+}
void smp_init(void)
{
@@ -106,4 +126,5 @@ void smp_init(void)
for (i = 1; i < cpu_count(); ++i)
on_cpu(i, setup_smp_id, 0);
+ atomic_inc(&active_cpus);
}
diff --git a/lib/x86/smp.h b/lib/x86/smp.h
index afabac8495f1..1453bb5e6805 100644
--- a/lib/x86/smp.h
+++ b/lib/x86/smp.h
@@ -6,7 +6,9 @@ void smp_init(void);
int cpu_count(void);
int smp_id(void);
+int cpus_active(void);
void on_cpu(int cpu, void (*function)(void *data), void *data);
void on_cpu_async(int cpu, void (*function)(void *data), void *data);
+void on_cpus(void (*function)(void *data), void *data);
#endif
--
2.9.4
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH kvm-unit-tests v2 4/8] x86/hyperv_clock: apply on_cpus
2017-06-13 9:21 [PATCH kvm-unit-tests v2 0/8] x86: introduce and apply on_cpus Andrew Jones
` (2 preceding siblings ...)
2017-06-13 9:21 ` [PATCH kvm-unit-tests v2 3/8] lib/x86/smp: introduce on_cpus and cpus_active Andrew Jones
@ 2017-06-13 9:21 ` Andrew Jones
2017-06-13 9:21 ` [PATCH kvm-unit-tests v2 5/8] x86/hyperv_stimer: " Andrew Jones
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Andrew Jones @ 2017-06-13 9:21 UTC (permalink / raw)
To: kvm; +Cc: rkrcmar, pbonzini
Signed-off-by: Andrew Jones <drjones@redhat.com>
---
x86/hyperv_clock.c | 27 ++++++---------------------
1 file changed, 6 insertions(+), 21 deletions(-)
diff --git a/x86/hyperv_clock.c b/x86/hyperv_clock.c
index 6c4dd56f948d..9497269719b6 100644
--- a/x86/hyperv_clock.c
+++ b/x86/hyperv_clock.c
@@ -55,7 +55,6 @@ 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];
@@ -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, NULL);
pass = true;
for (i = ncpus - 1; i >= 0; i--)
@@ -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, NULL);
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
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH kvm-unit-tests v2 5/8] x86/hyperv_stimer: apply on_cpus
2017-06-13 9:21 [PATCH kvm-unit-tests v2 0/8] x86: introduce and apply on_cpus Andrew Jones
` (3 preceding siblings ...)
2017-06-13 9:21 ` [PATCH kvm-unit-tests v2 4/8] x86/hyperv_clock: apply on_cpus Andrew Jones
@ 2017-06-13 9:21 ` Andrew Jones
2017-06-13 9:21 ` [PATCH kvm-unit-tests v2 6/8] x86/hyperv_synic: " Andrew Jones
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Andrew Jones @ 2017-06-13 9:21 UTC (permalink / raw)
To: kvm; +Cc: rkrcmar, pbonzini
Signed-off-by: Andrew Jones <drjones@redhat.com>
---
x86/hyperv_stimer.c | 41 ++++++++---------------------------------
1 file changed, 8 insertions(+), 33 deletions(-)
diff --git a/x86/hyperv_stimer.c b/x86/hyperv_stimer.c
index 5292523709ea..a067c5097f88 100644
--- a/x86/hyperv_stimer.c
+++ b/x86/hyperv_stimer.c
@@ -19,8 +19,6 @@
#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;
struct stimer {
@@ -216,10 +214,6 @@ 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)
{
@@ -229,7 +223,6 @@ static void stimer_test_prepare(void *ctx)
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,
@@ -297,7 +290,6 @@ static void stimer_test(void *ctx)
stimer_test_auto_enable_periodic(vcpu, timer1);
irq_disable();
- cpu_comp();
}
static void stimer_test_cleanup(void *ctx)
@@ -308,20 +300,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 +310,17 @@ 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);
+
+ on_cpus(stimer_test_prepare, (void *)read_cr3());
+ on_cpus(stimer_test, NULL);
+ on_cpus(stimer_test_cleanup, NULL);
}
int main(int ac, char **av)
--
2.9.4
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH kvm-unit-tests v2 6/8] x86/hyperv_synic: apply on_cpus
2017-06-13 9:21 [PATCH kvm-unit-tests v2 0/8] x86: introduce and apply on_cpus Andrew Jones
` (4 preceding siblings ...)
2017-06-13 9:21 ` [PATCH kvm-unit-tests v2 5/8] x86/hyperv_stimer: " Andrew Jones
@ 2017-06-13 9:21 ` Andrew Jones
2017-06-13 9:21 ` [PATCH kvm-unit-tests v2 7/8] x86/kvmclock_test: " Andrew Jones
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Andrew Jones @ 2017-06-13 9:21 UTC (permalink / raw)
To: kvm; +Cc: rkrcmar, pbonzini
Signed-off-by: Andrew Jones <drjones@redhat.com>
---
x86/hyperv_synic.c | 36 ++++++++----------------------------
1 file changed, 8 insertions(+), 28 deletions(-)
diff --git a/x86/hyperv_synic.c b/x86/hyperv_synic.c
index a08e69f7da5f..cf508f16fd5d 100644
--- a/x86/hyperv_synic.c
+++ b/x86/hyperv_synic.c
@@ -12,7 +12,6 @@
#define MAX_CPUS 4
static atomic_t isr_enter_count[MAX_CPUS];
-static atomic_t cpus_comp_count;
static void synic_sint_auto_eoi_isr(isr_regs_t *regs)
{
@@ -91,7 +90,7 @@ static void synic_test_prepare(void *ctx)
r = rdmsr(HV_X64_MSR_EOM);
if (r != 0) {
report("Hyper-V SynIC test, EOM read %#" PRIx64, false, r);
- goto ret;
+ return;
}
wrmsr(HV_X64_MSR_SIMP, (u64)virt_to_phys(alloc_page()) |
@@ -101,8 +100,6 @@ static void synic_test_prepare(void *ctx)
wrmsr(HV_X64_MSR_SCONTROL, HV_SYNIC_CONTROL_ENABLE);
synic_sints_prepare(smp_id());
-ret:
- atomic_inc(&cpus_comp_count);
}
static void synic_sints_test(int dst_vcpu)
@@ -125,7 +122,6 @@ static void synic_test(void *ctx)
irq_enable();
synic_sints_test(dst_vcpu);
- atomic_inc(&cpus_comp_count);
}
static void synic_test_cleanup(void *ctx)
@@ -142,7 +138,6 @@ static void synic_test_cleanup(void *ctx)
wrmsr(HV_X64_MSR_SCONTROL, 0);
wrmsr(HV_X64_MSR_SIMP, 0);
wrmsr(HV_X64_MSR_SIEFP, 0);
- atomic_inc(&cpus_comp_count);
}
int main(int ac, char **av)
@@ -156,40 +151,25 @@ int main(int ac, char **av)
smp_init();
enable_apic();
- synic_prepare_sint_vecs();
-
ncpus = cpu_count();
- if (ncpus > MAX_CPUS) {
- ncpus = MAX_CPUS;
- }
+ if (ncpus > MAX_CPUS)
+ report_abort("number cpus exceeds %d", MAX_CPUS);
printf("ncpus = %d\n", ncpus);
- atomic_set(&cpus_comp_count, 0);
- for (i = 0; i < ncpus; i++) {
- on_cpu_async(i, synic_test_prepare, (void *)read_cr3());
- }
+ synic_prepare_sint_vecs();
+
printf("prepare\n");
- while (atomic_read(&cpus_comp_count) != ncpus) {
- pause();
- }
+ on_cpus(synic_test_prepare, (void *)read_cr3());
- atomic_set(&cpus_comp_count, 0);
for (i = 0; i < ncpus; i++) {
printf("test %d -> %d\n", i, ncpus - 1 - i);
on_cpu_async(i, synic_test, (void *)(ulong)(ncpus - 1 - i));
}
- while (atomic_read(&cpus_comp_count) != ncpus) {
+ while (cpus_active() > 1)
pause();
- }
- atomic_set(&cpus_comp_count, 0);
- for (i = 0; i < ncpus; i++) {
- on_cpu_async(i, synic_test_cleanup, NULL);
- }
printf("cleanup\n");
- while (atomic_read(&cpus_comp_count) != ncpus) {
- pause();
- }
+ on_cpus(synic_test_cleanup, NULL);
ok = true;
for (i = 0; i < ncpus; ++i) {
--
2.9.4
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH kvm-unit-tests v2 7/8] x86/kvmclock_test: apply on_cpus
2017-06-13 9:21 [PATCH kvm-unit-tests v2 0/8] x86: introduce and apply on_cpus Andrew Jones
` (5 preceding siblings ...)
2017-06-13 9:21 ` [PATCH kvm-unit-tests v2 6/8] x86/hyperv_synic: " Andrew Jones
@ 2017-06-13 9:21 ` Andrew Jones
2017-06-13 9:21 ` [PATCH kvm-unit-tests v2 8/8] x86/vmexit: " Andrew Jones
2017-06-14 18:58 ` [PATCH kvm-unit-tests v2 0/8] x86: introduce and " Radim Krčmář
8 siblings, 0 replies; 10+ messages in thread
From: Andrew Jones @ 2017-06-13 9:21 UTC (permalink / raw)
To: kvm; +Cc: rkrcmar, pbonzini
Signed-off-by: Andrew Jones <drjones@redhat.com>
---
x86/kvmclock_test.c | 33 +++++++++++----------------------
1 file changed, 11 insertions(+), 22 deletions(-)
diff --git a/x86/kvmclock_test.c b/x86/kvmclock_test.c
index b90203e0f624..48a7cdb20e44 100644
--- a/x86/kvmclock_test.c
+++ b/x86/kvmclock_test.c
@@ -17,7 +17,6 @@ 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 ? */
};
@@ -78,29 +77,20 @@ 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))
- ;
+ on_cpus(kvm_clock_test, ti);
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 +119,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, NULL);
if (ac > 2) {
printf("Wallclock test, threshold %ld\n", threshold);
@@ -143,26 +133,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, NULL);
return nerr > 0 ? 1 : 0;
}
--
2.9.4
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH kvm-unit-tests v2 8/8] x86/vmexit: apply on_cpus
2017-06-13 9:21 [PATCH kvm-unit-tests v2 0/8] x86: introduce and apply on_cpus Andrew Jones
` (6 preceding siblings ...)
2017-06-13 9:21 ` [PATCH kvm-unit-tests v2 7/8] x86/kvmclock_test: " Andrew Jones
@ 2017-06-13 9:21 ` Andrew Jones
2017-06-14 18:58 ` [PATCH kvm-unit-tests v2 0/8] x86: introduce and " Radim Krčmář
8 siblings, 0 replies; 10+ messages in thread
From: Andrew Jones @ 2017-06-13 9:21 UTC (permalink / raw)
To: kvm; +Cc: rkrcmar, pbonzini
Signed-off-by: Andrew Jones <drjones@redhat.com>
---
x86/vmexit.c | 12 ++----------
1 file changed, 2 insertions(+), 10 deletions(-)
diff --git a/x86/vmexit.c b/x86/vmexit.c
index 8d2bf1a31982..543c4772eb17 100644
--- a/x86/vmexit.c
+++ b/x86/vmexit.c
@@ -419,7 +419,6 @@ static struct test tests[] = {
};
unsigned iterations;
-static atomic_t nr_cpus_done;
static void run_test(void *_func)
{
@@ -428,8 +427,6 @@ static void run_test(void *_func)
for (i = 0; i < iterations; ++i)
func();
-
- atomic_inc(&nr_cpus_done);
}
static bool do_test(struct test *test)
@@ -463,11 +460,7 @@ static bool do_test(struct test *test)
for (i = 0; i < iterations; ++i)
func();
} else {
- atomic_set(&nr_cpus_done, 0);
- for (i = cpu_count(); i > 0; i--)
- on_cpu_async(i-1, run_test, func);
- while (atomic_read(&nr_cpus_done) < cpu_count())
- ;
+ on_cpus(run_test, func);
}
t2 = rdtsc();
} while ((t2 - t1) < GOAL);
@@ -509,8 +502,7 @@ int main(int ac, char **av)
nr_cpus = cpu_count();
irq_enable();
- for (i = cpu_count(); i > 0; i--)
- on_cpu(i-1, enable_nx, 0);
+ on_cpus(enable_nx, NULL);
fadt = find_acpi_table_addr(FACP_SIGNATURE);
pm_tmr_blk = fadt->pm_tmr_blk;
--
2.9.4
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH kvm-unit-tests v2 0/8] x86: introduce and apply on_cpus
2017-06-13 9:21 [PATCH kvm-unit-tests v2 0/8] x86: introduce and apply on_cpus Andrew Jones
` (7 preceding siblings ...)
2017-06-13 9:21 ` [PATCH kvm-unit-tests v2 8/8] x86/vmexit: " Andrew Jones
@ 2017-06-14 18:58 ` Radim Krčmář
8 siblings, 0 replies; 10+ messages in thread
From: Radim Krčmář @ 2017-06-14 18:58 UTC (permalink / raw)
To: Andrew Jones; +Cc: kvm, pbonzini
2017-06-13 11:21+0200, Andrew Jones:
> v2: give on_cpus() an argument [Radim], and add a patch to fixup ARM,
> so it has the same API
Applied, thanks.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2017-06-14 18:58 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-13 9:21 [PATCH kvm-unit-tests v2 0/8] x86: introduce and apply on_cpus Andrew Jones
2017-06-13 9:21 ` [PATCH kvm-unit-tests v2 1/8] arm/arm64: smp: give on_cpus an argument Andrew Jones
2017-06-13 9:21 ` [PATCH kvm-unit-tests v2 2/8] x86/unittests.cfg: create hyperv group Andrew Jones
2017-06-13 9:21 ` [PATCH kvm-unit-tests v2 3/8] lib/x86/smp: introduce on_cpus and cpus_active Andrew Jones
2017-06-13 9:21 ` [PATCH kvm-unit-tests v2 4/8] x86/hyperv_clock: apply on_cpus Andrew Jones
2017-06-13 9:21 ` [PATCH kvm-unit-tests v2 5/8] x86/hyperv_stimer: " Andrew Jones
2017-06-13 9:21 ` [PATCH kvm-unit-tests v2 6/8] x86/hyperv_synic: " Andrew Jones
2017-06-13 9:21 ` [PATCH kvm-unit-tests v2 7/8] x86/kvmclock_test: " Andrew Jones
2017-06-13 9:21 ` [PATCH kvm-unit-tests v2 8/8] x86/vmexit: " Andrew Jones
2017-06-14 18:58 ` [PATCH kvm-unit-tests v2 0/8] x86: introduce and " Radim Krčmář
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).