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.


some fixes for profiling
[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
41   info->profiler.root.rb_node = NULL;
42 }
43
44
45
46 static inline struct exit_event * __insert_event(struct guest_info * info, 
47                                                  struct exit_event * evt) {
48   struct rb_node ** p = &(info->profiler.root.rb_node);
49   struct rb_node * parent = NULL;
50   struct exit_event * tmp_evt = NULL;
51
52   while (*p) {
53     parent = *p;
54     tmp_evt = rb_entry(parent, struct exit_event, tree_node);
55
56     if (evt->exit_code < tmp_evt->exit_code) {
57       p = &(*p)->rb_left;
58     } else if (evt->exit_code > tmp_evt->exit_code) {
59       p = &(*p)->rb_right;
60     } else {
61       return tmp_evt;
62     }
63   }
64   rb_link_node(&(evt->tree_node), parent, p);
65
66   return NULL;
67 }
68
69 static inline struct exit_event * insert_event(struct guest_info * info, 
70                                                struct exit_event * evt) {
71   struct exit_event * ret;
72
73   if ((ret = __insert_event(info, evt))) {
74     return ret;
75   }
76
77   v3_rb_insert_color(&(evt->tree_node), &(info->profiler.root));
78
79   return NULL;
80 }
81
82
83 static struct exit_event * get_exit(struct guest_info * info, uint_t exit_code) {
84   struct rb_node * n = info->profiler.root.rb_node;
85   struct exit_event * evt = NULL;
86
87   while (n) {
88     evt = rb_entry(n, struct exit_event, tree_node);
89     
90     if (exit_code < evt->exit_code) {
91       n = n->rb_left;
92     } else if (exit_code > evt->exit_code) {
93       n = n->rb_right;
94     } else {
95       return evt;
96     }
97   }
98
99   return NULL;
100 }
101
102
103 static inline struct exit_event * create_exit(uint_t exit_code) {
104   struct exit_event * evt = V3_Malloc(sizeof(struct exit_event));
105
106   evt->exit_code = exit_code;
107   evt->exit_count = 0;
108   evt->handler_time = 0;
109
110   return evt;
111 }
112
113 void v3_profile_exit(struct guest_info * info, uint_t exit_code) {
114   uint_t time = (info->profiler.end_time - info->profiler.start_time);
115   struct exit_event * evt = get_exit(info, exit_code);
116
117   if (evt == NULL) {
118     evt = create_exit(exit_code);
119     insert_event(info, evt);
120   }
121
122   evt->handler_time += time;
123   evt->exit_count++;
124   
125   info->profiler.total_exits++;
126 }
127
128
129 void v3_print_profile(struct guest_info * info) {
130   struct exit_event * evt = NULL;
131   struct rb_node * node = v3_rb_first(&(info->profiler.root));
132   
133   do {
134     evt = rb_entry(node, struct exit_event, tree_node);
135     const char * code_str = vmexit_code_to_str(evt->exit_code);
136
137     PrintDebug("%s:%sCnt=%u,%sTime=%u\n", 
138                code_str,
139                (strlen(code_str) > 14) ? "\t" : "\t\t",
140                evt->exit_count,
141                (evt->exit_count >= 100) ? "\t" : "\t\t",
142                evt->handler_time);
143                
144   } while ((node = v3_rb_next(node)));
145 }