Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Allow to set latency_factor, bandwidth_factor and weight_S parameters of the network...
[simgrid.git] / src / surf / surf_config.c
1 /* Copyright (c) 2009-2010 The SimGrid team. All rights reserved.           */
2
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. */
5
6 /* surf_config: configuration infrastructure for the simulation world       */
7
8 #include "xbt/config.h"
9 #include "xbt/str.h"
10 #include "surf/surf_private.h"
11
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_config, surf,
13                                 "About the configuration of surf (and the rest of the simulation)");
14
15 xbt_cfg_t _surf_cfg_set = NULL;
16
17
18 /* Parse the command line, looking for options */
19 static void surf_config_cmd_line(int *argc, char **argv)
20 {
21   int i, j;
22   char *opt;
23
24   for (i = 1; i < *argc; i++) {
25     int remove_it = 0;
26     if (!strncmp(argv[i], "--cfg=", strlen("--cfg="))) {
27       opt = strchr(argv[i], '=');
28       opt++;
29
30       xbt_cfg_set_parse(_surf_cfg_set, opt);
31       DEBUG1("Did apply '%s' as config setting", opt);
32       remove_it = 1;
33     } else if (!strncmp(argv[i], "--cfg-help", strlen("--cfg-help") + 1) ||
34                !strncmp(argv[i], "--help", strlen("--help") + 1)) {
35       printf
36         ("Description of the configuration accepted by this simulator:\n");
37       xbt_cfg_help(_surf_cfg_set);
38       remove_it = 1;
39       exit(0);
40     }
41     if (remove_it) {            /*remove this from argv */
42       for (j = i + 1; j < *argc; j++) {
43         argv[j - 1] = argv[j];
44       }
45
46       argv[j - 1] = NULL;
47       (*argc)--;
48       i--;                      /* compensate effect of next loop incrementation */
49     }
50   }
51 }
52
53
54 int _surf_init_status = 0;      /* 0: beginning of time;
55                                    1: pre-inited (cfg_set created);
56                                    2: inited (running) */
57
58 /* callback of the workstation/model variable */
59 static void _surf_cfg_cb__workstation_model(const char *name, int pos)
60 {
61   char *val;
62
63   xbt_assert0(_surf_init_status < 2,
64               "Cannot change the model after the initialization");
65
66   val = xbt_cfg_get_string(_surf_cfg_set, name);
67   /* New Module missing */
68
69   find_model_description(surf_workstation_model_description, val);
70 }
71
72 /* callback of the cpu/model variable */
73 static void _surf_cfg_cb__cpu_model(const char *name, int pos)
74 {
75   char *val;
76
77   xbt_assert0(_surf_init_status < 2,
78               "Cannot change the model after the initialization");
79
80   val = xbt_cfg_get_string(_surf_cfg_set, name);
81   /* New Module missing */
82   find_model_description(surf_cpu_model_description, val);
83 }
84
85 /* callback of the workstation_model variable */
86 static void _surf_cfg_cb__network_model(const char *name, int pos)
87 {
88   char *val;
89
90   xbt_assert0(_surf_init_status < 2,
91               "Cannot change the model after the initialization");
92
93   val = xbt_cfg_get_string(_surf_cfg_set, name);
94   /* New Module missing */
95   find_model_description(surf_network_model_description, val);
96 }
97
98
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);
102 }
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);
105 }
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);
108 }
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);
111 }
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);
114 }
115
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);
120 }
121
122
123 #ifdef HAVE_GTNETS
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);
126 }
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);
129 }
130 #endif
131
132 /* create the config set, register what should be and parse the command line*/
133 void surf_config_init(int *argc, char **argv)
134 {
135
136   /* Create the configuration support */
137   if (_surf_init_status == 0) { /* Only create stuff if not already inited */
138     _surf_init_status = 1;
139
140     char *description = xbt_malloc(1024), *p = description;
141     char *default_value;
142     double double_default_value;
143         int default_value_int;
144     int i;
145
146     sprintf(description, "The model to use for the CPU. Possible values: ");
147     p = description;
148     while (*(++p) != '\0');
149     for (i = 0; surf_cpu_model_description[i].name; i++)
150       p +=
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);
157
158     sprintf(description,
159             "The model to use for the network. Possible values: ");
160     p = description;
161     while (*(++p) != '\0');
162     for (i = 0; surf_network_model_description[i].name; i++)
163       p +=
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,
170                      NULL);
171
172     sprintf(description,
173             "The model to use for the workstation. Possible values: ");
174     p = description;
175     while (*(++p) != '\0');
176     for (i = 0; surf_workstation_model_description[i].name; i++)
177       p +=
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,
184                      NULL);
185
186     xbt_free(description);
187
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);
192
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);
197
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);
211
212     /* Inclusion path */
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,
216                      NULL);
217
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);
222
223 #ifdef HAVE_GTNETS
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);
228
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);
233 #endif
234
235     if (!surf_path) {
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");
240
241       surf_path = xbt_dynar_new(sizeof(char *), NULL);
242       xbt_cfg_set_string(_surf_cfg_set, "path", initial_path);
243     }
244
245
246     surf_config_cmd_line(argc, argv);
247   }
248 }
249
250 void surf_config_finalize(void)
251 {
252   if (!_surf_init_status)
253     return;                     /* Not initialized yet. Nothing to do */
254
255   xbt_cfg_free(&_surf_cfg_set);
256   _surf_init_status = 0;
257 }
258
259 void surf_config_models_setup(const char *platform_file)
260 {
261   char *workstation_model_name;
262   int workstation_id = -1;
263
264   surf_timer_model_init(platform_file);
265
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");
270
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";
277   }
278
279   DEBUG1("Workstation model: %s", workstation_model_name);
280   workstation_id =
281     find_model_description(surf_workstation_model_description,
282                            workstation_model_name);
283   if (!strcmp(workstation_model_name, "compound")) {
284     int network_id = -1;
285     int cpu_id = -1;
286
287     xbt_assert0(cpu_model_name,
288         "Set a cpu model to use with the 'compound' workstation model");
289
290     xbt_assert0(network_model_name,
291         "Set a network model to use with the 'compound' workstation model");
292
293     network_id =
294       find_model_description(surf_network_model_description,
295                              network_model_name);
296     cpu_id =
297       find_model_description(surf_cpu_model_description, cpu_model_name);
298
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);
302   }
303
304   DEBUG0("Call workstation_model_init");
305   surf_workstation_model_description[workstation_id].model_init_preparse
306     (platform_file);
307 }
308
309 void surf_config_models_create_elms(void)
310 {
311   char *workstation_model_name =
312     xbt_cfg_get_string(_surf_cfg_set, "workstation/model");
313   int workstation_id =
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();
319 }