[PATCH v2 3/3] x86/perfc: fold HVM's VM-exit counter arrays

Jan Beulich posted 3 patches 4 years, 1 month ago
[PATCH v2 3/3] x86/perfc: fold HVM's VM-exit counter arrays
Posted by Jan Beulich 4 years, 1 month ago
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 of VMEXIT_NPF.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
---
v2: New.

--- a/xen/arch/x86/hvm/svm/svm.c
+++ b/xen/arch/x86/hvm/svm/svm.c
@@ -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
--- a/xen/arch/x86/include/asm/perfc_defn.h
+++ b/xen/arch/x86/include/asm/perfc_defn.h
@@ -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
Posted by Roger Pau Monné 3 years, 11 months ago
On Wed, Jan 05, 2022 at 02:59:03PM +0100, Jan Beulich wrote:
> 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 of VMEXIT_NPF.
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>

> ---
> v2: New.
> 
> --- a/xen/arch/x86/hvm/svm/svm.c
> +++ b/xen/arch/x86/hvm/svm/svm.c
> @@ -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
Posted by Jan Beulich 3 years, 11 months ago
On 22.02.2022 10:40, Roger Pau Monné wrote:
> On Wed, Jan 05, 2022 at 02:59:03PM +0100, Jan Beulich wrote:
>> 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 of VMEXIT_NPF.
>>
>> Signed-off-by: Jan Beulich <jbeulich@suse.com>
> 
> Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>

Thanks.

>> --- a/xen/arch/x86/hvm/svm/svm.c
>> +++ b/xen/arch/x86/hvm/svm/svm.c
>> @@ -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?

But that's what the comments are for that the previous patch adds.

Jan