Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge lmm into base to avoid diamond inheritance
[simgrid.git] / src / surf / vm_workstation_interface.cpp
1 /*
2  * vm_workstation.cpp
3  *
4  *  Created on: Nov 12, 2013
5  *      Author: bedaride
6  */
7 #include "vm_workstation_interface.hpp"
8 #include "cpu_cas01.hpp"
9
10 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_vm_workstation, surf,
11                                 "Logging specific to the SURF VM workstation module");
12
13 WorkstationVMModelPtr surf_vm_workstation_model = NULL;
14
15 /*********
16  * Model *
17  *********/
18
19 WorkstationVMModel::WorkstationVMModel() : WorkstationModel("Virtual Workstation") {
20   p_cpuModel = surf_cpu_model_vm;
21 }
22
23 /************
24  * Resource *
25  ************/
26
27 /*
28  * A physical host does not disapper in the current SimGrid code, but a VM may
29  * disapper during a simulation.
30  */
31 WorkstationVM::~WorkstationVM()
32 {
33   /* ind_phys_workstation equals to smx_host_t */
34   surf_resource_t ind_vm_workstation = xbt_lib_get_elm_or_null(host_lib, getName());
35
36   /* Before clearing the entries in host_lib, we have to pick up resources. */
37   CpuCas01Ptr cpu = dynamic_cast<CpuCas01Ptr>(
38                     static_cast<ResourcePtr>(
39                       surf_cpu_resource_priv(ind_vm_workstation)));
40
41   /* We deregister objects from host_lib, without invoking the freeing callback
42    * of each level.
43    *
44    * Do not call xbt_lib_remove() here. It deletes all levels of the key,
45    * including MSG_HOST_LEVEL and others. We should unregister only what we know.
46    */
47   xbt_lib_unset(host_lib, getName(), SURF_CPU_LEVEL, 0);
48   xbt_lib_unset(host_lib, getName(), ROUTING_HOST_LEVEL, 0);
49   xbt_lib_unset(host_lib, getName(), SURF_WKS_LEVEL, 0);
50
51   /* TODO: comment out when VM stroage is implemented. */
52   // xbt_lib_unset(host_lib, name, SURF_STORAGE_LEVEL, 0);
53
54
55   /* Free the cpu_action of the VM. */
56   int ret = p_action->unref();
57   xbt_assert(ret == 1, "Bug: some resource still remains");
58
59   /* Free the cpu resource of the VM. If using power_trace, we will have to */
60   delete cpu;
61 }
62
63 /*
64  * A surf level object will be useless in the upper layer. Returing the
65  * dict_elm of the host.
66  **/
67 surf_resource_t WorkstationVM::getPm()
68 {
69   return xbt_lib_get_elm_or_null(host_lib, p_subWs->getName());
70 }
71
72 /**********
73  * Action *
74  **********/
75
76 //FIME:: handle action cancel
77