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"
12 #include "surf/surf_routing.h" /* COORD_HOST_LEVEL and COORD_ASR_LEVEL */
13 #include "simix/context.h"
15 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_config, surf,
16 "About the configuration of surf (and the rest of the simulation)");
18 xbt_cfg_t _surf_cfg_set = NULL;
20 /* Parse the command line, looking for options */
21 static void surf_config_cmd_line(int *argc, char **argv)
26 for (i = 1; i < *argc; i++) {
28 if (!strncmp(argv[i], "--cfg=", strlen("--cfg="))) {
29 opt = strchr(argv[i], '=');
32 xbt_cfg_set_parse(_surf_cfg_set, opt);
33 XBT_DEBUG("Did apply '%s' as config setting", opt);
35 } else if (!strncmp(argv[i], "--cfg-help", strlen("--cfg-help") + 1) ||
36 !strncmp(argv[i], "--help", strlen("--help") + 1)) {
38 ("Description of the configuration accepted by this simulator:\n");
39 xbt_cfg_help(_surf_cfg_set);
41 ("\nYou can also use --help-models to see the details of all models known by this simulator.\n");
44 ("\nYou can also use --help-tracing to see the details of all tracing options known by this simulator.\n");
49 (argv[i], "--help-models", strlen("--help-models") + 1)) {
50 model_help("workstation", surf_workstation_model_description);
51 model_help("CPU", surf_cpu_model_description);
52 model_help("network", surf_network_model_description);
57 (argv[i], "--help-tracing", strlen("--help-tracing") + 1)) {
62 if (remove_it) { /*remove this from argv */
63 for (j = i + 1; j < *argc; j++) {
64 argv[j - 1] = argv[j];
69 i--; /* compensate effect of next loop incrementation */
75 int _surf_init_status = 0; /* 0: beginning of time;
76 1: pre-inited (cfg_set created);
77 2: inited (running) */
79 /* callback of the workstation/model variable */
80 static void _surf_cfg_cb__workstation_model(const char *name, int pos)
84 xbt_assert(_surf_init_status < 2,
85 "Cannot change the model after the initialization");
87 val = xbt_cfg_get_string(_surf_cfg_set, name);
89 if (!strcmp(val, "help")) {
90 model_help("workstation", surf_workstation_model_description);
94 /* Make sure that the model exists */
95 find_model_description(surf_workstation_model_description, val);
98 /* callback of the cpu/model variable */
99 static void _surf_cfg_cb__cpu_model(const char *name, int pos)
103 xbt_assert(_surf_init_status < 2,
104 "Cannot change the model after the initialization");
106 val = xbt_cfg_get_string(_surf_cfg_set, name);
108 if (!strcmp(val, "help")) {
109 model_help("CPU", surf_cpu_model_description);
113 /* New Module missing */
114 find_model_description(surf_cpu_model_description, val);
117 /* callback of the workstation_model variable */
118 static void _surf_cfg_cb__network_model(const char *name, int pos)
122 xbt_assert(_surf_init_status < 2,
123 "Cannot change the model after the initialization");
125 val = xbt_cfg_get_string(_surf_cfg_set, name);
127 if (!strcmp(val, "help")) {
128 model_help("network", surf_network_model_description);
132 /* New Module missing */
133 find_model_description(surf_network_model_description, val);
137 /* callbacks of the network models values */
138 static void _surf_cfg_cb__tcp_gamma(const char *name, int pos)
140 sg_tcp_gamma = xbt_cfg_get_double(_surf_cfg_set, name);
143 static void _surf_cfg_cb__maxmin_precision(const char* name, int pos)
145 sg_maxmin_precision = xbt_cfg_get_double(_surf_cfg_set, name);
148 static void _surf_cfg_cb__sender_gap(const char* name, int pos)
150 sg_sender_gap = xbt_cfg_get_double(_surf_cfg_set, name);
153 static void _surf_cfg_cb__latency_factor(const char *name, int pos)
155 sg_latency_factor = xbt_cfg_get_double(_surf_cfg_set, name);
158 static void _surf_cfg_cb__bandwidth_factor(const char *name, int pos)
160 sg_bandwidth_factor = xbt_cfg_get_double(_surf_cfg_set, name);
163 static void _surf_cfg_cb__weight_S(const char *name, int pos)
165 sg_weight_S_parameter = xbt_cfg_get_double(_surf_cfg_set, name);
168 static void _surf_cfg_cb__surf_maxmin_selective_update(const char *name,
171 sg_maxmin_selective_update = xbt_cfg_get_int(_surf_cfg_set, name);
174 /* callback of the inclusion path */
175 static void _surf_cfg_cb__surf_path(const char *name, int pos)
177 char *path = xbt_cfg_get_string_at(_surf_cfg_set, name, pos);
178 xbt_dynar_push(surf_path, &path);
181 /* callback to decide if we want to use the model-checking */
182 #include "xbt_modinter.h"
183 extern int _surf_do_model_check; /* this variable lives in xbt_main until I find a right location for it */
185 static void _surf_cfg_cb_model_check(const char *name, int pos)
187 _surf_do_model_check = xbt_cfg_get_int(_surf_cfg_set, name);
189 if (_surf_do_model_check) {
190 /* Tell modules using mallocators that they shouldn't. MC don't like them */
196 extern int _surf_do_verbose_exit;
198 static void _surf_cfg_cb_verbose_exit(const char *name, int pos)
200 _surf_do_verbose_exit = xbt_cfg_get_int(_surf_cfg_set, name);
204 static void _surf_cfg_cb_context_factory(const char *name, int pos)
206 smx_context_factory_name = xbt_cfg_get_string(_surf_cfg_set, name);
209 static void _surf_cfg_cb_context_stack_size(const char *name, int pos)
211 smx_context_stack_size = xbt_cfg_get_int(_surf_cfg_set, name) * 1024;
214 static void _surf_cfg_cb_contexts_nthreads(const char *name, int pos)
216 SIMIX_context_set_nthreads(xbt_cfg_get_int(_surf_cfg_set, name));
219 static void _surf_cfg_cb_contexts_parallel_threshold(const char *name, int pos)
221 SIMIX_context_set_parallel_threshold(xbt_cfg_get_int(_surf_cfg_set, name));
224 static void _surf_cfg_cb__surf_network_coordinates(const char *name,
227 char *val = xbt_cfg_get_string(_surf_cfg_set, name);
228 if (!strcmp(val, "yes")) {
229 if (!COORD_HOST_LEVEL) {
230 COORD_HOST_LEVEL = xbt_lib_add_level(host_lib,xbt_dynar_free_voidp);
231 COORD_ASR_LEVEL = xbt_lib_add_level(as_router_lib,xbt_dynar_free_voidp);
233 } else if (!strcmp(val, "no")) {
234 if (COORD_HOST_LEVEL)
235 XBT_WARN("Cannot disable CMD prop coordinates, once set.");
237 XBT_WARN("Setting CMD prop coordinates must be \"yes\" or \"no\"");
241 static void _surf_cfg_cb__surf_network_fullduplex(const char *name,
244 sg_network_fullduplex = xbt_cfg_get_int(_surf_cfg_set, name);
248 static void _surf_cfg_cb__gtnets_jitter(const char *name, int pos)
250 sg_gtnets_jitter = xbt_cfg_get_double(_surf_cfg_set, name);
253 static void _surf_cfg_cb__gtnets_jitter_seed(const char *name, int pos)
255 sg_gtnets_jitter_seed = xbt_cfg_get_int(_surf_cfg_set, name);
259 /* create the config set, register what should be and parse the command line*/
260 void surf_config_init(int *argc, char **argv)
262 char *description = xbt_malloc(1024), *p = description;
264 double double_default_value;
265 int default_value_int;
268 /* Create the configuration support */
269 if (_surf_init_status == 0) { /* Only create stuff if not already inited */
270 _surf_init_status = 1;
273 "The model to use for the CPU. Possible values: ");
275 while (*(++p) != '\0');
276 for (i = 0; surf_cpu_model_description[i].name; i++)
277 p += sprintf(p, "%s%s", (i == 0 ? "" : ", "),
278 surf_cpu_model_description[i].name);
280 ".\n (use 'help' as a value to see the long description of each model)");
281 default_value = xbt_strdup("Cas01");
282 xbt_cfg_register(&_surf_cfg_set,
283 "cpu/model", description, xbt_cfgelm_string,
284 &default_value, 1, 1, &_surf_cfg_cb__cpu_model, NULL);
287 "The model to use for the network. Possible values: ");
289 while (*(++p) != '\0');
290 for (i = 0; surf_network_model_description[i].name; i++)
291 p += sprintf(p, "%s%s", (i == 0 ? "" : ", "),
292 surf_network_model_description[i].name);
294 ".\n (use 'help' as a value to see the long description of each model)");
295 default_value = xbt_strdup("LV08");
296 xbt_cfg_register(&_surf_cfg_set,
297 "network/model", description, xbt_cfgelm_string,
298 &default_value, 1, 1, &_surf_cfg_cb__network_model,
302 "The model to use for the workstation. Possible values: ");
304 while (*(++p) != '\0');
305 for (i = 0; surf_workstation_model_description[i].name; i++)
306 p += sprintf(p, "%s%s", (i == 0 ? "" : ", "),
307 surf_workstation_model_description[i].name);
309 ".\n (use 'help' as a value to see the long description of each model)");
310 default_value = xbt_strdup("CLM03");
311 xbt_cfg_register(&_surf_cfg_set,
312 "workstation/model", description, xbt_cfgelm_string,
313 &default_value, 1, 1,
314 &_surf_cfg_cb__workstation_model, NULL);
316 xbt_free(description);
318 default_value = xbt_strdup("Full");
319 xbt_cfg_register(&_surf_cfg_set, "routing",
320 "Model to use to store the routing information",
321 xbt_cfgelm_string, &default_value, 1, 1, NULL, NULL);
323 xbt_cfg_register(&_surf_cfg_set, "TCP_gamma",
324 "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)",
325 xbt_cfgelm_double, NULL, 1, 1,
326 _surf_cfg_cb__tcp_gamma, NULL);
327 xbt_cfg_setdefault_double(_surf_cfg_set, "TCP_gamma", 20000.0);
329 xbt_cfg_register(&_surf_cfg_set, "maxmin/precision",
330 "Minimum retained action value when updating simulation",
331 xbt_cfgelm_double, NULL, 1, 1, _surf_cfg_cb__maxmin_precision, NULL);
332 xbt_cfg_setdefault_double(_surf_cfg_set, "maxmin/precision", 0.00001); // FIXME use setdefault everywhere here!
334 /* The parameters of network models */
336 double_default_value = 0.0;
337 xbt_cfg_register(&_surf_cfg_set, "network/sender_gap",
338 "Minimum gap between two overlapping sends",
339 xbt_cfgelm_double, &double_default_value, 1, 1,
340 _surf_cfg_cb__sender_gap, NULL);
342 double_default_value = 1.0;
343 xbt_cfg_register(&_surf_cfg_set, "network/latency_factor",
344 "Correction factor to apply to the provided latency (default value set by network model)",
345 xbt_cfgelm_double, &double_default_value, 1, 1,
346 _surf_cfg_cb__latency_factor, NULL);
347 double_default_value = 1.0;
348 xbt_cfg_register(&_surf_cfg_set, "network/bandwidth_factor",
349 "Correction factor to apply to the provided bandwidth (default value set by network model)",
350 xbt_cfgelm_double, &double_default_value, 1, 1,
351 _surf_cfg_cb__bandwidth_factor, NULL);
352 double_default_value = 0.0;
353 xbt_cfg_register(&_surf_cfg_set, "network/weight_S",
354 "Correction factor to apply to the weight of competing streams(default value set by network model)",
355 xbt_cfgelm_double, &double_default_value, 1, 1,
356 _surf_cfg_cb__weight_S, NULL);
359 xbt_cfg_register(&_surf_cfg_set, "path",
360 "Lookup path for inclusions in platform and deployment XML files",
361 xbt_cfgelm_string, NULL, 0, 0,
362 _surf_cfg_cb__surf_path, NULL);
364 default_value_int = 0;
365 xbt_cfg_register(&_surf_cfg_set, "maxmin_selective_update",
366 "Update the constraint set propagating recursively to others constraints",
367 xbt_cfgelm_int, &default_value_int, 0, 1,
368 _surf_cfg_cb__surf_maxmin_selective_update, NULL);
371 default_value_int = 0;
372 xbt_cfg_register(&_surf_cfg_set, "model-check",
373 "Activate the model-checking of the \"simulated\" system (EXPERIMENTAL -- msg only for now)",
374 xbt_cfgelm_int, &default_value_int, 0, 1,
375 _surf_cfg_cb_model_check, NULL);
378 FIXME: this function is not setting model-check to it's default value because
379 internally it calls to variable->cb_set that in this case is the function
380 _surf_cfg_cb_model_check which sets it's value to 1 (instead of the default value 0)
381 xbt_cfg_set_int(_surf_cfg_set, "model-check", default_value_int); */
383 /* do verbose-exit */
384 default_value_int = 0;
385 xbt_cfg_register(&_surf_cfg_set, "verbose-exit",
386 "Activate the \"do nothing\" mode in Ctrl-C",
387 xbt_cfgelm_int, &default_value_int, 0, 1,
388 _surf_cfg_cb_verbose_exit, NULL);
391 /* context factory */
392 default_value = xbt_strdup("ucontext");
393 xbt_cfg_register(&_surf_cfg_set, "contexts/factory",
394 "Context factory to use in SIMIX (ucontext, thread or raw)",
395 xbt_cfgelm_string, &default_value, 1, 1, _surf_cfg_cb_context_factory, NULL);
397 /* stack size of contexts in Ko */
398 default_value_int = 128;
399 xbt_cfg_register(&_surf_cfg_set, "contexts/stack_size",
400 "Stack size of contexts in Ko (ucontext or raw only)",
401 xbt_cfgelm_int, &default_value_int, 1, 1,
402 _surf_cfg_cb_context_stack_size, NULL);
404 /* number of parallel threads for user processes */
405 default_value_int = 1;
406 xbt_cfg_register(&_surf_cfg_set, "contexts/nthreads",
407 "Number of parallel threads for user contexts (EXPERIMENTAL)",
408 xbt_cfgelm_int, &default_value_int, 1, 1,
409 _surf_cfg_cb_contexts_nthreads, NULL);
411 /* minimal number of user contexts to be run in parallel */
412 default_value_int = 1;
413 xbt_cfg_register(&_surf_cfg_set, "contexts/parallel_threshold",
414 "Minimal number of user contexts to be run in parallel",
415 xbt_cfgelm_int, &default_value_int, 1, 1,
416 _surf_cfg_cb_contexts_parallel_threshold, NULL);
418 default_value = xbt_strdup("no");
419 xbt_cfg_register(&_surf_cfg_set, "coordinates",
420 "\"yes\" or \"no\" (FIXME: document)",
421 xbt_cfgelm_string, &default_value, 1, 1,
422 _surf_cfg_cb__surf_network_coordinates, NULL);
423 xbt_cfg_setdefault_string(_surf_cfg_set, "coordinates", default_value);
425 default_value_int = 0;
426 xbt_cfg_register(&_surf_cfg_set, "fullduplex",
427 "Activate the interferences between uploads and downloads for fluid max-min models (LV08, CM03)",
428 xbt_cfgelm_int, &default_value_int, 0, 1,
429 _surf_cfg_cb__surf_network_fullduplex, NULL);
430 xbt_cfg_setdefault_int(_surf_cfg_set, "fullduplex", default_value_int);
433 xbt_cfg_register(&_surf_cfg_set, "gtnets_jitter",
434 "Double value to oscillate the link latency, uniformly in random interval [-latency*gtnets_jitter,latency*gtnets_jitter)",
435 xbt_cfgelm_double, NULL, 1, 1,
436 _surf_cfg_cb__gtnets_jitter, NULL);
437 xbt_cfg_setdefault_double(_surf_cfg_set, "gtnets_jitter", 0.0);
439 default_value_int = 10;
440 xbt_cfg_register(&_surf_cfg_set, "gtnets_jitter_seed",
441 "Use a positive seed to reproduce jitted results, value must be in [1,1e8], default is 10",
442 xbt_cfgelm_int, &default_value_int, 0, 1,
443 _surf_cfg_cb__gtnets_jitter_seed, NULL);
447 /* retrieves the current directory of the current process */
448 const char *initial_path = __surf_get_initial_path();
449 xbt_assert((initial_path),
450 "__surf_get_initial_path() failed! Can't resolves current Windows directory");
452 surf_path = xbt_dynar_new(sizeof(char *), NULL);
453 xbt_cfg_setdefault_string(_surf_cfg_set, "path", initial_path);
457 surf_config_cmd_line(argc, argv);
459 XBT_WARN("Call to surf_config_init() after initialization ignored");
463 void surf_config_finalize(void)
465 if (!_surf_init_status)
466 return; /* Not initialized yet. Nothing to do */
468 xbt_cfg_free(&_surf_cfg_set);
469 _surf_init_status = 0;
472 void surf_config_models_setup(const char *platform_file)
474 char *workstation_model_name;
475 int workstation_id = -1;
476 char *network_model_name = NULL;
477 char *cpu_model_name = NULL;
479 workstation_model_name =
480 xbt_cfg_get_string(_surf_cfg_set, "workstation/model");
481 network_model_name = xbt_cfg_get_string(_surf_cfg_set, "network/model");
482 cpu_model_name = xbt_cfg_get_string(_surf_cfg_set, "cpu/model");
484 /* Check whether we use a net/cpu model differing from the default ones, in which case
485 * we should switch to the "compound" workstation model to correctly dispatch stuff to
486 * the right net/cpu models.
489 if((!xbt_cfg_is_default_value(_surf_cfg_set, "network/model") ||
490 !xbt_cfg_is_default_value(_surf_cfg_set, "cpu/model")) &&
491 xbt_cfg_is_default_value(_surf_cfg_set, "workstation/model"))
493 const char *val = "compound";
495 ("Switching workstation model to compound since you changed the network and/or cpu model(s)");
496 xbt_cfg_set_string(_surf_cfg_set, "workstation/model", val);
497 workstation_model_name = (char *) "compound";
500 XBT_DEBUG("Workstation model: %s", workstation_model_name);
502 find_model_description(surf_workstation_model_description,
503 workstation_model_name);
504 if (!strcmp(workstation_model_name, "compound")) {
508 xbt_assert(cpu_model_name,
509 "Set a cpu model to use with the 'compound' workstation model");
511 xbt_assert(network_model_name,
512 "Set a network model to use with the 'compound' workstation model");
515 find_model_description(surf_network_model_description,
518 find_model_description(surf_cpu_model_description, cpu_model_name);
520 surf_cpu_model_description[cpu_id].model_init_preparse(platform_file);
521 surf_network_model_description[network_id].model_init_preparse
525 XBT_DEBUG("Call workstation_model_init");
526 surf_workstation_model_description[workstation_id].model_init_preparse
530 void surf_config_models_create_elms(void)
532 char *workstation_model_name =
533 xbt_cfg_get_string(_surf_cfg_set, "workstation/model");
535 find_model_description(surf_workstation_model_description,
536 workstation_model_name);
537 if (surf_workstation_model_description
538 [workstation_id].model_init_postparse != NULL)
539 surf_workstation_model_description[workstation_id].model_init_postparse