From fb87a25b953371e3523b597ee68427d4d590c05a Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Sat, 2 Dec 2017 21:46:02 +0100 Subject: [PATCH] Convert simgrid::simix::Host::process_list to boost::intrusive::list. --- src/msg/msg_host.cpp | 5 ++-- src/plugins/vm/VirtualMachineImpl.cpp | 38 +++++++++++---------------- src/s4u/s4u_host.cpp | 11 +++----- src/simix/ActorImpl.cpp | 15 ++++++----- src/simix/ActorImpl.hpp | 3 ++- src/simix/smx_host.cpp | 22 ++++++---------- src/simix/smx_host_private.hpp | 5 +++- src/smpi/mpi/smpi_comm.cpp | 14 ++++------ 8 files changed, 50 insertions(+), 63 deletions(-) diff --git a/src/msg/msg_host.cpp b/src/msg/msg_host.cpp index 5db2de1d5c..3857879173 100644 --- a/src/msg/msg_host.cpp +++ b/src/msg/msg_host.cpp @@ -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"); - smx_actor_t actor = NULL; - xbt_swag_foreach(actor, host->extension()->process_list) { - msg_process_t p = actor->ciface(); + for (auto& actor : host->extension()->process_list) { + msg_process_t p = actor.ciface(); xbt_dynar_push(whereto, &p); } } diff --git a/src/plugins/vm/VirtualMachineImpl.cpp b/src/plugins/vm/VirtualMachineImpl.cpp index 2cccd60a8d..ce764f6be8 100644 --- a/src/plugins/vm/VirtualMachineImpl.cpp +++ b/src/plugins/vm/VirtualMachineImpl.cpp @@ -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()); - xbt_swag_t process_list = piface_->extension()->process_list; - XBT_DEBUG("suspend VM(%s), where %d processes exist", piface_->getCname(), xbt_swag_size(process_list)); + auto& process_list = piface_->extension()->process_list; + XBT_DEBUG("suspend VM(%s), where %zu processes exist", piface_->getCname(), process_list.size()); 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"); @@ -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()); - xbt_swag_t process_list = piface_->extension()->process_list; - XBT_DEBUG("Resume VM %s, containing %d processes.", piface_->getCname(), xbt_swag_size(process_list)); + auto& process_list = piface_->extension()->process_list; + XBT_DEBUG("Resume VM %s, containing %zu processes.", piface_->getCname(), process_list.size()); 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; @@ -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_swag_t process_list = piface_->extension()->process_list; - XBT_DEBUG("shutdown VM %s, that contains %d processes", piface_->getCname(), xbt_swag_size(process_list)); + auto& process_list = piface_->extension()->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); diff --git a/src/s4u/s4u_host.cpp b/src/s4u/s4u_host.cpp index f1738215b0..da99e12394 100644 --- a/src/s4u/s4u_host.cpp +++ b/src/s4u/s4u_host.cpp @@ -134,10 +134,8 @@ int Host::getPstatesCount() const */ void Host::actorList(std::vector* whereto) { - smx_actor_t actor = NULL; - xbt_swag_foreach(actor, this->extension()->process_list) - { - whereto->push_back(actor->ciface()); + for (auto& actor : this->extension()->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* list) { - smx_actor_t actor = NULL; - xbt_swag_foreach(actor, this->extension()->process_list) { - list->push_back(actor->iface()); + for (auto& actor : this->extension()->process_list) { + list->push_back(actor.iface()); } } diff --git a/src/simix/ActorImpl.cpp b/src/simix/ActorImpl.cpp index 29ca5bfda2..3effdcb81e 100644 --- a/src/simix/ActorImpl.cpp +++ b/src/simix/ActorImpl.cpp @@ -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); - if (process->host) - xbt_swag_remove(process, process->host->extension()->process_list); + if (process->host && process->host_process_list_hook.is_linked()) { + auto& list = process->host->extension()->process_list; + list.erase(list.iterator_to(*process)); + } 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 code, v host->extension_set(new simgrid::simix::Host()); /* Add the process to its host process list */ - xbt_swag_insert(process, host->extension()->process_list); + host->extension()->process_list.push_back(*process); 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 */ - xbt_swag_insert(process, host->extension()->process_list); + host->extension()->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; @@ -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"); - xbt_swag_remove(process, process->host->extension()->process_list); + auto& list = process->host->extension()->process_list; + list.erase(list.iterator_to(*process)); process->host = dest; - xbt_swag_insert(process, dest->extension()->process_list); + dest->extension()->process_list.push_back(*process); } void simcall_HANDLER_process_suspend(smx_simcall_t simcall, smx_actor_t process) diff --git a/src/simix/ActorImpl.hpp b/src/simix/ActorImpl.hpp index b0c3b44917..e8cf4089cd 100644 --- a/src/simix/ActorImpl.hpp +++ b/src/simix/ActorImpl.hpp @@ -10,6 +10,7 @@ #include "src/simix/popping_private.hpp" #include "src/surf/PropertyHolder.hpp" #include "xbt/swag.h" +#include #include #include @@ -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 */ - 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 */ + boost::intrusive::list_member_hook<> host_process_list_hook; /* simgrid::simix::Host::process_list */ aid_t pid = 0; aid_t ppid = -1; diff --git a/src/simix/smx_host.cpp b/src/simix/smx_host.cpp index 393256fc27..60f61ca94a 100644 --- a/src/simix/smx_host.cpp +++ b/src/simix/smx_host.cpp @@ -22,19 +22,15 @@ namespace simgrid { { if (not Host::EXTENSION_ID.valid()) Host::EXTENSION_ID = s4u::Host::extension_create(); - - 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). */ - 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:"); - 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()); @@ -45,7 +41,6 @@ namespace simgrid { 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. @@ -78,12 +73,11 @@ void SIMIX_host_off(sg_host_t h, smx_actor_t issuer) 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 { diff --git a/src/simix/smx_host_private.hpp b/src/simix/smx_host_private.hpp index 5f49d3fe1e..50a6f5f6c8 100644 --- a/src/simix/smx_host_private.hpp +++ b/src/simix/smx_host_private.hpp @@ -6,6 +6,7 @@ #ifndef SIMIX_HOST_PRIVATE_HPP #define SIMIX_HOST_PRIVATE_HPP +#include #include #include #include @@ -30,7 +31,9 @@ public: explicit Host(); virtual ~Host(); - xbt_swag_t process_list; + boost::intrusive::list, + &ActorImpl::host_process_list_hook>> + process_list; std::vector auto_restart_processes; std::vector boot_processes; diff --git a/src/smpi/mpi/smpi_comm.cpp b/src/smpi/mpi/smpi_comm.cpp index 4998ea0c11..68df1180c9 100644 --- a/src/smpi/mpi/smpi_comm.cpp +++ b/src/smpi/mpi/smpi_comm.cpp @@ -302,14 +302,11 @@ void Comm::init_smp(){ } //identify neighbours in comm //get the indexes of all processes sharing the same simix host - xbt_swag_t process_list = sg_host_self()->extension()->process_list; + const auto& process_list = sg_host_self()->extension()->process_list; 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 @@ -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; - 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++; -- 2.20.1