Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 27 Mar 2023 06:40:11 GMT
From:      =?utf-8?Q?Corvin=20K=C3=B6hne?= <corvink@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 6dace6a5cc84 - stable/13 - vmm: fix missing ipi statistic
Message-ID:  <202303270640.32R6eBYb086570@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by corvink:

URL: https://cgit.FreeBSD.org/src/commit/?id=6dace6a5cc84644668a66d58502b779243a666f0

commit 6dace6a5cc84644668a66d58502b779243a666f0
Author:     Vitaliy Gusev <gusev.vitaliy@gmail.com>
AuthorDate: 2023-03-17 09:17:22 +0000
Commit:     Corvin Köhne <corvink@FreeBSD.org>
CommitDate: 2023-03-27 06:33:00 +0000

    vmm: fix missing ipi statistic
    
    ipi counters are missing in bhyvectl's output because vm_maxcpu is 0
    when initializing them. That's because vmm_stat_register is executed
    before vmm_init.
    
    Instead of directly fixing it, there's a better solution in illumos
    which is cherry picked:
    https://github.com/illumos/illumos-gate/commit/65a3bc83734e5fb0fc2c19df3e5112b87dcdc3f8
    
    It replaces the matrix statistic by two counters per vcpu. One for
    counting the ipis to the vcpu and one counting the ipis received by the
    vcpu. This has several advantages:
    
    - A matrix statistic becomes huge when using many vcpus.
    - A matrix statistic easily reaches the MAX_VMM_STAT_ELEMS limit.
    - Two counters are enough in most cases. DTrace can be used for more
      advanced debugging purposes.
    - A matrix statistic wastes memory. The matrix size is determined by
      vm_maxcpu regardless of the number of vcpus assigned to the vm.
    
    Reviewed by:            corvink, markj
    Fixes:                  ee98f99d7a68b284a669fefb969cbfc31df2d0ab ("vmm: Convert VM_MAXCPU into a loader tunable hw.vmm.maxcpu.")
    MFC after:              1 week
    Sponsored by:           vStack
    Differential Revision:  https://reviews.freebsd.org/D39038
    
    (cherry picked from commit 94a3876d7e18ada9596464623829d37d186da856)
---
 sys/amd64/vmm/io/vlapic.c | 9 ++++++---
 sys/amd64/vmm/vmm_stat.c  | 3 ---
 sys/amd64/vmm/vmm_stat.h  | 2 --
 3 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/sys/amd64/vmm/io/vlapic.c b/sys/amd64/vmm/io/vlapic.c
index 884e232b1422..2144cbabd979 100644
--- a/sys/amd64/vmm/io/vlapic.c
+++ b/sys/amd64/vmm/io/vlapic.c
@@ -905,7 +905,8 @@ vlapic_calcdest(struct vm *vm, cpuset_t *dmask, uint32_t dest, bool phys,
 	}
 }
 
-static VMM_STAT_ARRAY(IPIS_SENT, VMM_STAT_NELEMS_VCPU, "ipis sent to vcpu");
+static VMM_STAT(VLAPIC_IPI_SEND, "ipis sent from vcpu");
+static VMM_STAT(VLAPIC_IPI_RECV, "ipis received by vcpu");
 
 static void
 vlapic_set_tpr(struct vlapic *vlapic, uint8_t val)
@@ -1102,7 +1103,8 @@ vlapic_icrlo_write_handler(struct vlapic *vlapic, bool *retu)
 		CPU_FOREACH_ISSET(i, &dmask) {
 			vcpu = vm_vcpu(vlapic->vm, i);
 			lapic_intr_edge(vcpu, vec);
-			vmm_stat_array_incr(vlapic->vcpu, IPIS_SENT, i, 1);
+			vmm_stat_incr(vlapic->vcpu, VLAPIC_IPI_SEND, 1);
+			vmm_stat_incr(vcpu, VLAPIC_IPI_RECV, 1);
 			VLAPIC_CTR2(vlapic,
 			    "vlapic sending ipi %d to vcpuid %d", vec, i);
 		}
@@ -1223,7 +1225,8 @@ vlapic_self_ipi_handler(struct vlapic *vlapic, uint64_t val)
 
 	vec = val & 0xff;
 	lapic_intr_edge(vlapic->vcpu, vec);
-	vmm_stat_array_incr(vlapic->vcpu, IPIS_SENT, vlapic->vcpuid, 1);
+	vmm_stat_incr(vlapic->vcpu, VLAPIC_IPI_SEND, 1);
+	vmm_stat_incr(vlapic->vcpu, VLAPIC_IPI_RECV, 1);
 	VLAPIC_CTR1(vlapic, "vlapic self-ipi %d", vec);
 }
 
diff --git a/sys/amd64/vmm/vmm_stat.c b/sys/amd64/vmm/vmm_stat.c
index 2750982185aa..2df4423bc60f 100644
--- a/sys/amd64/vmm/vmm_stat.c
+++ b/sys/amd64/vmm/vmm_stat.c
@@ -70,9 +70,6 @@ vmm_stat_register(void *arg)
 	if (vst->scope == VMM_STAT_SCOPE_AMD && !vmm_is_svm())
 		return;
 
-	if (vst->nelems == VMM_STAT_NELEMS_VCPU)
-		vst->nelems = vm_maxcpu;
-
 	if (vst_num_elems + vst->nelems >= MAX_VMM_STAT_ELEMS) {
 		printf("Cannot accommodate vmm stat type \"%s\"!\n", vst->desc);
 		return;
diff --git a/sys/amd64/vmm/vmm_stat.h b/sys/amd64/vmm/vmm_stat.h
index 050d3c13dda1..e40a960ec82a 100644
--- a/sys/amd64/vmm/vmm_stat.h
+++ b/sys/amd64/vmm/vmm_stat.h
@@ -58,8 +58,6 @@ struct vmm_stat_type {
 
 void	vmm_stat_register(void *arg);
 
-#define	VMM_STAT_NELEMS_VCPU	(-1)
-
 #define	VMM_STAT_FDEFINE(type, nelems, desc, func, scope)		\
 	struct vmm_stat_type type[1] = {				\
 		{ -1, nelems, desc, func, scope }			\



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202303270640.32R6eBYb086570>