Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Convert simgrid::simix::Host::process_list to boost::intrusive::list.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sat, 2 Dec 2017 20:46:02 +0000 (21:46 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sun, 3 Dec 2017 20:36:48 +0000 (21:36 +0100)
src/msg/msg_host.cpp
src/plugins/vm/VirtualMachineImpl.cpp
src/s4u/s4u_host.cpp
src/simix/ActorImpl.cpp
src/simix/ActorImpl.hpp
src/simix/smx_host.cpp
src/simix/smx_host_private.hpp
src/smpi/mpi/smpi_comm.cpp

index 5db2de1..3857879 100644 (file)
@@ -132,9 +132,8 @@ int MSG_host_get_core_number(msg_host_t host) {
 void MSG_host_get_process_list(msg_host_t host, xbt_dynar_t whereto)
 {
   xbt_assert((host != nullptr), "Invalid parameters");
 void MSG_host_get_process_list(msg_host_t host, xbt_dynar_t whereto)
 {
   xbt_assert((host != nullptr), "Invalid parameters");
-  smx_actor_t actor = NULL;
-  xbt_swag_foreach(actor, host->extension<simgrid::simix::Host>()->process_list) {
-    msg_process_t p = actor->ciface();
+  for (auto& actor : host->extension<simgrid::simix::Host>()->process_list) {
+    msg_process_t p = actor.ciface();
     xbt_dynar_push(whereto, &p);
   }
 }
     xbt_dynar_push(whereto, &p);
   }
 }
index 2cccd60..ce764f6 100644 (file)
@@ -176,16 +176,14 @@ void VirtualMachineImpl::suspend(smx_actor_t issuer)
   if (issuer->host == piface_)
     THROWF(vm_error, 0, "Actor %s cannot suspend the VM %s in which it runs", issuer->getCname(), piface_->getCname());
 
   if (issuer->host == piface_)
     THROWF(vm_error, 0, "Actor %s cannot suspend the VM %s in which it runs", issuer->getCname(), piface_->getCname());
 
-  xbt_swag_t process_list = piface_->extension<simgrid::simix::Host>()->process_list;
-  XBT_DEBUG("suspend VM(%s), where %d processes exist", piface_->getCname(), xbt_swag_size(process_list));
+  auto& process_list = piface_->extension<simgrid::simix::Host>()->process_list;
+  XBT_DEBUG("suspend VM(%s), where %zu processes exist", piface_->getCname(), process_list.size());
 
   action_->suspend();
 
 
   action_->suspend();
 
-  smx_actor_t smx_process;
-  smx_actor_t smx_process_safe;
-  xbt_swag_foreach_safe(smx_process, smx_process_safe, process_list) {
-    XBT_DEBUG("suspend %s", smx_process->name.c_str());
-    smx_process->suspend(issuer);
+  for (auto& smx_process : process_list) {
+    XBT_DEBUG("suspend %s", smx_process.name.c_str());
+    smx_process.suspend(issuer);
   }
 
   XBT_DEBUG("suspend all processes on the VM done done");
   }
 
   XBT_DEBUG("suspend all processes on the VM done done");
@@ -198,16 +196,14 @@ void VirtualMachineImpl::resume()
   if (getState() != SURF_VM_STATE_SUSPENDED)
     THROWF(vm_error, 0, "Cannot resume VM %s: it was not suspended", piface_->getCname());
 
   if (getState() != SURF_VM_STATE_SUSPENDED)
     THROWF(vm_error, 0, "Cannot resume VM %s: it was not suspended", piface_->getCname());
 
-  xbt_swag_t process_list = piface_->extension<simgrid::simix::Host>()->process_list;
-  XBT_DEBUG("Resume VM %s, containing %d processes.", piface_->getCname(), xbt_swag_size(process_list));
+  auto& process_list = piface_->extension<simgrid::simix::Host>()->process_list;
+  XBT_DEBUG("Resume VM %s, containing %zu processes.", piface_->getCname(), process_list.size());
 
   action_->resume();
 
 
   action_->resume();
 
-  smx_actor_t smx_process;
-  smx_actor_t smx_process_safe;
-  xbt_swag_foreach_safe(smx_process, smx_process_safe, process_list) {
-    XBT_DEBUG("resume %s", smx_process->getCname());
-    smx_process->resume();
+  for (auto& smx_process : process_list) {
+    XBT_DEBUG("resume %s", smx_process.getCname());
+    smx_process.resume();
   }
 
   vmState_ = SURF_VM_STATE_RUNNING;
   }
 
   vmState_ = SURF_VM_STATE_RUNNING;
@@ -241,15 +237,13 @@ void VirtualMachineImpl::shutdown(smx_actor_t issuer)
     XBT_VERB("Shutting down the VM %s even if it's not running but %s", piface_->getCname(), stateName);
   }
 
     XBT_VERB("Shutting down the VM %s even if it's not running but %s", piface_->getCname(), stateName);
   }
 
-  xbt_swag_t process_list = piface_->extension<simgrid::simix::Host>()->process_list;
-  XBT_DEBUG("shutdown VM %s, that contains %d processes", piface_->getCname(), xbt_swag_size(process_list));
+  auto& process_list = piface_->extension<simgrid::simix::Host>()->process_list;
+  XBT_DEBUG("shutdown VM %s, that contains %zu processes", piface_->getCname(), process_list.size());
 
 
-  smx_actor_t smx_process;
-  smx_actor_t smx_process_safe;
-  xbt_swag_foreach_safe(smx_process, smx_process_safe, process_list) {
-    XBT_DEBUG("kill %s@%s on behalf of %s which shutdown that VM.", smx_process->getCname(),
-              smx_process->host->getCname(), issuer->getCname());
-    SIMIX_process_kill(smx_process, issuer);
+  for (auto& smx_process : process_list) {
+    XBT_DEBUG("kill %s@%s on behalf of %s which shutdown that VM.", smx_process.getCname(),
+              smx_process.host->getCname(), issuer->getCname());
+    SIMIX_process_kill(&smx_process, issuer);
   }
 
   setState(SURF_VM_STATE_DESTROYED);
   }
 
   setState(SURF_VM_STATE_DESTROYED);
index f173821..da99e12 100644 (file)
@@ -134,10 +134,8 @@ int Host::getPstatesCount() const
  */
 void Host::actorList(std::vector<ActorPtr>* whereto)
 {
  */
 void Host::actorList(std::vector<ActorPtr>* whereto)
 {
-  smx_actor_t actor = NULL;
-  xbt_swag_foreach(actor, this->extension<simgrid::simix::Host>()->process_list)
-  {
-    whereto->push_back(actor->ciface());
+  for (auto& actor : this->extension<simgrid::simix::Host>()->process_list) {
+    whereto->push_back(actor.ciface());
   }
 }
 
   }
 }
 
@@ -193,9 +191,8 @@ void Host::setProperty(std::string key, std::string value)
 /** Get the processes attached to the host */
 void Host::getProcesses(std::vector<ActorPtr>* list)
 {
 /** Get the processes attached to the host */
 void Host::getProcesses(std::vector<ActorPtr>* list)
 {
-  smx_actor_t actor = NULL;
-  xbt_swag_foreach(actor, this->extension<simgrid::simix::Host>()->process_list) {
-    list->push_back(actor->iface());
+  for (auto& actor : this->extension<simgrid::simix::Host>()->process_list) {
+    list->push_back(actor.iface());
   }
 }
 
   }
 }
 
index 29ca5bf..3effdcb 100644 (file)
@@ -112,8 +112,10 @@ void SIMIX_process_cleanup(smx_actor_t process)
 
   XBT_DEBUG("%p should not be run anymore",process);
   simix_global->process_list.erase(process->pid);
 
   XBT_DEBUG("%p should not be run anymore",process);
   simix_global->process_list.erase(process->pid);
-  if (process->host)
-    xbt_swag_remove(process, process->host->extension<simgrid::simix::Host>()->process_list);
+  if (process->host && process->host_process_list_hook.is_linked()) {
+    auto& list = process->host->extension<simgrid::simix::Host>()->process_list;
+    list.erase(list.iterator_to(*process));
+  }
   xbt_swag_insert(process, simix_global->process_to_destroy);
   process->context->iwannadie = 0;
 
   xbt_swag_insert(process, simix_global->process_to_destroy);
   process->context->iwannadie = 0;
 
@@ -340,7 +342,7 @@ smx_actor_t SIMIX_process_create(const char* name, std::function<void()> code, v
     host->extension_set<simgrid::simix::Host>(new simgrid::simix::Host());
 
   /* Add the process to its host process list */
     host->extension_set<simgrid::simix::Host>(new simgrid::simix::Host());
 
   /* Add the process to its host process list */
-  xbt_swag_insert(process, host->extension<simgrid::simix::Host>()->process_list);
+  host->extension<simgrid::simix::Host>()->process_list.push_back(*process);
 
   XBT_DEBUG("Start context '%s'", process->name.c_str());
 
 
   XBT_DEBUG("Start context '%s'", process->name.c_str());
 
@@ -406,7 +408,7 @@ smx_actor_t SIMIX_process_attach(const char* name, void* data, const char* hostn
       process->setProperty(kv.first, kv.second);
 
   /* Add the process to it's host process list */
       process->setProperty(kv.first, kv.second);
 
   /* Add the process to it's host process list */
-  xbt_swag_insert(process, host->extension<simgrid::simix::Host>()->process_list);
+  host->extension<simgrid::simix::Host>()->process_list.push_back(*process);
 
   /* Now insert it in the global process list and in the process to run list */
   simix_global->process_list[process->pid] = process;
 
   /* Now insert it in the global process list and in the process to run list */
   simix_global->process_list[process->pid] = process;
@@ -598,9 +600,10 @@ void SIMIX_process_killall(smx_actor_t issuer, int reset_pid)
 void SIMIX_process_change_host(smx_actor_t process, sg_host_t dest)
 {
   xbt_assert((process != nullptr), "Invalid parameters");
 void SIMIX_process_change_host(smx_actor_t process, sg_host_t dest)
 {
   xbt_assert((process != nullptr), "Invalid parameters");
-  xbt_swag_remove(process, process->host->extension<simgrid::simix::Host>()->process_list);
+  auto& list = process->host->extension<simgrid::simix::Host>()->process_list;
+  list.erase(list.iterator_to(*process));
   process->host = dest;
   process->host = dest;
-  xbt_swag_insert(process, dest->extension<simgrid::simix::Host>()->process_list);
+  dest->extension<simgrid::simix::Host>()->process_list.push_back(*process);
 }
 
 void simcall_HANDLER_process_suspend(smx_simcall_t simcall, smx_actor_t process)
 }
 
 void simcall_HANDLER_process_suspend(smx_simcall_t simcall, smx_actor_t process)
index b0c3b44..e8cf408 100644 (file)
@@ -10,6 +10,7 @@
 #include "src/simix/popping_private.hpp"
 #include "src/surf/PropertyHolder.hpp"
 #include "xbt/swag.h"
 #include "src/simix/popping_private.hpp"
 #include "src/surf/PropertyHolder.hpp"
 #include "xbt/swag.h"
+#include <boost/intrusive/list.hpp>
 #include <list>
 #include <map>
 
 #include <list>
 #include <map>
 
@@ -39,8 +40,8 @@ public:
 
   // TODO, replace with boost intrusive container hooks
   s_xbt_swag_hookup_t synchro_hookup   = { nullptr, nullptr }; /* {mutex,cond,sem}->sleeping */
 
   // TODO, replace with boost intrusive container hooks
   s_xbt_swag_hookup_t synchro_hookup   = { nullptr, nullptr }; /* {mutex,cond,sem}->sleeping */
-  s_xbt_swag_hookup_t host_proc_hookup = { nullptr, nullptr }; /* smx_host->process_lis */
   s_xbt_swag_hookup_t destroy_hookup   = { nullptr, nullptr }; /* simix_global->process_to_destroy */
   s_xbt_swag_hookup_t destroy_hookup   = { nullptr, nullptr }; /* simix_global->process_to_destroy */
+  boost::intrusive::list_member_hook<> host_process_list_hook; /* simgrid::simix::Host::process_list */
 
   aid_t pid  = 0;
   aid_t ppid = -1;
 
   aid_t pid  = 0;
   aid_t ppid = -1;
index 393256f..60f61ca 100644 (file)
@@ -22,19 +22,15 @@ namespace simgrid {
     {
       if (not Host::EXTENSION_ID.valid())
         Host::EXTENSION_ID = s4u::Host::extension_create<simix::Host>();
     {
       if (not Host::EXTENSION_ID.valid())
         Host::EXTENSION_ID = s4u::Host::extension_create<simix::Host>();
-
-      simgrid::simix::ActorImpl act;
-      process_list = xbt_swag_new(xbt_swag_offset(act, host_proc_hookup));
     }
 
     Host::~Host()
     {
       /* All processes should be gone when the host is turned off (by the end of the simulation). */
     }
 
     Host::~Host()
     {
       /* All processes should be gone when the host is turned off (by the end of the simulation). */
-      if (xbt_swag_size(process_list) != 0) {
+      if (not process_list.empty()) {
         std::string msg     = std::string("Shutting down host, but it's not empty:");
         std::string msg     = std::string("Shutting down host, but it's not empty:");
-        smx_actor_t process = nullptr;
-
-        xbt_swag_foreach(process, process_list) msg = msg + "\n\t" + process->name.c_str();
+        for (auto const& process : process_list)
+          msg += "\n\t" + std::string(process.getName());
 
         SIMIX_display_process_status();
         THROWF(arg_error, 0, "%s", msg.c_str());
 
         SIMIX_display_process_status();
         THROWF(arg_error, 0, "%s", msg.c_str());
@@ -45,7 +41,6 @@ namespace simgrid {
       for (auto const& arg : boot_processes)
         delete arg;
       boot_processes.clear();
       for (auto const& arg : boot_processes)
         delete arg;
       boot_processes.clear();
-      xbt_swag_free(process_list);
     }
 
     /** Re-starts all the actors that are marked as restartable.
     }
 
     /** Re-starts all the actors that are marked as restartable.
@@ -78,12 +73,11 @@ void SIMIX_host_off(sg_host_t h, smx_actor_t issuer)
     h->pimpl_cpu->turnOff();
 
     /* Clean Simulator data */
     h->pimpl_cpu->turnOff();
 
     /* Clean Simulator data */
-    if (xbt_swag_size(host->process_list) != 0) {
-      smx_actor_t process = nullptr;
-      xbt_swag_foreach(process, host->process_list) {
-        SIMIX_process_kill(process, issuer);
-        XBT_DEBUG("Killing %s@%s on behalf of %s which turned off that host.", process->getCname(),
-                  process->host->getCname(), issuer->getCname());
+    if (not host->process_list.empty()) {
+      for (auto& process : host->process_list) {
+        SIMIX_process_kill(&process, issuer);
+        XBT_DEBUG("Killing %s@%s on behalf of %s which turned off that host.", process.getCname(),
+                  process.host->getCname(), issuer->getCname());
       }
     }
   } else {
       }
     }
   } else {
index 5f49d3f..50a6f5f 100644 (file)
@@ -6,6 +6,7 @@
 #ifndef SIMIX_HOST_PRIVATE_HPP
 #define SIMIX_HOST_PRIVATE_HPP
 
 #ifndef SIMIX_HOST_PRIVATE_HPP
 #define SIMIX_HOST_PRIVATE_HPP
 
+#include <boost/intrusive/list.hpp>
 #include <functional>
 #include <map>
 #include <vector>
 #include <functional>
 #include <map>
 #include <vector>
@@ -30,7 +31,9 @@ public:
   explicit Host();
   virtual ~Host();
 
   explicit Host();
   virtual ~Host();
 
-  xbt_swag_t process_list;
+  boost::intrusive::list<ActorImpl, boost::intrusive::member_hook<ActorImpl, boost::intrusive::list_member_hook<>,
+                                                                  &ActorImpl::host_process_list_hook>>
+      process_list;
   std::vector<ProcessArg*> auto_restart_processes;
   std::vector<ProcessArg*> boot_processes;
 
   std::vector<ProcessArg*> auto_restart_processes;
   std::vector<ProcessArg*> boot_processes;
 
index 4998ea0..68df118 100644 (file)
@@ -302,14 +302,11 @@ void Comm::init_smp(){
   }
   //identify neighbours in comm
   //get the indexes of all processes sharing the same simix host
   }
   //identify neighbours in comm
   //get the indexes of all processes sharing the same simix host
-  xbt_swag_t process_list = sg_host_self()->extension<simgrid::simix::Host>()->process_list;
+  const auto& process_list = sg_host_self()->extension<simgrid::simix::Host>()->process_list;
   int intra_comm_size     = 0;
   int min_index           = INT_MAX; // the minimum index will be the leader
   int intra_comm_size     = 0;
   int min_index           = INT_MAX; // the minimum index will be the leader
-  smx_actor_t actor       = nullptr;
-  xbt_swag_foreach(actor, process_list)
-  {
-    int index = actor->pid - 1;
-
+  for (auto const& actor : process_list) {
+    int index = actor.pid - 1;
     if (this->group()->rank(index) != MPI_UNDEFINED) {
       intra_comm_size++;
       // the process is in the comm
     if (this->group()->rank(index) != MPI_UNDEFINED) {
       intra_comm_size++;
       // the process is in the comm
@@ -320,9 +317,8 @@ void Comm::init_smp(){
   XBT_DEBUG("number of processes deployed on my node : %d", intra_comm_size);
   MPI_Group group_intra = new  Group(intra_comm_size);
   int i = 0;
   XBT_DEBUG("number of processes deployed on my node : %d", intra_comm_size);
   MPI_Group group_intra = new  Group(intra_comm_size);
   int i = 0;
-  actor = nullptr;
-  xbt_swag_foreach(actor, process_list) {
-    int index = actor->pid -1;
+  for (auto const& actor : process_list) {
+    int index = actor.pid - 1;
     if(this->group()->rank(index)!=MPI_UNDEFINED){
       group_intra->set_mapping(index, i);
       i++;
     if(this->group()->rank(index)!=MPI_UNDEFINED){
       group_intra->set_mapping(index, i);
       i++;