Logo AND Algorithmique Numérique Distribuée

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