Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Restructure surf++ storage
[simgrid.git] / src / surf / vm_workstation.cpp
index 744576b..6f868cc 100644 (file)
@@ -6,23 +6,30 @@
  */
 #include "vm_workstation.hpp"
 #include "cpu_cas01.hpp"
-#include "maxmin_private.h"
 
+extern "C" {
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_vm_workstation, surf,
                                 "Logging specific to the SURF VM workstation module");
+}
 
 WorkstationVMModelPtr surf_vm_workstation_model = NULL;
 
 void surf_vm_workstation_model_init_current_default(void){
-  surf_vm_workstation_model = new WorkstationVMModel();
-  xbt_dynar_push(model_list, &surf_vm_workstation_model);
-  xbt_dynar_push(model_list_invoke, &surf_vm_workstation_model);
+  if (surf_cpu_model_vm) {
+    surf_vm_workstation_model = new WorkstationVMModel();
+    ModelPtr model = static_cast<ModelPtr>(surf_vm_workstation_model);
+
+    xbt_dynar_push(model_list, &model);
+    xbt_dynar_push(model_list_invoke, &model);
+  }
 }
+
 /*********
  * Model *
  *********/
 
 WorkstationVMModel::WorkstationVMModel() : WorkstationModel("Virtual Workstation") {
+  p_cpuModel = surf_cpu_model_vm;
 }
 
 /* ind means ''indirect'' that this is a reference on the whole dict_elm
@@ -32,7 +39,7 @@ void WorkstationVMModel::createResource(const char *name, void *ind_phys_worksta
 {
   WorkstationVM2013LmmPtr ws = new WorkstationVM2013Lmm(this, name, NULL, static_cast<surf_resource_t>(ind_phys_workstation));
 
-  xbt_lib_set(host_lib, name, SURF_WKS_LEVEL, ws);
+  xbt_lib_set(host_lib, name, SURF_WKS_LEVEL, static_cast<ResourcePtr>(ws));
 
   /* TODO:
    * - check how network requests are scheduled between distinct processes competing for the same card.
@@ -59,8 +66,10 @@ double WorkstationVMModel::shareResources(double now)
   /* 0. Make sure that we already calculated the resource share at the physical
    * machine layer. */
   {
-    unsigned int index_of_pm_ws_model = xbt_dynar_search(model_list_invoke, &surf_workstation_model);
-    unsigned int index_of_vm_ws_model = xbt_dynar_search(model_list_invoke, &surf_vm_workstation_model);
+       ModelPtr ws_model = static_cast<ModelPtr>(surf_workstation_model);
+       ModelPtr vm_ws_model = static_cast<ModelPtr>(surf_vm_workstation_model);
+    unsigned int index_of_pm_ws_model = xbt_dynar_search(model_list_invoke, &ws_model);
+    unsigned int index_of_vm_ws_model = xbt_dynar_search(model_list_invoke, &vm_ws_model);
     xbt_assert((index_of_pm_ws_model < index_of_vm_ws_model), "Cannot assume surf_workstation_model comes before");
 
     /* Another option is that we call sub_ws->share_resource() here. The
@@ -170,13 +179,12 @@ double WorkstationVMModel::shareResources(double now)
 /************
  * Resource *
  ************/
-
 WorkstationVM2013Lmm::WorkstationVM2013Lmm(WorkstationVMModelPtr model, const char* name, xbt_dict_t props,
                                                   surf_resource_t ind_phys_workstation)
-  :  WorkstationVM2013(model, name, props, NULL, NULL),
-     WorkstationCLM03Lmm(model, name, props, NULL, NULL, NULL),
+  :  Resource(model, name, props),
      WorkstationCLM03(model, name, props, NULL, NULL, NULL),
-     Resource(model, name, props) {
+     WorkstationVM2013(model, name, props, NULL, NULL),
+     WorkstationCLM03Lmm(model, name, props, NULL, NULL, NULL) {
   WorkstationCLM03Ptr sub_ws = dynamic_cast<WorkstationCLM03Ptr>(
                                static_cast<ResourcePtr>(
                                  surf_workstation_resource_priv(ind_phys_workstation)));
@@ -205,7 +213,7 @@ WorkstationVM2013Lmm::WorkstationVM2013Lmm(WorkstationVMModelPtr model, const ch
   /* We can assume one core and cas01 cpu for the first step.
    * Do xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, cpu) if you get the resource. */
 
-  static_cast<CpuCas01ModelPtr>(surf_cpu_model_vm)->createResource(name, // name
+  p_cpu = static_cast<CpuCas01ModelPtr>(surf_cpu_model_vm)->createResource(name, // name
       sub_cpu->p_powerPeakList,        // host->power_peak,
       sub_cpu->m_pstate,
       1,                          // host->power_scale,
@@ -262,20 +270,7 @@ WorkstationVM2013Lmm::~WorkstationVM2013Lmm()
   int ret = p_action->unref();
   xbt_assert(ret == 1, "Bug: some resource still remains");
 
-  /* Free the cpu resource of the VM. If using power_trace, we will have to
-   * free other objects than lmm_constraint. */
-  lmm_constraint_free(cpu->p_model->p_maxminSystem, cpu->p_constraint);
-  {
-    unsigned long i;
-    for (i = 0; i < cpu->m_core; i++) {
-      void *cnst_id = cpu->p_constraintCore[i]->id;
-      lmm_constraint_free(cpu->p_model->p_maxminSystem, cpu->p_constraintCore[i]);
-      xbt_free(cnst_id);
-    }
-
-    xbt_free(cpu->p_constraintCore);
-  }
-
+  /* Free the cpu resource of the VM. If using power_trace, we will have to */
   delete cpu;
 
   /* Free the network resource of the VM. */