Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove useless length modifier 'l' in %l[efg] for printf.
[simgrid.git] / src / surf / vm_workstation_hl13.cpp
index a0b0b75..baad9ae 100644 (file)
@@ -110,27 +110,18 @@ double WorkstationVMHL13Model::shareResources(double now)
    *
    **/
 
-  /* iterate for all hosts including virtual machines */
-  xbt_lib_cursor_t cursor;
-  char *key;
-  void **ind_host;
-  xbt_lib_foreach(host_lib, cursor, key, ind_host) {
-    WorkstationPtr ws = static_cast<WorkstationPtr>(ind_host[SURF_WKS_LEVEL]);
-    CpuPtr cpu = static_cast<CpuPtr>(ind_host[SURF_CPU_LEVEL]);
-
-    if (!ws)
-      continue;
-    /* skip if it is not a virtual machine */
-    if (ws->getModel() != static_cast<ModelPtr>(surf_vm_workstation_model))
-      continue;
-    xbt_assert(cpu, "cpu-less workstation");
+  /* iterate for all virtual machines */
+  for (WorkstationVMModel::vm_list_t::iterator iter =
+         WorkstationVMModel::ws_vms.begin();
+       iter !=  WorkstationVMModel::ws_vms.end(); ++iter) {
 
-    /* It is a virtual machine, so we can cast it to workstation_VM2013_t */
-    WorkstationVMPtr ws_vm = static_cast<WorkstationVMPtr>(ws);
+    WorkstationVMPtr ws_vm = &*iter;
+    CpuPtr cpu = static_cast<CpuPtr>(ws_vm->p_cpu);
+    xbt_assert(cpu, "cpu-less workstation");
 
     double solved_value = get_solved_value(static_cast<CpuActionPtr>(ws_vm->p_action));
     XBT_DEBUG("assign %f to vm %s @ pm %s", solved_value,
-        ws->getName(), ws_vm->p_subWs->getName());
+        ws_vm->getName(), ws_vm->p_subWs->getName());
 
     // TODO: check lmm_update_constraint_bound() works fine instead of the below manual substitution.
     // cpu_cas01->constraint->bound = solved_value;
@@ -144,7 +135,7 @@ double WorkstationVMHL13Model::shareResources(double now)
   adjustWeightOfDummyCpuActions();
 
   double min_by_cpu = p_cpuModel->shareResources(now);
-  double min_by_net = surf_network_model->shareResources(now);
+  double min_by_net = (strcmp(surf_network_model->getName(), "network NS3")) ? surf_network_model->shareResources(now) : -1;
   double min_by_sto = -1;
   if (p_cpuModel == surf_cpu_model_pm)
        min_by_sto = surf_storage_model->shareResources(now);
@@ -164,20 +155,14 @@ double WorkstationVMHL13Model::shareResources(double now)
 
   /* FIXME: 3. do we have to re-initialize our cpu_action object? */
 #if 0
-  /* iterate for all hosts including virtual machines */
-  xbt_lib_foreach(host_lib, cursor, key, ind_host) {
-    WorkstationCLM03Ptr ws_clm03 = ind_host[SURF_WKS_LEVEL];
-
-    /* skip if it is not a virtual machine */
-    if (!ws_clm03)
-      continue;
-    if (ws_clm03->getModel() != surf_vm_workstation_model)
-      continue;
+  /* iterate for all virtual machines */
+  for (WorkstationVMModel::vm_list_t::iterator iter =
+         WorkstationVMModel::ws_vms.begin();
+       iter !=  WorkstationVMModel::ws_vms.end(); ++iter) {
 
-    /* It is a virtual machine, so we can cast it to workstation_VM2013_t */
     {
 #if 0
-      WorkstationVM2013Ptr ws_vm2013 = (workstation_VM2013_t) ws_clm03;
+      WorkstationVM2013Ptr ws_vm2013 = static_cast<WorkstationVM2013Ptr>(&*iter);
       XBT_INFO("cost %f remains %f start %f finish %f", ws_vm2013->cpu_action->cost,
           ws_vm2013->cpu_action->remains,
           ws_vm2013->cpu_action->start,
@@ -252,7 +237,7 @@ WorkstationVMHL13::WorkstationVMHL13(WorkstationVMModelPtr model, const char* na
    * from the VM name, we have to make sure that the system does not call the
    * free callback for the network resource object. The network resource object
    * is still used by the physical machine. */
-  p_netElm = new RoutingEdgeWrapper(static_cast<RoutingEdgePtr>(xbt_lib_get_or_null(host_lib, sub_ws->getName(), ROUTING_HOST_LEVEL)));
+  p_netElm = static_cast<RoutingEdgePtr>(xbt_lib_get_or_null(host_lib, sub_ws->getName(), ROUTING_HOST_LEVEL));
   xbt_lib_set(host_lib, name, ROUTING_HOST_LEVEL, p_netElm);
 
   p_subWs = sub_ws;
@@ -266,8 +251,8 @@ WorkstationVMHL13::WorkstationVMHL13(WorkstationVMModelPtr model, const char* na
    * Do xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, cpu) if you get the resource. */
 
   p_cpu = static_cast<CpuCas01ModelPtr>(surf_cpu_model_vm)->createResource(name, // name
-      sub_cpu->p_powerPeakList,        // host->power_peak,
-      sub_cpu->m_pstate,
+      sub_cpu->getPowerPeakList(),        // host->power_peak,
+      sub_cpu->getPState(),
       1,                          // host->power_scale,
       NULL,                       // host->power_trace,
       1,                          // host->core_amount,
@@ -297,10 +282,10 @@ WorkstationVMHL13::WorkstationVMHL13(WorkstationVMModelPtr model, const char* na
 WorkstationVMHL13::~WorkstationVMHL13()
 {
   /* ind_phys_workstation equals to smx_host_t */
-  // surf_resource_t ind_vm_workstation = xbt_lib_get_elm_or_null(host_lib, getName());
+  surf_resource_t ind_vm_workstation = xbt_lib_get_elm_or_null(host_lib, getName());
 
   /* Before clearing the entries in host_lib, we have to pick up resources. */
-  // CpuCas01Ptr cpu = static_cast<CpuCas01Ptr>(surf_cpu_resource_priv(ind_vm_workstation));
+  CpuCas01Ptr cpu = static_cast<CpuCas01Ptr>(surf_cpu_resource_priv(ind_vm_workstation));
 
   /* We deregister objects from host_lib, without invoking the freeing callback
    * of each level.
@@ -321,15 +306,15 @@ WorkstationVMHL13::~WorkstationVMHL13()
   xbt_assert(ret == 1, "Bug: some resource still remains");
 
   /* Free the cpu resource of the VM. If using power_trace, we will have to */
-  //delete cpu;
+  delete cpu;
 
   /* Free the network resource of the VM. */
-       // Nothing has to be done, because net_elmts is just a pointer on the physical one
+  // Nothing has to be done, because net_elmts is just a pointer on the physical one
 
   /* Free the storage resource of the VM. */
   // Not relevant yet
 
-       /* Free the workstation resource of the VM. */
+  /* Free the workstation resource of the VM. */
 }
 
 void WorkstationVMHL13::updateState(tmgr_trace_event_t /*event_type*/, double /*value*/, double /*date*/) {
@@ -435,7 +420,7 @@ void WorkstationVMHL13::migrate(surf_resource_t ind_dst_pm)
      /* keep the bound value of the cpu action of the VM. */
      double old_bound = p_action->getBound();
      if (old_bound != 0) {
-       XBT_INFO("migrate VM(%s): set bound (%lf) at %s", vm_name, old_bound, pm_name_dst);
+       XBT_INFO("migrate VM(%s): set bound (%f) at %s", vm_name, old_bound, pm_name_dst);
        new_cpu_action->setBound(old_bound);
      }