From: Patrick G. Bridges Date: Wed, 20 Oct 2010 19:27:37 +0000 (-0600) Subject: Minor cleanups on time handling. X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=commitdiff_plain;h=2869a01dc962b40e05da69dd7eb628ac1dd41af7 Minor cleanups on time handling. --- diff --git a/palacios/src/palacios/svm.c b/palacios/src/palacios/svm.c index 775a379..3ac98d4 100644 --- a/palacios/src/palacios/svm.c +++ b/palacios/src/palacios/svm.c @@ -97,6 +97,12 @@ static void Init_VMCB_BIOS(vmcb_t * vmcb, struct guest_info * core) { ctrl_area->instrs.CPUID = 1; ctrl_area->instrs.HLT = 1; + +#ifdef CONFIG_TIME_VIRTUALIZE_TSC + ctrl_area->instrs.rdtsc = 1; + ctrl_area->svm_instrs.rdtscp = 1; +#endif + // guest_state->cr0 = 0x00000001; // PE /* diff --git a/palacios/src/palacios/vmm_time.c b/palacios/src/palacios/vmm_time.c index 2d5c74e..e191e9f 100644 --- a/palacios/src/palacios/vmm_time.c +++ b/palacios/src/palacios/vmm_time.c @@ -81,20 +81,23 @@ int v3_start_time(struct guest_info * info) { // If the guest is supposed to run slower than the host, yield out until // the host time is appropriately far along; -int v3_adjust_time(struct guest_info * info) -{ +int v3_adjust_time(struct guest_info * info) { struct vm_time * time_state = &(info->time_state); - uint64_t guest_time, host_time, target_host_time; - guest_time = v3_get_guest_time(time_state); - host_time = v3_get_host_time(time_state); - target_host_time = (host_time - time_state->initial_time) * - time_state->host_cpu_freq / time_state->guest_cpu_freq; - - while (host_time < target_host_time) { - v3_yield(info); + if (time_state->host_cpu_freq == time_state->guest_cpu_freq) { + time_state->guest_host_offset = 0; + } else { + uint64_t guest_time, host_time, target_host_time; + guest_time = v3_get_guest_time(time_state); host_time = v3_get_host_time(time_state); + target_host_time = (host_time - time_state->initial_time) * + time_state->host_cpu_freq / time_state->guest_cpu_freq; + while (host_time < target_host_time) { + v3_yield(info); + host_time = v3_get_host_time(time_state); + } + time_state->guest_host_offset = guest_time - host_time; + } - time_state->guest_host_offset = guest_time - host_time; return 0; } @@ -113,7 +116,6 @@ int v3_add_timer(struct guest_info * info, struct vm_timer_ops * ops, return 0; } - int v3_remove_timer(struct guest_info * info, struct vm_timer * timer) { list_del(&(timer->timer_link)); info->time_state.num_timers--; @@ -135,7 +137,6 @@ void v3_update_timers(struct guest_info * info) { } } - /* * Handle full virtualization of the time stamp counter. As noted * above, we don't store the actual value of the TSC, only the guest's diff --git a/palacios/src/palacios/vmx.c b/palacios/src/palacios/vmx.c index f12e17f..beb2437 100644 --- a/palacios/src/palacios/vmx.c +++ b/palacios/src/palacios/vmx.c @@ -225,8 +225,8 @@ static int init_vmcs_bios(struct guest_info * info, struct vmx_data * vmx_state) vmx_state->pri_proc_ctrls.invlpg_exit = 1; vmx_state->pri_proc_ctrls.use_msr_bitmap = 1; vmx_state->pri_proc_ctrls.pause_exit = 1; -#ifdef CONFIG_TIME_VIRTUALIZE_TSC vmx_state->pri_proc_ctrls.tsc_offset = 1; +#ifdef CONFIG_TIME_VIRTUALIZE_TSC vmx_state->pri_proc_ctrls.rdtsc_exit = 1; #endif