Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'hypervisor' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid into hypervisor
[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
76   /* set migration speed */
77   double mig_speed;
78 } s_ws_params_t, *ws_params_t;
79
80 typedef struct tmgr_trace *tmgr_trace_t; /**< Opaque structure defining an availability trace */
81
82 /** opaque structure defining a event generator for availability based on a probability distribution */
83 typedef struct probabilist_event_generator *probabilist_event_generator_t;
84
85 XBT_PUBLIC(tmgr_trace_t) tmgr_trace_new_from_file(const char *filename);
86 XBT_PUBLIC(tmgr_trace_t) tmgr_trace_new_from_string(const char *id,
87                                                     const char *input,
88                                                     double periodicity);
89
90 XBT_PUBLIC(tmgr_trace_t) tmgr_trace_generator_value(const char *id,
91                                               probabilist_event_generator_t date_generator,
92                                               probabilist_event_generator_t value_generator);
93 XBT_PUBLIC(tmgr_trace_t) tmgr_trace_generator_state(const char *id,
94                                               probabilist_event_generator_t date_generator,
95                                               e_surf_resource_state_t first_event_value);
96 XBT_PUBLIC(tmgr_trace_t) tmgr_trace_generator_avail_unavail(const char *id,
97                                               probabilist_event_generator_t avail_duration_generator,
98                                               probabilist_event_generator_t unavail_duration_generator,
99                                               e_surf_resource_state_t first_event_value);
100
101 XBT_PUBLIC(probabilist_event_generator_t) tmgr_event_generator_new_uniform(const char* id,
102                                                                            double min,
103                                                                            double max);
104 XBT_PUBLIC(probabilist_event_generator_t) tmgr_event_generator_new_exponential(const char* id,
105                                                                            double rate);
106 XBT_PUBLIC(probabilist_event_generator_t) tmgr_event_generator_new_weibull(const char* id,
107                                                                            double scale,
108                                                                            double shape);
109 typedef xbt_dictelm_t sg_host_t;
110 static inline char* sg_host_name(sg_host_t host) {
111   return host->key;
112 }
113
114
115 /*
116  * Platform creation functions. Instead of passing 123 arguments to the creation functions
117  * (one for each possible XML attribute), we pass structures containing them all. It removes the
118  * chances of switching arguments by error, and reduce the burden when we add a new attribute:
119  * old models can just continue to ignore it without having to update their headers.
120  *
121  * It shouldn't be too costly at runtime, provided that structures living on the stack are
122  * used, instead of malloced structures.
123  */
124
125 typedef struct {
126   const char* id;
127   double power_peak;
128   int core_amount;
129   double power_scale;
130   tmgr_trace_t power_trace;
131   e_surf_resource_state_t initial_state;
132   tmgr_trace_t state_trace;
133   const char* coord;
134   xbt_dict_t properties;
135 } s_sg_platf_host_cbarg_t, *sg_platf_host_cbarg_t;
136
137 #define SG_PLATF_HOST_INITIALIZER { \
138     .id = NULL,\
139     .power_peak = 0,\
140     .core_amount = 1.,\
141     .power_scale = 1,\
142     .initial_state = SURF_RESOURCE_ON,\
143     .power_trace = NULL,\
144     .state_trace = NULL,\
145     .coord = NULL,\
146     .properties = NULL\
147     }
148
149 typedef struct {
150   const char* id;
151   const char* link_up;
152   const char* link_down;
153 } s_sg_platf_host_link_cbarg_t, *sg_platf_host_link_cbarg_t;
154
155 #define SG_PLATF_HOST_LINK_INITIALIZER {NULL,NULL,NULL}
156
157 typedef struct {
158   const char* id;
159   const char* coord;
160 } s_sg_platf_router_cbarg_t, *sg_platf_router_cbarg_t;
161
162 #define SG_PLATF_ROUTER_INITIALIZER {NULL,NULL}
163
164 typedef struct {
165   const char* id;
166   double bandwidth;
167   tmgr_trace_t bandwidth_trace;
168   double latency;
169   tmgr_trace_t latency_trace;
170   e_surf_resource_state_t state;
171   tmgr_trace_t state_trace;
172   e_surf_link_sharing_policy_t policy;
173   xbt_dict_t properties;
174 } s_sg_platf_link_cbarg_t, *sg_platf_link_cbarg_t;
175
176 #define SG_PLATF_LINK_INITIALIZER {\
177   .id = NULL,\
178   .bandwidth = 0.,\
179   .bandwidth_trace = NULL,\
180   .latency = 0.,\
181   .latency_trace = NULL,\
182   .state = SURF_RESOURCE_ON,\
183   .state_trace = NULL,\
184   .policy = SURF_LINK_SHARED,\
185   .properties = NULL\
186 }
187
188 typedef struct s_sg_platf_peer_cbarg *sg_platf_peer_cbarg_t;
189 typedef struct s_sg_platf_peer_cbarg {
190   const char* id;
191   double power;
192   double bw_in;
193   double bw_out;
194   double lat;
195   const char* coord;
196   tmgr_trace_t availability_trace;
197   tmgr_trace_t state_trace;
198 } s_sg_platf_peer_cbarg_t;
199
200 #define SG_PLATF_PEER_INITIALIZER {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}
201
202 typedef struct s_sg_platf_route_cbarg *sg_platf_route_cbarg_t;
203 typedef struct s_sg_platf_route_cbarg {
204   int symmetrical;
205   const char *src;
206   const char *dst;
207   sg_routing_edge_t gw_src;
208   sg_routing_edge_t gw_dst;
209   xbt_dynar_t link_list;
210 } s_sg_platf_route_cbarg_t;
211
212 #define SG_PLATF_ROUTE_INITIALIZER {TRUE,NULL,NULL,NULL,NULL,NULL}
213
214 typedef struct s_sg_platf_cluster_cbarg *sg_platf_cluster_cbarg_t;
215 typedef struct s_sg_platf_cluster_cbarg {
216   const char* id;
217   const char* prefix;
218   const char* suffix;
219   const char* radical;
220   double power;
221   int core_amount;
222   double bw;
223   double lat;
224   double bb_bw;
225   double bb_lat;
226   double loopback_bw;
227   double loopback_lat;
228   double limiter_link;
229   const char* router_id;
230   e_surf_link_sharing_policy_t sharing_policy;
231   e_surf_link_sharing_policy_t bb_sharing_policy;
232   const char* availability_trace; //don't convert to tmgr_trace_t since there is a trace per host and some rewriting is needed
233   const char* state_trace;
234 } s_sg_platf_cluster_cbarg_t;
235
236 #define SG_PLATF_CLUSTER_INITIALIZER {NULL,NULL,NULL,NULL,NULL,NULL \
237   ,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}
238
239 typedef struct s_sg_platf_cabinet_cbarg *sg_platf_cabinet_cbarg_t;
240 typedef struct s_sg_platf_cabinet_cbarg {
241   const char* id;
242   const char* prefix;
243   const char* suffix;
244   const char* radical;
245   double power;
246   double bw;
247   double lat;
248 } s_sg_platf_cabinet_cbarg_t;
249
250 #define SG_PLATF_CABINET_INITIALIZER {NULL,NULL,NULL,NULL,NULL,NULL,NULL}
251
252 typedef struct {
253   const char* id;
254   const char* type_id;
255   const char* content;
256   xbt_dict_t properties;
257 } s_sg_platf_storage_cbarg_t, *sg_platf_storage_cbarg_t;
258
259 #define SG_PLATF_STORAGE_INITIALIZER {NULL,NULL,NULL,NULL}
260
261 typedef struct {
262   const char* id;
263   const char* model;
264   const char* content;
265   xbt_dict_t properties;
266   unsigned long size; /* size in Gbytes */
267 } s_sg_platf_storage_type_cbarg_t, *sg_platf_storage_type_cbarg_t;
268
269 #define SG_PLATF_STORAGE_TYPE_INITIALIZER {NULL,NULL,NULL,NULL,NULL}
270
271 typedef struct {
272   const char* type_id;
273   const char* name;
274 } s_sg_platf_mstorage_cbarg_t, *sg_platf_mstorage_cbarg_t;
275
276 #define SG_PLATF_MSTORAGE_INITIALIZER {NULL,NULL}
277
278 typedef struct {
279   const char* id;
280   const char* name;
281 } s_sg_platf_mount_cbarg_t, *sg_platf_mount_cbarg_t;
282
283 #define SG_PLATF_MOUNT_INITIALIZER {NULL,NULL}
284
285 typedef struct s_sg_platf_prop_cbarg *sg_platf_prop_cbarg_t;
286 typedef struct s_sg_platf_prop_cbarg {
287   const char *id;
288   const char *value;
289 } s_sg_platf_prop_cbarg_t;
290
291 #define SG_PLATF_PROP_INITIALIZER {NULL,NULL}
292
293 typedef struct s_sg_platf_trace_cbarg *sg_platf_trace_cbarg_t;
294 typedef struct s_sg_platf_trace_cbarg {
295   const char *id;
296   const char *file;
297   double periodicity;
298   const char *pc_data;
299 } s_sg_platf_trace_cbarg_t;
300
301 #define SG_PLATF_TRACE_INITIALIZER {NULL,NULL,NULL,NULL}
302
303 typedef struct s_sg_platf_trace_connect_cbarg *sg_platf_trace_connect_cbarg_t;
304 typedef struct s_sg_platf_trace_connect_cbarg {
305   e_surf_trace_connect_kind_t kind;
306   const char *trace;
307   const char *element;
308 } s_sg_platf_trace_connect_cbarg_t;
309
310 #define SG_PLATF_TRACE_CONNECT_INITIALIZER {NULL,NULL,NULL}
311
312 typedef struct s_sg_platf_process_cbarg *sg_platf_process_cbarg_t;
313 typedef struct s_sg_platf_process_cbarg {
314   const char **argv;
315   int argc;
316   xbt_dict_t properties;
317   const char *host;
318   const char *function;
319   double start_time;
320   double kill_time;
321   e_surf_process_on_failure_t on_failure;
322 } s_sg_platf_process_cbarg_t;
323
324 #define SG_PLATF_PROCESS_INITIALIZER {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}
325
326 typedef struct s_sg_platf_AS_cbarg *sg_platf_AS_cbarg_t;
327 typedef struct s_sg_platf_AS_cbarg {
328   const char *id;
329   int routing;
330 } s_sg_platf_AS_cbarg_t;
331
332 #define SG_PLATF_AS_INITIALIZER {NULL,0}
333
334 /* ***************************************** */
335 /* TUTORIAL: New TAG                         */
336
337 typedef struct s_sg_platf_gpu_cbarg *sg_platf_gpu_cbarg_t;
338 typedef struct s_sg_platf_gpu_cbarg {
339   const char *name;
340 } s_sg_platf_gpu_cbarg_t;
341
342 #define SG_PLATF_GPU_INITIALIZER {NULL}
343
344 /* ***************************************** */
345
346 XBT_PUBLIC(void) sg_platf_begin(void);  // Start a new platform
347 XBT_PUBLIC(void) sg_platf_end(void); // Finish the creation of the platform
348
349 XBT_PUBLIC(void) sg_platf_new_AS_begin(sg_platf_AS_cbarg_t AS); // Begin description of new AS
350 XBT_PUBLIC(void) sg_platf_new_AS_end(void);                            // That AS is fully described
351
352 XBT_PUBLIC(void) sg_platf_new_host   (sg_platf_host_cbarg_t   host);   // Add an host   to the currently described AS
353 XBT_PUBLIC(void) sg_platf_new_host_link(sg_platf_host_link_cbarg_t h); // Add an host_link to the currently described AS
354 XBT_PUBLIC(void) sg_platf_new_router (sg_platf_router_cbarg_t router); // Add a router  to the currently described AS
355 XBT_PUBLIC(void) sg_platf_new_link   (sg_platf_link_cbarg_t link);     // Add a link    to the currently described AS
356 XBT_PUBLIC(void) sg_platf_new_peer   (sg_platf_peer_cbarg_t peer);     // Add a peer    to the currently described AS
357 XBT_PUBLIC(void) sg_platf_new_cluster(sg_platf_cluster_cbarg_t clust); // Add a cluster to the currently described AS
358 XBT_PUBLIC(void) sg_platf_new_cabinet(sg_platf_cabinet_cbarg_t cabinet); // Add a cabinet to the currently described AS
359
360 XBT_PUBLIC(void) sg_platf_new_route (sg_platf_route_cbarg_t route); // Add a route
361 XBT_PUBLIC(void) sg_platf_new_ASroute (sg_platf_route_cbarg_t ASroute); // Add an ASroute
362 XBT_PUBLIC(void) sg_platf_new_bypassRoute (sg_platf_route_cbarg_t bypassroute); // Add a bypassRoute
363 XBT_PUBLIC(void) sg_platf_new_bypassASroute (sg_platf_route_cbarg_t bypassASroute); // Add an bypassASroute
364 XBT_PUBLIC(void) sg_platf_new_prop (sg_platf_prop_cbarg_t prop); // Add a prop
365
366 XBT_PUBLIC(void) sg_platf_new_trace(sg_platf_trace_cbarg_t trace);
367 XBT_PUBLIC(void) sg_platf_trace_connect(sg_platf_trace_connect_cbarg_t trace_connect);
368
369 XBT_PUBLIC(void) sg_platf_new_storage(sg_platf_storage_cbarg_t storage); // Add a storage to the currently described AS
370 XBT_PUBLIC(void) sg_platf_new_storage(sg_platf_storage_cbarg_t storage); // Add a storage to the currently described AS
371 XBT_PUBLIC(void) sg_platf_new_mstorage(sg_platf_mstorage_cbarg_t mstorage);
372 XBT_PUBLIC(void) sg_platf_new_storage_type(sg_platf_storage_type_cbarg_t storage_type);
373 XBT_PUBLIC(void) sg_platf_new_mount(sg_platf_mount_cbarg_t mount);
374
375 XBT_PUBLIC(void) sg_platf_new_process(sg_platf_process_cbarg_t process);
376
377 /* ***************************************** */
378 /* TUTORIAL: New TAG                         */
379 XBT_PUBLIC(void) sg_platf_new_gpu(sg_platf_gpu_cbarg_t gpu);
380 /* ***************************************** */
381
382 // Add route and Asroute without xml file with those functions
383 XBT_PUBLIC(void) sg_platf_route_begin (sg_platf_route_cbarg_t route); // Initialize route
384 XBT_PUBLIC(void) sg_platf_route_end (sg_platf_route_cbarg_t route); // Finalize and add a route
385
386 XBT_PUBLIC(void) sg_platf_ASroute_begin (sg_platf_route_cbarg_t ASroute); // Initialize ASroute
387 XBT_PUBLIC(void) sg_platf_ASroute_end (sg_platf_route_cbarg_t ASroute); // Finalize and add a ASroute
388
389 XBT_PUBLIC(void) sg_platf_route_add_link (const char* link_id, sg_platf_route_cbarg_t route); // Add a link to link list
390 XBT_PUBLIC(void) sg_platf_ASroute_add_link (const char* link_id, sg_platf_route_cbarg_t ASroute); // Add a link to link list
391
392 typedef void (*sg_platf_process_cb_t)(sg_platf_process_cbarg_t);
393 XBT_PUBLIC(void) sg_platf_process_add_cb(sg_platf_process_cb_t fct);
394
395
396 #endif                          /* SG_PLATF_H */