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.
6 * The V3VEE Project is a joint project between Northwestern University
7 * and the University of New Mexico. You can find out more at
10 * Copyright (c) 2013, Oscar Mondragon <omondrag@cs.unm.edu>
11 * Copyright (c) 2013, The V3VEE Project <http://www.v3vee.org>
12 * All rights reserved.
14 * Author: Oscar Mondragon <omondrag@cs.unm.edu>
16 * This is free software. You are permitted to use,
17 * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
21 #include <palacios/vmm.h>
22 #include <palacios/vm_guest.h>
23 #include <palacios/vmm_extensions.h>
24 #include <palacios/vmm_cpu_mapper.h>
27 #ifndef V3_CONFIG_DEBUG_EXT_CPU_MAPPER_EDF
29 #define PrintDebug(fmt, args...)
35 * cpu_mapper for EDF Scheduling
43 // First Next Fit heuristic implementation
45 int firstNextFit(int save, int tdf,struct v3_vm_info *vm){
47 V3_Print(vm, VCORE_NONE,"firstNextFit for tdf %d \n", tdf);
49 int V = vm->num_cores; // Number of virtual cores
50 int L = vm->avail_cores; // Number of Logical cores
51 int ULCores[L]; // Utilization array for logical cores
52 int uVCores[V]; // Utilization array for virtual cores
54 int vc=0; // virtual core id
55 int lc=0; // logical core id
71 // Initialize Virtual cores utilization vector
72 v3_cfg_tree_t * cfg_tree = vm->cfg_data->cfg;
73 v3_cfg_tree_t * core = v3_cfg_subtree(v3_cfg_subtree(cfg_tree, "cores"), "core");
77 char *period = v3_cfg_val(core, "period");
78 char *slice = v3_cfg_val(core, "slice");
79 uint64_t p = atoi(period);
80 uint64_t s = atoi(slice);
81 uVCores[vc]= 100 * s / p;
83 core = v3_cfg_next_branch(core);
88 // TODO Control Target CPU case
92 if( ULCores[lc] + (uVCores[vc])/tdf <= 100 ){
93 ULCores[lc] = ULCores[lc] + (uVCores[vc])/tdf;
99 ULCores[lc] = ULCores[lc] + (uVCores[vc])/tdf;
103 return -1; // Could not map
115 // Assing computed TDF
116 struct v3_time *vm_ts = &(vm->time_state);
117 vm_ts->td_denom = tdf;
119 // mapping virtual cores in logical cores
120 for (vc = 0; vc < vm->num_cores; vc++) {
121 struct guest_info * core = &(vm->cores[vc]);
122 core-> pcpu_id = mapping[vc];
128 PrintDebug(vm, VCORE_NONE,"%d ",mapping[x]);
132 PrintDebug(vm, VCORE_NONE,"%d ",ULCores[x]);
134 PrintDebug(vm, VCORE_NONE,"\n");
142 int edf_mapper_vm_init(struct v3_vm_info *vm, unsigned int cpu_mask){
144 V3_Print(vm, VCORE_NONE,"mapper. Initializing edf cpu_mapper");
146 int min_tdf = MIN_TDF;
147 int max_tdf = MAX_TDF;
148 int tdf = MAX_TDF; // Time dilation factor
151 // Binary Search of TDF
155 while( (max_tdf-min_tdf) > 0 ){
157 mappable = firstNextFit(-1,tdf,vm);
169 firstNextFit(0,tdf,vm);
176 int edf_mapper_admit(struct v3_vm_info *vm){
178 PrintDebug(vm, VCORE_NONE,"mapper. Edf cpu_mapper admit");
182 int edf_mapper_admit_core(struct v3_vm_info * vm, int vcore_id, int target_cpu){
184 PrintDebug(vm, VCORE_NONE,"mapper. Edf cpu_mapper admit core");
189 static struct vm_cpu_mapper_impl edf_mapper = {
194 .vm_init = edf_mapper_vm_init,
196 .admit = edf_mapper_admit,
197 .admit_core = edf_mapper_admit_core
203 ext_mapper_edf_init() {
204 PrintDebug(VM_NONE, VCORE_NONE,"mapper. Creating (%s) cpu_mapper\n",edf_mapper.name);
205 return v3_register_cpu_mapper(&edf_mapper);
209 ext_mapper_edf_vm_init() {
213 static struct v3_extension_impl mapper_edf_impl = {
215 .name = "cpu_mapper for EDF Scheduler",
216 .init = ext_mapper_edf_init,
217 .vm_init = ext_mapper_edf_vm_init,
225 register_extension(&mapper_edf_impl);