host->setPstate(3);
XBT_INFO("Actually start the host");
- host->turnOn();
+ host->turn_on();
XBT_INFO("Wait 150s to simulate the boot time.");
simgrid::s4u::this_actor::sleep_for(150);
host->setPstate(previous_pstate);
XBT_INFO("Actually shutdown the host");
- host->turnOff();
+ host->turn_off();
}
static int monitor()
simgrid::s4u::Host* host1 = simgrid::s4u::Host::by_name("MyHost1");
simgrid::s4u::Host* host2 = simgrid::s4u::Host::by_name("MyHost2");
- XBT_INFO("Energetic profile: %s", host1->getProperty("watt_per_state"));
+ XBT_INFO("Energetic profile: %s", host1->get_property("watt_per_state"));
XBT_INFO("Initial peak speed=%.0E flop/s; Energy dissipated =%.0E J", host1->getSpeed(),
sg_host_get_consumed_energy(host1));
// =========== Turn the other host off ==========
XBT_INFO("Turning MyHost2 off, and sleeping another 10 seconds. MyHost2 dissipated %.0f J so far.",
sg_host_get_consumed_energy(host2));
- host2->turnOff();
+ host2->turn_off();
start = simgrid::s4u::Engine::get_clock();
simgrid::s4u::this_actor::sleep_for(10);
XBT_INFO("Done sleeping (duration: %.2f s). Current peak speed=%.0E flop/s; Energy dissipated=%.0f J",
XBT_INFO(" Host property: '%s' -> '%s'", kv.first.c_str(), kv.second.c_str());
XBT_INFO("== Try to get a host property that does not exist");
- value = thehost->getProperty(noexist);
+ value = thehost->get_property(noexist);
xbt_assert(not value, "The key exists (it's not supposed to)");
XBT_INFO("== Try to get a host property that does exist");
- value = thehost->getProperty(exist);
+ value = thehost->get_property(exist);
xbt_assert(value, "\tProperty %s is undefined (where it should)", exist);
xbt_assert(!strcmp(value, "180"), "\tValue of property %s is defined to %s (where it should be 180)", exist, value);
XBT_INFO(" Property: %s old value: %s", exist, value);
XBT_INFO("== Trying to modify a host property");
- thehost->setProperty(exist, "250");
+ thehost->set_property(exist, "250");
/* Test if we have changed the value */
- value = thehost->getProperty(exist);
+ value = thehost->get_property(exist);
xbt_assert(value, "Property %s is undefined (where it should)", exist);
xbt_assert(!strcmp(value, "250"), "Value of property %s is defined to %s (where it should be 250)", exist, value);
XBT_INFO(" Property: %s old value: %s", exist, value);
/* Restore the value for the next test */
- thehost->setProperty(exist, "180");
+ thehost->set_property(exist, "180");
}
static int alice(int argc, char* argv[])
s4u_Host* host2 = simgrid::s4u::Host::by_name("MyHost2");
XBT_INFO("Turning MyHost2 off, and sleeping another 10 seconds. MyHost2 computed %.0f flops so far and has an average load of %.5f.",
sg_host_get_computed_flops(host2), sg_host_get_avg_load(host2));
- host2->turnOff();
+ host2->turn_off();
start = simgrid::s4u::Engine::get_clock();
simgrid::s4u::this_actor::sleep_for(10);
XBT_INFO("Done sleeping %.2f s; peak speed: %.0E flop/s; number of flops computed so far: %.0E",
/** Retrieves the name of that host as a C string */
const char* get_cname() const { return name_.c_str(); }
- void actorList(std::vector<ActorPtr> * whereto);
+ int get_actor_count();
+ std::vector<ActorPtr> get_all_actors();
/** Turns that host on if it was previously off
*
* All actors on that host which were marked autorestart will be restarted automatically.
* This call does nothing if the host is already on.
*/
- void turnOn();
+ void turn_on();
/** Turns that host off. All actors are forcefully stopped. */
- void turnOff();
+ void turn_off();
/** Returns if that host is currently up and running */
- bool isOn();
+ bool is_on();
/** Returns if that host is currently down and offline */
- bool isOff() { return not isOn(); }
+ bool is_off() { return not is_on(); }
+
+ const char* get_property(const char* key);
+ void set_property(std::string key, std::string value);
+ std::map<std::string, std::string>* getProperties();
double getSpeed();
double get_available_speed();
int getCoreCount();
- std::map<std::string, std::string>* getProperties();
- const char* getProperty(const char* key);
- void setProperty(std::string key, std::string value);
- void getProcesses(std::vector<ActorPtr> * list);
- int get_actor_count();
+
double getPstateSpeed(int pstate_index);
int getPstatesCount() const;
void setPstate(int pstate_index);
return name_;
}
XBT_ATTRIB_DEPRECATED_v323("Please use Host::get_cname()") const char* getCname() const { return name_.c_str(); }
+ XBT_ATTRIB_DEPRECATED_v323("Please use Host::get_all_actors()") void actorList(std::vector<ActorPtr>* whereto);
+ XBT_ATTRIB_DEPRECATED_v323("Please use Host::get_all_actors()") void getProcesses(std::vector<ActorPtr>* list);
+ XBT_ATTRIB_DEPRECATED_v323("Please use Host::turn_on()") void turnOn() { turn_on(); }
+ XBT_ATTRIB_DEPRECATED_v323("Please use Host::turn_off()") void turnOff() { turn_off(); }
+ XBT_ATTRIB_DEPRECATED_v323("Please use Host::is_on()") bool isOn() { return is_on(); }
+ XBT_ATTRIB_DEPRECATED_v323("Please use Host::is_off()") bool isOff() { return is_off(); }
+
+ XBT_ATTRIB_DEPRECATED_v323("Please use Host::get_property()") const char* getProperty(const char* key)
+ {
+ return get_property(key);
+ }
+ XBT_ATTRIB_DEPRECATED_v323("Please use Host::set_property()") void setProperty(std::string key, std::string value)
+ {
+ set_property(key, value);
+ }
private:
simgrid::xbt::string name_{"noname"};
sg_host_t host = sg_host_by_name(name);
lua_ensure(host, "no host '%s' found",name);
- host->setProperty(prop_id, prop_value);
+ host->set_property(prop_id, prop_value);
return 0;
}
void simgrid::kernel::activity::ExecImpl::post()
{
- if (host_ && host_->isOff()) { /* FIXME: handle resource failure for parallel tasks too */
- /* If the host running the synchro failed, notice it. This way, the asking
- * process can be killed if it runs on that host itself */
- state_ = SIMIX_FAILED;
+ if (host_ && host_->is_off()) { /* FIXME: handle resource failure for parallel tasks too */
+ /* If the host running the synchro failed, notice it. This way, the asking
+ * process can be killed if it runs on that host itself */
+ state_ = SIMIX_FAILED;
} else if (surf_action_ && surf_action_->get_state() == simgrid::kernel::resource::Action::State::FAILED) {
/* If the host running the synchro didn't fail, then the synchro was canceled */
state_ = SIMIX_CANCELED;
THROW_IMPOSSIBLE;
break;
}
- if (simcall->issuer->host->isOff()) {
+ if (simcall->issuer->host->is_off()) {
simcall->issuer->context->iwannadie = 1;
}
simcall_process_sleep__set__result(simcall, result);
if (props != nullptr)
for (auto const& kv : *props)
- res->setProperty(kv.first, kv.second);
+ res->set_property(kv.first, kv.second);
simgrid::s4u::Host::on_creation(*res); // notify the signal
static void hostStateChange(s4u::Host& host)
{
- if (host.isOff()) { // just turned off.
+ if (host.is_off()) { // just turned off.
std::vector<s4u::VirtualMachine*> trash;
/* Find all VMs living on that host */
for (s4u::VirtualMachine* const& vm : VirtualMachineImpl::allVms_)
{
simgrid::s4u::Host* src_pm = vm->getPm();
- if (src_pm->isOff())
+ if (src_pm->is_off())
THROWF(vm_error, 0, "Cannot migrate VM '%s' from host '%s', which is offline.", vm->get_cname(),
src_pm->get_cname());
- if (dst_pm->isOff())
+ if (dst_pm->is_off())
THROWF(vm_error, 0, "Cannot migrate VM '%s' to host '%s', which is offline.", vm->get_cname(), dst_pm->get_cname());
if (vm->getState() != SURF_VM_STATE_RUNNING)
THROWF(vm_error, 0, "Cannot migrate VM '%s' that is not running yet.", vm->get_cname());
return smx_proc->host;
}
-void Host::turnOn()
+void Host::turn_on()
{
- if (isOff()) {
+ if (is_off()) {
simgrid::simix::simcall([this] {
this->extension<simgrid::simix::Host>()->turnOn();
this->pimpl_cpu->turn_on();
}
/** @brief Stop the host if it is on */
-void Host::turnOff()
+void Host::turn_off()
{
- if (isOn()) {
+ if (is_on()) {
smx_actor_t self = SIMIX_process_self();
simgrid::simix::simcall([this, self] {
simgrid::simix::Host* host = this->extension<simgrid::simix::Host>();
}
}
-bool Host::isOn()
+bool Host::is_on()
{
return this->pimpl_cpu->is_on();
}
}
/**
- * \brief Return the list of actors attached to an host.
+ * \brief Return a copy of the list of actors that are executing on this host.
*
- * \param whereto a vector in which we should push actors living on that host
+ * Daemons and regular actors are all mixed in this list.
*/
+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;
+}
+
+/** @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();
+}
+
+/** @deprecated */
+void Host::getProcesses(std::vector<ActorPtr>* list)
+{
+ for (auto& actor : this->extension<simgrid::simix::Host>()->process_list) {
+ list->push_back(actor.iface());
+ }
+}
+
+/** @deprecated */
void Host::actorList(std::vector<ActorPtr>* whereto)
{
for (auto& actor : this->extension<simgrid::simix::Host>()->process_list) {
}
/** Retrieve the property value (or nullptr if not set) */
-const char* Host::getProperty(const char* key)
+const char* Host::get_property(const char* key)
{
return this->pimpl_->getProperty(key);
}
-void Host::setProperty(std::string key, std::string value)
+void Host::set_property(std::string key, std::string value)
{
simgrid::simix::simcall([this, key, value] { this->pimpl_->setProperty(key, value); });
}
-/** Get the processes attached to the host */
-void Host::getProcesses(std::vector<ActorPtr>* list)
-{
- for (auto& actor : this->extension<simgrid::simix::Host>()->process_list) {
- list->push_back(actor.iface());
- }
-}
-
-/** @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();
-}
-
/** @brief Get the peak processor speed (in flops/s), at the specified pstate */
double Host::getPstateSpeed(int pstate_index)
{
*/
void sg_host_turn_on(sg_host_t host)
{
- host->turnOn();
+ host->turn_on();
}
/** \ingroup m_host_management
*/
void sg_host_turn_off(sg_host_t host)
{
- host->turnOff();
+ host->turn_off();
}
/** @ingroup m_host_management
*/
int sg_host_is_on(sg_host_t host)
{
- return host->isOn();
+ return host->is_on();
}
/** @ingroup m_host_management
*/
int sg_host_is_off(sg_host_t host)
{
- return host->isOff();
+ return host->is_off();
}
/** @brief Get the properties of an host */
*/
const char* sg_host_get_property_value(sg_host_t host, const char* name)
{
- return host->getProperty(name);
+ return host->get_property(name);
}
void sg_host_set_property_value(sg_host_t host, const char* name, const char* value)
{
- host->setProperty(name, value);
+ host->set_property(name, value);
}
/**
smx_activity_t ActorImpl::sleep(double duration)
{
- if (host->isOff())
+ if (host->is_off())
THROWF(host_error, 0, "Host %s failed, you cannot sleep there.", host->get_cname());
simgrid::kernel::activity::SleepImpl* synchro = new simgrid::kernel::activity::SleepImpl();
XBT_DEBUG("Start process %s on host '%s'", name, host->get_cname());
- if (host->isOff()) {
+ if (host->is_off()) {
XBT_WARN("Cannot launch process '%s' on failed host '%s'", name, host->get_cname());
return nullptr;
}
sg_host_t host = sg_host_by_name(hostname);
XBT_DEBUG("Attach process %s on host '%s'", name, hostname);
- if (host->isOff()) {
+ if (host->is_off()) {
XBT_WARN("Cannot launch process '%s' on failed host '%s'", name, hostname);
return nullptr;
}
/* execute the on_exit functions */
SIMIX_process_on_exit_runall(self);
/* Add the process to the list of process to restart, only if the host is down */
- if (self->auto_restart && self->host->isOff()) {
+ if (self->auto_restart && self->host->is_off()) {
SIMIX_host_add_auto_restart_process(self->host, self->get_cname(), self->code, self->getUserData(),
SIMIX_timer_get_date(self->kill_timer), self->getProperties(),
self->auto_restart);
new simgrid::kernel::actor::ProcessArg(name, code, data, host, kill_time, nullptr, auto_restart);
arg->properties.reset(properties, [](decltype(properties)) {});
- if (host->isOff() && watched_hosts.find(host->get_cname()) == watched_hosts.end()) {
+ if (host->is_off() && watched_hosts.find(host->get_cname()) == watched_hosts.end()) {
watched_hosts.insert(host->get_cname());
XBT_DEBUG("Push host %s to watched_hosts because state == SURF_RESOURCE_OFF", host->get_cname());
}
xbt_die("Internal error in SIMIX_execution_finish: unexpected synchro state %d", (int)exec->state_);
}
/* Fail the process if the host is down */
- if (simcall->issuer->host->isOff())
+ if (simcall->issuer->host->is_off())
simcall->issuer->context->iwannadie = 1;
simcall->issuer->waiting_synchro = nullptr;
xbt_die("Internal error in SIMIX_io_finish: unexpected synchro state %d", static_cast<int>(synchro->state_));
}
- if (simcall->issuer->host->isOff()) {
+ if (simcall->issuer->host->is_off()) {
simcall->issuer->context->iwannadie = 1;
}
/* Check out for errors */
- if (simcall->issuer->host->isOff()) {
+ if (simcall->issuer->host->is_off()) {
simcall->issuer->context->iwannadie = 1;
SMX_EXCEPTION(simcall->issuer, host_error, 0, "Host failed");
} else {
}
}
- if (simcall->issuer->host->isOff()) {
+ if (simcall->issuer->host->is_off()) {
simcall->issuer->context->iwannadie = 1;
}
if (not Host::EXTENSION_ID.valid())
Host::EXTENSION_ID = simgrid::s4u::Host::extension_create<Host>();
- const char* orecv_string = host->getProperty("smpi/or");
+ const char* orecv_string = host->get_property("smpi/or");
if (orecv_string != nullptr) {
orecv_parsed_values = parse_factor(orecv_string);
} else {
orecv_parsed_values = parse_factor(simgrid::config::get_value<std::string>("smpi/or"));
}
- const char* osend_string = host->getProperty("smpi/os");
+ const char* osend_string = host->get_property("smpi/os");
if (osend_string != nullptr) {
osend_parsed_values = parse_factor(osend_string);
} else {
osend_parsed_values = parse_factor(simgrid::config::get_value<std::string>("smpi/os"));
}
- const char* oisend_string = host->getProperty("smpi/ois");
+ const char* oisend_string = host->get_property("smpi/ois");
if (oisend_string != nullptr) {
oisend_parsed_values = parse_factor(oisend_string);
} else {
void init()
{
- const char* local_sampling_rate_config = host_->getProperty(property_sampling_rate);
+ const char* local_sampling_rate_config = host_->get_property(property_sampling_rate);
double global_sampling_rate_config = simgrid::config::get_value<double>(property_sampling_rate);
if (local_sampling_rate_config != nullptr) {
sampling_rate = std::stod(local_sampling_rate_config);
XBT_DEBUG("DVFS process on %s is a daemon: %d", daemon_proc->get_host()->get_cname(), daemon_proc->is_daemon());
std::string dvfs_governor;
- const char* host_conf = daemon_proc->get_host()->getProperty(property_governor);
+ const char* host_conf = daemon_proc->get_host()->get_property(property_governor);
if (host_conf != nullptr) {
- dvfs_governor = std::string(daemon_proc->get_host()->getProperty(property_governor));
+ dvfs_governor = std::string(daemon_proc->get_host()->get_property(property_governor));
boost::algorithm::to_lower(dvfs_governor);
} else {
dvfs_governor = simgrid::config::get_value<std::string>(property_governor);
}
/* Save data for the upcoming time interval: whether it's on/off and the pstate if it's on */
- this->pstate = host->isOn() ? host->getPstate() : pstate_off;
+ this->pstate = host->is_on() ? host->getPstate() : pstate_off;
}
HostEnergy::HostEnergy(simgrid::s4u::Host* ptr) : host(ptr), last_updated(surf_get_clock())
{
initWattsRangeList();
- const char* off_power_str = host->getProperty("watt_off");
+ const char* off_power_str = host->get_property("watt_off");
if (off_power_str != nullptr) {
try {
this->watts_off = std::stod(std::string(off_power_str));
void HostEnergy::initWattsRangeList()
{
- const char* all_power_values_str = host->getProperty("watt_per_state");
+ const char* all_power_values_str = host->get_property("watt_per_state");
if (all_power_values_str == nullptr)
return;
static void master()
{
simgrid::s4u::this_actor::sleep_for(1);
- std::vector<simgrid::s4u::ActorPtr>* actor_list = new std::vector<simgrid::s4u::ActorPtr>();
- simgrid::s4u::this_actor::get_host()->actorList(actor_list);
+ std::vector<simgrid::s4u::ActorPtr> actor_list = simgrid::s4u::this_actor::get_host()->get_all_actors();
- for (auto const& actor : *actor_list) {
+ for (auto const& actor : actor_list) {
XBT_INFO("Actor (pid=%ld, ppid=%ld, name=%s)", actor->get_pid(), actor->get_ppid(), actor->get_cname());
if (simgrid::s4u::this_actor::get_pid() != actor->get_pid())
actor->kill();
simgrid::s4u::this_actor::sleep_for(2);
actor->kill();
- delete actor_list;
XBT_INFO("Goodbye now!");
}
simgrid::s4u::this_actor::sleep_for(1);
XBT_INFO("Turning off the worker host");
- jupiter->turnOff();
+ jupiter->turn_off();
XBT_INFO("Master has finished");
}