X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fpalacios%2Fvmm_halt.c;h=7dbc8ade83041ea5918b438ec3972e96c9650345;hb=5641fc7c3abf79756d28a28da8c15b4addf26fe5;hp=5015046ed5b2fa7ea6ab1e9f50f9489082f101b1;hpb=c4e343e346404fcc7674dcfa32e588a282be0f86;p=palacios.git diff --git a/palacios/src/palacios/vmm_halt.c b/palacios/src/palacios/vmm_halt.c index 5015046..7dbc8ad 100644 --- a/palacios/src/palacios/vmm_halt.c +++ b/palacios/src/palacios/vmm_halt.c @@ -20,47 +20,76 @@ #include #include +#include +#include - -#ifndef CONFIG_DEBUG_HALT +#ifndef V3_CONFIG_DEBUG_HALT #undef PrintDebug #define PrintDebug(fmt, args...) #endif - // // This should trigger a #GP if cpl != 0, otherwise, yield to host // -int v3_handle_halt(struct guest_info * info) { - +int v3_handle_halt(struct guest_info * info) +{ + if (info->cpl != 0) { v3_raise_exception(info, GPF_EXCEPTION); } else { - uint64_t yield_start = 0; + uint64_t start_cycles; - PrintDebug("CPU Yield\n"); + PrintDebug(info->vm_info, info, "CPU Yield\n"); - while (!v3_intr_pending(info)) { - rdtscll(yield_start); - v3_yield(info); - - v3_update_time(info, yield_start - info->time_state.cached_host_tsc); - - rdtscll(info->time_state.cached_host_tsc); + start_cycles = v3_get_host_time(&info->time_state); + + while (!v3_intr_pending(info) && + !v3_excp_pending(info) && + (info->vm_info->run_state == VM_RUNNING)) { + uint64_t t, cycles; + + t = v3_get_host_time(&info->time_state); + + /* Yield, allowing time to pass while yielded */ + v3_strategy_driven_yield(info, v3_cycle_diff_in_usec(info, start_cycles, t)); + + cycles = v3_get_host_time(&info->time_state) - t; + + v3_advance_time(info, &cycles); + + v3_update_timers(info); + + /* At this point, we either have some combination of interrupts, including perhaps a timer interrupt, or no interrupt. */ if (!v3_intr_pending(info)) { /* if no interrupt, then we do halt */ - asm("hlt"); + /* asm("hlt"); */ + } + + // participate in any barrier that might be raised + v3_wait_at_barrier(info); + + // stop if the VM is being halted or core is being reset + if (info->core_run_state == CORE_STOPPED || info->core_run_state == CORE_RESETTING) { + break; } + } + + /* V3_Print(info->vm_info, info, "palacios: done with halt\n"); */ info->rip += 1; + + if (info->vcpu_id==2) { + V3_Print(info->vm_info,info,"palacios: finishing halt with exppend=%d intrpend=%d\n", v3_excp_pending(info), v3_intr_pending(info)); + } + } return 0;