1 /* Copyright (c) 2009-2023. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 /* sg_config: configuration infrastructure for the simulation world */
8 #include <simgrid/instr.h>
9 #include <simgrid/version.h>
10 #include <xbt/config.hpp>
11 #include <xbt/file.hpp>
13 #include "src/instr/instr_private.hpp"
14 #include "src/internal_config.h"
15 #include "src/kernel/context/Context.hpp"
16 #include "src/kernel/lmm/maxmin.hpp"
17 #include "src/kernel/resource/NetworkModel.hpp"
18 #include "src/mc/mc_config.hpp"
19 #include "src/mc/mc_replay.hpp"
20 #include "src/simgrid/module.hpp"
21 #include "src/simgrid/sg_config.hpp"
22 #include "src/smpi/include/smpi_config.hpp"
24 #include <string_view>
26 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(config, kernel, "About the configuration of SimGrid");
28 static simgrid::config::Flag<bool> cfg_continue_after_help
29 {"help-nostop", "Do not stop the execution when --help is found", false};
31 /** @brief Allow other libraries to react to the --help flag, too
33 * When finding --help on the command line, SimGrid usually stops right after displaying its help message.
34 * If you are writing a library using SimGrid, you may want to display your own help message before everything stops.
35 * If so, just call this function before having SimGrid parsing the command line, and you will be given the control
36 * even if the user is asking for help.
38 void sg_config_continue_after_help()
40 cfg_continue_after_help = true;
43 /* 0: beginning of time (config cannot be changed yet)
44 * 1: initialized: cfg_set created (config can now be changed)
45 * 2: configured: command line parsed and config part of platform file was
46 * integrated also, platform construction ongoing or done.
47 * (Config cannot be changed anymore!)
49 int _sg_cfg_init_status = 0;
51 /* Parse the command line, looking for options */
52 static void sg_config_cmd_line(int *argc, char **argv)
54 bool shall_exit = false;
55 bool parse_args = true; // Stop parsing the parameters once we found '--'
58 for (int i = j; i < *argc; i++) {
59 if (not strcmp("--", argv[i])) {
61 // Remove that '--' from the arguments
62 } else if (parse_args && not strncmp(argv[i], "--cfg=", strlen("--cfg="))) {
63 char *opt = strchr(argv[i], '=');
66 simgrid::config::set_parse(opt);
67 XBT_DEBUG("Did apply '%s' as config setting", opt);
68 } else if (parse_args && not strcmp(argv[i], "--version")) {
71 } else if (parse_args && (not strcmp(argv[i], "--cfg-help") || not strcmp(argv[i], "--help"))) {
72 XBT_HELP("Description of the configuration accepted by this simulator:");
73 simgrid::config::help();
75 "Each of these configurations can be used by adding\n"
76 " --cfg=<option name>:<option value>\n"
77 "to the command line. Try passing \"help\" as a value\n"
78 "to get the list of values accepted by a given option.\n"
79 "For example, \"--cfg=plugin:help\" gives you the list of\n"
80 "plugins available in your installation of SimGrid.\n"
82 "For more information, please refer to:\n"
83 " --help-aliases for the list of all option aliases.\n"
84 " --help-logs and --help-log-categories for the details of logging output.\n"
85 " --help-models for a list of all models known by this simulator.\n"
86 " --help-tracing for the details of all tracing options known by this simulator.\n"
87 " --version to get SimGrid version information.\n");
88 shall_exit = not cfg_continue_after_help;
89 argv[j++] = argv[i]; // Preserve the --help in argv just in case someone else wants to see it
90 } else if (parse_args && not strcmp(argv[i], "--help-aliases")) {
91 XBT_HELP("Here is a list of all deprecated option names, with their replacement.");
92 simgrid::config::show_aliases();
93 XBT_HELP("Please consider using the recent names");
95 } else if (parse_args && not strcmp(argv[i], "--help-models")) {
96 simgrid_host_models().help();
98 simgrid_cpu_models().help();
100 simgrid_network_models().help();
102 } else if (parse_args && not strcmp(argv[i], "--help-tracing")) {
117 static void _sg_cfg_cb_contexts_parallel_mode(std::string_view mode_name)
119 if (mode_name == "posix") {
120 simgrid::kernel::context::Context::parallel_mode = XBT_PARMAP_POSIX;
121 } else if (mode_name == "futex") {
122 simgrid::kernel::context::Context::parallel_mode = XBT_PARMAP_FUTEX;
123 } else if (mode_name == "busy_wait") {
124 simgrid::kernel::context::Context::parallel_mode = XBT_PARMAP_BUSY_WAIT;
126 xbt_die("Command line setting of the parallel synchronization mode should "
127 "be one of \"posix\", \"futex\" or \"busy_wait\"");
131 /* create the config set, register what should be and parse the command line*/
132 void sg_config_init(int *argc, char **argv)
134 /* Create the configuration support */
135 if (_sg_cfg_init_status != 0) { /* Only create stuff if not already inited */
136 XBT_WARN("Call to sg_config_init() after initialization ignored");
139 _sg_cfg_init_status = 1;
141 /* Plugins and models configuration */
142 simgrid_plugins().create_flag("plugin", "The plugins", "", true);
143 simgrid_cpu_models().create_flag("cpu/model", "The model to use for the CPU", "Cas01", false);
144 simgrid_network_models().create_flag("network/model", "The model to use for the network", "LV08", false);
145 simgrid_host_models().create_flag("host/model", "The model to use for the host", "default", false);
146 simgrid_disk_models().create_flag("disk/model", "The model to use for the disk", "S19", false);
148 simgrid::config::bind_flag(sg_precision_timing, "precision/timing", {"surf/precision"},
149 "Numerical precision used when updating simulation times (in seconds)");
151 simgrid::config::bind_flag(sg_precision_workamount, "precision/work-amount", {"maxmin/precision"},
152 "Numerical precision used when computing resource sharing (in flops/sec or bytes/sec)");
154 simgrid::config::bind_flag(sg_concurrency_limit, "maxmin/concurrency-limit",
155 "Maximum number of concurrent variables in the maxmim system. Also limits the number of "
156 "processes on each host, at higher level. (default: -1 means no such limitation)");
158 /* The parameters of network models */
159 static simgrid::config::Flag<double> _sg_network_loopback_latency{
160 "network/loopback-lat",
161 "For network models with an implicit loopback link (L07, CM02, LV08), "
162 "latency of the loopback link. 0 by default",
165 static simgrid::config::Flag<double> _sg_network_loopback_bandwidth{
166 "network/loopback-bw",
167 "For network models with an implicit loopback link (L07, CM02, LV08), "
168 "bandwidth of the loopback link. 10GBps by default",
172 static simgrid::config::Flag<std::string> cfg_path{
173 "path", "Lookup path for inclusions in platform and deployment XML files", "./", [](std::string const& path) {
174 if (not path.empty())
175 simgrid::xbt::path_push(path);
178 static simgrid::config::Flag<bool> cfg_cpu_maxmin_selective_update{
179 "cpu/maxmin-selective-update",
180 "Update the constraint set propagating recursively to others constraints "
181 "(off by default unless optim is set to lazy)",
183 static simgrid::config::Flag<bool> cfg_network_maxmin_selective_update{"network/maxmin-selective-update",
184 "Update the constraint set propagating "
185 "recursively to others constraints (off by "
186 "default unless optim is set to lazy)",
189 static simgrid::config::Flag<int> cfg_context_stack_size{
190 "contexts/stack-size", "Stack size of contexts in KiB (not with threads)", 8 * 1024,
191 [](int value) { simgrid::kernel::context::Context::stack_size = value * 1024; }};
193 /* guard size for contexts stacks in memory pages */
194 #if (PTH_STACKGROWTH != -1)
195 int default_guard_size = 0;
197 int default_guard_size = 1;
199 static simgrid::config::Flag<int> cfg_context_guard_size{
200 "contexts/guard-size", "Guard size for contexts stacks in memory pages", default_guard_size,
201 [](int value) { simgrid::kernel::context::Context::guard_size = value * xbt_pagesize; }};
203 static simgrid::config::Flag<int> cfg_context_nthreads{
204 "contexts/nthreads", "Number of parallel threads used to execute user contexts", 1,
205 [](int nthreads) { simgrid::kernel::context::Context::set_nthreads(nthreads); }};
207 /* synchronization mode for parallel user contexts */
209 std::string default_synchro_mode = "futex";
210 #else // No futex on mac and posix is unimplemented yet
211 std::string default_synchro_mode = "busy_wait";
213 static simgrid::config::Flag<std::string> cfg_context_synchro{"contexts/synchro",
214 "Synchronization mode to use when running contexts in "
215 "parallel (either futex, posix or busy_wait)",
216 default_synchro_mode,
217 &_sg_cfg_cb_contexts_parallel_mode};
219 // SMPI model can be used without enable_smpi, so keep this out of the ifdef.
220 static simgrid::config::Flag<std::string> cfg_smpi_IB_penalty_factors{
221 "smpi/IB-penalty-factors",
222 "Correction factor to communications using Infiniband model with "
223 "contention (default value based on Stampede cluster profiling)",
227 static simgrid::config::Flag<bool> cfg_execution_cutpath{
228 "exception/cutpath", "Whether to cut all path information from call traces, used e.g. in exceptions.", false};
230 sg_config_cmd_line(argc, argv);
232 xbt_mallocator_initialization_is_done(simgrid::kernel::context::Context::is_parallel());
235 void sg_config_finalize()
237 simgrid::config::finalize();
238 _sg_cfg_init_status = 0;