X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fpalacios%2Fvmm_time.c;h=b169669d4dd54861c6f21e7955ddb015e7b0e44a;hb=1cc3466d1edc53576a1f70fe45b048b219e5c468;hp=027236d1636b4e47dbb2ac86a4374f0c3eebaa02;hpb=d8fc6aa4bc2a5d9cec50923e9d2bd30f867dd50a;p=palacios.git diff --git a/palacios/src/palacios/vmm_time.c b/palacios/src/palacios/vmm_time.c index 027236d..b169669 100644 --- a/palacios/src/palacios/vmm_time.c +++ b/palacios/src/palacios/vmm_time.c @@ -1,49 +1,105 @@ -#include "palacios/vmm_time.h" -#include "palacios/vmm.h" +/* + * This file is part of the Palacios Virtual Machine Monitor developed + * by the V3VEE Project with funding from the United States National + * Science Foundation and the Department of Energy. + * + * The V3VEE Project is a joint project between Northwestern University + * and the University of New Mexico. You can find out more at + * http://www.v3vee.org + * + * Copyright (c) 2008, Jack Lange + * Copyright (c) 2008, The V3VEE Project + * All rights reserved. + * + * Author: Jack Lange + * + * This is free software. You are permitted to use, + * redistribute, and modify it as specified in the file "V3VEE_LICENSE". + */ +#include +#include +#include -void v3_init_time(struct vm_time * time_state) { - ullong_t cpu_khz = 0; +static int handle_cpufreq_hcall(struct guest_info * info, uint_t hcall_id, void * priv_data) { + struct vm_time * time_state = &(info->time_state); - V3_CPU_KHZ(cpu_khz); - time_state->cpu_freq = cpu_khz; + info->vm_regs.rbx = time_state->cpu_freq; - PrintDebug("CPU KHZ = HI=%x LO=%x\n", (uint_t)(cpu_khz >> 32), (uint_t)cpu_khz); + PrintDebug("Guest request cpu frequency: return %ld\n", (long)info->vm_regs.rbx); + + return 0; +} + + + +void v3_init_time(struct guest_info * info) { + struct vm_time * time_state = &(info->time_state); + + time_state->cpu_freq = V3_CPU_KHZ(); - time_state->guest_tsc = 0; - time_state->cached_host_tsc = 0; - time_state->pending_cycles = 0; + time_state->guest_tsc = 0; + time_state->cached_host_tsc = 0; + // time_state->pending_cycles = 0; - INIT_LIST_HEAD(&(time_state->timers)); - time_state->num_timers = 0; + INIT_LIST_HEAD(&(time_state->timers)); + time_state->num_timers = 0; + + v3_register_hypercall(info->vm_info, TIME_CPUFREQ_HCALL, handle_cpufreq_hcall, NULL); } int v3_add_timer(struct guest_info * info, struct vm_timer_ops * ops, void * private_data) { - // V3_Malloc + struct vm_timer * timer = NULL; + timer = (struct vm_timer *)V3_Malloc(sizeof(struct vm_timer)); + V3_ASSERT(timer != NULL); + + timer->ops = ops; + timer->private_data = private_data; + + list_add(&(timer->timer_link), &(info->time_state.timers)); + info->time_state.num_timers++; + + return 0; +} - /* - list_add(&(timer->timer_link), &(info->time_state.timers)); - info->time_state.num_timers++; - */ - return 0; + +int v3_remove_timer(struct guest_info * info, struct vm_timer * timer) { + list_del(&(timer->timer_link)); + info->time_state.num_timers--; + + V3_Free(timer); + return 0; } -int remove_timer(struct guest_info * info, struct vm_timer * timer) { - list_del(&(timer->timer_link)); - info->time_state.num_timers--; - return 0; + +void v3_update_time(struct guest_info * info, uint64_t cycles) { + struct vm_timer * tmp_timer; + + // cycles *= 8; + +// cycles /= 150; + + info->time_state.guest_tsc += cycles; + + list_for_each_entry(tmp_timer, &(info->time_state.timers), timer_link) { + tmp_timer->ops->update_time(info, cycles, info->time_state.cpu_freq, tmp_timer->private_data); + } + + + + //info->time_state.pending_cycles = 0; } +void v3_advance_time(struct guest_info * core) { + struct vm_timer * tmp_timer; + -void update_timers(struct guest_info * info) { - struct vm_timer * tmp_timer; + list_for_each_entry(tmp_timer, &(core->time_state.timers), timer_link) { + tmp_timer->ops->advance_timer(core, tmp_timer->private_data); + } - list_for_each_entry(tmp_timer, &(info->time_state.timers), timer_link) { - tmp_timer->ops.update_time(info->time_state.pending_cycles, info->time_state.cpu_freq, tmp_timer->private_data); - } - info->time_state.pending_cycles = 0; }