git: 3b6cb9b43657 - main - bhyve: Avoid shadowing global variables in bhyverun.c

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Tue, 25 Oct 2022 15:17:04 UTC
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=3b6cb9b43657d8898c165c5cd26459e4646ba4f0

commit 3b6cb9b43657d8898c165c5cd26459e4646ba4f0
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2022-09-09 00:40:02 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2022-10-25 15:16:56 +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.
    
    MFC after:      1 week
---
 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 a0261e755cfc..65e1223bd25f 100644
--- a/usr.sbin/bhyve/bhyverun.c
+++ b/usr.sbin/bhyve/bhyverun.c
@@ -185,7 +185,7 @@ static const char * const vmx_exit_reason_desc[] = {
 typedef int (*vmexit_handler_t)(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;
 
@@ -348,25 +348,25 @@ calc_topolopgy(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);
@@ -374,7 +374,8 @@ calc_topolopgy(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;
@@ -1153,7 +1154,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 e68b68fe5483..1e1e5f9880f8 100644
--- a/usr.sbin/bhyve/bhyverun.h
+++ b/usr.sbin/bhyve/bhyverun.h
@@ -35,7 +35,7 @@
 #define	VMEXIT_ABORT		(-1)
 
 extern int guest_ncpus;
-extern uint16_t cores, sockets, threads;
+extern uint16_t cpu_cores, cpu_sockets, cpu_threads;
 
 struct vmctx;
 struct vm_exit;
diff --git a/usr.sbin/bhyve/smbiostbl.c b/usr.sbin/bhyve/smbiostbl.c
index 22e6a6c73848..075371808ca9 100644
--- a/usr.sbin/bhyve/smbiostbl.c
+++ b/usr.sbin/bhyve/smbiostbl.c
@@ -718,7 +718,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;
@@ -738,15 +738,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;
 	}