1 /* Copyright (c) 2009-2010 The SimGrid team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 /* surf_config: configuration infrastructure for the simulation world */
8 #include "xbt/config.h"
10 #include "surf/surf_private.h"
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_config, surf,
13 "About the configuration of surf (and the rest of the simulation)");
15 xbt_cfg_t _surf_cfg_set = NULL;
18 /* Parse the command line, looking for options */
19 static void surf_config_cmd_line(int *argc, char **argv)
24 for (i = 1; i < *argc; i++) {
26 if (!strncmp(argv[i], "--cfg=", strlen("--cfg="))) {
27 opt = strchr(argv[i], '=');
30 xbt_cfg_set_parse(_surf_cfg_set, opt);
31 DEBUG1("Did apply '%s' as config setting", opt);
33 } else if (!strncmp(argv[i], "--cfg-help", strlen("--cfg-help") + 1) ||
34 !strncmp(argv[i], "--help", strlen("--help") + 1)) {
35 printf("Description of the configuration accepted by this simulator:\n");
36 xbt_cfg_help(_surf_cfg_set);
37 printf("\nYou can also use --help-models to see the details of all models known by this simulator.\n");
39 } else if (!strncmp(argv[i], "--help-models", strlen("--help-models")+1)) {
40 model_help("workstation",surf_workstation_model_description);
41 model_help("CPU",surf_cpu_model_description);
42 model_help("network",surf_network_model_description);
45 if (remove_it) { /*remove this from argv */
46 for (j = i + 1; j < *argc; j++) {
47 argv[j - 1] = argv[j];
52 i--; /* compensate effect of next loop incrementation */
58 int _surf_init_status = 0; /* 0: beginning of time;
59 1: pre-inited (cfg_set created);
60 2: inited (running) */
62 /* callback of the workstation/model variable */
63 static void _surf_cfg_cb__workstation_model(const char *name, int pos)
67 xbt_assert0(_surf_init_status < 2,
68 "Cannot change the model after the initialization");
70 val = xbt_cfg_get_string(_surf_cfg_set, name);
72 if (!strcmp(val,"help")) {
73 model_help("workstation",surf_workstation_model_description);
77 /* Make sure that the model exists */
78 find_model_description(surf_workstation_model_description, val);
81 /* callback of the cpu/model variable */
82 static void _surf_cfg_cb__cpu_model(const char *name, int pos)
86 xbt_assert0(_surf_init_status < 2,
87 "Cannot change the model after the initialization");
89 val = xbt_cfg_get_string(_surf_cfg_set, name);
91 if (!strcmp(val,"help")) {
92 model_help("CPU",surf_cpu_model_description);
96 /* New Module missing */
97 find_model_description(surf_cpu_model_description, val);
100 /* callback of the workstation_model variable */
101 static void _surf_cfg_cb__network_model(const char *name, int pos)
105 xbt_assert0(_surf_init_status < 2,
106 "Cannot change the model after the initialization");
108 val = xbt_cfg_get_string(_surf_cfg_set, name);
110 if (!strcmp(val,"help")) {
111 model_help("network",surf_network_model_description);
115 /* New Module missing */
116 find_model_description(surf_network_model_description, val);
120 /* callbacks of the network models values */
121 static void _surf_cfg_cb__tcp_gamma(const char *name, int pos) {
122 sg_tcp_gamma = xbt_cfg_get_double(_surf_cfg_set, name);
124 static void _surf_cfg_cb__latency_factor(const char *name, int pos) {
125 sg_latency_factor = xbt_cfg_get_double(_surf_cfg_set, name);
127 static void _surf_cfg_cb__bandwidth_factor(const char *name, int pos) {
128 sg_bandwidth_factor = xbt_cfg_get_double(_surf_cfg_set, name);
130 static void _surf_cfg_cb__weight_S(const char *name, int pos) {
131 sg_weight_S_parameter = xbt_cfg_get_double(_surf_cfg_set, name);
133 static void _surf_cfg_cb__surf_maxmin_selective_update(const char *name, int pos) {
134 sg_maxmin_selective_update = xbt_cfg_get_int(_surf_cfg_set, name);
137 /* callback of the inclusion path */
138 static void _surf_cfg_cb__surf_path(const char *name, int pos) {
139 char *path = xbt_cfg_get_string_at(_surf_cfg_set, name, pos);
140 xbt_dynar_push(surf_path, &path);
145 static void _surf_cfg_cb__gtnets_jitter(const char *name, int pos){
146 sg_gtnets_jitter = xbt_cfg_get_double(_surf_cfg_set, name);
148 static void _surf_cfg_cb__gtnets_jitter_seed(const char *name, int pos){
149 sg_gtnets_jitter_seed = xbt_cfg_get_int(_surf_cfg_set, name);
153 /* create the config set, register what should be and parse the command line*/
154 void surf_config_init(int *argc, char **argv)
157 /* Create the configuration support */
158 if (_surf_init_status == 0) { /* Only create stuff if not already inited */
159 _surf_init_status = 1;
161 char *description = xbt_malloc(1024), *p = description;
163 double double_default_value;
164 int default_value_int;
167 sprintf(description, "The model to use for the CPU. Possible values: ");
169 while (*(++p) != '\0');
170 for (i = 0; surf_cpu_model_description[i].name; i++)
172 sprintf(p, "%s%s", (i == 0 ? "" : ", "),
173 surf_cpu_model_description[i].name);
174 sprintf(p,".\n (use 'help' as a value to see the long description of each model)");
175 default_value = xbt_strdup("Cas01");
176 xbt_cfg_register(&_surf_cfg_set,
177 "cpu/model", description, xbt_cfgelm_string,
178 &default_value, 1, 1, &_surf_cfg_cb__cpu_model, NULL);
181 "The model to use for the network. Possible values: ");
183 while (*(++p) != '\0');
184 for (i = 0; surf_network_model_description[i].name; i++)
186 sprintf(p, "%s%s", (i == 0 ? "" : ", "),
187 surf_network_model_description[i].name);
188 sprintf(p,".\n (use 'help' as a value to see the long description of each model)");
189 default_value = xbt_strdup("LV08");
190 xbt_cfg_register(&_surf_cfg_set,
191 "network/model", description, xbt_cfgelm_string,
192 &default_value, 1, 1, &_surf_cfg_cb__network_model,
196 "The model to use for the workstation. Possible values: ");
198 while (*(++p) != '\0');
199 for (i = 0; surf_workstation_model_description[i].name; i++)
201 sprintf(p, "%s%s", (i == 0 ? "" : ", "),
202 surf_workstation_model_description[i].name);
203 sprintf(p,".\n (use 'help' as a value to see the long description of each model)");
204 default_value = xbt_strdup("CLM03");
205 xbt_cfg_register(&_surf_cfg_set,
206 "workstation/model", description, xbt_cfgelm_string,
207 &default_value, 1, 1, &_surf_cfg_cb__workstation_model,
210 xbt_free(description);
212 default_value = xbt_strdup("Full");
213 xbt_cfg_register(&_surf_cfg_set, "routing",
214 "Model to use to store the routing information",
215 xbt_cfgelm_string, &default_value, 1, 1, NULL, NULL);
217 xbt_cfg_register(&_surf_cfg_set, "TCP_gamma",
218 "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)",
219 xbt_cfgelm_double, NULL, 1, 1, _surf_cfg_cb__tcp_gamma, NULL);
220 xbt_cfg_set_double(_surf_cfg_set, "TCP_gamma", 20000.0);
222 /* The parameters of network models */
223 double_default_value = 1.0;
224 xbt_cfg_register(&_surf_cfg_set, "network/latency_factor",
225 "Correction factor to apply to the provided latency (default value set by network model)",
226 xbt_cfgelm_double, &double_default_value, 1, 1, _surf_cfg_cb__latency_factor, NULL);
227 double_default_value = 1.0;
228 xbt_cfg_register(&_surf_cfg_set, "network/bandwidth_factor",
229 "Correction factor to apply to the provided bandwidth (default value set by network model)",
230 xbt_cfgelm_double, &double_default_value, 1, 1, _surf_cfg_cb__bandwidth_factor, NULL);
231 double_default_value = 0.0;
232 xbt_cfg_register(&_surf_cfg_set, "network/weight_S",
233 "Correction factor to apply to the weight of competing streams(default value set by network model)",
234 xbt_cfgelm_double, &double_default_value, 1, 1, _surf_cfg_cb__weight_S, NULL);
237 xbt_cfg_register(&_surf_cfg_set, "path",
238 "Lookup path for inclusions in platform and deployment XML files",
239 xbt_cfgelm_string, NULL, 0, 0, _surf_cfg_cb__surf_path,
242 default_value_int = 0;
243 xbt_cfg_register(&_surf_cfg_set, "maxmin_selective_update",
244 "Update the constraint set propagating recursively to others constraints",
245 xbt_cfgelm_int, &default_value_int, 0, 1, _surf_cfg_cb__surf_maxmin_selective_update, NULL);
248 xbt_cfg_register(&_surf_cfg_set, "gtnets_jitter",
249 "Double value to oscillate the link latency, uniformly in random interval [-latency*gtnets_jitter,latency*gtnets_jitter)", xbt_cfgelm_double,
250 NULL, 1, 1, _surf_cfg_cb__gtnets_jitter, NULL);
251 xbt_cfg_set_double(_surf_cfg_set, "gtnets_jitter", 0.0);
253 default_value_int = 10;
254 xbt_cfg_register(&_surf_cfg_set, "gtnets_jitter_seed",
255 "Use a positive seed to reproduce jitted results, value must be in [1,1e8], default is 10",
256 xbt_cfgelm_int, &default_value_int, 0, 1, _surf_cfg_cb__gtnets_jitter_seed, NULL);
260 /* retrieves the current directory of the current process */
261 const char *initial_path = __surf_get_initial_path();
262 xbt_assert0((initial_path),
263 "__surf_get_initial_path() failed! Can't resolves current Windows directory");
265 surf_path = xbt_dynar_new(sizeof(char *), NULL);
266 xbt_cfg_set_string(_surf_cfg_set, "path", initial_path);
270 surf_config_cmd_line(argc, argv);
272 WARN0("Call to surf_config_init() after initialization ignored");
276 void surf_config_finalize(void)
278 if (!_surf_init_status)
279 return; /* Not initialized yet. Nothing to do */
281 xbt_cfg_free(&_surf_cfg_set);
282 _surf_init_status = 0;
285 void surf_config_models_setup(const char *platform_file)
287 char *workstation_model_name;
288 int workstation_id = -1;
290 surf_timer_model_init(platform_file);
292 workstation_model_name =
293 xbt_cfg_get_string(_surf_cfg_set, "workstation/model");
294 char *network_model_name = xbt_cfg_get_string(_surf_cfg_set, "network/model");
295 char *cpu_model_name = xbt_cfg_get_string(_surf_cfg_set, "cpu/model");
297 if ((strcmp(network_model_name,"LV08") || strcmp(cpu_model_name,"Cas01"))
298 && !strcmp(workstation_model_name, "CLM03")){
299 const char *val = "compound";
300 INFO0("Switching workstation model to compound since you changed the network and/or cpu model(s)");
301 xbt_cfg_set_string(_surf_cfg_set,"workstation/model",val);
302 workstation_model_name = (char*)"compound";
305 DEBUG1("Workstation model: %s", workstation_model_name);
307 find_model_description(surf_workstation_model_description,
308 workstation_model_name);
309 if (!strcmp(workstation_model_name, "compound")) {
313 xbt_assert0(cpu_model_name,
314 "Set a cpu model to use with the 'compound' workstation model");
316 xbt_assert0(network_model_name,
317 "Set a network model to use with the 'compound' workstation model");
320 find_model_description(surf_network_model_description,
323 find_model_description(surf_cpu_model_description, cpu_model_name);
325 surf_cpu_model_description[cpu_id].model_init_preparse(platform_file);
326 surf_network_model_description[network_id].
327 model_init_preparse(platform_file);
330 DEBUG0("Call workstation_model_init");
331 surf_workstation_model_description[workstation_id].model_init_preparse
335 void surf_config_models_create_elms(void)
337 char *workstation_model_name =
338 xbt_cfg_get_string(_surf_cfg_set, "workstation/model");
340 find_model_description(surf_workstation_model_description,
341 workstation_model_name);
342 if (surf_workstation_model_description[workstation_id].
343 model_init_postparse != NULL)
344 surf_workstation_model_description[workstation_id].model_init_postparse();