From 5fd60ae4fdc2aaaff1bed6ac2978e8c7ed2077c4 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sat, 10 Oct 2020 16:14:32 +0200 Subject: [PATCH] Rename the link load plugin for decency (and consistency) --- MANIFEST.in | 10 +- examples/s4u/CMakeLists.txt | 3 +- .../s4u-plugin-host-load.cpp} | 8 +- .../s4u-plugin-host-load.tesh} | 4 +- .../s4u-plugin-link-cumload.cpp | 109 ------ .../plugin-link-load/s4u-plugin-link-load.cpp | 104 ++++++ .../s4u-plugin-link-load.tesh} | 4 +- include/simgrid/plugins/load.h | 8 +- src/plugins/link_cumload.cpp | 314 ---------------- src/plugins/link_load.cpp | 345 ++++++++++++++++++ tools/cmake/DefinePackages.cmake | 2 +- 11 files changed, 469 insertions(+), 442 deletions(-) rename examples/s4u/{plugin-hostload/s4u-plugin-hostload.cpp => plugin-host-load/s4u-plugin-host-load.cpp} (96%) rename examples/s4u/{plugin-hostload/s4u-plugin-hostload.tesh => plugin-host-load/s4u-plugin-host-load.tesh} (90%) delete mode 100644 examples/s4u/plugin-link-cumload/s4u-plugin-link-cumload.cpp create mode 100644 examples/s4u/plugin-link-load/s4u-plugin-link-load.cpp rename examples/s4u/{plugin-link-cumload/s4u-plugin-link-cumload.tesh => plugin-link-load/s4u-plugin-link-load.tesh} (97%) delete mode 100644 src/plugins/link_cumload.cpp create mode 100644 src/plugins/link_load.cpp diff --git a/MANIFEST.in b/MANIFEST.in index 43c0df94f6..0166849ca5 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -492,10 +492,10 @@ include examples/s4u/platform-profile/s4u-platform-profile.tesh include examples/s4u/platform-properties/s4u-platform-properties.cpp include examples/s4u/platform-properties/s4u-platform-properties.tesh include examples/s4u/platform-properties/s4u-platform-properties_d.xml -include examples/s4u/plugin-hostload/s4u-plugin-hostload.cpp -include examples/s4u/plugin-hostload/s4u-plugin-hostload.tesh -include examples/s4u/plugin-link-cumload/s4u-plugin-link-cumload.cpp -include examples/s4u/plugin-link-cumload/s4u-plugin-link-cumload.tesh +include examples/s4u/plugin-host-load/s4u-plugin-host-load.cpp +include examples/s4u/plugin-host-load/s4u-plugin-host-load.tesh +include examples/s4u/plugin-link-load/s4u-plugin-link-load.cpp +include examples/s4u/plugin-link-load/s4u-plugin-link-load.tesh include examples/s4u/replay-comm/s4u-replay-comm-split-p0.txt include examples/s4u/replay-comm/s4u-replay-comm-split-p1.txt include examples/s4u/replay-comm/s4u-replay-comm-split_d.xml @@ -2347,9 +2347,9 @@ include src/plugins/file_system/s4u_FileSystem.cpp include src/plugins/host_dvfs.cpp include src/plugins/host_energy.cpp include src/plugins/host_load.cpp -include src/plugins/link_cumload.cpp include src/plugins/link_energy.cpp include src/plugins/link_energy_wifi.cpp +include src/plugins/link_load.cpp include src/plugins/vm/VirtualMachineImpl.cpp include src/plugins/vm/VirtualMachineImpl.hpp include src/plugins/vm/VmHostExt.cpp diff --git a/examples/s4u/CMakeLists.txt b/examples/s4u/CMakeLists.txt index eedf83c7f2..0d5c32edae 100644 --- a/examples/s4u/CMakeLists.txt +++ b/examples/s4u/CMakeLists.txt @@ -74,8 +74,7 @@ foreach (example actor-create actor-daemon actor-exiting actor-join actor-kill network-wifi io-async io-file-system io-file-remote io-disk-raw io-dependent platform-failures platform-profile platform-properties - plugin-hostload - plugin-link-cumload + plugin-host-load plugin-link-load replay-comm replay-io routing-get-clusters synchro-barrier synchro-condition-variable synchro-mutex synchro-semaphore) diff --git a/examples/s4u/plugin-hostload/s4u-plugin-hostload.cpp b/examples/s4u/plugin-host-load/s4u-plugin-host-load.cpp similarity index 96% rename from examples/s4u/plugin-hostload/s4u-plugin-hostload.cpp rename to examples/s4u/plugin-host-load/s4u-plugin-host-load.cpp index bb3c752ed4..c59e4bd170 100644 --- a/examples/s4u/plugin-hostload/s4u-plugin-hostload.cpp +++ b/examples/s4u/plugin-host-load/s4u-plugin-host-load.cpp @@ -3,8 +3,8 @@ /* 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. */ -#include "simgrid/s4u.hpp" #include "simgrid/plugins/load.h" +#include "simgrid/s4u.hpp" XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example"); @@ -57,7 +57,8 @@ static void execute_load_test() start = simgrid::s4u::Engine::get_clock(); XBT_INFO("========= Requesting a reset of the computation and load counters"); sg_host_load_reset(host); - XBT_INFO("After reset: %.0E flops computed; load is %.5f", sg_host_get_computed_flops(host), sg_host_get_avg_load(host)); + XBT_INFO("After reset: %.0E flops computed; load is %.5f", sg_host_get_computed_flops(host), + sg_host_get_avg_load(host)); XBT_INFO("Sleep for 4 seconds"); simgrid::s4u::this_actor::sleep_for(4); XBT_INFO("Done sleeping %.2f s; peak speed: %.0E flop/s; number of flops computed so far: %.0E", @@ -65,7 +66,8 @@ static void execute_load_test() // =========== Turn the other host off ========== 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.", + 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->turn_off(); start = simgrid::s4u::Engine::get_clock(); diff --git a/examples/s4u/plugin-hostload/s4u-plugin-hostload.tesh b/examples/s4u/plugin-host-load/s4u-plugin-host-load.tesh similarity index 90% rename from examples/s4u/plugin-hostload/s4u-plugin-hostload.tesh rename to examples/s4u/plugin-host-load/s4u-plugin-host-load.tesh index 2e77b81390..276ef37d69 100644 --- a/examples/s4u/plugin-hostload/s4u-plugin-hostload.tesh +++ b/examples/s4u/plugin-host-load/s4u-plugin-host-load.tesh @@ -1,8 +1,8 @@ #!/usr/bin/env tesh -p This tests the HostLoad plugin (this allows the user to get the current load of a host and the computed flops) +p This tests the Host Load plugin (that allows the user to get the current load of a host and the computed flops) -$ ${bindir:=.}/s4u-plugin-hostload ${platfdir}/energy_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" +$ ${bindir:=.}/s4u-plugin-host-load ${platfdir}/energy_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" > [ 0.000000] (1:load_test@MyHost1) Initial peak speed: 1E+08 flop/s; number of flops computed so far: 0E+00 (should be 0) and current average load: 0.00000 (should be 0) > [ 0.000000] (1:load_test@MyHost1) Sleep for 10 seconds > [ 10.000000] (1:load_test@MyHost1) Done sleeping 10.00s; peak speed: 1E+08 flop/s; number of flops computed so far: 0E+00 (nothing should have changed) diff --git a/examples/s4u/plugin-link-cumload/s4u-plugin-link-cumload.cpp b/examples/s4u/plugin-link-cumload/s4u-plugin-link-cumload.cpp deleted file mode 100644 index 658add80ad..0000000000 --- a/examples/s4u/plugin-link-cumload/s4u-plugin-link-cumload.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/* Copyright (c) 2007-2020. 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. */ - -#include "simgrid/s4u.hpp" -#include "simgrid/plugins/load.h" - -XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example"); - -static void sender(const std::string & mailbox, uint64_t msg_size) -{ - auto mbox = simgrid::s4u::Mailbox::by_name(mailbox); - mbox->put((void*)1, msg_size); -} - -static void receiver(const std::string & mailbox) -{ - auto mbox = simgrid::s4u::Mailbox::by_name(mailbox); - mbox->get(); -} - -static void run_transfer(simgrid::s4u::Host* src_host, simgrid::s4u::Host* dst_host, - const std::string & mailbox, uint64_t msg_size) -{ - XBT_INFO("Launching the transfer of %lu bytes", msg_size); - simgrid::s4u::Actor::create("sender", src_host, sender, mailbox, msg_size); - simgrid::s4u::Actor::create("receiver", dst_host, receiver, mailbox); -} - -static void execute_load_test() -{ - auto host0 = simgrid::s4u::Host::by_name("node-0.simgrid.org"); - auto host1 = simgrid::s4u::Host::by_name("node-1.simgrid.org"); - - simgrid::s4u::this_actor::sleep_for(1); - run_transfer(host0, host1, "1", 1000*1000*1000); - - simgrid::s4u::this_actor::sleep_for(10); - run_transfer(host0, host1, "2", 1000*1000*1000); - simgrid::s4u::this_actor::sleep_for(3); - run_transfer(host0, host1, "3", 1000*1000*1000); -} - -static void show_link_load(const std::string & link_name, const simgrid::s4u::Link* link) -{ - XBT_INFO("%s link load (cum, avg, min, max): (%g, %g, %g, %g)", link_name.c_str(), - sg_link_get_cum_load(link), - sg_link_get_avg_load(link), - sg_link_get_min_instantaneous_load(link), - sg_link_get_max_instantaneous_load(link) - ); -} - -static void monitor() -{ - auto link_backbone = simgrid::s4u::Link::by_name("cluster0_backbone"); - auto link_host0 = simgrid::s4u::Link::by_name("cluster0_link_0_UP"); - auto link_host1 = simgrid::s4u::Link::by_name("cluster0_link_1_DOWN"); - - XBT_INFO("Tracking desired links"); - sg_link_cumload_track(link_backbone); - sg_link_cumload_track(link_host0); - sg_link_cumload_track(link_host1); - - show_link_load("Backbone", link_backbone); - while (simgrid::s4u::Engine::get_clock() < 5) - { - simgrid::s4u::this_actor::sleep_for(1); - show_link_load("Backbone", link_backbone); - } - - XBT_INFO("Untracking the backbone link"); - sg_link_cumload_untrack(link_backbone); - - show_link_load("Host0_UP", link_host0); - show_link_load("Host1_UP", link_host1); - - XBT_INFO("Now resetting and probing host links each second."); - - while (simgrid::s4u::Engine::get_clock() < 29) - { - sg_link_cumload_reset(link_host0); - sg_link_cumload_reset(link_host1); - - simgrid::s4u::this_actor::sleep_for(1); - - show_link_load("Host0_UP", link_host0); - show_link_load("Host1_UP", link_host1); - } -} - -int main(int argc, char* argv[]) -{ - simgrid::s4u::Engine e(&argc, argv); - sg_link_cumload_plugin_init(); - - xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s ../platforms/energy_platform.xml\n", argv[0], argv[0]); - e.load_platform(argv[1]); - - simgrid::s4u::Actor::create("load_test", simgrid::s4u::Host::by_name("node-42.simgrid.org"), execute_load_test); - simgrid::s4u::Actor::create("monitor", simgrid::s4u::Host::by_name("node-51.simgrid.org"), monitor); - - e.run(); - - XBT_INFO("Total simulation time: %.2f", simgrid::s4u::Engine::get_clock()); - - return 0; -} diff --git a/examples/s4u/plugin-link-load/s4u-plugin-link-load.cpp b/examples/s4u/plugin-link-load/s4u-plugin-link-load.cpp new file mode 100644 index 0000000000..ee20ed5618 --- /dev/null +++ b/examples/s4u/plugin-link-load/s4u-plugin-link-load.cpp @@ -0,0 +1,104 @@ +/* Copyright (c) 2007-2020. 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. */ + +#include "simgrid/plugins/load.h" +#include "simgrid/s4u.hpp" + +XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example"); + +static void sender(const std::string& mailbox, uint64_t msg_size) +{ + auto mbox = simgrid::s4u::Mailbox::by_name(mailbox); + mbox->put((void*)1, msg_size); +} + +static void receiver(const std::string& mailbox) +{ + auto mbox = simgrid::s4u::Mailbox::by_name(mailbox); + mbox->get(); +} + +static void run_transfer(simgrid::s4u::Host* src_host, simgrid::s4u::Host* dst_host, const std::string& mailbox, + uint64_t msg_size) +{ + XBT_INFO("Launching the transfer of %lu bytes", msg_size); + simgrid::s4u::Actor::create("sender", src_host, sender, mailbox, msg_size); + simgrid::s4u::Actor::create("receiver", dst_host, receiver, mailbox); +} + +static void execute_load_test() +{ + auto host0 = simgrid::s4u::Host::by_name("node-0.simgrid.org"); + auto host1 = simgrid::s4u::Host::by_name("node-1.simgrid.org"); + + simgrid::s4u::this_actor::sleep_for(1); + run_transfer(host0, host1, "1", 1000 * 1000 * 1000); + + simgrid::s4u::this_actor::sleep_for(10); + run_transfer(host0, host1, "2", 1000 * 1000 * 1000); + simgrid::s4u::this_actor::sleep_for(3); + run_transfer(host0, host1, "3", 1000 * 1000 * 1000); +} + +static void show_link_load(const std::string& link_name, const simgrid::s4u::Link* link) +{ + XBT_INFO("%s link load (cum, avg, min, max): (%g, %g, %g, %g)", link_name.c_str(), sg_link_get_cum_load(link), + sg_link_get_avg_load(link), sg_link_get_min_instantaneous_load(link), + sg_link_get_max_instantaneous_load(link)); +} + +static void monitor() +{ + auto link_backbone = simgrid::s4u::Link::by_name("cluster0_backbone"); + auto link_host0 = simgrid::s4u::Link::by_name("cluster0_link_0_UP"); + auto link_host1 = simgrid::s4u::Link::by_name("cluster0_link_1_DOWN"); + + XBT_INFO("Tracking desired links"); + sg_link_load_track(link_backbone); + sg_link_load_track(link_host0); + sg_link_load_track(link_host1); + + show_link_load("Backbone", link_backbone); + while (simgrid::s4u::Engine::get_clock() < 5) { + simgrid::s4u::this_actor::sleep_for(1); + show_link_load("Backbone", link_backbone); + } + + XBT_INFO("Untracking the backbone link"); + sg_link_load_untrack(link_backbone); + + show_link_load("Host0_UP", link_host0); + show_link_load("Host1_UP", link_host1); + + XBT_INFO("Now resetting and probing host links each second."); + + while (simgrid::s4u::Engine::get_clock() < 29) { + sg_link_load_reset(link_host0); + sg_link_load_reset(link_host1); + + simgrid::s4u::this_actor::sleep_for(1); + + show_link_load("Host0_UP", link_host0); + show_link_load("Host1_UP", link_host1); + } +} + +int main(int argc, char* argv[]) +{ + simgrid::s4u::Engine e(&argc, argv); + sg_link_load_plugin_init(); + + xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s ../platforms/energy_platform.xml\n", argv[0], argv[0]); + e.load_platform(argv[1]); + + simgrid::s4u::Actor::create("load_test", simgrid::s4u::Host::by_name("node-42.simgrid.org"), execute_load_test); + simgrid::s4u::Actor::create("monitor", simgrid::s4u::Host::by_name("node-51.simgrid.org"), monitor); + + e.run(); + + XBT_INFO("Total simulation time: %.2f", simgrid::s4u::Engine::get_clock()); + + return 0; +} diff --git a/examples/s4u/plugin-link-cumload/s4u-plugin-link-cumload.tesh b/examples/s4u/plugin-link-load/s4u-plugin-link-load.tesh similarity index 97% rename from examples/s4u/plugin-link-cumload/s4u-plugin-link-cumload.tesh rename to examples/s4u/plugin-link-load/s4u-plugin-link-load.tesh index 43848c7ac1..cc078cd081 100644 --- a/examples/s4u/plugin-link-cumload/s4u-plugin-link-cumload.tesh +++ b/examples/s4u/plugin-link-load/s4u-plugin-link-load.tesh @@ -1,8 +1,8 @@ #!/usr/bin/env tesh -p This tests the LinkCumload plugin (this allows the user to get the cumulated load of a link) +p This tests the LinkLoad plugin (that allows the user to get the load of a link) -$ ${bindir:=.}/s4u-plugin-link-cumload ${platfdir}/cluster_backbone.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" +$ ${bindir:=.}/s4u-plugin-link-load ${platfdir}/cluster_backbone.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" > [ 0.000000] (2:monitor@node-51.simgrid.org) Tracking desired links > [ 0.000000] (2:monitor@node-51.simgrid.org) Backbone link load (cum, avg, min, max): (0, 0, 0, 0) > [ 1.000000] (2:monitor@node-51.simgrid.org) Backbone link load (cum, avg, min, max): (0, 0, 0, 0) diff --git a/include/simgrid/plugins/load.h b/include/simgrid/plugins/load.h index 33f704c076..a9e3f91b13 100644 --- a/include/simgrid/plugins/load.h +++ b/include/simgrid/plugins/load.h @@ -19,10 +19,10 @@ XBT_PUBLIC double sg_host_get_total_idle_time(const_sg_host_t host); XBT_PUBLIC double sg_host_get_computed_flops(const_sg_host_t host); XBT_PUBLIC void sg_host_load_reset(const_sg_host_t host); -XBT_PUBLIC void sg_link_cumload_plugin_init(); -XBT_PUBLIC void sg_link_cumload_track(const_sg_link_t link); -XBT_PUBLIC void sg_link_cumload_untrack(const_sg_link_t link); -XBT_PUBLIC void sg_link_cumload_reset(const_sg_link_t link); +XBT_PUBLIC void sg_link_load_plugin_init(); +XBT_PUBLIC void sg_link_load_track(const_sg_link_t link); +XBT_PUBLIC void sg_link_load_untrack(const_sg_link_t link); +XBT_PUBLIC void sg_link_load_reset(const_sg_link_t link); XBT_PUBLIC double sg_link_get_cum_load(const_sg_link_t link); XBT_PUBLIC double sg_link_get_avg_load(const_sg_link_t link); XBT_PUBLIC double sg_link_get_min_instantaneous_load(const_sg_link_t link); diff --git a/src/plugins/link_cumload.cpp b/src/plugins/link_cumload.cpp deleted file mode 100644 index ae1d46eb43..0000000000 --- a/src/plugins/link_cumload.cpp +++ /dev/null @@ -1,314 +0,0 @@ -/* Copyright (c) 2017-2020. 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. */ - -#include "simgrid/host.h" -#include "simgrid/plugins/load.h" -#include "simgrid/s4u/Link.hpp" -#include "src/surf/network_interface.hpp" -#include "src/surf/surf_interface.hpp" -#include "surf/surf.hpp" - -#include - -SIMGRID_REGISTER_PLUGIN(link_energy, "Link cumulated load.", &sg_link_cumload_plugin_init) - -/** @defgroup plugin_link_cumload Plugin Link Cumulated Load - - This is the link cumulated load plugin. - It enables to monitor how links are used over time by cumulating the amount of bytes that go through the link. - - Usage: - - Call sg_link_cumload_plugin_init() between the SimGrid engine initialization and the platform loading. - - Track the links you want to monitor with sg_link_cumload_track() — you can untrack them later with sg_link_cumload_untrack(). - - Query the cumulated data about your link via these functions: - - sg_link_get_cum_load() to get the total load (in bytes) that went though the link since last reset. - - sg_link_get_avg_load() to get the average load (in bytes) that went though the link since last reset. - - sg_link_get_min_instantaneous_load() to get the peak minimum load (in bytes per second) observed on the link since last reset. - - sg_link_get_max_instantaneous_load() to get the peak maximum load (in bytes per second) observer on the link since last reset. - - Reset the counters on any tracked link via sg_link_cumload_reset(). -*/ - -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(link_cumload, surf, "Logging specific to the SURF LinkCumload plugin"); - -namespace simgrid { -namespace plugin { - -class LinkCumload { -public: - static simgrid::xbt::Extension EXTENSION_ID; - - explicit LinkCumload(simgrid::s4u::Link* ptr); - ~LinkCumload() = default; - - void track(); - void untrack(); - void reset(); - void update(); - double get_average_bytes(); - - /// Getter methods. - bool is_tracked() const; - double get_cumulated_bytes(); - double get_min_bytes_per_second(); - double get_max_bytes_per_second(); - -private: - s4u::Link* link_{}; /*< The link onto which this data is attached*/ - bool is_tracked_{false}; /* LinkCumload::EXTENSION_ID; - -LinkCumload::LinkCumload(simgrid::s4u::Link* ptr) : link_(ptr), is_tracked_(false) -{ - XBT_DEBUG("Instantiating a LinkCumload for link '%s'", link_->get_cname()); -} - -void LinkCumload::track() -{ - xbt_assert(!is_tracked_, "Trying to track cumload of link '%s' while it is already tracked, aborting.", link_->get_cname()); - XBT_DEBUG("Tracking load of link '%s'", link_->get_cname()); - - is_tracked_ = true; - reset(); -} - -void LinkCumload::untrack() -{ - xbt_assert(is_tracked_, "Trying to untrack cumload of link '%s' while it is not tracked, aborting.", link_->get_cname()); - XBT_DEBUG("Untracking load of link '%s'", link_->get_cname()); - - is_tracked_ = false; -} - -void LinkCumload::reset() -{ - XBT_DEBUG("Resetting load of link '%s'", link_->get_cname()); - - cumulated_bytes_ = 0.0; - min_bytes_per_second_ = std::numeric_limits::max(); - max_bytes_per_second_ = std::numeric_limits::lowest(); - XBT_DEBUG("min_bytes_per_second_ = %g", min_bytes_per_second_); - XBT_DEBUG("max_bytes_per_second_ = %g", max_bytes_per_second_); - last_reset_ = surf_get_clock(); - last_updated_ = last_updated_; -} - -void LinkCumload::update() -{ - XBT_DEBUG("Updating load of link '%s'", link_->get_cname()); - xbt_assert(is_tracked_, - "Trying to update cumload of link '%s' while it is NOT tracked, aborting." - " Please track your link with sg_link_cumload_track before trying to access any of its load metrics.", - link_->get_cname()); - - double current_instantaneous_bytes_per_second = link_->get_usage(); - double now = surf_get_clock(); - - // Update minimum/maximum observed values if needed - min_bytes_per_second_ = std::min(min_bytes_per_second_, current_instantaneous_bytes_per_second); - max_bytes_per_second_ = std::max(max_bytes_per_second_, current_instantaneous_bytes_per_second); - - // Update cumulated load - double duration_since_last_update = now - last_updated_; - double bytes_since_last_update = duration_since_last_update * current_instantaneous_bytes_per_second; - XBT_DEBUG("Cumulated %g bytes since last update (duration of %g seconds)", bytes_since_last_update, duration_since_last_update); - xbt_assert(bytes_since_last_update >= 0, "LinkCumload plugin inconsistency: negative amount of bytes is accumulated."); - - cumulated_bytes_ += bytes_since_last_update; - last_updated_ = now; -} - -bool LinkCumload::is_tracked() const { return is_tracked_; } -double LinkCumload::get_cumulated_bytes() { update(); return cumulated_bytes_; } -double LinkCumload::get_min_bytes_per_second() { update(); return min_bytes_per_second_; } -double LinkCumload::get_max_bytes_per_second() { update(); return max_bytes_per_second_; } - -double LinkCumload::get_average_bytes() { - update(); - - double now = surf_get_clock(); - if (now > last_reset_) - return cumulated_bytes_ / (now - last_reset_); - else - return 0; -} - -} // namespace plugin -} // namespace simgrid - -using simgrid::plugin::LinkCumload; - -/* **************************** events callback *************************** */ -static void on_communicate(const simgrid::kernel::resource::NetworkAction& action) -{ - XBT_DEBUG("on_communicate is called"); - for (simgrid::kernel::resource::LinkImpl* link : action.get_links()) { - if (link == nullptr || link->get_sharing_policy() == simgrid::s4u::Link::SharingPolicy::WIFI) - continue; - - auto link_cumload = link->get_iface()->extension(); - if (link_cumload->is_tracked()) { - link_cumload->update(); - } - } -} - -/* **************************** Public interface *************************** */ - -/** - * @ingroup plugin_link_cumload - * @brief Initialize the link cumulated load plugin. - * @pre The energy plugin should NOT be initialized. - */ -void sg_link_cumload_plugin_init() -{ - xbt_assert(sg_host_count() == 0, "Please call sg_link_cumload_plugin_init() BEFORE initializing the platform."); - xbt_assert(!LinkCumload::EXTENSION_ID.valid(), "Double call to sg_link_cumload_plugin_init. Aborting."); - LinkCumload::EXTENSION_ID = simgrid::s4u::Link::extension_create(); - - // Attach new LinkCumload links created in the future. - simgrid::s4u::Link::on_creation.connect([](simgrid::s4u::Link& link) { - if (link.get_sharing_policy() != simgrid::s4u::Link::SharingPolicy::WIFI) { - XBT_DEBUG("Wired link '%s' created. Attaching a LinkCumload to it.", link.get_cname()); - link.extension_set(new LinkCumload(&link)); - } else { - XBT_DEBUG("Wireless link '%s' created. NOT attaching any LinkCumload to it.", link.get_cname()); - } - }); - - // Call this plugin on some of the links' events. - simgrid::s4u::Link::on_communicate.connect(&on_communicate); - simgrid::s4u::Link::on_state_change.connect([](simgrid::s4u::Link const& link) { - if (link.get_sharing_policy() != simgrid::s4u::Link::SharingPolicy::WIFI) { - auto link_cumload = link.extension(); - if (link_cumload->is_tracked()) - link_cumload->update(); - } - }); - simgrid::s4u::Link::on_communication_state_change.connect( - [](simgrid::kernel::resource::NetworkAction const& action, - simgrid::kernel::resource::Action::State /* previous */) { - for (simgrid::kernel::resource::LinkImpl* link : action.get_links()) { - if (link != nullptr && link->get_sharing_policy() != simgrid::s4u::Link::SharingPolicy::WIFI) { - auto link_cumload = link->get_iface()->extension(); - if (link_cumload->is_tracked()) - link_cumload->update(); - } - } - } - ); -} - -/** - * @ingroup plugin_link_cumload - * @brief Start the tracking of a link. - * @details This is required so the link cumulated load can be obtained later on. - * @pre The energy plugin should be initialized (cf. sg_link_cumload_plugin_init()). - * @pre The link should be in "untracked" state. In other words, do not call this function twice on the same link without a sg_link_cumload_untrack() call between them. - * - * @param link The link to track. - */ -void sg_link_cumload_track(const_sg_link_t link) -{ - xbt_assert(LinkCumload::EXTENSION_ID.valid(), "Please call sg_link_cumload_plugin_init before sg_link_cumload_track. Aborting."); - link->extension()->track(); -} - -/** - * @ingroup plugin_link_cumload - * @brief Stop the tracking of a link. - * @details Once the tracking is stopped, the cumulated load of the link can no longer be obtained until sg_link_cumload_track() is called again on this link. - * @pre The energy plugin should be initialized (cf. sg_link_cumload_plugin_init()). - * @pre The link should be in "tracked" state. In other words, do not call this function twice on the same link without a sg_link_cumload_track() call between them. - * - * @param link The link to untrack. - */ -void sg_link_cumload_untrack(const_sg_link_t link) -{ - xbt_assert(LinkCumload::EXTENSION_ID.valid(), "Please call sg_link_cumload_plugin_init before sg_link_cumload_untrack. Aborting."); - link->extension()->untrack(); -} - -/** - * @ingroup plugin_link_cumload - * @brief Resets the cumulated load counters of a link. - * @pre The energy plugin should be initialized (cf. sg_link_cumload_plugin_init()). - * @pre The link should be in "tracked" state (cf. sg_link_cumload_track()). - * - * @param link The link whose counters should be reset. - */ -void sg_link_cumload_reset(const_sg_link_t link) -{ - xbt_assert(LinkCumload::EXTENSION_ID.valid(), "Please call sg_link_cumload_plugin_init before sg_link_cumload_reset. Aborting."); - link->extension()->reset(); -} - -/** - * @ingroup plugin_link_cumload - * @brief Get the cumulated load of a link (since the last call to sg_link_cumload_reset()). - * @pre The energy plugin should be initialized (cf. sg_link_cumload_plugin_init()). - * @pre The link should be in "tracked" state (cf. sg_link_cumload_track()). - - * @param link The link whose cumulated load is requested. - * @return The load (in bytes) that passed through the given link since the last call to sg_link_cumload_reset. - */ -double sg_link_get_cum_load(const_sg_link_t link) -{ - xbt_assert(LinkCumload::EXTENSION_ID.valid(), "Please call sg_link_cumload_plugin_init before sg_link_get_cum_load. Aborting."); - return link->extension()->get_cumulated_bytes(); -} - -/** - * @ingroup plugin_link_cumload - * @brief Get the average load of a link (since the last call to sg_link_cumload_reset()). - * @pre The energy plugin should be initialized (cf. sg_link_cumload_plugin_init()). - * @pre The link should be in "tracked" state (cf. sg_link_cumload_track()). - - * @param link The link whose average load is requested. - * @return The average load (in bytes) that passed through the given link since the last call to sg_link_cumload_reset. - */ -double sg_link_get_avg_load(const_sg_link_t link) -{ - xbt_assert(LinkCumload::EXTENSION_ID.valid(), "Please call sg_link_cumload_plugin_init before sg_link_get_avg_load. Aborting."); - return link->extension()->get_average_bytes(); -} - -/** - * @ingroup plugin_link_cumload - * @brief Get the minimum instantaneous load of a link (since the last call to sg_link_cumload_reset()). - * @pre The energy plugin should be initialized (cf. sg_link_cumload_plugin_init()). - * @pre The link should be in "tracked" state (cf. sg_link_cumload_track()). - - * @param link The link whose average load is requested. - * @return The minimum load instantaneous load (in bytes per second) that passed through the given link since the last call to sg_link_cumload_reset. - */ -double sg_link_get_min_instantaneous_load(const_sg_link_t link) -{ - xbt_assert(LinkCumload::EXTENSION_ID.valid(), "Please call sg_link_cumload_plugin_init before sg_link_get_min_load. Aborting."); - return link->extension()->get_min_bytes_per_second(); -} - -/** - * @ingroup plugin_link_cumload - * @brief Get the maximum instantaneous load of a link (since the last call to sg_link_cumload_reset()). - * @pre The energy plugin should be initialized (cf. sg_link_cumload_plugin_init()). - * @pre The link should be in "tracked" state (cf. sg_link_cumload_track()). - - * @param link The link whose average load is requested. - * @return The maximum load instantaneous load (in bytes per second) that passed through the given link since the last call to sg_link_cumload_reset. - */ -double sg_link_get_max_instantaneous_load(const_sg_link_t link) -{ - xbt_assert(LinkCumload::EXTENSION_ID.valid(), "Please call sg_link_cumload_plugin_init before sg_link_get_max_load. Aborting."); - return link->extension()->get_max_bytes_per_second(); -} - diff --git a/src/plugins/link_load.cpp b/src/plugins/link_load.cpp new file mode 100644 index 0000000000..1b72c1da33 --- /dev/null +++ b/src/plugins/link_load.cpp @@ -0,0 +1,345 @@ +/* Copyright (c) 2017-2020. 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. */ + +#include "simgrid/host.h" +#include "simgrid/plugins/load.h" +#include "simgrid/s4u/Link.hpp" +#include "src/surf/network_interface.hpp" +#include "src/surf/surf_interface.hpp" +#include "surf/surf.hpp" + +#include + +SIMGRID_REGISTER_PLUGIN(link_energy, "Link cumulated load.", &sg_link_load_plugin_init) + +/** @defgroup plugin_link_load Plugin Link Cumulated Load + + This is the link cumulated load plugin. + It enables to monitor how links are used over time by cumulating the amount of bytes that go through the link. + + Usage: + - Call sg_link_load_plugin_init() between the SimGrid engine initialization and the platform loading. + - Track the links you want to monitor with sg_link_load_track() — you can untrack them later with + sg_link_load_untrack(). + - Query the cumulated data about your link via these functions: + - sg_link_get_cum_load() to get the total load (in bytes) that went though the link since last reset. + - sg_link_get_avg_load() to get the average load (in bytes) that went though the link since last reset. + - sg_link_get_min_instantaneous_load() to get the peak minimum load (in bytes per second) observed on the link since + last reset. + - sg_link_get_max_instantaneous_load() to get the peak maximum load (in bytes per second) observer on the link since + last reset. + - Reset the counters on any tracked link via sg_link_load_reset(). +*/ + +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(link_load, surf, "Logging specific to the SURF LinkLoad plugin"); + +namespace simgrid { +namespace plugin { + +class LinkLoad { +public: + static simgrid::xbt::Extension EXTENSION_ID; + + explicit LinkLoad(simgrid::s4u::Link* ptr); + ~LinkLoad() = default; + + void track(); + void untrack(); + void reset(); + void update(); + double get_average_bytes(); + + /// Getter methods. + bool is_tracked() const; + double get_cumulated_bytes(); + double get_min_bytes_per_second(); + double get_max_bytes_per_second(); + +private: + s4u::Link* link_{}; /*< The link onto which this data is attached*/ + bool is_tracked_{false}; /* LinkLoad::EXTENSION_ID; + +LinkLoad::LinkLoad(simgrid::s4u::Link* ptr) : link_(ptr), is_tracked_(false) +{ + XBT_DEBUG("Instantiating a LinkLoad for link '%s'", link_->get_cname()); +} + +void LinkLoad::track() +{ + xbt_assert(!is_tracked_, "Trying to track load of link '%s' while it is already tracked, aborting.", + link_->get_cname()); + XBT_DEBUG("Tracking load of link '%s'", link_->get_cname()); + + is_tracked_ = true; + reset(); +} + +void LinkLoad::untrack() +{ + xbt_assert(is_tracked_, "Trying to untrack load of link '%s' while it is not tracked, aborting.", link_->get_cname()); + XBT_DEBUG("Untracking load of link '%s'", link_->get_cname()); + + is_tracked_ = false; +} + +void LinkLoad::reset() +{ + XBT_DEBUG("Resetting load of link '%s'", link_->get_cname()); + + cumulated_bytes_ = 0.0; + min_bytes_per_second_ = std::numeric_limits::max(); + max_bytes_per_second_ = std::numeric_limits::lowest(); + XBT_DEBUG("min_bytes_per_second_ = %g", min_bytes_per_second_); + XBT_DEBUG("max_bytes_per_second_ = %g", max_bytes_per_second_); + last_reset_ = surf_get_clock(); + last_updated_ = last_updated_; +} + +void LinkLoad::update() +{ + XBT_DEBUG("Updating load of link '%s'", link_->get_cname()); + xbt_assert(is_tracked_, + "Trying to update load of link '%s' while it is NOT tracked, aborting." + " Please track your link with sg_link_load_track before trying to access any of its load metrics.", + link_->get_cname()); + + double current_instantaneous_bytes_per_second = link_->get_usage(); + double now = surf_get_clock(); + + // Update minimum/maximum observed values if needed + min_bytes_per_second_ = std::min(min_bytes_per_second_, current_instantaneous_bytes_per_second); + max_bytes_per_second_ = std::max(max_bytes_per_second_, current_instantaneous_bytes_per_second); + + // Update cumulated load + double duration_since_last_update = now - last_updated_; + double bytes_since_last_update = duration_since_last_update * current_instantaneous_bytes_per_second; + XBT_DEBUG("Cumulated %g bytes since last update (duration of %g seconds)", bytes_since_last_update, + duration_since_last_update); + xbt_assert(bytes_since_last_update >= 0, "LinkLoad plugin inconsistency: negative amount of bytes is accumulated."); + + cumulated_bytes_ += bytes_since_last_update; + last_updated_ = now; +} + +bool LinkLoad::is_tracked() const +{ + return is_tracked_; +} +double LinkLoad::get_cumulated_bytes() +{ + update(); + return cumulated_bytes_; +} +double LinkLoad::get_min_bytes_per_second() +{ + update(); + return min_bytes_per_second_; +} +double LinkLoad::get_max_bytes_per_second() +{ + update(); + return max_bytes_per_second_; +} + +double LinkLoad::get_average_bytes() +{ + update(); + + double now = surf_get_clock(); + if (now > last_reset_) + return cumulated_bytes_ / (now - last_reset_); + else + return 0; +} + +} // namespace plugin +} // namespace simgrid + +using simgrid::plugin::LinkLoad; + +/* **************************** events callback *************************** */ +static void on_communicate(const simgrid::kernel::resource::NetworkAction& action) +{ + XBT_DEBUG("on_communicate is called"); + for (simgrid::kernel::resource::LinkImpl* link : action.get_links()) { + if (link == nullptr || link->get_sharing_policy() == simgrid::s4u::Link::SharingPolicy::WIFI) + continue; + + auto link_load = link->get_iface()->extension(); + if (link_load->is_tracked()) { + link_load->update(); + } + } +} + +/* **************************** Public interface *************************** */ + +/** + * @ingroup plugin_link_load + * @brief Initialize the link cumulated load plugin. + * @pre The energy plugin should NOT be initialized. + */ +void sg_link_load_plugin_init() +{ + xbt_assert(sg_host_count() == 0, "Please call sg_link_load_plugin_init() BEFORE initializing the platform."); + xbt_assert(!LinkLoad::EXTENSION_ID.valid(), "Double call to sg_link_load_plugin_init. Aborting."); + LinkLoad::EXTENSION_ID = simgrid::s4u::Link::extension_create(); + + // Attach new LinkLoad links created in the future. + simgrid::s4u::Link::on_creation.connect([](simgrid::s4u::Link& link) { + if (link.get_sharing_policy() != simgrid::s4u::Link::SharingPolicy::WIFI) { + XBT_DEBUG("Wired link '%s' created. Attaching a LinkLoad to it.", link.get_cname()); + link.extension_set(new LinkLoad(&link)); + } else { + XBT_DEBUG("Wireless link '%s' created. NOT attaching any LinkLoad to it.", link.get_cname()); + } + }); + + // Call this plugin on some of the links' events. + simgrid::s4u::Link::on_communicate.connect(&on_communicate); + simgrid::s4u::Link::on_state_change.connect([](simgrid::s4u::Link const& link) { + if (link.get_sharing_policy() != simgrid::s4u::Link::SharingPolicy::WIFI) { + auto link_load = link.extension(); + if (link_load->is_tracked()) + link_load->update(); + } + }); + simgrid::s4u::Link::on_communication_state_change.connect( + [](simgrid::kernel::resource::NetworkAction const& action, + simgrid::kernel::resource::Action::State /* previous */) { + for (simgrid::kernel::resource::LinkImpl* link : action.get_links()) { + if (link != nullptr && link->get_sharing_policy() != simgrid::s4u::Link::SharingPolicy::WIFI) { + auto link_load = link->get_iface()->extension(); + if (link_load->is_tracked()) + link_load->update(); + } + } + }); +} + +/** + * @ingroup plugin_link_load + * @brief Start the tracking of a link. + * @details This is required so the link cumulated load can be obtained later on. + * @pre The energy plugin should be initialized (cf. sg_link_load_plugin_init()). + * @pre The link should be in "untracked" state. In other words, do not call this function twice on the same link + * without a sg_link_load_untrack() call between them. + * + * @param link The link to track. + */ +void sg_link_load_track(const_sg_link_t link) +{ + xbt_assert(LinkLoad::EXTENSION_ID.valid(), + "Please call sg_link_load_plugin_init before sg_link_load_track. Aborting."); + link->extension()->track(); +} + +/** + * @ingroup plugin_link_load + * @brief Stop the tracking of a link. + * @details Once the tracking is stopped, the cumulated load of the link can no longer be obtained until + * sg_link_load_track() is called again on this link. + * @pre The energy plugin should be initialized (cf. sg_link_load_plugin_init()). + * @pre The link should be in "tracked" state. In other words, do not call this function twice on the same link without + * a sg_link_load_track() call between them. + * + * @param link The link to untrack. + */ +void sg_link_load_untrack(const_sg_link_t link) +{ + xbt_assert(LinkLoad::EXTENSION_ID.valid(), + "Please call sg_link_load_plugin_init before sg_link_load_untrack. Aborting."); + link->extension()->untrack(); +} + +/** + * @ingroup plugin_link_load + * @brief Resets the cumulated load counters of a link. + * @pre The energy plugin should be initialized (cf. sg_link_load_plugin_init()). + * @pre The link should be in "tracked" state (cf. sg_link_load_track()). + * + * @param link The link whose counters should be reset. + */ +void sg_link_load_reset(const_sg_link_t link) +{ + xbt_assert(LinkLoad::EXTENSION_ID.valid(), + "Please call sg_link_load_plugin_init before sg_link_load_reset. Aborting."); + link->extension()->reset(); +} + +/** + * @ingroup plugin_link_load + * @brief Get the cumulated load of a link (since the last call to sg_link_load_reset()). + * @pre The energy plugin should be initialized (cf. sg_link_load_plugin_init()). + * @pre The link should be in "tracked" state (cf. sg_link_load_track()). + + * @param link The link whose cumulated load is requested. + * @return The load (in bytes) that passed through the given link since the last call to sg_link_load_reset. + */ +double sg_link_get_cum_load(const_sg_link_t link) +{ + xbt_assert(LinkLoad::EXTENSION_ID.valid(), + "Please call sg_link_load_plugin_init before sg_link_get_cum_load. Aborting."); + return link->extension()->get_cumulated_bytes(); +} + +/** + * @ingroup plugin_link_load + * @brief Get the average load of a link (since the last call to sg_link_load_reset()). + * @pre The energy plugin should be initialized (cf. sg_link_load_plugin_init()). + * @pre The link should be in "tracked" state (cf. sg_link_load_track()). + + * @param link The link whose average load is requested. + * @return The average load (in bytes) that passed through the given link since the last call to sg_link_load_reset. + */ +double sg_link_get_avg_load(const_sg_link_t link) +{ + xbt_assert(LinkLoad::EXTENSION_ID.valid(), + "Please call sg_link_load_plugin_init before sg_link_get_avg_load. Aborting."); + return link->extension()->get_average_bytes(); +} + +/** + * @ingroup plugin_link_load + * @brief Get the minimum instantaneous load of a link (since the last call to sg_link_load_reset()). + * @pre The energy plugin should be initialized (cf. sg_link_load_plugin_init()). + * @pre The link should be in "tracked" state (cf. sg_link_load_track()). + + * @param link The link whose average load is requested. + * @return The minimum load instantaneous load (in bytes per second) that passed through the given link since the last + call to sg_link_load_reset. + */ +double sg_link_get_min_instantaneous_load(const_sg_link_t link) +{ + xbt_assert(LinkLoad::EXTENSION_ID.valid(), + "Please call sg_link_load_plugin_init before sg_link_get_min_load. Aborting."); + return link->extension()->get_min_bytes_per_second(); +} + +/** + * @ingroup plugin_link_load + * @brief Get the maximum instantaneous load of a link (since the last call to sg_link_load_reset()). + * @pre The energy plugin should be initialized (cf. sg_link_load_plugin_init()). + * @pre The link should be in "tracked" state (cf. sg_link_load_track()). + + * @param link The link whose average load is requested. + * @return The maximum load instantaneous load (in bytes per second) that passed through the given link since the last + call to sg_link_load_reset. + */ +double sg_link_get_max_instantaneous_load(const_sg_link_t link) +{ + xbt_assert(LinkLoad::EXTENSION_ID.valid(), + "Please call sg_link_load_plugin_init before sg_link_get_max_load. Aborting."); + return link->extension()->get_max_bytes_per_second(); +} diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index 13d83f3fdc..c07a6b5881 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -376,7 +376,7 @@ set(PLUGINS_SRC src/plugins/link_energy.cpp src/plugins/link_energy_wifi.cpp src/plugins/host_load.cpp - src/plugins/link_cumload.cpp + src/plugins/link_load.cpp src/plugins/file_system/s4u_FileSystem.cpp src/plugins/vm/VirtualMachineImpl.hpp src/plugins/vm/s4u_VirtualMachine.cpp -- 2.20.1