Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Allow to register plugins from their file, w/o touching the core implem
authorMartin Quinson <martin.quinson@loria.fr>
Sun, 8 Jul 2018 00:27:39 +0000 (02:27 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Sun, 8 Jul 2018 00:40:33 +0000 (02:40 +0200)
src/plugins/host_dvfs.cpp
src/plugins/host_energy.cpp
src/plugins/host_load.cpp
src/plugins/link_energy.cpp
src/surf/surf_interface.cpp
src/surf/surf_interface.hpp
teshsuite/msg/energy-consumption/energy-consumption.c

index b99df53..2024426 100644 (file)
@@ -10,6 +10,8 @@
 
 #include <boost/algorithm/string.hpp>
 
+SIMGRID_REGISTER_PLUGIN(host_dvfs, "Dvfs support", &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.
index 1e7bdb7..6334ddd 100644 (file)
@@ -13,6 +13,8 @@
 #include <boost/algorithm/string/classification.hpp>
 #include <boost/algorithm/string/split.hpp>
 
+SIMGRID_REGISTER_PLUGIN(host_energy, "Cpu energy consumption.", &sg_host_energy_plugin_init)
+
 /** @addtogroup plugin_energy
 
 This is the energy plugin, enabling to account not only for computation time, but also for the dissipated energy in the
index 9c297c7..264ea2d 100644 (file)
@@ -8,6 +8,8 @@
 #include "src/plugins/vm/VirtualMachineImpl.hpp"
 #include <simgrid/s4u.hpp>
 
+SIMGRID_REGISTER_PLUGIN(host_load, "Cpu load", &sg_host_load_plugin_init)
+
 /** @addtogroup plugin_load
 
 This plugin makes it very simple for users to obtain the current load for each host.
index 2f42d3e..2057c0e 100644 (file)
@@ -6,11 +6,14 @@
 #include "simgrid/plugins/energy.h"
 #include "simgrid/s4u/Engine.hpp"
 #include "src/surf/network_interface.hpp"
+#include "src/surf/surf_interface.hpp"
 #include "surf/surf.hpp"
 
 #include <boost/algorithm/string/classification.hpp>
 #include <boost/algorithm/string/split.hpp>
 
+SIMGRID_REGISTER_PLUGIN(link_energy, "Link energy consumption.", &sg_link_energy_plugin_init)
+
 /** @addtogroup SURF_plugin_energy
 
 
index 93a3b17..ce3e759 100644 (file)
@@ -36,17 +36,21 @@ std::vector<simgrid::s4u::Host*> host_that_restart;
 std::set<std::string> watched_hosts;
 extern std::map<std::string, simgrid::surf::StorageType*> storage_types;
 
-#include <simgrid/plugins/dvfs.h>   // FIXME: this plug-in should not be linked to the core
-#include <simgrid/plugins/energy.h> // FIXME: this plug-in should not be linked to the core
-#include <simgrid/plugins/load.h>   // FIXME: this plug-in should not be linked to the core
-
-s_surf_model_description_t surf_plugin_description[] = {
-    {"host_energy", "Cpu energy consumption.", &sg_host_energy_plugin_init},
-    {"link_energy", "Link energy consumption.", &sg_link_energy_plugin_init},
-    {"host_dvfs", "Dvfs support", &sg_host_dvfs_plugin_init},
-    {"host_load", "Cpu load.", &sg_host_load_plugin_init},
-    {nullptr, nullptr, nullptr} /* this array must be nullptr terminated */
-};
+s_surf_model_description_t* surf_plugin_description = nullptr;
+XBT_PUBLIC void simgrid_add_plugin_description(const char* name, const char* description, void_f_void_t init_fun)
+{
+  static int plugin_amount = 0;
+
+  /* no need to check for plugin name conflict: the compiler already ensures that the generated
+   * simgrid_##id##_plugin_register() is unique */
+
+  plugin_amount++;
+  surf_plugin_description = static_cast<s_surf_model_description_t*>(
+      xbt_realloc(surf_plugin_description, sizeof(s_surf_model_description_t) * (plugin_amount + 2)));
+
+  surf_plugin_description[plugin_amount - 1] = {name, description, init_fun};
+  surf_plugin_description[plugin_amount]     = {nullptr, nullptr, nullptr}; // this array must be null terminated
+}
 
 /* Don't forget to update the option description in smx_config when you change this */
 s_surf_model_description_t surf_network_model_description[] = {
index 75c69dd..e1af3a4 100644 (file)
@@ -221,8 +221,16 @@ typedef struct surf_model_description s_surf_model_description_t;
 XBT_PUBLIC int find_model_description(s_surf_model_description_t* table, std::string name);
 XBT_PUBLIC void model_help(const char* category, s_surf_model_description_t* table);
 
+#define SIMGRID_REGISTER_PLUGIN(id, desc, init)                       \
+  void simgrid_##id##_plugin_register();                              \
+  void XBT_ATTRIB_CONSTRUCTOR(800) simgrid_##id##_plugin_register() { \
+    simgrid_add_plugin_description(#id, desc, init);                  \
+  }
+
+XBT_PUBLIC void simgrid_add_plugin_description(const char* name, const char* description, void_f_void_t init_fun);
+
 /** @brief The list of all available plugins */
-XBT_PUBLIC_DATA s_surf_model_description_t surf_plugin_description[];
+XBT_PUBLIC_DATA s_surf_model_description_t* surf_plugin_description;
 /** @brief The list of all available optimization modes (both for cpu and networks).
  *  These optimization modes can be set using --cfg=cpu/optim:... and --cfg=network/optim:... */
 XBT_PUBLIC_DATA s_surf_model_description_t surf_optimization_mode_description[];
index 64e0744..0698a42 100644 (file)
@@ -68,8 +68,8 @@ static int dvfs(int argc, char* argv[])
 
 int main(int argc, char* argv[])
 {
-  sg_host_energy_plugin_init();
   MSG_init(&argc, argv);
+  MSG_config("plugin", "host_energy");
 
   xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);