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"
20 /* Actions and models are higly connected structures... */
22 /** \brief Action datatype
23 * \ingroup SURF_actions
25 * An action is some working amount on a model.
26 * It is represented as a cost, a priority, a duration and a state.
28 * \see e_surf_action_state_t
30 typedef struct surf_action *surf_action_t;
32 /** \brief Resource datatype
33 * \ingroup SURF_models
35 * Generic data structure for a model. The workstations,
36 * the CPUs and the network links are examples of models.
38 typedef struct surf_model *surf_model_t;
40 /** \brief Resource model description
42 typedef struct surf_model_description {
45 void (* model_init) (const char *filename);
46 void (* create_ws) (void);
47 } s_surf_model_description_t, *surf_model_description_t;
49 XBT_PUBLIC(void) update_model_description(s_surf_model_description_t *table,
53 XBT_PUBLIC(int) find_model_description(s_surf_model_description_t *table,
56 /** \brief Action structure
57 * \ingroup SURF_actions
59 * Never create s_surf_action_t by yourself ! The actions are created
60 * on the fly when you call execute or communicate on a model.
62 * \see e_surf_action_state_t
64 typedef struct surf_action {
65 s_xbt_swag_hookup_t state_hookup;
67 double cost; /**< cost */
68 double priority; /**< priority (1.0 by default) */
69 double max_duration; /**< max_duration (may fluctuate until
70 the task is completed) */
71 double remains; /**< How much of that cost remains to
72 * be done in the currently running task */
73 double start; /**< start time */
74 double finish; /**< finish time : this is modified during the run
75 * and fluctuates until the task is completed */
76 void *data; /**< for your convenience */
78 surf_model_t model_type;
81 /** \brief Action states
82 * \ingroup SURF_actions
86 * \see surf_action_t, surf_action_state_t
89 SURF_ACTION_READY = 0, /**< Ready */
90 SURF_ACTION_RUNNING, /**< Running */
91 SURF_ACTION_FAILED, /**< Task Failure */
92 SURF_ACTION_DONE, /**< Completed */
93 SURF_ACTION_TO_FREE, /**< Action to free in next cleanup */
94 SURF_ACTION_NOT_IN_THE_SYSTEM /**< Not in the system anymore. Why did you ask ? */
95 } e_surf_action_state_t;
97 /** \brief Action state sets
98 * \ingroup SURF_actions
100 * This structure contains some sets of actions.
101 * It provides a fast access to the actions in each state.
103 * \see surf_action_t, e_surf_action_state_t
105 typedef struct surf_action_state {
106 xbt_swag_t ready_action_set; /**< Actions in state SURF_ACTION_READY */
107 xbt_swag_t running_action_set; /**< Actions in state SURF_ACTION_RUNNING */
108 xbt_swag_t failed_action_set; /**< Actions in state SURF_ACTION_FAILED */
109 xbt_swag_t done_action_set; /**< Actions in state SURF_ACTION_DONE */
110 } s_surf_action_state_t, *surf_action_state_t;
112 /***************************/
113 /* Generic model object */
114 /***************************/
116 /** \brief Public data available on all models
117 * \ingroup SURF_models
119 * These functions are implemented by all models.
121 typedef struct surf_model_public {
122 s_surf_action_state_t states; /**< Any living action on this model */
123 void *(*name_service) (const char *name); /**< Return a model given its name */
124 const char *(*get_resource_name) (void *resource_id); /**< Return the name of a resource */
126 e_surf_action_state_t(*action_get_state) (surf_action_t action); /**< Return the state of an action */
127 double (*action_get_start_time) (surf_action_t action); /**< Return the start time of an action */
128 double (*action_get_finish_time) (surf_action_t action); /**< Return the finish time of an action */
129 void (*action_use) (surf_action_t action); /**< Set an action used */
130 int (*action_free) (surf_action_t action); /**< Free an action */
131 void (*action_cancel) (surf_action_t action); /**< Cancel a running action */
132 void (*action_recycle) (surf_action_t action); /**< Recycle an action */
133 void (*action_change_state) (surf_action_t action, /**< Change an action state*/
134 e_surf_action_state_t state);
135 void (*action_set_data) (surf_action_t action, void *data); /**< Set the user data of an action */
136 void (*suspend) (surf_action_t action); /**< Suspend an action */
137 void (*resume) (surf_action_t action); /**< Resume a suspended action */
138 int (*is_suspended) (surf_action_t action); /**< Return whether an action is suspended */
139 void (*set_max_duration) (surf_action_t action, double duration); /**< Set the max duration of an action*/
140 void (*set_priority) (surf_action_t action, double priority); /**< Set the priority of an action */
141 xbt_dict_t (*get_properties) (void* resource_id); /**< Return the properties dictionary */
142 const char *name; /**< Name of this model */
143 } s_surf_model_public_t, *surf_model_public_t;
145 /** \brief Private data available on all models
146 * \ingroup SURF_models
148 typedef struct surf_model_private *surf_model_private_t;
150 /** \brief Resource datatype
151 * \ingroup SURF_models
153 * Generic data structure for a model. The workstations,
154 * the CPUs and the network links are examples of models.
156 typedef struct surf_model {
157 surf_model_private_t common_private;
158 surf_model_public_t common_public;
161 /**************************************/
162 /* Implementations of model object */
163 /**************************************/
165 /** \brief Timer model extension public
166 * \ingroup SURF_model
168 * Additionnal functions specific to the timer model
170 typedef struct surf_timer_model_extension_public {
171 void (*set) (double date, void *function, void *arg);
172 int (*get) (void **function, void **arg);
173 } s_surf_timer_model_extension_public_t,
174 *surf_timer_model_extension_public_t;
176 /** \brief Timer model
177 * \ingroup SURF_models
179 typedef struct surf_timer_model {
180 surf_model_private_t common_private;
181 surf_model_public_t common_public;
182 surf_timer_model_extension_public_t extension_public;
183 } s_surf_timer_model_t, *surf_timer_model_t;
185 /** \brief The timer model
186 * \ingroup SURF_models
188 XBT_PUBLIC_DATA(surf_timer_model_t) surf_timer_model;
190 /** \brief Initializes the timer model
191 * \ingroup SURF_models
193 XBT_PUBLIC(void) surf_timer_model_init(const char *filename);
198 * \ingroup SURF_models
201 SURF_CPU_ON = 1, /**< Up & ready */
202 SURF_CPU_OFF = 0 /**< Down & broken */
203 } e_surf_cpu_state_t;
205 /** \brief CPU model extension public
206 * \ingroup SURF_models
208 * Public functions specific to the CPU model.
210 typedef struct surf_cpu_model_extension_public {
211 surf_action_t(*execute) (void *cpu, double size);
212 surf_action_t(*sleep) (void *cpu, double duration);
213 e_surf_cpu_state_t(*get_state) (void *cpu);
214 double (*get_speed) (void *cpu, double load);
215 double (*get_available_speed) (void *cpu);
216 } s_surf_cpu_model_extension_public_t,
217 *surf_cpu_model_extension_public_t;
219 /** \brief CPU model datatype
220 * \ingroup SURF_models
222 typedef struct surf_cpu_model {
223 surf_model_private_t common_private;
224 surf_model_public_t common_public;
225 surf_cpu_model_extension_public_t extension_public;
226 } s_surf_cpu_model_t, *surf_cpu_model_t;
228 /** \brief The CPU model
229 * \ingroup SURF_models
231 XBT_PUBLIC_DATA(surf_cpu_model_t) surf_cpu_model;
233 /** \brief Initializes the CPU model with the model Cas01
234 * \ingroup SURF_models
236 * This function is called by surf_workstation_model_init_CLM03
237 * so you shouldn't have to call it by yourself.
239 * \see surf_workstation_model_init_CLM03()
241 XBT_PUBLIC(void) surf_cpu_model_init_Cas01(const char *filename);
243 /** \brief The list of all available cpu model models
244 * \ingroup SURF_models
246 XBT_PUBLIC_DATA(s_surf_model_description_t) surf_cpu_model_description[];
250 /** \brief Network model extension public
251 * \ingroup SURF_models
253 * Public functions specific to the network model
255 typedef struct surf_network_model_extension_public {
256 surf_action_t(*communicate) (void *src, void *dst, double size,
258 const void** (*get_route) (void *src, void *dst);
259 int (*get_route_size) (void *src, void *dst);
260 const char* (*get_link_name) (const void *link);
261 double (*get_link_bandwidth) (const void *link);
262 double (*get_link_latency) (const void *link);
263 int (*link_shared) (const void *link);
264 } s_surf_network_model_extension_public_t,
265 *surf_network_model_extension_public_t;
267 /** \brief Network model datatype
268 * \ingroup SURF_models
270 typedef struct surf_network_model {
271 surf_model_private_t common_private;
272 surf_model_public_t common_public;
273 surf_network_model_extension_public_t extension_public;
274 } s_surf_network_model_t, *surf_network_model_t;
276 XBT_PUBLIC(void) create_workstations(void);
278 /** \brief The network model
279 * \ingroup SURF_models
281 * When creating a new API on top on SURF, you shouldn't use the
282 * network model unless you know what you are doing. Only the workstation
283 * model should be accessed because depending on the platform model,
284 * the network model can be NULL.
286 XBT_PUBLIC_DATA(surf_network_model_t) surf_network_model;
289 /** \brief Initializes the platform with the network model 'Constant'
290 * \ingroup SURF_models
291 * \param filename XML platform file name
293 * In this model, the communication time between two network cards is
294 * constant, hence no need for a routing table. This is particularly
295 * usefull when simulating huge distributed algorithms where
296 * scalability is really an issue. This function is called in
297 * conjunction with surf_workstation_model_init_compound.
299 * \see surf_workstation_model_init_compound()
301 XBT_PUBLIC(void) surf_network_model_init_Constant(const char *filename);
303 /** \brief Initializes the platform with the network model CM02
304 * \ingroup SURF_models
305 * \param filename XML platform file name
307 * This function is called by surf_workstation_model_init_CLM03
308 * or by yourself only if you plan using surf_workstation_model_init_compound
310 * \see surf_workstation_model_init_CLM03()
312 XBT_PUBLIC(void) surf_network_model_init_CM02(const char *filename);
315 /** \brief Initializes the platform with the network model GTNETS
316 * \ingroup SURF_models
317 * \param filename XML platform file name
319 * This function is called by surf_workstation_model_init_GTNETS
320 * or by yourself only if you plan using surf_workstation_model_init_compound
322 * \see surf_workstation_model_init_GTNETS()
324 XBT_PUBLIC(void) surf_network_model_init_GTNETS(const char *filename);
327 /** \brief Initializes the platform with the network model Reno
328 * \ingroup SURF_models
329 * \param filename XML platform file name
331 * The problem is related to max( sum( arctan(C * Df * xi) ) ).
334 * [LOW03] S. H. Low. A duality model of TCP and queue management algorithms.
335 * IEEE/ACM Transaction on Networking, 11(4):525-536, 2003.
337 * Call this function only if you plan using surf_workstation_model_init_compound.
340 XBT_PUBLIC(void) surf_network_model_init_Reno(const char *filename);
342 /** \brief Initializes the platform with the network model Reno2
343 * \ingroup SURF_models
344 * \param filename XML platform file name
346 * The problem is related to max( sum( arctan(C * Df * xi) ) ).
349 * [LOW01] S. H. Low. A duality model of TCP and queue management algorithms.
350 * IEEE/ACM Transaction on Networking, 11(4):525-536, 2003.
352 * Call this function only if you plan using surf_workstation_model_init_compound.
355 XBT_PUBLIC(void) surf_network_model_init_Reno2(const char *filename);
357 /** \brief Initializes the platform with the network model Vegas
358 * \ingroup SURF_models
359 * \param filename XML platform file name
361 * This problem is related to max( sum( a * Df * ln(xi) ) ) which is equivalent
362 * to the proportional fairness.
365 * [LOW03] S. H. Low. A duality model of TCP and queue management algorithms.
366 * IEEE/ACM Transaction on Networking, 11(4):525-536, 2003.
368 * Call this function only if you plan using surf_workstation_model_init_compound.
371 XBT_PUBLIC(void) surf_network_model_init_Vegas(const char *filename);
374 /** \brief Initializes the platform with the network model based on SDP
375 * \ingroup SURF_models
376 * \param filename XML platform file name
378 * This function implements the proportional fairness known as the maximization
383 * [TAG03]. Corinne Touati, Eitan Altman, and Jerome Galtier.
384 * Semi-definite programming approach for bandwidth allocation and routing in networks.
385 * Game Theory and Applications, 9:169-179, December 2003. Nova publisher.
387 * Call this function only if you plan using surf_workstation_model_init_compound.
389 XBT_PUBLIC(void) surf_network_model_init_SDP(const char *filename);
392 /** \brief The list of all available network model models
393 * \ingroup SURF_models
395 XBT_PUBLIC_DATA(s_surf_model_description_t) surf_network_model_description[];
397 /** \brief Workstation model extension public
398 * \ingroup SURF_models
400 * Public functions specific to the workstation model.
402 typedef struct surf_workstation_model_extension_public {
403 surf_action_t(*execute) (void *workstation, double size); /**< Execute a computation amount on a workstation
404 and create the corresponding action */
405 surf_action_t(*sleep) (void *workstation, double duration); /**< Make a workstation sleep during a given duration */
406 e_surf_cpu_state_t(*get_state) (void *workstation); /**< Return the CPU state of a workstation */
407 double (*get_speed) (void *workstation, double load); /**< Return the speed of a workstation */
408 double (*get_available_speed) (void *workstation); /**< Return tha available speed of a workstation */
409 surf_action_t(*communicate) (void *workstation_src, /**< Execute a communication amount between two workstations */
410 void *workstation_dst, double size,
413 surf_action_t(*execute_parallel_task) (int workstation_nb, /**< Execute a parallel task on several workstations */
414 void **workstation_list,
415 double *computation_amount,
416 double *communication_amount,
419 const void** (*get_route) (void *src, void *dst); /**< Return the network link list between two workstations */
420 int (*get_route_size) (void *src, void *dst); /**< Return the route size between two workstations */
421 const char* (*get_link_name) (const void *link); /**< Return the name of a network link */
422 double (*get_link_bandwidth) (const void *link); /**< Return the current bandwidth of a network link */
423 double (*get_link_latency) (const void *link); /**< Return the current latency of a network link */
424 int (*link_shared) (const void *link);
425 } s_surf_workstation_model_extension_public_t,
426 *surf_workstation_model_extension_public_t;
428 /** \brief Workstation model datatype.
429 * \ingroup SURF_models
432 typedef struct surf_workstation_model {
433 surf_model_private_t common_private;
434 surf_model_public_t common_public;
435 surf_workstation_model_extension_public_t extension_public;
436 } s_surf_workstation_model_t, *surf_workstation_model_t;
438 /** \brief The workstation model
439 * \ingroup SURF_models
441 * Note that when you create an API on top of SURF,
442 * the workstation model should be the only one you use
443 * because depending on the platform model, the network model and the CPU model
446 XBT_PUBLIC_DATA(surf_workstation_model_t) surf_workstation_model;
448 /** \brief Initializes the platform with a compound workstation model
449 * \ingroup SURF_models
450 * \param filename XML platform file name
452 * This function should be called after a cpu_model and a
453 * network_model have been set up.
456 XBT_PUBLIC(void) surf_workstation_model_init_compound(const char *filename);
458 /** \brief Initializes the platform with the workstation model CLM03
459 * \ingroup SURF_models
460 * \param filename XML platform file name
462 * This platform model seperates the workstation model and the network model.
463 * The workstation model will be initialized with the model CLM03, the network
464 * model with the model CM02 and the CPU model with the model Cas01.
465 * In future releases, some other network models will be implemented and will be
466 * combined with the workstation model CLM03.
468 * \see surf_workstation_model_init_KCCFLN05()
470 XBT_PUBLIC(void) surf_workstation_model_init_CLM03(const char *filename);
472 /** \brief Initializes the platform with the model KCCFLN05
473 * \ingroup SURF_models
474 * \param filename XML platform file name
476 * With this model, the workstations and the network are handled
477 * together. The network model is roughly the same as in CM02 but
478 * interference between computations and communications can be taken
479 * into account. This platform model is the default one for MSG and
483 XBT_PUBLIC(void) surf_workstation_model_init_KCCFLN05(const char *filename);
485 /** \brief Initializes the platform with the model KCCFLN05
486 * \ingroup SURF_models
487 * \param filename XML platform file name
489 * With this model, only parallel tasks can be used. Resource sharing
490 * is done by identifying bottlenecks and giving an equal share of
491 * the model to each action.
494 XBT_PUBLIC(void) surf_workstation_model_init_ptask_L07(const char *filename);
496 /** \brief The list of all available workstation model models
497 * \ingroup SURF_models
499 XBT_PUBLIC_DATA(s_surf_model_description_t) surf_workstation_model_description[];
501 /** \brief The network links
502 * \ingroup SURF_models
504 * This dict contains all network links.
506 * \see workstation_set
508 XBT_PUBLIC_DATA(xbt_dict_t) link_set;
510 /** \brief The workstations
511 * \ingroup SURF_models
513 * This dict contains all workstations.
517 XBT_PUBLIC_DATA(xbt_dict_t) workstation_set;
518 XBT_PUBLIC_DATA(xbt_dict_t) cpu_set;
519 /** \brief List of initialized models
520 * \ingroup SURF_models
522 XBT_PUBLIC_DATA(xbt_dynar_t) model_list;
524 /*******************************************/
525 /*** SURF Globals **************************/
526 /*******************************************/
528 /** \brief Initialize SURF
529 * \ingroup SURF_simulation
530 * \param argc argument number
531 * \param argv arguments
533 * This function has to be called to initialize the common
534 * structures. Then you will have to create the environment by
535 * calling surf_timer_model_init() and
536 * e.g. surf_workstation_model_init_CLM03() or
537 * surf_workstation_model_init_KCCFLN05().
539 * \see surf_timer_model_init(), surf_workstation_model_init_CLM03(),
540 * surf_workstation_model_init_KCCFLN05(), surf_workstation_model_init_compound(), surf_exit()
542 XBT_PUBLIC(void) surf_init(int *argc, char **argv); /* initialize common structures */
544 /** \brief Finish simulation initialization
545 * \ingroup SURF_simulation
547 * This function must be called before the first call to surf_solve()
549 XBT_PUBLIC(void) surf_presolve(void);
551 /** \brief Performs a part of the simulation
552 * \ingroup SURF_simulation
553 * \return the elapsed time, or -1.0 if no event could be executed
555 * This function execute all possible events, update the action states
556 * and returns the time elapsed.
557 * When you call execute or communicate on a model, the corresponding actions
558 * are not executed immediately but only when you call surf_solve.
559 * Note that the returned elapsed time can be zero.
561 XBT_PUBLIC(double) surf_solve(void);
563 /** \brief Return the current time
564 * \ingroup SURF_simulation
566 * Return the current time in millisecond.
568 XBT_PUBLIC(double)surf_get_clock(void);
571 * \ingroup SURF_simulation
577 XBT_PUBLIC(void) surf_exit(void);
579 /* Prototypes of the functions that handle the properties */
580 XBT_PUBLIC_DATA(xbt_dict_t) current_property_set; /* the prop set for the currently parsed element (also used in SIMIX) */
581 XBT_PUBLIC_DATA(void) parse_properties(void);
583 /* surf parse file related (public because called from a test suite) */
584 XBT_PUBLIC(void) parse_platform_file(const char* file);
586 /* Stores the sets */
587 XBT_PUBLIC_DATA(xbt_dict_t) set_list;
589 XBT_PUBLIC_DATA(void) manage_route(xbt_dict_t route_table, const char* route_name, int action, int isMultiRoute);
590 XBT_PUBLIC_DATA(int) route_action;
592 /* This is used by all models when creating the routing table while parsing */
593 XBT_PUBLIC_DATA(xbt_dict_t) route_table;
594 XBT_PUBLIC_DATA(xbt_dict_t) route_multi_table;
595 XBT_PUBLIC_DATA(xbt_dict_t) route_multi_table;
597 /* For the trace and trace:connect tag (store their content till the end of the parsing) */
598 XBT_PUBLIC_DATA(xbt_dict_t) traces_set_list;
599 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_host_avail;
600 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_power;
601 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_link_avail;
602 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_bandwidth;
603 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_latency;
606 XBT_PUBLIC_DATA(double) get_cpu_power(const char* power);
611 #endif /* _SURF_SURF_H */