diff options
author | neel <neel@FreeBSD.org> | 2014-03-20 18:15:37 +0000 |
---|---|---|
committer | neel <neel@FreeBSD.org> | 2014-03-20 18:15:37 +0000 |
commit | a6ec3f983cfcbf6a7ac84063fae92751b2fd6566 (patch) | |
tree | a5b97de549687c093f6a552a9938cba05100502e /usr.sbin/bhyve | |
parent | e7f72e1f8d5c1c11e4e690a5adb2f1947ef49615 (diff) | |
download | FreeBSD-src-a6ec3f983cfcbf6a7ac84063fae92751b2fd6566.zip FreeBSD-src-a6ec3f983cfcbf6a7ac84063fae92751b2fd6566.tar.gz |
Use 'cpuset_t' to represent the vcpus active in a virtual machine.
Diffstat (limited to 'usr.sbin/bhyve')
-rw-r--r-- | usr.sbin/bhyve/bhyverun.c | 32 | ||||
-rw-r--r-- | usr.sbin/bhyve/bhyverun.h | 2 | ||||
-rw-r--r-- | usr.sbin/bhyve/spinup_ap.c | 2 |
3 files changed, 16 insertions, 20 deletions
diff --git a/usr.sbin/bhyve/bhyverun.c b/usr.sbin/bhyve/bhyverun.c index cf35841..99194f2 100644 --- a/usr.sbin/bhyve/bhyverun.c +++ b/usr.sbin/bhyve/bhyverun.c @@ -98,7 +98,7 @@ static int acpi; static char *progname; static const int BSP = 0; -static int cpumask; +static cpuset_t cpumask; static void vm_loop(struct vmctx *ctx, int vcpu, uint64_t rip); @@ -199,30 +199,26 @@ fbsdrun_start_thread(void *param) } void -fbsdrun_addcpu(struct vmctx *ctx, int vcpu, uint64_t rip) +fbsdrun_addcpu(struct vmctx *ctx, int fromcpu, int newcpu, uint64_t rip) { int error; - if (cpumask & (1 << vcpu)) { - fprintf(stderr, "addcpu: attempting to add existing cpu %d\n", - vcpu); - exit(1); - } + assert(fromcpu == BSP); - atomic_set_int(&cpumask, 1 << vcpu); + CPU_SET_ATOMIC(newcpu, &cpumask); /* * Set up the vmexit struct to allow execution to start * at the given RIP */ - vmexit[vcpu].rip = rip; - vmexit[vcpu].inst_length = 0; + vmexit[newcpu].rip = rip; + vmexit[newcpu].inst_length = 0; - mt_vmm_info[vcpu].mt_ctx = ctx; - mt_vmm_info[vcpu].mt_vcpu = vcpu; + mt_vmm_info[newcpu].mt_ctx = ctx; + mt_vmm_info[newcpu].mt_vcpu = newcpu; - error = pthread_create(&mt_vmm_info[vcpu].mt_thr, NULL, - fbsdrun_start_thread, &mt_vmm_info[vcpu]); + error = pthread_create(&mt_vmm_info[newcpu].mt_thr, NULL, + fbsdrun_start_thread, &mt_vmm_info[newcpu]); assert(error == 0); } @@ -230,14 +226,14 @@ static int fbsdrun_deletecpu(struct vmctx *ctx, int vcpu) { - if ((cpumask & (1 << vcpu)) == 0) { + if (!CPU_ISSET(vcpu, &cpumask)) { fprintf(stderr, "addcpu: attempting to delete unknown cpu %d\n", vcpu); exit(1); } - atomic_clear_int(&cpumask, 1 << vcpu); - return (cpumask == 0); + CPU_CLR_ATOMIC(vcpu, &cpumask); + return (CPU_EMPTY(&cpumask)); } static int @@ -745,7 +741,7 @@ main(int argc, char *argv[]) /* * Add CPU 0 */ - fbsdrun_addcpu(ctx, BSP, rip); + fbsdrun_addcpu(ctx, BSP, BSP, rip); /* * Head off to the main event dispatch loop diff --git a/usr.sbin/bhyve/bhyverun.h b/usr.sbin/bhyve/bhyverun.h index 738d5b6..f18d42f 100644 --- a/usr.sbin/bhyve/bhyverun.h +++ b/usr.sbin/bhyve/bhyverun.h @@ -43,7 +43,7 @@ extern char *vmname; void *paddr_guest2host(struct vmctx *ctx, uintptr_t addr, size_t len); void fbsdrun_set_capabilities(struct vmctx *ctx, int cpu); -void fbsdrun_addcpu(struct vmctx *ctx, int cpu, uint64_t rip); +void fbsdrun_addcpu(struct vmctx *ctx, int fromcpu, int newcpu, uint64_t rip); int fbsdrun_muxed(void); int fbsdrun_vmexit_on_hlt(void); int fbsdrun_vmexit_on_pause(void); diff --git a/usr.sbin/bhyve/spinup_ap.c b/usr.sbin/bhyve/spinup_ap.c index 729108a..c597023 100644 --- a/usr.sbin/bhyve/spinup_ap.c +++ b/usr.sbin/bhyve/spinup_ap.c @@ -98,7 +98,7 @@ spinup_ap(struct vmctx *ctx, int vcpu, int newcpu, uint64_t rip) spinup_ap_realmode(ctx, newcpu, &rip); - fbsdrun_addcpu(ctx, newcpu, rip); + fbsdrun_addcpu(ctx, vcpu, newcpu, rip); return (newcpu); } |