X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fpalacios%2Fvmm.c;h=589f57673353261e22b0914f1f9d10170af1016f;hb=3040cb0b3c89d04aab4a6e229dcf4d2223a45295;hp=341996a984ac834f96e40eed84e12ac185278249;hpb=0b342d28c860e4b3911b529f5363d35faa86aa25;p=palacios.git diff --git a/palacios/src/palacios/vmm.c b/palacios/src/palacios/vmm.c index 341996a..589f576 100644 --- a/palacios/src/palacios/vmm.c +++ b/palacios/src/palacios/vmm.c @@ -39,6 +39,8 @@ v3_cpu_arch_t v3_cpu_types[V3_CONFIG_MAX_CPUS]; +v3_cpu_arch_t v3_mach_type = V3_INVALID_CPU; + struct v3_os_hooks * os_hooks = NULL; int v3_dbg_enable = 0; @@ -105,6 +107,9 @@ void Init_V3(struct v3_os_hooks * hooks, int num_cpus) { // Set global variables. os_hooks = hooks; + // Determine the global machine type + v3_mach_type = V3_INVALID_CPU; + for (i = 0; i < V3_CONFIG_MAX_CPUS; i++) { v3_cpu_types[i] = V3_INVALID_CPU; } @@ -131,11 +136,15 @@ void Init_V3(struct v3_os_hooks * hooks, int num_cpus) { if ((hooks) && (hooks->call_on_cpu)) { - for (i = 0; i < num_cpus; i++) { V3_Print("Initializing VMM extensions on cpu %d\n", i); hooks->call_on_cpu(i, &init_cpu, (void *)(addr_t)i); + + if (v3_mach_type == V3_INVALID_CPU) { + v3_mach_type = v3_cpu_types[i]; + } + } } @@ -210,7 +219,7 @@ static int start_core(void * p) PrintDebug("virtual core %u (on logical core %u): in start_core (RIP=%p)\n", core->vcpu_id, core->pcpu_id, (void *)(addr_t)core->rip); - switch (v3_cpu_types[0]) { + switch (v3_mach_type) { #ifdef V3_CONFIG_SVM case V3_SVM_CPU: case V3_SVM_REV3_CPU: @@ -255,7 +264,11 @@ int v3_start_vm(struct v3_vm_info * vm, unsigned int cpu_mask) { int minor = i % 8; if (core_mask[major] & (0x1 << minor)) { - avail_cores++; + if (v3_cpu_types[i] == V3_INVALID_CPU) { + core_mask[major] &= ~(0x1 << minor); + } else { + avail_cores++; + } } } @@ -266,6 +279,8 @@ int v3_start_vm(struct v3_vm_info * vm, unsigned int cpu_mask) { return -1; } + vm->run_state = VM_RUNNING; + // Spawn off threads for each core. // We work backwards, so that core 0 is always started last. for (i = 0, vcore_id = vm->num_cores - 1; (i < MAX_CORES) && (vcore_id >= 0); i++) { @@ -311,6 +326,7 @@ int v3_start_vm(struct v3_vm_info * vm, unsigned int cpu_mask) { PrintDebug("run: core=%u, func=0x%p, arg=0x%p, name=%s\n", core_idx, start_core, core, core->exec_name); + core->core_run_state = CORE_STOPPED; // core zero will turn itself on core->pcpu_id = core_idx; core->core_thread = V3_CREATE_THREAD_ON_CPU(core_idx, start_core, core, core->exec_name); @@ -323,6 +339,12 @@ int v3_start_vm(struct v3_vm_info * vm, unsigned int cpu_mask) { vcore_id--; } + if (vcore_id >= 0) { + PrintError("Error starting VM: Not enough available CPU cores\n"); + v3_stop_vm(vm); + return -1; + } + return 0; @@ -563,11 +585,10 @@ void v3_yield_cond(struct guest_info * info) { cur_cycle = v3_get_host_time(&info->time_state); if (cur_cycle > (info->yield_start_cycle + info->vm_info->yield_cycle_period)) { - - /* - PrintDebug("Conditional Yield (cur_cyle=%p, start_cycle=%p, period=%p)\n", - (void *)cur_cycle, (void *)info->yield_start_cycle, (void *)info->yield_cycle_period); - */ + //PrintDebug("Conditional Yield (cur_cyle=%p, start_cycle=%p, period=%p)\n", + // (void *)cur_cycle, (void *)info->yield_start_cycle, + // (void *)info->yield_cycle_period); + V3_Yield(); info->yield_start_cycle = v3_get_host_time(&info->time_state); } @@ -616,7 +637,7 @@ void v3_interrupt_cpu(struct v3_vm_info * vm, int logical_cpu, int vector) { int v3_vm_enter(struct guest_info * info) { - switch (v3_cpu_types[0]) { + switch (v3_mach_type) { #ifdef V3_CONFIG_SVM case V3_SVM_CPU: case V3_SVM_REV3_CPU: