x86/perfc: assorted adjustments
v2 cover x86/perfc: assorted adjustments
Addressing some observations made while reviewing other patches.
1: VMX: sync VM-exit perf counters with known VM-exit reasons 2: SVM: sync VM-exit perf counters with known VM-exit reasons 3: x86/perfc: fold HVM's VM-exit counter arrays
Jan
PATCH v2 1/3 VMX: sync VM-exit perf counters with known VM-exit reasons
This has gone out of sync over time. Introduce a simplistic mechanism to hopefully keep things in sync going forward.
Also limit the array index to just the "basic exit reason" part, which is what the pseudo-enumeration covers.
---
v2: Use sentinel comment only.
xen/arch/x86/hvm/vmx/vmx.c +1 -1
@@ -3869,7 +3869,7 @@ void vmx_vmexit_handler(struct cpu_user_else HVMTRACE_ND (VMEXIT ,0 ,1 /*cycles*/ , exit_reason, regs->eip); -perfc_incra (vmexits, exit_reason); +perfc_incra (vmexits, (uint16_t )exit_reason);/* Handle the interrupt we missed before allowing any more in. */ switch ( (uint16_t)exit_reason )
xen/arch/x86/include/asm/hvm/vmx/vmx.h +1 -0
@@ -219,6 +219,7 @@ static inline void pi_clear_sn(struct pi#define EXIT_REASON_PML_FULL 62#define EXIT_REASON_XSAVES 63#define EXIT_REASON_XRSTORS 64 +/* Remember to also update VMX_PERF_EXIT_REASON_SIZE! */ /* * Interruption-information format
xen/arch/x86/include/asm/perfc_defn.h +1 -1
@@ -6,7 +6,7 @@ PERFCOUNTER_ARRAY(exceptions,#ifdef CONFIG_HVM -#define VMX_PERF_EXIT_REASON_SIZE 56 +#define VMX_PERF_EXIT_REASON_SIZE 65#define VMX_PERF_VECTOR_SIZE 0x20 PERFCOUNTER_ARRAY(vmexits, "vmexits", VMX_PERF_EXIT_REASON_SIZE)PERFCOUNTER_ARRAY (cause_vector,"cause vector" ,VMX_PERF_VECTOR_SIZE )
RE: [PATCH v2 1/3] VMX: sync VM-exit perf counters with known VM-exit reasons
Quoted 10 lines
From: Beulich
Sent: Wednesday, January 5, 2022 9:58 PMThis has gone out of sync over time. Introduce a simplistic mechanism to hopefully keep things in sync going forward.
Also limit the array index to just the "basic exit reason" part, which is what the pseudo-enumeration covers.
Signed-off-by Jan Beulich <[email protected]>
Quoted 38 lines
---
v2: Use sentinel comment only.xen/arch/x86/hvm/vmx/vmx.c +1
-1@@ -3869,7 +3869,7 @@ void vmx_vmexit_handler(struct cpu_user_else HVMTRACE_ND (VMEXIT ,0 ,1 /*cycles*/ , exit_reason, regs->eip); -perfc_incra (vmexits, exit_reason); +perfc_incra (vmexits, (uint16_t )exit_reason);/* Handle the interrupt we missed before allowing any more in. */ switch ( (uint16_t)exit_reason )xen/arch/x86/include/asm/hvm/vmx/vmx.h +1
-0@@ -219,6 +219,7 @@ static inline void pi_clear_sn(struct pi#define EXIT_REASON_PML_FULL 62#define EXIT_REASON_XSAVES 63#define EXIT_REASON_XRSTORS 64 +/* Remember to also update VMX_PERF_EXIT_REASON_SIZE! */ /* * Interruption-information format xen/arch/x86/include/asm/perfc_defn.h +1
-1@@ -6,7 +6,7 @@ PERFCOUNTER_ARRAY(exceptions,#ifdef CONFIG_HVM -#define VMX_PERF_EXIT_REASON_SIZE 56 +#define VMX_PERF_EXIT_REASON_SIZE 65#define VMX_PERF_VECTOR_SIZE 0x20PERFCOUNTER_ARRAY (vmexits,"vmexits" ,VMX_PERF_EXIT_REASON_SIZE )PERFCOUNTER_ARRAY(cause_vector, "cause vector",
VMX_PERF_VECTOR_SIZE)
PATCH v2 2/3 SVM: sync VM-exit perf counters with known VM-exit reasons
In reply to Jan BeulichThis has gone out of sync over time, resulting in NPF and XSETBV exits incrementing the same counter. Introduce a simplistic mechanism to hopefully keep things in better sync going forward.
---
v2: Use sentinel comments only.
xen/arch/x86/include/asm/hvm/svm/vmcb.h +2 -0
@@ -302,7 +302,9 @@ enum VMEXIT_EXITCODEVMEXIT_MWAIT_CONDITIONAL =140 ,/* 0x8c */ VMEXIT_XSETBV =141 ,/* 0x8d */ VMEXIT_RDPRU =142 ,/* 0x8e */ +/* Remember to also update VMEXIT_NPF_PERFC! */ VMEXIT_NPF =1024 ,/* 0x400, nested paging fault */ +/* Remember to also update SVM_PERF_EXIT_REASON_SIZE! */ VMEXIT_INVALID = -1 };
xen/arch/x86/include/asm/perfc_defn.h +2 -2
@@ -11,8 +11,8 @@ PERFCOUNTER_ARRAY(exceptions, PERFCOUNTER_ARRAY(vmexits, "vmexits", VMX_PERF_EXIT_REASON_SIZE) PERFCOUNTER_ARRAY(cause_vector, "cause vector", VMX_PERF_VECTOR_SIZE) -#define VMEXIT_NPF_PERFC 141 -#define SVM_PERF_EXIT_REASON_SIZE (1+141) +#define VMEXIT_NPF_PERFC 143 +#define SVM_PERF_EXIT_REASON_SIZE (VMEXIT_NPF_PERFC + 1) PERFCOUNTER_ARRAY(svmexits, "SVMexits", SVM_PERF_EXIT_REASON_SIZE)#endif /* CONFIG_HVM */
Re: [PATCH v2 2/3] SVM: sync VM-exit perf counters with known VM-exit reasons
Quoted 5 lines · Jan Beulich
This has gone out of sync over time, resulting in NPF and XSETBV exits incrementing the same counter. Introduce a simplistic mechanism to hopefully keep things in better sync going forward.
Signed-off-by Jan Beulich <[email protected]>
Thanks, Roger.
PATCH v2 3/3 x86/perfc: fold HVM's VM-exit counter arrays
In reply to Jan BeulichOnly one of them can be in use at a time, so make the whole set union- like. While doing the rename in SVM code, combine the two perf_incra(), generalizing the range upwards of VMEXIT_NPF.
---
v2: New.
xen/arch/x86/hvm/svm/svm.c +4 -2
@@ -2644,7 +2644,10 @@ void svm_vmexit_handler(struct cpu_user_ goto out; } -perfc_incra (svmexits, exit_reason); +perfc_incra (vmexits, + exit_reason <VMEXIT_NPF + ? exit_reason + : exit_reason -VMEXIT_NPF +VMEXIT_NPF_PERFC );hvm_maybe_deassert_evtchn_irq ();
@@ -2973,7 +2976,6 @@ void svm_vmexit_handler(struct cpu_user_break ;case VMEXIT_NPF : -perfc_incra (svmexits,VMEXIT_NPF_PERFC );if ( cpu_has_svm_decode ) v->arch.hvm.svm.cached_insn_len = vmcb->guest_ins_len &0xf ; rc = vmcb->exitinfo1 & PFEC_page_present
xen/arch/x86/include/asm/perfc_defn.h +5 -5
@@ -7,13 +7,13 @@ PERFCOUNTER_ARRAY(exceptions,#ifdef CONFIG_HVM #define VMX_PERF_EXIT_REASON_SIZE 65 -#define VMX_PERF_VECTOR_SIZE 0x20 -PERFCOUNTER_ARRAY(vmexits, "vmexits", VMX_PERF_EXIT_REASON_SIZE) -PERFCOUNTER_ARRAY(cause_vector, "cause vector", VMX_PERF_VECTOR_SIZE) -#define VMEXIT_NPF_PERFC 143#define SVM_PERF_EXIT_REASON_SIZE (VMEXIT_NPF_PERFC + 1) -PERFCOUNTER_ARRAY(svmexits, "SVMexits", SVM_PERF_EXIT_REASON_SIZE) +PERFCOUNTER_ARRAY (vmexits,"vmexits" , + MAX(VMX_PERF_EXIT_REASON_SIZE, SVM_PERF_EXIT_REASON_SIZE)) + +#define VMX_PERF_VECTOR_SIZE 0x20 +PERFCOUNTER_ARRAY(cause_vector, "cause vector", VMX_PERF_VECTOR_SIZE)#endif /* CONFIG_HVM */
Re: [PATCH v2 3/3] x86/perfc: fold HVM's VM-exit counter arrays
Quoted 5 lines · Jan Beulich
Only one of them can be in use at a time, so make the whole set union- like. While doing the rename in SVM code, combine the two
perf_incra(), generalizing the range upwards ofVMEXIT_NPF.Signed-off-by Jan Beulich <[email protected]>
Quoted 6 lines
---
v2: New.
xen/arch/x86/hvm/svm/svm.c void svm_vmexit_handler(struct cpu_user_ · line 2650
Quoted 8 lines
xen/arch/x86/hvm/svm/svm.c +4
-1@@ -2644,7 +2644,10 @@ void svm_vmexit_handler(struct cpu_user_ goto out; } -perfc_incra (svmexits, exit_reason); +perfc_incra (vmexits, + exit_reason <VMEXIT_NPF + ? exit_reason + : exit_reason -VMEXIT_NPF +VMEXIT_NPF_PERFC );
Should we assert that the index used here < SVM_PERF_EXIT_REASON_SIZE?
Just so that adding new exit reasons without increasing SVM_PERF_EXIT_REASON_SIZE is not likely to go unnoticed?
Thanks, Roger.
Re: [PATCH v2 3/3] x86/perfc: fold HVM's VM-exit counter arrays
Quoted 8 lines · Roger Pau Monné
Quoted 5 lines · Jan Beulich
Only one of them can be in use at a time, so make the whole set union- like. While doing the rename in SVM code, combine the two
perf_incra(), generalizing the range upwards ofVMEXIT_NPF.Signed-off-by Jan Beulich <[email protected]>Reviewed-by Roger Pau Monné <[email protected]>
Thanks.
Quoted 14 lines
xen/arch/x86/hvm/svm/svm.c void svm_vmexit_handler(struct cpu_user_ · line 2650
Quoted 11 lines
xen/arch/x86/hvm/svm/svm.c +4
-1@@ -2644,7 +2644,10 @@ void svm_vmexit_handler(struct cpu_user_ goto out; } -perfc_incra (svmexits, exit_reason); +perfc_incra (vmexits, + exit_reason <VMEXIT_NPF + ? exit_reason + : exit_reason -VMEXIT_NPF +VMEXIT_NPF_PERFC );Should we assert that the index used here <
SVM_PERF_EXIT_REASON_SIZE?
Quoted 2 lines
Just so that adding new exit reasons without increasing
SVM_PERF_EXIT_REASON_SIZEis not likely to go unnoticed?
But that's what the comments are for that the previous patch adds.
Jan
Ping: [PATCH v2 0/3] x86/perfc: assorted adjustments
In reply to Jan BeulichQuoted 5 lines · Jan Beulich
Addressing some observations made while reviewing other patches.
1: VMX: sync VM-exit perf counters with known VM-exit reasons 2: SVM: sync VM-exit perf counters with known VM-exit reasons 3: x86/perfc: fold HVM's VM-exit counter arrays
Patch 1 has gone in a little while ago. Would be nice for the other two to also be acked, or for adjustment requests to be voiced.
Thanks, Jan