2 * This file is part of the Palacios Virtual Machine Monitor developed
3 * by the V3VEE Project with funding from the United States National
4 * Science Foundation and the Department of Energy.
6 * The V3VEE Project is a joint project between Northwestern University
7 * and the University of New Mexico. You can find out more at
10 * Copyright (c) 2010, Patrick Bridges <bridges@cs.unm.edu>
11 * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu>
12 * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org>
13 * All rights reserved.
15 * Author: Jack Lange <jarusl@cs.northwestern.edu>
16 * Patrick Bridges <bridges@cs.unm.edu>
18 * This is free software. You are permitted to use,
19 * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
27 #include <palacios/vmm_types.h>
28 #include <palacios/vmm_list.h>
29 #include <palacios/vmm_msr.h>
30 #include <palacios/vmm_util.h>
35 uint32_t host_cpu_freq; // in kHZ
36 uint32_t guest_cpu_freq; // can be lower than host CPU freq!
38 sint64_t guest_host_offset;// Offset of monotonic guest time from host time
39 sint64_t tsc_guest_offset; // Offset of guest TSC from monotonic guest time
41 uint64_t last_update; // Last time (in monotonic guest time) the
42 // timers were updated
44 uint64_t initial_time; // Time when VMM started.
45 uint64_t enter_time; // Host time the guest was last entered
46 uint64_t exit_time; // Host time the the VM was exited to
47 struct v3_msr tsc_aux; // Auxilliary MSR for RDTSCP
49 // Installed Timers slaved off of the guest monotonic TSC
51 struct list_head timers;
55 void (*update_timer)(struct guest_info * info, ullong_t cpu_cycles, ullong_t cpu_freq, void * priv_data);
56 void (*advance_timer)(struct guest_info * info, void * private_data);
61 struct v3_timer_ops * ops;
63 struct list_head timer_link;
66 // Basic functions for handling passage of time in palacios
67 void v3_init_time_core(struct guest_info * core);
68 int v3_init_time_vm(struct v3_vm_info * vm);
70 void v3_deinit_time_core(struct guest_info * core);
71 void v3_deinit_time_vm(struct v3_vm_info * vm);
73 int v3_start_time(struct guest_info * core);
75 int v3_time_enter_vm(struct guest_info * core);
76 int v3_time_exit_vm(struct guest_info * core);
78 int v3_adjust_time(struct guest_info * core);
79 int v3_offset_time(struct guest_info * core, sint64_t offset);
81 // Basic functions for attaching timers to the passage of time
82 struct v3_timer * v3_add_timer(struct guest_info * info, struct v3_timer_ops * ops, void * private_data);
83 int v3_remove_timer(struct guest_info * info, struct v3_timer * timer);
84 void v3_update_timers(struct guest_info * info);
86 // Functions to return the different notions of time in Palacios.
87 static inline uint64_t v3_get_host_time(struct vm_time *t) {
93 // Returns *monotonic* guest time.
94 static inline uint64_t v3_get_guest_time(struct vm_time *t) {
95 #ifdef V3_CONFIG_TIME_HIDE_VM_COST
96 V3_ASSERT(t->exit_time);
97 return t->exit_time + t->guest_host_offset;
99 return v3_get_host_time(t) + t->guest_host_offset;
103 // Returns the TSC value seen by the guest
104 static inline uint64_t v3_get_guest_tsc(struct vm_time *t) {
105 return v3_get_guest_time(t) + t->tsc_guest_offset;
108 // Returns offset of guest TSC from host TSC
109 static inline sint64_t v3_tsc_host_offset(struct vm_time *time_state) {
110 return time_state->guest_host_offset + time_state->tsc_guest_offset;
113 // Functions for handling exits on the TSC when fully virtualizing
114 // the timestamp counter.
116 #define TSC_AUX_MSR 0xC0000103
118 int v3_handle_rdtscp(struct guest_info *info);
119 int v3_handle_rdtsc(struct guest_info *info);