Similar to lbr-fmt, target/i386 does not support multi-bit CPU
properties, so the PEBS record format cannot be exposed as a
user-visible CPU feature.
Add a pebs-fmt option to allow users to specify the PEBS format via the
command line. Since the PEBS state is part of the vmstate, this option
is considered migratable.
With this option, PEBS can be enabled when migratable=on.
Signed-off-by: Zide Chen <zide.chen@intel.com>
---
V2: New patch
target/i386/cpu.c | 11 ++++++++++-
target/i386/cpu.h | 5 +++++
target/i386/kvm/kvm-cpu.c | 1 +
3 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 54f04adb0b48..ec6f49916de3 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -9796,7 +9796,9 @@ static bool x86_cpu_apply_lbr_pebs_fmt(X86CPU *cpu, uint64_t host_perf_cap,
shift = PERF_CAP_LBR_FMT_SHIFT;
name = "lbr";
} else {
- return false;
+ mask = PERF_CAP_PEBS_FMT_MASK;
+ shift = PERF_CAP_PEBS_FMT_SHIFT;
+ name = "pebs";
}
if (user_req != -1) {
@@ -9838,6 +9840,11 @@ static int x86_cpu_pmu_realize(X86CPU *cpu, Error **errp)
return -EINVAL;
}
+ if (!x86_cpu_apply_lbr_pebs_fmt(cpu, host_perf_cap,
+ cpu->pebs_fmt, false, errp)) {
+ return -EINVAL;
+ }
+
return 0;
}
@@ -10307,6 +10314,7 @@ static void x86_cpu_initfn(Object *obj)
object_property_add_alias(obj, "hv-apicv", obj, "hv-avic");
object_property_add_alias(obj, "lbr_fmt", obj, "lbr-fmt");
+ object_property_add_alias(obj, "pebs_fmt", obj, "pebs-fmt");
if (xcc->model) {
x86_cpu_load_model(cpu, xcc->model);
@@ -10478,6 +10486,7 @@ static const Property x86_cpu_properties[] = {
DEFINE_PROP_INT32("node-id", X86CPU, node_id, CPU_UNSET_NUMA_NODE_ID),
DEFINE_PROP_BOOL("pmu", X86CPU, enable_pmu, false),
DEFINE_PROP_UINT64_CHECKMASK("lbr-fmt", X86CPU, lbr_fmt, PERF_CAP_LBR_FMT_MASK),
+ DEFINE_PROP_UINT64_CHECKMASK("pebs-fmt", X86CPU, pebs_fmt, PERF_CAP_PEBS_FMT_MASK),
DEFINE_PROP_UINT32("hv-spinlocks", X86CPU, hyperv_spinlock_attempts,
HYPERV_SPINLOCK_NEVER_NOTIFY),
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index aa3c24e0ba13..5ab107dfa29f 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -422,6 +422,8 @@ typedef enum X86Seg {
#define MSR_IA32_PERF_CAPABILITIES 0x345
#define PERF_CAP_LBR_FMT_MASK 0x3f
#define PERF_CAP_LBR_FMT_SHIFT 0x0
+#define PERF_CAP_PEBS_FMT_MASK 0xf
+#define PERF_CAP_PEBS_FMT_SHIFT 0x8
#define PERF_CAP_FULL_WRITE (1U << 13)
#define PERF_CAP_PEBS_BASELINE (1U << 14)
@@ -2399,6 +2401,9 @@ struct ArchCPU {
*/
uint64_t lbr_fmt;
+ /* PEBS_FMT bits in IA32_PERF_CAPABILITIES MSR. */
+ uint64_t pebs_fmt;
+
/* LMCE support can be enabled/disabled via cpu option 'lmce=on/off'. It is
* disabled by default to avoid breaking migration between QEMU with
* different LMCE configurations.
diff --git a/target/i386/kvm/kvm-cpu.c b/target/i386/kvm/kvm-cpu.c
index b4500ab69f82..7029629a9d09 100644
--- a/target/i386/kvm/kvm-cpu.c
+++ b/target/i386/kvm/kvm-cpu.c
@@ -232,6 +232,7 @@ static void kvm_cpu_instance_init(CPUState *cs)
}
cpu->lbr_fmt = -1;
+ cpu->pebs_fmt = -1;
kvm_cpu_xsave_init();
}
--
2.52.0