Changeset View
Changeset View
Standalone View
Standalone View
head/sys/amd64/vmm/vmm.c
Show First 20 Lines • Show All 160 Lines • ▼ Show 20 Lines | struct vm { | ||||
void *rendezvous_arg; /* (x) rendezvous func/arg */ | void *rendezvous_arg; /* (x) rendezvous func/arg */ | ||||
vm_rendezvous_func_t rendezvous_func; | vm_rendezvous_func_t rendezvous_func; | ||||
struct mtx rendezvous_mtx; /* (o) rendezvous lock */ | struct mtx rendezvous_mtx; /* (o) rendezvous lock */ | ||||
struct mem_map mem_maps[VM_MAX_MEMMAPS]; /* (i) guest address space */ | struct mem_map mem_maps[VM_MAX_MEMMAPS]; /* (i) guest address space */ | ||||
struct mem_seg mem_segs[VM_MAX_MEMSEGS]; /* (o) guest memory regions */ | struct mem_seg mem_segs[VM_MAX_MEMSEGS]; /* (o) guest memory regions */ | ||||
struct vmspace *vmspace; /* (o) guest's address space */ | struct vmspace *vmspace; /* (o) guest's address space */ | ||||
char name[VM_MAX_NAMELEN]; /* (o) virtual machine name */ | char name[VM_MAX_NAMELEN]; /* (o) virtual machine name */ | ||||
struct vcpu vcpu[VM_MAXCPU]; /* (i) guest vcpus */ | struct vcpu vcpu[VM_MAXCPU]; /* (i) guest vcpus */ | ||||
/* The following describe the vm cpu topology */ | |||||
uint16_t sockets; /* (o) num of sockets */ | |||||
uint16_t cores; /* (o) num of cores/socket */ | |||||
uint16_t threads; /* (o) num of threads/core */ | |||||
uint16_t maxcpus; /* (o) max pluggable cpus */ | |||||
}; | }; | ||||
static int vmm_initialized; | static int vmm_initialized; | ||||
static struct vmm_ops *ops; | static struct vmm_ops *ops; | ||||
#define VMM_INIT(num) (ops != NULL ? (*ops->init)(num) : 0) | #define VMM_INIT(num) (ops != NULL ? (*ops->init)(num) : 0) | ||||
#define VMM_CLEANUP() (ops != NULL ? (*ops->cleanup)() : 0) | #define VMM_CLEANUP() (ops != NULL ? (*ops->cleanup)() : 0) | ||||
#define VMM_RESUME() (ops != NULL ? (*ops->resume)() : 0) | #define VMM_RESUME() (ops != NULL ? (*ops->resume)() : 0) | ||||
▲ Show 20 Lines • Show All 243 Lines • ▼ Show 20 Lines | vm_init(struct vm *vm, bool create) | ||||
vm->suspend = 0; | vm->suspend = 0; | ||||
CPU_ZERO(&vm->suspended_cpus); | CPU_ZERO(&vm->suspended_cpus); | ||||
for (i = 0; i < VM_MAXCPU; i++) | for (i = 0; i < VM_MAXCPU; i++) | ||||
vcpu_init(vm, i, create); | vcpu_init(vm, i, create); | ||||
} | } | ||||
/* | |||||
* The default CPU topology is a single thread per package. | |||||
*/ | |||||
u_int cores_per_package = 1; | |||||
u_int threads_per_core = 1; | |||||
int | int | ||||
vm_create(const char *name, struct vm **retvm) | vm_create(const char *name, struct vm **retvm) | ||||
{ | { | ||||
struct vm *vm; | struct vm *vm; | ||||
struct vmspace *vmspace; | struct vmspace *vmspace; | ||||
/* | /* | ||||
* If vmm.ko could not be successfully initialized then don't attempt | * If vmm.ko could not be successfully initialized then don't attempt | ||||
Show All 9 Lines | vm_create(const char *name, struct vm **retvm) | ||||
if (vmspace == NULL) | if (vmspace == NULL) | ||||
return (ENOMEM); | return (ENOMEM); | ||||
vm = malloc(sizeof(struct vm), M_VM, M_WAITOK | M_ZERO); | vm = malloc(sizeof(struct vm), M_VM, M_WAITOK | M_ZERO); | ||||
strcpy(vm->name, name); | strcpy(vm->name, name); | ||||
vm->vmspace = vmspace; | vm->vmspace = vmspace; | ||||
mtx_init(&vm->rendezvous_mtx, "vm rendezvous lock", 0, MTX_DEF); | mtx_init(&vm->rendezvous_mtx, "vm rendezvous lock", 0, MTX_DEF); | ||||
vm->sockets = 1; | |||||
vm->cores = cores_per_package; /* XXX backwards compatibility */ | |||||
vm->threads = threads_per_core; /* XXX backwards compatibility */ | |||||
vm->maxcpus = 0; /* XXX not implemented */ | |||||
vm_init(vm, true); | vm_init(vm, true); | ||||
*retvm = vm; | *retvm = vm; | ||||
return (0); | |||||
} | |||||
void | |||||
vm_get_topology(struct vm *vm, uint16_t *sockets, uint16_t *cores, | |||||
uint16_t *threads, uint16_t *maxcpus) | |||||
{ | |||||
*sockets = vm->sockets; | |||||
*cores = vm->cores; | |||||
*threads = vm->threads; | |||||
*maxcpus = vm->maxcpus; | |||||
} | |||||
int | |||||
vm_set_topology(struct vm *vm, uint16_t sockets, uint16_t cores, | |||||
uint16_t threads, uint16_t maxcpus) | |||||
{ | |||||
if (maxcpus != 0) | |||||
return (EINVAL); /* XXX remove when supported */ | |||||
if ((sockets * cores * threads) > VM_MAXCPU) | |||||
return (EINVAL); | |||||
/* XXX need to check sockets * cores * threads == vCPU, how? */ | |||||
vm->sockets = sockets; | |||||
vm->cores = cores; | |||||
vm->threads = threads; | |||||
vm->maxcpus = maxcpus; | |||||
return (0); | return(0); | ||||
} | } | ||||
static void | static void | ||||
vm_cleanup(struct vm *vm, bool destroy) | vm_cleanup(struct vm *vm, bool destroy) | ||||
{ | { | ||||
struct mem_map *mm; | struct mem_map *mm; | ||||
int i; | int i; | ||||
▲ Show 20 Lines • Show All 2,202 Lines • Show Last 20 Lines |