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.


Cleanup and sanity-checking of switch issues, negative array indexes, operand indepen...
[palacios.git] / palacios / src / palacios / vmm_perftune.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) 2012, Peter Dinda <pdinda@northwestern.edu>
11  * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org> 
12  * All rights reserved.
13  *
14  * Author: Peter Dinda <pdinda@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.h>
21 #include <palacios/vm_guest.h>
22
23
24 void     v3_strategy_driven_yield(struct guest_info *core, uint64_t time_since_last_did_work_usec)
25 {
26     // yield according to strategy
27     switch (core->vm_info->perf_options.yield_strategy.strategy) { 
28         case V3_YIELD_STRATEGY_GREEDY:
29             v3_yield(core,-1);
30             break;
31         case V3_YIELD_STRATEGY_FRIENDLY:
32             v3_yield(core,core->vm_info->perf_options.yield_strategy.time_usec);
33             break;
34         case V3_YIELD_STRATEGY_ADAPTIVE:
35             if (time_since_last_did_work_usec > core->vm_info->perf_options.yield_strategy.threshold_usec) { 
36                 v3_yield(core,core->vm_info->perf_options.yield_strategy.time_usec);
37             } else {
38                 v3_yield(core,-1);
39             }
40             break;
41         default:
42             PrintError(core->vm_info, core, "Unknown yield strategy (%d) using GREEDY\n",core->vm_info->perf_options.yield_strategy.strategy);
43             v3_yield(core,-1);
44             break;
45     }
46 }
47
48
49
50 uint64_t v3_cycle_diff_in_usec(struct guest_info *core, uint64_t first, uint64_t second)
51 {
52     uint64_t cycle_diff = second - first;
53     uint64_t mhz = (core->time_state.host_cpu_freq) / 1000; // KHZ->MHZ
54
55     return cycle_diff / mhz ;  // cycles / (millioncycles/sec) = sec/million = usec
56 }
57
58 static void set_yield_defaults(struct v3_vm_info *vm)
59 {
60     vm->perf_options.yield_strategy.strategy = V3_DEFAULT_YIELD_STRATEGY;
61     vm->perf_options.yield_strategy.threshold_usec = V3_DEFAULT_YIELD_THRESHOLD_USEC;
62     vm->perf_options.yield_strategy.time_usec = V3_DEFAULT_YIELD_TIME_USEC;
63 }
64     
65
66 static void set_yield(struct v3_vm_info *vm, v3_cfg_tree_t *cfg)
67
68 {
69     char *t;
70
71     set_yield_defaults(vm);
72     
73     // now override
74
75     t = v3_cfg_val(cfg, "strategy");
76
77     if (t) { 
78         if (!strcasecmp(t,"greedy")) { 
79             vm->perf_options.yield_strategy.strategy = V3_YIELD_STRATEGY_GREEDY;
80             V3_Print(vm, VCORE_NONE, "Setting yield strategy to GREEDY\n");
81         } else if (!strcasecmp(t, "friendly")) { 
82             vm->perf_options.yield_strategy.strategy = V3_YIELD_STRATEGY_FRIENDLY;
83             V3_Print(vm, VCORE_NONE, "Setting yield strategy to FRIENDLY\n");
84         } else if (!strcasecmp(t, "adaptive")) { 
85             vm->perf_options.yield_strategy.strategy = V3_YIELD_STRATEGY_ADAPTIVE;
86             V3_Print(vm, VCORE_NONE, "Setting yield strategy to ADAPTIVE\n");
87         } else {
88             V3_Print(vm, VCORE_NONE, "Unknown yield strategy '%s', using default\n",t);
89         }
90     } else {
91         V3_Print(vm, VCORE_NONE, "Yield strategy not given, using default\n");
92     }
93
94     t = v3_cfg_val(cfg, "threshold");
95     
96     if (t) { 
97         vm->perf_options.yield_strategy.threshold_usec = atoi(t);
98         V3_Print(vm, VCORE_NONE, "Setting yield threshold to %llu\n",vm->perf_options.yield_strategy.threshold_usec);
99     } else {
100         V3_Print(vm, VCORE_NONE, "Yield threshold not given, using default\n");
101     }
102
103
104     t = v3_cfg_val(cfg, "time");
105     
106     if (t) { 
107         vm->perf_options.yield_strategy.time_usec = atoi(t);
108         V3_Print(vm, VCORE_NONE, "Setting yield time to %llu\n",vm->perf_options.yield_strategy.time_usec);
109     } else {
110         V3_Print(vm, VCORE_NONE, "Yield time not given, using default\n");
111     }
112     
113     
114 }
115
116     
117
118
119 /*
120 <vm>
121   <perftune>
122      <group name="yield">
123         <strategy>greedy,friendly,adaptive</strategy>
124         <threshold>us</threshold>
125         <time>us</time>
126      </group>
127      <group name="something else">
128         <group-specific>....</group-specific>
129      </group>
130      ...
131   </perftune>
132 </vm>
133 */
134 int      v3_setup_performance_tuning(struct v3_vm_info *vm, v3_cfg_tree_t *cfg)
135 {
136     v3_cfg_tree_t *t = v3_cfg_subtree(cfg,"perftune");
137     
138     if (!t) { 
139         V3_Print(vm, VCORE_NONE,  "No performance tuning tree - using defaults\n");
140         set_yield_defaults(vm);
141         return 0;
142     }
143
144     t = v3_cfg_subtree(t,"group");
145     
146     while (t) {
147         char *id = v3_cfg_val(t,"name");
148         if (!id) { 
149             V3_Print(vm, VCORE_NONE,  "Skipping performance parameter group without name\n");
150         } else {
151             if (!strcasecmp(id,"yield")) { 
152                 set_yield(vm,t);
153             } else {
154                 V3_Print(vm, VCORE_NONE,  "Skipping unknown performance parameter group\n");
155             }
156         }
157         t = v3_cfg_next_branch(t);
158     }
159     
160     return 0;
161 }
162