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 * so you shouldn't call it by yourself.
271 * \see surf_workstation_resource_init_CLM03()
273 XBT_PUBLIC(void) surf_network_resource_init_CM02(const char *filename);
275 /** \brief Workstation resource extension public
276 * \ingroup SURF_resources
278 * Public functions specific to the workstation resource.
280 typedef struct surf_workstation_resource_extension_public {
281 surf_action_t(*execute) (void *workstation, double size); /**< Execute a computation amount on a workstation
282 and create the corresponding action */
283 surf_action_t(*sleep) (void *workstation, double duration); /**< Make a workstation sleep during a given duration */
284 e_surf_cpu_state_t(*get_state) (void *workstation); /**< Return the CPU state of a workstation */
285 double (*get_speed) (void *workstation, double load); /**< Return the speed of a workstation */
286 double (*get_available_speed) (void *workstation); /**< Return tha available speed of a workstation */
287 surf_action_t(*communicate) (void *workstation_src, /**< Execute a communication amount between two workstations */
288 void *workstation_dst, double size,
290 surf_action_t(*execute_parallel_task) (int workstation_nb, /**< Execute a parallel task on several workstations */
291 void **workstation_list,
292 double *computation_amount,
293 double *communication_amount,
296 const void** (*get_route) (void *src, void *dst); /**< Return the network link list between two workstations */
297 int (*get_route_size) (void *src, void *dst); /**< Return the route size between two workstations */
298 const char* (*get_link_name) (const void *link); /**< Return the name of a network link */
299 double (*get_link_bandwidth) (const void *link); /**< Return the current bandwidth of a network link */
300 double (*get_link_latency) (const void *link); /**< Return the current latency of a network link */
301 } s_surf_workstation_resource_extension_public_t,
302 *surf_workstation_resource_extension_public_t;
304 /** \brief Workstation resource datatype.
305 * \ingroup SURF_resources
308 typedef struct surf_workstation_resource {
309 surf_resource_private_t common_private;
310 surf_resource_public_t common_public;
311 surf_workstation_resource_extension_public_t extension_public;
312 } s_surf_workstation_resource_t, *surf_workstation_resource_t;
314 /** \brief The workstation resource
315 * \ingroup SURF_resources
317 * Note that when you create an API on top of SURF,
318 * the workstation resource should be the only one you use
319 * because depending on the platform model, the network resource and the CPU resource
322 XBT_PUBLIC_DATA(surf_workstation_resource_t) surf_workstation_resource;
324 /** \brief Initializes the platform with the workstation model CLM03
325 * \ingroup SURF_resources
326 * \param filename XML platform file name
328 * This platform model seperates the workstation resource and the network resource.
329 * The workstation resource will be initialized with the model CLM03, the network
330 * resource with the model CM02 and the CPU resource with the model Cas01.
331 * In future releases, some other network models will be implemented and will be
332 * combined with the workstation model CLM03.
334 * \see surf_workstation_resource_init_KCCFLN05()
336 XBT_PUBLIC(void) surf_workstation_resource_init_CLM03(const char *filename);
338 /** \brief Initializes the platform with the model KCCFLN05
339 * \ingroup SURF_resources
340 * \param filename XML platform file name
342 * With this model, the workstations and the network are handled together.
343 * There is no network resource. This platform model is the default one for
346 * \see surf_workstation_resource_init_CLM03()
348 XBT_PUBLIC(void) surf_workstation_resource_init_KCCFLN05(const char *filename);
350 /** \brief Initializes the platform with the model KCCFLN05 using the proportional
351 * approach as described in [TAG03].
353 * \ingroup SURF_resources
354 * \param filename XML platform file name
356 * This function implements the proportional fairness known as the maximization
357 * of sum ( x1*x2*...*xn ).
361 * [TAG03]. Corinne Touati, Eitan Altman, and Jérôme Galtier.
362 * Semi-definite programming approach for bandwidth allocation and routing in networks.
363 * Game Theory and Applications, 9:169-179, December 2003. Nova publisher.
364 * With this model, the workstations and the network are handled together.
365 * There is no network resource. This platform model is the default one for
368 * \see surf_workstation_resource_init_CLM03()
370 XBT_PUBLIC(void) surf_workstation_resource_init_KCCFLN05_proportionnal(const char *filename);
372 /** \brief Initializes the platform with the model KCCFLN05 using a lagrange
373 * optimization approach to compute the effectivet bandwidth of each flow based
374 * on the Vegas TCP flavor fairness as shown in [LOW03].
376 * \ingroup SURF_resources
377 * \param filename XML platform file name
379 * This problem is related to max( sum( a * Df * ln(xi) ) ) which is equivalent
380 * to the proportional fairness.
383 * [LOW03] S. H. Low. A duality model of TCP and queue management algorithms.
384 * IEEE/ACM Transaction on Networking, 11(4):525-536, 2003.
387 XBT_PUBLIC(void) surf_workstation_resource_init_KCCFLN05_Vegas(const char *filename);
389 /** \brief Initializes the platform with the model KCCFLN05 using a lagrange
390 * optimization approach to compute the effectivet bandwidth of each flow based
391 * on the Reno TCP flavor fairness as shown in [LOW03].
393 * \ingroup SURF_resources
394 * \param filename XML platform file name
396 * The problem is related to max( sum( arctan(C * Df * xi) ) ).
399 * [LOW03] S. H. Low. A duality model of TCP and queue management algorithms.
400 * IEEE/ACM Transaction on Networking, 11(4):525-536, 2003.
402 * \see surf_workstation_resource_init_KCCFLN05_Vegas()
404 XBT_PUBLIC(void) surf_workstation_resource_init_KCCFLN05_Reno(const char *filename);
410 XBT_PUBLIC(void) surf_workstation_resource_init_GTNETS(const char *filename);
413 /** \brief The network links
414 * \ingroup SURF_resources
416 * This dict contains all network links.
418 * \see workstation_set
420 XBT_PUBLIC_DATA(xbt_dict_t) network_link_set;
422 /** \brief The workstations
423 * \ingroup SURF_resources
425 * This dict contains all workstations.
427 * \see network_link_set
429 XBT_PUBLIC_DATA(xbt_dict_t) workstation_set;
431 /** \brief List of initialized resources
432 * \ingroup SURF_resources
434 XBT_PUBLIC_DATA(xbt_dynar_t) resource_list;
436 /*******************************************/
437 /*** SURF Globals **************************/
438 /*******************************************/
440 /** \brief Initialize SURF
441 * \ingroup SURF_simulation
442 * \param argc argument number
443 * \param argv arguments
445 * This function has to be called to initialize the common structures.
446 * Then you will have to create the environment by calling surf_timer_resource_init()
447 * and surf_workstation_resource_init_CLM03() or surf_workstation_resource_init_KCCFLN05().
449 * \see surf_timer_resource_init(), surf_workstation_resource_init_CLM03(),
450 * surf_workstation_resource_init_KCCFLN05(), surf_exit()
452 XBT_PUBLIC(void) surf_init(int *argc, char **argv); /* initialize common structures */
454 /** \brief Performs a part of the simulation
455 * \ingroup SURF_simulation
456 * \return the elapsed time, or -1.0 if no event could be executed
458 * This function execute all possible events, update the action states
459 * and returns the time elapsed.
460 * When you call execute or communicate on a resource, the corresponding actions
461 * are not executed immediately but only when you call surf_solve.
462 * Note that the returned elapsed time can be zero.
464 XBT_PUBLIC(double) surf_solve(void);
466 /** \brief Return the current time
467 * \ingroup SURF_simulation
469 * Return the current time in millisecond.
471 XBT_PUBLIC(double)surf_get_clock(void);
474 * \ingroup SURF_simulation
480 XBT_PUBLIC(void) surf_exit(void);
485 #endif /* _SURF_SURF_H */