Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
routing: inline method routing_get_network_element_type
[simgrid.git] / src / surf / sg_platf.cpp
1 /* Copyright (c) 2006-2014. 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 #include "xbt/misc.h"
8 #include "xbt/log.h"
9 #include "xbt/str.h"
10 #include "xbt/dict.h"
11 #include "xbt/RngStream.h"
12 #include <xbt/signal.hpp>
13 #include "simgrid/platf_interface.h"
14 #include "surf/surf.h"
15
16 #include "src/simix/smx_private.h"
17 #include "src/surf/platform.hpp"
18
19 #include "surf/surfxml_parse.h"// FIXME: brain dead public header
20
21 #include "src/surf/platform.hpp"
22 #include "src/surf/cpu_interface.hpp"
23 #include "src/surf/host_interface.hpp"
24 #include "src/surf/network_interface.hpp"
25 #include "surf/surf_routing.h" // FIXME: brain dead public header
26 #include "src/surf/surf_routing_cluster.hpp"
27 #include "src/surf/surf_routing_cluster_torus.hpp"
28 #include "src/surf/surf_routing_cluster_fat_tree.hpp"
29
30 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_parse);
31
32 XBT_PRIVATE xbt_dynar_t mount_list = NULL;
33
34 namespace simgrid {
35 namespace surf {
36
37 simgrid::xbt::signal<void(sg_platf_link_cbarg_t)> on_link;
38 simgrid::xbt::signal<void(sg_platf_cluster_cbarg_t)> on_cluster;
39 simgrid::xbt::signal<void(void)> on_postparse;
40
41 }
42 }
43
44 static int surf_parse_models_setup_already_called = 0;
45
46 /** Module management function: creates all internal data structures */
47 void sg_platf_init(void) {
48 }
49
50 /** Module management function: frees all internal data structures */
51 void sg_platf_exit(void) {
52   simgrid::surf::on_link.disconnect_all_slots();
53   simgrid::surf::on_cluster.disconnect_all_slots();
54   simgrid::surf::on_postparse.disconnect_all_slots();
55
56   /* make sure that we will reinit the models while loading the platf once reinited */
57   surf_parse_models_setup_already_called = 0;
58 }
59
60 /** @brief Add an "host" to the current AS */
61 void sg_platf_new_host(sg_platf_host_cbarg_t host)
62 {
63   xbt_assert(! sg_host_by_name(host->id),
64       "Refusing to create a second host named '%s'.", host->id);
65
66   simgrid::surf::As* current_routing = routing_get_current();
67   if (current_routing->hierarchy_ == SURF_ROUTING_NULL)
68     current_routing->hierarchy_ = SURF_ROUTING_BASE;
69
70   simgrid::surf::NetCard *netcard =
71       new simgrid::surf::NetCardImpl(host->id, SURF_NETWORK_ELEMENT_HOST, current_routing);
72
73   netcard->setId(current_routing->addComponent(netcard));
74   sg_host_t h = simgrid::s4u::Host::by_name_or_create(host->id);
75   h->pimpl_netcard = netcard;
76   simgrid::surf::netcardCreatedCallbacks(netcard);
77
78   if(mount_list){
79     xbt_lib_set(storage_lib, host->id, ROUTING_STORAGE_HOST_LEVEL, (void *) mount_list);
80     mount_list = NULL;
81   }
82
83   if (host->coord && strcmp(host->coord, "")) {
84     unsigned int cursor;
85     char*str;
86
87     if (!COORD_HOST_LEVEL)
88       xbt_die ("To use host coordinates, please add --cfg=network/coordinates:yes to your command line");
89     /* Pre-parse the host coordinates -- FIXME factorize with routers by overloading the routing->parse_PU function*/
90     xbt_dynar_t ctn_str = xbt_str_split_str(host->coord, " ");
91     xbt_dynar_t ctn = xbt_dynar_new(sizeof(double),NULL);
92     xbt_dynar_foreach(ctn_str,cursor, str) {
93       double val = xbt_str_parse_double(str, "Invalid coordinate: %s");
94       xbt_dynar_push(ctn,&val);
95     }
96     xbt_dynar_shrink(ctn, 0);
97     xbt_dynar_free(&ctn_str);
98     h->extension_set(COORD_HOST_LEVEL, (void *) ctn);
99     XBT_DEBUG("Having set host coordinates for '%s'",host->id);
100   }
101
102
103   simgrid::surf::Cpu *cpu = surf_cpu_model_pm->createCpu( h,
104       host->speed_peak,
105       host->pstate,
106       host->speed_scale, host->speed_trace,
107       host->core_amount,
108       host->initiallyOn, host->state_trace);
109   surf_host_model->createHost(host->id, netcard, cpu, host->properties)->attach(h);
110   simgrid::s4u::Host::onCreation(*h);
111
112   if (TRACE_is_enabled() && TRACE_needs_platform())
113     sg_instr_new_host(host);
114 }
115
116 /**
117  * \brief Add a "router" to the network element list
118  */
119 void sg_platf_new_router(sg_platf_router_cbarg_t router)
120 {
121   simgrid::surf::As* current_routing = routing_get_current();
122
123   if (current_routing->hierarchy_ == SURF_ROUTING_NULL)
124     current_routing->hierarchy_ = SURF_ROUTING_BASE;
125   xbt_assert(nullptr == xbt_lib_get_or_null(as_router_lib, router->id, ROUTING_ASR_LEVEL),
126              "Refusing to create a router named '%s': this name already describes a node.", router->id);
127
128   simgrid::surf::NetCard *netcard = new simgrid::surf::NetCardImpl(router->id, SURF_NETWORK_ELEMENT_ROUTER, current_routing);
129   netcard->setId(current_routing->addComponent(netcard));
130   xbt_lib_set(as_router_lib, router->id, ROUTING_ASR_LEVEL, (void *) netcard);
131   XBT_DEBUG("Having set name '%s' id '%d'", router->id, netcard->id());
132   simgrid::surf::netcardCreatedCallbacks(netcard);
133
134   if (router->coord && strcmp(router->coord, "")) {
135     unsigned int cursor;
136     char*str;
137
138     if (!COORD_ASR_LEVEL)
139       xbt_die ("To use host coordinates, please add --cfg=network/coordinates:yes to your command line");
140     /* Pre-parse the host coordinates */
141     xbt_dynar_t ctn_str = xbt_str_split_str(router->coord, " ");
142     xbt_dynar_t ctn = xbt_dynar_new(sizeof(double),NULL);
143     xbt_dynar_foreach(ctn_str,cursor, str) {
144       double val = xbt_str_parse_double(str, "Invalid coordinate: %s");
145       xbt_dynar_push(ctn,&val);
146     }
147     xbt_dynar_shrink(ctn, 0);
148     xbt_dynar_free(&ctn_str);
149     xbt_lib_set(as_router_lib, router->id, COORD_ASR_LEVEL, (void *) ctn);
150     XBT_DEBUG("Having set router coordinates for '%s'",router->id);
151   }
152
153   if (TRACE_is_enabled() && TRACE_needs_platform())
154     sg_instr_new_router(router);
155 }
156
157 void sg_platf_new_link(sg_platf_link_cbarg_t link){
158   simgrid::surf::on_link(link);
159 }
160
161 void sg_platf_new_cluster(sg_platf_cluster_cbarg_t cluster)
162 {
163   using simgrid::surf::AsCluster;
164   using simgrid::surf::AsClusterTorus;
165   using simgrid::surf::AsClusterFatTree;
166
167   char *host_id, *groups, *link_id = NULL;
168   xbt_dict_t patterns = NULL;
169   int rankId=0;
170
171   s_sg_platf_host_cbarg_t host = SG_PLATF_HOST_INITIALIZER;
172   s_sg_platf_link_cbarg_t link = SG_PLATF_LINK_INITIALIZER;
173
174   unsigned int iter;
175
176   if ((cluster->availability_trace && strcmp(cluster->availability_trace, ""))
177       || (cluster->state_trace && strcmp(cluster->state_trace, ""))) {
178     patterns = xbt_dict_new_homogeneous(xbt_free_f);
179     xbt_dict_set(patterns, "id", xbt_strdup(cluster->id), NULL);
180     xbt_dict_set(patterns, "prefix", xbt_strdup(cluster->prefix), NULL);
181     xbt_dict_set(patterns, "suffix", xbt_strdup(cluster->suffix), NULL);
182   }
183
184   /* Parse the topology attributes.
185    * Nothing to do in a vanilla cluster, but that's another story for torus and flat_trees */
186   s_sg_platf_AS_cbarg_t AS = SG_PLATF_AS_INITIALIZER;
187   AS.id = cluster->id;
188
189   switch (cluster->topology) {
190   case SURF_CLUSTER_TORUS:
191     AS.routing = A_surfxml_AS_routing_ClusterTorus;
192     break;
193   case SURF_CLUSTER_FAT_TREE:
194     AS.routing = A_surfxml_AS_routing_ClusterFatTree;
195     break;
196   default:
197     AS.routing = A_surfxml_AS_routing_Cluster;
198     break;
199   }
200
201   // What an inventive way of initializing the AS that I have as ancestor :-(
202   sg_platf_new_AS_begin(&AS);
203   simgrid::surf::As *current_routing = routing_get_current();
204   static_cast<AsCluster*>(current_routing)->parse_specific_arguments(cluster);
205
206   if(cluster->loopback_bw!=0 || cluster->loopback_lat!=0){
207       ((AsCluster*)current_routing)->nb_links_per_node_++;
208       ((AsCluster*)current_routing)->has_loopback_=1;
209   }
210
211   if(cluster->limiter_link!=0){
212       ((AsCluster*)current_routing)->nb_links_per_node_++;
213       ((AsCluster*)current_routing)->has_limiter_=1;
214   }
215
216
217   //Make all hosts
218   xbt_dynar_t radical_elements = xbt_str_split(cluster->radical, ",");
219   xbt_dynar_foreach(radical_elements, iter, groups) {
220
221     xbt_dynar_t radical_ends = xbt_str_split(groups, "-");
222     int start = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 0, char *));
223     int end;
224
225     switch (xbt_dynar_length(radical_ends)) {
226     case 1:
227       end = start;
228       break;
229     case 2:
230       end = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 1, char *));
231       break;
232     default:
233       surf_parse_error("Malformed radical");
234       break;
235     }
236     for (int i = start; i <= end; i++) {
237       host_id = bprintf("%s%d%s", cluster->prefix, i, cluster->suffix);
238       link_id = bprintf("%s_link_%d", cluster->id, i);
239
240       XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%f\">", host_id, cluster->speed);
241
242       memset(&host, 0, sizeof(host));
243       host.id = host_id;
244       if ((cluster->properties != NULL) && (!xbt_dict_is_empty(cluster->properties))) {
245         xbt_dict_cursor_t cursor=NULL;
246         char *key,*data;
247         host.properties = xbt_dict_new();
248
249         xbt_dict_foreach(cluster->properties,cursor,key,data) {
250           xbt_dict_set(host.properties, key, xbt_strdup(data),free);
251         }
252       }
253       if (cluster->availability_trace && strcmp(cluster->availability_trace, "")) {
254         xbt_dict_set(patterns, "radical", bprintf("%d", i), NULL);
255         char *avail_file = xbt_str_varsubst(cluster->availability_trace, patterns);
256         XBT_DEBUG("\tavailability_file=\"%s\"", avail_file);
257         host.speed_trace = tmgr_trace_new_from_file(avail_file);
258         xbt_free(avail_file);
259       } else {
260         XBT_DEBUG("\tavailability_file=\"\"");
261       }
262
263       if (cluster->state_trace && strcmp(cluster->state_trace, "")) {
264         char *avail_file = xbt_str_varsubst(cluster->state_trace, patterns);
265         XBT_DEBUG("\tstate_file=\"%s\"", avail_file);
266         host.state_trace = tmgr_trace_new_from_file(avail_file);
267         xbt_free(avail_file);
268       } else {
269         XBT_DEBUG("\tstate_file=\"\"");
270       }
271
272       host.speed_peak = xbt_dynar_new(sizeof(double), NULL);
273       xbt_dynar_push(host.speed_peak,&cluster->speed);
274       host.pstate = 0;
275
276       //host.power_peak = cluster->power;
277       host.speed_scale = 1.0;
278       host.core_amount = cluster->core_amount;
279       host.initiallyOn = 1;
280       host.coord = "";
281       sg_platf_new_host(&host);
282       xbt_dynar_free(&host.speed_peak);
283       XBT_DEBUG("</host>");
284
285       XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%f\"\tlat=\"%f\"/>", link_id,
286                 cluster->bw, cluster->lat);
287
288
289       s_surf_parsing_link_up_down_t info_lim, info_loop;
290       // All links are saved in a matrix;
291       // every row describes a single node; every node
292       // may have multiple links.
293       // the first column may store a link from x to x if p_has_loopback is set
294       // the second column may store a limiter link if p_has_limiter is set
295       // other columns are to store one or more link for the node
296
297       //add a loopback link
298       if(cluster->loopback_bw!=0 || cluster->loopback_lat!=0){
299         char *tmp_link = bprintf("%s_loopback", link_id);
300         XBT_DEBUG("<loopback\tid=\"%s\"\tbw=\"%f\"/>", tmp_link,
301                 cluster->limiter_link);
302
303
304         memset(&link, 0, sizeof(link));
305         link.id        = tmp_link;
306         link.bandwidth = cluster->loopback_bw;
307         link.latency   = cluster->loopback_lat;
308         link.initiallyOn = 1;
309         link.policy    = SURF_LINK_FATPIPE;
310         sg_platf_new_link(&link);
311         info_loop.link_up   = Link::byName(tmp_link);
312         info_loop.link_down = info_loop.link_up;
313         free(tmp_link);
314         xbt_dynar_set(current_routing->upDownLinks,
315           rankId*(static_cast<AsCluster*>(current_routing))->nb_links_per_node_, &info_loop);
316       }
317
318       //add a limiter link (shared link to account for maximal bandwidth of the node)
319       if(cluster->limiter_link!=0){
320         char *tmp_link = bprintf("%s_limiter", link_id);
321         XBT_DEBUG("<limiter\tid=\"%s\"\tbw=\"%f\"/>", tmp_link,
322                 cluster->limiter_link);
323
324
325         memset(&link, 0, sizeof(link));
326         link.id = tmp_link;
327         link.bandwidth = cluster->limiter_link;
328         link.latency = 0;
329         link.initiallyOn = 1;
330         link.policy = SURF_LINK_SHARED;
331         sg_platf_new_link(&link);
332         info_lim.link_up = Link::byName(tmp_link);
333         info_lim.link_down = info_lim.link_up;
334         free(tmp_link);
335         auto as_cluster = static_cast<AsCluster*>(current_routing);
336         xbt_dynar_set(current_routing->upDownLinks,
337             rankId*(as_cluster)->nb_links_per_node_ + as_cluster->has_loopback_ ,
338             &info_lim);
339
340       }
341
342
343       //call the cluster function that adds the others links
344       if (cluster->topology == SURF_CLUSTER_FAT_TREE) {
345         ((AsClusterFatTree*) current_routing)->addProcessingNode(i);
346       }
347       else {
348       static_cast<AsCluster*>(current_routing)->create_links_for_node(cluster, i, rankId, rankId*
349           static_cast<AsCluster*>(current_routing)->nb_links_per_node_
350           + static_cast<AsCluster*>(current_routing)->has_loopback_
351           + static_cast<AsCluster*>(current_routing)->has_limiter_ );
352       }
353       xbt_free(link_id);
354       xbt_free(host_id);
355       rankId++;
356     }
357
358     xbt_dynar_free(&radical_ends);
359   }
360   xbt_dynar_free(&radical_elements);
361
362   // For fat trees, the links must be created once all nodes have been added
363   if(cluster->topology == SURF_CLUSTER_FAT_TREE) {
364     static_cast<simgrid::surf::AsClusterFatTree*>(current_routing)->create_links();
365   }
366   // Add a router. It is magically used thanks to the way in which surf_routing_cluster is written,
367   // and it's very useful to connect clusters together
368   XBT_DEBUG(" ");
369   XBT_DEBUG("<router id=\"%s\"/>", cluster->router_id);
370   char *newid = NULL;
371   s_sg_platf_router_cbarg_t router = SG_PLATF_ROUTER_INITIALIZER;
372   memset(&router, 0, sizeof(router));
373   router.id = cluster->router_id;
374   router.coord = "";
375   if (!router.id || !strcmp(router.id, ""))
376     router.id = newid =
377         bprintf("%s%s_router%s", cluster->prefix, cluster->id,
378                 cluster->suffix);
379   sg_platf_new_router(&router);
380   ((AsCluster*)current_routing)->router_ = (simgrid::surf::NetCard*) xbt_lib_get_or_null(as_router_lib, router.id, ROUTING_ASR_LEVEL);
381   free(newid);
382
383   //Make the backbone
384   if ((cluster->bb_bw != 0) || (cluster->bb_lat != 0)) {
385     char *link_backbone = bprintf("%s_backbone", cluster->id);
386     XBT_DEBUG("<link\tid=\"%s\" bw=\"%f\" lat=\"%f\"/>", link_backbone,
387               cluster->bb_bw, cluster->bb_lat);
388
389     memset(&link, 0, sizeof(link));
390     link.id        = link_backbone;
391     link.bandwidth = cluster->bb_bw;
392     link.latency   = cluster->bb_lat;
393     link.initiallyOn = 1;
394     link.policy    = cluster->bb_sharing_policy;
395
396     sg_platf_new_link(&link);
397
398     routing_cluster_add_backbone(Link::byName(link_backbone));
399
400     free(link_backbone);
401   }
402
403   XBT_DEBUG("</AS>");
404   sg_platf_new_AS_end();
405   XBT_DEBUG(" ");
406   xbt_dict_free(&patterns); // no op if it were never set
407
408   simgrid::surf::on_cluster(cluster);
409 }
410
411 void sg_platf_new_storage(sg_platf_storage_cbarg_t storage)
412 {
413   xbt_assert(!xbt_lib_get_or_null(storage_lib, storage->id,ROUTING_STORAGE_LEVEL),
414                "Refusing to add a second storage named \"%s\"", storage->id);
415
416   void* stype = xbt_lib_get_or_null(storage_type_lib, storage->type_id,ROUTING_STORAGE_TYPE_LEVEL);
417   xbt_assert(stype,"No storage type '%s'", storage->type_id);
418
419   XBT_DEBUG("ROUTING Create a storage name '%s' with type_id '%s' and content '%s'",
420       storage->id,
421       storage->type_id,
422       storage->content);
423
424   xbt_lib_set(storage_lib,
425       storage->id,
426       ROUTING_STORAGE_LEVEL,
427       (void *) xbt_strdup(storage->type_id));
428
429   // if storage content is not specified use the content of storage_type if any
430   if(!strcmp(storage->content,"") && strcmp(((storage_type_t) stype)->content,"")){
431     storage->content = ((storage_type_t) stype)->content;
432     storage->content_type = ((storage_type_t) stype)->content_type;
433     XBT_DEBUG("For disk '%s' content is empty, inherit the content (of type %s) from storage type '%s' ",
434         storage->id,((storage_type_t) stype)->content_type,
435         ((storage_type_t) stype)->type_id);
436   }
437
438   XBT_DEBUG("SURF storage create resource\n\t\tid '%s'\n\t\ttype '%s' "
439       "\n\t\tmodel '%s' \n\t\tcontent '%s'\n\t\tcontent_type '%s' "
440       "\n\t\tproperties '%p''\n",
441       storage->id,
442       ((storage_type_t) stype)->model,
443       ((storage_type_t) stype)->type_id,
444       storage->content,
445       storage->content_type,
446     storage->properties);
447
448   surf_storage_model->createStorage(storage->id,
449                                      ((storage_type_t) stype)->type_id,
450                                      storage->content,
451                                      storage->content_type,
452                    storage->properties,
453                                      storage->attach);
454 }
455 void sg_platf_new_storage_type(sg_platf_storage_type_cbarg_t storage_type){
456
457   xbt_assert(!xbt_lib_get_or_null(storage_type_lib, storage_type->id,ROUTING_STORAGE_TYPE_LEVEL),
458                "Reading a storage type, processing unit \"%s\" already exists", storage_type->id);
459
460   storage_type_t stype = xbt_new0(s_storage_type_t, 1);
461   stype->model = xbt_strdup(storage_type->model);
462   stype->properties = storage_type->properties;
463   stype->content = xbt_strdup(storage_type->content);
464   stype->content_type = xbt_strdup(storage_type->content_type);
465   stype->type_id = xbt_strdup(storage_type->id);
466   stype->size = storage_type->size;
467   stype->model_properties = storage_type->model_properties;
468
469   XBT_DEBUG("ROUTING Create a storage type id '%s' with model '%s', "
470       "content '%s', and content_type '%s'",
471       stype->type_id,
472       stype->model,
473       storage_type->content,
474       storage_type->content_type);
475
476   xbt_lib_set(storage_type_lib,
477       stype->type_id,
478       ROUTING_STORAGE_TYPE_LEVEL,
479       (void *) stype);
480 }
481 void sg_platf_new_mstorage(sg_platf_mstorage_cbarg_t mstorage)
482 {
483   THROW_UNIMPLEMENTED;
484 }
485
486 static void mount_free(void *p)
487 {
488   mount_t mnt = (mount_t) p;
489   xbt_free(mnt->name);
490 }
491
492 void sg_platf_new_mount(sg_platf_mount_cbarg_t mount){
493   // Verification of an existing storage
494   xbt_assert(xbt_lib_get_or_null(storage_lib, mount->storageId, ROUTING_STORAGE_LEVEL),
495       "Cannot mount non-existent disk \"%s\"", mount->storageId);
496
497   XBT_DEBUG("ROUTING Mount '%s' on '%s'",mount->storageId, mount->name);
498
499   s_mount_t mnt;
500   mnt.storage = surf_storage_resource_priv(surf_storage_resource_by_name(mount->storageId));
501   mnt.name = xbt_strdup(mount->name);
502
503   if(!mount_list){
504     XBT_DEBUG("Create a Mount list for %s",A_surfxml_host_id);
505     mount_list = xbt_dynar_new(sizeof(s_mount_t), mount_free);
506   }
507   xbt_dynar_push(mount_list, &mnt);
508 }
509
510 void sg_platf_new_route(sg_platf_route_cbarg_t route)
511 {
512   routing_get_current()->addRoute(route);
513 }
514
515 void sg_platf_new_bypassRoute(sg_platf_route_cbarg_t bypassRoute)
516 {
517   routing_get_current()->parseBypassroute(bypassRoute);
518 }
519
520 void sg_platf_new_process(sg_platf_process_cbarg_t process)
521 {
522   xbt_assert(simix_global,"Cannot create process without SIMIX.");
523
524   sg_host_t host = sg_host_by_name(process->host);
525   if (!host) {
526     // The requested host does not exist. Do a nice message to the user
527     char *tmp = bprintf("Cannot create process '%s': host '%s' does not exist\nExisting hosts: '",process->function, process->host);
528     xbt_strbuff_t msg = xbt_strbuff_new_from(tmp);
529     free(tmp);
530     xbt_dynar_t all_hosts = xbt_dynar_sort_strings(sg_hosts_as_dynar());
531     simgrid::s4u::Host* host;
532     unsigned int cursor;
533     xbt_dynar_foreach(all_hosts,cursor, host) {
534       xbt_strbuff_append(msg,host->name().c_str());
535       xbt_strbuff_append(msg,"', '");
536       if (msg->used > 1024) {
537         msg->data[msg->used-3]='\0';
538         msg->used -= 3;
539
540         xbt_strbuff_append(msg," ...(list truncated)......");// That will be shortened by 3 chars when existing the loop
541       }
542     }
543     msg->data[msg->used-3]='\0';
544     xbt_die("%s", msg->data);
545   }
546   xbt_main_func_t parse_code = SIMIX_get_registered_function(process->function);
547   xbt_assert(parse_code, "Function '%s' unknown", process->function);
548
549   double start_time = process->start_time;
550   double kill_time  = process->kill_time;
551   int auto_restart = process->on_failure == SURF_PROCESS_ON_FAILURE_DIE ? 0 : 1;
552
553   smx_process_arg_t arg = NULL;
554   smx_process_t process_created = NULL;
555
556   arg = xbt_new0(s_smx_process_arg_t, 1);
557   arg->code = parse_code;
558   arg->data = NULL;
559   arg->hostname = sg_host_get_name(host);
560   arg->argc = process->argc;
561   arg->argv = xbt_new(char *,process->argc);
562   int i;
563   for (i=0; i<process->argc; i++)
564     arg->argv[i] = xbt_strdup(process->argv[i]);
565   arg->name = xbt_strdup(arg->argv[0]);
566   arg->kill_time = kill_time;
567   arg->properties = current_property_set;
568   if (!sg_host_simix(host)->boot_processes) {
569     sg_host_simix(host)->boot_processes = xbt_dynar_new(sizeof(smx_process_arg_t), _SIMIX_host_free_process_arg);
570   }
571   xbt_dynar_push_as(sg_host_simix(host)->boot_processes,smx_process_arg_t,arg);
572
573   if (start_time > SIMIX_get_clock()) {
574     arg = xbt_new0(s_smx_process_arg_t, 1);
575     arg->name = (char*)(process->argv)[0];
576     arg->code = parse_code;
577     arg->data = NULL;
578     arg->hostname = sg_host_get_name(host);
579     arg->argc = process->argc;
580     arg->argv = (char**)(process->argv);
581     arg->kill_time = kill_time;
582     arg->properties = current_property_set;
583
584     XBT_DEBUG("Process %s(%s) will be started at time %f", arg->name,
585            arg->hostname, start_time);
586     SIMIX_timer_set(start_time, [](void* arg) {
587       SIMIX_process_create_from_wrapper((smx_process_arg_t) arg);
588     }, arg);
589   } else {                      // start_time <= SIMIX_get_clock()
590     XBT_DEBUG("Starting Process %s(%s) right now", arg->name, sg_host_get_name(host));
591
592     if (simix_global->create_process_function)
593       process_created = simix_global->create_process_function(
594           arg->name,
595                                             parse_code,
596                                             NULL,
597                                             sg_host_get_name(host),
598                                             kill_time,
599                                             process->argc,
600                                             (char**)(process->argv),
601                                             current_property_set,
602                                             auto_restart, NULL);
603     else
604       process_created = simcall_process_create(arg->name, parse_code, NULL, sg_host_get_name(host), kill_time, process->argc,
605           (char**)process->argv, current_property_set,auto_restart);
606
607     /* verify if process has been created (won't be the case if the host is currently dead, but that's fine) */
608     if (!process_created) {
609       return;
610     }
611   }
612   current_property_set = NULL;
613 }
614
615 void sg_platf_begin() { /* Do nothing: just for symmetry of user code */ }
616
617 void sg_platf_end() {
618   simgrid::surf::on_postparse();
619 }
620
621 void sg_platf_new_AS_begin(sg_platf_AS_cbarg_t AS)
622 {
623   if (!surf_parse_models_setup_already_called) {
624     /* Initialize the surf models. That must be done after we got all config, and before we need the models.
625      * That is, after the last <config> tag, if any, and before the first of cluster|peer|AS|trace|trace_connect
626      *
627      * I'm not sure for <trace> and <trace_connect>, there may be a bug here
628      * (FIXME: check it out by creating a file beginning with one of these tags)
629      * but cluster and peer create ASes internally, so putting the code in there is ok.
630      *
631      * TODO, There used to be a guard protecting here against
632      * xbt_dynar_length(sg_platf_AS_begin_cb_list) because we don't want to
633      * initialize the models if we are parsing the file to get the deployment.
634      * That could happen if the same file would be used for platf and deploy:
635      * it'd contain AS tags even during the deploy parsing. Removing that guard
636      * would result of the models to get re-inited when parsing for deploy.
637      * Currently using the same file for platform and deployment is broken
638      * however. This guard will have to ba adapted in order to make this feature
639      * work again.
640      */
641     surf_parse_models_setup_already_called = 1;
642     surf_config_models_setup();
643   }
644
645   routing_AS_begin(AS);
646   if (TRACE_is_enabled())
647     sg_instr_AS_begin(AS);
648 }
649
650 void sg_platf_new_AS_end()
651 {
652   routing_AS_end();
653   if (TRACE_is_enabled())
654     sg_instr_AS_end();
655 }