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.


removed floating point operations from profiler
[palacios.git] / palacios / src / palacios / vmm_profiler.c
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 #include <palacios/vmm_types.h>
21 #include <palacios/vmm_profiler.h>
22 #include <palacios/svm_handler.h>
23 #include <palacios/vmm_rbtree.h>
24
25
26 struct exit_event {
27     uint_t exit_code;
28     uint_t exit_count;
29     uint_t handler_time;
30
31     struct rb_node tree_node;
32 };
33
34
35 void v3_init_profiler(struct guest_info * info) {
36     info->profiler.total_exits = 0;
37
38     info->profiler.start_time = 0;
39     info->profiler.end_time = 0;  
40     info->profiler.guest_pf_cnt = 0;
41
42     info->profiler.root.rb_node = NULL;
43 }
44
45
46
47 static inline struct exit_event * __insert_event(struct guest_info * info, 
48                                                  struct exit_event * evt) {
49     struct rb_node ** p = &(info->profiler.root.rb_node);
50     struct rb_node * parent = NULL;
51     struct exit_event * tmp_evt = NULL;
52
53     while (*p) {
54         parent = *p;
55         tmp_evt = rb_entry(parent, struct exit_event, tree_node);
56
57         if (evt->exit_code < tmp_evt->exit_code) {
58             p = &(*p)->rb_left;
59         } else if (evt->exit_code > tmp_evt->exit_code) {
60             p = &(*p)->rb_right;
61         } else {
62             return tmp_evt;
63         }
64     }
65     rb_link_node(&(evt->tree_node), parent, p);
66
67     return NULL;
68 }
69
70 static inline struct exit_event * insert_event(struct guest_info * info, 
71                                                struct exit_event * evt) {
72     struct exit_event * ret;
73
74     if ((ret = __insert_event(info, evt))) {
75         return ret;
76     }
77
78     v3_rb_insert_color(&(evt->tree_node), &(info->profiler.root));
79
80     return NULL;
81 }
82
83
84 static struct exit_event * get_exit(struct guest_info * info, uint_t exit_code) {
85     struct rb_node * n = info->profiler.root.rb_node;
86     struct exit_event * evt = NULL;
87
88     while (n) {
89         evt = rb_entry(n, struct exit_event, tree_node);
90     
91         if (exit_code < evt->exit_code) {
92             n = n->rb_left;
93         } else if (exit_code > evt->exit_code) {
94             n = n->rb_right;
95         } else {
96             return evt;
97         }
98     }
99
100     return NULL;
101 }
102
103
104 static inline struct exit_event * create_exit(uint_t exit_code) {
105     struct exit_event * evt = V3_Malloc(sizeof(struct exit_event));
106
107     evt->exit_code = exit_code;
108     evt->exit_count = 0;
109     evt->handler_time = 0;
110
111     return evt;
112 }
113
114 void v3_profile_exit(struct guest_info * info, uint_t exit_code) {
115     uint_t time = (info->profiler.end_time - info->profiler.start_time);
116     struct exit_event * evt = get_exit(info, exit_code);
117
118     if (evt == NULL) {
119         evt = create_exit(exit_code);
120         insert_event(info, evt);
121     }
122
123     
124   
125
126     evt->handler_time = (evt->handler_time * 127ull + time) / 128;
127
128
129     evt->exit_count++;
130   
131     info->profiler.total_exits++;
132 }
133
134
135 void v3_print_profile(struct guest_info * info) {
136     struct exit_event * evt = NULL;
137     struct rb_node * node = v3_rb_first(&(info->profiler.root));
138   
139     PrintDebug("GUEST_PF: %u\n", info->profiler.guest_pf_cnt);
140
141     do {
142         evt = rb_entry(node, struct exit_event, tree_node);
143         const char * code_str = vmexit_code_to_str(evt->exit_code);
144
145         PrintDebug("%s:%sCnt=%u,%sTime=%u\n", 
146                    code_str,
147                    (strlen(code_str) > 14) ? "\t" : "\t\t",
148                    evt->exit_count,
149                    (evt->exit_count >= 100) ? "\t" : "\t\t",
150                    evt->handler_time);
151                
152     } while ((node = v3_rb_next(node)));
153 }