1 /* Copyright (c) 2009, 2010. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 /* surf_config: configuration infrastructure for the simulation world */
9 #include "xbt/config.h"
11 #include "surf/surf_private.h"
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_config, surf,
14 "About the configuration of surf (and the rest of the simulation)");
16 xbt_cfg_t _surf_cfg_set = NULL;
19 /* Parse the command line, looking for options */
20 static void surf_config_cmd_line(int *argc, char **argv)
25 for (i = 1; i < *argc; i++) {
27 if (!strncmp(argv[i], "--cfg=", strlen("--cfg="))) {
28 opt = strchr(argv[i], '=');
31 xbt_cfg_set_parse(_surf_cfg_set, opt);
32 DEBUG1("Did apply '%s' as config setting", opt);
34 } else if (!strncmp(argv[i], "--cfg-help", strlen("--cfg-help") + 1) ||
35 !strncmp(argv[i], "--help", strlen("--help") + 1)) {
37 ("Description of the configuration accepted by this simulator:\n");
38 xbt_cfg_help(_surf_cfg_set);
40 ("\nYou can also use --help-models to see the details of all models known by this simulator.\n");
44 (argv[i], "--help-models", strlen("--help-models") + 1)) {
45 model_help("workstation", surf_workstation_model_description);
46 model_help("CPU", surf_cpu_model_description);
47 model_help("network", surf_network_model_description);
50 if (remove_it) { /*remove this from argv */
51 for (j = i + 1; j < *argc; j++) {
52 argv[j - 1] = argv[j];
57 i--; /* compensate effect of next loop incrementation */
63 int _surf_init_status = 0; /* 0: beginning of time;
64 1: pre-inited (cfg_set created);
65 2: inited (running) */
67 /* callback of the workstation/model variable */
68 static void _surf_cfg_cb__workstation_model(const char *name, int pos)
72 xbt_assert0(_surf_init_status < 2,
73 "Cannot change the model after the initialization");
75 val = xbt_cfg_get_string(_surf_cfg_set, name);
77 if (!strcmp(val, "help")) {
78 model_help("workstation", surf_workstation_model_description);
82 /* Make sure that the model exists */
83 find_model_description(surf_workstation_model_description, val);
86 /* callback of the cpu/model variable */
87 static void _surf_cfg_cb__cpu_model(const char *name, int pos)
91 xbt_assert0(_surf_init_status < 2,
92 "Cannot change the model after the initialization");
94 val = xbt_cfg_get_string(_surf_cfg_set, name);
96 if (!strcmp(val, "help")) {
97 model_help("CPU", surf_cpu_model_description);
101 /* New Module missing */
102 find_model_description(surf_cpu_model_description, val);
105 /* callback of the workstation_model variable */
106 static void _surf_cfg_cb__network_model(const char *name, int pos)
110 xbt_assert0(_surf_init_status < 2,
111 "Cannot change the model after the initialization");
113 val = xbt_cfg_get_string(_surf_cfg_set, name);
115 if (!strcmp(val, "help")) {
116 model_help("network", surf_network_model_description);
120 /* New Module missing */
121 find_model_description(surf_network_model_description, val);
125 /* callbacks of the network models values */
126 static void _surf_cfg_cb__tcp_gamma(const char *name, int pos)
128 sg_tcp_gamma = xbt_cfg_get_double(_surf_cfg_set, name);
131 static void _surf_cfg_cb__latency_factor(const char *name, int pos)
133 sg_latency_factor = xbt_cfg_get_double(_surf_cfg_set, name);
136 static void _surf_cfg_cb__bandwidth_factor(const char *name, int pos)
138 sg_bandwidth_factor = xbt_cfg_get_double(_surf_cfg_set, name);
141 static void _surf_cfg_cb__weight_S(const char *name, int pos)
143 sg_weight_S_parameter = xbt_cfg_get_double(_surf_cfg_set, name);
146 static void _surf_cfg_cb__surf_maxmin_selective_update(const char *name,
149 sg_maxmin_selective_update = xbt_cfg_get_int(_surf_cfg_set, name);
152 /* callback of the inclusion path */
153 static void _surf_cfg_cb__surf_path(const char *name, int pos)
155 char *path = xbt_cfg_get_string_at(_surf_cfg_set, name, pos);
156 xbt_dynar_push(surf_path, &path);
159 /* callback to decide if we want to use the model-checking */
160 #include "xbt_modinter.h"
161 int _surf_do_model_check = 0; /* this variable is used accros the lib */
163 static void _surf_cfg_cb_model_check(const char *name, int pos)
165 _surf_do_model_check = 1;
166 /* Tell modules using mallocators that they shouldn't. MC don't like them */
171 int _surf_parallel_contexts = 0;
173 static void _surf_cfg_cb_parallel_contexts(const char *name, int pos)
175 _surf_parallel_contexts = 1;
178 static void _surf_cfg_cb__surf_network_fullduplex(const char *name,
181 sg_network_fullduplex = xbt_cfg_get_int(_surf_cfg_set, name);
185 static void _surf_cfg_cb__gtnets_jitter(const char *name, int pos)
187 sg_gtnets_jitter = xbt_cfg_get_double(_surf_cfg_set, name);
190 static void _surf_cfg_cb__gtnets_jitter_seed(const char *name, int pos)
192 sg_gtnets_jitter_seed = xbt_cfg_get_int(_surf_cfg_set, name);
196 /* create the config set, register what should be and parse the command line*/
197 void surf_config_init(int *argc, char **argv)
199 char *description = xbt_malloc(1024), *p = description;
201 double double_default_value;
202 int default_value_int;
205 /* Create the configuration support */
206 if (_surf_init_status == 0) { /* Only create stuff if not already inited */
207 _surf_init_status = 1;
210 "The model to use for the CPU. Possible values: ");
212 while (*(++p) != '\0');
213 for (i = 0; surf_cpu_model_description[i].name; i++)
214 p += sprintf(p, "%s%s", (i == 0 ? "" : ", "),
215 surf_cpu_model_description[i].name);
217 ".\n (use 'help' as a value to see the long description of each model)");
218 default_value = xbt_strdup("Cas01");
219 xbt_cfg_register(&_surf_cfg_set,
220 "cpu/model", description, xbt_cfgelm_string,
221 &default_value, 1, 1, &_surf_cfg_cb__cpu_model, NULL);
224 "The model to use for the network. Possible values: ");
226 while (*(++p) != '\0');
227 for (i = 0; surf_network_model_description[i].name; i++)
228 p += sprintf(p, "%s%s", (i == 0 ? "" : ", "),
229 surf_network_model_description[i].name);
231 ".\n (use 'help' as a value to see the long description of each model)");
232 default_value = xbt_strdup("LV08");
233 xbt_cfg_register(&_surf_cfg_set,
234 "network/model", description, xbt_cfgelm_string,
235 &default_value, 1, 1, &_surf_cfg_cb__network_model,
239 "The model to use for the workstation. Possible values: ");
241 while (*(++p) != '\0');
242 for (i = 0; surf_workstation_model_description[i].name; i++)
243 p += sprintf(p, "%s%s", (i == 0 ? "" : ", "),
244 surf_workstation_model_description[i].name);
246 ".\n (use 'help' as a value to see the long description of each model)");
247 default_value = xbt_strdup("CLM03");
248 xbt_cfg_register(&_surf_cfg_set,
249 "workstation/model", description, xbt_cfgelm_string,
250 &default_value, 1, 1,
251 &_surf_cfg_cb__workstation_model, NULL);
253 xbt_free(description);
255 default_value = xbt_strdup("Full");
256 xbt_cfg_register(&_surf_cfg_set, "routing",
257 "Model to use to store the routing information",
258 xbt_cfgelm_string, &default_value, 1, 1, NULL, NULL);
260 xbt_cfg_register(&_surf_cfg_set, "TCP_gamma",
261 "Size of the biggest TCP window (cat /proc/sys/net/ipv4/tcp_[rw]mem for recv/send window; Use the last given value, which is the max window size)",
262 xbt_cfgelm_double, NULL, 1, 1,
263 _surf_cfg_cb__tcp_gamma, NULL);
264 xbt_cfg_set_double(_surf_cfg_set, "TCP_gamma", 20000.0);
266 /* The parameters of network models */
267 double_default_value = 1.0;
268 xbt_cfg_register(&_surf_cfg_set, "network/latency_factor",
269 "Correction factor to apply to the provided latency (default value set by network model)",
270 xbt_cfgelm_double, &double_default_value, 1, 1,
271 _surf_cfg_cb__latency_factor, NULL);
272 double_default_value = 1.0;
273 xbt_cfg_register(&_surf_cfg_set, "network/bandwidth_factor",
274 "Correction factor to apply to the provided bandwidth (default value set by network model)",
275 xbt_cfgelm_double, &double_default_value, 1, 1,
276 _surf_cfg_cb__bandwidth_factor, NULL);
277 double_default_value = 0.0;
278 xbt_cfg_register(&_surf_cfg_set, "network/weight_S",
279 "Correction factor to apply to the weight of competing streams(default value set by network model)",
280 xbt_cfgelm_double, &double_default_value, 1, 1,
281 _surf_cfg_cb__weight_S, NULL);
284 xbt_cfg_register(&_surf_cfg_set, "path",
285 "Lookup path for inclusions in platform and deployment XML files",
286 xbt_cfgelm_string, NULL, 0, 0,
287 _surf_cfg_cb__surf_path, NULL);
289 default_value_int = 0;
290 xbt_cfg_register(&_surf_cfg_set, "maxmin_selective_update",
291 "Update the constraint set propagating recursively to others constraints",
292 xbt_cfgelm_int, &default_value_int, 0, 1,
293 _surf_cfg_cb__surf_maxmin_selective_update, NULL);
296 default_value_int = 0;
297 xbt_cfg_register(&_surf_cfg_set, "model-check",
298 "Activate the model-checking of the \"simulated\" system (EXPERIMENTAL -- msg only for now)",
299 xbt_cfgelm_int, &default_value_int, 0, 1,
300 _surf_cfg_cb_model_check, NULL);
302 FIXME: this function is not setting model-check to it's default value because
303 internally it calls to variable->cb_set that in this case is the function
304 _surf_cfg_cb_model_check which sets it's value to 1 (instead of the defalut value 0)
305 xbt_cfg_set_int(_surf_cfg_set, "model-check", default_value_int); */
307 /* parallel contexts */
308 default_value_int = 0;
309 xbt_cfg_register(&_surf_cfg_set, "parallel-contexts",
310 "Activate the parallel execution of user contexts (EXPERIMENTAL -- pthreads only)",
311 xbt_cfgelm_int, &default_value_int, 0, 1,
312 _surf_cfg_cb_parallel_contexts, NULL);
314 default_value_int = 0;
315 xbt_cfg_register(&_surf_cfg_set, "fullduplex",
316 "Update the constraint set propagating recursively to others constraints",
317 xbt_cfgelm_int, &default_value_int, 0, 1,
318 _surf_cfg_cb__surf_network_fullduplex, NULL);
319 xbt_cfg_set_int(_surf_cfg_set, "fullduplex", default_value_int);
322 xbt_cfg_register(&_surf_cfg_set, "gtnets_jitter",
323 "Double value to oscillate the link latency, uniformly in random interval [-latency*gtnets_jitter,latency*gtnets_jitter)",
324 xbt_cfgelm_double, NULL, 1, 1,
325 _surf_cfg_cb__gtnets_jitter, NULL);
326 xbt_cfg_set_double(_surf_cfg_set, "gtnets_jitter", 0.0);
328 default_value_int = 10;
329 xbt_cfg_register(&_surf_cfg_set, "gtnets_jitter_seed",
330 "Use a positive seed to reproduce jitted results, value must be in [1,1e8], default is 10",
331 xbt_cfgelm_int, &default_value_int, 0, 1,
332 _surf_cfg_cb__gtnets_jitter_seed, NULL);
336 /* retrieves the current directory of the current process */
337 const char *initial_path = __surf_get_initial_path();
338 xbt_assert0((initial_path),
339 "__surf_get_initial_path() failed! Can't resolves current Windows directory");
341 surf_path = xbt_dynar_new(sizeof(char *), NULL);
342 xbt_cfg_set_string(_surf_cfg_set, "path", initial_path);
346 surf_config_cmd_line(argc, argv);
348 WARN0("Call to surf_config_init() after initialization ignored");
352 void surf_config_finalize(void)
354 if (!_surf_init_status)
355 return; /* Not initialized yet. Nothing to do */
357 xbt_cfg_free(&_surf_cfg_set);
358 _surf_init_status = 0;
361 void surf_config_models_setup(const char *platform_file)
363 char *workstation_model_name;
364 int workstation_id = -1;
365 char *network_model_name = NULL;
366 char *cpu_model_name = NULL;
368 workstation_model_name =
369 xbt_cfg_get_string(_surf_cfg_set, "workstation/model");
370 network_model_name = xbt_cfg_get_string(_surf_cfg_set, "network/model");
371 cpu_model_name = xbt_cfg_get_string(_surf_cfg_set, "cpu/model");
373 /* Check whether we use a net/cpu model differing from the default ones, in which case
374 * we should switch to the "compound" workstation model to correctly dispatch stuff to
375 * the right net/cpu models.
377 if ((strcmp(network_model_name, "LV08")
378 || strcmp(cpu_model_name, "Cas01"))
379 && !strcmp(workstation_model_name, "CLM03")) {
380 const char *val = "compound";
382 ("Switching workstation model to compound since you changed the network and/or cpu model(s)");
383 xbt_cfg_set_string(_surf_cfg_set, "workstation/model", val);
384 workstation_model_name = (char *) "compound";
387 DEBUG1("Workstation model: %s", workstation_model_name);
389 find_model_description(surf_workstation_model_description,
390 workstation_model_name);
391 if (!strcmp(workstation_model_name, "compound")) {
395 xbt_assert0(cpu_model_name,
396 "Set a cpu model to use with the 'compound' workstation model");
398 xbt_assert0(network_model_name,
399 "Set a network model to use with the 'compound' workstation model");
402 find_model_description(surf_network_model_description,
405 find_model_description(surf_cpu_model_description, cpu_model_name);
407 surf_cpu_model_description[cpu_id].model_init_preparse(platform_file);
408 surf_network_model_description[network_id].model_init_preparse
412 DEBUG0("Call workstation_model_init");
413 surf_workstation_model_description[workstation_id].model_init_preparse
417 void surf_config_models_create_elms(void)
419 char *workstation_model_name =
420 xbt_cfg_get_string(_surf_cfg_set, "workstation/model");
422 find_model_description(surf_workstation_model_description,
423 workstation_model_name);
424 if (surf_workstation_model_description
425 [workstation_id].model_init_postparse != NULL)
426 surf_workstation_model_description[workstation_id].model_init_postparse