Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
4c4959162ea026312960e9eead6ec5f3569cbc0c
[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 WorkstationVMLmm::WorkstationVMLmm(RoutingEdgePtr netElm, CpuPtr cpu)
29   : WorkstationVM(netElm, cpu)
30   , WorkstationLmm()
31 {}
32
33 /*
34  * A physical host does not disapper in the current SimGrid code, but a VM may
35  * disapper during a simulation.
36  */
37 WorkstationVM::~WorkstationVM()
38 {
39   /* ind_phys_workstation equals to smx_host_t */
40   surf_resource_t ind_vm_workstation = xbt_lib_get_elm_or_null(host_lib, getName());
41
42   /* Before clearing the entries in host_lib, we have to pick up resources. */
43   CpuCas01LmmPtr cpu = dynamic_cast<CpuCas01LmmPtr>(
44                     static_cast<ResourcePtr>(
45                       surf_cpu_resource_priv(ind_vm_workstation)));
46
47   /* We deregister objects from host_lib, without invoking the freeing callback
48    * of each level.
49    *
50    * Do not call xbt_lib_remove() here. It deletes all levels of the key,
51    * including MSG_HOST_LEVEL and others. We should unregister only what we know.
52    */
53   xbt_lib_unset(host_lib, getName(), SURF_CPU_LEVEL, 0);
54   xbt_lib_unset(host_lib, getName(), ROUTING_HOST_LEVEL, 0);
55   xbt_lib_unset(host_lib, getName(), SURF_WKS_LEVEL, 0);
56
57   /* TODO: comment out when VM stroage is implemented. */
58   // xbt_lib_unset(host_lib, name, SURF_STORAGE_LEVEL, 0);
59
60
61   /* Free the cpu_action of the VM. */
62   int ret = p_action->unref();
63   xbt_assert(ret == 1, "Bug: some resource still remains");
64
65   /* Free the cpu resource of the VM. If using power_trace, we will have to */
66   delete cpu;
67 }
68
69 /*
70  * A surf level object will be useless in the upper layer. Returing the
71  * dict_elm of the host.
72  **/
73 surf_resource_t WorkstationVM::getPm()
74 {
75   return xbt_lib_get_elm_or_null(host_lib, p_subWs->getName());
76 }
77
78 /**********
79  * Action *
80  **********/
81
82 //FIME:: handle action cancel
83