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)) {
36 printf("Description of the configuration accepted by this simulator:\n");
37 xbt_cfg_help(_surf_cfg_set);
38 printf("\nYou can also use --help-models to see the details of all models known by this simulator.\n");
40 } else if (!strncmp(argv[i], "--help-models", strlen("--help-models")+1)) {
41 model_help("workstation",surf_workstation_model_description);
42 model_help("CPU",surf_cpu_model_description);
43 model_help("network",surf_network_model_description);
46 if (remove_it) { /*remove this from argv */
47 for (j = i + 1; j < *argc; j++) {
48 argv[j - 1] = argv[j];
53 i--; /* compensate effect of next loop incrementation */
59 int _surf_init_status = 0; /* 0: beginning of time;
60 1: pre-inited (cfg_set created);
61 2: inited (running) */
63 /* callback of the workstation/model variable */
64 static void _surf_cfg_cb__workstation_model(const char *name, int pos)
68 xbt_assert0(_surf_init_status < 2,
69 "Cannot change the model after the initialization");
71 val = xbt_cfg_get_string(_surf_cfg_set, name);
73 if (!strcmp(val,"help")) {
74 model_help("workstation",surf_workstation_model_description);
78 /* Make sure that the model exists */
79 find_model_description(surf_workstation_model_description, val);
82 /* callback of the cpu/model variable */
83 static void _surf_cfg_cb__cpu_model(const char *name, int pos)
87 xbt_assert0(_surf_init_status < 2,
88 "Cannot change the model after the initialization");
90 val = xbt_cfg_get_string(_surf_cfg_set, name);
92 if (!strcmp(val,"help")) {
93 model_help("CPU",surf_cpu_model_description);
97 /* New Module missing */
98 find_model_description(surf_cpu_model_description, val);
101 /* callback of the workstation_model variable */
102 static void _surf_cfg_cb__network_model(const char *name, int pos)
106 xbt_assert0(_surf_init_status < 2,
107 "Cannot change the model after the initialization");
109 val = xbt_cfg_get_string(_surf_cfg_set, name);
111 if (!strcmp(val,"help")) {
112 model_help("network",surf_network_model_description);
116 /* New Module missing */
117 find_model_description(surf_network_model_description, val);
121 /* callbacks of the network models values */
122 static void _surf_cfg_cb__tcp_gamma(const char *name, int pos) {
123 sg_tcp_gamma = xbt_cfg_get_double(_surf_cfg_set, name);
125 static void _surf_cfg_cb__latency_factor(const char *name, int pos) {
126 sg_latency_factor = xbt_cfg_get_double(_surf_cfg_set, name);
128 static void _surf_cfg_cb__bandwidth_factor(const char *name, int pos) {
129 sg_bandwidth_factor = xbt_cfg_get_double(_surf_cfg_set, name);
131 static void _surf_cfg_cb__weight_S(const char *name, int pos) {
132 sg_weight_S_parameter = xbt_cfg_get_double(_surf_cfg_set, name);
134 static void _surf_cfg_cb__surf_maxmin_selective_update(const char *name, int pos) {
135 sg_maxmin_selective_update = xbt_cfg_get_int(_surf_cfg_set, name);
138 /* callback of the inclusion path */
139 static void _surf_cfg_cb__surf_path(const char *name, int pos) {
140 char *path = xbt_cfg_get_string_at(_surf_cfg_set, name, pos);
141 xbt_dynar_push(surf_path, &path);
144 /* callback to decide if we want to use the model-checking */
145 #include "xbt_modinter.h"
146 int _surf_do_model_check = 0; /* this variable is used accros the lib */
148 static void _surf_cfg_cb_model_check(const char *name, int pos) {
149 _surf_do_model_check = 1;
150 /* Tell modules using mallocators that they shouldn't. MC don't like them */
156 static void _surf_cfg_cb__gtnets_jitter(const char *name, int pos){
157 sg_gtnets_jitter = xbt_cfg_get_double(_surf_cfg_set, name);
159 static void _surf_cfg_cb__gtnets_jitter_seed(const char *name, int pos){
160 sg_gtnets_jitter_seed = xbt_cfg_get_int(_surf_cfg_set, name);
164 /* create the config set, register what should be and parse the command line*/
165 void surf_config_init(int *argc, char **argv)
167 char *description = xbt_malloc(1024), *p = description;
169 double double_default_value;
170 int default_value_int;
173 /* Create the configuration support */
174 if (_surf_init_status == 0) { /* Only create stuff if not already inited */
175 _surf_init_status = 1;
177 sprintf(description, "The model to use for the CPU. Possible values: ");
179 while (*(++p) != '\0');
180 for (i = 0; surf_cpu_model_description[i].name; i++)
182 sprintf(p, "%s%s", (i == 0 ? "" : ", "),
183 surf_cpu_model_description[i].name);
184 sprintf(p,".\n (use 'help' as a value to see the long description of each model)");
185 default_value = xbt_strdup("Cas01");
186 xbt_cfg_register(&_surf_cfg_set,
187 "cpu/model", description, xbt_cfgelm_string,
188 &default_value, 1, 1, &_surf_cfg_cb__cpu_model, NULL);
191 "The model to use for the network. Possible values: ");
193 while (*(++p) != '\0');
194 for (i = 0; surf_network_model_description[i].name; i++)
196 sprintf(p, "%s%s", (i == 0 ? "" : ", "),
197 surf_network_model_description[i].name);
198 sprintf(p,".\n (use 'help' as a value to see the long description of each model)");
199 default_value = xbt_strdup("LV08");
200 xbt_cfg_register(&_surf_cfg_set,
201 "network/model", description, xbt_cfgelm_string,
202 &default_value, 1, 1, &_surf_cfg_cb__network_model,
206 "The model to use for the workstation. Possible values: ");
208 while (*(++p) != '\0');
209 for (i = 0; surf_workstation_model_description[i].name; i++)
211 sprintf(p, "%s%s", (i == 0 ? "" : ", "),
212 surf_workstation_model_description[i].name);
213 sprintf(p,".\n (use 'help' as a value to see the long description of each model)");
214 default_value = xbt_strdup("CLM03");
215 xbt_cfg_register(&_surf_cfg_set,
216 "workstation/model", description, xbt_cfgelm_string,
217 &default_value, 1, 1, &_surf_cfg_cb__workstation_model,
220 xbt_free(description);
222 default_value = xbt_strdup("Full");
223 xbt_cfg_register(&_surf_cfg_set, "routing",
224 "Model to use to store the routing information",
225 xbt_cfgelm_string, &default_value, 1, 1, NULL, NULL);
227 xbt_cfg_register(&_surf_cfg_set, "TCP_gamma",
228 "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)",
229 xbt_cfgelm_double, NULL, 1, 1, _surf_cfg_cb__tcp_gamma, NULL);
230 xbt_cfg_set_double(_surf_cfg_set, "TCP_gamma", 20000.0);
232 /* The parameters of network models */
233 double_default_value = 1.0;
234 xbt_cfg_register(&_surf_cfg_set, "network/latency_factor",
235 "Correction factor to apply to the provided latency (default value set by network model)",
236 xbt_cfgelm_double, &double_default_value, 1, 1, _surf_cfg_cb__latency_factor, NULL);
237 double_default_value = 1.0;
238 xbt_cfg_register(&_surf_cfg_set, "network/bandwidth_factor",
239 "Correction factor to apply to the provided bandwidth (default value set by network model)",
240 xbt_cfgelm_double, &double_default_value, 1, 1, _surf_cfg_cb__bandwidth_factor, NULL);
241 double_default_value = 0.0;
242 xbt_cfg_register(&_surf_cfg_set, "network/weight_S",
243 "Correction factor to apply to the weight of competing streams(default value set by network model)",
244 xbt_cfgelm_double, &double_default_value, 1, 1, _surf_cfg_cb__weight_S, NULL);
247 xbt_cfg_register(&_surf_cfg_set, "path",
248 "Lookup path for inclusions in platform and deployment XML files",
249 xbt_cfgelm_string, NULL, 0, 0, _surf_cfg_cb__surf_path,
252 default_value_int = 0;
253 xbt_cfg_register(&_surf_cfg_set, "maxmin_selective_update",
254 "Update the constraint set propagating recursively to others constraints",
255 xbt_cfgelm_int, &default_value_int, 0, 1, _surf_cfg_cb__surf_maxmin_selective_update, NULL);
258 default_value_int = 0;
259 xbt_cfg_register(&_surf_cfg_set, "model-check",
260 "Activate the model-checking of the \"simulated\" system (EXPERIMENTAL -- msg only for now)",
261 xbt_cfgelm_int, &default_value_int, 0, 1, _surf_cfg_cb_model_check, NULL);
264 xbt_cfg_register(&_surf_cfg_set, "gtnets_jitter",
265 "Double value to oscillate the link latency, uniformly in random interval [-latency*gtnets_jitter,latency*gtnets_jitter)", xbt_cfgelm_double,
266 NULL, 1, 1, _surf_cfg_cb__gtnets_jitter, NULL);
267 xbt_cfg_set_double(_surf_cfg_set, "gtnets_jitter", 0.0);
269 default_value_int = 10;
270 xbt_cfg_register(&_surf_cfg_set, "gtnets_jitter_seed",
271 "Use a positive seed to reproduce jitted results, value must be in [1,1e8], default is 10",
272 xbt_cfgelm_int, &default_value_int, 0, 1, _surf_cfg_cb__gtnets_jitter_seed, NULL);
276 /* retrieves the current directory of the current process */
277 const char *initial_path = __surf_get_initial_path();
278 xbt_assert0((initial_path),
279 "__surf_get_initial_path() failed! Can't resolves current Windows directory");
281 surf_path = xbt_dynar_new(sizeof(char *), NULL);
282 xbt_cfg_set_string(_surf_cfg_set, "path", initial_path);
286 surf_config_cmd_line(argc, argv);
288 WARN0("Call to surf_config_init() after initialization ignored");
292 void surf_config_finalize(void)
294 if (!_surf_init_status)
295 return; /* Not initialized yet. Nothing to do */
297 xbt_cfg_free(&_surf_cfg_set);
298 _surf_init_status = 0;
301 void surf_config_models_setup(const char *platform_file)
303 char *workstation_model_name;
304 int workstation_id = -1;
305 char *network_model_name = NULL;
306 char *cpu_model_name = NULL;
307 surf_timer_model_init(platform_file);
309 workstation_model_name =
310 xbt_cfg_get_string(_surf_cfg_set, "workstation/model");
311 network_model_name = xbt_cfg_get_string(_surf_cfg_set, "network/model");
312 cpu_model_name = xbt_cfg_get_string(_surf_cfg_set, "cpu/model");
314 /* Check whether we use a net/cpu model differing from the default ones, in which case
315 * we should switch to the "compound" workstation model to correctly dispatch stuff to
316 * the right net/cpu models.
318 if ((strcmp(network_model_name,"LV08") || strcmp(cpu_model_name,"Cas01"))
319 && !strcmp(workstation_model_name, "CLM03")){
320 const char *val = "compound";
321 INFO0("Switching workstation model to compound since you changed the network and/or cpu model(s)");
322 xbt_cfg_set_string(_surf_cfg_set,"workstation/model",val);
323 workstation_model_name = (char*)"compound";
326 DEBUG1("Workstation model: %s", workstation_model_name);
328 find_model_description(surf_workstation_model_description,
329 workstation_model_name);
330 if (!strcmp(workstation_model_name, "compound")) {
334 xbt_assert0(cpu_model_name,
335 "Set a cpu model to use with the 'compound' workstation model");
337 xbt_assert0(network_model_name,
338 "Set a network model to use with the 'compound' workstation model");
341 find_model_description(surf_network_model_description,
344 find_model_description(surf_cpu_model_description, cpu_model_name);
346 surf_cpu_model_description[cpu_id].model_init_preparse(platform_file);
347 surf_network_model_description[network_id].
348 model_init_preparse(platform_file);
351 DEBUG0("Call workstation_model_init");
352 surf_workstation_model_description[workstation_id].model_init_preparse
356 void surf_config_models_create_elms(void)
358 char *workstation_model_name =
359 xbt_cfg_get_string(_surf_cfg_set, "workstation/model");
361 find_model_description(surf_workstation_model_description,
362 workstation_model_name);
363 if (surf_workstation_model_description[workstation_id].
364 model_init_postparse != NULL)
365 surf_workstation_model_description[workstation_id].model_init_postparse();