summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorneel <neel@FreeBSD.org>2014-05-31 23:37:34 +0000
committerneel <neel@FreeBSD.org>2014-05-31 23:37:34 +0000
commit9c2a9423876303af6b7757283943735603cdacf7 (patch)
tree7c418a681bb97d7aaf33db6bbb701d15bf078026 /lib
parent7f92c4861a4aba3ec77c8d72e941a081d86a2d1a (diff)
downloadFreeBSD-src-9c2a9423876303af6b7757283943735603cdacf7.zip
FreeBSD-src-9c2a9423876303af6b7757283943735603cdacf7.tar.gz
Activate vcpus from bhyve(8) using the ioctl VM_ACTIVATE_CPU instead of doing
it implicitly in vmm.ko. Add ioctl VM_GET_CPUS to get the current set of 'active' and 'suspended' cpus and display them via /usr/sbin/bhyvectl using the "--get-active-cpus" and "--get-suspended-cpus" options. This is in preparation for being able to reset virtual machine state without having to destroy and recreate it.
Diffstat (limited to 'lib')
-rw-r--r--lib/libvmmapi/vmmapi.c44
-rw-r--r--lib/libvmmapi/vmmapi.h7
2 files changed, 50 insertions, 1 deletions
diff --git a/lib/libvmmapi/vmmapi.c b/lib/libvmmapi/vmmapi.c
index ba2904c..89c7825 100644
--- a/lib/libvmmapi/vmmapi.c
+++ b/lib/libvmmapi/vmmapi.c
@@ -29,11 +29,12 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
-#include <sys/types.h>
+#include <sys/param.h>
#include <sys/sysctl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/_iovec.h>
+#include <sys/cpuset.h>
#include <machine/specialreg.h>
#include <machine/param.h>
@@ -1043,3 +1044,44 @@ vm_copyout(struct vmctx *ctx, int vcpu, const void *vp, struct iovec *iov,
len -= n;
}
}
+
+static int
+vm_get_cpus(struct vmctx *ctx, int which, cpuset_t *cpus)
+{
+ struct vm_cpuset vm_cpuset;
+ int error;
+
+ bzero(&vm_cpuset, sizeof(struct vm_cpuset));
+ vm_cpuset.which = which;
+ vm_cpuset.cpusetsize = sizeof(cpuset_t);
+ vm_cpuset.cpus = cpus;
+
+ error = ioctl(ctx->fd, VM_GET_CPUS, &vm_cpuset);
+ return (error);
+}
+
+int
+vm_active_cpus(struct vmctx *ctx, cpuset_t *cpus)
+{
+
+ return (vm_get_cpus(ctx, VM_ACTIVE_CPUS, cpus));
+}
+
+int
+vm_suspended_cpus(struct vmctx *ctx, cpuset_t *cpus)
+{
+
+ return (vm_get_cpus(ctx, VM_SUSPENDED_CPUS, cpus));
+}
+
+int
+vm_activate_cpu(struct vmctx *ctx, int vcpu)
+{
+ struct vm_activate_cpu ac;
+ int error;
+
+ bzero(&ac, sizeof(struct vm_activate_cpu));
+ ac.vcpuid = vcpu;
+ error = ioctl(ctx->fd, VM_ACTIVATE_CPU, &ac);
+ return (error);
+}
diff --git a/lib/libvmmapi/vmmapi.h b/lib/libvmmapi/vmmapi.h
index bab41da..0f2e3ae 100644
--- a/lib/libvmmapi/vmmapi.h
+++ b/lib/libvmmapi/vmmapi.h
@@ -29,6 +29,9 @@
#ifndef _VMMAPI_H_
#define _VMMAPI_H_
+#include <sys/param.h>
+#include <sys/cpuset.h>
+
struct iovec;
struct vmctx;
enum x2apic_state;
@@ -125,6 +128,10 @@ void vm_copyout(struct vmctx *ctx, int vcpu, const void *host_src,
/* Reset vcpu register state */
int vcpu_reset(struct vmctx *ctx, int vcpu);
+int vm_active_cpus(struct vmctx *ctx, cpuset_t *cpus);
+int vm_suspended_cpus(struct vmctx *ctx, cpuset_t *cpus);
+int vm_activate_cpu(struct vmctx *ctx, int vcpu);
+
/*
* FreeBSD specific APIs
*/
OpenPOWER on IntegriCloud