Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
* Cleanup the DTD by renaming:
[simgrid.git] / src / include / surf / surf.h
1 /*      $Id$     */
2
3 /* Copyright (c) 2004 Arnaud Legrand. 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 _SURF_SURF_H
9 #define _SURF_SURF_H
10
11 #include "xbt/swag.h"
12 #include "xbt/dynar.h"
13 #include "xbt/dict.h"
14 #include "xbt/misc.h"
15 #include "portable.h"
16
17 SG_BEGIN_DECL()
18
19
20
21 /* Actions and models are higly connected structures... */
22
23 /** \brief Action datatype
24  *  \ingroup SURF_actions
25  *  
26  * An action is some working amount on a model.
27  * It is represented as a cost, a priority, a duration and a state.
28  *
29  * \see e_surf_action_state_t
30  */
31 typedef struct surf_action *surf_action_t;
32
33 /** \brief Resource datatype
34  *  \ingroup SURF_models
35  *  
36  *  Generic data structure for a model. The workstations,
37  *  the CPUs and the network links are examples of models.
38  */
39 typedef struct surf_model *surf_model_t;
40
41 /** \brief Resource model description
42  */
43 typedef struct surf_model_description {
44   const char *name;
45   surf_model_t model;
46   void (* model_init) (const char *filename);
47 } s_surf_model_description_t, *surf_model_description_t;
48
49 XBT_PUBLIC(void) update_model_description(s_surf_model_description_t *table,
50                                              int table_size,
51                                              const char* name, 
52                                              surf_model_t model
53                                              );
54 XBT_PUBLIC(int) find_model_description(s_surf_model_description_t *table,
55                                           int table_size,
56                                           const char* name);
57
58 /** \brief Action structure
59  * \ingroup SURF_actions
60  *
61  *  Never create s_surf_action_t by yourself ! The actions are created
62  *  on the fly when you call execute or communicate on a model.
63  *  
64  *  \see e_surf_action_state_t
65  */
66 typedef struct surf_action {
67   s_xbt_swag_hookup_t state_hookup;
68   xbt_swag_t state_set;
69   double cost;                  /**< cost        */
70   double priority;              /**< priority (1.0 by default) */
71   double max_duration;          /**< max_duration (may fluctuate until
72                                    the task is completed) */
73   double remains;               /**< How much of that cost remains to
74                                  * be done in the currently running task */
75   double start;                 /**< start time  */
76   double finish;                /**< finish time : this is modified during the run
77                                  * and fluctuates until the task is completed */
78   void *data;                   /**< for your convenience */
79   int using;
80   surf_model_t model_type;
81 } s_surf_action_t;
82
83 /** \brief Action states
84  *  \ingroup SURF_actions
85  *
86  *  Action states.
87  *
88  *  \see surf_action_t, surf_action_state_t
89  */
90 typedef enum {
91   SURF_ACTION_READY = 0,        /**< Ready        */
92   SURF_ACTION_RUNNING,          /**< Running      */
93   SURF_ACTION_FAILED,           /**< Task Failure */
94   SURF_ACTION_DONE,             /**< Completed    */
95   SURF_ACTION_TO_FREE,          /**< Action to free in next cleanup */
96   SURF_ACTION_NOT_IN_THE_SYSTEM /**< Not in the system anymore. Why did you ask ? */
97 } e_surf_action_state_t;
98
99 /** \brief Action state sets
100  *  \ingroup SURF_actions
101  *
102  *  This structure contains some sets of actions.
103  *  It provides a fast access to the actions in each state.
104  *
105  *  \see surf_action_t, e_surf_action_state_t
106  */
107 typedef struct surf_action_state {
108   xbt_swag_t ready_action_set;   /**< Actions in state SURF_ACTION_READY */
109   xbt_swag_t running_action_set; /**< Actions in state SURF_ACTION_RUNNING */
110   xbt_swag_t failed_action_set;  /**< Actions in state SURF_ACTION_FAILED */
111   xbt_swag_t done_action_set;    /**< Actions in state SURF_ACTION_DONE */
112 } s_surf_action_state_t, *surf_action_state_t;
113
114 /***************************/
115 /* Generic model object */
116 /***************************/
117
118 /** \brief Public data available on all models
119  *  \ingroup SURF_models
120  *
121  *  These functions are implemented by all models.
122  */
123 typedef struct surf_model_public {
124   s_surf_action_state_t states; /**< Any living action on this model */
125   void *(*name_service) (const char *name); /**< Return a model given its name */
126   const char *(*get_resource_name) (void *resource_id); /**< Return the name of a resource */
127
128   e_surf_action_state_t(*action_get_state) (surf_action_t action); /**< Return the state of an action */
129   double (*action_get_start_time) (surf_action_t action); /**< Return the start time of an action */
130   double (*action_get_finish_time) (surf_action_t action); /**< Return the finish time of an action */
131   void (*action_use) (surf_action_t action); /**< Set an action used */
132   int  (*action_free) (surf_action_t action); /**< Free an action */
133   void (*action_cancel) (surf_action_t action); /**< Cancel a running action */
134   void (*action_recycle) (surf_action_t action); /**< Recycle an action */
135   void (*action_change_state) (surf_action_t action, /**< Change an action state*/
136                                e_surf_action_state_t state);
137   void (*action_set_data) (surf_action_t action, void *data); /**< Set the user data of an action */
138   void (*suspend) (surf_action_t action); /**< Suspend an action */
139   void (*resume) (surf_action_t action); /**< Resume a suspended action */
140   int (*is_suspended) (surf_action_t action); /**< Return whether an action is suspended */
141   void (*set_max_duration) (surf_action_t action, double duration); /**< Set the max duration of an action*/
142   void (*set_priority) (surf_action_t action, double priority); /**< Set the priority of an action */
143   const char *name; /**< Name of this model */
144
145   /*for the properties of the link*/
146   xbt_dict_t (*get_link_properties) (void* link);
147
148   /*for the properties of the cpu*/
149   xbt_dict_t (*get_cpu_properties) (void* cpu);
150
151 } s_surf_model_public_t, *surf_model_public_t;
152
153 /** \brief Private data available on all models
154  *  \ingroup SURF_models
155  */
156 typedef struct surf_model_private *surf_model_private_t;
157
158 /** \brief Resource datatype
159  *  \ingroup SURF_models
160  *  
161  *  Generic data structure for a model. The workstations,
162  *  the CPUs and the network links are examples of models.
163  */
164 typedef struct surf_model {
165   surf_model_private_t common_private;
166   surf_model_public_t common_public;
167 } s_surf_model_t;
168
169 /**************************************/
170 /* Implementations of model object */
171 /**************************************/
172
173 /** \brief Timer model extension public
174  * \ingroup SURF_model
175  *
176  * Additionnal functions specific to the timer model
177  */
178 typedef struct surf_timer_model_extension_public {
179   void (*set) (double date, void *function, void *arg);
180   int (*get)  (void **function, void **arg);
181 } s_surf_timer_model_extension_public_t,
182   *surf_timer_model_extension_public_t;
183
184 /** \brief Timer model
185  *  \ingroup SURF_models
186  */
187 typedef struct surf_timer_model {
188   surf_model_private_t common_private;
189   surf_model_public_t common_public;
190   surf_timer_model_extension_public_t extension_public;
191 } s_surf_timer_model_t, *surf_timer_model_t;
192
193 /** \brief The timer model
194  *  \ingroup SURF_models
195  */
196 XBT_PUBLIC_DATA(surf_timer_model_t) surf_timer_model;
197
198 /** \brief Initializes the timer model
199  *  \ingroup SURF_models
200  */
201 XBT_PUBLIC(void) surf_timer_model_init(const char *filename);
202
203 /* Cpu model */
204
205 /** \brief CPU state
206  *  \ingroup SURF_models
207  */
208 typedef enum {
209   SURF_CPU_ON = 1,              /**< Ready        */
210   SURF_CPU_OFF = 0              /**< Running      */
211 } e_surf_cpu_state_t;
212
213 /** \brief CPU model extension public
214  *  \ingroup SURF_models
215  *  
216  *  Public functions specific to the CPU model.
217  */
218 typedef struct surf_cpu_model_extension_public {
219   surf_action_t(*execute) (void *cpu, double size);
220   surf_action_t(*sleep) (void *cpu, double duration);
221   e_surf_cpu_state_t(*get_state) (void *cpu);
222   double (*get_speed) (void *cpu, double load);
223   double (*get_available_speed) (void *cpu);
224 } s_surf_cpu_model_extension_public_t,
225     *surf_cpu_model_extension_public_t;
226
227 /** \brief CPU model datatype
228  *  \ingroup SURF_models
229  */
230 typedef struct surf_cpu_model {
231   surf_model_private_t common_private;
232   surf_model_public_t common_public;
233   surf_cpu_model_extension_public_t extension_public;
234 } s_surf_cpu_model_t, *surf_cpu_model_t;
235
236 /** \brief The CPU model
237  *  \ingroup SURF_models
238  */
239 XBT_PUBLIC_DATA(surf_cpu_model_t) surf_cpu_model;
240
241 /** \brief Initializes the CPU model with the model Cas01
242  *  \ingroup SURF_models
243  *
244  *  This function is called by surf_workstation_model_init_CLM03
245  *  so you shouldn't have to call it by yourself.
246  *
247  *  \see surf_workstation_model_init_CLM03()
248  */
249 XBT_PUBLIC(void) surf_cpu_model_init_Cas01(const char *filename);
250
251 XBT_PUBLIC_DATA(int) surf_cpu_model_description_size;
252 /** \brief The list of all available cpu model models
253  *  \ingroup SURF_models
254  */
255 XBT_PUBLIC_DATA(s_surf_model_description_t) surf_cpu_model_description[];
256
257 /* Network model */
258
259 /** \brief Network model extension public
260  *  \ingroup SURF_models
261  *
262  *  Public functions specific to the network model
263  */
264 typedef struct surf_network_model_extension_public {
265   surf_action_t(*communicate) (void *src, void *dst, double size,
266                                double max_rate);
267   const void** (*get_route) (void *src, void *dst);
268   int (*get_route_size) (void *src, void *dst);
269   const char* (*get_link_name) (const void *link);
270   double (*get_link_bandwidth) (const void *link);
271   double (*get_link_latency) (const void *link);
272 } s_surf_network_model_extension_public_t,
273     *surf_network_model_extension_public_t;
274
275 /** \brief Network model datatype
276  *  \ingroup SURF_models
277  */
278 typedef struct surf_network_model {
279   surf_model_private_t common_private;
280   surf_model_public_t common_public;
281   surf_network_model_extension_public_t extension_public;
282 } s_surf_network_model_t, *surf_network_model_t;
283
284 /** \brief The network model
285  *  \ingroup SURF_models
286  *
287  *  When creating a new API on top on SURF, you shouldn't use the
288  *  network model unless you know what you are doing. Only the workstation
289  *  model should be accessed because depending on the platform model,
290  *  the network model can be NULL.
291  */
292 XBT_PUBLIC_DATA(surf_network_model_t) surf_network_model;
293
294 /** \brief Initializes the platform with the network model CM02
295  *  \ingroup SURF_models
296  *  \param filename XML platform file name
297  *
298  *  This function is called by surf_workstation_model_init_CLM03
299  *  or by yourself only if you plan using surf_workstation_model_init_compound
300  *
301  *  \see surf_workstation_model_init_CLM03()
302  */
303 XBT_PUBLIC(void) surf_network_model_init_CM02(const char *filename);
304
305 #ifdef HAVE_GTNETS
306 /** \brief Initializes the platform with the network model GTNETS
307  *  \ingroup SURF_models
308  *  \param filename XML platform file name
309  *
310  *  This function is called by surf_workstation_model_init_GTNETS
311  *  or by yourself only if you plan using surf_workstation_model_init_compound
312  *
313  *  \see surf_workstation_model_init_GTNETS()
314  */
315 XBT_PUBLIC(void) surf_network_model_init_GTNETS(const char *filename);
316 #endif
317
318 /** \brief Initializes the platform with the network model Reno
319  *  \ingroup SURF_models
320  *  \param filename XML platform file name
321  *
322  *  The problem is related to max( sum( arctan(C * Df * xi) ) ).
323  *
324  *  Reference:
325  *  [LOW03] S. H. Low. A duality model of TCP and queue management algorithms.
326  *  IEEE/ACM Transaction on Networking, 11(4):525-536, 2003.
327  *
328  *  Call this function only if you plan using surf_workstation_model_init_compound.
329  *
330  */
331 XBT_PUBLIC(void) surf_network_model_init_Reno(const char *filename);
332
333 /** \brief Initializes the platform with the network model Vegas
334  *  \ingroup SURF_models
335  *  \param filename XML platform file name
336  *
337  *  This problem is related to max( sum( a * Df * ln(xi) ) ) which is equivalent 
338  *  to the proportional fairness.
339  *
340  *  Reference:
341  *  [LOW03] S. H. Low. A duality model of TCP and queue management algorithms.
342  *  IEEE/ACM Transaction on Networking, 11(4):525-536, 2003.
343  *
344  *  Call this function only if you plan using surf_workstation_model_init_compound.
345  *
346  */
347 XBT_PUBLIC(void) surf_network_model_init_Vegas(const char *filename);
348
349 #ifdef HAVE_SDP
350 /** \brief Initializes the platform with the network model based on SDP
351  *  \ingroup SURF_models
352  *  \param filename XML platform file name
353  *
354  *  This function implements the proportional fairness known as the maximization
355  *  of x1*x2*...*xn .
356  *
357  *  Reference:
358  *
359  *  [TAG03]. Corinne Touati, Eitan Altman, and Jérôme Galtier.  
360  *  Semi-definite programming approach for bandwidth allocation and routing in networks.
361  *  Game Theory and Applications, 9:169-179, December 2003. Nova publisher.
362  *
363  *  Call this function only if you plan using surf_workstation_model_init_compound.
364  */
365 XBT_PUBLIC(void) surf_network_model_init_SDP(const char *filename);
366 #endif
367
368
369
370 XBT_PUBLIC_DATA(int) surf_network_model_description_size;
371 /** \brief The list of all available network model models
372  *  \ingroup SURF_models
373  */
374 XBT_PUBLIC_DATA(s_surf_model_description_t) surf_network_model_description[];
375
376 /** \brief Workstation model extension public
377  *  \ingroup SURF_models
378  *
379  *  Public functions specific to the workstation model.
380  */
381 typedef struct surf_workstation_model_extension_public {
382   surf_action_t(*execute) (void *workstation, double size);            /**< Execute a computation amount on a workstation
383                                                                         and create the corresponding action */
384   surf_action_t(*sleep) (void *workstation, double duration);          /**< Make a workstation sleep during a given duration */
385   e_surf_cpu_state_t(*get_state) (void *workstation);                  /**< Return the CPU state of a workstation */
386   double (*get_speed) (void *workstation, double load);                /**< Return the speed of a workstation */
387   double (*get_available_speed) (void *workstation);                   /**< Return tha available speed of a workstation */
388   surf_action_t(*communicate) (void *workstation_src,                  /**< Execute a communication amount between two workstations */
389                                void *workstation_dst, double size,
390                                double max_rate);
391
392   surf_action_t(*execute_parallel_task) (int workstation_nb,           /**< Execute a parallel task on several workstations */
393                                          void **workstation_list,
394                                          double *computation_amount,
395                                          double *communication_amount,
396                                          double amount,
397                                          double rate);
398   const void** (*get_route) (void *src, void *dst);                    /**< Return the network link list between two workstations */
399   int (*get_route_size) (void *src, void *dst);                        /**< Return the route size between two workstations */
400   const char* (*get_link_name) (const void *link);                     /**< Return the name of a network link */
401   double (*get_link_bandwidth) (const void *link);                     /**< Return the current bandwidth of a network link */
402   double (*get_link_latency) (const void *link);                       /**< Return the current latency of a network link */
403 } s_surf_workstation_model_extension_public_t,
404     *surf_workstation_model_extension_public_t;
405
406 /** \brief Workstation model datatype.
407  *  \ingroup SURF_models
408  *
409  */
410 typedef struct surf_workstation_model {
411   surf_model_private_t common_private;
412   surf_model_public_t common_public;
413   surf_workstation_model_extension_public_t extension_public;
414 } s_surf_workstation_model_t, *surf_workstation_model_t;
415
416 /** \brief The workstation model
417  *  \ingroup SURF_models
418  *
419  *  Note that when you create an API on top of SURF,
420  *  the workstation model should be the only one you use
421  *  because depending on the platform model, the network model and the CPU model
422  *  may not exist.
423  */
424 XBT_PUBLIC_DATA(surf_workstation_model_t) surf_workstation_model;
425
426 /** \brief Initializes the platform with a compound workstation model
427  *  \ingroup SURF_models
428  *  \param filename XML platform file name
429  *
430  *  This function should be called after a cpu_model and a
431  *  network_model have been set up.
432  *
433  */
434 XBT_PUBLIC(void) surf_workstation_model_init_compound(const char *filename);
435
436 /** \brief Initializes the platform with the workstation model CLM03
437  *  \ingroup SURF_models
438  *  \param filename XML platform file name
439  *
440  *  This platform model seperates the workstation model and the network model.
441  *  The workstation model will be initialized with the model CLM03, the network
442  *  model with the model CM02 and the CPU model with the model Cas01.
443  *  In future releases, some other network models will be implemented and will be
444  *  combined with the workstation model CLM03.
445  *
446  *  \see surf_workstation_model_init_KCCFLN05()
447  */
448 XBT_PUBLIC(void) surf_workstation_model_init_CLM03(const char *filename);
449
450 /** \brief Initializes the platform with the model KCCFLN05
451  *  \ingroup SURF_models
452  *  \param filename XML platform file name
453  *
454  *  With this model, the workstations and the network are handled
455  *  together. The network model is roughly the same as in CM02 but
456  *  interference between computations and communications can be taken
457  *  into account. This platform model is the default one for MSG and
458  *  SimDag.
459  *
460  */
461 XBT_PUBLIC(void) surf_workstation_model_init_KCCFLN05(const char *filename);
462
463 /** \brief Initializes the platform with the model KCCFLN05
464  *  \ingroup SURF_models
465  *  \param filename XML platform file name
466  *
467  *  With this model, only parallel tasks can be used. Resource sharing
468  *  is done by identifying bottlenecks and giving an equal share of
469  *  the model to each action.
470  *
471  */
472 XBT_PUBLIC(void) surf_workstation_model_init_ptask_L07(const char *filename);
473
474 XBT_PUBLIC_DATA(int) surf_workstation_model_description_size;
475 /** \brief The list of all available workstation model models
476  *  \ingroup SURF_models
477  */
478 XBT_PUBLIC_DATA(s_surf_model_description_t) surf_workstation_model_description[];
479
480 /** \brief The network links
481  *  \ingroup SURF_models
482  *
483  *  This dict contains all network links.
484  *
485  *  \see workstation_set
486  */
487 XBT_PUBLIC_DATA(xbt_dict_t) network_link_set;
488
489 /** \brief The workstations
490  *  \ingroup SURF_models
491  *
492  *  This dict contains all workstations.
493  *
494  *  \see network_link_set
495  */
496 XBT_PUBLIC_DATA(xbt_dict_t)  workstation_set;
497
498 /** \brief List of initialized models
499  *  \ingroup SURF_models
500  */
501 XBT_PUBLIC_DATA(xbt_dynar_t)  model_list;
502
503 /*******************************************/
504 /*** SURF Globals **************************/
505 /*******************************************/
506
507 /** \brief Initialize SURF
508  *  \ingroup SURF_simulation
509  *  \param argc argument number
510  *  \param argv arguments
511  *
512  *  This function has to be called to initialize the common
513  *  structures.  Then you will have to create the environment by
514  *  calling surf_timer_model_init() and
515  *  e.g. surf_workstation_model_init_CLM03() or
516  *  surf_workstation_model_init_KCCFLN05().
517  *
518  *  \see surf_timer_model_init(), surf_workstation_model_init_CLM03(),
519  *  surf_workstation_model_init_KCCFLN05(), surf_workstation_model_init_compound(), surf_exit()
520  */
521 XBT_PUBLIC(void) surf_init(int *argc, char **argv);     /* initialize common structures */
522
523 /** \brief Performs a part of the simulation
524  *  \ingroup SURF_simulation
525  *  \return the elapsed time, or -1.0 if no event could be executed
526  *
527  *  This function execute all possible events, update the action states
528  *  and returns the time elapsed.
529  *  When you call execute or communicate on a model, the corresponding actions
530  *  are not executed immediately but only when you call surf_solve.
531  *  Note that the returned elapsed time can be zero.
532  */
533 XBT_PUBLIC(double) surf_solve(void);
534
535 /** \brief Return the current time
536  *  \ingroup SURF_simulation
537  *
538  *  Return the current time in millisecond.
539  */
540 XBT_PUBLIC(double)surf_get_clock(void);
541
542 /** \brief Exit SURF
543  *  \ingroup SURF_simulation
544  *
545  *  Clean everything.
546  *
547  *  \see surf_init()
548  */
549 XBT_PUBLIC(void) surf_exit(void);
550
551 /* Prototypes of the functions that handle the properties */
552 void parse_properties(void);
553 void free_string(void*);
554
555 /*Add callback lists*/
556 xbt_dynar_t STag_surfxml_platform_description_cb_list;
557 xbt_dynar_t ETag_surfxml_platform_description_cb_list;
558 xbt_dynar_t STag_surfxml_host_cb_list;
559 xbt_dynar_t ETag_surfxml_host_cb_list;
560 xbt_dynar_t STag_surfxml_router_cb_list;
561 xbt_dynar_t ETag_surfxml_router_cb_list;
562 xbt_dynar_t STag_surfxml_link_cb_list;
563 xbt_dynar_t ETag_surfxml_link_cb_list;
564 xbt_dynar_t STag_surfxml_route_cb_list;
565 xbt_dynar_t ETag_surfxml_route_cb_list;
566 xbt_dynar_t STag_surfxml_link_c_ctn_cb_list;
567 xbt_dynar_t ETag_surfxml_link_c_ctn_cb_list;
568 xbt_dynar_t STag_surfxml_process_cb_list;
569 xbt_dynar_t ETag_surfxml_process_cb_list;
570 xbt_dynar_t STag_surfxml_argument_cb_list;
571 xbt_dynar_t ETag_surfxml_argument_cb_list;
572 xbt_dynar_t STag_surfxml_prop_cb_list;
573 xbt_dynar_t ETag_surfxml_prop_cb_list;
574
575 XBT_PUBLIC(void) surfxml_add_callback(xbt_dynar_t cb_list, void_f_void_t function);
576
577 SG_END_DECL()
578
579 #endif                          /* _SURF_SURF_H */