From: Bruno Donassolo Date: Fri, 26 Mar 2021 17:27:38 +0000 (+0100) Subject: NetworkModelIntf: Interface to dynamic factors X-Git-Tag: v3.28~262 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/a44d99b7ed60456d5f016fc2ac2e2aa41410a008 NetworkModelIntf: Interface to dynamic factors Adding API to set user callbacks for bandwidth and network factors. Valid for CM02 models and its childrens (SMPI, IB, etc). Not fully working yet. --- diff --git a/MANIFEST.in b/MANIFEST.in index 8416dc1266..c264244675 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1976,6 +1976,7 @@ include include/simgrid/kernel/Timer.hpp include include/simgrid/kernel/future.hpp include include/simgrid/kernel/resource/Action.hpp include include/simgrid/kernel/resource/Model.hpp +include include/simgrid/kernel/resource/NetworkModelIntf.hpp include include/simgrid/kernel/resource/Resource.hpp include include/simgrid/kernel/routing/ClusterZone.hpp include include/simgrid/kernel/routing/DijkstraZone.hpp diff --git a/include/simgrid/forward.h b/include/simgrid/forward.h index 7f110d54a6..32a23f4fa6 100644 --- a/include/simgrid/forward.h +++ b/include/simgrid/forward.h @@ -161,6 +161,7 @@ class Model; class Resource; class CpuModel; class NetworkModel; +class NetworkModelIntf; class LinkImpl; class NetworkAction; class DiskImpl; diff --git a/include/simgrid/kernel/resource/NetworkModelIntf.hpp b/include/simgrid/kernel/resource/NetworkModelIntf.hpp new file mode 100644 index 0000000000..bafd98eea1 --- /dev/null +++ b/include/simgrid/kernel/resource/NetworkModelIntf.hpp @@ -0,0 +1,35 @@ +/* Copyright (c) 2004-2021. 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. */ + +#ifndef SIMGRID_KERNEL_RESOURCE_NETWORKMODELINTF_HPP +#define SIMGRID_KERNEL_RESOURCE_NETWORKMODELINTF_HPP + +#include +#include + +#include +#include + +namespace simgrid { +namespace kernel { +namespace resource { + +/** @ingroup SURF_interface + * @brief Network Model interface class + * @details Defines the methods that a Network model must implement + */ +class XBT_PUBLIC NetworkModelIntf { +public: + using NetworkFactorCb = double(double size, const std::vector& links, + const std::unordered_set& netzones); + virtual void set_lat_factor_cb(const std::function& cb) = 0; + virtual void set_bw_factor_cb(const std::function& cb) = 0; +}; + +} // namespace resource +} // namespace kernel +} // namespace simgrid + +#endif /* SIMGRID_KERNEL_RESOURCE_NETWORKMODELINTF_HPP */ \ No newline at end of file diff --git a/include/simgrid/s4u/NetZone.hpp b/include/simgrid/s4u/NetZone.hpp index b4dc45b34b..9daaf7b750 100644 --- a/include/simgrid/s4u/NetZone.hpp +++ b/include/simgrid/s4u/NetZone.hpp @@ -129,6 +129,8 @@ public: s4u::Link* create_link(const std::string& name, const std::vector& bandwidths); s4u::Link* create_link(const std::string& name, const std::string& bandwidth); + kernel::resource::NetworkModelIntf* get_network_model() const; + /** * @brief Make a router within that NetZone * diff --git a/src/s4u/s4u_Netzone.cpp b/src/s4u/s4u_Netzone.cpp index 17ac925b76..3d768ab5da 100644 --- a/src/s4u/s4u_Netzone.cpp +++ b/src/s4u/s4u_Netzone.cpp @@ -10,6 +10,7 @@ #include "simgrid/s4u/NetZone.hpp" #include "simgrid/simix.hpp" #include "simgrid/zone.h" +#include "src/surf/network_interface.hpp" #include "xbt/parse_units.hpp" namespace simgrid { @@ -204,6 +205,12 @@ kernel::routing::NetPoint* NetZone::get_netpoint() { return pimpl_->get_netpoint(); } + +kernel::resource::NetworkModelIntf* NetZone::get_network_model() const +{ + kernel::resource::NetworkModelIntf* model = pimpl_->get_network_model().get(); + return model; +} } // namespace s4u } // namespace simgrid diff --git a/src/surf/network_cm02.cpp b/src/surf/network_cm02.cpp index 19db714d5d..08bd06afed 100644 --- a/src/surf/network_cm02.cpp +++ b/src/surf/network_cm02.cpp @@ -93,6 +93,40 @@ NetworkCm02Model::NetworkCm02Model(const std::string& name) : NetworkModel(name) loopback_->seal(); } +void NetworkCm02Model::check_lat_factor_cb() +{ + if (not simgrid::config::is_default("network/latency-factor")) { + throw std::invalid_argument( + "NetworkModelIntf: Cannot mix network/latency-factor and callback configuration. Choose only one of them."); + } +} + +void NetworkCm02Model::check_bw_factor_cb() +{ + if (not simgrid::config::is_default("network/bandwidth-factor")) { + throw std::invalid_argument( + "NetworkModelIntf: Cannot mix network/bandwidth-factor and callback configuration. Choose only one of them."); + } +} + +void NetworkCm02Model::set_lat_factor_cb(const std::function& cb) +{ + if (not cb) + throw std::invalid_argument("NetworkModelIntf: Invalid callback"); + check_lat_factor_cb(); + + lat_factor_cb_ = cb; +} + +void NetworkCm02Model::set_bw_factor_cb(const std::function& cb) +{ + if (not cb) + throw std::invalid_argument("NetworkModelIntf: Invalid callback"); + check_bw_factor_cb(); + + bw_factor_cb_ = cb; +} + LinkImpl* NetworkCm02Model::create_link(const std::string& name, const std::vector& bandwidths) { xbt_assert(bandwidths.size() == 1, "Non-WIFI links must use only 1 bandwidth."); diff --git a/src/surf/network_cm02.hpp b/src/surf/network_cm02.hpp index dfa4e8ea69..6765921bfb 100644 --- a/src/surf/network_cm02.hpp +++ b/src/surf/network_cm02.hpp @@ -9,6 +9,7 @@ #include #include "network_interface.hpp" +#include "simgrid/kernel/resource/NetworkModelIntf.hpp" #include "xbt/graph.h" #include "xbt/string.hpp" @@ -36,6 +37,14 @@ public: void update_actions_state_lazy(double now, double delta) override; void update_actions_state_full(double now, double delta) override; Action* communicate(s4u::Host* src, s4u::Host* dst, double size, double rate) override; + void set_lat_factor_cb(const std::function& cb) override; + void set_bw_factor_cb(const std::function& cb) override; + +protected: + virtual void check_lat_factor_cb(); + virtual void check_bw_factor_cb(); + std::function lat_factor_cb_; + std::function bw_factor_cb_; }; /************ @@ -60,7 +69,7 @@ public: using NetworkAction::NetworkAction; void update_remains_lazy(double now) override; }; -} -} +} // namespace resource +} // namespace kernel } // namespace simgrid #endif /* SURF_NETWORK_CM02_HPP_ */ diff --git a/src/surf/network_interface.hpp b/src/surf/network_interface.hpp index a3dcab0dc0..3b0c8933ef 100644 --- a/src/surf/network_interface.hpp +++ b/src/surf/network_interface.hpp @@ -7,6 +7,7 @@ #define SURF_NETWORK_INTERFACE_HPP_ #include "simgrid/kernel/resource/Model.hpp" +#include "simgrid/kernel/resource/NetworkModelIntf.hpp" #include "simgrid/kernel/resource/Resource.hpp" #include "simgrid/s4u/Link.hpp" #include "src/kernel/lmm/maxmin.hpp" @@ -30,7 +31,7 @@ namespace resource { * @brief SURF network model interface class * @details A model is an object which handles the interactions between its Resources and its Actions */ -class NetworkModel : public Model { +class NetworkModel : public Model, public NetworkModelIntf { public: static config::Flag cfg_tcp_gamma; static config::Flag cfg_crosstraffic; @@ -97,6 +98,9 @@ public: double next_occurring_event_full(double now) override; + virtual void set_lat_factor_cb(const std::function& cb) override { THROW_UNIMPLEMENTED; } + virtual void set_bw_factor_cb(const std::function& cb) override { THROW_UNIMPLEMENTED; } + LinkImpl* loopback_ = nullptr; }; @@ -156,8 +160,8 @@ public: * Profile must contain absolute values */ virtual LinkImpl* set_latency_profile(kernel::profile::Profile* profile); - Metric latency_ = {0.0, 0, nullptr}; - Metric bandwidth_ = {1.0, 0, nullptr}; + Metric latency_ = {0.0, 0, nullptr}; + Metric bandwidth_ = {1.0, 0, nullptr}; }; /********** @@ -209,5 +213,3 @@ public: } // namespace simgrid #endif /* SURF_NETWORK_INTERFACE_HPP_ */ - - diff --git a/src/surf/network_smpi.cpp b/src/surf/network_smpi.cpp index 54772d2b74..4c9adb6c7e 100644 --- a/src/surf/network_smpi.cpp +++ b/src/surf/network_smpi.cpp @@ -43,6 +43,22 @@ namespace simgrid { namespace kernel { namespace resource { +void NetworkSmpiModel::check_lat_factor_cb() +{ + if (not simgrid::config::is_default("smpi/lat-factor")) { + throw std::invalid_argument( + "NetworkModelIntf: Cannot mix network/latency-factor and callback configuration. Choose only one of them."); + } +} + +void NetworkSmpiModel::check_bw_factor_cb() +{ + if (not simgrid::config::is_default("smpi/bw-factor")) { + throw std::invalid_argument( + "NetworkModelIntf: Cannot mix network/bandwidth-factor and callback configuration. Choose only one of them."); + } +} + double NetworkSmpiModel::get_bandwidth_factor(double size) { static std::vector smpi_bw_factor; diff --git a/src/surf/network_smpi.hpp b/src/surf/network_smpi.hpp index 3e5b4d7a53..ea69e4af2b 100644 --- a/src/surf/network_smpi.hpp +++ b/src/surf/network_smpi.hpp @@ -22,9 +22,13 @@ public: double get_latency_factor(double size) override; double get_bandwidth_factor(double size) override; double get_bandwidth_constraint(double rate, double bound, double size) override; + +protected: + virtual void check_lat_factor_cb() override; + virtual void check_bw_factor_cb() override; }; } // namespace resource } // namespace kernel -} +} // namespace simgrid #endif diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index d756d5887a..e368f54dee 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -718,6 +718,7 @@ set(headers_to_install include/simgrid/s4u.hpp include/simgrid/kernel/resource/Action.hpp + include/simgrid/kernel/resource/NetworkModelIntf.hpp include/simgrid/kernel/resource/Model.hpp include/simgrid/kernel/resource/Resource.hpp