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)) {
36 ("Description of the configuration accepted by this simulator:\n");
37 xbt_cfg_help(_surf_cfg_set);
41 if (remove_it) { /*remove this from argv */
42 for (j = i + 1; j < *argc; j++) {
43 argv[j - 1] = argv[j];
48 i--; /* compensate effect of next loop incrementation */
54 int _surf_init_status = 0; /* 0: beginning of time;
55 1: pre-inited (cfg_set created);
56 2: inited (running) */
58 /* callback of the workstation/model variable */
59 static void _surf_cfg_cb__workstation_model(const char *name, int pos)
63 xbt_assert0(_surf_init_status < 2,
64 "Cannot change the model after the initialization");
66 val = xbt_cfg_get_string(_surf_cfg_set, name);
67 /* New Module missing */
69 find_model_description(surf_workstation_model_description, val);
72 /* callback of the cpu/model variable */
73 static void _surf_cfg_cb__cpu_model(const char *name, int pos)
77 xbt_assert0(_surf_init_status < 2,
78 "Cannot change the model after the initialization");
80 val = xbt_cfg_get_string(_surf_cfg_set, name);
81 /* New Module missing */
82 find_model_description(surf_cpu_model_description, val);
85 /* callback of the workstation_model variable */
86 static void _surf_cfg_cb__network_model(const char *name, int pos)
90 xbt_assert0(_surf_init_status < 2,
91 "Cannot change the model after the initialization");
93 val = xbt_cfg_get_string(_surf_cfg_set, name);
94 /* New Module missing */
95 find_model_description(surf_network_model_description, val);
99 /* callbacks of the network models values */
100 static void _surf_cfg_cb__tcp_gamma(const char *name, int pos) {
101 sg_tcp_gamma = xbt_cfg_get_double(_surf_cfg_set, name);
103 static void _surf_cfg_cb__latency_factor(const char *name, int pos) {
104 sg_latency_factor = xbt_cfg_get_double(_surf_cfg_set, name);
106 static void _surf_cfg_cb__bandwidth_factor(const char *name, int pos) {
107 sg_bandwidth_factor = xbt_cfg_get_double(_surf_cfg_set, name);
109 static void _surf_cfg_cb__weight_S(const char *name, int pos) {
110 sg_weight_S_parameter = xbt_cfg_get_double(_surf_cfg_set, name);
112 static void _surf_cfg_cb__surf_maxmin_selective_update(const char *name, int pos) {
113 sg_maxmin_selective_update = xbt_cfg_get_int(_surf_cfg_set, name);
116 /* callback of the inclusion path */
117 static void _surf_cfg_cb__surf_path(const char *name, int pos) {
118 char *path = xbt_cfg_get_string_at(_surf_cfg_set, name, pos);
119 xbt_dynar_push(surf_path, &path);
124 static void _surf_cfg_cb__gtnets_jitter(const char *name, int pos){
125 sg_gtnets_jitter = xbt_cfg_get_double(_surf_cfg_set, name);
127 static void _surf_cfg_cb__gtnets_jitter_seed(const char *name, int pos){
128 sg_gtnets_jitter_seed = xbt_cfg_get_int(_surf_cfg_set, name);
132 /* create the config set, register what should be and parse the command line*/
133 void surf_config_init(int *argc, char **argv)
136 /* Create the configuration support */
137 if (_surf_init_status == 0) { /* Only create stuff if not already inited */
138 _surf_init_status = 1;
140 char *description = xbt_malloc(1024), *p = description;
142 double double_default_value;
143 int default_value_int;
146 sprintf(description, "The model to use for the CPU. Possible values: ");
148 while (*(++p) != '\0');
149 for (i = 0; surf_cpu_model_description[i].name; i++)
151 sprintf(p, "%s%s", (i == 0 ? "" : ", "),
152 surf_cpu_model_description[i].name);
153 default_value = xbt_strdup("Cas01");
154 xbt_cfg_register(&_surf_cfg_set,
155 "cpu/model", description, xbt_cfgelm_string,
156 &default_value, 1, 1, &_surf_cfg_cb__cpu_model, NULL);
159 "The model to use for the network. Possible values: ");
161 while (*(++p) != '\0');
162 for (i = 0; surf_network_model_description[i].name; i++)
164 sprintf(p, "%s%s", (i == 0 ? "" : ", "),
165 surf_network_model_description[i].name);
166 default_value = xbt_strdup("LV08");
167 xbt_cfg_register(&_surf_cfg_set,
168 "network/model", description, xbt_cfgelm_string,
169 &default_value, 1, 1, &_surf_cfg_cb__network_model,
173 "The model to use for the workstation. Possible values: ");
175 while (*(++p) != '\0');
176 for (i = 0; surf_workstation_model_description[i].name; i++)
178 sprintf(p, "%s%s", (i == 0 ? "" : ", "),
179 surf_workstation_model_description[i].name);
180 default_value = xbt_strdup("CLM03");
181 xbt_cfg_register(&_surf_cfg_set,
182 "workstation/model", description, xbt_cfgelm_string,
183 &default_value, 1, 1, &_surf_cfg_cb__workstation_model,
186 xbt_free(description);
188 default_value = xbt_strdup("Full");
189 xbt_cfg_register(&_surf_cfg_set, "routing",
190 "Model to use to store the routing information",
191 xbt_cfgelm_string, &default_value, 1, 1, NULL, NULL);
193 xbt_cfg_register(&_surf_cfg_set, "TCP_gamma",
194 "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)",
195 xbt_cfgelm_double, NULL, 1, 1, _surf_cfg_cb__tcp_gamma, NULL);
196 xbt_cfg_set_double(_surf_cfg_set, "TCP_gamma", 20000.0);
198 /* The parameters of network models */
199 double_default_value = 1.0;
200 xbt_cfg_register(&_surf_cfg_set, "network/latency_factor",
201 "Correction factor to apply to the provided latency (default value set by network model)",
202 xbt_cfgelm_double, &double_default_value, 1, 1, _surf_cfg_cb__latency_factor, NULL);
203 double_default_value = 1.0;
204 xbt_cfg_register(&_surf_cfg_set, "network/bandwidth_factor",
205 "Correction factor to apply to the provided bandwidth (default value set by network model)",
206 xbt_cfgelm_double, &double_default_value, 1, 1, _surf_cfg_cb__bandwidth_factor, NULL);
207 double_default_value = 0.0;
208 xbt_cfg_register(&_surf_cfg_set, "network/weight_S",
209 "Correction factor to apply to the weight of competing streams(default value set by network model)",
210 xbt_cfgelm_double, &double_default_value, 1, 1, _surf_cfg_cb__weight_S, NULL);
213 xbt_cfg_register(&_surf_cfg_set, "path",
214 "Lookup path for inclusions in platform and deployment XML files",
215 xbt_cfgelm_string, NULL, 0, 0, _surf_cfg_cb__surf_path,
218 default_value_int = 0;
219 xbt_cfg_register(&_surf_cfg_set, "maxmin_selective_update",
220 "Update the constraint set propagating recursively to others constraints",
221 xbt_cfgelm_int, &default_value_int, 0, 1, _surf_cfg_cb__surf_maxmin_selective_update, NULL);
224 xbt_cfg_register(&_surf_cfg_set, "gtnets_jitter",
225 "Double value to oscillate the link latency, uniformly in random interval [-latency*gtnets_jitter,latency*gtnets_jitter)", xbt_cfgelm_double,
226 NULL, 1, 1, _surf_cfg_cb__gtnets_jitter, NULL);
227 xbt_cfg_set_double(_surf_cfg_set, "gtnets_jitter", 0.0);
229 default_value_int = 10;
230 xbt_cfg_register(&_surf_cfg_set, "gtnets_jitter_seed",
231 "Use a positive seed to reproduce jitted results, value must be in [1,1e8], default is 10",
232 xbt_cfgelm_int, &default_value_int, 0, 1, _surf_cfg_cb__gtnets_jitter_seed, NULL);
236 /* retrieves the current directory of the current process */
237 const char *initial_path = __surf_get_initial_path();
238 xbt_assert0((initial_path),
239 "__surf_get_initial_path() failed! Can't resolves current Windows directory");
241 surf_path = xbt_dynar_new(sizeof(char *), NULL);
242 xbt_cfg_set_string(_surf_cfg_set, "path", initial_path);
246 surf_config_cmd_line(argc, argv);
250 void surf_config_finalize(void)
252 if (!_surf_init_status)
253 return; /* Not initialized yet. Nothing to do */
255 xbt_cfg_free(&_surf_cfg_set);
256 _surf_init_status = 0;
259 void surf_config_models_setup(const char *platform_file)
261 char *workstation_model_name;
262 int workstation_id = -1;
264 surf_timer_model_init(platform_file);
266 workstation_model_name =
267 xbt_cfg_get_string(_surf_cfg_set, "workstation/model");
268 char *network_model_name = xbt_cfg_get_string(_surf_cfg_set, "network/model");
269 char *cpu_model_name = xbt_cfg_get_string(_surf_cfg_set, "cpu/model");
271 if ((strcmp(network_model_name,"LV08") || strcmp(cpu_model_name,"Cas01"))
272 && !strcmp(workstation_model_name, "CLM03")){
273 const char *val = "compound";
274 INFO0("Switching workstation model to compound since you changed the network and/or cpu model(s)");
275 xbt_cfg_set_string(_surf_cfg_set,"workstation/model",val);
276 workstation_model_name = (char*)"compound";
279 DEBUG1("Workstation model: %s", workstation_model_name);
281 find_model_description(surf_workstation_model_description,
282 workstation_model_name);
283 if (!strcmp(workstation_model_name, "compound")) {
287 xbt_assert0(cpu_model_name,
288 "Set a cpu model to use with the 'compound' workstation model");
290 xbt_assert0(network_model_name,
291 "Set a network model to use with the 'compound' workstation model");
294 find_model_description(surf_network_model_description,
297 find_model_description(surf_cpu_model_description, cpu_model_name);
299 surf_cpu_model_description[cpu_id].model_init_preparse(platform_file);
300 surf_network_model_description[network_id].
301 model_init_preparse(platform_file);
304 DEBUG0("Call workstation_model_init");
305 surf_workstation_model_description[workstation_id].model_init_preparse
309 void surf_config_models_create_elms(void)
311 char *workstation_model_name =
312 xbt_cfg_get_string(_surf_cfg_set, "workstation/model");
314 find_model_description(surf_workstation_model_description,
315 workstation_model_name);
316 if (surf_workstation_model_description[workstation_id].
317 model_init_postparse != NULL)
318 surf_workstation_model_description[workstation_id].model_init_postparse();