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) 2008, Jack Lange <jarusl@cs.northwestern.edu>
11 * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org>
12 * All rights reserved.
14 * Author: Jack Lange <jarusl@cs.northwestern.edu>
16 * This is free software. You are permitted to use,
17 * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
25 #include <palacios/vmm_types.h>
26 #include <palacios/vmm_list.h>
27 #include <palacios/vmm_msr.h>
28 #include <palacios/vmm_util.h>
33 uint32_t host_cpu_freq; // in kHZ
34 uint32_t guest_cpu_freq; // can be lower than host CPU freq!
36 sint64_t guest_host_offset;// Offset of monotonic guest time from host time
37 sint64_t tsc_guest_offset; // Offset of guest TSC from monotonic guest time
39 uint64_t last_update; // Last time (in monotonic guest time) the
40 // timers were updated
42 uint64_t initial_time; // Time when VMM started.
44 struct v3_msr tsc_aux; // Auxilliary MSR for RDTSCP
46 // Installed Timers slaved off of the guest monotonic TSC
48 struct list_head timers;
52 void (*update_timer)(struct guest_info * info, ullong_t cpu_cycles, ullong_t cpu_freq, void * priv_data);
53 void (*advance_timer)(struct guest_info * info, void * private_data);
58 struct v3_timer_ops * ops;
60 struct list_head timer_link;
63 // Basic functions for handling passage of time in palacios
64 void v3_init_time(struct guest_info * info);
65 int v3_start_time(struct guest_info * info);
66 int v3_adjust_time(struct guest_info * info);
68 // Basic functions for attaching timers to the passage of time
69 struct v3_timer * v3_add_timer(struct guest_info * info, struct v3_timer_ops * ops, void * private_data);
70 int v3_remove_timer(struct guest_info * info, struct v3_timer * timer);
71 void v3_update_timers(struct guest_info * info);
73 // Functions to return the different notions of time in Palacios.
74 static inline uint64_t v3_get_host_time(struct vm_time *t) {
80 // Returns *monotonic* guest time.
81 static inline uint64_t v3_get_guest_time(struct vm_time *t) {
82 return v3_get_host_time(t) + t->guest_host_offset;
85 // Returns the TSC value seen by the guest
86 static inline uint64_t v3_get_guest_tsc(struct vm_time *t) {
87 return v3_get_guest_time(t) + t->tsc_guest_offset;
90 // Returns offset of guest TSC from host TSC
91 static inline sint64_t v3_tsc_host_offset(struct vm_time *time_state) {
92 return time_state->guest_host_offset + time_state->tsc_guest_offset;
95 // Functions for handling exits on the TSC when fully virtualizing
96 // the timestamp counter.
98 #define TSC_AUX_MSR 0xC0000103
100 int v3_handle_rdtscp(struct guest_info *info);
101 int v3_handle_rdtsc(struct guest_info *info);