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<simgrid::simix::Host>()->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();
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<simgrid::simix::Host>()->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();
XBT_VERB("Shutting down the VM %s even if it's not running but %s", piface_->get_cname(), stateName);
}
- auto& process_list = piface_->extension<simgrid::simix::Host>()->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) {
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<simgrid::simix::Host>(new simgrid::simix::Host());
}
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<simgrid::simix::Host>(nullptr);
-
/* Don't free these things twice: they are the ones of my physical host */
pimpl_netpoint = nullptr;
}
{
if (is_off()) {
simgrid::simix::simcall([this] {
- this->extension<simgrid::simix::Host>()->turnOn();
+ this->pimpl_->turn_on();
this->pimpl_cpu->turn_on();
on_state_change(*this);
});
if (is_on()) {
smx_actor_t self = SIMIX_process_self();
simgrid::simix::simcall([this, self] {
- simgrid::simix::Host* host = this->extension<simgrid::simix::Host>();
-
- 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);
});
*/
std::vector<ActorPtr> Host::get_all_actors()
{
- std::vector<ActorPtr> res;
- for (auto& actor : this->extension<simgrid::simix::Host>()->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<simgrid::simix::Host>()->process_list.size();
+ return pimpl_->get_actor_count();
}
/** @deprecated */
void Host::getProcesses(std::vector<ActorPtr>* list)
{
- for (auto& actor : this->extension<simgrid::simix::Host>()->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<ActorPtr>* whereto)
{
- for (auto& actor : this->extension<simgrid::simix::Host>()->process_list) {
- whereto->push_back(actor.ciface());
- }
+ auto actors = get_all_actors();
+ for (auto& actor : actors)
+ whereto->push_back(actor);
}
/**
*/
void sg_host_get_actor_list(sg_host_t host, xbt_dynar_t whereto)
{
- for (auto& actor : host->extension<simgrid::simix::Host>()->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()
#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"
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<simgrid::simix::Host>()->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);
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<simgrid::simix::Host>() == nullptr)
- host->extension_set<simgrid::simix::Host>(new simgrid::simix::Host());
-
/* Add the process to its host's process list */
- host->extension<simgrid::simix::Host>()->process_list.push_back(*process);
+ host->pimpl_->process_list.push_back(*process);
XBT_DEBUG("Start context '%s'", process->get_cname());
process->set_property(kv.first, kv.second);
/* Add the process to it's host process list */
- host->extension<simgrid::simix::Host>()->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;
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<simgrid::simix::Host>()->process_list, *actor);
+ simgrid::xbt::intrusive_erase(actor->host_->pimpl_->process_list, *actor);
actor->host_ = dest;
- dest->extension<simgrid::simix::Host>()->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)
#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"
/* 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<simgrid::simix::Host>() == nullptr) // another callback to the same signal may have created it
- host.extension_set<simgrid::simix::Host>(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());
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_host, simix, "SIMIX hosts");
-namespace simgrid {
- namespace simix {
- simgrid::xbt::Extension<simgrid::s4u::Host, Host> Host::EXTENSION_ID;
-
- Host::Host()
- {
- if (not Host::EXTENSION_ID.valid())
- Host::EXTENSION_ID = s4u::Host::extension_create<simix::Host>();
- }
-
- 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()
{
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<simgrid::simix::Host>()->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<simgrid::kernel::actor::ProcessArg*> process_list =
- host->extension<simgrid::simix::Host>()->auto_restart_processes;
+ std::vector<simgrid::kernel::actor::ProcessArg*> 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());
#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<simgrid::s4u::Host, Host> EXTENSION_ID;
-
- explicit Host();
- virtual ~Host();
-
- boost::intrusive::list<kernel::actor::ActorImpl,
- boost::intrusive::member_hook<kernel::actor::ActorImpl, boost::intrusive::list_member_hook<>,
- &kernel::actor::ActorImpl::host_process_list_hook>>
- process_list;
- std::vector<kernel::actor::ProcessArg*> auto_restart_processes;
- std::vector<kernel::actor::ProcessArg*> 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);
#include "smpi_win.hpp"
#include "src/simix/smx_host_private.hpp"
#include "src/simix/smx_private.hpp"
+#include "src/surf/HostImpl.hpp"
#include <algorithm>
#include <climits>
}
//identify neighbours in comm
//get the indices of all processes sharing the same simix host
- auto& process_list = sg_host_self()->extension<simgrid::simix::Host>()->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) {
* 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 <string>
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_host, surf, "Logging specific to the SURF host module");
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<s4u::ActorPtr> HostImpl::get_all_actors()
+{
+ std::vector<s4u::ActorPtr> res;
+ for (auto& actor : process_list)
+ res.push_back(actor.ciface());
+ return res;
+}
+int HostImpl::get_actor_count()
+{
+ return process_list.size();
+}
std::vector<const char*> HostImpl::get_attached_storages()
{
std::vector<const char*> storages;
/* 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 <vector>
-#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
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<const char*> get_attached_storages();
std::map<std::string, simgrid::surf::StorageImpl*> storage_;
simgrid::s4u::Host* piface_ = nullptr;
+
+ void turn_on();
+ void turn_off();
+ std::vector<s4u::ActorPtr> get_all_actors();
+ int get_actor_count();
+
+ typedef boost::intrusive::list<
+ kernel::actor::ActorImpl,
+ boost::intrusive::member_hook<kernel::actor::ActorImpl, boost::intrusive::list_member_hook<>,
+ &kernel::actor::ActorImpl::host_process_list_hook>>
+ ActorList;
+
+ // FIXME: make these private
+ ActorList process_list;
+ std::vector<kernel::actor::ProcessArg*> auto_restart_processes;
+ std::vector<kernel::actor::ProcessArg*> boot_processes;
};
}
}
simgrid::kernel::actor::ProcessArg* arg =
new simgrid::kernel::actor::ProcessArg(actor_name, code, nullptr, host, kill_time, properties, auto_restart);
- host->extension<simgrid::simix::Host>()->boot_processes.push_back(arg);
+ host->pimpl_->boot_processes.push_back(arg);
if (start_time > SIMIX_get_clock()) {