Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Start at new guest time representaion
[palacios.git] / palacios / include / palacios / vmm_time.h
1 /*
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.  
5  *
6  * The V3VEE Project is a joint project between Northwestern University
7  * and the University of New Mexico.  You can find out more at 
8  * http://www.v3vee.org
9  *
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.
14  *
15  * Author: Jack Lange <jarusl@cs.northwestern.edu>
16  *         Patrick Bridges <bridges@cs.unm.edu>
17  *
18  * This is free software.  You are permitted to use,
19  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
20  */
21
22 #ifndef __VMM_TIME_H
23 #define __VMM_TIME_H
24
25 #ifdef __V3VEE__
26
27 #include <palacios/vmm_types.h>
28 #include <palacios/vmm_list.h>
29 #include <palacios/vmm_msr.h>
30 #include <palacios/vmm_util.h>
31
32 struct guest_info;
33
34 /* Per-VM time information */
35 struct v3_time {
36     uint32_t td_mult; 
37 };
38
39 /* Per-core time information */
40 struct vm_core_time {
41     uint32_t host_cpu_freq;    // in kHZ 
42     uint32_t guest_cpu_freq;   // can be lower than host CPU freq!
43
44     uint64_t guest_cycles;
45     sint64_t tsc_guest_offset; // Offset of guest TSC from guest cycles
46
47     uint64_t last_update;      // Last time (in guest cycles) the 
48                                // timers were updated
49
50     uint64_t initial_time;     // Host time when VMM started. 
51     uint64_t enter_time;       // Host time the guest was last entered
52     uint64_t exit_time;        // Host time the the VM was exited to
53     struct v3_msr tsc_aux;     // Auxilliary MSR for RDTSCP
54
55     // Installed Timers slaved off of the guest monotonic TSC
56     uint_t num_timers;
57     struct list_head timers;
58
59 };
60
61 struct v3_timer_ops {
62     void (*update_timer)(struct guest_info * info, ullong_t cpu_cycles, ullong_t cpu_freq, void * priv_data);
63     void (*advance_timer)(struct guest_info * info, void * private_data);
64 };
65
66 struct v3_timer {
67     void * private_data;
68     struct v3_timer_ops * ops;
69
70     // Need to add accuracy/resolution fields later.
71
72     struct list_head timer_link;
73 };
74
75
76
77 // Basic functions for handling passage of time in palacios
78 void v3_init_time_core(struct guest_info * core);
79 int v3_init_time_vm(struct v3_vm_info * vm);
80
81 void v3_deinit_time_core(struct guest_info * core);
82 void v3_deinit_time_vm(struct v3_vm_info * vm);
83
84 int v3_start_time(struct guest_info * core);
85
86 int v3_time_enter_vm(struct guest_info * core);
87 int v3_time_exit_vm(struct guest_info * core, uint64_t * guest_cycles);
88
89 int v3_pause_time(struct guest_info * core);
90 int v3_resume_time(struct guest_info * core);
91 int v3_offset_time(struct guest_info * core, sint64_t offset);
92
93 int v3_adjust_time(struct guest_info * core);
94
95 // Basic functions for attaching timers to the passage of time - these timers 
96 // should eventually specify their accuracy and resolution.
97 struct v3_timer * v3_add_timer(struct guest_info * info, struct v3_timer_ops * ops, void * private_data);
98 int v3_remove_timer(struct guest_info * info, struct v3_timer * timer);
99 void v3_update_timers(struct guest_info * info);
100
101 // Functions to return the different notions of time in Palacios.
102 static inline uint64_t v3_get_host_time(struct vm_core_time *t) {
103     uint64_t tmp;
104     rdtscll(tmp);
105     return tmp;
106 }
107
108 // Returns *monotonic* guest time.
109 static inline uint64_t v3_get_guest_time(struct vm_core_time *t) {
110     return t->guest_cycles;
111 }
112
113 static inline uint64_t v3_get_guest_tsc(struct vm_core_time *t) {
114     return v3_get_guest_time(t) + t->tsc_guest_offset;
115 }
116
117 // Returns offset of guest TSC from host TSC
118 static inline sint64_t v3_tsc_host_offset(struct vm_core_time *time_state) {
119     uint64_t host_time = v3_get_host_time(time_state);
120     return ((sint64_t)host_time - (sint64_t)time_state->guest_cycles) + time_state->tsc_guest_offset;
121 }
122
123 // Functions for handling exits on the TSC when fully virtualizing 
124 // the timestamp counter.
125 #define TSC_MSR     0x10
126 #define TSC_AUX_MSR 0xC0000103
127
128 int v3_handle_rdtscp(struct guest_info *info);
129 int v3_handle_rdtsc(struct guest_info *info);
130
131
132
133
134 #endif // !__V3VEE__
135
136 #endif