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 /* Per-VM time information */
38 uint32_t td_num, td_denom;
40 #define V3_TIME_SLAVE_HOST (1 << 0)
41 #define V3_TIME_TSC_PASSTHROUGH (1 << 1)
43 /* Per-core time information */
45 uint32_t host_cpu_freq; // in kHZ
46 uint32_t guest_cpu_freq; // can be lower than host CPU freq!
48 // Multipliers for TSC speed and performance speed
49 uint32_t clock_ratio_num, clock_ratio_denom;
50 uint32_t ipc_ratio_num, ipc_ratio_denom;
52 uint64_t guest_cycles;
53 sint64_t tsc_guest_offset; // Offset of guest TSC from guest cycles
55 uint64_t last_update; // Last time (in guest cycles) the
56 // timers were updated
58 uint64_t initial_host_time;// Host time when VMM started.
59 struct v3_msr tsc_aux; // Auxilliary MSR for RDTSCP
63 // Installed Timers slaved off of the guest monotonic TSC
65 struct list_head timers;
69 #define VM_TIME_SLAVE_HOST (1 << 0)
70 #define VM_TIME_TSC_PASSTHROUGH (1 << 1)
71 #define VM_TIME_TRAP_RDTSC (1 << 2)
74 void (*update_timer)(struct guest_info * info, ullong_t cpu_cycles, ullong_t cpu_freq, void * priv_data);
75 void (*advance_timer)(struct guest_info * info, void * private_data);
80 struct v3_timer_ops * ops;
82 // Need to add accuracy/resolution fields later.
84 struct list_head timer_link;
89 // Basic functions for handling passage of time in palacios
90 void v3_init_time_core(struct guest_info * core);
91 int v3_init_time_vm(struct v3_vm_info * vm);
93 void v3_deinit_time_core(struct guest_info * core);
94 void v3_deinit_time_vm(struct v3_vm_info * vm);
96 int v3_start_time(struct guest_info * core);
98 int v3_advance_time(struct guest_info * core, uint64_t * guest_cycles);
100 // Basic functions for attaching timers to the passage of time - these timers
101 // should eventually specify their accuracy and resolution.
102 struct v3_timer * v3_add_timer(struct guest_info * info, struct v3_timer_ops * ops, void * private_data);
103 int v3_remove_timer(struct guest_info * info, struct v3_timer * timer);
104 void v3_update_timers(struct guest_info * info);
106 // Functions to return the different notions of time in Palacios.
107 static inline uint64_t v3_get_host_time(struct vm_core_time *t) {
113 // Returns *monotonic* guest time.
114 static inline uint64_t v3_get_guest_time(struct vm_core_time *t) {
115 return t->guest_cycles;
118 static inline uint64_t v3_get_guest_tsc(struct vm_core_time *t) {
119 return v3_get_guest_time(t) + t->tsc_guest_offset;
122 // Returns offset of guest TSC from host TSC
123 static inline sint64_t v3_tsc_host_offset(struct vm_core_time *time_state) {
124 uint64_t host_time = v3_get_host_time(time_state);
125 return (sint64_t)v3_get_guest_tsc(time_state) - (sint64_t)host_time;
128 // Functions for handling exits on the TSC when fully virtualizing
129 // the timestamp counter.
131 #define TSC_AUX_MSR 0xC0000103
133 int v3_handle_rdtscp(struct guest_info *info);
134 int v3_handle_rdtsc(struct guest_info *info);