Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
* Moving things around (private->public)
[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 "gras_config.h"
16
17 SG_BEGIN_DECL()
18
19
20
21 /* Actions and resources are higly connected structures... */
22
23 /** \brief Action datatype
24  *  \ingroup SURF_actions
25  *  
26  * An action is some working amount on a resource.
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_resources
35  *  
36  *  Generic data structure for a resource. The workstations,
37  *  the CPUs and the network links are examples of resources.
38  */
39 typedef struct surf_resource *surf_resource_t;
40
41 /** \brief Action structure
42  * \ingroup SURF_actions
43  *
44  *  Never create s_surf_action_t by yourself ! The actions are created
45  *  on the fly when you call execute or communicate on a resource.
46  *  
47  *  \see e_surf_action_state_t
48  */
49 typedef struct surf_action {
50   s_xbt_swag_hookup_t state_hookup;
51   xbt_swag_t state_set;
52   double cost;                  /**< cost        */
53   double priority;              /**< priority (1.0 by default) */
54   double max_duration;          /**< max_duration (may fluctuate until
55                                    the task is completed) */
56   double remains;               /**< How much of that cost remains to
57                                  * be done in the currently running task */
58   double start;                 /**< start time  */
59   double finish;                /**< finish time : this is modified during the run
60                                  * and fluctuates until the task is completed */
61   void *data;                   /**< for your convenience */
62   int using;
63   surf_resource_t resource_type;
64 } s_surf_action_t;
65
66 /** \brief Action states
67  *  \ingroup SURF_actions
68  *
69  *  Action states.
70  *
71  *  \see surf_action_t, surf_action_state_t
72  */
73 typedef enum {
74   SURF_ACTION_READY = 0,        /**< Ready        */
75   SURF_ACTION_RUNNING,          /**< Running      */
76   SURF_ACTION_FAILED,           /**< Task Failure */
77   SURF_ACTION_DONE,             /**< Completed    */
78   SURF_ACTION_TO_FREE,          /**< Action to free in next cleanup */
79   SURF_ACTION_NOT_IN_THE_SYSTEM /**< Not in the system anymore. Why did you ask ? */
80 } e_surf_action_state_t;
81
82 /** \brief Action state sets
83  *  \ingroup SURF_actions
84  *
85  *  This structure contains some sets of actions.
86  *  It provides a fast access to the actions in each state.
87  *
88  *  \see surf_action_t, e_surf_action_state_t
89  */
90 typedef struct surf_action_state {
91   xbt_swag_t ready_action_set;   /**< Actions in state SURF_ACTION_READY */
92   xbt_swag_t running_action_set; /**< Actions in state SURF_ACTION_RUNNING */
93   xbt_swag_t failed_action_set;  /**< Actions in state SURF_ACTION_FAILED */
94   xbt_swag_t done_action_set;    /**< Actions in state SURF_ACTION_DONE */
95 } s_surf_action_state_t, *surf_action_state_t;
96
97 /***************************/
98 /* Generic resource object */
99 /***************************/
100
101 /** \brief Public data available on all resources
102  *  \ingroup SURF_resources
103  *
104  *  These functions are implemented by all resources.
105  */
106 typedef struct surf_resource_public {
107   s_surf_action_state_t states; /**< Any living action on this resource */
108   void *(*name_service) (const char *name); /**< Return a resource given its name */
109   const char *(*get_resource_name) (void *resource_id); /**< Return the name of a resource */
110
111   e_surf_action_state_t(*action_get_state) (surf_action_t action); /**< Return the state of an action */
112   double (*action_get_start_time) (surf_action_t action); /**< Return the start time of an action */
113   double (*action_get_finish_time) (surf_action_t action); /**< Return the finish time of an action */
114   void (*action_use) (surf_action_t action); /**< Set an action used */
115   int  (*action_free) (surf_action_t action); /**< Free an action */
116   void (*action_cancel) (surf_action_t action); /**< Cancel a running action */
117   void (*action_recycle) (surf_action_t action); /**< Recycle an action */
118   void (*action_change_state) (surf_action_t action, /**< Change an action state*/
119                                e_surf_action_state_t state);
120   void (*action_set_data) (surf_action_t action, void *data); /**< Set the user data of an action */
121   void (*suspend) (surf_action_t action); /**< Suspend an action */
122   void (*resume) (surf_action_t action); /**< Resume a suspended action */
123   int (*is_suspended) (surf_action_t action); /**< Return whether an action is suspended */
124   void (*set_max_duration) (surf_action_t action, double duration); /**< Set the max duration of an action*/
125   void (*set_priority) (surf_action_t action, double priority); /**< Set the priority of an action */
126   const char *name; /**< Name of this resource */
127 } s_surf_resource_public_t, *surf_resource_public_t;
128
129 /** \brief Private data available on all resources
130  *  \ingroup SURF_resources
131  */
132 typedef struct surf_resource_private *surf_resource_private_t;
133
134 /** \brief Resource datatype
135  *  \ingroup SURF_resources
136  *  
137  *  Generic data structure for a resource. The workstations,
138  *  the CPUs and the network links are examples of resources.
139  */
140 typedef struct surf_resource {
141   surf_resource_private_t common_private;
142   surf_resource_public_t common_public;
143 } s_surf_resource_t;
144
145 /**************************************/
146 /* Implementations of resource object */
147 /**************************************/
148
149 /** \brief Timer resource extension public
150  * \ingroup SURF_resource
151  *
152  * Additionnal functions specific to the timer resource
153  */
154 typedef struct surf_timer_resource_extension_public {
155   void (*set) (double date, void *function, void *arg);
156   int (*get)  (void **function, void **arg);
157 } s_surf_timer_resource_extension_public_t,
158   *surf_timer_resource_extension_public_t;
159
160 /** \brief Timer resource
161  *  \ingroup SURF_resources
162  */
163 typedef struct surf_timer_resource {
164   surf_resource_private_t common_private;
165   surf_resource_public_t common_public;
166   surf_timer_resource_extension_public_t extension_public;
167 } s_surf_timer_resource_t, *surf_timer_resource_t;
168
169 /** \brief The timer resource
170  *  \ingroup SURF_resources
171  */
172 XBT_PUBLIC_DATA(surf_timer_resource_t) surf_timer_resource;
173
174 /** \brief Initializes the timer resource
175  *  \ingroup SURF_resources
176  */
177 XBT_PUBLIC(void) surf_timer_resource_init(const char *filename);
178
179 /* Cpu resource */
180
181 /** \brief CPU state
182  *  \ingroup SURF_resources
183  */
184 typedef enum {
185   SURF_CPU_ON = 1,              /**< Ready        */
186   SURF_CPU_OFF = 0              /**< Running      */
187 } e_surf_cpu_state_t;
188
189 /** \brief CPU resource extension public
190  *  \ingroup SURF_resources
191  *  
192  *  Public functions specific to the CPU resource.
193  */
194 typedef struct surf_cpu_resource_extension_public {
195   surf_action_t(*execute) (void *cpu, double size);
196   surf_action_t(*sleep) (void *cpu, double duration);
197   e_surf_cpu_state_t(*get_state) (void *cpu);
198   double (*get_speed) (void *cpu, double load);
199   double (*get_available_speed) (void *cpu);
200 } s_surf_cpu_resource_extension_public_t,
201     *surf_cpu_resource_extension_public_t;
202
203 /** \brief CPU resource datatype
204  *  \ingroup SURF_resources
205  */
206 typedef struct surf_cpu_resource {
207   surf_resource_private_t common_private;
208   surf_resource_public_t common_public;
209   surf_cpu_resource_extension_public_t extension_public;
210 } s_surf_cpu_resource_t, *surf_cpu_resource_t;
211
212 /** \brief The CPU resource
213  *  \ingroup SURF_resources
214  */
215 XBT_PUBLIC_DATA(surf_cpu_resource_t) surf_cpu_resource;
216
217 /** \brief Initializes the CPU resource with the model Cas01
218  *  \ingroup SURF_resources
219  *
220  *  This function is called by surf_workstation_resource_init_CLM03
221  *  so you shouldn't have to call it by yourself.
222  *
223  *  \see surf_workstation_resource_init_CLM03()
224  */
225 XBT_PUBLIC(void) surf_cpu_resource_init_Cas01(const char *filename);
226
227 /* Network resource */
228
229 /** \brief Network resource extension public
230  *  \ingroup SURF_resources
231  *
232  *  Public functions specific to the network resource
233  */
234 typedef struct surf_network_resource_extension_public {
235   surf_action_t(*communicate) (void *src, void *dst, double size,
236                                double max_rate);
237   const void** (*get_route) (void *src, void *dst);
238   int (*get_route_size) (void *src, void *dst);
239   const char* (*get_link_name) (const void *link);
240   double (*get_link_bandwidth) (const void *link);
241   double (*get_link_latency) (const void *link);
242 } s_surf_network_resource_extension_public_t,
243     *surf_network_resource_extension_public_t;
244
245 /** \brief Network resource datatype
246  *  \ingroup SURF_resources
247  */
248 typedef struct surf_network_resource {
249   surf_resource_private_t common_private;
250   surf_resource_public_t common_public;
251   surf_network_resource_extension_public_t extension_public;
252 } s_surf_network_resource_t, *surf_network_resource_t;
253
254 /** \brief The network resource
255  *  \ingroup SURF_resources
256  *
257  *  When creating a new API on top on SURF, you shouldn't use the
258  *  network resource unless you know what you are doing. Only the workstation
259  *  resource should be accessed because depending on the platform model,
260  *  the network resource can be NULL.
261  */
262 XBT_PUBLIC_DATA(surf_network_resource_t) surf_network_resource;
263
264 /** \brief Initializes the platform with the network model CM02
265  *  \ingroup SURF_resources
266  *  \param filename XML platform file name
267  *
268  *  This function is called by surf_workstation_resource_init_CLM03
269  *  or by yourself only if you plan using surf_workstation_resource_init_compound
270  *
271  *  \see surf_workstation_resource_init_CLM03()
272  */
273 XBT_PUBLIC(void) surf_network_resource_init_CM02(const char *filename);
274
275 #ifdef USE_GTNETS
276 /** \brief Initializes the platform with the network model GTNETS
277  *  \ingroup SURF_resources
278  *  \param filename XML platform file name
279  *
280  *  This function is called by surf_workstation_resource_init_GTNETS
281  *  or by yourself only if you plan using surf_workstation_resource_init_compound
282  *
283  *  \see surf_workstation_resource_init_GTNETS()
284  */
285 XBT_PUBLIC(void) surf_network_resource_init_GTNETS(const char *filename);
286 #endif
287
288 /** \brief Workstation resource extension public
289  *  \ingroup SURF_resources
290  *
291  *  Public functions specific to the workstation resource.
292  */
293 typedef struct surf_workstation_resource_extension_public {
294   surf_action_t(*execute) (void *workstation, double size);            /**< Execute a computation amount on a workstation
295                                                                         and create the corresponding action */
296   surf_action_t(*sleep) (void *workstation, double duration);          /**< Make a workstation sleep during a given duration */
297   e_surf_cpu_state_t(*get_state) (void *workstation);                  /**< Return the CPU state of a workstation */
298   double (*get_speed) (void *workstation, double load);                /**< Return the speed of a workstation */
299   double (*get_available_speed) (void *workstation);                   /**< Return tha available speed of a workstation */
300   surf_action_t(*communicate) (void *workstation_src,                  /**< Execute a communication amount between two workstations */
301                                void *workstation_dst, double size,
302                                double max_rate);
303   surf_action_t(*execute_parallel_task) (int workstation_nb,           /**< Execute a parallel task on several workstations */
304                                          void **workstation_list,
305                                          double *computation_amount,
306                                          double *communication_amount,
307                                          double amount,
308                                          double rate);
309   const void** (*get_route) (void *src, void *dst);                    /**< Return the network link list between two workstations */
310   int (*get_route_size) (void *src, void *dst);                        /**< Return the route size between two workstations */
311   const char* (*get_link_name) (const void *link);                     /**< Return the name of a network link */
312   double (*get_link_bandwidth) (const void *link);                     /**< Return the current bandwidth of a network link */
313   double (*get_link_latency) (const void *link);                       /**< Return the current latency of a network link */
314 } s_surf_workstation_resource_extension_public_t,
315     *surf_workstation_resource_extension_public_t;
316
317 /** \brief Workstation resource datatype.
318  *  \ingroup SURF_resources
319  *
320  */
321 typedef struct surf_workstation_resource {
322   surf_resource_private_t common_private;
323   surf_resource_public_t common_public;
324   surf_workstation_resource_extension_public_t extension_public;
325 } s_surf_workstation_resource_t, *surf_workstation_resource_t;
326
327 /** \brief The workstation resource
328  *  \ingroup SURF_resources
329  *
330  *  Note that when you create an API on top of SURF,
331  *  the workstation resource should be the only one you use
332  *  because depending on the platform model, the network resource and the CPU resource
333  *  may not exist.
334  */
335 XBT_PUBLIC_DATA(surf_workstation_resource_t) surf_workstation_resource;
336
337 /** \brief Initializes the platform with a compound workstation model
338  *  \ingroup SURF_resources
339  *  \param filename XML platform file name
340  *
341  *  This function should be called after a cpu_resource and a
342  *  network_resource have been set up.
343  *
344  */
345 XBT_PUBLIC(void) surf_workstation_resource_init_compound(const char *filename);
346
347 /** \brief Initializes the platform with the workstation model CLM03
348  *  \ingroup SURF_resources
349  *  \param filename XML platform file name
350  *
351  *  This platform model seperates the workstation resource and the network resource.
352  *  The workstation resource will be initialized with the model CLM03, the network
353  *  resource with the model CM02 and the CPU resource with the model Cas01.
354  *  In future releases, some other network models will be implemented and will be
355  *  combined with the workstation model CLM03.
356  *
357  *  \see surf_workstation_resource_init_KCCFLN05()
358  */
359 XBT_PUBLIC(void) surf_workstation_resource_init_CLM03(const char *filename);
360
361 /** \brief Initializes the platform with the model KCCFLN05
362  *  \ingroup SURF_resources
363  *  \param filename XML platform file name
364  *
365  *  With this model, the workstations and the network are handled together.
366  *  There is no network resource. This platform model is the default one for
367  *  MSG and SimDag.
368  *
369  *  \see surf_workstation_resource_init_CLM03()
370  */
371 XBT_PUBLIC(void) surf_workstation_resource_init_KCCFLN05(const char *filename);
372
373 /** \brief Initializes the platform with the model KCCFLN05 using the proportional
374  *  approach as described in [TAG03]. 
375  *  
376  *  \ingroup SURF_resources
377  *  \param filename XML platform file name
378  *
379  *  This function implements the proportional fairness known as the maximization
380  *  of sum ( x1*x2*...*xn ).
381  *
382  *  Reference:
383  *
384  *  [TAG03]. Corinne Touati, Eitan Altman, and Jérôme Galtier.  
385  *  Semi-definite programming approach for bandwidth allocation and routing in networks.
386  *  Game Theory and Applications, 9:169-179, December 2003. Nova publisher.
387  *  With this model, the workstations and the network are handled together.
388  *  There is no network resource. This platform model is the default one for
389  *  MSG and SimDag.
390  *
391  *  \see surf_workstation_resource_init_CLM03()
392  */
393 XBT_PUBLIC(void) surf_workstation_resource_init_KCCFLN05_proportional(const char *filename);
394
395 /** \brief Initializes the platform with the model KCCFLN05 using a lagrange
396  *  optimization approach to compute the effectivet bandwidth of each flow based
397  *  on the Vegas TCP flavor fairness as shown in [LOW03]. 
398  *  
399  *  \ingroup SURF_resources
400  *  \param filename XML platform file name
401  *
402  *  This problem is related to max( sum( a * Df * ln(xi) ) ) which is equivalent 
403  *  to the proportional fairness.
404  *
405  *  Reference:
406  *  [LOW03] S. H. Low. A duality model of TCP and queue management algorithms.
407  *  IEEE/ACM Transaction on Networking, 11(4):525-536, 2003.
408  *
409  */
410 XBT_PUBLIC(void) surf_workstation_resource_init_KCCFLN05_Vegas(const char *filename);
411
412 /** \brief Initializes the platform with the model KCCFLN05 using a lagrange
413  *  optimization approach to compute the effectivet bandwidth of each flow based
414  *  on the Reno TCP flavor fairness as shown in [LOW03]. 
415  *  
416  *  \ingroup SURF_resources
417  *  \param filename XML platform file name
418  *
419  *  The problem is related to max( sum( arctan(C * Df * xi) ) ).
420  *
421  *  Reference:
422  *  [LOW03] S. H. Low. A duality model of TCP and queue management algorithms.
423  *  IEEE/ACM Transaction on Networking, 11(4):525-536, 2003.
424  *
425  *  \see surf_workstation_resource_init_KCCFLN05_Vegas()
426  */
427 XBT_PUBLIC(void) surf_workstation_resource_init_KCCFLN05_Reno(const char *filename);
428
429
430
431
432 #ifdef USE_GTNETS
433 XBT_PUBLIC(void) surf_workstation_resource_init_GTNETS(const char *filename);
434 #endif
435
436 /** \brief The network links
437  *  \ingroup SURF_resources
438  *
439  *  This dict contains all network links.
440  *
441  *  \see workstation_set
442  */
443 XBT_PUBLIC_DATA(xbt_dict_t) network_link_set;
444
445 /** \brief The workstations
446  *  \ingroup SURF_resources
447  *
448  *  This dict contains all workstations.
449  *
450  *  \see network_link_set
451  */
452 XBT_PUBLIC_DATA(xbt_dict_t)  workstation_set;
453
454 /** \brief List of initialized resources
455  *  \ingroup SURF_resources
456  */
457 XBT_PUBLIC_DATA(xbt_dynar_t)  resource_list;
458
459 /*******************************************/
460 /*** SURF Globals **************************/
461 /*******************************************/
462
463 /** \brief Initialize SURF
464  *  \ingroup SURF_simulation
465  *  \param argc argument number
466  *  \param argv arguments
467  *
468  *  This function has to be called to initialize the common structures.
469  *  Then you will have to create the environment by calling surf_timer_resource_init()
470  *  and surf_workstation_resource_init_CLM03() or surf_workstation_resource_init_KCCFLN05().
471  *
472  *  \see surf_timer_resource_init(), surf_workstation_resource_init_CLM03(),
473  *  surf_workstation_resource_init_KCCFLN05(), surf_exit()
474  */
475 XBT_PUBLIC(void) surf_init(int *argc, char **argv);     /* initialize common structures */
476
477 /** \brief Performs a part of the simulation
478  *  \ingroup SURF_simulation
479  *  \return the elapsed time, or -1.0 if no event could be executed
480  *
481  *  This function execute all possible events, update the action states
482  *  and returns the time elapsed.
483  *  When you call execute or communicate on a resource, the corresponding actions
484  *  are not executed immediately but only when you call surf_solve.
485  *  Note that the returned elapsed time can be zero.
486  */
487 XBT_PUBLIC(double) surf_solve(void);
488
489 /** \brief Return the current time
490  *  \ingroup SURF_simulation
491  *
492  *  Return the current time in millisecond.
493  */
494 XBT_PUBLIC(double)surf_get_clock(void);
495
496 /** \brief Exit SURF
497  *  \ingroup SURF_simulation
498  *
499  *  Clean everything.
500  *
501  *  \see surf_init()
502  */
503 XBT_PUBLIC(void) surf_exit(void);
504
505
506 SG_END_DECL()
507
508 #endif                          /* _SURF_SURF_H */