From 4c34ab4cc0212a08411fd0fa4ef9d452db66d3f3 Mon Sep 17 00:00:00 2001 From: SUTER Frederic Date: Thu, 25 Mar 2021 10:48:51 +0100 Subject: [PATCH] more chaining for CPUs too --- include/simgrid/s4u/Host.hpp | 8 ++++---- src/s4u/s4u_Host.cpp | 18 +++++++++++------- src/surf/cpu_interface.cpp | 13 ++++++++----- src/surf/cpu_interface.hpp | 8 ++++---- src/surf/cpu_ti.cpp | 3 ++- src/surf/cpu_ti.hpp | 2 +- src/surf/sg_platf.cpp | 6 ++---- .../storage_client_server.tesh | 2 +- 8 files changed, 33 insertions(+), 27 deletions(-) diff --git a/include/simgrid/s4u/Host.hpp b/include/simgrid/s4u/Host.hpp index 9d658f6d56..f4a11749f7 100644 --- a/include/simgrid/s4u/Host.hpp +++ b/include/simgrid/s4u/Host.hpp @@ -104,8 +104,8 @@ public: const std::unordered_map* get_properties() const; Host* set_properties(const std::unordered_map& properties); - void set_state_profile(kernel::profile::Profile* p); - void set_speed_profile(kernel::profile::Profile* p); + Host* set_state_profile(kernel::profile::Profile* p); + Host* set_speed_profile(kernel::profile::Profile* p); /** @brief Get the peak computing speed in flops/s at the current pstate, NOT taking the external load into account. * @@ -140,10 +140,10 @@ public: */ double get_load() const; - double get_pstate_speed(int pstate_index) const; int get_pstate_count() const; - void set_pstate(int pstate_index); int get_pstate() const; + double get_pstate_speed(int pstate_index) const; + Host* set_pstate(int pstate_index); std::vector get_disks() const; Disk* create_disk(const std::string& name, double read_bandwidth, double write_bandwidth); diff --git a/src/s4u/s4u_Host.cpp b/src/s4u/s4u_Host.cpp index 47feede354..ab974c3b0c 100644 --- a/src/s4u/s4u_Host.cpp +++ b/src/s4u/s4u_Host.cpp @@ -217,9 +217,10 @@ Host* Host::set_properties(const std::unordered_map& p /** Specify a profile turning the host on and off according to an exhaustive list or a stochastic law. * The profile must contain boolean values. */ -void Host::set_state_profile(kernel::profile::Profile* p) +Host* Host::set_state_profile(kernel::profile::Profile* p) { - return kernel::actor::simcall([this, p] { pimpl_cpu->set_state_profile(p); }); + kernel::actor::simcall([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. * @@ -227,9 +228,10 @@ void Host::set_state_profile(kernel::profile::Profile* p) * of the initial value. This means that the actual value is obtained by multiplying the initial value (the peek speed * at this pstate level) by the rate coming from the profile. */ -void Host::set_speed_profile(kernel::profile::Profile* p) +Host* Host::set_speed_profile(kernel::profile::Profile* p) { - return kernel::actor::simcall([this, p] { pimpl_cpu->set_speed_profile(p); }); + kernel::actor::simcall([this, p] { pimpl_cpu->set_speed_profile(p); }); + return this; } /** @brief Get the peak processor speed (in flops/s), at the specified pstate */ @@ -258,15 +260,17 @@ int Host::get_core_count() const Host* Host::set_core_count(int core_count) { - this->pimpl_cpu->set_core_count(core_count); + kernel::actor::simcall([this, core_count] { this->pimpl_cpu->set_core_count(core_count); }); return this; } /** @brief Set the pstate at which the host should run */ -void Host::set_pstate(int pstate_index) +Host* Host::set_pstate(int pstate_index) { kernel::actor::simcall([this, pstate_index] { this->pimpl_cpu->set_pstate(pstate_index); }); + return this; } + /** @brief Retrieve the pstate at which the host is currently running */ int Host::get_pstate() const { @@ -275,7 +279,7 @@ int Host::get_pstate() const std::vector Host::get_disks() const { - return kernel::actor::simcall([this] { return this->pimpl_->get_disks(); }); + return this->pimpl_->get_disks(); } Disk* Host::create_disk(const std::string& name, double read_bandwidth, double write_bandwidth) diff --git a/src/surf/cpu_interface.cpp b/src/surf/cpu_interface.cpp index b07f84f9fa..33d23ebef3 100644 --- a/src/surf/cpu_interface.cpp +++ b/src/surf/cpu_interface.cpp @@ -65,7 +65,7 @@ void Cpu::reset_vcpu(Cpu* that) this->speed_per_pstate_.assign(that->speed_per_pstate_.begin(), that->speed_per_pstate_.end()); } -void Cpu::set_pstate(int pstate_index) +Cpu* Cpu::set_pstate(int pstate_index) { xbt_assert(pstate_index <= static_cast(speed_per_pstate_.size()), "Invalid parameters for CPU %s (pstate %d > length of pstates %d). Please fix your platform file, or your " @@ -77,6 +77,7 @@ void Cpu::set_pstate(int pstate_index) speed_.peak = new_peak_speed; on_speed_change(); + return this; } double Cpu::get_pstate_peak_speed(int pstate_index) const @@ -108,11 +109,13 @@ int Cpu::get_core_count() return core_count_; } -void Cpu::set_speed_profile(kernel::profile::Profile* profile) +Cpu* Cpu::set_speed_profile(kernel::profile::Profile* profile) { - xbt_assert(speed_.event == nullptr, "Cannot set a second speed trace to Host %s", piface_->get_cname()); - - speed_.event = profile->schedule(&profile::future_evt_set, this); + if (profile) { + xbt_assert(speed_.event == nullptr, "Cannot set a second speed trace to Host %s", piface_->get_cname()); + speed_.event = profile->schedule(&profile::future_evt_set, this); + } + return this; } void Cpu::seal() diff --git a/src/surf/cpu_interface.hpp b/src/surf/cpu_interface.hpp index f96a75d46e..5ff2d29cf2 100644 --- a/src/surf/cpu_interface.hpp +++ b/src/surf/cpu_interface.hpp @@ -97,13 +97,13 @@ public: virtual int get_pstate_count() const { return speed_per_pstate_.size(); } - virtual void set_pstate(int pstate_index); virtual int get_pstate() const { return pstate_; } + virtual Cpu* set_pstate(int pstate_index); - /*< @brief Setup the trace file with availability events (peak speed changes due to external load). - * Trace must contain relative values (ratio between 0 and 1) + /*< @brief Setup the profile file with availability events (peak speed changes due to external load). + * Profile must contain relative values (ratio between 0 and 1) */ - virtual void set_speed_profile(profile::Profile* profile); + virtual Cpu* set_speed_profile(profile::Profile* profile); /** * @brief Execute some quantity of computation diff --git a/src/surf/cpu_ti.cpp b/src/surf/cpu_ti.cpp index f030e46dd2..df5dd669f0 100644 --- a/src/surf/cpu_ti.cpp +++ b/src/surf/cpu_ti.cpp @@ -328,7 +328,7 @@ CpuTi::~CpuTi() delete speed_integrated_trace_; } -void CpuTi::set_speed_profile(kernel::profile::Profile* profile) +Cpu* CpuTi::set_speed_profile(kernel::profile::Profile* profile) { delete speed_integrated_trace_; speed_integrated_trace_ = new CpuTiTmgr(profile, speed_.scale); @@ -341,6 +341,7 @@ void CpuTi::set_speed_profile(kernel::profile::Profile* profile) speed_.event = prof->schedule(&profile::future_evt_set, this); } } + return this; } void CpuTi::apply_event(kernel::profile::Event* event, double value) diff --git a/src/surf/cpu_ti.hpp b/src/surf/cpu_ti.hpp index 7ee7930521..6997bfe5b3 100644 --- a/src/surf/cpu_ti.hpp +++ b/src/surf/cpu_ti.hpp @@ -105,7 +105,7 @@ public: CpuTi& operator&(const CpuTi&) = delete; ~CpuTi() override; - void set_speed_profile(profile::Profile* profile) override; + Cpu* set_speed_profile(profile::Profile* profile) override; void apply_event(profile::Event* event, double value) override; void update_actions_finish_time(double now); diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index b1700c3c2b..2c22bfbdae 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -77,10 +77,8 @@ void sg_platf_new_host(const simgrid::kernel::routing::HostCreationArgs* args) host->pimpl_->set_disks(args->disks, host); /* Change from the defaults */ - if (args->state_trace) - host->set_state_profile(args->state_trace); - if (args->speed_trace) - host->set_speed_profile(args->speed_trace); + host->set_state_profile(args->state_trace)->set_speed_profile(args->speed_trace); + if (not args->coord.empty()) new simgrid::kernel::routing::vivaldi::Coords(host->get_netpoint(), args->coord); diff --git a/teshsuite/s4u/storage_client_server/storage_client_server.tesh b/teshsuite/s4u/storage_client_server/storage_client_server.tesh index a103fbba93..f724c4d616 100644 --- a/teshsuite/s4u/storage_client_server/storage_client_server.tesh +++ b/teshsuite/s4u/storage_client_server/storage_client_server.tesh @@ -88,10 +88,10 @@ $ ./storage_client_server ${platfdir}/hosts_with_disks.xml "--log=root.fmt:[%10. > [ 1.207952] (server@alice) /tmp/tata.c size: 6217 bytes > [ 1.207952] (server@alice) /tmp/titi.xml size: 654 bytes > [ 1.207952] (server@alice) /tmp/toto.xml size: 972 bytes +> [ 1.207952] (server@alice) Disk1 is attached to alice > [ 1.207952] (client@bob) *** GET/SET DATA for disk: Disk1 *** > [ 1.207952] (client@bob) Get data: 'No User Data' > [ 1.207952] (client@bob) Set and get data: 'Some data' -> [ 1.207952] (server@alice) Disk1 is attached to alice > [ 1.207952] (server@alice) Disk1 is attached to bob > [ 1.207952] (server@alice) Disk2 is attached to bob > [ 1.207952] (maestro@) Simulated time: 1.20795 -- 2.20.1