Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Java binding (on going) - Adrien
[simgrid.git] / include / simgrid / platf.h
1 /* platf.h - Public interface to the SimGrid platforms                      */
2
3 /* Copyright (c) 2004-2012. 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 #ifndef SG_PLATF_H
9 #define SG_PLATF_H
10
11 #include <xbt.h>
12
13 typedef void *sg_routing_link_t; /* The actual type is model-dependent so use void* instead*/
14 typedef struct s_routing_edge *sg_routing_edge_t;
15
16 XBT_PUBLIC(sg_routing_edge_t) sg_routing_edge_by_name_or_null(const char *name);
17
18 /** Defines whether a given resource is working or not */
19 typedef enum {
20   SURF_RESOURCE_ON = 1,                   /**< Up & ready        */
21   SURF_RESOURCE_OFF = 0                   /**< Down & broken     */
22 } e_surf_resource_state_t;
23
24 typedef enum {
25   SURF_LINK_FULLDUPLEX = 2,
26   SURF_LINK_SHARED = 1,
27   SURF_LINK_FATPIPE = 0
28 } e_surf_link_sharing_policy_t;
29
30 typedef enum {
31   SURF_TRACE_CONNECT_KIND_HOST_AVAIL = 4,
32   SURF_TRACE_CONNECT_KIND_POWER = 3,
33   SURF_TRACE_CONNECT_KIND_LINK_AVAIL = 2,
34   SURF_TRACE_CONNECT_KIND_BANDWIDTH = 1,
35   SURF_TRACE_CONNECT_KIND_LATENCY = 0
36 } e_surf_trace_connect_kind_t;
37
38 typedef enum {
39   SURF_PROCESS_ON_FAILURE_DIE = 1,
40   SURF_PROCESS_ON_FAILURE_RESTART = 0
41 } e_surf_process_on_failure_t;
42
43
44 /* FIXME: Where should the VM state be defined? */
45 typedef enum {
46   /* created, but not yet started */
47   SURF_VM_STATE_CREATED,
48
49   SURF_VM_STATE_RUNNING,
50   SURF_VM_STATE_MIGRATING,
51
52   /* Suspend/resume does not involve disk I/O, so we assume there is no transition states. */
53   SURF_VM_STATE_SUSPENDED,
54
55   /* Save/restore involves disk I/O, so there should be transition states. */
56   SURF_VM_STATE_SAVING,
57   SURF_VM_STATE_SAVED,
58   SURF_VM_STATE_RESTORING,
59
60 } e_surf_vm_state_t;
61
62 typedef struct ws_params {
63   int ncpus;
64   long ramsize;
65   int overcommit;
66
67   /* The size of other states than memory pages, which is out-of-scope of dirty
68    * page tracking. */
69   long devsize;
70   int skip_stage2;
71   double max_downtime;
72
73   double dp_rate;
74   double dp_cap;
75 } s_ws_params_t, *ws_params_t;
76
77 typedef struct tmgr_trace *tmgr_trace_t; /**< Opaque structure defining an availability trace */
78
79 /** opaque structure defining a event generator for availability based on a probability distribution */
80 typedef struct probabilist_event_generator *probabilist_event_generator_t;
81
82 XBT_PUBLIC(tmgr_trace_t) tmgr_trace_new_from_file(const char *filename);
83 XBT_PUBLIC(tmgr_trace_t) tmgr_trace_new_from_string(const char *id,
84                                                     const char *input,
85                                                     double periodicity);
86
87 XBT_PUBLIC(tmgr_trace_t) tmgr_trace_generator_value(const char *id,
88                                               probabilist_event_generator_t date_generator,
89                                               probabilist_event_generator_t value_generator);
90 XBT_PUBLIC(tmgr_trace_t) tmgr_trace_generator_state(const char *id,
91                                               probabilist_event_generator_t date_generator,
92                                               e_surf_resource_state_t first_event_value);
93 XBT_PUBLIC(tmgr_trace_t) tmgr_trace_generator_avail_unavail(const char *id,
94                                               probabilist_event_generator_t avail_duration_generator,
95                                               probabilist_event_generator_t unavail_duration_generator,
96                                               e_surf_resource_state_t first_event_value);
97
98 XBT_PUBLIC(probabilist_event_generator_t) tmgr_event_generator_new_uniform(const char* id,
99                                                                            double min,
100                                                                            double max);
101 XBT_PUBLIC(probabilist_event_generator_t) tmgr_event_generator_new_exponential(const char* id,
102                                                                            double rate);
103 XBT_PUBLIC(probabilist_event_generator_t) tmgr_event_generator_new_weibull(const char* id,
104                                                                            double scale,
105                                                                            double shape);
106 typedef xbt_dictelm_t sg_host_t;
107 static inline char* sg_host_name(sg_host_t host) {
108   return host->key;
109 }
110
111
112 /*
113  * Platform creation functions. Instead of passing 123 arguments to the creation functions
114  * (one for each possible XML attribute), we pass structures containing them all. It removes the
115  * chances of switching arguments by error, and reduce the burden when we add a new attribute:
116  * old models can just continue to ignore it without having to update their headers.
117  *
118  * It shouldn't be too costly at runtime, provided that structures living on the stack are
119  * used, instead of malloced structures.
120  */
121
122 typedef struct {
123   const char* id;
124   double power_peak;
125   int core_amount;
126   double power_scale;
127   tmgr_trace_t power_trace;
128   e_surf_resource_state_t initial_state;
129   tmgr_trace_t state_trace;
130   const char* coord;
131   xbt_dict_t properties;
132 } s_sg_platf_host_cbarg_t, *sg_platf_host_cbarg_t;
133
134 #define SG_PLATF_HOST_INITIALIZER { \
135     .id = NULL,\
136     .power_peak = 0,\
137     .core_amount = 1.,\
138     .power_scale = 1,\
139     .initial_state = SURF_RESOURCE_ON,\
140     .power_trace = NULL,\
141     .state_trace = NULL,\
142     .coord = NULL,\
143     .properties = NULL\
144     }
145
146 typedef struct {
147   const char* id;
148   const char* link_up;
149   const char* link_down;
150 } s_sg_platf_host_link_cbarg_t, *sg_platf_host_link_cbarg_t;
151
152 #define SG_PLATF_HOST_LINK_INITIALIZER {NULL,NULL,NULL}
153
154 typedef struct {
155   const char* id;
156   const char* coord;
157 } s_sg_platf_router_cbarg_t, *sg_platf_router_cbarg_t;
158
159 #define SG_PLATF_ROUTER_INITIALIZER {NULL,NULL}
160
161 typedef struct {
162   const char* id;
163   double bandwidth;
164   tmgr_trace_t bandwidth_trace;
165   double latency;
166   tmgr_trace_t latency_trace;
167   e_surf_resource_state_t state;
168   tmgr_trace_t state_trace;
169   e_surf_link_sharing_policy_t policy;
170   xbt_dict_t properties;
171 } s_sg_platf_link_cbarg_t, *sg_platf_link_cbarg_t;
172
173 #define SG_PLATF_LINK_INITIALIZER {\
174   .id = NULL,\
175   .bandwidth = 0.,\
176   .bandwidth_trace = NULL,\
177   .latency = 0.,\
178   .latency_trace = NULL,\
179   .state = SURF_RESOURCE_ON,\
180   .state_trace = NULL,\
181   .policy = SURF_LINK_SHARED,\
182   .properties = NULL\
183 }
184
185 typedef struct s_sg_platf_peer_cbarg *sg_platf_peer_cbarg_t;
186 typedef struct s_sg_platf_peer_cbarg {
187   const char* id;
188   double power;
189   double bw_in;
190   double bw_out;
191   double lat;
192   const char* coord;
193   tmgr_trace_t availability_trace;
194   tmgr_trace_t state_trace;
195 } s_sg_platf_peer_cbarg_t;
196
197 #define SG_PLATF_PEER_INITIALIZER {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}
198
199 typedef struct s_sg_platf_route_cbarg *sg_platf_route_cbarg_t;
200 typedef struct s_sg_platf_route_cbarg {
201   int symmetrical;
202   const char *src;
203   const char *dst;
204   sg_routing_edge_t gw_src;
205   sg_routing_edge_t gw_dst;
206   xbt_dynar_t link_list;
207 } s_sg_platf_route_cbarg_t;
208
209 #define SG_PLATF_ROUTE_INITIALIZER {TRUE,NULL,NULL,NULL,NULL,NULL}
210
211 typedef struct s_sg_platf_cluster_cbarg *sg_platf_cluster_cbarg_t;
212 typedef struct s_sg_platf_cluster_cbarg {
213   const char* id;
214   const char* prefix;
215   const char* suffix;
216   const char* radical;
217   double power;
218   int core_amount;
219   double bw;
220   double lat;
221   double bb_bw;
222   double bb_lat;
223   double loopback_bw;
224   double loopback_lat;
225   double limiter_link;
226   const char* router_id;
227   e_surf_link_sharing_policy_t sharing_policy;
228   e_surf_link_sharing_policy_t bb_sharing_policy;
229   const char* availability_trace; //don't convert to tmgr_trace_t since there is a trace per host and some rewriting is needed
230   const char* state_trace;
231 } s_sg_platf_cluster_cbarg_t;
232
233 #define SG_PLATF_CLUSTER_INITIALIZER {NULL,NULL,NULL,NULL,NULL,NULL \
234   ,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}
235
236 typedef struct s_sg_platf_cabinet_cbarg *sg_platf_cabinet_cbarg_t;
237 typedef struct s_sg_platf_cabinet_cbarg {
238   const char* id;
239   const char* prefix;
240   const char* suffix;
241   const char* radical;
242   double power;
243   double bw;
244   double lat;
245 } s_sg_platf_cabinet_cbarg_t;
246
247 #define SG_PLATF_CABINET_INITIALIZER {NULL,NULL,NULL,NULL,NULL,NULL,NULL}
248
249 typedef struct {
250   const char* id;
251   const char* type_id;
252   const char* content;
253   xbt_dict_t properties;
254 } s_sg_platf_storage_cbarg_t, *sg_platf_storage_cbarg_t;
255
256 #define SG_PLATF_STORAGE_INITIALIZER {NULL,NULL,NULL,NULL}
257
258 typedef struct {
259   const char* id;
260   const char* model;
261   const char* content;
262   xbt_dict_t properties;
263   unsigned long size; /* size in Gbytes */
264 } s_sg_platf_storage_type_cbarg_t, *sg_platf_storage_type_cbarg_t;
265
266 #define SG_PLATF_STORAGE_TYPE_INITIALIZER {NULL,NULL,NULL,NULL,NULL}
267
268 typedef struct {
269   const char* type_id;
270   const char* name;
271 } s_sg_platf_mstorage_cbarg_t, *sg_platf_mstorage_cbarg_t;
272
273 #define SG_PLATF_MSTORAGE_INITIALIZER {NULL,NULL}
274
275 typedef struct {
276   const char* id;
277   const char* name;
278 } s_sg_platf_mount_cbarg_t, *sg_platf_mount_cbarg_t;
279
280 #define SG_PLATF_MOUNT_INITIALIZER {NULL,NULL}
281
282 typedef struct s_sg_platf_prop_cbarg *sg_platf_prop_cbarg_t;
283 typedef struct s_sg_platf_prop_cbarg {
284   const char *id;
285   const char *value;
286 } s_sg_platf_prop_cbarg_t;
287
288 #define SG_PLATF_PROP_INITIALIZER {NULL,NULL}
289
290 typedef struct s_sg_platf_trace_cbarg *sg_platf_trace_cbarg_t;
291 typedef struct s_sg_platf_trace_cbarg {
292   const char *id;
293   const char *file;
294   double periodicity;
295   const char *pc_data;
296 } s_sg_platf_trace_cbarg_t;
297
298 #define SG_PLATF_TRACE_INITIALIZER {NULL,NULL,NULL,NULL}
299
300 typedef struct s_sg_platf_trace_connect_cbarg *sg_platf_trace_connect_cbarg_t;
301 typedef struct s_sg_platf_trace_connect_cbarg {
302   e_surf_trace_connect_kind_t kind;
303   const char *trace;
304   const char *element;
305 } s_sg_platf_trace_connect_cbarg_t;
306
307 #define SG_PLATF_TRACE_CONNECT_INITIALIZER {NULL,NULL,NULL}
308
309 typedef struct s_sg_platf_process_cbarg *sg_platf_process_cbarg_t;
310 typedef struct s_sg_platf_process_cbarg {
311   const char **argv;
312   int argc;
313   xbt_dict_t properties;
314   const char *host;
315   const char *function;
316   double start_time;
317   double kill_time;
318   e_surf_process_on_failure_t on_failure;
319 } s_sg_platf_process_cbarg_t;
320
321 #define SG_PLATF_PROCESS_INITIALIZER {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}
322
323 typedef struct s_sg_platf_AS_cbarg *sg_platf_AS_cbarg_t;
324 typedef struct s_sg_platf_AS_cbarg {
325   const char *id;
326   int routing;
327 } s_sg_platf_AS_cbarg_t;
328
329 #define SG_PLATF_AS_INITIALIZER {NULL,0}
330
331 /* ***************************************** */
332 /* TUTORIAL: New TAG                         */
333
334 typedef struct s_sg_platf_gpu_cbarg *sg_platf_gpu_cbarg_t;
335 typedef struct s_sg_platf_gpu_cbarg {
336   const char *name;
337 } s_sg_platf_gpu_cbarg_t;
338
339 #define SG_PLATF_GPU_INITIALIZER {NULL}
340
341 /* ***************************************** */
342
343 XBT_PUBLIC(void) sg_platf_begin(void);  // Start a new platform
344 XBT_PUBLIC(void) sg_platf_end(void); // Finish the creation of the platform
345
346 XBT_PUBLIC(void) sg_platf_new_AS_begin(sg_platf_AS_cbarg_t AS); // Begin description of new AS
347 XBT_PUBLIC(void) sg_platf_new_AS_end(void);                            // That AS is fully described
348
349 XBT_PUBLIC(void) sg_platf_new_host   (sg_platf_host_cbarg_t   host);   // Add an host   to the currently described AS
350 XBT_PUBLIC(void) sg_platf_new_host_link(sg_platf_host_link_cbarg_t h); // Add an host_link to the currently described AS
351 XBT_PUBLIC(void) sg_platf_new_router (sg_platf_router_cbarg_t router); // Add a router  to the currently described AS
352 XBT_PUBLIC(void) sg_platf_new_link   (sg_platf_link_cbarg_t link);     // Add a link    to the currently described AS
353 XBT_PUBLIC(void) sg_platf_new_peer   (sg_platf_peer_cbarg_t peer);     // Add a peer    to the currently described AS
354 XBT_PUBLIC(void) sg_platf_new_cluster(sg_platf_cluster_cbarg_t clust); // Add a cluster to the currently described AS
355 XBT_PUBLIC(void) sg_platf_new_cabinet(sg_platf_cabinet_cbarg_t cabinet); // Add a cabinet to the currently described AS
356
357 XBT_PUBLIC(void) sg_platf_new_route (sg_platf_route_cbarg_t route); // Add a route
358 XBT_PUBLIC(void) sg_platf_new_ASroute (sg_platf_route_cbarg_t ASroute); // Add an ASroute
359 XBT_PUBLIC(void) sg_platf_new_bypassRoute (sg_platf_route_cbarg_t bypassroute); // Add a bypassRoute
360 XBT_PUBLIC(void) sg_platf_new_bypassASroute (sg_platf_route_cbarg_t bypassASroute); // Add an bypassASroute
361 XBT_PUBLIC(void) sg_platf_new_prop (sg_platf_prop_cbarg_t prop); // Add a prop
362
363 XBT_PUBLIC(void) sg_platf_new_trace(sg_platf_trace_cbarg_t trace);
364 XBT_PUBLIC(void) sg_platf_trace_connect(sg_platf_trace_connect_cbarg_t trace_connect);
365
366 XBT_PUBLIC(void) sg_platf_new_storage(sg_platf_storage_cbarg_t storage); // Add a storage to the currently described AS
367 XBT_PUBLIC(void) sg_platf_new_storage(sg_platf_storage_cbarg_t storage); // Add a storage to the currently described AS
368 XBT_PUBLIC(void) sg_platf_new_mstorage(sg_platf_mstorage_cbarg_t mstorage);
369 XBT_PUBLIC(void) sg_platf_new_storage_type(sg_platf_storage_type_cbarg_t storage_type);
370 XBT_PUBLIC(void) sg_platf_new_mount(sg_platf_mount_cbarg_t mount);
371
372 XBT_PUBLIC(void) sg_platf_new_process(sg_platf_process_cbarg_t process);
373
374 /* ***************************************** */
375 /* TUTORIAL: New TAG                         */
376 XBT_PUBLIC(void) sg_platf_new_gpu(sg_platf_gpu_cbarg_t gpu);
377 /* ***************************************** */
378
379 // Add route and Asroute without xml file with those functions
380 XBT_PUBLIC(void) sg_platf_route_begin (sg_platf_route_cbarg_t route); // Initialize route
381 XBT_PUBLIC(void) sg_platf_route_end (sg_platf_route_cbarg_t route); // Finalize and add a route
382
383 XBT_PUBLIC(void) sg_platf_ASroute_begin (sg_platf_route_cbarg_t ASroute); // Initialize ASroute
384 XBT_PUBLIC(void) sg_platf_ASroute_end (sg_platf_route_cbarg_t ASroute); // Finalize and add a ASroute
385
386 XBT_PUBLIC(void) sg_platf_route_add_link (const char* link_id, sg_platf_route_cbarg_t route); // Add a link to link list
387 XBT_PUBLIC(void) sg_platf_ASroute_add_link (const char* link_id, sg_platf_route_cbarg_t ASroute); // Add a link to link list
388
389 typedef void (*sg_platf_process_cb_t)(sg_platf_process_cbarg_t);
390 XBT_PUBLIC(void) sg_platf_process_add_cb(sg_platf_process_cb_t fct);
391
392
393 #endif                          /* SG_PLATF_H */