Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make a list of WorkstationVM, instead of iterating over all hosts to list them.
authorArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Mon, 10 Feb 2014 13:51:25 +0000 (14:51 +0100)
committerArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Mon, 10 Feb 2014 14:27:17 +0000 (15:27 +0100)
With this change, execution time is reduced by 50% on a chord example with 10000 hosts.

src/surf/vm_workstation_hl13.cpp
src/surf/vm_workstation_interface.cpp
src/surf/vm_workstation_interface.hpp
src/surf/workstation_interface.cpp

index d9299c0..b5fe764 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.begin(); ++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;
@@ -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.begin(); ++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,
index 46299a4..688ad12 100644 (file)
@@ -28,6 +28,8 @@ WorkstationVMModel::WorkstationVMModel() : WorkstationModel("Virtual Workstation
   p_cpuModel = surf_cpu_model_vm;
 }
 
+WorkstationVMModel::vm_list_t WorkstationVMModel::ws_vms;
+
 /************
  * Resource *
  ************/
@@ -36,6 +38,7 @@ WorkstationVM::WorkstationVM(ModelPtr model, const char *name, xbt_dict_t props,
                        RoutingEdgePtr netElm, CpuPtr cpu)
 : Workstation(model, name, props, NULL, netElm, cpu)
 {
+  WorkstationVMModel::ws_vms.push_back(*this);
   surf_callback_emit(workstationVMCreatedCallbacks, this);
 }
 
@@ -46,6 +49,8 @@ WorkstationVM::WorkstationVM(ModelPtr model, const char *name, xbt_dict_t props,
 WorkstationVM::~WorkstationVM()
 {
   surf_callback_emit(workstationVMDestructedCallbacks, this);
+  WorkstationVMModel::ws_vms.erase(WorkstationVMModel::
+                                   vm_list_t::s_iterator_to(*this));
 }
 
 void WorkstationVM::setState(e_surf_resource_state_t state){
index 262b288..66a3e9d 100644 (file)
@@ -78,6 +78,11 @@ public:
   virtual void createResource(const char *name, void *ind_phys_workstation)=0;
 
   void adjustWeightOfDummyCpuActions() {};
+
+  typedef boost::intrusive::list<WorkstationVM,
+                                 boost::intrusive::constant_time_size<false> >
+          vm_list_t;
+  static vm_list_t ws_vms;
 };
 
 /************
@@ -88,7 +93,8 @@ public:
  * @brief SURF workstation VM interface class
  * @details A workstation VM represent an virtual machine
  */
-class WorkstationVM : public Workstation {
+class WorkstationVM : public Workstation,
+                      public boost::intrusive::list_base_hook<> {
 public:
   /**
    * @brief WorkstationVM consrtructor
index 5f8d501..cd22204 100644 (file)
@@ -46,24 +46,14 @@ WorkstationModel::~WorkstationModel() {
  * not get any CPU share in the PM layer. */
 void WorkstationModel::adjustWeightOfDummyCpuActions()
 {
-  /* 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]);
-    CpuCas01Ptr cpu_cas01 = static_cast<CpuCas01Ptr>(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_cas01, "cpu-less workstation");
+  /* iterate for all virtual machines */
+  for (WorkstationVMModel::vm_list_t::iterator iter =
+         WorkstationVMModel::ws_vms.begin();
+       iter !=  WorkstationVMModel::ws_vms.begin(); ++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;
+    CpuCas01Ptr cpu_cas01 = static_cast<CpuCas01Ptr>(ws_vm->p_cpu);
+    xbt_assert(cpu_cas01, "cpu-less workstation");
 
     int is_active = lmm_constraint_used(cpu_cas01->getModel()->getMaxminSystem(), cpu_cas01->getConstraint());
     // int is_active_old = constraint_is_active(cpu_cas01);
@@ -309,20 +299,12 @@ xbt_dynar_t Workstation::getVms()
 {
   xbt_dynar_t dyn = xbt_dynar_new(sizeof(smx_host_t), NULL);
 
-  /* 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]);
-    if (!ws)
-      continue;
-    /* skip if it is not a virtual machine */
-    if (ws->getModel() != static_cast<ModelPtr>(surf_vm_workstation_model))
-      continue;
-
-    /* It is a virtual machine, so we can cast it to workstation_VM2013_t */
-    WorkstationVMPtr ws_vm = static_cast<WorkstationVMPtr>(ws);
+  /* iterate for all virtual machines */
+  for (WorkstationVMModel::vm_list_t::iterator iter =
+         WorkstationVMModel::ws_vms.begin();
+       iter !=  WorkstationVMModel::ws_vms.begin(); ++iter) {
+
+    WorkstationVMPtr ws_vm = &*iter;
     if (this == ws_vm-> p_subWs)
       xbt_dynar_push(dyn, &ws_vm->p_subWs);
   }