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 cpu_freq; // in kHZ in terms of guest CPU speed
34 // which ideally can be different lower than
37 uint32_t time_mult; // Fields for computing monotonic guest time
38 uint32_t time_div; // from host (tsc) time
41 sint64_t tsc_time_offset; // Offset for computing guest TSC value from
42 // monotonic guest time
44 uint64_t last_update; // Last time (in monotonic guest time) the
45 // timers were updated
47 uint64_t pause_time; // Cache value to help calculate the guest_tsc
49 struct v3_msr tsc_aux; // Auxilliary MSR for RDTSCP
51 // Installed Timers slaved off of the guest monotonic TSC
53 struct list_head timers;
60 void (*update_timer)(struct guest_info * info, ullong_t cpu_cycles, ullong_t cpu_freq, void * priv_data);
61 void (*advance_timer)(struct guest_info * info, void * private_data);
66 struct vm_timer_ops * ops;
68 struct list_head timer_link;
74 int v3_add_timer(struct guest_info * info, struct vm_timer_ops * ops, void * private_data);
75 int v3_remove_timer(struct guest_info * info, struct vm_timer * timer);
76 void v3_update_timers(struct guest_info * info);
79 void v3_init_time(struct guest_info * info);
80 int v3_start_time(struct guest_info * info);
81 int v3_pause_time(struct guest_info * info);
82 int v3_resume_time(struct guest_info * info);
85 static inline uint64_t v3_get_host_time(struct vm_time *t) {
91 // Returns *monotonic* guest time.
92 static inline uint64_t v3_get_guest_time(struct vm_time *t) {
93 if (t->pause_time) return t->pause_time;
94 else return v3_get_host_time(t) + t->time_offset;
97 // Returns the TSC value seen by the guest
98 static inline uint64_t v3_get_guest_tsc(struct vm_time *t) {
99 return v3_get_guest_time(t) + t->tsc_time_offset;
103 #define TSC_AUX_MSR 0xC0000103
105 int v3_handle_rdtscp(struct guest_info *info);
106 int v3_handle_rdtsc(struct guest_info *info);