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.


a2074555aca06c9833779140ce9152952f87ca71
[palacios.git] / palacios / src / palacios / vmm_instrument.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: Chang Bae <c.s.bae@u.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 #ifdef INSTRUMENT_VMM 
21
22 #include <palacios/svm_handler.h>
23 #include <palacios/vmm_instrument.h>
24
25 #define NO_INSTRUMENTATION
26 #include <palacios/vmm_ringbuffer.h>
27 #undef NO_INSTRUMENTATION
28
29 #define RING_SIZE 2000
30
31 static ullong_t last = 0;
32 static struct v3_ringbuf * func_ring = NULL;
33
34 struct instrumented_func {
35   ullong_t time; 
36   uint_t exiting;
37   void * called_fn;
38   void * calling_fn;
39 } __attribute__((packed));
40
41
42
43 static void print_instrumentation()  __attribute__((__no_instrument_function__));
44
45 void __cyg_profile_func_enter(void * this, void * callsite)   __attribute__((__no_instrument_function__));
46 void __cyg_profile_func_exit(void * this, void * callsite)   __attribute__((__no_instrument_function__));
47
48 void v3_init_instrumentation() {
49   PrintDebug("Creating Ring Buffer (unit size = %d)\n", (uint_t)sizeof(struct instrumented_func));
50   // initialize
51   func_ring = v3_create_ringbuf(sizeof(struct instrumented_func) * RING_SIZE); //dequeue at every 4095  
52 }
53
54
55
56  __attribute__((__no_instrument_function__))
57 void __cyg_profile_func_enter(void * this, void * callsite) {
58
59   if (func_ring != NULL) {
60
61     struct instrumented_func tmp_fn;
62     ullong_t now = 0; 
63
64     rdtscll(now);
65
66     //PrintDebug("Entering Function\n");
67
68     if (v3_ringbuf_avail_space(func_ring) < sizeof(struct instrumented_func)) {
69       print_instrumentation();
70     }
71     
72     tmp_fn.time = now - last; // current tsc
73     tmp_fn.exiting = 0; //enter to be 0
74     tmp_fn.called_fn = this; //this
75     tmp_fn.calling_fn = callsite; //callsite
76     
77     //    PrintDebug("Writing Function: fn_data=%p, size=%d\n", 
78     //       (void *)&tmp_fn, (uint_t)sizeof(struct instrumented_func));
79     v3_ringbuf_write(func_ring, (uchar_t *)&tmp_fn, sizeof(struct instrumented_func));  
80
81     rdtscll(last);
82   }
83 }
84
85
86  __attribute__((__no_instrument_function__))
87 void __cyg_profile_func_exit(void * this, void * callsite){
88
89   if (func_ring != NULL) {
90
91     struct instrumented_func tmp_fn;
92     ullong_t now = 0;
93
94     rdtscll(now);
95     
96     //    PrintDebug("Exiting Function\n");
97
98     if (v3_ringbuf_avail_space(func_ring) < sizeof(struct instrumented_func)) {
99       print_instrumentation();
100     }
101     
102     tmp_fn.time = now - last; // current tsc
103     tmp_fn.exiting = 1; //exit to be 0
104     tmp_fn.called_fn = this; //this
105     tmp_fn.calling_fn = callsite; //callsite
106
107     //    PrintDebug("Writing Function: fn_data=%p, size=%d\n", 
108     //       (void *)&tmp_fn, (uint_t)sizeof(struct instrumented_func));    
109     v3_ringbuf_write(func_ring, (uchar_t *)&tmp_fn, sizeof(struct instrumented_func));
110     
111     rdtscll(last);
112   }
113 }
114
115
116
117 static void print_instrumentation() {
118
119   struct instrumented_func tmp_fn;
120
121   //  PrintDebug("Printing Instrumentation\n");
122   while (v3_ringbuf_data_len(func_ring) >= sizeof(struct instrumented_func)) {
123     
124     v3_ringbuf_read(func_ring, (uchar_t *)&tmp_fn, sizeof(struct instrumented_func)); 
125     
126     PrintDebug("CYG_PROF: %d %p %p %p\n", 
127                tmp_fn.exiting, 
128                (void *)(addr_t)(tmp_fn.time), 
129                tmp_fn.called_fn, 
130                tmp_fn.calling_fn);
131   }
132 }
133
134
135
136 #endif