arm64: add an option to turn on/off vpmu support
RFC PATCH 1/1 arm64: add an option to turn on/off vpmu support
This patch adds a pmu=[on/off] option to enable/disable vpmu support in guest vm. There are several reasons to justify this option. First vpmu can be problematic for cross-migration between different SoC as perf counters is architecture-dependent. It is more flexible to have an option to turn it on/off. Secondly it matches the -cpu pmu option in libivrt. This patch has been tested on both DT/ACPI modes.
--- hw/arm/virt-acpi-build.c | 2 +- hw/arm/virt.c | 2 +- target-arm/cpu.c | 1 + target-arm/cpu.h | 5 +++-- target-arm/kvm64.c | 10 +++++----- 5 files changed, 11 insertions(+), 9 deletions(-)
hw/arm/virt-acpi-build.c +1 -1
@@ -540,7 +540,7 @@ build_madt(GArray *table_data, BIOSLinker *linker, VirtGuestInfo *guest_info) gicc->uid = i; gicc->flags =cpu_to_le32 (ACPI_GICC_ENABLED ); -if (armcpu->has_pmu) { +if (armcpu->enable_pmu) { gicc->performance_interrupt =cpu_to_le32 (PPI (VIRTUAL_PMU_IRQ )); } }
hw/arm/virt.c +1 -1
@@ -477,7 +477,7 @@ static void fdt_add_pmu_nodes(const VirtBoardInfo *vbi, int gictype)CPU_FOREACH (cpu) { armcpu =ARM_CPU (cpu); -if (!armcpu->has_pmu || +if (!armcpu->enable_pmu || !kvm_arm_pmu_create (cpu,PPI (VIRTUAL_PMU_IRQ ))) {return ; }
target-arm/cpu.c +1 -0
@@ -1412,6 +1412,7 @@ static const ARMCPUInfo arm_cpus[] = { };static Property arm_cpu_properties[] = { +DEFINE_PROP_BOOL ("pmu" ,ARMCPU , enable_pmu, true),DEFINE_PROP_BOOL ("start-powered-off" ,ARMCPU , start_powered_off, false),DEFINE_PROP_UINT32 ("psci-conduit" ,ARMCPU , psci_conduit,0 ),DEFINE_PROP_UINT32 ("midr" ,ARMCPU , midr,0 ),
target-arm/cpu.h +3 -2
@@ -579,8 +579,9 @@ struct ARMCPU {bool powered_off;/* CPU has security extension */ bool has_el3; -/* CPU has PMU (Performance Monitor Unit) */ -bool has_pmu; + +/* CPU has vPMU (Performance Monitor Unit) support */ +bool enable_pmu;/* CPU has memory protection unit */ bool has_mpu;
target-arm/kvm64.c +5 -5
@@ -501,11 +501,11 @@ int kvm_arch_init_vcpu(CPUState *cs)if (!arm_feature (&cpu->env,ARM_FEATURE_AARCH64 )) { cpu->kvm_init_features[0 ] |=1 <<KVM_ARM_VCPU_EL1_32BIT ; } -if (kvm_irqchip_in_kernel () && -kvm_check_extension (cs->kvm_state,KVM_CAP_ARM_PMU_V3 )) { - cpu->has_pmu = true; - cpu->kvm_init_features[0 ] |=1 <<KVM_ARM_VCPU_PMU_V3 ; - } + +/* enable vPMU based on KVM mode and hardware capability */ + cpu->enable_pmu &= (kvm_irqchip_in_kernel () && +kvm_check_extension (cs->kvm_state,KVM_CAP_ARM_PMU_V3 )); + cpu->kvm_init_features[0 ] |= cpu->enable_pmu <<KVM_ARM_VCPU_PMU_V3 ;/* Do KVM_ARM_VCPU_INIT ioctl */ ret =kvm_arm_vcpu_init (cs);
Signature · 1 line
2.4.11
Quoted 8 lines · Wei Huang
This patch adds a pmu=[on/off] option to enable/disable vpmu support in guest vm. There are several reasons to justify this option. First vpmu can be problematic for cross-migration between different SoC as perf counters is architecture-dependent. It is more flexible to have an option to turn it on/off. Secondly it matches the -cpu pmu option in libivrt. This patch has been tested on both DT/ACPI modes.
Signed-off-by Wei Huang <[email protected]>
Reviewed-by:Shannon Zhao <[email protected]>
Quoted 84 lines
--- hw/arm/virt-acpi-build.c | 2 +- hw/arm/virt.c | 2 +- target-arm/cpu.c | 1 + target-arm/cpu.h | 5 +++-- target-arm/kvm64.c | 10 +++++----- 5 files changed, 11 insertions(+), 9 deletions(-)hw/arm/virt-acpi-build.c +1
-1@@ -540,7 +540,7 @@ build_madt(GArray *table_data, BIOSLinker *linker, VirtGuestInfo *guest_info) gicc->uid = i; gicc->flags =cpu_to_le32 (ACPI_GICC_ENABLED ); -if (armcpu->has_pmu) { +if (armcpu->enable_pmu) { gicc->performance_interrupt =cpu_to_le32 (PPI (VIRTUAL_PMU_IRQ )); } }hw/arm/virt.c +1
-1@@ -477,7 +477,7 @@ static void fdt_add_pmu_nodes(const VirtBoardInfo *vbi, int gictype)CPU_FOREACH (cpu) { armcpu =ARM_CPU (cpu); -if (!armcpu->has_pmu || +if (!armcpu->enable_pmu || !kvm_arm_pmu_create (cpu,PPI (VIRTUAL_PMU_IRQ ))) {return ; }target-arm/cpu.c +1
-0@@ -1412,6 +1412,7 @@ static const ARMCPUInfo arm_cpus[] = { };static Property arm_cpu_properties[] = { +DEFINE_PROP_BOOL ("pmu" ,ARMCPU , enable_pmu, true),DEFINE_PROP_BOOL ("start-powered-off" ,ARMCPU , start_powered_off, false),DEFINE_PROP_UINT32 ("psci-conduit" ,ARMCPU , psci_conduit,0 ),DEFINE_PROP_UINT32 ("midr" ,ARMCPU , midr,0 ),target-arm/cpu.h +3
-2@@ -579,8 +579,9 @@ struct ARMCPU {bool powered_off;/* CPU has security extension */ bool has_el3; -/* CPU has PMU (Performance Monitor Unit) */ -bool has_pmu; + +/* CPU has vPMU (Performance Monitor Unit) support */ +bool enable_pmu;/* CPU has memory protection unit */ bool has_mpu;target-arm/kvm64.c +5
-5@@ -501,11 +501,11 @@ int kvm_arch_init_vcpu(CPUState *cs)if (!arm_feature (&cpu->env,ARM_FEATURE_AARCH64 )) { cpu->kvm_init_features[0 ] |=1 <<KVM_ARM_VCPU_EL1_32BIT ; } -if (kvm_irqchip_in_kernel () && -kvm_check_extension (cs->kvm_state,KVM_CAP_ARM_PMU_V3 )) { - cpu->has_pmu = true; - cpu->kvm_init_features[0 ] |=1 <<KVM_ARM_VCPU_PMU_V3 ; - } + +/* enable vPMU based on KVM mode and hardware capability */ + cpu->enable_pmu &= (kvm_irqchip_in_kernel () && +kvm_check_extension (cs->kvm_state,KVM_CAP_ARM_PMU_V3 )); + cpu->kvm_init_features[0 ] |= cpu->enable_pmu <<KVM_ARM_VCPU_PMU_V3 ;/* Do KVM_ARM_VCPU_INIT ioctl */ ret =kvm_arm_vcpu_init (cs);
Signature · 1 line
Shannon
Quoted 47 lines · Wei Huang
This patch adds a pmu=[on/off] option to enable/disable vpmu support in guest vm. There are several reasons to justify this option. First vpmu can be problematic for cross-migration between different SoC as perf counters is architecture-dependent. It is more flexible to have an option to turn it on/off. Secondly it matches the -cpu pmu option in libivrt. This patch has been tested on both DT/ACPI modes.
Signed-off-by Wei Huang <[email protected]>--- hw/arm/virt-acpi-build.c | 2 +- hw/arm/virt.c | 2 +- target-arm/cpu.c | 1 + target-arm/cpu.h | 5 +++-- target-arm/kvm64.c | 10 +++++----- 5 files changed, 11 insertions(+), 9 deletions(-)hw/arm/virt-acpi-build.c +1
-1@@ -540,7 +540,7 @@ build_madt(GArray *table_data, BIOSLinker *linker, VirtGuestInfo *guest_info) gicc->uid = i; gicc->flags =cpu_to_le32 (ACPI_GICC_ENABLED ); -if (armcpu->has_pmu) { +if (armcpu->enable_pmu) { gicc->performance_interrupt =cpu_to_le32 (PPI (VIRTUAL_PMU_IRQ )); } }hw/arm/virt.c +1
-1@@ -477,7 +477,7 @@ static void fdt_add_pmu_nodes(const VirtBoardInfo *vbi, int gictype)CPU_FOREACH (cpu) { armcpu =ARM_CPU (cpu); -if (!armcpu->has_pmu || +if (!armcpu->enable_pmu || !kvm_arm_pmu_create (cpu,PPI (VIRTUAL_PMU_IRQ ))) {return ; }target-arm/cpu.c +0
-0
target-arm/cpu.c static const ARMCPUInfo arm_cpus[] = { · line 1415
Quoted 4 lines
target-arm/cpu.c +1
-0@@ -1412,6 +1412,7 @@ static const ARMCPUInfo arm_cpus[] = { };static Property arm_cpu_properties[] = { +DEFINE_PROP_BOOL ("pmu" ,ARMCPU , enable_pmu, true),
x86's pmu property defaults to off. I'm not sure if it's necessary to have a consistent default between x86 and arm in order for libvirt to be able to use it in the same way. We should confirm with libvirt people. Anyway, I think I'd prefer we default off here, and then we can default on in machine code for configurations that we want it by default (only AArch64 KVM). Or, maybe we don't want it by default at all? Possibly we should only set it on by default for virt-2.6, and then, from 2.7 on, require users to opt-in to the feature. It makes sense to require opting-in to features that can cause problems with migration.
Quoted 26 lines
target-arm/cpu.c +0
-0DEFINE_PROP_BOOL ("start-powered-off" ,ARMCPU , start_powered_off, false),DEFINE_PROP_UINT32 ("psci-conduit" ,ARMCPU , psci_conduit,0 ), DEFINE_PROP_UINT32("midr", ARMCPU, midr, 0),target-arm/cpu.h +3
-2@@ -579,8 +579,9 @@ struct ARMCPU {bool powered_off;/* CPU has security extension */ bool has_el3; -/* CPU has PMU (Performance Monitor Unit) */ -bool has_pmu; + +/* CPU has vPMU (Performance Monitor Unit) support */ +bool enable_pmu;/* CPU has memory protection unit */ bool has_mpu;target-arm/kvm64.c +0
-0@@ -501,11 +501,11 @@ int kvm_arch_init_vcpu(CPUState *cs)if (!arm_feature (&cpu->env,ARM_FEATURE_AARCH64 )) { cpu->kvm_init_features[0 ] |=1 <<KVM_ARM_VCPU_EL1_32BIT ;
target-arm/kvm64.c int kvm_arch_init_vcpu(CPUState *cs) · line 507
Quoted 10 lines
target-arm/kvm64.c +4
-5} -if (kvm_irqchip_in_kernel () && -kvm_check_extension (cs->kvm_state,KVM_CAP_ARM_PMU_V3 )) { - cpu->has_pmu = true; - cpu->kvm_init_features[0 ] |=1 <<KVM_ARM_VCPU_PMU_V3 ; - } + +/* enable vPMU based on KVM mode and hardware capability */ + cpu->enable_pmu &= (kvm_irqchip_in_kernel () && +kvm_check_extension (cs->kvm_state,KVM_CAP_ARM_PMU_V3 ));
nit: the () aren't necessary
Quoted 8 lines
target-arm/kvm64.c +1
-0+ cpu->kvm_init_features[0 ] |= cpu->enable_pmu <<KVM_ARM_VCPU_PMU_V3 ;/* Do KVM_ARM_VCPU_INIT ioctl */ ret =kvm_arm_vcpu_init (cs);Signature · 1 line
2.4.11
OK, so this property will be exposed to all ARM cpu types, and if a user turns it on, then it will stay on for all types, except when using KVM with an aarch64 cpu type, and KVM doesn't support it. This could mislead users to believe they'll get a pmu, by simply adding pmu=on, even when they can't. I think we'd ideally keep has_pmu, and the current code that sets it, and then add code like
if (enable_pmu && !has_pmu) {
error_report("Warning: ...")
}
somewhere. Unfortunately I don't think there's any one place we could add that. We'd need to add it to every ARM machine type that cares about not misleading users. Too bad cpu properties aren't whitelisted by machines to avoid this issue.
Anyway, all that said, I see this is just how cpu properties currently work, so we probably don't need to worry about it for every machine. I do still suggest we add the above warning to mach-virt though.
Thanks,
drew
Quoted 50 lines · Andrew Jones
Quoted 49 lines · Wei Huang
This patch adds a pmu=[on/off] option to enable/disable vpmu support in guest vm. There are several reasons to justify this option. First vpmu can be problematic for cross-migration between different SoC as perf counters is architecture-dependent. It is more flexible to have an option to turn it on/off. Secondly it matches the -cpu pmu option in libivrt. This patch has been tested on both DT/ACPI modes.
Signed-off-by Wei Huang <[email protected]>--- hw/arm/virt-acpi-build.c | 2 +- hw/arm/virt.c | 2 +- target-arm/cpu.c | 1 + target-arm/cpu.h | 5 +++-- target-arm/kvm64.c | 10 +++++----- 5 files changed, 11 insertions(+), 9 deletions(-)hw/arm/virt-acpi-build.c +1
-1@@ -540,7 +540,7 @@ build_madt(GArray *table_data, BIOSLinker *linker, VirtGuestInfo *guest_info) gicc->uid = i; gicc->flags =cpu_to_le32 (ACPI_GICC_ENABLED ); -if (armcpu->has_pmu) { +if (armcpu->enable_pmu) { gicc->performance_interrupt =cpu_to_le32 (PPI (VIRTUAL_PMU_IRQ )); } }hw/arm/virt.c +1
-1@@ -477,7 +477,7 @@ static void fdt_add_pmu_nodes(const VirtBoardInfo *vbi, int gictype)CPU_FOREACH (cpu) { armcpu =ARM_CPU (cpu); -if (!armcpu->has_pmu || +if (!armcpu->enable_pmu || !kvm_arm_pmu_create (cpu,PPI (VIRTUAL_PMU_IRQ ))) {return ; }target-arm/cpu.c +0
-0@@ -1412,6 +1412,7 @@ static const ARMCPUInfo arm_cpus[] = { };
Quoted 13 lines
target-arm/cpu.c static const ARMCPUInfo arm_cpus[] = { · line 1415
Quoted 2 lines
target-arm/cpu.c +1
-0static Property arm_cpu_properties[] = { +DEFINE_PROP_BOOL ("pmu" ,ARMCPU , enable_pmu, true),x86's pmu property defaults to off. I'm not sure if it's necessary to have a consistent default between x86 and arm in order for libvirt to be able to use it in the same way. We should confirm with libvirt people. Anyway, I think I'd prefer we default off here, and then we can default on in machine code for configurations that we want it by default (only AArch64 KVM). Or, maybe we don't want it by default at all? Possibly we should only set it on by default for virt-2.6, and then, from 2.7 on, require users to opt-in to the feature. It makes sense to require opting-in to features that can cause problems with migration.
This option is default=off on x86. I agree that it is a compatibility related issue which can break migration. So it is reasonable to turn it off on ARM as well. Let us wait for libvirt people to voice out.
Quoted 31 lines
Quoted 31 lines
target-arm/cpu.c +0
-0DEFINE_PROP_BOOL ("start-powered-off" ,ARMCPU , start_powered_off, false),DEFINE_PROP_UINT32 ("psci-conduit" ,ARMCPU , psci_conduit,0 ), DEFINE_PROP_UINT32("midr", ARMCPU, midr, 0),target-arm/cpu.h +3
-2@@ -579,8 +579,9 @@ struct ARMCPU {bool powered_off;/* CPU has security extension */ bool has_el3; -/* CPU has PMU (Performance Monitor Unit) */ -bool has_pmu; + +/* CPU has vPMU (Performance Monitor Unit) support */ +bool enable_pmu;/* CPU has memory protection unit */ bool has_mpu;target-arm/kvm64.c +0
-3@@ -501,11 +501,11 @@ int kvm_arch_init_vcpu(CPUState *cs)if (!arm_feature (&cpu->env,ARM_FEATURE_AARCH64 )) { cpu->kvm_init_features[0 ] |=1 <<KVM_ARM_VCPU_EL1_32BIT ; } -if (kvm_irqchip_in_kernel () && -kvm_check_extension (cs->kvm_state,KVM_CAP_ARM_PMU_V3 )) { - cpu->has_pmu = true;
Quoted 9 lines
target-arm/kvm64.c int kvm_arch_init_vcpu(CPUState *cs) · line 507
Quoted 6 lines
target-arm/kvm64.c +4
-2- cpu->kvm_init_features[0 ] |=1 <<KVM_ARM_VCPU_PMU_V3 ; - } + +/* enable vPMU based on KVM mode and hardware capability */ + cpu->enable_pmu &= (kvm_irqchip_in_kernel () && +kvm_check_extension (cs->kvm_state,KVM_CAP_ARM_PMU_V3 ));nit: the () aren't necessary
Will fix
Quoted 20 lines
Quoted 8 lines
target-arm/kvm64.c +1
-0+ cpu->kvm_init_features[0 ] |= cpu->enable_pmu <<KVM_ARM_VCPU_PMU_V3 ;/* Do KVM_ARM_VCPU_INIT ioctl */ ret =kvm_arm_vcpu_init (cs);Signature · 1 line
2.4.11OK, so this property will be exposed to all ARM cpu types, and if a user turns it on, then it will stay on for all types, except when using KVM with an aarch64 cpu type, and KVM doesn't support it. This could mislead users to believe they'll get a pmu, by simply adding pmu=on, even when they can't. I think we'd ideally keep
has_pmu, and the current code that sets it, and then add code likeif (enable_pmu && !has_pmu) { error_report("Warning: ...")}
Quoted 8 lines
somewhere. Unfortunately I don't think there's any one place we could add that. We'd need to add it to every ARM machine type that cares about not misleading users. Too bad cpu properties aren't whitelisted by machines to avoid this issue.
Anyway, all that said, I see this is just how cpu properties currently work, so we probably don't need to worry about it for every machine. I do still suggest we add the above warning to mach-virt though.
Will try to keep both has_pmu & enable_pmu in the next re-spin...
Quoted 4 lines
Thanks,
drew
Quoted 7 lines · Andrew Jones
OK, so this property will be exposed to all ARM cpu types, and if a user turns it on, then it will stay on for all types, except when using KVM with an aarch64 cpu type, and KVM doesn't support it. This could mislead users to believe they'll get a pmu, by simply adding pmu=on, even when they can't. I think we'd ideally keep
has_pmu, and the current code that sets it, and then add code like
Quoted 5 lines
if (enable_pmu && !has_pmu) { error_report("Warning: ...")}
somewhere.
I think we should probably follow the existing model used by has_el3, where the property only exists if it's valid to set it.
thanks
-- PMM
Quoted 56 lines · Andrew Jones
Quoted 49 lines · Wei Huang
This patch adds a pmu=[on/off] option to enable/disable vpmu support in guest vm. There are several reasons to justify this option. First vpmu can be problematic for cross-migration between different SoC as perf counters is architecture-dependent. It is more flexible to have an option to turn it on/off. Secondly it matches the -cpu pmu option in libivrt. This patch has been tested on both DT/ACPI modes.Signed-off-by Wei Huang <[email protected]>---
hw/arm/virt-acpi-build.c | 2 +-
hw/arm/virt.c | 2 +-
target-arm/cpu.c | 1 +
target-arm/cpu.h | 5 +++--
target-arm/kvm64.c | 10 +++++-----5 files changed, 11 insertions(+), 9 deletions(-)hw/arm/virt-acpi-build.c +0
-0@@ -540,7 +540,7 @@ build_madt(GArray *table_data, BIOSLinker *linker, VirtGuestInfo *guest_info) gicc->uid = i; gicc->flags = cpu_to_le32(ACPI_GICC_ENABLED);
- if (armcpu->has_pmu) {
+ if (armcpu->enable_pmu) {
gicc->performance_interrupt = cpu_to_le32(PPI(VIRTUAL_PMU_IRQ)); }
}hw/arm/virt.c +0
-0@@ -477,7 +477,7 @@ static void fdt_add_pmu_nodes(const VirtBoardInfo *vbi, int gictype)
CPU_FOREACH(cpu) {
armcpu =ARM_CPU(cpu);
- if (!armcpu->has_pmu ||
+ if (!armcpu->enable_pmu || !kvm_arm_pmu_create(cpu,PPI(VIRTUAL_PMU_IRQ))) { return;
}target-arm/cpu.c +0
-0@@ -1412,6 +1412,7 @@ static const ARMCPUInfo arm_cpus[] = { };Quoted 3 lines
static Property arm_cpu_properties[] = {
+ DEFINE_PROP_BOOL("pmu", ARMCPU,enable_pmu, true),
x86's pmu property defaults to off. I'm not sure if it's necessary to have a consistent default between x86 and arm in order for libvirt to
Quoted 8 lines
be able to use it in the same way. We should confirm with libvirt people. Anyway, I think I'd prefer we default off here, and then we can default on in machine code for configurations that we want it by default (only AArch64 KVM). Or, maybe we don't want it by default at all? Possibly we should only set it on by default for virt-2.6, and then, from 2.7 on, require users to opt-in to the feature. It makes sense to require opting-in to features that can cause problems with migration.
After thinking about this a bit, I don't think it matters that much (from libvirt's point of view) whether the default is on or off - there are a bunch of other situations where the user is required to specify explicitly whether he wants the feature or not, and if he doesn't choose either side he will get whatever QEMU uses as a default.
What's important is that the user can pick one or the other when it matters to him, and having a pmu property like the one x86 already has fits the bill.
That said, defaulting to off looks like it would be the least confusing behaviour.
Quoted 16 lines
Quoted 4 lines
+ cpu->kvm_init_features[0] |=
cpu->enable_pmu<<KVM_ARM_VCPU_PMU_V3;
/* DoKVM_ARM_VCPU_INITioctl */
ret =kvm_arm_vcpu_init(cs);
OK, so this property will be exposed to all ARM cpu types, and if a user turns it on, then it will stay on for all types, except when using KVM with an aarch64 cpu type, and KVM doesn't support it. This could mislead users to believe they'll get a pmu, by simply adding pmu=on, even when they can't. I think we'd ideally keephas_pmu, and the current code that sets it, and then add code like
if (enable_pmu&& !has_pmu) {
error_report("Warning: ...")
}
Quoted 8 lines
somewhere. Unfortunately I don't think there's any one place we could add that. We'd need to add it to every ARM machine type that cares about not misleading users. Too bad cpu properties aren't whitelisted by machines to avoid this issue.
Anyway, all that said, I see this is just how cpu properties currently work, so we probably don't need to worry about it for every machine. I do still suggest we add the above warning to mach-virt though.
I'm not sure a warning is enough: if I start a guest and explicitly ask for a PMU, I expect it to be there, or for the guest not to start at all. How does x86 behave in this regard?
--
Andrea Bolognani / Red Hat / Virtualization
Quoted 73 lines · Andrea Bolognani
Quoted 56 lines · Andrew Jones
Quoted 49 lines · Wei Huang
This patch adds a pmu=[on/off] option to enable/disable vpmu support in guest vm. There are several reasons to justify this option. First vpmu can be problematic for cross-migration between different SoC as perf counters is architecture-dependent. It is more flexible to have an option to turn it on/off. Secondly it matches the -cpu pmu option in libivrt. This patch has been tested on both DT/ACPI modes.Signed-off-by Wei Huang <[email protected]>---
hw/arm/virt-acpi-build.c | 2 +-
hw/arm/virt.c | 2 +-
target-arm/cpu.c | 1 +
target-arm/cpu.h | 5 +++--
target-arm/kvm64.c | 10 +++++-----5 files changed, 11 insertions(+), 9 deletions(-)hw/arm/virt-acpi-build.c +0
-0@@ -540,7 +540,7 @@ build_madt(GArray *table_data, BIOSLinker *linker, VirtGuestInfo *guest_info) gicc->uid = i; gicc->flags = cpu_to_le32(ACPI_GICC_ENABLED);
- if (armcpu->has_pmu) {
+ if (armcpu->enable_pmu) {
gicc->performance_interrupt = cpu_to_le32(PPI(VIRTUAL_PMU_IRQ)); }
}hw/arm/virt.c +0
-0@@ -477,7 +477,7 @@ static void fdt_add_pmu_nodes(const VirtBoardInfo *vbi, int gictype)
CPU_FOREACH(cpu) {
armcpu =ARM_CPU(cpu);
- if (!armcpu->has_pmu ||
+ if (!armcpu->enable_pmu || !kvm_arm_pmu_create(cpu,PPI(VIRTUAL_PMU_IRQ))) { return;
}target-arm/cpu.c +0
-0@@ -1412,6 +1412,7 @@ static const ARMCPUInfo arm_cpus[] = { };Quoted 3 lines
static Property arm_cpu_properties[] = {
+ DEFINE_PROP_BOOL("pmu", ARMCPU,enable_pmu, true),
x86's pmu property defaults to off. I'm not sure if it's necessary to have a consistent default between x86 and arm in order for libvirt toQuoted 8 lines
be able to use it in the same way. We should confirm with libvirt people. Anyway, I think I'd prefer we default off here, and then we can default on in machine code for configurations that we want it by default (only AArch64 KVM). Or, maybe we don't want it by default at all? Possibly we should only set it on by default for virt-2.6, and then, from 2.7 on, require users to opt-in to the feature. It makes sense to require opting-in to features that can cause problems with migration.
After thinking about this a bit, I don't think it matters that much (from libvirt's point of view) whether the default is on or off - there are a bunch of other situations where the user is required to specify explicitly whether he wants the feature or not, and if he doesn't choose either side he will get whatever QEMU uses as a default.
Quoted 6 lines
What's important is that the user can pick one or the other when it matters to him, and having a pmu property like the one x86 already has fits the bill.
That said, defaulting to off looks like it would be the least confusing behaviour.
OK, so the default is still up for debate.
Pros of ON Cons of ON ---------- ---------- We already do it The default instance is less migratable
Less typing on cmdline
(libvirt covers typing for us anyway...)
Pros of OFF Cons of OFF ----------- ----------- See 'Cons of ON' See 'Pros on ON' (virt-2.6 needs compat code)
Quoted 26 lines
Quoted 17 lines
Quoted 5 lines
+ cpu->kvm_init_features[0] |=
cpu->enable_pmu<<KVM_ARM_VCPU_PMU_V3;
/* DoKVM_ARM_VCPU_INITioctl */
ret =kvm_arm_vcpu_init(cs);
OK, so this property will be exposed to all ARM cpu types, and if a user turns it on, then it will stay on for all types, except when using KVM with an aarch64 cpu type, and KVM doesn't support it. This could mislead users to believe they'll get a pmu, by simply adding pmu=on, even when they can't. I think we'd ideally keephas_pmu, and the current code that sets it, and then add code like
if (enable_pmu&& !has_pmu) {
error_report("Warning: ...")
}Quoted 8 lines
somewhere. Unfortunately I don't think there's any one place we could add that. We'd need to add it to every ARM machine type that cares about not misleading users. Too bad cpu properties aren't whitelisted by machines to avoid this issue.
Anyway, all that said, I see this is just how cpu properties currently work, so we probably don't need to worry about it for every machine. I do still suggest we add the above warning to mach-virt though.
Quoted 4 lines
I'm not sure a warning is enough: if I start a guest and explicitly ask for a PMU, I expect it to be there, or for the guest not to start at all. How does x86 behave in this regard?
Peter had a good suggestion for this. We need to wrap the property addition in an arm_feature check like the has_el3 property. That will remove it from all cpu types that don't support it. Then there's no need for the enable_pmu && !has_pmu check as the has_pmu part is covered very early with the feature flag in arm_cpu_post_init(). Peter also suggested we keep the 'has_pmu' name, rather than change it to 'enable_pmu'. On that one I would disagree. 'has_pmu' indicates that the feature is available at all, which it is to all cpu types that have the arm feature, but not all users will want it enabled. 'enable_pmu', which matches x86's naming, seems more appropriate for that.
Thanks,
drew
Quoted 3 lines
--
Andrea Bolognani / Red Hat / Virtualization
Quoted 10 lines · Andrew Jones
Peter had a good suggestion for this. We need to wrap the property addition in an
arm_featurecheck like thehas_el3property. That will remove it from all cpu types that don't support it. Then there's no need for theenable_pmu&& !has_pmu check as thehas_pmupart is covered very early with the feature flag inarm_cpu_post_init(). Peter also suggested we keep the 'has_pmu' name, rather than change it to 'enable_pmu'. On that one I would disagree. 'has_pmu' indicates that the feature is available at all, which it is to all cpu types that have the arm feature, but not all users will want it enabled. 'enable_pmu', which matches x86's naming, seems more appropriate for that.
If you create the CPU with pmu=off then it does not have a PMU, and so has_pmu is false. I don't see any reason for the naming convention for the PMU to diverge from what we have for EL3 and for the MPU, where the property names and the struct fields both use 'has'.
thanks
-- PMM
Quoted 8 lines · Andrew Jones
Quoted 4 lines
I'm not sure a warning is enough: if I start a guest and explicitly ask for a PMU, I expect it to be there, or for the guest not to start at all. How does x86 behave in this regard?
Peter had a good suggestion for this. We need to wrap the property addition in anarm_featurecheck like thehas_el3property. That will remove it from all cpu types that don't support it.
Wouldn't that mean that you'd be unable to use
-cpu foo,pmu=off
if CPU model 'foo' doesn't support a PMU? I'd expect that to work.
I've played around with this a bit on x86 and it doesn't look like it necessarily behaves the way I'd expect it to, either, so maybe this is just a case of my expectations being unreasonable? :)
--
Andrea Bolognani / Red Hat / Virtualization
Quoted 10 lines · Andrea Bolognani
Quoted 8 lines · Andrew Jones
Quoted 4 lines
I'm not sure a warning is enough: if I start a guest and explicitly ask for a PMU, I expect it to be there, or for the guest not to start at all. How does x86 behave in this regard?
Peter had a good suggestion for this. We need to wrap the property addition in an
arm_featurecheck like thehas_el3property. That will remove it from all cpu types that don't support it.
Quoted 6 lines
Wouldn't that mean that you'd be unable to use
-cpu foo,pmu=off
if CPU model 'foo' doesn't support a PMU? I'd expect that to work.
The current precedent (has_el3) doesn't work like that: if foo isn't a CPU which can support EL3 then the property doesn't exist, and it's an error to try to set it.
thanks
-- PMM
Quoted 10 lines · Peter Maydell
Quoted 6 lines
Wouldn't that mean that you'd be unable to use
-cpu foo,pmu=off
if CPU model 'foo' doesn't support a PMU? I'd expect that to work.
The current precedent (has_el3) doesn't work like that: if foo isn't a CPU which can support EL3 then the property doesn't exist, and it's an error to try to set it.
Doesn't look like the pmu option works like that on x86, though, unless I'm missing something.
I have a guest running with
-cpu pentium,pmu=on
and I can't see hardware perf events from inside the guest, eg. dmesg reports
Performance Events: no PMU driver, software events only.
and perf tells me
<not supported> instructions
<not supported> branches
...
I'm not sure whether that's because the PMU is being emulated but the kernel doesn't have a driver for it, or whether it's not being emulated at all. Any way to find out?
--
Andrea Bolognani / Red Hat / Virtualization
Quoted 13 lines · Peter Maydell
Quoted 12 lines · Andrea Bolognani
Quoted 8 lines · Andrew Jones
Quoted 4 lines
I'm not sure a warning is enough: if I start a guest and explicitly ask for a PMU, I expect it to be there, or for the guest not to start at all. How does x86 behave in this regard?
Peter had a good suggestion for this. We need to wrap the property addition in an
arm_featurecheck like thehas_el3property. That will remove it from all cpu types that don't support it.Wouldn't that mean that you'd be unable to use
Quoted 8 lines
Quoted 4 lines
-cpu foo,pmu=off
if CPU model 'foo' doesn't support a PMU? I'd expect that to work.
The current precedent (
has_el3) doesn't work like that: if foo isn't a CPU which can support EL3 then the property doesn't exist, and it's an error to try to set it.
V1 sent. I tried to follow everyone's advice. See the following:
* set default pmu=off
* like el3, add a new feature ARM_FEATURE_HOST_PMU
* "pmu" property becomes CPU dependent. Only cortex-a53/cortex-a57/host under certain mode support this option
* change struct ARMCPU field name "has_pmu" ==> "has_host_pmu" because IMO "has_pmu" is misleading
BTW answering Andrea's question above: "-cpu foo,pmu=off" won't be allowed in this patch if CPU "foo" doesn't support host-backed PMU. QEMU will fail to run in this case. Maybe this is what we want?
Thanks,
-Wei
Quoted 4 lines
thanks
-- PMM
Quoted 10 lines · Wei Huang
Quoted 10 lines
Quoted 6 lines
Wouldn't that mean that you'd be unable to use
-cpu foo,pmu=off
if CPU model 'foo' doesn't support a PMU? I'd expect that to work.
The current precedent (has_el3) doesn't work like that: if foo isn't a CPU which can support EL3 then the property doesn't exist, and it's an error to try to set it.
Quoted 13 lines
V1 sent. I tried to follow everyone's advice. See the following:
* set default pmu=off
* like el3, add a new featureARM_FEATURE_HOST_PMU
* "pmu" property becomes CPU dependent. Only cortex-a53/cortex-a57/host under certain mode support this option
* change struct ARMCPU field name "has_pmu" ==> "has_host_pmu" because IMO "has_pmu" is misleading
BTW answering Andrea's question above: "-cpu foo,pmu=off" won't be allowed in this patch if CPU "foo" doesn't support host-backed PMU. QEMU will fail to run in this case. Maybe this is what we want?
After discussing this a bit offline, I came to the conclusion that there isn't a Single Right Way™ to handle this - both my proposal and what you implemented are reasonable behaviors one could expect.
On the other hand, what you implemented:
* matches x86
* is more strict than what I proposed, so there's room to change it later without breaking any existing guest
so I'm happy with it :)
--
Andrea Bolognani / Red Hat / Virtualization
Quoted 6 lines · Wei Huang
This patch adds a pmu=[on/off] option to enable/disable vpmu support in guest vm. There are several reasons to justify this option. First vpmu can be problematic for cross-migration between different SoC as perf counters is architecture-dependent. It is more flexible to have an option to turn it on/off. Secondly it matches the -cpu pmu option in libivrt. This patch has been tested on both DT/ACPI modes.
What particular two systems are you trying to migrate between? In general we don't support migrating between different CPU types at the moment, so the PMU sholud be the same on both ends.
(If we ever do get to supporting cross-cpu-type migration then it will probably involve a very long and detailed command line to specify exactly a whole lot of things like pmu yes/no, number of hw breakpoints/watchpoints, and everything else that can differ between implementations.)
That said, I don't have any objection to making the PMU presence controllable (especially if we have similar control on x86).
target-arm/cpu.h struct ARMCPU { · line 584
Quoted 11 lines
target-arm/cpu.h +3
-2@@ -579,8 +579,9 @@ struct ARMCPU {bool powered_off;/* CPU has security extension */ bool has_el3; -/* CPU has PMU (Performance Monitor Unit) */ -bool has_pmu; + +/* CPU has vPMU (Performance Monitor Unit) support */ +bool enable_pmu;
Why rename the flag? has_foo is what we use for other features, as you can see in the context of this bit of the patch.
target-arm/cpu.h struct ARMCPU { · line 587
Quoted 3 lines
target-arm/cpu.h +0
-0/* CPU has memory protection unit */ bool has_mpu;
thanks
-- PMM
Quoted 10 lines · Peter Maydell
Quoted 6 lines · Wei Huang
This patch adds a pmu=[on/off] option to enable/disable vpmu support in guest vm. There are several reasons to justify this option. First vpmu can be problematic for cross-migration between different SoC as perf counters is architecture-dependent. It is more flexible to have an option to turn it on/off. Secondly it matches the -cpu pmu option in libivrt. This patch has been tested on both DT/ACPI modes.
What particular two systems are you trying to migrate between?
One example: APM's Mustang has 5 perf counters while AMD's Seattle has 7 counters.
Quoted 13 lines
In general we don't support migrating between different CPU types at the moment, so the PMU sholud be the same on both ends.
(If we ever do get to supporting cross-cpu-type migration then it will probably involve a very long and detailed command line to specify exactly a whole lot of things like pmu yes/no, number of hw breakpoints/watchpoints, and everything else that can differ between implementations.)
That said, I don't have any objection to making the PMU presence controllable (especially if we have similar control on x86).
Quoted 14 lines
target-arm/cpu.h struct ARMCPU { · line 584
Quoted 11 lines
target-arm/cpu.h +3
-2@@ -579,8 +579,9 @@ struct ARMCPU {bool powered_off;/* CPU has security extension */ bool has_el3; -/* CPU has PMU (Performance Monitor Unit) */ -bool has_pmu; + +/* CPU has vPMU (Performance Monitor Unit) support */ +bool enable_pmu;Why rename the flag?
has_foois what we use for other features, as you can see in the context of this bit of the patch.
I will fix it. Maybe follow the suggestion Drew's suggestion, keeping has_pmu and add another option for turning it on/off.
Quoted 8 lines
target-arm/cpu.h struct ARMCPU { · line 587
Quoted 4 lines
target-arm/cpu.h +0
-0/* CPU has memory protection unit */ bool has_mpu;thanks
-- PMM
Quoted 12 lines · Wei Huang
Quoted 9 lines · Peter Maydell
Quoted 6 lines · Wei Huang
This patch adds a pmu=[on/off] option to enable/disable vpmu support in guest vm. There are several reasons to justify this option. First vpmu can be problematic for cross-migration between different SoC as perf counters is architecture-dependent. It is more flexible to have an option to turn it on/off. Secondly it matches the -cpu pmu option in libivrt. This patch has been tested on both DT/ACPI modes.
Quoted 4 lines
Quoted 1 line
What particular two systems are you trying to migrate between?
One example: APM's Mustang has 5 perf counters while AMD's Seattle has 7 counters.
Right; this is a cross-implementation migration, which isn't supposed to work at the moment, and more will be required for it to work than just pmu on/off.
thanks
-- PMM