git: 7224a96a55d5 - main - bhyve: Tidy vCPU pthread startup.

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Wed, 21 Dec 2022 18:34:06 UTC
The branch main has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=7224a96a55d512e00f390d4477e0fb0a163d7528

commit 7224a96a55d512e00f390d4477e0fb0a163d7528
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2022-12-21 18:33:18 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2022-12-21 18:33:18 +0000

    bhyve: Tidy vCPU pthread startup.
    
    Set the thread affinity in fbsdrun_start_thread next to where the
    thread name is set.  This keeps all the pthread initialization
    operations at the start of a thread in one place.
    
    Reviewed by:    corvink, markj
    Differential Revision:  https://reviews.freebsd.org/D37646
---
 usr.sbin/bhyve/bhyverun.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/usr.sbin/bhyve/bhyverun.c b/usr.sbin/bhyve/bhyverun.c
index c110fecf31b0..aeafed1d0c69 100644
--- a/usr.sbin/bhyve/bhyverun.c
+++ b/usr.sbin/bhyve/bhyverun.c
@@ -525,7 +525,7 @@ fbsdrun_start_thread(void *param)
 {
 	char tname[MAXCOMLEN + 1];
 	struct mt_vmm_info *mtp;
-	int vcpu;
+	int error, vcpu;
 
 	mtp = param;
 	vcpu = mtp->mt_vcpu;
@@ -533,6 +533,12 @@ fbsdrun_start_thread(void *param)
 	snprintf(tname, sizeof(tname), "vcpu %d", vcpu);
 	pthread_set_name_np(mtp->mt_thr, tname);
 
+	if (vcpumap[vcpu] != NULL) {
+		error = pthread_setaffinity_np(mtp->mt_thr, sizeof(cpuset_t),
+		    vcpumap[vcpu]);
+		assert(error == 0);
+	}
+
 #ifdef BHYVE_SNAPSHOT
 	checkpoint_cpu_add(vcpu);
 #endif
@@ -971,12 +977,6 @@ vm_loop(struct vmctx *ctx, int vcpu)
 	enum vm_exitcode exitcode;
 	cpuset_t active_cpus;
 
-	if (vcpumap[vcpu] != NULL) {
-		error = pthread_setaffinity_np(pthread_self(),
-		    sizeof(cpuset_t), vcpumap[vcpu]);
-		assert(error == 0);
-	}
-
 	error = vm_active_cpus(ctx, &active_cpus);
 	assert(CPU_ISSET(vcpu, &active_cpus));