Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
abf48f44c38c53317bf3b576eac9160e83c3f998
[simgrid.git] / src / surf / surf_config.c
1 /* Copyright (c) 2009, 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 /* surf_config: configuration infrastructure for the simulation world       */
8
9 #include "xbt/config.h"
10 #include "xbt/str.h"
11 #include "surf/surf_private.h"
12 #include "surf/surf_routing.h"  /* COORD_HOST_LEVEL and COORD_ASR_LEVEL */
13 #include "simix/context.h"
14
15 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_config, surf,
16                                 "About the configuration of surf (and the rest of the simulation)");
17
18 xbt_cfg_t _surf_cfg_set = NULL;
19
20 static void LOG_help(void)
21 {
22   printf(
23 "Description of the logging output:\n"
24 "\n"
25 "   Threshold configuration: --log=CATEGORY_NAME.thres:PRIORITY_LEVEL\n"
26 "      CATEGORY_NAME: defined in code with function 'XBT_LOG_NEW_CATEGORY'\n"
27 "      PRIORITY_LEVEL: the level to print (trace,debug,verbose,info,warning,error,critical)\n"
28 "         -> trace: enter and return of some functions\n"
29 "         -> debug: crufty output\n"
30 "         -> verbose: verbose output for the user wanting more\n"
31 "         -> info: output about the regular functionning\n"
32 "         -> warning: minor issue encountered\n"
33 "         -> error: issue encountered\n"
34 "         -> critical: major issue encountered\n"
35 "\n"
36 "   Format configuration: --log=CATEGORY_NAME.fmt:OPTIONS\n"
37 "      OPTIONS may be:\n"
38 "         -> %%%%: the %% char\n"
39 "         -> %%n: platform-dependent line separator (LOG4J compatible)\n"
40 "         -> %%e: plain old space (SimGrid extension)\n"
41 "\n"
42 "         -> %%m: user-provided message\n"
43 "\n"
44 "         -> %%c: Category name (LOG4J compatible)\n"
45 "         -> %%p: Priority name (LOG4J compatible)\n"
46 "\n"
47 "         -> %%h: Hostname (SimGrid extension)\n"
48 "         -> %%P: Process name (SimGrid extension)\n"
49 "         -> %%t: Thread \"name\" (LOG4J compatible -- actually the address of the thread in memory)\n"
50 "         -> %%i: Process PID (SimGrid extension -- this is a 'i' as in 'i'dea)\n"
51 "\n"
52 "         -> %%F: file name where the log event was raised (LOG4J compatible)\n"
53 "         -> %%l: location where the log event was raised (LOG4J compatible, like '%%F:%%L' -- this is a l as in 'l'etter)\n"
54 "         -> %%L: line number where the log event was raised (LOG4J compatible)\n"
55 "         -> %%M: function name (LOG4J compatible -- called method name here of course).\n"
56 "                 Defined only when using gcc because there is no __FUNCTION__ elsewhere.\n"
57 "\n"
58 "         -> %%b: full backtrace (Called %%throwable in LOG4J). Defined only under windows or when using the GNU libc because\n"
59 "                 backtrace() is not defined elsewhere, and we only have a fallback for windows boxes, not mac ones for example.\n"
60 "         -> %%B: short backtrace (only the first line of the %%b). Called %%throwable{short} in LOG4J; defined where %%b is.\n"
61 "\n"
62 "         -> %%d: date (UNIX-like epoch)\n"
63 "         -> %%r: application age (time elapsed since the beginning of the application)\n"
64 "\n"
65     );
66 }
67
68 /* Parse the command line, looking for options */
69 static void surf_config_cmd_line(int *argc, char **argv)
70 {
71   int shall_exit = 0;
72   int i, j;
73   char *opt;
74
75   for (j = i = 1; i < *argc; i++) {
76     if (!strncmp(argv[i], "--cfg=", strlen("--cfg="))) {
77       opt = strchr(argv[i], '=');
78       opt++;
79
80       xbt_cfg_set_parse(_surf_cfg_set, opt);
81       XBT_DEBUG("Did apply '%s' as config setting", opt);
82     } else if (!strcmp(argv[i], "--cfg-help") || !strcmp(argv[i], "--help")) {
83       printf
84           ("Description of the configuration accepted by this simulator:\n");
85       xbt_cfg_help(_surf_cfg_set);
86       printf(
87 "\n"
88 "You can also use --help-models to see the details of all models known by this simulator.\n"
89 #ifdef HAVE_TRACING
90 "\n"
91 "You can also use --help-tracing to see the details of all tracing options known by this simulator.\n"
92 #endif
93 "\n"
94 "You can also use --help-logs to see the details of logging output.\n"
95 "\n"
96         );
97       shall_exit = 1;
98     } else if (!strcmp(argv[i], "--help-models")) {
99       int k;
100
101       model_help("workstation", surf_workstation_model_description);
102       printf("\n");
103       model_help("CPU", surf_cpu_model_description);
104       printf("\n");
105       model_help("network", surf_network_model_description);
106       printf("\nLong description of all optimization levels accepted by the models of this simulator:\n");
107       for (k = 0; surf_optimization_mode_description[k].name; k++)
108         printf("  %s: %s\n",
109                surf_optimization_mode_description[k].name,
110                surf_optimization_mode_description[k].description);
111       printf("Both network and CPU models have 'Lazy' as default optimization level\n\n");
112       shall_exit = 1;
113     } else if (!strcmp(argv[i], "--help-logs")) {
114       LOG_help ();
115       shall_exit = 1;
116 #ifdef HAVE_TRACING
117     } else if (!strcmp(argv[i], "--help-tracing")) {
118       TRACE_help (1);
119       shall_exit = 1;
120 #endif
121     } else {
122       argv[j++] = argv[i];
123     }
124   }
125   if (j < *argc) {
126     argv[j] = NULL;
127     *argc = j;
128   }
129   if (shall_exit)
130     exit(0);
131 }
132
133
134 int _surf_init_status = 0;      /* 0: beginning of time;
135                                    1: pre-inited (cfg_set created);
136                                    2: inited (running) */
137
138 /* callback of the workstation/model variable */
139 static void _surf_cfg_cb__workstation_model(const char *name, int pos)
140 {
141   char *val;
142
143   xbt_assert(_surf_init_status < 2,
144               "Cannot change the model after the initialization");
145
146   val = xbt_cfg_get_string(_surf_cfg_set, name);
147
148   if (!strcmp(val, "help")) {
149     model_help("workstation", surf_workstation_model_description);
150     exit(0);
151   }
152
153   /* Make sure that the model exists */
154   find_model_description(surf_workstation_model_description, val);
155 }
156
157 /* callback of the cpu/model variable */
158 static void _surf_cfg_cb__cpu_model(const char *name, int pos)
159 {
160   char *val;
161
162   xbt_assert(_surf_init_status < 2,
163               "Cannot change the model after the initialization");
164
165   val = xbt_cfg_get_string(_surf_cfg_set, name);
166
167   if (!strcmp(val, "help")) {
168     model_help("CPU", surf_cpu_model_description);
169     exit(0);
170   }
171
172   /* New Module missing */
173   find_model_description(surf_cpu_model_description, val);
174 }
175
176 /* callback of the cpu/model variable */
177 static void _surf_cfg_cb__optimization_mode(const char *name, int pos)
178 {
179   char *val;
180
181   xbt_assert(_surf_init_status < 2,
182               "Cannot change the model after the initialization");
183
184   val = xbt_cfg_get_string(_surf_cfg_set, name);
185
186   if (!strcmp(val, "help")) {
187     model_help("optimization", surf_optimization_mode_description);
188     exit(0);
189   }
190
191   /* New Module missing */
192   find_model_description(surf_optimization_mode_description, val);
193 }
194
195 /* callback of the cpu/model variable */
196 static void _surf_cfg_cb__storage_mode(const char *name, int pos)
197 {
198   char *val;
199
200   xbt_assert(_surf_init_status < 2,
201               "Cannot change the model after the initialization");
202
203   val = xbt_cfg_get_string(_surf_cfg_set, name);
204
205   if (!strcmp(val, "help")) {
206     model_help("storage", surf_storage_model_description);
207     exit(0);
208   }
209
210   /* New Module missing */
211   find_model_description(surf_storage_model_description, val);
212 }
213
214 /* callback of the workstation_model variable */
215 static void _surf_cfg_cb__network_model(const char *name, int pos)
216 {
217   char *val;
218
219   xbt_assert(_surf_init_status < 2,
220               "Cannot change the model after the initialization");
221
222   val = xbt_cfg_get_string(_surf_cfg_set, name);
223
224   if (!strcmp(val, "help")) {
225     model_help("network", surf_network_model_description);
226     exit(0);
227   }
228
229   /* New Module missing */
230   find_model_description(surf_network_model_description, val);
231 }
232
233
234 /* callbacks of the network models values */
235 static void _surf_cfg_cb__tcp_gamma(const char *name, int pos)
236 {
237   sg_tcp_gamma = xbt_cfg_get_double(_surf_cfg_set, name);
238 }
239
240 static void _surf_cfg_cb__maxmin_precision(const char* name, int pos)
241 {
242   sg_maxmin_precision = xbt_cfg_get_double(_surf_cfg_set, name);
243 }
244
245 static void _surf_cfg_cb__sender_gap(const char* name, int pos)
246 {
247   sg_sender_gap = xbt_cfg_get_double(_surf_cfg_set, name);
248 }
249
250 static void _surf_cfg_cb__latency_factor(const char *name, int pos)
251 {
252   sg_latency_factor = xbt_cfg_get_double(_surf_cfg_set, name);
253 }
254
255 static void _surf_cfg_cb__bandwidth_factor(const char *name, int pos)
256 {
257   sg_bandwidth_factor = xbt_cfg_get_double(_surf_cfg_set, name);
258 }
259
260 static void _surf_cfg_cb__weight_S(const char *name, int pos)
261 {
262   sg_weight_S_parameter = xbt_cfg_get_double(_surf_cfg_set, name);
263 }
264
265 /* callback of the inclusion path */
266 static void _surf_cfg_cb__surf_path(const char *name, int pos)
267 {
268   char *path = xbt_cfg_get_string_at(_surf_cfg_set, name, pos);
269   xbt_dynar_push(surf_path, &path);
270 }
271
272 /* callback to decide if we want to use the model-checking */
273 #include "xbt_modinter.h"
274 extern int _surf_do_model_check;   /* this variable lives in xbt_main until I find a right location for it */
275
276 static void _surf_cfg_cb_model_check(const char *name, int pos)
277 {
278   _surf_do_model_check = xbt_cfg_get_int(_surf_cfg_set, name);
279
280   if (_surf_do_model_check) {
281     /* Tell modules using mallocators that they shouldn't. MC don't like them */
282     xbt_fifo_preinit();
283     xbt_dict_preinit();
284   }
285 }
286
287 extern int _surf_do_verbose_exit;
288
289 static void _surf_cfg_cb_verbose_exit(const char *name, int pos)
290 {
291   _surf_do_verbose_exit = xbt_cfg_get_int(_surf_cfg_set, name);
292 }
293
294
295 static void _surf_cfg_cb_context_factory(const char *name, int pos)
296 {
297   smx_context_factory_name = xbt_cfg_get_string(_surf_cfg_set, name);
298 }
299
300 static void _surf_cfg_cb_context_stack_size(const char *name, int pos)
301 {
302   smx_context_stack_size = xbt_cfg_get_int(_surf_cfg_set, name) * 1024;
303 }
304
305 static void _surf_cfg_cb_contexts_nthreads(const char *name, int pos)
306 {
307   SIMIX_context_set_nthreads(xbt_cfg_get_int(_surf_cfg_set, name));
308 }
309
310 static void _surf_cfg_cb_contexts_parallel_threshold(const char *name, int pos)
311 {
312   SIMIX_context_set_parallel_threshold(xbt_cfg_get_int(_surf_cfg_set, name));
313 }
314
315 static void _surf_cfg_cb_contexts_parallel_mode(const char *name, int pos)
316 {
317   const char* mode_name = xbt_cfg_get_string(_surf_cfg_set, name);
318   if (!strcmp(mode_name, "posix")) {
319     SIMIX_context_set_parallel_mode(XBT_PARMAP_POSIX);
320   }
321   else if (!strcmp(mode_name, "futex")) {
322     SIMIX_context_set_parallel_mode(XBT_PARMAP_FUTEX);
323   }
324   else if (!strcmp(mode_name, "busy_wait")) {
325     SIMIX_context_set_parallel_mode(XBT_PARMAP_BUSY_WAIT);
326   }
327   else {
328     xbt_die("Command line setting of the parallel synchronization mode should "
329         "be one of \"posix\", \"futex\" or \"busy_wait\"");
330   }
331 }
332
333 static void _surf_cfg_cb_surf_nthreads(const char *name, int pos)
334 {
335   surf_set_nthreads(xbt_cfg_get_int(_surf_cfg_set, name));
336 }
337
338 static void _surf_cfg_cb__surf_network_coordinates(const char *name,
339                                                    int pos)
340 {
341   char *val = xbt_cfg_get_string(_surf_cfg_set, name);
342   if (!strcmp(val, "yes")) {
343     if (!COORD_HOST_LEVEL) {
344       COORD_HOST_LEVEL = xbt_lib_add_level(host_lib,xbt_dynar_free_voidp);
345       COORD_ASR_LEVEL  = xbt_lib_add_level(as_router_lib,xbt_dynar_free_voidp);
346     }
347   } else if (!strcmp(val, "no")) {
348     if (COORD_HOST_LEVEL)
349       xbt_die("Setting of whether to use coordinate cannot be disabled once set.");
350   } else {
351     xbt_die("Command line setting of whether to use coordinates must be either \"yes\" or \"no\"");
352   }
353 }
354
355 static void _surf_cfg_cb__surf_network_crosstraffic(const char *name,
356                                                   int pos)
357 {
358   sg_network_crosstraffic = xbt_cfg_get_int(_surf_cfg_set, name);
359 }
360
361 #ifdef HAVE_GTNETS
362 static void _surf_cfg_cb__gtnets_jitter(const char *name, int pos)
363 {
364   sg_gtnets_jitter = xbt_cfg_get_double(_surf_cfg_set, name);
365 }
366
367 static void _surf_cfg_cb__gtnets_jitter_seed(const char *name, int pos)
368 {
369   sg_gtnets_jitter_seed = xbt_cfg_get_int(_surf_cfg_set, name);
370 }
371 #endif
372
373 /* create the config set, register what should be and parse the command line*/
374 void surf_config_init(int *argc, char **argv)
375 {
376   char *description = xbt_malloc(1024), *p = description;
377   char *default_value;
378   double double_default_value;
379   int default_value_int;
380   int i;
381
382   /* Create the configuration support */
383   if (_surf_init_status == 0) { /* Only create stuff if not already inited */
384     _surf_init_status = 1;
385
386     sprintf(description,
387             "The model to use for the CPU. Possible values: ");
388     p = description;
389     while (*(++p) != '\0');
390     for (i = 0; surf_cpu_model_description[i].name; i++)
391       p += sprintf(p, "%s%s", (i == 0 ? "" : ", "),
392                    surf_cpu_model_description[i].name);
393     sprintf(p,
394             ".\n       (use 'help' as a value to see the long description of each model)");
395     default_value = xbt_strdup("Cas01");
396     xbt_cfg_register(&_surf_cfg_set, "cpu/model", description, xbt_cfgelm_string,
397                      &default_value, 1, 1, &_surf_cfg_cb__cpu_model, NULL);
398
399     sprintf(description,
400             "The optimization modes to use for the CPU. Possible values: ");
401     p = description;
402     while (*(++p) != '\0');
403     for (i = 0; surf_optimization_mode_description[i].name; i++)
404       p += sprintf(p, "%s%s", (i == 0 ? "" : ", "),
405                    surf_optimization_mode_description[i].name);
406     sprintf(p,
407             ".\n       (use 'help' as a value to see the long description of each optimization mode)");
408     default_value = xbt_strdup("Lazy");
409     xbt_cfg_register(&_surf_cfg_set, "cpu/optim", description, xbt_cfgelm_string,
410                      &default_value, 1, 1, &_surf_cfg_cb__optimization_mode, NULL);
411
412     sprintf(description,
413             "The model to use for the storage. Possible values: ");
414     p = description;
415     while (*(++p) != '\0');
416     for (i = 0; surf_storage_model_description[i].name; i++)
417       p += sprintf(p, "%s%s", (i == 0 ? "" : ", "),
418                    surf_storage_model_description[i].name);
419     sprintf(p,
420             ".\n       (use 'help' as a value to see the long description of each model)");
421     default_value = xbt_strdup("default");
422     xbt_cfg_register(&_surf_cfg_set, "storage/model", description, xbt_cfgelm_string,
423                      &default_value, 1, 1, &_surf_cfg_cb__storage_mode,
424                      NULL);
425
426     sprintf(description,
427             "The model to use for the network. Possible values: ");
428     p = description;
429     while (*(++p) != '\0');
430     for (i = 0; surf_network_model_description[i].name; i++)
431       p += sprintf(p, "%s%s", (i == 0 ? "" : ", "),
432                    surf_network_model_description[i].name);
433     sprintf(p,
434             ".\n       (use 'help' as a value to see the long description of each model)");
435     default_value = xbt_strdup("LV08");
436     xbt_cfg_register(&_surf_cfg_set, "network/model", description, xbt_cfgelm_string,
437                      &default_value, 1, 1, &_surf_cfg_cb__network_model,
438                      NULL);
439
440     sprintf(description,
441             "The optimization modes to use for the network. Possible values: ");
442     p = description;
443     while (*(++p) != '\0');
444     for (i = 0; surf_optimization_mode_description[i].name; i++)
445       p += sprintf(p, "%s%s", (i == 0 ? "" : ", "),
446                    surf_optimization_mode_description[i].name);
447     sprintf(p,
448             ".\n       (use 'help' as a value to see the long description of each optimization mode)");
449     default_value = xbt_strdup("Lazy");
450     xbt_cfg_register(&_surf_cfg_set, "network/optim", description, xbt_cfgelm_string,
451                      &default_value, 1, 1, &_surf_cfg_cb__optimization_mode, NULL);
452
453     sprintf(description,
454             "The model to use for the workstation. Possible values: ");
455     p = description;
456     while (*(++p) != '\0');
457     for (i = 0; surf_workstation_model_description[i].name; i++)
458       p += sprintf(p, "%s%s", (i == 0 ? "" : ", "),
459                    surf_workstation_model_description[i].name);
460     sprintf(p,
461             ".\n       (use 'help' as a value to see the long description of each model)");
462     default_value = xbt_strdup("default");
463     xbt_cfg_register(&_surf_cfg_set, "workstation/model", description, xbt_cfgelm_string,
464                      &default_value, 1, 1,
465                      &_surf_cfg_cb__workstation_model, NULL);
466
467     xbt_free(description);
468
469     xbt_cfg_register(&_surf_cfg_set, "network/TCP_gamma",
470                      "Size of the biggest TCP window (cat /proc/sys/net/ipv4/tcp_[rw]mem for recv/send window; Use the last given value, which is the max window size)",
471                      xbt_cfgelm_double, NULL, 1, 1,
472                      _surf_cfg_cb__tcp_gamma, NULL);
473     xbt_cfg_setdefault_double(_surf_cfg_set, "network/TCP_gamma", 20000.0);
474
475     xbt_cfg_register(&_surf_cfg_set, "maxmin/precision",
476                      "Numerical precision used when updating simulation models (epsilon in double comparisons)",
477                      xbt_cfgelm_double, NULL, 1, 1, _surf_cfg_cb__maxmin_precision, NULL);
478     xbt_cfg_setdefault_double(_surf_cfg_set, "maxmin/precision", 0.00001); // FIXME use setdefault everywhere here!
479
480     /* The parameters of network models */
481
482     double_default_value = 0.0;
483     xbt_cfg_register(&_surf_cfg_set, "network/sender_gap",
484                      "Minimum gap between two overlapping sends",
485                      xbt_cfgelm_double, &double_default_value, 1, 1,
486                      _surf_cfg_cb__sender_gap, NULL);
487
488     double_default_value = 1.0;
489     xbt_cfg_register(&_surf_cfg_set, "network/latency_factor",
490                      "Correction factor to apply to the provided latency (default value set by network model)",
491                      xbt_cfgelm_double, &double_default_value, 1, 1,
492                      _surf_cfg_cb__latency_factor, NULL);
493     double_default_value = 1.0;
494     xbt_cfg_register(&_surf_cfg_set, "network/bandwidth_factor",
495                      "Correction factor to apply to the provided bandwidth (default value set by network model)",
496                      xbt_cfgelm_double, &double_default_value, 1, 1,
497                      _surf_cfg_cb__bandwidth_factor, NULL);
498     double_default_value = 0.0;
499     xbt_cfg_register(&_surf_cfg_set, "network/weight_S",
500                      "Correction factor to apply to the weight of competing streams(default value set by network model)",
501                      xbt_cfgelm_double, &double_default_value, 1, 1,
502                      _surf_cfg_cb__weight_S, NULL);
503
504     /* Inclusion path */
505     xbt_cfg_register(&_surf_cfg_set, "path",
506                      "Lookup path for inclusions in platform and deployment XML files",
507                      xbt_cfgelm_string, NULL, 0, 0,
508                      _surf_cfg_cb__surf_path, NULL);
509
510     default_value_int = 0;
511     xbt_cfg_register(&_surf_cfg_set, "cpu/maxmin_selective_update",
512                      "Update the constraint set propagating recursively to others constraints (1 by default when optim is set to lazy)",
513                      xbt_cfgelm_int, &default_value_int, 0, 1,
514                      NULL, NULL);
515     default_value_int = 0;
516     xbt_cfg_register(&_surf_cfg_set, "network/maxmin_selective_update",
517                      "Update the constraint set propagating recursively to others constraints (1 by default when optim is set to lazy)",
518                      xbt_cfgelm_int, &default_value_int, 0, 1,
519                      NULL, NULL);
520
521     /* do model-check */
522     default_value_int = 0;
523     xbt_cfg_register(&_surf_cfg_set, "model-check",
524                      "Activate the model-checking of the \"simulated\" system (EXPERIMENTAL -- msg only for now)",
525                      xbt_cfgelm_int, &default_value_int, 0, 1,
526                      _surf_cfg_cb_model_check, NULL);
527     
528     /*
529        FIXME: this function is not setting model-check to it's default value because
530        internally it calls to variable->cb_set that in this case is the function 
531        _surf_cfg_cb_model_check which sets it's value to 1 (instead of the default value 0)
532        xbt_cfg_set_int(_surf_cfg_set, "model-check", default_value_int); */
533
534     /* do verbose-exit */
535     default_value_int = 1;
536     xbt_cfg_register(&_surf_cfg_set, "verbose-exit",
537                      "Activate the \"do nothing\" mode in Ctrl-C",
538                      xbt_cfgelm_int, &default_value_int, 0, 1,
539                      _surf_cfg_cb_verbose_exit, NULL);
540     
541     
542     /* context factory */
543     default_value = xbt_strdup("ucontext");
544     xbt_cfg_register(&_surf_cfg_set, "contexts/factory",
545                      "Context factory to use in SIMIX (ucontext, thread or raw)",
546                      xbt_cfgelm_string, &default_value, 1, 1, _surf_cfg_cb_context_factory, NULL);
547
548     /* stack size of contexts in Ko */
549     default_value_int = 128;
550     xbt_cfg_register(&_surf_cfg_set, "contexts/stack_size",
551                      "Stack size of contexts in Kib (ucontext or raw only)",
552                      xbt_cfgelm_int, &default_value_int, 1, 1,
553                      _surf_cfg_cb_context_stack_size, NULL);
554
555     /* number of parallel threads for user processes */
556     default_value_int = 1;
557     xbt_cfg_register(&_surf_cfg_set, "contexts/nthreads",
558                      "Number of parallel threads used to execute user contexts",
559                      xbt_cfgelm_int, &default_value_int, 1, 1,
560                      _surf_cfg_cb_contexts_nthreads, NULL);
561
562     /* minimal number of user contexts to be run in parallel */
563     default_value_int = 2;
564     xbt_cfg_register(&_surf_cfg_set, "contexts/parallel_threshold",
565         "Minimal number of user contexts to be run in parallel (raw contexts only)",
566         xbt_cfgelm_int, &default_value_int, 1, 1,
567         _surf_cfg_cb_contexts_parallel_threshold, NULL);
568
569     /* synchronization mode for parallel user contexts */
570 #ifdef HAVE_FUTEX_H
571     default_value = xbt_strdup("futex");
572 #else //No futex on mac and posix is unimplememted yet
573     default_value = xbt_strdup("busy_wait");
574 #endif
575     xbt_cfg_register(&_surf_cfg_set, "contexts/synchro",
576         "Synchronization mode to use when running contexts in parallel (either futex, posix or busy_wait)",
577         xbt_cfgelm_string, &default_value, 1, 1,
578         _surf_cfg_cb_contexts_parallel_mode, NULL);
579
580     /* number of parallel threads for Surf */
581     default_value_int = surf_get_nthreads();
582     xbt_cfg_register(&_surf_cfg_set, "surf/nthreads",
583                      "Number of parallel threads used to update Surf models",
584                      xbt_cfgelm_int, &default_value_int, 1, 1,
585                      _surf_cfg_cb_surf_nthreads, NULL);
586
587     default_value = xbt_strdup("no");
588     xbt_cfg_register(&_surf_cfg_set, "network/coordinates",
589                      "\"yes\" or \"no\", specifying whether we use a coordinate-based routing (as Vivaldi)",
590                      xbt_cfgelm_string, &default_value, 1, 1,
591                      _surf_cfg_cb__surf_network_coordinates, NULL);
592     xbt_cfg_setdefault_string(_surf_cfg_set, "network/coordinates", default_value);
593
594     default_value_int = 0;
595     xbt_cfg_register(&_surf_cfg_set, "network/crosstraffic",
596                      "Activate the interferences between uploads and downloads for fluid max-min models (LV08, CM02)",
597                      xbt_cfgelm_int, &default_value_int, 0, 1,
598                      _surf_cfg_cb__surf_network_crosstraffic, NULL);
599     xbt_cfg_setdefault_int(_surf_cfg_set, "network/crosstraffic", default_value_int);
600
601 #ifdef HAVE_GTNETS
602     xbt_cfg_register(&_surf_cfg_set, "gtnets/jitter",
603                      "Double value to oscillate the link latency, uniformly in random interval [-latency*gtnets_jitter,latency*gtnets_jitter)",
604                      xbt_cfgelm_double, NULL, 1, 1,
605                      _surf_cfg_cb__gtnets_jitter, NULL);
606     xbt_cfg_setdefault_double(_surf_cfg_set, "gtnets/jitter", 0.0);
607
608     default_value_int = 10;
609     xbt_cfg_register(&_surf_cfg_set, "gtnets/jitter_seed",
610                      "Use a positive seed to reproduce jitted results, value must be in [1,1e8], default is 10",
611                      xbt_cfgelm_int, &default_value_int, 0, 1,
612                      _surf_cfg_cb__gtnets_jitter_seed, NULL);
613 #endif
614 #ifdef HAVE_NS3
615     xbt_cfg_register(&_surf_cfg_set, "ns3/TcpModel",
616                      "The ns3 tcp model can be : NewReno or Reno or Tahoe",
617                      xbt_cfgelm_string, NULL, 1, 1,
618                      NULL, NULL);
619     xbt_cfg_setdefault_string(_surf_cfg_set, "ns3/TcpModel", "default");
620 #endif
621
622 //SMPI
623     double default_reference_speed = 20000.0;
624     xbt_cfg_register(&_surf_cfg_set, "smpi/running_power",
625                      "Power of the host running the simulation (in flop/s). Used to bench the operations.",
626                      xbt_cfgelm_double, &default_reference_speed, 1, 1, NULL,
627                      NULL);
628
629     int default_display_timing = 0;
630     xbt_cfg_register(&_surf_cfg_set, "smpi/display_timing",
631                      "Boolean indicating whether we should display the timing after simulation.",
632                      xbt_cfgelm_int, &default_display_timing, 1, 1, NULL,
633                      NULL);
634
635     double default_threshold = 1e-6;
636     xbt_cfg_register(&_surf_cfg_set, "smpi/cpu_threshold",
637                      "Minimal computation time (in seconds) not discarded.",
638                      xbt_cfgelm_double, &default_threshold, 1, 1, NULL,
639                      NULL);
640
641     //For smpi/bw_factor and smpi/lat_factor
642     //Default value have to be "threshold0:value0;threshold1:value1;...;thresholdN:valueN"
643     //test is if( size >= thresholdN ) return valueN;
644     //Values can be modified with command line --cfg=smpi/bw_factor:"threshold0:value0;threshold1:value1;...;thresholdN:valueN"
645     //  or with tag config put line <prop id="smpi/bw_factor" value="threshold0:value0;threshold1:value1;...;thresholdN:valueN"></prop>
646     xbt_cfg_register(&_surf_cfg_set, "smpi/bw_factor",
647                      "Bandwidth factors for smpi.",
648                      xbt_cfgelm_string, NULL, 1, 1, NULL,
649                      NULL);
650     xbt_cfg_setdefault_string(_surf_cfg_set, "smpi/bw_factor", "65472:0.940694;15424:0.697866;9376:0.58729;5776:1.08739;3484:0.77493;1426:0.608902;732:0.341987;257:0.338112;0:0.812084");
651
652     xbt_cfg_register(&_surf_cfg_set, "smpi/lat_factor",
653                      "Latency factors for smpi.",
654                      xbt_cfgelm_string, NULL, 1, 1, NULL,
655                      NULL);
656     xbt_cfg_setdefault_string(_surf_cfg_set, "smpi/lat_factor", "65472:11.6436;15424:3.48845;9376:2.59299;5776:2.18796;3484:1.88101;1426:1.61075;732:1.9503;257:1.95341;0:2.01467");
657 //END SMPI
658
659
660     if (!surf_path) {
661       /* retrieves the current directory of the        current process */
662       const char *initial_path = __surf_get_initial_path();
663       xbt_assert((initial_path),
664                   "__surf_get_initial_path() failed! Can't resolves current Windows directory");
665
666       surf_path = xbt_dynar_new(sizeof(char *), NULL);
667       xbt_cfg_setdefault_string(_surf_cfg_set, "path", initial_path);
668     }
669
670
671     surf_config_cmd_line(argc, argv);
672   } else {
673     XBT_WARN("Call to surf_config_init() after initialization ignored");
674   }
675 }
676
677 void surf_config_finalize(void)
678 {
679   if (!_surf_init_status)
680     return;                     /* Not initialized yet. Nothing to do */
681
682   xbt_cfg_free(&_surf_cfg_set);
683   _surf_init_status = 0;
684 }
685
686 /* Pick the right models for CPU, net and workstation, and call their model_init_preparse */
687 void surf_config_models_setup()
688 {
689   char *workstation_model_name;
690   int workstation_id = -1;
691   char *network_model_name = NULL;
692   char *cpu_model_name = NULL;
693   int storage_id = -1;
694   char *storage_model_name = NULL;
695
696   workstation_model_name =
697       xbt_cfg_get_string(_surf_cfg_set, "workstation/model");
698   network_model_name = xbt_cfg_get_string(_surf_cfg_set, "network/model");
699   cpu_model_name = xbt_cfg_get_string(_surf_cfg_set, "cpu/model");
700   storage_model_name = xbt_cfg_get_string(_surf_cfg_set, "storage/model");
701
702   /* Check whether we use a net/cpu model differing from the default ones, in which case
703    * we should switch to the "compound" workstation model to correctly dispatch stuff to
704    * the right net/cpu models.
705    */
706
707   if((!xbt_cfg_is_default_value(_surf_cfg_set, "network/model") ||
708           !xbt_cfg_is_default_value(_surf_cfg_set, "cpu/model")) &&
709           xbt_cfg_is_default_value(_surf_cfg_set, "workstation/model"))
710   {
711             const char *val = "compound";
712             XBT_INFO
713                 ("Switching workstation model to compound since you changed the network and/or cpu model(s)");
714             xbt_cfg_set_string(_surf_cfg_set, "workstation/model", val);
715             workstation_model_name = (char *) "compound";
716   }
717
718   XBT_DEBUG("Workstation model: %s", workstation_model_name);
719   workstation_id =
720       find_model_description(surf_workstation_model_description,
721                              workstation_model_name);
722   if (!strcmp(workstation_model_name, "compound")) {
723     int network_id = -1;
724     int cpu_id = -1;
725
726     xbt_assert(cpu_model_name,
727                 "Set a cpu model to use with the 'compound' workstation model");
728
729     xbt_assert(network_model_name,
730                 "Set a network model to use with the 'compound' workstation model");
731
732     network_id =
733         find_model_description(surf_network_model_description,
734                                network_model_name);
735     cpu_id =
736         find_model_description(surf_cpu_model_description, cpu_model_name);
737
738     surf_cpu_model_description[cpu_id].model_init_preparse();
739     surf_network_model_description[network_id].model_init_preparse();
740   }
741
742   XBT_DEBUG("Call workstation_model_init");
743   surf_workstation_model_description[workstation_id].model_init_preparse();
744
745   XBT_DEBUG("Call storage_model_init");
746   storage_id = find_model_description(surf_storage_model_description, storage_model_name);
747   surf_storage_model_description[storage_id].model_init_preparse();
748 }