3 /* Copyright (c) 2009 The SimGrid team. All rights reserved. */
5 /* This program is free software; you can redistribute it and/or modify it
6 * under the terms of the license (GNU LGPL) which comes with this package. */
8 /* surf_config: configuration infrastructure for the simulation world */
10 #include "xbt/config.h"
12 #include "surf/surf_private.h"
14 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_config, surf,
15 "About the configuration of surf (and the rest of the simulation)");
17 xbt_cfg_t _surf_cfg_set = NULL;
19 extern double sg_gtnets_jitter;
22 /* Parse the command line, looking for options */
23 static void surf_config_cmd_line(int *argc, char **argv)
28 for (i = 1; i < *argc; i++) {
30 if (!strncmp(argv[i], "--cfg=", strlen("--cfg="))) {
31 opt = strchr(argv[i], '=');
34 xbt_cfg_set_parse(_surf_cfg_set, opt);
35 DEBUG1("Did apply '%s' as config setting", opt);
37 } else if (!strncmp(argv[i], "--cfg-help", strlen("--cfg-help") + 1) ||
38 !strncmp(argv[i], "--help", strlen("--help") + 1)) {
40 ("Description of the configuration accepted by this simulator:\n");
41 xbt_cfg_help(_surf_cfg_set);
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);
71 /* New Module missing */
73 find_model_description(surf_workstation_model_description, val);
76 /* callback of the cpu_model variable */
77 static void _surf_cfg_cb__cpu_model(const char *name, int pos)
81 xbt_assert0(_surf_init_status < 2,
82 "Cannot change the model after the initialization");
84 val = xbt_cfg_get_string(_surf_cfg_set, name);
85 /* New Module missing */
86 find_model_description(surf_cpu_model_description, val);
89 /* callback of the workstation_model variable */
90 static void _surf_cfg_cb__network_model(const char *name, int pos)
94 xbt_assert0(_surf_init_status < 2,
95 "Cannot change the model after the initialization");
97 val = xbt_cfg_get_string(_surf_cfg_set, name);
98 /* New Module missing */
99 find_model_description(surf_network_model_description, val);
102 /* callback of the tcp gamma variable */
103 static void _surf_cfg_cb__tcp_gamma(const char *name, int pos)
105 sg_tcp_gamma = xbt_cfg_get_double(_surf_cfg_set, name);
108 static void _surf_cfg_cb__surf_path(const char *name, int pos)
110 char *path = xbt_cfg_get_string_at(_surf_cfg_set, name, pos);
111 xbt_dynar_push(surf_path, &path);
114 static void _surf_cfg_cb__surf_maxmin_selective_update(const char *name, int pos)
116 sg_maxmin_selective_update = xbt_cfg_get_int(_surf_cfg_set, name);
120 static void _surf_cfg_cb__gtnets_jitter(const char *name, int pos){
121 sg_gtnets_jitter = xbt_cfg_get_double(_surf_cfg_set, name);
125 /* create the config set, register what should be and parse the command line*/
126 void surf_config_init(int *argc, char **argv)
129 /* Create the configuration support */
130 if (_surf_init_status == 0) { /* Only create stuff if not already inited */
131 _surf_init_status = 1;
133 char *description = xbt_malloc(1024), *p = description;
135 int default_value_int;
138 sprintf(description, "The model to use for the CPU. Possible values: ");
140 while (*(++p) != '\0');
141 for (i = 0; surf_cpu_model_description[i].name; i++)
143 sprintf(p, "%s%s", (i == 0 ? "" : ", "),
144 surf_cpu_model_description[i].name);
145 default_value = xbt_strdup("Cas01");
146 xbt_cfg_register(&_surf_cfg_set,
147 "cpu_model", description, xbt_cfgelm_string,
148 &default_value, 1, 1, &_surf_cfg_cb__cpu_model, NULL);
151 "The model to use for the network. Possible values: ");
153 while (*(++p) != '\0');
154 for (i = 0; surf_network_model_description[i].name; i++)
156 sprintf(p, "%s%s", (i == 0 ? "" : ", "),
157 surf_network_model_description[i].name);
158 default_value = xbt_strdup("LV08");
159 xbt_cfg_register(&_surf_cfg_set,
160 "network_model", description, xbt_cfgelm_string,
161 &default_value, 1, 1, &_surf_cfg_cb__network_model,
165 "The model to use for the workstation. Possible values: ");
167 while (*(++p) != '\0');
168 for (i = 0; surf_workstation_model_description[i].name; i++)
170 sprintf(p, "%s%s", (i == 0 ? "" : ", "),
171 surf_workstation_model_description[i].name);
172 default_value = xbt_strdup("CLM03");
173 xbt_cfg_register(&_surf_cfg_set,
174 "workstation_model", description, xbt_cfgelm_string,
175 &default_value, 1, 1, &_surf_cfg_cb__workstation_model,
178 xbt_free(description);
180 default_value = xbt_strdup("Full");
181 xbt_cfg_register(&_surf_cfg_set, "routing",
182 "Model to use to store the routing information",
183 xbt_cfgelm_string, &default_value, 1, 1, NULL,
186 xbt_cfg_register(&_surf_cfg_set, "TCP_gamma",
187 "Size of the biggest TCP window", xbt_cfgelm_double,
188 NULL, 1, 1, _surf_cfg_cb__tcp_gamma, NULL);
189 xbt_cfg_set_double(_surf_cfg_set, "TCP_gamma", 20000.0);
191 xbt_cfg_register(&_surf_cfg_set, "path",
192 "Lookup path for inclusions in platform and deployment XML files",
193 xbt_cfgelm_string, NULL, 0, 0, _surf_cfg_cb__surf_path,
196 default_value_int = 0;
197 xbt_cfg_register(&_surf_cfg_set, "maxmin_selective_update",
198 "Update the constraint set propagating recursively to others constraints",
199 xbt_cfgelm_int, &default_value_int, 0, 1, _surf_cfg_cb__surf_maxmin_selective_update, NULL);
202 xbt_cfg_register(&_surf_cfg_set, "gtnets_jitter",
203 "Double value to oscillate the link latency, uniformly in random interval [-latency*gtnets_jitter,latency*gtnets_jitter)", xbt_cfgelm_double,
204 NULL, 1, 1, _surf_cfg_cb__gtnets_jitter, NULL);
205 xbt_cfg_set_double(_surf_cfg_set, "gtnets_jitter", 0.0);
209 /* retrieves the current directory of the current process */
210 const char *initial_path = __surf_get_initial_path();
211 xbt_assert0((initial_path),
212 "__surf_get_initial_path() failed! Can't resolves current Windows directory");
214 surf_path = xbt_dynar_new(sizeof(char *), NULL);
215 xbt_cfg_set_string(_surf_cfg_set, "path", initial_path);
219 surf_config_cmd_line(argc, argv);
223 void surf_config_finalize(void)
225 if (!_surf_init_status)
226 return; /* Not initialized yet. Nothing to do */
228 xbt_cfg_free(&_surf_cfg_set);
229 _surf_init_status = 0;
232 void surf_config_models_setup(const char *platform_file)
234 char *workstation_model_name;
235 int workstation_id = -1;
237 surf_timer_model_init(platform_file);
239 workstation_model_name =
240 xbt_cfg_get_string(_surf_cfg_set, "workstation_model");
241 char *network_model_name = xbt_cfg_get_string(_surf_cfg_set, "network_model");
242 char *cpu_model_name = xbt_cfg_get_string(_surf_cfg_set, "cpu_model");
244 if ((strcmp(network_model_name,"LV08") || strcmp(cpu_model_name,"Cas01"))
245 && !strcmp(workstation_model_name, "CLM03")){
246 const char *val = "compound";
247 INFO0("Switching workstation model to compound since you changed the network and/or cpu model(s)");
248 xbt_cfg_set_string(_surf_cfg_set,"workstation_model",val);
249 workstation_model_name = (char*)"compound";
252 DEBUG1("Workstation model: %s", workstation_model_name);
254 find_model_description(surf_workstation_model_description,
255 workstation_model_name);
256 if (!strcmp(workstation_model_name, "compound")) {
260 xbt_assert0(cpu_model_name,
261 "Set a cpu model to use with the 'compound' workstation model");
263 xbt_assert0(network_model_name,
264 "Set a network model to use with the 'compound' workstation model");
267 find_model_description(surf_network_model_description,
270 find_model_description(surf_cpu_model_description, cpu_model_name);
272 surf_cpu_model_description[cpu_id].model_init_preparse(platform_file);
273 surf_network_model_description[network_id].
274 model_init_preparse(platform_file);
277 DEBUG0("Call workstation_model_init");
278 surf_workstation_model_description[workstation_id].model_init_preparse
282 void surf_config_models_create_elms(void)
284 char *workstation_model_name =
285 xbt_cfg_get_string(_surf_cfg_set, "workstation_model");
287 find_model_description(surf_workstation_model_description,
288 workstation_model_name);
289 if (surf_workstation_model_description[workstation_id].
290 model_init_postparse != NULL)
291 surf_workstation_model_description[workstation_id].model_init_postparse();