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 static void _surf_cfg_cb__surf_network_fullduplex(const char *name,
174 sg_network_fullduplex = xbt_cfg_get_int(_surf_cfg_set, name);
178 static void _surf_cfg_cb__gtnets_jitter(const char *name, int pos)
180 sg_gtnets_jitter = xbt_cfg_get_double(_surf_cfg_set, name);
183 static void _surf_cfg_cb__gtnets_jitter_seed(const char *name, int pos)
185 sg_gtnets_jitter_seed = xbt_cfg_get_int(_surf_cfg_set, name);
189 /* create the config set, register what should be and parse the command line*/
190 void surf_config_init(int *argc, char **argv)
192 char *description = xbt_malloc(1024), *p = description;
194 double double_default_value;
195 int default_value_int;
198 /* Create the configuration support */
199 if (_surf_init_status == 0) { /* Only create stuff if not already inited */
200 _surf_init_status = 1;
203 "The model to use for the CPU. Possible values: ");
205 while (*(++p) != '\0');
206 for (i = 0; surf_cpu_model_description[i].name; i++)
207 p += sprintf(p, "%s%s", (i == 0 ? "" : ", "),
208 surf_cpu_model_description[i].name);
210 ".\n (use 'help' as a value to see the long description of each model)");
211 default_value = xbt_strdup("Cas01");
212 xbt_cfg_register(&_surf_cfg_set,
213 "cpu/model", description, xbt_cfgelm_string,
214 &default_value, 1, 1, &_surf_cfg_cb__cpu_model, NULL);
217 "The model to use for the network. Possible values: ");
219 while (*(++p) != '\0');
220 for (i = 0; surf_network_model_description[i].name; i++)
221 p += sprintf(p, "%s%s", (i == 0 ? "" : ", "),
222 surf_network_model_description[i].name);
224 ".\n (use 'help' as a value to see the long description of each model)");
225 default_value = xbt_strdup("LV08");
226 xbt_cfg_register(&_surf_cfg_set,
227 "network/model", description, xbt_cfgelm_string,
228 &default_value, 1, 1, &_surf_cfg_cb__network_model,
232 "The model to use for the workstation. Possible values: ");
234 while (*(++p) != '\0');
235 for (i = 0; surf_workstation_model_description[i].name; i++)
236 p += sprintf(p, "%s%s", (i == 0 ? "" : ", "),
237 surf_workstation_model_description[i].name);
239 ".\n (use 'help' as a value to see the long description of each model)");
240 default_value = xbt_strdup("CLM03");
241 xbt_cfg_register(&_surf_cfg_set,
242 "workstation/model", description, xbt_cfgelm_string,
243 &default_value, 1, 1,
244 &_surf_cfg_cb__workstation_model, NULL);
246 xbt_free(description);
248 default_value = xbt_strdup("Full");
249 xbt_cfg_register(&_surf_cfg_set, "routing",
250 "Model to use to store the routing information",
251 xbt_cfgelm_string, &default_value, 1, 1, NULL, NULL);
253 xbt_cfg_register(&_surf_cfg_set, "TCP_gamma",
254 "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)",
255 xbt_cfgelm_double, NULL, 1, 1,
256 _surf_cfg_cb__tcp_gamma, NULL);
257 xbt_cfg_set_double(_surf_cfg_set, "TCP_gamma", 20000.0);
259 /* The parameters of network models */
260 double_default_value = 1.0;
261 xbt_cfg_register(&_surf_cfg_set, "network/latency_factor",
262 "Correction factor to apply to the provided latency (default value set by network model)",
263 xbt_cfgelm_double, &double_default_value, 1, 1,
264 _surf_cfg_cb__latency_factor, NULL);
265 double_default_value = 1.0;
266 xbt_cfg_register(&_surf_cfg_set, "network/bandwidth_factor",
267 "Correction factor to apply to the provided bandwidth (default value set by network model)",
268 xbt_cfgelm_double, &double_default_value, 1, 1,
269 _surf_cfg_cb__bandwidth_factor, NULL);
270 double_default_value = 0.0;
271 xbt_cfg_register(&_surf_cfg_set, "network/weight_S",
272 "Correction factor to apply to the weight of competing streams(default value set by network model)",
273 xbt_cfgelm_double, &double_default_value, 1, 1,
274 _surf_cfg_cb__weight_S, NULL);
277 xbt_cfg_register(&_surf_cfg_set, "path",
278 "Lookup path for inclusions in platform and deployment XML files",
279 xbt_cfgelm_string, NULL, 0, 0,
280 _surf_cfg_cb__surf_path, NULL);
282 default_value_int = 0;
283 xbt_cfg_register(&_surf_cfg_set, "maxmin_selective_update",
284 "Update the constraint set propagating recursively to others constraints",
285 xbt_cfgelm_int, &default_value_int, 0, 1,
286 _surf_cfg_cb__surf_maxmin_selective_update, NULL);
289 default_value_int = 0;
290 xbt_cfg_register(&_surf_cfg_set, "model-check",
291 "Activate the model-checking of the \"simulated\" system (EXPERIMENTAL -- msg only for now)",
292 xbt_cfgelm_int, &default_value_int, 0, 1,
293 _surf_cfg_cb_model_check, NULL);
295 FIXME: this function is not setting model-check to it's default value because
296 internally it calls to variable->cb_set that in this case is the function
297 _surf_cfg_cb_model_check which sets it's value to 1 (instead of the defalut value 0)
298 xbt_cfg_set_int(_surf_cfg_set, "model-check", default_value_int); */
300 default_value_int = 0;
301 xbt_cfg_register(&_surf_cfg_set, "fullduplex",
302 "Update the constraint set propagating recursively to others constraints",
303 xbt_cfgelm_int, &default_value_int, 0, 1,
304 _surf_cfg_cb__surf_network_fullduplex, NULL);
305 xbt_cfg_set_int(_surf_cfg_set, "fullduplex", default_value_int);
308 xbt_cfg_register(&_surf_cfg_set, "gtnets_jitter",
309 "Double value to oscillate the link latency, uniformly in random interval [-latency*gtnets_jitter,latency*gtnets_jitter)",
310 xbt_cfgelm_double, NULL, 1, 1,
311 _surf_cfg_cb__gtnets_jitter, NULL);
312 xbt_cfg_set_double(_surf_cfg_set, "gtnets_jitter", 0.0);
314 default_value_int = 10;
315 xbt_cfg_register(&_surf_cfg_set, "gtnets_jitter_seed",
316 "Use a positive seed to reproduce jitted results, value must be in [1,1e8], default is 10",
317 xbt_cfgelm_int, &default_value_int, 0, 1,
318 _surf_cfg_cb__gtnets_jitter_seed, NULL);
322 /* retrieves the current directory of the current process */
323 const char *initial_path = __surf_get_initial_path();
324 xbt_assert0((initial_path),
325 "__surf_get_initial_path() failed! Can't resolves current Windows directory");
327 surf_path = xbt_dynar_new(sizeof(char *), NULL);
328 xbt_cfg_set_string(_surf_cfg_set, "path", initial_path);
332 surf_config_cmd_line(argc, argv);
334 WARN0("Call to surf_config_init() after initialization ignored");
338 void surf_config_finalize(void)
340 if (!_surf_init_status)
341 return; /* Not initialized yet. Nothing to do */
343 xbt_cfg_free(&_surf_cfg_set);
344 _surf_init_status = 0;
347 void surf_config_models_setup(const char *platform_file)
349 char *workstation_model_name;
350 int workstation_id = -1;
351 char *network_model_name = NULL;
352 char *cpu_model_name = NULL;
353 surf_timer_model_init(platform_file);
355 workstation_model_name =
356 xbt_cfg_get_string(_surf_cfg_set, "workstation/model");
357 network_model_name = xbt_cfg_get_string(_surf_cfg_set, "network/model");
358 cpu_model_name = xbt_cfg_get_string(_surf_cfg_set, "cpu/model");
360 /* Check whether we use a net/cpu model differing from the default ones, in which case
361 * we should switch to the "compound" workstation model to correctly dispatch stuff to
362 * the right net/cpu models.
364 if ((strcmp(network_model_name, "LV08")
365 || strcmp(cpu_model_name, "Cas01"))
366 && !strcmp(workstation_model_name, "CLM03")) {
367 const char *val = "compound";
369 ("Switching workstation model to compound since you changed the network and/or cpu model(s)");
370 xbt_cfg_set_string(_surf_cfg_set, "workstation/model", val);
371 workstation_model_name = (char *) "compound";
374 DEBUG1("Workstation model: %s", workstation_model_name);
376 find_model_description(surf_workstation_model_description,
377 workstation_model_name);
378 if (!strcmp(workstation_model_name, "compound")) {
382 xbt_assert0(cpu_model_name,
383 "Set a cpu model to use with the 'compound' workstation model");
385 xbt_assert0(network_model_name,
386 "Set a network model to use with the 'compound' workstation model");
389 find_model_description(surf_network_model_description,
392 find_model_description(surf_cpu_model_description, cpu_model_name);
394 surf_cpu_model_description[cpu_id].model_init_preparse(platform_file);
395 surf_network_model_description[network_id].model_init_preparse
399 DEBUG0("Call workstation_model_init");
400 surf_workstation_model_description[workstation_id].model_init_preparse
404 void surf_config_models_create_elms(void)
406 char *workstation_model_name =
407 xbt_cfg_get_string(_surf_cfg_set, "workstation/model");
409 find_model_description(surf_workstation_model_description,
410 workstation_model_name);
411 if (surf_workstation_model_description
412 [workstation_id].model_init_postparse != NULL)
413 surf_workstation_model_description[workstation_id].model_init_postparse