Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Disable gtnets jitter by default.
[simgrid.git] / src / surf / surf_config.c
1 /*      $Id$     */
2
3 /* Copyright (c) 2009 The SimGrid team. All rights reserved.                */
4
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. */
7
8 /* surf_config: configuration infrastructure for the simulation world       */
9
10 #include "xbt/config.h"
11 #include "xbt/str.h"
12 #include "surf/surf_private.h"
13
14 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_config, surf,
15                                 "About the configuration of surf (and the rest of the simulation)");
16
17 xbt_cfg_t _surf_cfg_set = NULL;
18 #ifdef HAVE_GTNETS
19 extern double sg_gtnets_jitter;
20 #endif
21
22 /* Parse the command line, looking for options */
23 static void surf_config_cmd_line(int *argc, char **argv)
24 {
25   int i, j;
26   char *opt;
27
28   for (i = 1; i < *argc; i++) {
29     int remove_it = 0;
30     if (!strncmp(argv[i], "--cfg=", strlen("--cfg="))) {
31       opt = strchr(argv[i], '=');
32       opt++;
33
34       xbt_cfg_set_parse(_surf_cfg_set, opt);
35       DEBUG1("Did apply '%s' as config setting", opt);
36       remove_it = 1;
37     } else if (!strncmp(argv[i], "--cfg-help", strlen("--cfg-help") + 1) ||
38                !strncmp(argv[i], "--help", strlen("--help") + 1)) {
39       printf
40         ("Description of the configuration accepted by this simulator:\n");
41       xbt_cfg_help(_surf_cfg_set);
42       remove_it = 1;
43       exit(0);
44     }
45     if (remove_it) {            /*remove this from argv */
46       for (j = i + 1; j < *argc; j++) {
47         argv[j - 1] = argv[j];
48       }
49
50       argv[j - 1] = NULL;
51       (*argc)--;
52       i--;                      /* compensate effect of next loop incrementation */
53     }
54   }
55 }
56
57
58 int _surf_init_status = 0;      /* 0: beginning of time;
59                                    1: pre-inited (cfg_set created);
60                                    2: inited (running) */
61
62 /* callback of the workstation_model variable */
63 static void _surf_cfg_cb__workstation_model(const char *name, int pos)
64 {
65   char *val;
66
67   xbt_assert0(_surf_init_status < 2,
68               "Cannot change the model after the initialization");
69
70   val = xbt_cfg_get_string(_surf_cfg_set, name);
71   /* New Module missing */
72
73   find_model_description(surf_workstation_model_description, val);
74 }
75
76 /* callback of the cpu_model variable */
77 static void _surf_cfg_cb__cpu_model(const char *name, int pos)
78 {
79   char *val;
80
81   xbt_assert0(_surf_init_status < 2,
82               "Cannot change the model after the initialization");
83
84   val = xbt_cfg_get_string(_surf_cfg_set, name);
85   /* New Module missing */
86   find_model_description(surf_cpu_model_description, val);
87 }
88
89 /* callback of the workstation_model variable */
90 static void _surf_cfg_cb__network_model(const char *name, int pos)
91 {
92   char *val;
93
94   xbt_assert0(_surf_init_status < 2,
95               "Cannot change the model after the initialization");
96
97   val = xbt_cfg_get_string(_surf_cfg_set, name);
98   /* New Module missing */
99   find_model_description(surf_network_model_description, val);
100 }
101
102 /* callback of the tcp gamma variable */
103 static void _surf_cfg_cb__tcp_gamma(const char *name, int pos)
104 {
105   sg_tcp_gamma = xbt_cfg_get_double(_surf_cfg_set, name);
106 }
107
108 static void _surf_cfg_cb__surf_path(const char *name, int pos)
109 {
110   char *path = xbt_cfg_get_string_at(_surf_cfg_set, name, pos);
111   xbt_dynar_push(surf_path, &path);
112 }
113
114 static void _surf_cfg_cb__surf_maxmin_selective_update(const char *name, int pos)
115 {
116         sg_maxmin_selective_update = xbt_cfg_get_int(_surf_cfg_set, name);
117 }
118
119 #ifdef HAVE_GTNETS
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);
122 }
123 #endif
124
125 /* create the config set, register what should be and parse the command line*/
126 void surf_config_init(int *argc, char **argv)
127 {
128
129   /* Create the configuration support */
130   if (_surf_init_status == 0) { /* Only create stuff if not already inited */
131     _surf_init_status = 1;
132
133     char *description = xbt_malloc(1024), *p = description;
134     char *default_value;
135                 int default_value_int;
136     int i;
137
138     sprintf(description, "The model to use for the CPU. Possible values: ");
139     p = description;
140     while (*(++p) != '\0');
141     for (i = 0; surf_cpu_model_description[i].name; i++)
142       p +=
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);
149
150     sprintf(description,
151             "The model to use for the network. Possible values: ");
152     p = description;
153     while (*(++p) != '\0');
154     for (i = 0; surf_network_model_description[i].name; i++)
155       p +=
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,
162                      NULL);
163
164     sprintf(description,
165             "The model to use for the workstation. Possible values: ");
166     p = description;
167     while (*(++p) != '\0');
168     for (i = 0; surf_workstation_model_description[i].name; i++)
169       p +=
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,
176                      NULL);
177
178     xbt_free(description);
179
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,
184                      NULL);
185
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);
190
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,
194                      NULL);
195
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);
200
201 #ifdef HAVE_GTNETS
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);
206 #endif
207
208     if (!surf_path) {
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");
213
214       surf_path = xbt_dynar_new(sizeof(char *), NULL);
215       xbt_cfg_set_string(_surf_cfg_set, "path", initial_path);
216     }
217
218
219     surf_config_cmd_line(argc, argv);
220   }
221 }
222
223 void surf_config_finalize(void)
224 {
225   if (!_surf_init_status)
226     return;                     /* Not initialized yet. Nothing to do */
227
228   xbt_cfg_free(&_surf_cfg_set);
229   _surf_init_status = 0;
230 }
231
232 void surf_config_models_setup(const char *platform_file)
233 {
234   char *workstation_model_name;
235   int workstation_id = -1;
236
237   surf_timer_model_init(platform_file);
238
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");
243
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";
250   }
251
252   DEBUG1("Workstation model: %s", workstation_model_name);
253   workstation_id =
254     find_model_description(surf_workstation_model_description,
255                            workstation_model_name);
256   if (!strcmp(workstation_model_name, "compound")) {
257     int network_id = -1;
258     int cpu_id = -1;
259
260     xbt_assert0(cpu_model_name,
261         "Set a cpu model to use with the 'compound' workstation model");
262
263     xbt_assert0(network_model_name,
264         "Set a network model to use with the 'compound' workstation model");
265
266     network_id =
267       find_model_description(surf_network_model_description,
268                              network_model_name);
269     cpu_id =
270       find_model_description(surf_cpu_model_description, cpu_model_name);
271
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);
275   }
276
277   DEBUG0("Call workstation_model_init");
278   surf_workstation_model_description[workstation_id].model_init_preparse
279     (platform_file);
280 }
281
282 void surf_config_models_create_elms(void)
283 {
284   char *workstation_model_name =
285     xbt_cfg_get_string(_surf_cfg_set, "workstation_model");
286   int workstation_id =
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();
292 }