@@ -961,6 +961,9 @@ static inline struct kvm_vm *vm_create_shape_with_one_vcpu(struct vm_shape shape
return __vm_create_shape_with_one_vcpu(shape, vcpu, 0, guest_code);
}
+struct kvm_vm *vm_create_with_one_vcpu_with_pmu(struct kvm_vcpu **vcpu,
+ void *guest_code);
+
struct kvm_vcpu *vm_recreate_with_one_vcpu(struct kvm_vm *vm);
void kvm_pin_this_task_to_pcpu(uint32_t pcpu);
@@ -545,6 +545,29 @@ struct kvm_vcpu *vm_recreate_with_one_vcpu(struct kvm_vm *vm)
return vm_vcpu_recreate(vm, 0);
}
+struct kvm_vm *vm_create_with_one_vcpu_with_pmu(struct kvm_vcpu **vcpu,
+ void *guest_code)
+{
+ struct kvm_vm *vm;
+ int r;
+
+ r = kvm_check_cap(KVM_CAP_PMU_CAPABILITY);
+ if (!(r & KVM_PMU_CAP_DISABLE))
+ return NULL;
+
+ vm = vm_create(1);
+
+ /*
+ * KVM_CAP_PMU_CAPABILITY ioctl must be explicitly called to enable
+ * mediated vPMU.
+ */
+ vm_enable_cap(vm, KVM_CAP_PMU_CAPABILITY, !KVM_PMU_CAP_DISABLE);
+
+ *vcpu = vm_vcpu_add(vm, 0, guest_code);
+
+ return vm;
+}
+
void kvm_pin_this_task_to_pcpu(uint32_t pcpu)
{
cpu_set_t mask;
@@ -40,7 +40,9 @@ static struct kvm_vm *pmu_vm_create_with_one_vcpu(struct kvm_vcpu **vcpu,
{
struct kvm_vm *vm;
- vm = vm_create_with_one_vcpu(vcpu, guest_code);
+ vm = vm_create_with_one_vcpu_with_pmu(vcpu, guest_code);
+ assert(vm);
+
sync_global_to_guest(vm, kvm_pmu_version);
/*
@@ -822,8 +822,9 @@ static void test_fixed_counter_bitmap(void)
* fixed performance counters.
*/
for (idx = 0; idx < nr_fixed_counters; idx++) {
- vm = vm_create_with_one_vcpu(&vcpu,
- intel_run_fixed_counter_guest_code);
+ vm = vm_create_with_one_vcpu_with_pmu(&vcpu,
+ intel_run_fixed_counter_guest_code);
+ assert(vm);
vcpu_args_set(vcpu, 1, idx);
__test_fixed_counter_bitmap(vcpu, idx, nr_fixed_counters);
kvm_vm_free(vm);
@@ -843,7 +844,8 @@ int main(int argc, char *argv[])
TEST_REQUIRE(use_intel_pmu() || use_amd_pmu());
guest_code = use_intel_pmu() ? intel_guest_code : amd_guest_code;
- vm = vm_create_with_one_vcpu(&vcpu, guest_code);
+ vm = vm_create_with_one_vcpu_with_pmu(&vcpu, guest_code);
+ assert(vm);
TEST_REQUIRE(sanity_check_pmu(vcpu));