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"
21 /* Actions and models are higly connected structures... */
23 /** \brief Action datatype
24 * \ingroup SURF_actions
26 * An action is some working amount on a model.
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_models
36 * Generic data structure for a model. The workstations,
37 * the CPUs and the network links are examples of models.
39 typedef struct surf_model *surf_model_t;
41 /** \brief Resource model description
43 typedef struct surf_model_description {
46 void (* model_init) (const char *filename);
47 void (* create_ws) (void);
48 } s_surf_model_description_t, *surf_model_description_t;
50 XBT_PUBLIC(void) update_model_description(s_surf_model_description_t *table,
54 XBT_PUBLIC(int) find_model_description(s_surf_model_description_t *table,
57 /** \brief Action structure
58 * \ingroup SURF_actions
60 * Never create s_surf_action_t by yourself ! The actions are created
61 * on the fly when you call execute or communicate on a model.
63 * \see e_surf_action_state_t
65 typedef struct surf_action {
66 s_xbt_swag_hookup_t state_hookup;
68 double cost; /**< cost */
69 double priority; /**< priority (1.0 by default) */
70 double max_duration; /**< max_duration (may fluctuate until
71 the task is completed) */
72 double remains; /**< How much of that cost remains to
73 * be done in the currently running task */
74 double start; /**< start time */
75 double finish; /**< finish time : this is modified during the run
76 * and fluctuates until the task is completed */
77 void *data; /**< for your convenience */
79 surf_model_t model_type;
82 /** \brief Action states
83 * \ingroup SURF_actions
87 * \see surf_action_t, surf_action_state_t
90 SURF_ACTION_READY = 0, /**< Ready */
91 SURF_ACTION_RUNNING, /**< Running */
92 SURF_ACTION_FAILED, /**< Task Failure */
93 SURF_ACTION_DONE, /**< Completed */
94 SURF_ACTION_TO_FREE, /**< Action to free in next cleanup */
95 SURF_ACTION_NOT_IN_THE_SYSTEM /**< Not in the system anymore. Why did you ask ? */
96 } e_surf_action_state_t;
98 /** \brief Action state sets
99 * \ingroup SURF_actions
101 * This structure contains some sets of actions.
102 * It provides a fast access to the actions in each state.
104 * \see surf_action_t, e_surf_action_state_t
106 typedef struct surf_action_state {
107 xbt_swag_t ready_action_set; /**< Actions in state SURF_ACTION_READY */
108 xbt_swag_t running_action_set; /**< Actions in state SURF_ACTION_RUNNING */
109 xbt_swag_t failed_action_set; /**< Actions in state SURF_ACTION_FAILED */
110 xbt_swag_t done_action_set; /**< Actions in state SURF_ACTION_DONE */
111 } s_surf_action_state_t, *surf_action_state_t;
113 /***************************/
114 /* Generic model object */
115 /***************************/
117 /** \brief Public data available on all models
118 * \ingroup SURF_models
120 * These functions are implemented by all models.
122 typedef struct surf_model_public {
123 s_surf_action_state_t states; /**< Any living action on this model */
124 void *(*name_service) (const char *name); /**< Return a model given its name */
125 const char *(*get_resource_name) (void *resource_id); /**< Return the name of a resource */
127 e_surf_action_state_t(*action_get_state) (surf_action_t action); /**< Return the state of an action */
128 double (*action_get_start_time) (surf_action_t action); /**< Return the start time of an action */
129 double (*action_get_finish_time) (surf_action_t action); /**< Return the finish time of an action */
130 void (*action_use) (surf_action_t action); /**< Set an action used */
131 int (*action_free) (surf_action_t action); /**< Free an action */
132 void (*action_cancel) (surf_action_t action); /**< Cancel a running action */
133 void (*action_recycle) (surf_action_t action); /**< Recycle an action */
134 void (*action_change_state) (surf_action_t action, /**< Change an action state*/
135 e_surf_action_state_t state);
136 void (*action_set_data) (surf_action_t action, void *data); /**< Set the user data of an action */
137 void (*suspend) (surf_action_t action); /**< Suspend an action */
138 void (*resume) (surf_action_t action); /**< Resume a suspended action */
139 int (*is_suspended) (surf_action_t action); /**< Return whether an action is suspended */
140 void (*set_max_duration) (surf_action_t action, double duration); /**< Set the max duration of an action*/
141 void (*set_priority) (surf_action_t action, double priority); /**< Set the priority of an action */
142 xbt_dict_t (*get_properties) (void* resource_id); /**< Return the properties dictionary */
143 const char *name; /**< Name of this model */
144 } s_surf_model_public_t, *surf_model_public_t;
146 /** \brief Private data available on all models
147 * \ingroup SURF_models
149 typedef struct surf_model_private *surf_model_private_t;
151 /** \brief Resource datatype
152 * \ingroup SURF_models
154 * Generic data structure for a model. The workstations,
155 * the CPUs and the network links are examples of models.
157 typedef struct surf_model {
158 surf_model_private_t common_private;
159 surf_model_public_t common_public;
162 /**************************************/
163 /* Implementations of model object */
164 /**************************************/
166 /** \brief Timer model extension public
167 * \ingroup SURF_model
169 * Additionnal functions specific to the timer model
171 typedef struct surf_timer_model_extension_public {
172 void (*set) (double date, void *function, void *arg);
173 int (*get) (void **function, void **arg);
174 } s_surf_timer_model_extension_public_t,
175 *surf_timer_model_extension_public_t;
177 /** \brief Timer model
178 * \ingroup SURF_models
180 typedef struct surf_timer_model {
181 surf_model_private_t common_private;
182 surf_model_public_t common_public;
183 surf_timer_model_extension_public_t extension_public;
184 } s_surf_timer_model_t, *surf_timer_model_t;
186 /** \brief The timer model
187 * \ingroup SURF_models
189 XBT_PUBLIC_DATA(surf_timer_model_t) surf_timer_model;
191 /** \brief Initializes the timer model
192 * \ingroup SURF_models
194 XBT_PUBLIC(void) surf_timer_model_init(const char *filename);
199 * \ingroup SURF_models
202 SURF_CPU_ON = 1, /**< Up & ready */
203 SURF_CPU_OFF = 0 /**< Down & broken */
204 } e_surf_cpu_state_t;
206 /** \brief CPU model extension public
207 * \ingroup SURF_models
209 * Public functions specific to the CPU model.
211 typedef struct surf_cpu_model_extension_public {
212 surf_action_t(*execute) (void *cpu, double size);
213 surf_action_t(*sleep) (void *cpu, double duration);
214 e_surf_cpu_state_t(*get_state) (void *cpu);
215 double (*get_speed) (void *cpu, double load);
216 double (*get_available_speed) (void *cpu);
217 } s_surf_cpu_model_extension_public_t,
218 *surf_cpu_model_extension_public_t;
220 /** \brief CPU model datatype
221 * \ingroup SURF_models
223 typedef struct surf_cpu_model {
224 surf_model_private_t common_private;
225 surf_model_public_t common_public;
226 surf_cpu_model_extension_public_t extension_public;
227 } s_surf_cpu_model_t, *surf_cpu_model_t;
229 /** \brief The CPU model
230 * \ingroup SURF_models
232 XBT_PUBLIC_DATA(surf_cpu_model_t) surf_cpu_model;
234 /** \brief Initializes the CPU model with the model Cas01
235 * \ingroup SURF_models
237 * This function is called by surf_workstation_model_init_CLM03
238 * so you shouldn't have to call it by yourself.
240 * \see surf_workstation_model_init_CLM03()
242 XBT_PUBLIC(void) surf_cpu_model_init_Cas01(const char *filename);
244 /** \brief The list of all available cpu model models
245 * \ingroup SURF_models
247 XBT_PUBLIC_DATA(s_surf_model_description_t) surf_cpu_model_description[];
251 /** \brief Network model extension public
252 * \ingroup SURF_models
254 * Public functions specific to the network model
256 typedef struct surf_network_model_extension_public {
257 surf_action_t(*communicate) (void *src, void *dst, double size,
259 const void** (*get_route) (void *src, void *dst);
260 int (*get_route_size) (void *src, void *dst);
261 const char* (*get_link_name) (const void *link);
262 double (*get_link_bandwidth) (const void *link);
263 double (*get_link_latency) (const void *link);
264 int (*link_shared) (const void *link);
265 } s_surf_network_model_extension_public_t,
266 *surf_network_model_extension_public_t;
268 /** \brief Network model datatype
269 * \ingroup SURF_models
271 typedef struct surf_network_model {
272 surf_model_private_t common_private;
273 surf_model_public_t common_public;
274 surf_network_model_extension_public_t extension_public;
275 } s_surf_network_model_t, *surf_network_model_t;
277 XBT_PUBLIC(void) create_workstations(void);
279 /** \brief The network model
280 * \ingroup SURF_models
282 * When creating a new API on top on SURF, you shouldn't use the
283 * network model unless you know what you are doing. Only the workstation
284 * model should be accessed because depending on the platform model,
285 * the network model can be NULL.
287 XBT_PUBLIC_DATA(surf_network_model_t) surf_network_model;
289 /** \brief Initializes the platform with the network model 'LagrangeVelho'
290 * \ingroup SURF_models
291 * \param filename XML platform file name
293 * This model is proposed by Arnaud Legrand and Pedro Velho based on
294 * the results obtained with the GTNets simulator for onelink and
295 * dogbone sharing scenarios.
297 * \see surf_workstation_model_init_LegrandVelho()
299 XBT_PUBLIC(void) surf_network_model_init_LegrandVelho(const char *filename);
301 /** \brief Initializes the platform with the network model 'Constant'
302 * \ingroup SURF_models
303 * \param filename XML platform file name
305 * In this model, the communication time between two network cards is
306 * constant, hence no need for a routing table. This is particularly
307 * usefull when simulating huge distributed algorithms where
308 * scalability is really an issue. This function is called in
309 * conjunction with surf_workstation_model_init_compound.
311 * \see surf_workstation_model_init_compound()
313 XBT_PUBLIC(void) surf_network_model_init_Constant(const char *filename);
315 /** \brief Initializes the platform with the network model CM02
316 * \ingroup SURF_models
317 * \param filename XML platform file name
319 * This function is called by surf_workstation_model_init_CLM03
320 * or by yourself only if you plan using surf_workstation_model_init_compound
322 * \see surf_workstation_model_init_CLM03()
324 XBT_PUBLIC(void) surf_network_model_init_CM02(const char *filename);
327 /** \brief Initializes the platform with the network model GTNETS
328 * \ingroup SURF_models
329 * \param filename XML platform file name
331 * This function is called by surf_workstation_model_init_GTNETS
332 * or by yourself only if you plan using surf_workstation_model_init_compound
334 * \see surf_workstation_model_init_GTNETS()
336 XBT_PUBLIC(void) surf_network_model_init_GTNETS(const char *filename);
339 /** \brief Initializes the platform with the network model Reno
340 * \ingroup SURF_models
341 * \param filename XML platform file name
343 * The problem is related to max( sum( arctan(C * Df * xi) ) ).
346 * [LOW03] S. H. Low. A duality model of TCP and queue management algorithms.
347 * IEEE/ACM Transaction on Networking, 11(4):525-536, 2003.
349 * Call this function only if you plan using surf_workstation_model_init_compound.
352 XBT_PUBLIC(void) surf_network_model_init_Reno(const char *filename);
354 /** \brief Initializes the platform with the network model Reno2
355 * \ingroup SURF_models
356 * \param filename XML platform file name
358 * The problem is related to max( sum( arctan(C * Df * xi) ) ).
361 * [LOW01] S. H. Low. A duality model of TCP and queue management algorithms.
362 * IEEE/ACM Transaction on Networking, 11(4):525-536, 2003.
364 * Call this function only if you plan using surf_workstation_model_init_compound.
367 XBT_PUBLIC(void) surf_network_model_init_Reno2(const char *filename);
369 /** \brief Initializes the platform with the network model Vegas
370 * \ingroup SURF_models
371 * \param filename XML platform file name
373 * This problem is related to max( sum( a * Df * ln(xi) ) ) which is equivalent
374 * to the proportional fairness.
377 * [LOW03] S. H. Low. A duality model of TCP and queue management algorithms.
378 * IEEE/ACM Transaction on Networking, 11(4):525-536, 2003.
380 * Call this function only if you plan using surf_workstation_model_init_compound.
383 XBT_PUBLIC(void) surf_network_model_init_Vegas(const char *filename);
386 /** \brief Initializes the platform with the network model based on SDP
387 * \ingroup SURF_models
388 * \param filename XML platform file name
390 * This function implements the proportional fairness known as the maximization
395 * [TAG03]. Corinne Touati, Eitan Altman, and Jerome Galtier.
396 * Semi-definite programming approach for bandwidth allocation and routing in networks.
397 * Game Theory and Applications, 9:169-179, December 2003. Nova publisher.
399 * Call this function only if you plan using surf_workstation_model_init_compound.
401 XBT_PUBLIC(void) surf_network_model_init_SDP(const char *filename);
404 /** \brief The list of all available network model models
405 * \ingroup SURF_models
407 XBT_PUBLIC_DATA(s_surf_model_description_t) surf_network_model_description[];
409 /** \brief Workstation model extension public
410 * \ingroup SURF_models
412 * Public functions specific to the workstation model.
414 typedef struct surf_workstation_model_extension_public {
415 surf_action_t(*execute) (void *workstation, double size); /**< Execute a computation amount on a workstation
416 and create the corresponding action */
417 surf_action_t(*sleep) (void *workstation, double duration); /**< Make a workstation sleep during a given duration */
418 e_surf_cpu_state_t(*get_state) (void *workstation); /**< Return the CPU state of a workstation */
419 double (*get_speed) (void *workstation, double load); /**< Return the speed of a workstation */
420 double (*get_available_speed) (void *workstation); /**< Return tha available speed of a workstation */
421 surf_action_t(*communicate) (void *workstation_src, /**< Execute a communication amount between two workstations */
422 void *workstation_dst, double size,
425 surf_action_t(*execute_parallel_task) (int workstation_nb, /**< Execute a parallel task on several workstations */
426 void **workstation_list,
427 double *computation_amount,
428 double *communication_amount,
431 const void** (*get_route) (void *src, void *dst); /**< Return the network link list between two workstations */
432 int (*get_route_size) (void *src, void *dst); /**< Return the route size between two workstations */
433 const char* (*get_link_name) (const void *link); /**< Return the name of a network link */
434 double (*get_link_bandwidth) (const void *link); /**< Return the current bandwidth of a network link */
435 double (*get_link_latency) (const void *link); /**< Return the current latency of a network link */
436 int (*link_shared) (const void *link);
437 } s_surf_workstation_model_extension_public_t,
438 *surf_workstation_model_extension_public_t;
440 /** \brief Workstation model datatype.
441 * \ingroup SURF_models
444 typedef struct surf_workstation_model {
445 surf_model_private_t common_private;
446 surf_model_public_t common_public;
447 surf_workstation_model_extension_public_t extension_public;
448 } s_surf_workstation_model_t, *surf_workstation_model_t;
450 /** \brief The workstation model
451 * \ingroup SURF_models
453 * Note that when you create an API on top of SURF,
454 * the workstation model should be the only one you use
455 * because depending on the platform model, the network model and the CPU model
458 XBT_PUBLIC_DATA(surf_workstation_model_t) surf_workstation_model;
460 /** \brief Initializes the platform with a compound workstation model
461 * \ingroup SURF_models
462 * \param filename XML platform file name
464 * This function should be called after a cpu_model and a
465 * network_model have been set up.
468 XBT_PUBLIC(void) surf_workstation_model_init_compound(const char *filename);
470 /** \brief Initializes the platform with the workstation model CLM03
471 * \ingroup SURF_models
472 * \param filename XML platform file name
474 * This platform model seperates the workstation model and the network model.
475 * The workstation model will be initialized with the model CLM03, the network
476 * model with the model CM02 and the CPU model with the model Cas01.
477 * In future releases, some other network models will be implemented and will be
478 * combined with the workstation model CLM03.
480 * \see surf_workstation_model_init_KCCFLN05()
482 XBT_PUBLIC(void) surf_workstation_model_init_CLM03(const char *filename);
484 /** \brief Initializes the platform with the model KCCFLN05
485 * \ingroup SURF_models
486 * \param filename XML platform file name
488 * With this model, the workstations and the network are handled
489 * together. The network model is roughly the same as in CM02 but
490 * interference between computations and communications can be taken
491 * into account. This platform model is the default one for MSG and
495 XBT_PUBLIC(void) surf_workstation_model_init_KCCFLN05(const char *filename);
497 /** \brief Initializes the platform with the model KCCFLN05
498 * \ingroup SURF_models
499 * \param filename XML platform file name
501 * With this model, only parallel tasks can be used. Resource sharing
502 * is done by identifying bottlenecks and giving an equal share of
503 * the model to each action.
506 XBT_PUBLIC(void) surf_workstation_model_init_ptask_L07(const char *filename);
508 /** \brief The list of all available workstation model models
509 * \ingroup SURF_models
511 XBT_PUBLIC_DATA(s_surf_model_description_t) surf_workstation_model_description[];
513 /** \brief The network links
514 * \ingroup SURF_models
516 * This dict contains all network links.
518 * \see workstation_set
520 XBT_PUBLIC_DATA(xbt_dict_t) link_set;
522 /** \brief The workstations
523 * \ingroup SURF_models
525 * This dict contains all workstations.
529 XBT_PUBLIC_DATA(xbt_dict_t) workstation_set;
530 XBT_PUBLIC_DATA(xbt_dict_t) cpu_set;
531 /** \brief List of initialized models
532 * \ingroup SURF_models
534 XBT_PUBLIC_DATA(xbt_dynar_t) model_list;
536 /*******************************************/
537 /*** SURF Globals **************************/
538 /*******************************************/
540 /** \brief Initialize SURF
541 * \ingroup SURF_simulation
542 * \param argc argument number
543 * \param argv arguments
545 * This function has to be called to initialize the common
546 * structures. Then you will have to create the environment by
547 * calling surf_timer_model_init() and
548 * e.g. surf_workstation_model_init_CLM03() or
549 * surf_workstation_model_init_KCCFLN05().
551 * \see surf_timer_model_init(), surf_workstation_model_init_CLM03(),
552 * surf_workstation_model_init_KCCFLN05(), surf_workstation_model_init_compound(), surf_exit()
554 XBT_PUBLIC(void) surf_init(int *argc, char **argv); /* initialize common structures */
556 /** \brief Finish simulation initialization
557 * \ingroup SURF_simulation
559 * This function must be called before the first call to surf_solve()
561 XBT_PUBLIC(void) surf_presolve(void);
563 /** \brief Performs a part of the simulation
564 * \ingroup SURF_simulation
565 * \return the elapsed time, or -1.0 if no event could be executed
567 * This function execute all possible events, update the action states
568 * and returns the time elapsed.
569 * When you call execute or communicate on a model, the corresponding actions
570 * are not executed immediately but only when you call surf_solve.
571 * Note that the returned elapsed time can be zero.
573 XBT_PUBLIC(double) surf_solve(void);
575 /** \brief Return the current time
576 * \ingroup SURF_simulation
578 * Return the current time in millisecond.
580 XBT_PUBLIC(double)surf_get_clock(void);
583 * \ingroup SURF_simulation
589 XBT_PUBLIC(void) surf_exit(void);
591 /* Prototypes of the functions that handle the properties */
592 XBT_PUBLIC_DATA(xbt_dict_t) current_property_set; /* the prop set for the currently parsed element (also used in SIMIX) */
593 XBT_PUBLIC_DATA(void) parse_properties(void);
595 /* surf parse file related (public because called from a test suite) */
596 XBT_PUBLIC(void) parse_platform_file(const char* file);
598 /* Stores the sets */
599 XBT_PUBLIC_DATA(xbt_dict_t) set_list;
601 XBT_PUBLIC_DATA(void) manage_route(xbt_dict_t route_table, const char* route_name, int action, int isMultiRoute);
602 XBT_PUBLIC_DATA(int) route_action;
604 /* This is used by all models when creating the routing table while parsing */
605 XBT_PUBLIC_DATA(xbt_dict_t) route_table;
606 XBT_PUBLIC_DATA(xbt_dict_t) route_multi_table;
609 /* For the trace and trace:connect tag (store their content till the end of the parsing) */
610 XBT_PUBLIC_DATA(xbt_dict_t) traces_set_list;
611 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_host_avail;
612 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_power;
613 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_link_avail;
614 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_bandwidth;
615 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_latency;
618 XBT_PUBLIC_DATA(double) get_cpu_power(const char* power);
623 #endif /* _SURF_SURF_H */