X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/18080b8f80c81ed30600da55f774a52cbd1101f8..f973433226af2e2e3059b62578bb0f3b215380fb:/src/s4u/s4u_Host.cpp diff --git a/src/s4u/s4u_Host.cpp b/src/s4u/s4u_Host.cpp index 9c0ab22d71..670882c392 100644 --- a/src/s4u/s4u_Host.cpp +++ b/src/s4u/s4u_Host.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2006-2022. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2006-2023. The SimGrid Team. All rights reserved. */ /* 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. */ @@ -13,14 +13,15 @@ #include #include +#include "simgrid/simix.hpp" +#include "src/kernel/resource/HostImpl.hpp" #include "src/kernel/resource/StandardLinkImpl.hpp" #include "src/kernel/resource/VirtualMachineImpl.hpp" -#include "src/surf/HostImpl.hpp" #include XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_host, s4u, "Logging specific to the S4U hosts"); -XBT_LOG_EXTERNAL_CATEGORY(ker_routing); +XBT_LOG_EXTERNAL_CATEGORY(ker_platform); namespace simgrid { @@ -31,8 +32,9 @@ namespace s4u { #ifndef DOXYGEN xbt::signal Host::on_creation; xbt::signal Host::on_destruction; -xbt::signal Host::on_state_change; +xbt::signal Host::on_onoff; xbt::signal Host::on_speed_change; +xbt::signal Host::on_exec_state_change; #endif Host* Host::set_cpu(kernel::resource::CpuImpl* cpu) @@ -84,7 +86,7 @@ Host* Host::current() return self->get_host(); } -xbt::string const& Host::get_name() const +std::string const& Host::get_name() const { return this->pimpl_->get_name(); } @@ -100,7 +102,8 @@ void Host::turn_on() kernel::actor::simcall_answered([this] { this->pimpl_cpu_->turn_on(); this->pimpl_->turn_on(); - on_state_change(*this); + on_onoff(*this); + on_this_onoff(*this); }); } } @@ -114,7 +117,8 @@ void Host::turn_off() this->pimpl_cpu_->turn_off(); this->pimpl_->turn_off(self); - on_state_change(*this); + on_onoff(*this); + on_this_onoff(*this); }); } } @@ -163,16 +167,26 @@ void Host::route_to(const Host* dest, std::vector& links, double* latency for (auto* l : linkImpls) links.push_back(l->get_iface()); } +std::pair, double> Host::route_to(const Host* dest) const +{ + std::vector linkImpls; + std::vector links; + double latency = 0; + this->route_to(dest, linkImpls, &latency); + for (auto* l : linkImpls) + links.push_back(l->get_iface()); + return std::make_pair(links, latency); +} /** @brief Just like Host::routeTo, but filling an array of link implementations */ void Host::route_to(const Host* dest, std::vector& links, double* latency) const { kernel::routing::NetZoneImpl::get_global_route(pimpl_netpoint_, dest->get_netpoint(), links, latency); - if (XBT_LOG_ISENABLED(ker_routing, xbt_log_priority_debug)) { - XBT_CDEBUG(ker_routing, "Route from '%s' to '%s' (latency: %f):", get_cname(), dest->get_cname(), + if (XBT_LOG_ISENABLED(ker_platform, xbt_log_priority_debug)) { + XBT_CDEBUG(ker_platform, "Route from '%s' to '%s' (latency: %f):", get_cname(), dest->get_cname(), (latency == nullptr ? -1 : *latency)); for (auto const* link : links) - XBT_CDEBUG(ker_routing, " Link '%s'", link->get_cname()); + XBT_CDEBUG(ker_platform, " Link '%s'", link->get_cname()); } } @@ -196,13 +210,24 @@ const char* Host::get_property(const std::string& key) const Host* Host::set_property(const std::string& key, const std::string& value) { - kernel::actor::simcall_answered([this, &key, &value] { this->pimpl_->set_property(key, value); }); + kernel::actor::simcall_object_access(pimpl_, [this, &key, &value] { this->pimpl_->set_property(key, value); }); return this; } Host* Host::set_properties(const std::unordered_map& properties) { - kernel::actor::simcall_answered([this, &properties] { this->pimpl_->set_properties(properties); }); + kernel::actor::simcall_object_access(pimpl_, [this, &properties] { this->pimpl_->set_properties(properties); }); + return this; +} + +int Host::get_concurrency_limit() const +{ + return pimpl_cpu_->get_concurrency_limit(); +} + +Host* Host::set_concurrency_limit(int limit) +{ + kernel::actor::simcall_object_access(pimpl_cpu_, [this, limit] { pimpl_cpu_->set_concurrency_limit(limit); }); return this; } @@ -210,7 +235,7 @@ Host* Host::set_properties(const std::unordered_map& p * The profile must contain boolean values. */ Host* Host::set_state_profile(kernel::profile::Profile* p) { - kernel::actor::simcall_answered([this, p] { pimpl_cpu_->set_state_profile(p); }); + kernel::actor::simcall_object_access(pimpl_, [this, p] { pimpl_cpu_->set_state_profile(p); }); return this; } /** Specify a profile modeling the external load according to an exhaustive list or a stochastic law. @@ -221,7 +246,7 @@ Host* Host::set_state_profile(kernel::profile::Profile* p) */ Host* Host::set_speed_profile(kernel::profile::Profile* p) { - kernel::actor::simcall_answered([this, p] { pimpl_cpu_->set_speed_profile(p); }); + kernel::actor::simcall_object_access(pimpl_, [this, p] { pimpl_cpu_->set_speed_profile(p); }); return this; } @@ -246,7 +271,7 @@ double Host::get_available_speed() const Host* Host::set_sharing_policy(SharingPolicy policy, const s4u::NonLinearResourceCb& cb) { - kernel::actor::simcall_answered([this, policy, &cb] { pimpl_cpu_->set_sharing_policy(policy, cb); }); + kernel::actor::simcall_object_access(pimpl_, [this, policy, &cb] { pimpl_cpu_->set_sharing_policy(policy, cb); }); return this; } @@ -262,13 +287,14 @@ int Host::get_core_count() const Host* Host::set_core_count(int core_count) { - kernel::actor::simcall_answered([this, core_count] { this->pimpl_cpu_->set_core_count(core_count); }); + kernel::actor::simcall_object_access(pimpl_, [this, core_count] { this->pimpl_cpu_->set_core_count(core_count); }); return this; } Host* Host::set_pstate_speed(const std::vector& speed_per_state) { - kernel::actor::simcall_answered([this, &speed_per_state] { pimpl_cpu_->set_pstate_speed(speed_per_state); }); + kernel::actor::simcall_object_access(pimpl_, + [this, &speed_per_state] { pimpl_cpu_->set_pstate_speed(speed_per_state); }); return this; } @@ -281,7 +307,7 @@ std::vector Host::convert_pstate_speed_vector(const std::vector& speed_per_state) /** @brief Set the pstate at which the host should run */ Host* Host::set_pstate(unsigned long pstate_index) { - kernel::actor::simcall_answered([this, pstate_index] { this->pimpl_cpu_->set_pstate(pstate_index); }); + kernel::actor::simcall_object_access(pimpl_, [this, pstate_index] { this->pimpl_cpu_->set_pstate(pstate_index); }); return this; } @@ -308,14 +334,14 @@ unsigned long Host::get_pstate() const Host* Host::set_factor_cb(const std::function& cb) { - kernel::actor::simcall_answered([this, &cb] { pimpl_cpu_->set_factor_cb(cb); }); + kernel::actor::simcall_object_access(pimpl_, [this, &cb] { pimpl_cpu_->set_factor_cb(cb); }); return this; } Host* Host::set_coordinates(const std::string& coords) { if (not coords.empty()) - kernel::actor::simcall_answered([this, coords] { this->pimpl_netpoint_->set_coordinates(coords); }); + kernel::actor::simcall_object_access(pimpl_, [this, coords] { this->pimpl_netpoint_->set_coordinates(coords); }); return this; } std::vector Host::get_disks() const @@ -338,15 +364,13 @@ Disk* Host::create_disk(const std::string& name, const std::string& read_bandwid try { d_read = xbt_parse_get_bandwidth("", 0, read_bandwidth, ""); } catch (const simgrid::ParseError&) { - throw std::invalid_argument(std::string("Impossible to create disk: ") + name + - std::string(". Invalid read bandwidth: ") + read_bandwidth); + throw std::invalid_argument("Impossible to create disk: " + name + ". Invalid read bandwidth: " + read_bandwidth); } double d_write; try { d_write = xbt_parse_get_bandwidth("", 0, write_bandwidth, ""); } catch (const simgrid::ParseError&) { - throw std::invalid_argument(std::string("Impossible to create disk: ") + name + - std::string(". Invalid write bandwidth: ") + write_bandwidth); + throw std::invalid_argument("Impossible to create disk: " + name + ". Invalid write bandwidth: " + write_bandwidth); } return create_disk(name, d_read, d_write); } @@ -373,6 +397,12 @@ VirtualMachine* Host::create_vm(const std::string& name, int core_amount, size_t [this, &name, core_amount, ramsize] { return this->pimpl_->create_vm(name, core_amount, ramsize); }); } +VirtualMachine* Host::vm_by_name_or_null(const std::string& name) +{ + simgrid::kernel::resource::VirtualMachineImpl* vm = this->pimpl_->get_vm_by_name_or_null(name); + return vm ? vm->get_iface() : nullptr; +} + ExecPtr Host::exec_init(double flops) const { return this_actor::exec_init(flops); @@ -390,7 +420,7 @@ void Host::execute(double flops) const void Host::execute(double flops, double priority) const { - this_actor::exec_init(flops)->set_priority(1 / priority)->vetoable_start()->wait(); + Exec::init()->set_flops_amount(flops)->set_host(const_cast(this))->set_priority(1 / priority)->wait(); } Host* Host::seal() @@ -442,6 +472,12 @@ sg_host_t sg_host_by_name(const char* name) return simgrid::s4u::Host::by_name_or_null(name); } +/** @brief Retrieve a VM running on a given host from its name, or return NULL if no VM matches*/ +sg_vm_t sg_vm_by_name(sg_host_t host, const char* name) +{ + return host->vm_by_name_or_null(name); +} + // ========= Layering madness ==============* // ========== User data Layer ========== @@ -540,7 +576,7 @@ void sg_host_turn_on(sg_host_t host) * * @brief Stop the host if it is on * - * See also #MSG_host_is_on() to test the current state of the host and @ref plugin_host_energy + * See also #sg_host_is_on() to test the current state of the host and @ref plugin_host_energy * for more info on DVFS. */ void sg_host_turn_off(sg_host_t host) @@ -570,8 +606,8 @@ xbt_dict_t sg_host_get_properties(const_sg_host_t host) if (props == nullptr) return nullptr; - for (auto const& elm : *props) { - xbt_dict_set(as_dict, elm.first.c_str(), xbt_strdup(elm.second.c_str())); + for (auto const& [key, value] : *props) { + xbt_dict_set(as_dict, key.c_str(), xbt_strdup(value.c_str())); } return as_dict; } @@ -645,22 +681,6 @@ void sg_host_sendto(sg_host_t from, sg_host_t to, double byte_amount) simgrid::s4u::Comm::sendto(from, to, byte_amount); } -/** @brief Displays debugging information about a host */ -void sg_host_dump(const_sg_host_t host) // XBT_ATTRIB_DEPRECATED_v335 -{ - XBT_INFO("Displaying host %s", host->get_cname()); - XBT_INFO(" - speed: %.0f", host->get_speed()); - XBT_INFO(" - available speed: %.2f", sg_host_get_available_speed(host)); - const std::unordered_map* props = host->get_properties(); - - if (not props->empty()) { - XBT_INFO(" - properties:"); - for (auto const& elm : *props) { - XBT_INFO(" %s->%s", elm.first.c_str(), elm.second.c_str()); - } - } -} - /** @brief Return the list of actors attached to a host. * * @param host a host