Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove duplicate entry.
[simgrid.git] / src / plugins / host_dvfs.cpp
index 2024426..b62cc98 100644 (file)
 
 SIMGRID_REGISTER_PLUGIN(host_dvfs, "Dvfs support", &sg_host_dvfs_plugin_init)
 
+static simgrid::config::Flag<double> cfg_sampling_rate("plugin/dvfs/sampling-rate", {"plugin/dvfs/sampling_rate"},
+    "How often should the dvfs plugin check whether the frequency needs to be changed?", 0.1,
+    [](double val){if (val != 0.1) sg_host_dvfs_plugin_init();});
+
+static simgrid::config::Flag<std::string> cfg_governor("plugin/dvfs/governor",
+    "Which Governor should be used that adapts the CPU frequency?", "performance",
+
+    std::map<std::string, std::string>({
+        {"conservative", "TODO: Doc"},
+        {"ondemand", "TODO: Doc"},
+        {"performance", "TODO: Doc"},
+        {"powersave", "TODO: Doc"},
+    }),
+
+    [](std::string val){if (val != "performance") sg_host_dvfs_plugin_init();});
+
 /** @addtogroup SURF_plugin_load
 
   This plugin makes it very simple for users to obtain the current load for each host.
@@ -20,9 +36,6 @@ SIMGRID_REGISTER_PLUGIN(host_dvfs, "Dvfs support", &sg_host_dvfs_plugin_init)
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_plugin_dvfs, surf, "Logging specific to the SURF HostDvfs plugin");
 
-static const char* property_sampling_rate = "plugin/dvfs/sampling_rate";
-static const char* property_governor      = "plugin/dvfs/governor";
-
 namespace simgrid {
 namespace plugin {
 
@@ -44,8 +57,8 @@ public:
 
   void init()
   {
-    const char* local_sampling_rate_config = host_->get_property(property_sampling_rate);
-    double global_sampling_rate_config     = simgrid::config::get_value<double>(property_sampling_rate);
+    const char* local_sampling_rate_config = host_->get_property(cfg_sampling_rate.get_name());
+    double global_sampling_rate_config     = cfg_sampling_rate;
     if (local_sampling_rate_config != nullptr) {
       sampling_rate_ = std::stod(local_sampling_rate_config);
     } else {
@@ -197,7 +210,7 @@ public:
  *
  *  For the sampling rate, use this:
  *
- *    - \<prop id="plugin/dvfs/sampling_rate" value="2" /\>
+ *    - \<prop id="plugin/dvfs/sampling-rate" value="2" /\>
  *
  *  This will run the update() method of the specified governor every 2 seconds
  *  on that host.
@@ -206,22 +219,10 @@ public:
  *  these values globally. Using them within the \<host\> will overwrite this
  *  global configuration
  */
-class HostDvfs {
-public:
-  static simgrid::xbt::Extension<simgrid::s4u::Host, HostDvfs> EXTENSION_ID;
-
-  explicit HostDvfs(simgrid::s4u::Host*){};
-  ~HostDvfs() = default;
-};
-
-simgrid::xbt::Extension<simgrid::s4u::Host, HostDvfs> HostDvfs::EXTENSION_ID;
-
 } // namespace dvfs
 } // namespace plugin
 } // namespace simgrid
 
-using simgrid::plugin::dvfs::HostDvfs;
-
 /* **************************** events  callback *************************** */
 static void on_host_added(simgrid::s4u::Host& host)
 {
@@ -240,12 +241,12 @@ static void on_host_added(simgrid::s4u::Host& host)
     XBT_DEBUG("DVFS process on %s is a daemon: %d", daemon_proc->get_host()->get_cname(), daemon_proc->is_daemon());
 
     std::string dvfs_governor;
-    const char* host_conf = daemon_proc->get_host()->get_property(property_governor);
+    const char* host_conf = daemon_proc->get_host()->get_property("plugin/dvfs/governor");
     if (host_conf != nullptr) {
-      dvfs_governor = std::string(daemon_proc->get_host()->get_property(property_governor));
+      dvfs_governor = std::string(host_conf);
       boost::algorithm::to_lower(dvfs_governor);
     } else {
-      dvfs_governor = simgrid::config::get_value<std::string>(property_governor);
+      dvfs_governor = cfg_governor;
       boost::algorithm::to_lower(dvfs_governor);
     }
 
@@ -290,22 +291,19 @@ static void on_host_added(simgrid::s4u::Host& host)
 
 /* **************************** Public interface *************************** */
 
+
 /** \ingroup SURF_plugin_load
  * \brief Initializes the HostDvfs plugin
  * \details The HostDvfs plugin provides an API to get the current load of each host.
  */
 void sg_host_dvfs_plugin_init()
 {
-  if (HostDvfs::EXTENSION_ID.valid())
+  static bool inited = false;
+  if (inited)
     return;
-
-  HostDvfs::EXTENSION_ID = simgrid::s4u::Host::extension_create<HostDvfs>();
+  inited = true;
 
   sg_host_load_plugin_init();
 
   simgrid::s4u::Host::on_creation.connect(&on_host_added);
-  simgrid::config::declare_flag<double>(
-      property_sampling_rate, "How often should the dvfs plugin check whether the frequency needs to be changed?", 0.1);
-  simgrid::config::declare_flag<std::string>(
-      property_governor, "Which Governor should be used that adapts the CPU frequency?", "performance");
 }