3 /* Copyright (c) 2004 Arnaud Legrand. All rights reserved. */
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. */
12 #include "xbt/dynar.h"
15 #include "gras_config.h"
21 /* Actions and resources are higly connected structures... */
23 /** \brief Action datatype
24 * \ingroup SURF_actions
26 * An action is some working amount on a resource.
27 * It is represented as a cost, a priority, a duration and a state.
29 * \see e_surf_action_state_t
31 typedef struct surf_action *surf_action_t;
33 /** \brief Resource datatype
34 * \ingroup SURF_resources
36 * Generic data structure for a resource. The workstations,
37 * the CPUs and the network links are examples of resources.
39 typedef struct surf_resource *surf_resource_t;
41 /** \brief Action structure
42 * \ingroup SURF_actions
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.
47 * \see e_surf_action_state_t
49 typedef struct surf_action {
50 s_xbt_swag_hookup_t state_hookup;
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 */
63 surf_resource_t resource_type;
66 /** \brief Action states
67 * \ingroup SURF_actions
71 * \see surf_action_t, surf_action_state_t
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;
82 /** \brief Action state sets
83 * \ingroup SURF_actions
85 * This structure contains some sets of actions.
86 * It provides a fast access to the actions in each state.
88 * \see surf_action_t, e_surf_action_state_t
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;
97 /***************************/
98 /* Generic resource object */
99 /***************************/
101 /** \brief Public data available on all resources
102 * \ingroup SURF_resources
104 * These functions are implemented by all resources.
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 */
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;
129 /** \brief Private data available on all resources
130 * \ingroup SURF_resources
132 typedef struct surf_resource_private *surf_resource_private_t;
134 /** \brief Resource datatype
135 * \ingroup SURF_resources
137 * Generic data structure for a resource. The workstations,
138 * the CPUs and the network links are examples of resources.
140 typedef struct surf_resource {
141 surf_resource_private_t common_private;
142 surf_resource_public_t common_public;
145 /**************************************/
146 /* Implementations of resource object */
147 /**************************************/
149 /** \brief Timer resource extension public
150 * \ingroup SURF_resource
152 * Additionnal functions specific to the timer resource
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;
160 /** \brief Timer resource
161 * \ingroup SURF_resources
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;
169 /** \brief The timer resource
170 * \ingroup SURF_resources
172 XBT_PUBLIC_DATA(surf_timer_resource_t) surf_timer_resource;
174 /** \brief Initializes the timer resource
175 * \ingroup SURF_resources
177 XBT_PUBLIC(void) surf_timer_resource_init(const char *filename);
182 * \ingroup SURF_resources
185 SURF_CPU_ON = 1, /**< Ready */
186 SURF_CPU_OFF = 0 /**< Running */
187 } e_surf_cpu_state_t;
189 /** \brief CPU resource extension public
190 * \ingroup SURF_resources
192 * Public functions specific to the CPU resource.
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;
203 /** \brief CPU resource datatype
204 * \ingroup SURF_resources
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;
212 /** \brief The CPU resource
213 * \ingroup SURF_resources
215 XBT_PUBLIC_DATA(surf_cpu_resource_t) surf_cpu_resource;
217 /** \brief Initializes the CPU resource with the model Cas01
218 * \ingroup SURF_resources
220 * This function is called by surf_workstation_resource_init_CLM03
221 * so you shouldn't have to call it by yourself.
223 * \see surf_workstation_resource_init_CLM03()
225 XBT_PUBLIC(void) surf_cpu_resource_init_Cas01(const char *filename);
227 /* Network resource */
229 /** \brief Network resource extension public
230 * \ingroup SURF_resources
232 * Public functions specific to the network resource
234 typedef struct surf_network_resource_extension_public {
235 surf_action_t(*communicate) (void *src, void *dst, double size,
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;
245 /** \brief Network resource datatype
246 * \ingroup SURF_resources
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;
254 /** \brief The network resource
255 * \ingroup SURF_resources
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.
262 XBT_PUBLIC_DATA(surf_network_resource_t) surf_network_resource;
264 /** \brief Initializes the platform with the network model CM02
265 * \ingroup SURF_resources
266 * \param filename XML platform file name
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
271 * \see surf_workstation_resource_init_CLM03()
273 XBT_PUBLIC(void) surf_network_resource_init_CM02(const char *filename);
276 /** \brief Initializes the platform with the network model GTNETS
277 * \ingroup SURF_resources
278 * \param filename XML platform file name
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
283 * \see surf_workstation_resource_init_GTNETS()
285 XBT_PUBLIC(void) surf_network_resource_init_GTNETS(const char *filename);
288 /** \brief Workstation resource extension public
289 * \ingroup SURF_resources
291 * Public functions specific to the workstation resource.
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,
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,
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;
317 /** \brief Workstation resource datatype.
318 * \ingroup SURF_resources
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;
327 /** \brief The workstation resource
328 * \ingroup SURF_resources
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
335 XBT_PUBLIC_DATA(surf_workstation_resource_t) surf_workstation_resource;
337 /** \brief Initializes the platform with a compound workstation model
338 * \ingroup SURF_resources
339 * \param filename XML platform file name
341 * This function should be called after a cpu_resource and a
342 * network_resource have been set up.
345 XBT_PUBLIC(void) surf_workstation_resource_init_compound(const char *filename);
347 /** \brief Initializes the platform with the workstation model CLM03
348 * \ingroup SURF_resources
349 * \param filename XML platform file name
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.
357 * \see surf_workstation_resource_init_KCCFLN05()
359 XBT_PUBLIC(void) surf_workstation_resource_init_CLM03(const char *filename);
361 /** \brief Initializes the platform with the model KCCFLN05
362 * \ingroup SURF_resources
363 * \param filename XML platform file name
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
369 * \see surf_workstation_resource_init_CLM03()
371 XBT_PUBLIC(void) surf_workstation_resource_init_KCCFLN05(const char *filename);
373 /** \brief Initializes the platform with the model KCCFLN05 using the proportional
374 * approach as described in [TAG03].
376 * \ingroup SURF_resources
377 * \param filename XML platform file name
379 * This function implements the proportional fairness known as the maximization
380 * of sum ( x1*x2*...*xn ).
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
391 * \see surf_workstation_resource_init_CLM03()
393 XBT_PUBLIC(void) surf_workstation_resource_init_KCCFLN05_proportional(const char *filename);
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].
399 * \ingroup SURF_resources
400 * \param filename XML platform file name
402 * This problem is related to max( sum( a * Df * ln(xi) ) ) which is equivalent
403 * to the proportional fairness.
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.
410 XBT_PUBLIC(void) surf_workstation_resource_init_KCCFLN05_Vegas(const char *filename);
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].
416 * \ingroup SURF_resources
417 * \param filename XML platform file name
419 * The problem is related to max( sum( arctan(C * Df * xi) ) ).
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.
425 * \see surf_workstation_resource_init_KCCFLN05_Vegas()
427 XBT_PUBLIC(void) surf_workstation_resource_init_KCCFLN05_Reno(const char *filename);
433 XBT_PUBLIC(void) surf_workstation_resource_init_GTNETS(const char *filename);
436 /** \brief The network links
437 * \ingroup SURF_resources
439 * This dict contains all network links.
441 * \see workstation_set
443 XBT_PUBLIC_DATA(xbt_dict_t) network_link_set;
445 /** \brief The workstations
446 * \ingroup SURF_resources
448 * This dict contains all workstations.
450 * \see network_link_set
452 XBT_PUBLIC_DATA(xbt_dict_t) workstation_set;
454 /** \brief List of initialized resources
455 * \ingroup SURF_resources
457 XBT_PUBLIC_DATA(xbt_dynar_t) resource_list;
459 /*******************************************/
460 /*** SURF Globals **************************/
461 /*******************************************/
463 /** \brief Initialize SURF
464 * \ingroup SURF_simulation
465 * \param argc argument number
466 * \param argv arguments
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().
472 * \see surf_timer_resource_init(), surf_workstation_resource_init_CLM03(),
473 * surf_workstation_resource_init_KCCFLN05(), surf_exit()
475 XBT_PUBLIC(void) surf_init(int *argc, char **argv); /* initialize common structures */
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
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.
487 XBT_PUBLIC(double) surf_solve(void);
489 /** \brief Return the current time
490 * \ingroup SURF_simulation
492 * Return the current time in millisecond.
494 XBT_PUBLIC(double)surf_get_clock(void);
497 * \ingroup SURF_simulation
503 XBT_PUBLIC(void) surf_exit(void);
508 #endif /* _SURF_SURF_H */