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
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
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)
/* 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");
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",
// =========== 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();
#!/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)
+++ /dev/null
-/* 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;
-}
--- /dev/null
+/* 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;
+}
#!/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)
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);
+++ /dev/null
-/* 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 <limits>
-
-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<simgrid::s4u::Link, LinkCumload> 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}; /*<Whether the link is tracked or not*/
-
- double cumulated_bytes_{}; /*< Cumulated load since last reset*/
- double min_bytes_per_second_{}; /*< Minimum instantaneous load observed since last reset*/
- double max_bytes_per_second_{}; /*< Maximum instantaneous load observed since last reset*/
- double last_reset_{}; /*< Timestamp of the last reset (init timestamp by default)*/
- double last_updated_{}; /*< Timestamp of the last energy update event*/
-};
-
-xbt::Extension<s4u::Link, LinkCumload> 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<double>::max();
- max_bytes_per_second_ = std::numeric_limits<double>::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<LinkCumload>();
- 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<LinkCumload>();
-
- // 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<LinkCumload>();
- 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<LinkCumload>();
- 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<LinkCumload>()->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<LinkCumload>()->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<LinkCumload>()->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<LinkCumload>()->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<LinkCumload>()->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<LinkCumload>()->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<LinkCumload>()->get_max_bytes_per_second();
-}
-
--- /dev/null
+/* 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 <limits>
+
+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<simgrid::s4u::Link, LinkLoad> 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}; /*<Whether the link is tracked or not*/
+
+ double cumulated_bytes_{}; /*< Cumulated load since last reset*/
+ double min_bytes_per_second_{}; /*< Minimum instantaneous load observed since last reset*/
+ double max_bytes_per_second_{}; /*< Maximum instantaneous load observed since last reset*/
+ double last_reset_{}; /*< Timestamp of the last reset (init timestamp by default)*/
+ double last_updated_{}; /*< Timestamp of the last energy update event*/
+};
+
+xbt::Extension<s4u::Link, LinkLoad> 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<double>::max();
+ max_bytes_per_second_ = std::numeric_limits<double>::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<LinkLoad>();
+ 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<LinkLoad>();
+
+ // 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<LinkLoad>();
+ 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<LinkLoad>();
+ 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<LinkLoad>()->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<LinkLoad>()->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<LinkLoad>()->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<LinkLoad>()->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<LinkLoad>()->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<LinkLoad>()->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<LinkLoad>()->get_max_bytes_per_second();
+}
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