#include <palacios/vmx.h>
#endif
-#ifdef V3_CONFIG_VNET
-#include <vnet/vnet.h>
-#endif
-
v3_cpu_arch_t v3_cpu_types[V3_CONFIG_MAX_CPUS];
struct v3_os_hooks * os_hooks = NULL;
+
static void init_cpu(void * arg) {
uint32_t cpu_id = (uint32_t)(addr_t)arg;
#endif
-#ifdef V3_CONFIG_VNET
- v3_init_vnet();
-#endif
-
#ifdef V3_CONFIG_MULTITHREAD_OS
if ((hooks) && (hooks->call_on_cpu)) {
#endif
-#ifdef V3_CONFIG_VNET
- v3_deinit_vnet();
-#endif
-
#ifdef V3_CONFIG_MULTITHREAD_OS
if ((os_hooks) && (os_hooks->call_on_cpu)) {
for (i = 0; i < V3_CONFIG_MAX_CPUS; i++) {
if (v3_cpu_types[i] != V3_INVALID_CPU) {
- deinit_cpu((void *)(addr_t)i);
+ V3_Call_On_CPU(i, deinit_cpu, (void *)(addr_t)i);
+ //deinit_cpu((void *)(addr_t)i);
}
}
}
}
+
+
static int start_core(void * p)
{
struct guest_info * core = (struct guest_info *)p;
for (i = 0, vcore_id = 1; (i < MAX_CORES) && (vcore_id < vm->num_cores); i++) {
int major = 0;
int minor = 0;
- void * core_thread = NULL;
struct guest_info * core = &(vm->cores[vcore_id]);
char * specified_cpu = v3_cfg_val(core->core_cfg_data, "target_cpu");
uint32_t core_idx = 0;
// TODO: actually manage these threads instead of just launching them
core->pcpu_id = core_idx;
- core_thread = V3_CREATE_THREAD_ON_CPU(core_idx, start_core, core, core->exec_name);
+ core->core_thread = V3_CREATE_THREAD_ON_CPU(core_idx, start_core, core, core->exec_name);
- if (core_thread == NULL) {
+ if (core->core_thread == NULL) {
PrintError("Thread launch failed\n");
v3_stop_vm(vm);
return -1;
}
+int v3_reset_vm_core(struct guest_info * core, addr_t rip) {
+
+ switch (v3_cpu_types[core->pcpu_id]) {
+#ifdef V3_CONFIG_SVM
+ case V3_SVM_CPU:
+ case V3_SVM_REV3_CPU:
+ PrintDebug("Resetting SVM Guest CPU %d\n", core->vcpu_id);
+ return v3_reset_svm_vm_core(core, rip);
+#endif
+#ifdef V3_CONFIG_VMX
+ case V3_VMX_CPU:
+ case V3_VMX_EPT_CPU:
+ case V3_VMX_EPT_UG_CPU:
+ PrintDebug("Resetting VMX Guest CPU %d\n", core->vcpu_id);
+ return v3_reset_vmx_vm_core(core, rip);
+#endif
+ case V3_INVALID_CPU:
+ default:
+ PrintError("CPU has no virtualization Extensions\n");
+ break;
+ }
+
+ return -1;
+}
+
+
+
+/* move a virtual core to different physical core */
+int v3_move_vm_core(struct v3_vm_info * vm, int vcore_id, int target_cpu) {
+ struct guest_info * core = NULL;
+
+ if(vcore_id < 0 || vcore_id > vm->num_cores) {
+ return -1;
+ }
+
+ core = &(vm->cores[vcore_id]);
+
+ if(target_cpu != core->pcpu_id &&
+ core->core_move_state != CORE_MOVE_PENDING){
+ core->core_move_state = CORE_MOVE_PENDING;
+ core->target_pcpu_id = target_cpu;
+ v3_interrupt_cpu(vm, core->pcpu_id, 0);
+
+ while(core->core_move_state != CORE_MOVE_DONE){
+ v3_yield(NULL);
+ }
+ }
+
+
+ return 0;
+}
+
int v3_stop_vm(struct v3_vm_info * vm) {
}
+int v3_pause_vm(struct v3_vm_info * vm) {
+
+ if (vm->run_state != VM_RUNNING) {
+ PrintError("Tried to pause a VM that was not running\n");
+ return -1;
+ }
+
+ while (v3_raise_barrier(vm, NULL) == -1);
+
+ vm->run_state = VM_PAUSED;
+
+ return 0;
+}
+
+
+int v3_continue_vm(struct v3_vm_info * vm) {
+
+ if (vm->run_state != VM_PAUSED) {
+ PrintError("Tried to continue a VM that was not paused\n");
+ return -1;
+ }
+
+ v3_lower_barrier(vm);
+
+ vm->run_state = VM_RUNNING;
+
+ return 0;
+}
+
+
int v3_free_vm(struct v3_vm_info * vm) {
int i = 0;
// deinitialize guest (free memory, etc...)