git: 419c10c8460b - stable/13 - bhyve: Avoid shadowing global variables in bhyverun.c

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Tue, 01 Nov 2022 13:52:36 UTC
The branch stable/13 has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=419c10c8460b84a4e1b4121add8b4e4c0a953d95

commit 419c10c8460b84a4e1b4121add8b4e4c0a953d95
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2022-09-09 00:40:02 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2022-11-01 13:46:05 +0000

    bhyve: Avoid shadowing global variables in bhyverun.c
    
    - Rename the global cores/sockets/threads to cpu_cores/sockets/threads.
      This way, num_vcpus_allowed() doesn't shadow them.
    - The global maxcpus is unused, remove it for the same reason.
    
    (cherry picked from commit 3b6cb9b43657d8898c165c5cd26459e4646ba4f0)
---
 usr.sbin/bhyve/bhyverun.c  | 22 ++++++++++++----------
 usr.sbin/bhyve/bhyverun.h  |  2 +-
 usr.sbin/bhyve/smbiostbl.c | 10 +++++-----
 3 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/usr.sbin/bhyve/bhyverun.c b/usr.sbin/bhyve/bhyverun.c
index b6bc94490d75..fec4ca29de80 100644
--- a/usr.sbin/bhyve/bhyverun.c
+++ b/usr.sbin/bhyve/bhyverun.c
@@ -185,7 +185,7 @@ typedef int (*vmexit_handler_t)(struct vmctx *, struct vm_exit *, int *vcpu);
 extern int vmexit_task_switch(struct vmctx *, struct vm_exit *, int *vcpu);
 
 int guest_ncpus;
-uint16_t cores, maxcpus, sockets, threads;
+uint16_t cpu_cores, cpu_sockets, cpu_threads;
 
 int raw_stdio = 0;
 
@@ -347,25 +347,25 @@ calc_topology(void)
 	}
 	value = get_config_value("cores");
 	if (value != NULL)
-		cores = parse_int_value("cores", value, 1, UINT16_MAX);
+		cpu_cores = parse_int_value("cores", value, 1, UINT16_MAX);
 	else
-		cores = 1;
+		cpu_cores = 1;
 	value = get_config_value("threads");
 	if (value != NULL)
-		threads = parse_int_value("threads", value, 1, UINT16_MAX);
+		cpu_threads = parse_int_value("threads", value, 1, UINT16_MAX);
 	else
-		threads = 1;
+		cpu_threads = 1;
 	value = get_config_value("sockets");
 	if (value != NULL)
-		sockets = parse_int_value("sockets", value, 1, UINT16_MAX);
+		cpu_sockets = parse_int_value("sockets", value, 1, UINT16_MAX);
 	else
-		sockets = guest_ncpus;
+		cpu_sockets = guest_ncpus;
 
 	/*
 	 * Compute sockets * cores * threads avoiding overflow.  The
 	 * range check above insures these are 16 bit values.
 	 */
-	ncpus = (uint64_t)sockets * cores * threads;
+	ncpus = (uint64_t)cpu_sockets * cpu_cores * cpu_threads;
 	if (ncpus > UINT16_MAX)
 		errx(4, "Computed number of vCPUs too high: %ju",
 		    (uintmax_t)ncpus);
@@ -373,7 +373,8 @@ calc_topology(void)
 	if (explicit_cpus) {
 		if (guest_ncpus != ncpus)
 			errx(4, "Topology (%d sockets, %d cores, %d threads) "
-			    "does not match %d vCPUs", sockets, cores, threads,
+			    "does not match %d vCPUs",
+			    cpu_sockets, cpu_cores, cpu_threads,
 			    guest_ncpus);
 	} else
 		guest_ncpus = ncpus;
@@ -1118,7 +1119,8 @@ do_open(const char *vmname)
 			exit(4);
 		}
 	}
-	error = vm_set_topology(ctx, sockets, cores, threads, maxcpus);
+	error = vm_set_topology(ctx, cpu_sockets, cpu_cores, cpu_threads,
+	    0 /* maxcpus, unimplemented */);
 	if (error)
 		errx(EX_OSERR, "vm_set_topology");
 	return (ctx);
diff --git a/usr.sbin/bhyve/bhyverun.h b/usr.sbin/bhyve/bhyverun.h
index 9b0c9fb533e2..d10604011d31 100644
--- a/usr.sbin/bhyve/bhyverun.h
+++ b/usr.sbin/bhyve/bhyverun.h
@@ -36,7 +36,7 @@
 
 struct vmctx;
 extern int guest_ncpus;
-extern uint16_t cores, sockets, threads;
+extern uint16_t cpu_cores, cpu_sockets, cpu_threads;
 
 void *paddr_guest2host(struct vmctx *ctx, uintptr_t addr, size_t len);
 #ifdef BHYVE_SNAPSHOT
diff --git a/usr.sbin/bhyve/smbiostbl.c b/usr.sbin/bhyve/smbiostbl.c
index c1b7652d90bf..9488d733b90e 100644
--- a/usr.sbin/bhyve/smbiostbl.c
+++ b/usr.sbin/bhyve/smbiostbl.c
@@ -716,7 +716,7 @@ smbios_type4_initializer(const struct smbios_structure *template_entry,
 {
 	int i;
 
-	for (i = 0; i < sockets; i++) {
+	for (i = 0; i < cpu_sockets; i++) {
 		struct smbios_table_type4 *type4;
 		char *p;
 		int nstrings, len;
@@ -736,15 +736,15 @@ smbios_type4_initializer(const struct smbios_structure *template_entry,
 		(*endaddr)++;
 		type4->socket = nstrings + 1;
 		/* Revise cores and threads after update to smbios 3.0 */
-		if (cores > 254)
+		if (cpu_cores > 254)
 			type4->cores = 0;
 		else
-			type4->cores = cores;
+			type4->cores = cpu_cores;
 		/* This threads is total threads in a socket */
-		if ((cores * threads) > 254)
+		if (cpu_cores * cpu_threads > 254)
 			type4->threads = 0;
 		else
-			type4->threads = (cores * threads);
+			type4->threads = cpu_cores * cpu_threads;
 		curaddr = *endaddr;
 	}