[PATCH 2/3] target/i386: Call KVM_CAP_PMU_CAPABILITY iotcl to enable/disable PMU

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

 



After introducing mediated vPMU, mediated vPMU must be enabled by
explicitly calling KVM_CAP_PMU_CAPABILITY to enable. Thus call
KVM_CAP_PMU_CAPABILITY to enable/disable PMU base on user configuration.

Suggested-by: Zhao Liu <zhao1.liu@xxxxxxxxx>
Signed-off-by: Dapeng Mi <dapeng1.mi@xxxxxxxxxxxxxxx>
---
 target/i386/kvm/kvm.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
index f41e190fb8..d3e6984844 100644
--- a/target/i386/kvm/kvm.c
+++ b/target/i386/kvm/kvm.c
@@ -2051,8 +2051,25 @@ full:
     abort();
 }
 
+static bool pmu_cap_set = false;
 int kvm_arch_pre_create_vcpu(CPUState *cpu, Error **errp)
 {
+    KVMState *s = kvm_state;
+    X86CPU *x86_cpu = X86_CPU(cpu);
+
+    if (!pmu_cap_set && kvm_check_extension(s, KVM_CAP_PMU_CAPABILITY)) {
+        int r = kvm_vm_enable_cap(s, KVM_CAP_PMU_CAPABILITY, 0,
+                                  KVM_PMU_CAP_DISABLE & !x86_cpu->enable_pmu);
+        if (r < 0) {
+            error_report("kvm: Failed to %s pmu cap: %s",
+                         x86_cpu->enable_pmu ? "enable" : "disable",
+                         strerror(-r));
+            return r;
+        }
+
+        pmu_cap_set = true;
+    }
+
     return 0;
 }
 
-- 
2.40.1





[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