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.


More updates getting basic version of time handling working.
[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) 2008, Jack Lange <jarusl@cs.northwestern.edu> 
11  * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org> 
12  * All rights reserved.
13  *
14  * Author: Jack Lange <jarusl@cs.northwestern.edu>
15  *
16  * This is free software.  You are permitted to use,
17  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
18  */
19
20 #ifndef __VMM_TIME_H
21 #define __VMM_TIME_H
22
23 #ifdef __V3VEE__
24
25 #include <palacios/vmm_types.h>
26 #include <palacios/vmm_list.h>
27 #include <palacios/vmm_msr.h>
28 #include <palacios/vmm_util.h>
29
30 struct guest_info;
31
32 struct vm_time {
33     uint32_t host_cpu_freq;    // in kHZ 
34     uint32_t guest_cpu_freq;   // can be lower than host CPU freq!
35          
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
38     
39     uint64_t last_update;      // Last time (in monotonic guest time) the 
40                                // timers were updated
41
42     uint64_t initial_time;     // Time when VMM started. 
43     
44     struct v3_msr tsc_aux;     // Auxilliary MSR for RDTSCP
45
46     // Installed Timers slaved off of the guest monotonic TSC
47     uint_t num_timers;
48     struct list_head timers;
49 };
50
51
52
53
54 struct vm_timer_ops {
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);
57 };
58
59 struct vm_timer {
60     void * private_data;
61     struct vm_timer_ops * ops;
62
63     struct list_head timer_link;
64 };
65
66
67
68
69 int v3_add_timer(struct guest_info * info, struct vm_timer_ops * ops, void * private_data);
70 int v3_remove_timer(struct guest_info * info, struct vm_timer * timer);
71 void v3_update_timers(struct guest_info * info);
72
73
74 void v3_init_time(struct guest_info * info);
75 int v3_start_time(struct guest_info * info);
76 int v3_adjust_time(struct guest_info * info);
77
78 // Returns host time
79 static inline uint64_t v3_get_host_time(struct vm_time *t) {
80     uint64_t tmp;
81     rdtscll(tmp);
82     return tmp;
83 }
84
85 // Returns *monotonic* guest time.
86 static inline uint64_t v3_get_guest_time(struct vm_time *t) {
87     return v3_get_host_time(t) + t->guest_host_offset;
88 }
89
90 // Returns the TSC value seen by the guest
91 static inline uint64_t v3_get_guest_tsc(struct vm_time *t) {
92     return v3_get_guest_time(t) + t->tsc_guest_offset;
93 }
94
95 // Returns offset of guest TSC from host TSC
96 static inline sint64_t v3_tsc_host_offset(struct vm_time *time_state) {
97     return time_state->guest_host_offset + time_state->tsc_guest_offset;
98 }
99
100
101 #define TSC_MSR     0x10
102 #define TSC_AUX_MSR 0xC0000103
103
104 int v3_handle_rdtscp(struct guest_info *info);
105 int v3_handle_rdtsc(struct guest_info *info);
106
107 #endif // !__V3VEE__
108
109 #endif