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);
40 if (remove_it) { /*remove this from argv */
41 for (j = i + 1; j < *argc; j++) {
42 argv[j - 1] = argv[j];
47 i--; /* compensate effect of next loop incrementation */
53 int _surf_init_status = 0; /* 0: beginning of time;
54 1: pre-inited (cfg_set created);
55 2: inited (running) */
57 /* callback of the workstation/model variable */
58 static void _surf_cfg_cb__workstation_model(const char *name, int pos)
62 xbt_assert0(_surf_init_status < 2,
63 "Cannot change the model after the initialization");
65 val = xbt_cfg_get_string(_surf_cfg_set, name);
67 if (!strcmp(val,"help"))
68 model_help("workstation",surf_workstation_model_description);
70 /* Make sure that the model exists */
71 find_model_description(surf_workstation_model_description, val);
74 /* callback of the cpu/model variable */
75 static void _surf_cfg_cb__cpu_model(const char *name, int pos)
79 xbt_assert0(_surf_init_status < 2,
80 "Cannot change the model after the initialization");
82 val = xbt_cfg_get_string(_surf_cfg_set, name);
84 if (!strcmp(val,"help"))
85 model_help("CPU",surf_cpu_model_description);
87 /* New Module missing */
88 find_model_description(surf_cpu_model_description, val);
91 /* callback of the workstation_model variable */
92 static void _surf_cfg_cb__network_model(const char *name, int pos)
96 xbt_assert0(_surf_init_status < 2,
97 "Cannot change the model after the initialization");
99 val = xbt_cfg_get_string(_surf_cfg_set, name);
101 if (!strcmp(val,"help"))
102 model_help("network",surf_network_model_description);
104 /* New Module missing */
105 find_model_description(surf_network_model_description, val);
109 /* callbacks of the network models values */
110 static void _surf_cfg_cb__tcp_gamma(const char *name, int pos) {
111 sg_tcp_gamma = xbt_cfg_get_double(_surf_cfg_set, name);
113 static void _surf_cfg_cb__latency_factor(const char *name, int pos) {
114 sg_latency_factor = xbt_cfg_get_double(_surf_cfg_set, name);
116 static void _surf_cfg_cb__bandwidth_factor(const char *name, int pos) {
117 sg_bandwidth_factor = xbt_cfg_get_double(_surf_cfg_set, name);
119 static void _surf_cfg_cb__weight_S(const char *name, int pos) {
120 sg_weight_S_parameter = xbt_cfg_get_double(_surf_cfg_set, name);
122 static void _surf_cfg_cb__surf_maxmin_selective_update(const char *name, int pos) {
123 sg_maxmin_selective_update = xbt_cfg_get_int(_surf_cfg_set, name);
126 /* callback of the inclusion path */
127 static void _surf_cfg_cb__surf_path(const char *name, int pos) {
128 char *path = xbt_cfg_get_string_at(_surf_cfg_set, name, pos);
129 xbt_dynar_push(surf_path, &path);
134 static void _surf_cfg_cb__gtnets_jitter(const char *name, int pos){
135 sg_gtnets_jitter = xbt_cfg_get_double(_surf_cfg_set, name);
137 static void _surf_cfg_cb__gtnets_jitter_seed(const char *name, int pos){
138 sg_gtnets_jitter_seed = xbt_cfg_get_int(_surf_cfg_set, name);
142 /* create the config set, register what should be and parse the command line*/
143 void surf_config_init(int *argc, char **argv)
146 /* Create the configuration support */
147 if (_surf_init_status == 0) { /* Only create stuff if not already inited */
148 _surf_init_status = 1;
150 char *description = xbt_malloc(1024), *p = description;
152 double double_default_value;
153 int default_value_int;
156 sprintf(description, "The model to use for the CPU. Possible values: ");
158 while (*(++p) != '\0');
159 for (i = 0; surf_cpu_model_description[i].name; i++)
161 sprintf(p, "%s%s", (i == 0 ? "" : ", "),
162 surf_cpu_model_description[i].name);
163 sprintf(p,".\n (use 'help' as a value to see the long description of each model)");
164 default_value = xbt_strdup("Cas01");
165 xbt_cfg_register(&_surf_cfg_set,
166 "cpu/model", description, xbt_cfgelm_string,
167 &default_value, 1, 1, &_surf_cfg_cb__cpu_model, NULL);
170 "The model to use for the network. Possible values: ");
172 while (*(++p) != '\0');
173 for (i = 0; surf_network_model_description[i].name; i++)
175 sprintf(p, "%s%s", (i == 0 ? "" : ", "),
176 surf_network_model_description[i].name);
177 sprintf(p,".\n (use 'help' as a value to see the long description of each model)");
178 default_value = xbt_strdup("LV08");
179 xbt_cfg_register(&_surf_cfg_set,
180 "network/model", description, xbt_cfgelm_string,
181 &default_value, 1, 1, &_surf_cfg_cb__network_model,
185 "The model to use for the workstation. Possible values: ");
187 while (*(++p) != '\0');
188 for (i = 0; surf_workstation_model_description[i].name; i++)
190 sprintf(p, "%s%s", (i == 0 ? "" : ", "),
191 surf_workstation_model_description[i].name);
192 sprintf(p,".\n (use 'help' as a value to see the long description of each model)");
193 default_value = xbt_strdup("CLM03");
194 xbt_cfg_register(&_surf_cfg_set,
195 "workstation/model", description, xbt_cfgelm_string,
196 &default_value, 1, 1, &_surf_cfg_cb__workstation_model,
199 xbt_free(description);
201 default_value = xbt_strdup("Full");
202 xbt_cfg_register(&_surf_cfg_set, "routing",
203 "Model to use to store the routing information",
204 xbt_cfgelm_string, &default_value, 1, 1, NULL, NULL);
206 xbt_cfg_register(&_surf_cfg_set, "TCP_gamma",
207 "Size of the biggest TCP window (cat /proc/sys/net/ipv4/tcp_[rw]mem for recv/send window; middle value=default value => you probably want default send value)",
208 xbt_cfgelm_double, NULL, 1, 1, _surf_cfg_cb__tcp_gamma, NULL);
209 xbt_cfg_set_double(_surf_cfg_set, "TCP_gamma", 20000.0);
211 /* The parameters of network models */
212 double_default_value = 1.0;
213 xbt_cfg_register(&_surf_cfg_set, "network/latency_factor",
214 "Correction factor to apply to the provided latency (default value set by network model)",
215 xbt_cfgelm_double, &double_default_value, 1, 1, _surf_cfg_cb__latency_factor, NULL);
216 double_default_value = 1.0;
217 xbt_cfg_register(&_surf_cfg_set, "network/bandwidth_factor",
218 "Correction factor to apply to the provided bandwidth (default value set by network model)",
219 xbt_cfgelm_double, &double_default_value, 1, 1, _surf_cfg_cb__bandwidth_factor, NULL);
220 double_default_value = 0.0;
221 xbt_cfg_register(&_surf_cfg_set, "network/weight_S",
222 "Correction factor to apply to the weight of competing streams(default value set by network model)",
223 xbt_cfgelm_double, &double_default_value, 1, 1, _surf_cfg_cb__weight_S, NULL);
226 xbt_cfg_register(&_surf_cfg_set, "path",
227 "Lookup path for inclusions in platform and deployment XML files",
228 xbt_cfgelm_string, NULL, 0, 0, _surf_cfg_cb__surf_path,
231 default_value_int = 0;
232 xbt_cfg_register(&_surf_cfg_set, "maxmin_selective_update",
233 "Update the constraint set propagating recursively to others constraints",
234 xbt_cfgelm_int, &default_value_int, 0, 1, _surf_cfg_cb__surf_maxmin_selective_update, NULL);
237 xbt_cfg_register(&_surf_cfg_set, "gtnets_jitter",
238 "Double value to oscillate the link latency, uniformly in random interval [-latency*gtnets_jitter,latency*gtnets_jitter)", xbt_cfgelm_double,
239 NULL, 1, 1, _surf_cfg_cb__gtnets_jitter, NULL);
240 xbt_cfg_set_double(_surf_cfg_set, "gtnets_jitter", 0.0);
242 default_value_int = 10;
243 xbt_cfg_register(&_surf_cfg_set, "gtnets_jitter_seed",
244 "Use a positive seed to reproduce jitted results, value must be in [1,1e8], default is 10",
245 xbt_cfgelm_int, &default_value_int, 0, 1, _surf_cfg_cb__gtnets_jitter_seed, NULL);
249 /* retrieves the current directory of the current process */
250 const char *initial_path = __surf_get_initial_path();
251 xbt_assert0((initial_path),
252 "__surf_get_initial_path() failed! Can't resolves current Windows directory");
254 surf_path = xbt_dynar_new(sizeof(char *), NULL);
255 xbt_cfg_set_string(_surf_cfg_set, "path", initial_path);
259 surf_config_cmd_line(argc, argv);
261 WARN0("Call to surf_config_init() after initialization ignored");
265 void surf_config_finalize(void)
267 if (!_surf_init_status)
268 return; /* Not initialized yet. Nothing to do */
270 xbt_cfg_free(&_surf_cfg_set);
271 _surf_init_status = 0;
274 void surf_config_models_setup(const char *platform_file)
276 char *workstation_model_name;
277 int workstation_id = -1;
279 surf_timer_model_init(platform_file);
281 workstation_model_name =
282 xbt_cfg_get_string(_surf_cfg_set, "workstation/model");
283 char *network_model_name = xbt_cfg_get_string(_surf_cfg_set, "network/model");
284 char *cpu_model_name = xbt_cfg_get_string(_surf_cfg_set, "cpu/model");
286 if ((strcmp(network_model_name,"LV08") || strcmp(cpu_model_name,"Cas01"))
287 && !strcmp(workstation_model_name, "CLM03")){
288 const char *val = "compound";
289 INFO0("Switching workstation model to compound since you changed the network and/or cpu model(s)");
290 xbt_cfg_set_string(_surf_cfg_set,"workstation/model",val);
291 workstation_model_name = (char*)"compound";
294 DEBUG1("Workstation model: %s", workstation_model_name);
296 find_model_description(surf_workstation_model_description,
297 workstation_model_name);
298 if (!strcmp(workstation_model_name, "compound")) {
302 xbt_assert0(cpu_model_name,
303 "Set a cpu model to use with the 'compound' workstation model");
305 xbt_assert0(network_model_name,
306 "Set a network model to use with the 'compound' workstation model");
309 find_model_description(surf_network_model_description,
312 find_model_description(surf_cpu_model_description, cpu_model_name);
314 surf_cpu_model_description[cpu_id].model_init_preparse(platform_file);
315 surf_network_model_description[network_id].
316 model_init_preparse(platform_file);
319 DEBUG0("Call workstation_model_init");
320 surf_workstation_model_description[workstation_id].model_init_preparse
324 void surf_config_models_create_elms(void)
326 char *workstation_model_name =
327 xbt_cfg_get_string(_surf_cfg_set, "workstation/model");
329 find_model_description(surf_workstation_model_description,
330 workstation_model_name);
331 if (surf_workstation_model_description[workstation_id].
332 model_init_postparse != NULL)
333 surf_workstation_model_description[workstation_id].model_init_postparse();