xbt_enforce(not disk_model_name.empty(), "Set a disk model to use with the 'compound' host model");
xbt_enforce(not network_model_name.empty(), "Set a network model to use with the 'compound' host model");
- const auto* cpu_model = find_model_description(surf_cpu_model_description, cpu_model_name);
- cpu_model->model_init_preparse();
-
- const auto* disk_model = find_model_description(surf_disk_model_description, disk_model_name);
- disk_model->model_init_preparse();
-
- const auto* network_model = find_model_description(surf_network_model_description, network_model_name);
- network_model->model_init_preparse();
+ surf_cpu_model_description.by_name(cpu_model_name).init();
+ surf_disk_model_description.by_name(disk_model_name).init();
+ surf_network_model_description.by_name(network_model_name).init();
}
- XBT_DEBUG("Call host_model_init");
- const auto* host_model = find_model_description(surf_host_model_description, host_model_name);
- host_model->model_init_preparse();
+ surf_host_model_description.by_name(host_model_name).init();
XBT_DEBUG("Call vm_model_init");
- /* ideally we should get back the pointer to CpuModel from model_init_preparse(), but this
- * requires changing the declaration of surf_cpu_model_description.
- * To be reviewed in the future */
+ /* TODO: ideally we should get back the pointer to CpuModel from init(), but this
+ * requires changing the declaration of surf_cpu_model_description. */
surf_vm_model_init_HL13(
simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->get_cpu_pm_model().get());
}
#include <simgrid/s4u/Host.hpp>
#include <xbt/config.hpp>
-#include "src/surf/surf_interface.hpp" // SIMGRID_REGISTER_PLUGIN
+#include "src/simgrid/module.hpp" // SIMGRID_REGISTER_PLUGIN
namespace sg4 = simgrid::s4u;
static simgrid::config::Flag<bool> cfg_tell{"cmonkey/tell", "Request the Chaos Monkey to display all timestamps",
#include <simgrid/s4u/VirtualMachine.hpp>
#include "src/kernel/activity/ExecImpl.hpp"
-#include "src/surf/surf_interface.hpp"
+#include "src/simgrid/module.hpp" // SIMGRID_REGISTER_PLUGIN
// Makes sure that this plugin can be activated from the command line with ``--cfg=plugin:host_load``
SIMGRID_REGISTER_PLUGIN(host_load, "Cpu load", &sg_host_load_plugin_init)
@endrst
*/
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(host_load, kernel, "Logging specific to the HostLoad plugin");
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(host_load, plugin, "Logging specific to the HostLoad plugin");
namespace simgrid::plugin {
#include "src/kernel/activity/CommImpl.hpp"
#include "src/kernel/resource/NetworkModel.hpp"
+#include "src/simgrid/module.hpp" // SIMGRID_REGISTER_PLUGIN
#include <limits>
--- /dev/null
+/* Copyright (c) 2004-2023. 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 <xbt/asserts.h>
+#include <xbt/log.h>
+
+#include "src/simgrid/module.hpp"
+#include "src/surf/surf_interface.hpp"
+
+#include <sstream>
+
+XBT_LOG_NEW_CATEGORY(plugin, "Common category for the logging of all plugins");
+XBT_LOG_EXTERNAL_CATEGORY(xbt_help);
+
+using namespace simgrid;
+
+ModuleGroup& ModuleGroup::add(const char* id, const char* desc, std::function<void()> init)
+{
+ table_.emplace_back(Module(id, desc, init));
+ return *this;
+}
+
+Module const& ModuleGroup::by_name(const std::string& name) const
+{
+ if (auto pos = std::find_if(table_.begin(), table_.end(), [&name](const Module& item) { return item.name_ == name; });
+ pos != table_.end())
+ return *pos;
+
+ xbt_die("Unable to find %s '%s'. Valid values are: %s.", kind_.c_str(), name.c_str(), existing_values().c_str());
+}
+/** Displays the long description of all registered models, and quit */
+void ModuleGroup::help() const
+{
+ XBT_HELP("Long description of the %s accepted by this simulator:", kind_.c_str());
+ for (auto const& item : table_)
+ XBT_HELP(" %s: %s", item.name_, item.description_);
+}
+std::string ModuleGroup::existing_values() const
+{
+ std::stringstream ss;
+ std::string sep;
+ for (auto const& item : table_) {
+ ss << sep + item.name_;
+ sep = ", ";
+ }
+ return ss.str();
+}
+
+/* -------------------------------------------------------------------------------------------------------------- */
+simgrid::ModuleGroup surf_optimization_mode_description("optimization mode");
+simgrid::ModuleGroup surf_cpu_model_description("CPU model");
+simgrid::ModuleGroup surf_network_model_description("network model");
+simgrid::ModuleGroup surf_disk_model_description("disk model");
+simgrid::ModuleGroup surf_host_model_description("host model");
+
+void simgrid_create_models()
+{
+ surf_network_model_description
+ .add("LV08",
+ "Realistic network analytic model (slow-start modeled by multiplying latency by 13.01, bandwidth by .97; "
+ "bottleneck sharing uses a payload of S=20537 for evaluating RTT). ",
+ &surf_network_model_init_LegrandVelho)
+ .add("Constant",
+ "Simplistic network model where all communication take a constant time (one second). This model "
+ "provides the lowest realism, but is (marginally) faster.",
+ &surf_network_model_init_Constant)
+ .add("SMPI",
+ "Realistic network model specifically tailored for HPC settings (accurate modeling of slow start with "
+ "correction factors on three intervals: < 1KiB, < 64 KiB, >= 64 KiB)",
+ &surf_network_model_init_SMPI)
+ .add("IB",
+#if HAVE_SMPI
+ "Realistic network model specifically tailored for HPC settings, with Infiniband contention model",
+#else
+ "(Infiniband model is only enabled when SMPI is)",
+#endif
+ &surf_network_model_init_IB)
+ .add("CM02",
+ "Legacy network analytic model (Very similar to LV08, but without corrective factors. The timings of "
+ "small messages are thus poorly modeled).",
+ &surf_network_model_init_CM02)
+ .add("ns-3",
+#if SIMGRID_HAVE_NS3
+ "Network pseudo-model using the ns-3 tcp model instead of an analytic model",
+#else
+ "(ns-3 pseudo-model is only activated when ns-3 support was compiled it)",
+#endif
+ &surf_network_model_init_NS3);
+
+ surf_cpu_model_description.add("Cas01", "Simplistic CPU model (time=size/speed).", &surf_cpu_model_init_Cas01);
+ surf_disk_model_description.add("S19", "Simplistic disk model.", &surf_disk_model_init_S19);
+
+ surf_host_model_description
+ .add("default",
+ "Default host model. Currently, CPU:Cas01, network:LV08 (with cross traffic enabled), and disk:S19",
+ &surf_host_model_init_current_default)
+ .add("compound", "Host model that is automatically chosen if you change the CPU, network, and disk models",
+ &surf_host_model_init_compound)
+ .add("ptask_L07", "Host model somehow similar to Cas01+CM02+S19 but allowing parallel tasks",
+ &surf_host_model_init_ptask_L07);
+
+ surf_optimization_mode_description
+ .add("Lazy", "Lazy action management (partial invalidation in lmm + heap in action remaining).", nullptr)
+ .add("TI",
+ "Trace integration. Highly optimized mode when using availability traces (only available for the Cas01 CPU "
+ "model for now).",
+ nullptr)
+ .add("Full", "Full update of remaining and variables. Slow but may be useful when debugging.", nullptr);
+}
+
+#if !HAVE_SMPI
+void surf_network_model_init_IB()
+{
+ xbt_die("Please activate SMPI support in cmake to use the IB network model.");
+}
+#endif
+#if !SIMGRID_HAVE_NS3
+void surf_network_model_init_NS3()
+{
+ xbt_die("Please activate ns-3 support in cmake and install the dependencies to use the NS3 network model.");
+}
+#endif
--- /dev/null
+/* Copyright (c) 2004-2023. 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_MODULE_HPP
+#define SIMGRID_MODULE_HPP
+
+#include <xbt/base.h>
+
+#include <functional>
+#include <string>
+#include <vector>
+
+namespace simgrid {
+
+struct Module {
+ const char* name_;
+ const char* description_;
+ std::function<void()> init;
+ Module(const char* id, const char* desc, std::function<void()> init_fun)
+ : name_(id), description_(desc), init(init_fun)
+ {
+ }
+};
+
+class ModuleGroup {
+ std::vector<Module> table_;
+ std::string kind_; // either 'plugin' or 'CPU model' or whatever. Used in error messages only
+public:
+ ModuleGroup(std::string kind) : kind_(kind) {}
+
+ ModuleGroup& add(const char* id, const char* desc, std::function<void()> init);
+ Module const& by_name(const std::string& name) const;
+ void help() const;
+ std::string existing_values() const;
+};
+
+}; // namespace simgrid
+
+#define SIMGRID_REGISTER_PLUGIN(id, desc, init) \
+ static void XBT_ATTRIB_CONSTRUCTOR(800) _XBT_CONCAT3(simgrid_, id, _plugin_register)() \
+ { \
+ simgrid_plugins().add(_XBT_STRINGIFY(id), (desc), (init)); \
+ }
+
+/** @brief The list of all available plugins */
+inline auto& simgrid_plugins() // Function to avoid static initialization order fiasco
+{
+ static simgrid::ModuleGroup plugins("plugin");
+ return plugins;
+}
+
+#endif
\ No newline at end of file
#include "src/kernel/resource/NetworkModel.hpp"
#include "src/mc/mc_config.hpp"
#include "src/mc/mc_replay.hpp"
+#include "src/simgrid/module.hpp"
#include "src/smpi/include/smpi_config.hpp"
#include "src/surf/surf_interface.hpp"
XBT_HELP("Please consider using the recent names");
shall_exit = true;
} else if (parse_args && not strcmp(argv[i], "--help-models")) {
- model_help("host", surf_host_model_description);
+ surf_host_model_description.help();
XBT_HELP("%s", "");
- model_help("CPU", surf_cpu_model_description);
+ surf_cpu_model_description.help();
XBT_HELP("%s", "");
- model_help("network", surf_network_model_description);
+ surf_network_model_description.help();
XBT_HELP("\nLong description of all optimization levels accepted by the models of this simulator:");
- for (auto const& item : surf_optimization_mode_description)
- XBT_HELP(" %s: %s", item.name, item.description);
+ surf_optimization_mode_description.help();
XBT_HELP("Both network and CPU models have 'Lazy' as default optimization level\n");
shall_exit = true;
} else if (parse_args && not strcmp(argv[i], "--help-tracing")) {
return;
if (value == "help") {
- model_help("plugin", surf_plugin_description());
+ simgrid_plugins().help();
exit(0);
}
- const auto* plugin = find_model_description(surf_plugin_description(), value);
- plugin->model_init_preparse();
+ simgrid_plugins().by_name(value).init();
}
/* callback of the host/model variable */
xbt_assert(_sg_cfg_init_status < 2, "Cannot change the model after the initialization");
if (value == "help") {
- model_help("host", surf_host_model_description);
+ surf_host_model_description.help();
exit(0);
}
/* Make sure that the model exists */
- find_model_description(surf_host_model_description, value);
+ surf_host_model_description.by_name(value);
}
/* callback of the cpu/model variable */
xbt_assert(_sg_cfg_init_status < 2, "Cannot change the model after the initialization");
if (value == "help") {
- model_help("CPU", surf_cpu_model_description);
+ surf_cpu_model_description.help();
exit(0);
}
- /* New Module missing */
- find_model_description(surf_cpu_model_description, value);
+ /* Make sure that the model exists */
+ surf_cpu_model_description.by_name(value);
}
/* callback of the cpu/model variable */
xbt_assert(_sg_cfg_init_status < 2, "Cannot change the model after the initialization");
if (value == "help") {
- model_help("optimization", surf_optimization_mode_description);
+ surf_optimization_mode_description.help();
exit(0);
}
- /* New Module missing */
- find_model_description(surf_optimization_mode_description, value);
+ /* Make sure that the model exists */
+ surf_optimization_mode_description.by_name(value);
}
static void _sg_cfg_cb__disk_model(const std::string& value)
xbt_assert(_sg_cfg_init_status < 2, "Cannot change the model after the initialization");
if (value == "help") {
- model_help("disk", surf_disk_model_description);
+ surf_disk_model_description.help();
exit(0);
}
- find_model_description(surf_disk_model_description, value);
+ surf_disk_model_description.by_name(value);
}
/* callback of the network_model variable */
xbt_assert(_sg_cfg_init_status < 2, "Cannot change the model after the initialization");
if (value == "help") {
- model_help("network", surf_network_model_description);
+ surf_network_model_description.help();
exit(0);
}
- /* New Module missing */
- find_model_description(surf_network_model_description, value);
+ surf_network_model_description.by_name(value);
}
static void _sg_cfg_cb_contexts_parallel_mode(std::string_view mode_name)
/* build description line with possible values */
static void declare_model_flag(const std::string& name, const std::string& value,
const std::function<void(std::string const&)>& callback,
- const std::vector<surf_model_description_t>& model_description, const std::string& type,
+ const simgrid::ModuleGroup& model_description, const std::string& type,
const std::string& descr)
{
- std::string description = descr + ". Possible values: ";
- std::string sep = "";
- for (auto const& item : model_description) {
- description += sep + item.name;
- sep = ", ";
- }
+ std::string description = descr + ". Possible values: " + model_description.existing_values();
description += ".\n (use 'help' as a value to see the long description of each " + type + ")";
simgrid::config::declare_flag<std::string>(name, description, value, callback);
}
XBT_WARN("Call to sg_config_init() after initialization ignored");
return;
}
-
+ simgrid_create_models();
/* Plugins configuration */
- declare_model_flag("plugin", "", &_sg_cfg_cb__plugin, surf_plugin_description(), "plugin", "The plugins");
+ declare_model_flag("plugin", "", &_sg_cfg_cb__plugin, simgrid_plugins(), "plugin", "The plugins");
declare_model_flag("cpu/model", "Cas01", &_sg_cfg_cb__cpu_model, surf_cpu_model_description, "model",
"The model to use for the CPU");
*********/
std::vector<std::string> surf_path;
-
-const std::vector<surf_model_description_t> surf_network_model_description = {
- {"LV08",
- "Realistic network analytic model (slow-start modeled by multiplying latency by 13.01, bandwidth by .97; "
- "bottleneck sharing uses a payload of S=20537 for evaluating RTT). ",
- &surf_network_model_init_LegrandVelho},
- {"Constant",
- "Simplistic network model where all communication take a constant time (one second). This model "
- "provides the lowest realism, but is (marginally) faster.",
- &surf_network_model_init_Constant},
- {"SMPI",
- "Realistic network model specifically tailored for HPC settings (accurate modeling of slow start with "
- "correction factors on three intervals: < 1KiB, < 64 KiB, >= 64 KiB)",
- &surf_network_model_init_SMPI},
- {"IB", "Realistic network model specifically tailored for HPC settings, with Infiniband contention model",
- &surf_network_model_init_IB},
- {"CM02",
- "Legacy network analytic model (Very similar to LV08, but without corrective factors. The timings of "
- "small messages are thus poorly modeled).",
- &surf_network_model_init_CM02},
- {"ns-3", "Network pseudo-model using the ns-3 tcp model instead of an analytic model",
- &surf_network_model_init_NS3},
-};
-
-#if !HAVE_SMPI
-void surf_network_model_init_IB()
-{
- xbt_die("Please activate SMPI support in cmake to use the IB network model.");
-}
-#endif
-#if !SIMGRID_HAVE_NS3
-void surf_network_model_init_NS3()
-{
- xbt_die("Please activate ns-3 support in cmake and install the dependencies to use the NS3 network model.");
-}
-#endif
-
-const std::vector<surf_model_description_t> surf_cpu_model_description = {
- {"Cas01", "Simplistic CPU model (time=size/speed).", &surf_cpu_model_init_Cas01},
-};
-
-const std::vector<surf_model_description_t> surf_disk_model_description = {
- {"S19", "Simplistic disk model.", &surf_disk_model_init_S19},
-};
-
-const std::vector<surf_model_description_t> surf_host_model_description = {
- {"default", "Default host model. Currently, CPU:Cas01, network:LV08 (with cross traffic enabled), and disk:S19",
- &surf_host_model_init_current_default},
- {"compound", "Host model that is automatically chosen if you change the CPU, network, and disk models",
- &surf_host_model_init_compound},
- {"ptask_L07", "Host model somehow similar to Cas01+CM02+S19 but allowing parallel tasks",
- &surf_host_model_init_ptask_L07},
-};
-
-const std::vector<surf_model_description_t> surf_optimization_mode_description = {
- {"Lazy", "Lazy action management (partial invalidation in lmm + heap in action remaining).", nullptr},
- {"TI",
- "Trace integration. Highly optimized mode when using availability traces (only available for the Cas01 CPU "
- "model for now).",
- nullptr},
- {"Full", "Full update of remaining and variables. Slow but may be useful when debugging.", nullptr},
-};
-
-/** Displays the long description of all registered models, and quit */
-void model_help(const char* category, const std::vector<surf_model_description_t>& table)
-{
- XBT_HELP("Long description of the %s models accepted by this simulator:", category);
- for (auto const& item : table)
- XBT_HELP(" %s: %s", item.name, item.description);
-}
-
-const surf_model_description_t* find_model_description(const std::vector<surf_model_description_t>& table,
- const std::string& name)
-{
- if (auto pos = std::find_if(table.begin(), table.end(),
- [&name](const surf_model_description_t& item) { return item.name == name; });
- pos != table.end())
- return &*pos;
-
- std::string sep;
- std::string name_list;
- for (auto const& item : table) {
- name_list += sep + item.name;
- sep = ", ";
- }
- xbt_die("Model '%s' is invalid! Valid models are: %s.", name.c_str(), name_list.c_str());
-}
#ifndef SURF_MODEL_H_
#define SURF_MODEL_H_
+#include "src/simgrid/module.hpp"
#include <xbt/asserts.h>
#include <xbt/function_types.h>
#include "src/internal_config.h"
+#include "src/kernel/resource/profile/Profile.hpp"
#include <cfloat>
#include <cmath>
* A VM model depends on the physical CPU model to share the resources inside the VM
* It will also creates the CPU model for actions running inside the VM
*
- * Such model is subject to modification with warning in the ChangeLog so monitor it!
*/
XBT_PUBLIC void surf_vm_model_init_HL13(simgrid::kernel::resource::CpuModel* cpu_pm_model);
/* --------------------
* Model Descriptions
* -------------------- */
-/** @brief Resource model description */
-struct surf_model_description_t {
- const char* name;
- const char* description;
- std::function<void()> model_init_preparse;
-};
-
-XBT_PUBLIC const surf_model_description_t* find_model_description(const std::vector<surf_model_description_t>& table,
- const std::string& name);
-XBT_PUBLIC void model_help(const char* category, const std::vector<surf_model_description_t>& table);
-
-#define SIMGRID_REGISTER_PLUGIN(id, desc, init) \
- static void XBT_ATTRIB_CONSTRUCTOR(800) _XBT_CONCAT3(simgrid_, id, _plugin_register)() \
- { \
- surf_plugin_description().emplace_back(surf_model_description_t{_XBT_STRINGIFY(id), (desc), (init)}); \
- }
-/** @brief The list of all available plugins */
-inline auto& surf_plugin_description() // Function to avoid static initialization order fiasco
-{
- static std::vector<surf_model_description_t> plugin_description_table;
- return plugin_description_table;
-}
/** @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 const std::vector<surf_model_description_t> surf_optimization_mode_description;
+XBT_PUBLIC_DATA simgrid::ModuleGroup surf_optimization_mode_description;
/** @brief The list of all cpu models (pick one with --cfg=cpu/model) */
-XBT_PUBLIC_DATA const std::vector<surf_model_description_t> surf_cpu_model_description;
+XBT_PUBLIC_DATA simgrid::ModuleGroup surf_cpu_model_description;
/** @brief The list of all network models (pick one with --cfg=network/model) */
-XBT_PUBLIC_DATA const std::vector<surf_model_description_t> surf_network_model_description;
+XBT_PUBLIC_DATA simgrid::ModuleGroup surf_network_model_description;
/** @brief The list of all disk models (pick one with --cfg=disk/model) */
-XBT_PUBLIC_DATA const std::vector<surf_model_description_t> surf_disk_model_description;
+XBT_PUBLIC_DATA simgrid::ModuleGroup surf_disk_model_description;
/** @brief The list of all host models (pick one with --cfg=host/model:) */
-XBT_PUBLIC_DATA const std::vector<surf_model_description_t> surf_host_model_description;
+XBT_PUBLIC_DATA simgrid::ModuleGroup surf_host_model_description;
+
+void simgrid_create_models();
#endif /* SURF_MODEL_H_ */
set(SIMGRID_SRC
src/simgrid/Exception.cpp
+ src/simgrid/module.cpp
+ src/simgrid/module.hpp
src/simgrid/sg_config.cpp
src/simgrid/sg_version.cpp
src/simgrid/util.hpp