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 "simix/context.h"
14 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_config, surf,
15 "About the configuration of surf (and the rest of the simulation)");
17 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");
43 ("\nYou can also use --help-tracing to see the details of all tracing options known by this simulator.\n");
48 (argv[i], "--help-models", strlen("--help-models") + 1)) {
49 model_help("workstation", surf_workstation_model_description);
50 model_help("CPU", surf_cpu_model_description);
51 model_help("network", surf_network_model_description);
56 (argv[i], "--help-tracing", strlen("--help-tracing") + 1)) {
61 if (remove_it) { /*remove this from argv */
62 for (j = i + 1; j < *argc; j++) {
63 argv[j - 1] = argv[j];
68 i--; /* compensate effect of next loop incrementation */
74 int _surf_init_status = 0; /* 0: beginning of time;
75 1: pre-inited (cfg_set created);
76 2: inited (running) */
78 /* callback of the workstation/model variable */
79 static void _surf_cfg_cb__workstation_model(const char *name, int pos)
83 xbt_assert0(_surf_init_status < 2,
84 "Cannot change the model after the initialization");
86 val = xbt_cfg_get_string(_surf_cfg_set, name);
88 if (!strcmp(val, "help")) {
89 model_help("workstation", surf_workstation_model_description);
93 /* Make sure that the model exists */
94 find_model_description(surf_workstation_model_description, val);
97 /* callback of the cpu/model variable */
98 static void _surf_cfg_cb__cpu_model(const char *name, int pos)
102 xbt_assert0(_surf_init_status < 2,
103 "Cannot change the model after the initialization");
105 val = xbt_cfg_get_string(_surf_cfg_set, name);
107 if (!strcmp(val, "help")) {
108 model_help("CPU", surf_cpu_model_description);
112 /* New Module missing */
113 find_model_description(surf_cpu_model_description, val);
116 /* callback of the workstation_model variable */
117 static void _surf_cfg_cb__network_model(const char *name, int pos)
121 xbt_assert0(_surf_init_status < 2,
122 "Cannot change the model after the initialization");
124 val = xbt_cfg_get_string(_surf_cfg_set, name);
126 if (!strcmp(val, "help")) {
127 model_help("network", surf_network_model_description);
131 /* New Module missing */
132 find_model_description(surf_network_model_description, val);
136 /* callbacks of the network models values */
137 static void _surf_cfg_cb__tcp_gamma(const char *name, int pos)
139 sg_tcp_gamma = xbt_cfg_get_double(_surf_cfg_set, name);
142 static void _surf_cfg_cb__maxmin_precision(const char* name, int pos)
144 sg_maxmin_precision = xbt_cfg_get_double(_surf_cfg_set, name);
147 static void _surf_cfg_cb__sender_gap(const char* name, int pos)
149 sg_sender_gap = xbt_cfg_get_double(_surf_cfg_set, name);
152 static void _surf_cfg_cb__latency_factor(const char *name, int pos)
154 sg_latency_factor = xbt_cfg_get_double(_surf_cfg_set, name);
157 static void _surf_cfg_cb__bandwidth_factor(const char *name, int pos)
159 sg_bandwidth_factor = xbt_cfg_get_double(_surf_cfg_set, name);
162 static void _surf_cfg_cb__weight_S(const char *name, int pos)
164 sg_weight_S_parameter = xbt_cfg_get_double(_surf_cfg_set, name);
167 static void _surf_cfg_cb__surf_maxmin_selective_update(const char *name,
170 sg_maxmin_selective_update = xbt_cfg_get_int(_surf_cfg_set, name);
173 /* callback of the inclusion path */
174 static void _surf_cfg_cb__surf_path(const char *name, int pos)
176 char *path = xbt_cfg_get_string_at(_surf_cfg_set, name, pos);
177 xbt_dynar_push(surf_path, &path);
180 /* callback to decide if we want to use the model-checking */
181 #include "xbt_modinter.h"
182 extern int _surf_do_model_check; /* this variable lives in xbt_main until I find a right location for it */
184 static void _surf_cfg_cb_model_check(const char *name, int pos)
186 _surf_do_model_check = 1;
187 /* Tell modules using mallocators that they shouldn't. MC don't like them */
192 static void _surf_cfg_cb_context_factory(const char *name, int pos)
194 smx_context_factory_name = xbt_cfg_get_string(_surf_cfg_set, name);
197 static void _surf_cfg_cb_context_stack_size(const char *name, int pos)
199 smx_context_stack_size = xbt_cfg_get_int(_surf_cfg_set, name) * 1024;
202 static void _surf_cfg_cb_contexts_nthreads(const char *name, int pos)
204 SIMIX_context_set_nthreads(xbt_cfg_get_int(_surf_cfg_set, name));
207 static void _surf_cfg_cb_contexts_parallel_threshold(const char *name, int pos)
209 SIMIX_context_set_parallel_threshold(xbt_cfg_get_int(_surf_cfg_set, name));
212 static void _surf_cfg_cb__surf_network_fullduplex(const char *name,
215 sg_network_fullduplex = xbt_cfg_get_int(_surf_cfg_set, name);
219 static void _surf_cfg_cb__gtnets_jitter(const char *name, int pos)
221 sg_gtnets_jitter = xbt_cfg_get_double(_surf_cfg_set, name);
224 static void _surf_cfg_cb__gtnets_jitter_seed(const char *name, int pos)
226 sg_gtnets_jitter_seed = xbt_cfg_get_int(_surf_cfg_set, name);
230 /* create the config set, register what should be and parse the command line*/
231 void surf_config_init(int *argc, char **argv)
233 char *description = xbt_malloc(1024), *p = description;
235 double double_default_value;
236 int default_value_int;
239 /* Create the configuration support */
240 if (_surf_init_status == 0) { /* Only create stuff if not already inited */
241 _surf_init_status = 1;
244 "The model to use for the CPU. Possible values: ");
246 while (*(++p) != '\0');
247 for (i = 0; surf_cpu_model_description[i].name; i++)
248 p += sprintf(p, "%s%s", (i == 0 ? "" : ", "),
249 surf_cpu_model_description[i].name);
251 ".\n (use 'help' as a value to see the long description of each model)");
252 default_value = xbt_strdup("Cas01");
253 xbt_cfg_register(&_surf_cfg_set,
254 "cpu/model", description, xbt_cfgelm_string,
255 &default_value, 1, 1, &_surf_cfg_cb__cpu_model, NULL);
258 "The model to use for the network. Possible values: ");
260 while (*(++p) != '\0');
261 for (i = 0; surf_network_model_description[i].name; i++)
262 p += sprintf(p, "%s%s", (i == 0 ? "" : ", "),
263 surf_network_model_description[i].name);
265 ".\n (use 'help' as a value to see the long description of each model)");
266 default_value = xbt_strdup("LV08");
267 xbt_cfg_register(&_surf_cfg_set,
268 "network/model", description, xbt_cfgelm_string,
269 &default_value, 1, 1, &_surf_cfg_cb__network_model,
273 "The model to use for the workstation. Possible values: ");
275 while (*(++p) != '\0');
276 for (i = 0; surf_workstation_model_description[i].name; i++)
277 p += sprintf(p, "%s%s", (i == 0 ? "" : ", "),
278 surf_workstation_model_description[i].name);
280 ".\n (use 'help' as a value to see the long description of each model)");
281 default_value = xbt_strdup("CLM03");
282 xbt_cfg_register(&_surf_cfg_set,
283 "workstation/model", description, xbt_cfgelm_string,
284 &default_value, 1, 1,
285 &_surf_cfg_cb__workstation_model, NULL);
287 xbt_free(description);
289 default_value = xbt_strdup("Full");
290 xbt_cfg_register(&_surf_cfg_set, "routing",
291 "Model to use to store the routing information",
292 xbt_cfgelm_string, &default_value, 1, 1, NULL, NULL);
294 xbt_cfg_register(&_surf_cfg_set, "TCP_gamma",
295 "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)",
296 xbt_cfgelm_double, NULL, 1, 1,
297 _surf_cfg_cb__tcp_gamma, NULL);
298 xbt_cfg_setdefault_double(_surf_cfg_set, "TCP_gamma", 20000.0);
300 xbt_cfg_register(&_surf_cfg_set, "maxmin/precision",
301 "Minimum retained action value when updating simulation",
302 xbt_cfgelm_double, NULL, 1, 1, _surf_cfg_cb__maxmin_precision, NULL);
303 xbt_cfg_setdefault_double(_surf_cfg_set, "maxmin/precision", 0.00001); // FIXME use setdefault everywhere here!
305 /* The parameters of network models */
307 double_default_value = 0.0;
308 xbt_cfg_register(&_surf_cfg_set, "network/sender_gap",
309 "Minimum gap between two overlapping sends",
310 xbt_cfgelm_double, &double_default_value, 1, 1,
311 _surf_cfg_cb__sender_gap, NULL);
313 double_default_value = 1.0;
314 xbt_cfg_register(&_surf_cfg_set, "network/latency_factor",
315 "Correction factor to apply to the provided latency (default value set by network model)",
316 xbt_cfgelm_double, &double_default_value, 1, 1,
317 _surf_cfg_cb__latency_factor, NULL);
318 double_default_value = 1.0;
319 xbt_cfg_register(&_surf_cfg_set, "network/bandwidth_factor",
320 "Correction factor to apply to the provided bandwidth (default value set by network model)",
321 xbt_cfgelm_double, &double_default_value, 1, 1,
322 _surf_cfg_cb__bandwidth_factor, NULL);
323 double_default_value = 0.0;
324 xbt_cfg_register(&_surf_cfg_set, "network/weight_S",
325 "Correction factor to apply to the weight of competing streams(default value set by network model)",
326 xbt_cfgelm_double, &double_default_value, 1, 1,
327 _surf_cfg_cb__weight_S, NULL);
330 xbt_cfg_register(&_surf_cfg_set, "path",
331 "Lookup path for inclusions in platform and deployment XML files",
332 xbt_cfgelm_string, NULL, 0, 0,
333 _surf_cfg_cb__surf_path, NULL);
335 default_value_int = 0;
336 xbt_cfg_register(&_surf_cfg_set, "maxmin_selective_update",
337 "Update the constraint set propagating recursively to others constraints",
338 xbt_cfgelm_int, &default_value_int, 0, 1,
339 _surf_cfg_cb__surf_maxmin_selective_update, NULL);
342 default_value_int = 0;
343 xbt_cfg_register(&_surf_cfg_set, "model-check",
344 "Activate the model-checking of the \"simulated\" system (EXPERIMENTAL -- msg only for now)",
345 xbt_cfgelm_int, &default_value_int, 0, 1,
346 _surf_cfg_cb_model_check, NULL);
348 FIXME: this function is not setting model-check to it's default value because
349 internally it calls to variable->cb_set that in this case is the function
350 _surf_cfg_cb_model_check which sets it's value to 1 (instead of the defalut value 0)
351 xbt_cfg_set_int(_surf_cfg_set, "model-check", default_value_int); */
353 /* context factory */
354 default_value = xbt_strdup("ucontext");
355 xbt_cfg_register(&_surf_cfg_set, "contexts/factory",
356 "Context factory to use in SIMIX (ucontext, thread or raw)",
357 xbt_cfgelm_string, &default_value, 1, 1, _surf_cfg_cb_context_factory, NULL);
359 /* stack size of contexts in Ko */
360 default_value_int = 128;
361 xbt_cfg_register(&_surf_cfg_set, "contexts/stack_size",
362 "Stack size of contexts in Ko (ucontext or raw only)",
363 xbt_cfgelm_int, &default_value_int, 1, 1,
364 _surf_cfg_cb_context_stack_size, NULL);
366 /* number of parallel threads for user processes */
367 default_value_int = 1;
368 xbt_cfg_register(&_surf_cfg_set, "contexts/nthreads",
369 "Number of parallel threads for user contexts (EXPERIMENTAL)",
370 xbt_cfgelm_int, &default_value_int, 1, 1,
371 _surf_cfg_cb_contexts_nthreads, NULL);
373 /* minimal number of user contexts to be run in parallel */
374 default_value_int = 1;
375 xbt_cfg_register(&_surf_cfg_set, "contexts/parallel_threshold",
376 "Minimal number of user contexts to be run in parallel",
377 xbt_cfgelm_int, &default_value_int, 1, 1,
378 _surf_cfg_cb_contexts_parallel_threshold, NULL);
380 default_value_int = 0;
381 xbt_cfg_register(&_surf_cfg_set, "fullduplex",
382 "Activate the interferences between uploads and downloads for fluid max-min models (LV08, CM03)",
383 xbt_cfgelm_int, &default_value_int, 0, 1,
384 _surf_cfg_cb__surf_network_fullduplex, NULL);
385 xbt_cfg_setdefault_int(_surf_cfg_set, "fullduplex", default_value_int);
388 xbt_cfg_register(&_surf_cfg_set, "gtnets_jitter",
389 "Double value to oscillate the link latency, uniformly in random interval [-latency*gtnets_jitter,latency*gtnets_jitter)",
390 xbt_cfgelm_double, NULL, 1, 1,
391 _surf_cfg_cb__gtnets_jitter, NULL);
392 xbt_cfg_setdefault_double(_surf_cfg_set, "gtnets_jitter", 0.0);
394 default_value_int = 10;
395 xbt_cfg_register(&_surf_cfg_set, "gtnets_jitter_seed",
396 "Use a positive seed to reproduce jitted results, value must be in [1,1e8], default is 10",
397 xbt_cfgelm_int, &default_value_int, 0, 1,
398 _surf_cfg_cb__gtnets_jitter_seed, NULL);
402 /* retrieves the current directory of the current process */
403 const char *initial_path = __surf_get_initial_path();
404 xbt_assert0((initial_path),
405 "__surf_get_initial_path() failed! Can't resolves current Windows directory");
407 surf_path = xbt_dynar_new(sizeof(char *), NULL);
408 xbt_cfg_setdefault_string(_surf_cfg_set, "path", initial_path);
412 surf_config_cmd_line(argc, argv);
414 WARN0("Call to surf_config_init() after initialization ignored");
418 void surf_config_finalize(void)
420 if (!_surf_init_status)
421 return; /* Not initialized yet. Nothing to do */
423 xbt_cfg_free(&_surf_cfg_set);
424 _surf_init_status = 0;
427 void surf_config_models_setup(const char *platform_file)
429 char *workstation_model_name;
430 int workstation_id = -1;
431 char *network_model_name = NULL;
432 char *cpu_model_name = NULL;
434 workstation_model_name =
435 xbt_cfg_get_string(_surf_cfg_set, "workstation/model");
436 network_model_name = xbt_cfg_get_string(_surf_cfg_set, "network/model");
437 cpu_model_name = xbt_cfg_get_string(_surf_cfg_set, "cpu/model");
439 /* Check whether we use a net/cpu model differing from the default ones, in which case
440 * we should switch to the "compound" workstation model to correctly dispatch stuff to
441 * the right net/cpu models.
443 if ((strcmp(network_model_name, "LV08")
444 || strcmp(cpu_model_name, "Cas01"))
445 && !strcmp(workstation_model_name, "CLM03")) {
446 const char *val = "compound";
448 ("Switching workstation model to compound since you changed the network and/or cpu model(s)");
449 xbt_cfg_set_string(_surf_cfg_set, "workstation/model", val);
450 workstation_model_name = (char *) "compound";
453 DEBUG1("Workstation model: %s", workstation_model_name);
455 find_model_description(surf_workstation_model_description,
456 workstation_model_name);
457 if (!strcmp(workstation_model_name, "compound")) {
461 xbt_assert0(cpu_model_name,
462 "Set a cpu model to use with the 'compound' workstation model");
464 xbt_assert0(network_model_name,
465 "Set a network model to use with the 'compound' workstation model");
468 find_model_description(surf_network_model_description,
471 find_model_description(surf_cpu_model_description, cpu_model_name);
473 surf_cpu_model_description[cpu_id].model_init_preparse(platform_file);
474 surf_network_model_description[network_id].model_init_preparse
478 DEBUG0("Call workstation_model_init");
479 surf_workstation_model_description[workstation_id].model_init_preparse
483 void surf_config_models_create_elms(void)
485 char *workstation_model_name =
486 xbt_cfg_get_string(_surf_cfg_set, "workstation/model");
488 find_model_description(surf_workstation_model_description,
489 workstation_model_name);
490 if (surf_workstation_model_description
491 [workstation_id].model_init_postparse != NULL)
492 surf_workstation_model_description[workstation_id].model_init_postparse