From: Martin Quinson Date: Sun, 1 Jul 2018 20:44:55 +0000 (+0200) Subject: merge extension() into HostImpl X-Git-Tag: v3_21~582 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/9f4672a8f952ceca9efa2771cce911306ae82592?ds=sidebyside merge extension() into HostImpl --- diff --git a/src/plugins/vm/VirtualMachineImpl.cpp b/src/plugins/vm/VirtualMachineImpl.cpp index 0b89632746..5553650a53 100644 --- a/src/plugins/vm/VirtualMachineImpl.cpp +++ b/src/plugins/vm/VirtualMachineImpl.cpp @@ -147,7 +147,7 @@ void VirtualMachineImpl::suspend(smx_actor_t issuer) THROWF(vm_error, 0, "Actor %s cannot suspend the VM %s in which it runs", issuer->get_cname(), piface_->get_cname()); - auto& process_list = piface_->extension()->process_list; + auto& process_list = piface_->pimpl_->process_list; XBT_DEBUG("suspend VM(%s), where %zu processes exist", piface_->get_cname(), process_list.size()); action_->suspend(); @@ -167,7 +167,7 @@ void VirtualMachineImpl::resume() if (get_state() != s4u::VirtualMachine::state::SUSPENDED) THROWF(vm_error, 0, "Cannot resume VM %s: it was not suspended", piface_->get_cname()); - auto& process_list = piface_->extension()->process_list; + auto& process_list = piface_->pimpl_->process_list; XBT_DEBUG("Resume VM %s, containing %zu processes.", piface_->get_cname(), process_list.size()); action_->resume(); @@ -208,7 +208,7 @@ void VirtualMachineImpl::shutdown(smx_actor_t issuer) XBT_VERB("Shutting down the VM %s even if it's not running but %s", piface_->get_cname(), stateName); } - auto& process_list = piface_->extension()->process_list; + auto& process_list = piface_->pimpl_->process_list; XBT_DEBUG("shutdown VM %s, that contains %zu processes", piface_->get_cname(), process_list.size()); for (auto& smx_process : process_list) { diff --git a/src/plugins/vm/s4u_VirtualMachine.cpp b/src/plugins/vm/s4u_VirtualMachine.cpp index b727465c9f..c81a2cdc32 100644 --- a/src/plugins/vm/s4u_VirtualMachine.cpp +++ b/src/plugins/vm/s4u_VirtualMachine.cpp @@ -42,9 +42,6 @@ VirtualMachine::VirtualMachine(const char* name, s4u::Host* physical_host, int c surf_cpu_model_vm->create_cpu(this, &speeds, physical_host->get_core_count()); if (physical_host->get_pstate() != 0) set_pstate(physical_host->get_pstate()); - - /* Make a process container */ - extension_set(new simgrid::simix::Host()); } VirtualMachine::~VirtualMachine() @@ -53,14 +50,6 @@ VirtualMachine::~VirtualMachine() XBT_DEBUG("destroy %s", get_cname()); - /* FIXME: this is really strange that everything fails if the next line is removed. - * This is as if we shared these data with the PM, which definitely should not be the case... - * - * We need to test that suspending a VM does not suspends the processes running on its PM, for example. - * Or we need to simplify this code enough to make it actually readable (but this sounds harder than testing) - */ - extension_set(nullptr); - /* Don't free these things twice: they are the ones of my physical host */ pimpl_netpoint = nullptr; } diff --git a/src/s4u/s4u_Host.cpp b/src/s4u/s4u_Host.cpp index f897380f3d..af48c95bf2 100644 --- a/src/s4u/s4u_Host.cpp +++ b/src/s4u/s4u_Host.cpp @@ -93,7 +93,7 @@ void Host::turn_on() { if (is_off()) { simgrid::simix::simcall([this] { - this->extension()->turnOn(); + this->pimpl_->turn_on(); this->pimpl_cpu->turn_on(); on_state_change(*this); }); @@ -106,20 +106,8 @@ void Host::turn_off() if (is_on()) { smx_actor_t self = SIMIX_process_self(); simgrid::simix::simcall([this, self] { - simgrid::simix::Host* host = this->extension(); - - xbt_assert((host != nullptr), "Invalid parameters"); - this->pimpl_cpu->turn_off(); - - /* Clean Simulator data */ - if (not host->process_list.empty()) { - for (auto& process : host->process_list) { - SIMIX_process_kill(&process, self); - XBT_DEBUG("Killing %s@%s on behalf of %s which turned off that host.", process.get_cname(), - process.host_->get_cname(), self->get_cname()); - } - } + this->pimpl_->turn_off(); on_state_change(*this); }); @@ -143,32 +131,29 @@ int Host::get_pstate_count() const */ std::vector Host::get_all_actors() { - std::vector res; - for (auto& actor : this->extension()->process_list) - res.push_back(actor.ciface()); - return res; + return pimpl_->get_all_actors(); } /** @brief Returns how many actors (daemonized or not) have been launched on this host */ int Host::get_actor_count() { - return this->extension()->process_list.size(); + return pimpl_->get_actor_count(); } /** @deprecated */ void Host::getProcesses(std::vector* list) { - for (auto& actor : this->extension()->process_list) { - list->push_back(actor.iface()); - } + auto actors = get_all_actors(); + for (auto& actor : actors) + list->push_back(actor); } /** @deprecated */ void Host::actorList(std::vector* whereto) { - for (auto& actor : this->extension()->process_list) { - whereto->push_back(actor.ciface()); - } + auto actors = get_all_actors(); + for (auto& actor : actors) + whereto->push_back(actor); } /** @@ -635,10 +620,9 @@ void sg_host_dump(sg_host_t host) */ void sg_host_get_actor_list(sg_host_t host, xbt_dynar_t whereto) { - for (auto& actor : host->extension()->process_list) { - s4u_Actor* p = actor.ciface(); - xbt_dynar_push(whereto, &p); - } + auto actors = host->get_all_actors(); + for (auto& actor : actors) + xbt_dynar_push(whereto, &actor); } sg_host_t sg_host_self() diff --git a/src/simix/ActorImpl.cpp b/src/simix/ActorImpl.cpp index 4c3537f7ec..da87116cbf 100644 --- a/src/simix/ActorImpl.cpp +++ b/src/simix/ActorImpl.cpp @@ -13,6 +13,7 @@ #include "src/simix/smx_host_private.hpp" #include "src/simix/smx_io_private.hpp" #include "src/simix/smx_synchro_private.hpp" +#include "src/surf/HostImpl.hpp" #include "src/surf/cpu_interface.hpp" #include "xbt/ex.hpp" @@ -101,7 +102,7 @@ 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_ && process->host_process_list_hook.is_linked()) - simgrid::xbt::intrusive_erase(process->host_->extension()->process_list, *process); + simgrid::xbt::intrusive_erase(process->host_->pimpl_->process_list, *process); if (not process->smx_destroy_list_hook.is_linked()) { #if SIMGRID_HAVE_MC xbt_dynar_push_as(simix_global->dead_actors_vector, smx_actor_t, process); @@ -312,12 +313,8 @@ smx_actor_t SIMIX_process_create(const char* name, simgrid::simix::ActorCode cod for (auto const& kv : *properties) process->set_property(kv.first, kv.second); - /* Make sure that the process is initialized for simix, in case we are called from the Host::onCreation signal */ - if (host->extension() == nullptr) - host->extension_set(new simgrid::simix::Host()); - /* Add the process to its host's process list */ - host->extension()->process_list.push_back(*process); + host->pimpl_->process_list.push_back(*process); XBT_DEBUG("Start context '%s'", process->get_cname()); @@ -374,7 +371,7 @@ smx_actor_t SIMIX_process_attach(const char* name, void* data, const char* hostn process->set_property(kv.first, kv.second); /* Add the process to it's host process list */ - host->extension()->process_list.push_back(*process); + host->pimpl_->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; @@ -567,9 +564,9 @@ void SIMIX_process_killall(smx_actor_t issuer) void SIMIX_process_change_host(smx_actor_t actor, sg_host_t dest) { xbt_assert((actor != nullptr), "Invalid parameters"); - simgrid::xbt::intrusive_erase(actor->host_->extension()->process_list, *actor); + simgrid::xbt::intrusive_erase(actor->host_->pimpl_->process_list, *actor); actor->host_ = dest; - dest->extension()->process_list.push_back(*actor); + dest->pimpl_->process_list.push_back(*actor); } void simcall_HANDLER_process_suspend(smx_simcall_t simcall, smx_actor_t process) diff --git a/src/simix/smx_global.cpp b/src/simix/smx_global.cpp index f16fa8980c..9e11626edf 100644 --- a/src/simix/smx_global.cpp +++ b/src/simix/smx_global.cpp @@ -9,12 +9,12 @@ #include "../kernel/activity/IoImpl.hpp" #include "simgrid/sg_config.hpp" -#include "smx_private.hpp" #include "src/kernel/activity/SleepImpl.hpp" #include "src/kernel/activity/SynchroRaw.hpp" #include "src/mc/mc_record.hpp" #include "src/mc/mc_replay.hpp" #include "src/simix/smx_host_private.hpp" +#include "src/simix/smx_private.hpp" #include "src/smpi/include/smpi_process.hpp" #include "src/surf/StorageImpl.hpp" #include "src/surf/xml/platf.hpp" @@ -208,10 +208,6 @@ void SIMIX_global_init(int *argc, char **argv) /* register a function to be called by SURF after the environment creation */ sg_platf_init(); simgrid::s4u::on_platform_created.connect(SIMIX_post_create_environment); - simgrid::s4u::Host::on_creation.connect([](simgrid::s4u::Host& host) { - if (host.extension() == nullptr) // another callback to the same signal may have created it - host.extension_set(new simgrid::simix::Host()); - }); simgrid::s4u::Storage::on_creation.connect([](simgrid::s4u::Storage& storage) { sg_storage_t s = simgrid::s4u::Storage::by_name(storage.get_cname()); diff --git a/src/simix/smx_host.cpp b/src/simix/smx_host.cpp index 3e565cbc86..a1f5cdf802 100644 --- a/src/simix/smx_host.cpp +++ b/src/simix/smx_host.cpp @@ -13,54 +13,6 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_host, simix, "SIMIX hosts"); -namespace simgrid { - namespace simix { - simgrid::xbt::Extension Host::EXTENSION_ID; - - Host::Host() - { - if (not Host::EXTENSION_ID.valid()) - Host::EXTENSION_ID = s4u::Host::extension_create(); - } - - Host::~Host() - { - /* All processes should be gone when the host is turned off (by the end of the simulation). */ - if (not process_list.empty()) { - std::string msg = std::string("Shutting down host, but it's not empty:"); - for (auto const& process : process_list) - msg += "\n\t" + std::string(process.get_name()); - - SIMIX_display_process_status(); - THROWF(arg_error, 0, "%s", msg.c_str()); - } - for (auto const& arg : auto_restart_processes) - delete arg; - auto_restart_processes.clear(); - for (auto const& arg : boot_processes) - delete arg; - boot_processes.clear(); - } - - /** Re-starts all the actors that are marked as restartable. - * - * Weird things will happen if you turn on an host that is already on. S4U is fool-proof, not this. - */ - void Host::turnOn() - { - for (auto const& arg : boot_processes) { - XBT_DEBUG("Booting Process %s(%s) right now", arg->name.c_str(), arg->host->get_cname()); - smx_actor_t actor = simix_global->create_process_function(arg->name.c_str(), arg->code, nullptr, arg->host, - arg->properties.get(), nullptr); - if (arg->kill_time >= 0) - simcall_process_set_kill_time(actor, arg->kill_time); - if (arg->auto_restart) - actor->auto_restart_ = arg->auto_restart; - } - } - -}} // namespaces - /* needs to be public and without simcall for exceptions and logging events */ const char* sg_host_self_get_name() { @@ -87,14 +39,13 @@ void SIMIX_host_add_auto_restart_process(sg_host_t host, simgrid::kernel::actor: XBT_DEBUG("Push host %s to watched_hosts because state == SURF_RESOURCE_OFF", host->get_cname()); } XBT_DEBUG("Adding Process %s to the auto-restart list of Host %s", arg->name.c_str(), arg->host->get_cname()); - host->extension()->auto_restart_processes.push_back(arg); + host->pimpl_->auto_restart_processes.push_back(arg); } /** @brief Restart the list of processes that have been registered to the host */ void SIMIX_host_autorestart(sg_host_t host) { - std::vector process_list = - host->extension()->auto_restart_processes; + std::vector process_list = host->pimpl_->auto_restart_processes; for (auto const& arg : process_list) { XBT_DEBUG("Restarting Process %s@%s right now", arg->name.c_str(), arg->host->get_cname()); diff --git a/src/simix/smx_host_private.hpp b/src/simix/smx_host_private.hpp index 87d081addb..920bc47f16 100644 --- a/src/simix/smx_host_private.hpp +++ b/src/simix/smx_host_private.hpp @@ -15,29 +15,6 @@ #include "src/simix/popping_private.hpp" #include "xbt/Extendable.hpp" -/** @brief Host datatype from SIMIX POV */ -namespace simgrid { -namespace simix { - -class Host { -public: - static simgrid::xbt::Extension EXTENSION_ID; - - explicit Host(); - virtual ~Host(); - - boost::intrusive::list, - &kernel::actor::ActorImpl::host_process_list_hook>> - process_list; - std::vector auto_restart_processes; - std::vector boot_processes; - - void turnOn(); -}; -} -} - XBT_PRIVATE void SIMIX_host_add_auto_restart_process(sg_host_t host, simgrid::kernel::actor::ActorImpl* actor); XBT_PRIVATE void SIMIX_host_autorestart(sg_host_t host); diff --git a/src/smpi/mpi/smpi_comm.cpp b/src/smpi/mpi/smpi_comm.cpp index 02b66fb946..4b0d125e85 100644 --- a/src/smpi/mpi/smpi_comm.cpp +++ b/src/smpi/mpi/smpi_comm.cpp @@ -14,6 +14,7 @@ #include "smpi_win.hpp" #include "src/simix/smx_host_private.hpp" #include "src/simix/smx_private.hpp" +#include "src/surf/HostImpl.hpp" #include #include @@ -306,7 +307,7 @@ void Comm::init_smp(){ } //identify neighbours in comm //get the indices of all processes sharing the same simix host - auto& process_list = sg_host_self()->extension()->process_list; + auto& process_list = sg_host_self()->pimpl_->process_list; int intra_comm_size = 0; int min_index = INT_MAX; // the minimum index will be the leader for (auto& actor : process_list) { diff --git a/src/surf/HostImpl.cpp b/src/surf/HostImpl.cpp index ef849d34fe..b24d0c04ca 100644 --- a/src/surf/HostImpl.cpp +++ b/src/surf/HostImpl.cpp @@ -4,6 +4,8 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "src/plugins/vm/VirtualMachineImpl.hpp" +#include "src/simix/smx_private.hpp" + #include XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_host, surf, "Logging specific to the SURF host module"); @@ -100,7 +102,64 @@ HostImpl::HostImpl(s4u::Host* host) : piface_(host) delete piface_->pimpl_; piface_->pimpl_ = this; } +HostImpl::~HostImpl() +{ + /* All processes should be gone when the host is turned off (by the end of the simulation). */ + if (not process_list.empty()) { + std::string msg = std::string("Shutting down host, but it's not empty:"); + for (auto const& process : process_list) + msg += "\n\t" + std::string(process.get_name()); + + SIMIX_display_process_status(); + THROWF(arg_error, 0, "%s", msg.c_str()); + } + for (auto const& arg : auto_restart_processes) + delete arg; + auto_restart_processes.clear(); + for (auto const& arg : boot_processes) + delete arg; + boot_processes.clear(); +} + +/** Re-starts all the actors that are marked as restartable. + * + * Weird things will happen if you turn on an host that is already on. S4U is fool-proof, not this. + */ +void HostImpl::turn_on() +{ + for (auto const& arg : boot_processes) { + XBT_DEBUG("Booting Process %s(%s) right now", arg->name.c_str(), arg->host->get_cname()); + smx_actor_t actor = simix_global->create_process_function(arg->name.c_str(), arg->code, nullptr, arg->host, + arg->properties.get(), nullptr); + if (arg->kill_time >= 0) + simcall_process_set_kill_time(actor, arg->kill_time); + if (arg->auto_restart) + actor->auto_restart_ = arg->auto_restart; + } +} +/** Kill all actors hosted here */ +void HostImpl::turn_off() +{ + if (not process_list.empty()) { + for (auto& actor : process_list) { + SIMIX_process_kill(&actor, SIMIX_process_self()); + XBT_DEBUG("Killing %s@%s on behalf of %s which turned off that host.", actor.get_cname(), + actor.host_->get_cname(), SIMIX_process_self()->get_cname()); + } + } +} +std::vector HostImpl::get_all_actors() +{ + std::vector res; + for (auto& actor : process_list) + res.push_back(actor.ciface()); + return res; +} +int HostImpl::get_actor_count() +{ + return process_list.size(); +} std::vector HostImpl::get_attached_storages() { std::vector storages; diff --git a/src/surf/HostImpl.hpp b/src/surf/HostImpl.hpp index a0a1892549..a206e76a2e 100644 --- a/src/surf/HostImpl.hpp +++ b/src/surf/HostImpl.hpp @@ -3,22 +3,24 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ +#ifndef SURF_HOST_INTERFACE_HPP_ +#define SURF_HOST_INTERFACE_HPP_ + +#include "StorageImpl.hpp" #include "cpu_interface.hpp" #include "network_interface.hpp" +#include "src/simix/ActorImpl.hpp" #include "src/surf/PropertyHolder.hpp" -#include "StorageImpl.hpp" +#include -#ifndef SURF_HOST_INTERFACE_HPP_ -#define SURF_HOST_INTERFACE_HPP_ +namespace simgrid { +namespace surf { /********* * Model * *********/ -namespace simgrid { -namespace surf { - /** @ingroup SURF_host_interface * @brief SURF Host model interface class * @details A model is an object which handle the interactions between its Resources and its Actions @@ -43,13 +45,29 @@ class XBT_PRIVATE HostImpl : public simgrid::surf::PropertyHolder { public: explicit HostImpl(s4u::Host* host); - virtual ~HostImpl() = default; + virtual ~HostImpl(); /** @brief Get the vector of storages (by names) attached to the Host */ virtual std::vector get_attached_storages(); std::map storage_; simgrid::s4u::Host* piface_ = nullptr; + + void turn_on(); + void turn_off(); + std::vector get_all_actors(); + int get_actor_count(); + + typedef boost::intrusive::list< + kernel::actor::ActorImpl, + boost::intrusive::member_hook, + &kernel::actor::ActorImpl::host_process_list_hook>> + ActorList; + + // FIXME: make these private + ActorList process_list; + std::vector auto_restart_processes; + std::vector boot_processes; }; } } diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 02e450387e..1fb6e16281 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -443,7 +443,7 @@ void sg_platf_new_actor(simgrid::kernel::routing::ActorCreationArgs* actor) simgrid::kernel::actor::ProcessArg* arg = new simgrid::kernel::actor::ProcessArg(actor_name, code, nullptr, host, kill_time, properties, auto_restart); - host->extension()->boot_processes.push_back(arg); + host->pimpl_->boot_processes.push_back(arg); if (start_time > SIMIX_get_clock()) {