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;
20 /* Parse the command line, looking for options */
21 static void surf_config_cmd_line(int *argc, char **argv)
26 for (i = 1; i < *argc; i++) {
28 if (!strncmp(argv[i], "--cfg=", strlen("--cfg="))) {
29 opt = strchr(argv[i], '=');
32 xbt_cfg_set_parse(_surf_cfg_set, opt);
33 DEBUG1("Did apply '%s' as config setting", opt);
35 } else if (!strncmp(argv[i], "--cfg-help", strlen("--cfg-help") + 1) ||
36 !strncmp(argv[i], "--help", strlen("--help") + 1)) {
38 ("Description of the configuration accepted by this simulator:\n");
39 xbt_cfg_help(_surf_cfg_set);
43 if (remove_it) { /*remove this from argv */
44 for (j = i + 1; j < *argc; j++) {
45 argv[j - 1] = argv[j];
50 i--; /* compensate effect of next loop incrementation */
56 int _surf_init_status = 0; /* 0: beginning of time;
57 1: pre-inited (cfg_set created);
58 2: inited (running) */
60 /* callback of the workstation_model variable */
61 static void _surf_cfg_cb__workstation_model(const char *name, int pos)
65 xbt_assert0(_surf_init_status < 2,
66 "Cannot change the model after the initialization");
68 val = xbt_cfg_get_string(_surf_cfg_set, name);
69 /* New Module missing */
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);
83 /* New Module missing */
84 find_model_description(surf_cpu_model_description, val);
87 /* callback of the workstation_model variable */
88 static void _surf_cfg_cb__network_model(const char *name, int pos)
92 xbt_assert0(_surf_init_status < 2,
93 "Cannot change the model after the initialization");
95 val = xbt_cfg_get_string(_surf_cfg_set, name);
96 /* New Module missing */
97 find_model_description(surf_network_model_description, val);
100 /* callback of the tcp gamma variable */
101 static void _surf_cfg_cb__tcp_gamma(const char *name, int pos)
103 sg_tcp_gamma = xbt_cfg_get_double(_surf_cfg_set, name);
106 static void _surf_cfg_cb__surf_path(const char *name, int pos)
108 char *path = xbt_cfg_get_string_at(_surf_cfg_set, name, pos);
109 xbt_dynar_push(surf_path, &path);
114 /* create the config set, register what should be and parse the command line*/
115 void surf_config_init(int *argc, char **argv)
118 /* Create the configuration support */
119 if (_surf_init_status == 0) { /* Only create stuff if not already inited */
120 _surf_init_status = 1;
122 char *description = xbt_malloc(1024), *p = description;
126 "The model to use for the workstation. Possible values: ");
127 while (*(++p) != '\0');
128 for (i = 0; surf_workstation_model_description[i].name; i++)
130 sprintf(p, "%s%s", (i == 0 ? "" : ", "),
131 surf_workstation_model_description[i].name);
132 default_value = xbt_strdup("CLM03");
133 xbt_cfg_register(&_surf_cfg_set,
134 "workstation_model", description, xbt_cfgelm_string,
135 &default_value, 1, 1, &_surf_cfg_cb__workstation_model,
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("CM02");
159 xbt_cfg_register(&_surf_cfg_set,
160 "network_model", description, xbt_cfgelm_string,
161 &default_value, 1, 1, &_surf_cfg_cb__network_model,
163 xbt_free(description);
165 xbt_cfg_register(&_surf_cfg_set, "TCP_gamma",
166 "Size of the biggest TCP window", xbt_cfgelm_double,
167 NULL, 1, 1, _surf_cfg_cb__tcp_gamma, NULL);
168 xbt_cfg_set_double(_surf_cfg_set, "TCP_gamma", 20000.0);
170 xbt_cfg_register(&_surf_cfg_set, "path",
171 "Lookup path for inclusions in platform and deployment XML files",
172 xbt_cfgelm_string, NULL, 0, 0, _surf_cfg_cb__surf_path,
175 /* retrieves the current directory of the current process */
176 const char *initial_path = __surf_get_initial_path();
177 xbt_assert0((initial_path),
178 "__surf_get_initial_path() failed! Can't resolves current Windows directory");
180 surf_path = xbt_dynar_new(sizeof(char *), NULL);
181 xbt_cfg_set_string(_surf_cfg_set, "path", initial_path);
184 surf_config_cmd_line(argc, argv);
188 void surf_config_finalize(void)
190 if (!_surf_init_status)
191 return; /* Not initialized yet. Nothing to do */
193 xbt_cfg_free(&_surf_cfg_set);
194 _surf_init_status = 0;
197 void surf_config_models_setup(const char *platform_file)
199 char *workstation_model_name;
200 int workstation_id = -1;
202 workstation_model_name =
203 xbt_cfg_get_string(_surf_cfg_set, "workstation_model");
205 DEBUG1("Model : %s", workstation_model_name);
207 find_model_description(surf_workstation_model_description,
208 workstation_model_name);
209 if (!strcmp(workstation_model_name, "compound")) {
211 char *network_model_name = NULL;
212 char *cpu_model_name = NULL;
217 cpu_model_name = xbt_cfg_get_string(_surf_cfg_set, "cpu_model");
219 if (e.category == bound_error) {
221 "Set a cpu model to use with the 'compound' workstation model");
229 network_model_name = xbt_cfg_get_string(_surf_cfg_set, "network_model");
232 if (e.category == bound_error) {
234 "Set a network model to use with the 'compound' workstation model");
242 find_model_description(surf_network_model_description,
245 find_model_description(surf_cpu_model_description, cpu_model_name);
247 surf_cpu_model_description[cpu_id].model_init_preparse(platform_file);
248 surf_network_model_description[network_id].
249 model_init_preparse(platform_file);
252 DEBUG0("Call workstation_model_init");
253 surf_workstation_model_description[workstation_id].model_init_preparse
257 void surf_config_models_create_elms(void)
259 char *workstation_model_name =
260 xbt_cfg_get_string(_surf_cfg_set, "workstation_model");
262 find_model_description(surf_workstation_model_description,
263 workstation_model_name);
264 if (surf_workstation_model_description[workstation_id].
265 model_init_postparse != NULL)
266 surf_workstation_model_description[workstation_id].model_init_postparse();