Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
69f6c67fc287603088ddbd8f1f8c093ee3834347
[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 = static_cast<CpuCas01Ptr>(surf_cpu_resource_priv(ind_vm_workstation));
38
39   /* We deregister objects from host_lib, without invoking the freeing callback
40    * of each level.
41    *
42    * Do not call xbt_lib_remove() here. It deletes all levels of the key,
43    * including MSG_HOST_LEVEL and others. We should unregister only what we know.
44    */
45   xbt_lib_unset(host_lib, getName(), SURF_CPU_LEVEL, 0);
46   xbt_lib_unset(host_lib, getName(), ROUTING_HOST_LEVEL, 0);
47   xbt_lib_unset(host_lib, getName(), SURF_WKS_LEVEL, 0);
48
49   /* TODO: comment out when VM stroage is implemented. */
50   // xbt_lib_unset(host_lib, name, SURF_STORAGE_LEVEL, 0);
51
52
53   /* Free the cpu_action of the VM. */
54   int ret = p_action->unref();
55   xbt_assert(ret == 1, "Bug: some resource still remains");
56
57   /* Free the cpu resource of the VM. If using power_trace, we will have to */
58   delete cpu;
59 }
60
61 /*
62  * A surf level object will be useless in the upper layer. Returing the
63  * dict_elm of the host.
64  **/
65 surf_resource_t WorkstationVM::getPm()
66 {
67   return xbt_lib_get_elm_or_null(host_lib, p_subWs->getName());
68 }
69
70 /**********
71  * Action *
72  **********/
73
74 //FIME:: handle action cancel
75