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