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 resources are higly connected structures... */
22 /** \brief Action datatype
23 * \ingroup SURF_actions
25 * An action is some working amount on a resource.
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_resources
35 * Generic data structure for a resource. The workstations,
36 * the CPUs and the network links are examples of resources.
38 typedef struct surf_resource *surf_resource_t;
40 /** \brief Action structure
41 * \ingroup SURF_actions
43 * Never create s_surf_action_t by yourself ! The actions are created
44 * on the fly when you call execute or communicate on a resource.
46 * \see e_surf_action_state_t
48 typedef struct surf_action {
49 s_xbt_swag_hookup_t state_hookup;
51 double cost; /**< cost */
52 double priority; /**< priority (1.0 by default) */
53 double max_duration; /**< max_duration (may fluctuate until
54 the task is completed) */
55 double remains; /**< How much of that cost remains to
56 * be done in the currently running task */
57 double start; /**< start time */
58 double finish; /**< finish time : this is modified during the run
59 * and fluctuates until the task is completed */
60 void *data; /**< for your convenience */
62 surf_resource_t resource_type;
65 /** \brief Action states
66 * \ingroup SURF_actions
70 * \see surf_action_t, surf_action_state_t
73 SURF_ACTION_READY = 0, /**< Ready */
74 SURF_ACTION_RUNNING, /**< Running */
75 SURF_ACTION_FAILED, /**< Task Failure */
76 SURF_ACTION_DONE, /**< Completed */
77 SURF_ACTION_TO_FREE, /**< Action to free in next cleanup */
78 SURF_ACTION_NOT_IN_THE_SYSTEM /**< Not in the system anymore. Why did you ask ? */
79 } e_surf_action_state_t;
81 /** \brief Action state sets
82 * \ingroup SURF_actions
84 * This structure contains some sets of actions.
85 * It provides a fast access to the actions in each state.
87 * \see surf_action_t, e_surf_action_state_t
89 typedef struct surf_action_state {
90 xbt_swag_t ready_action_set; /**< Actions in state SURF_ACTION_READY */
91 xbt_swag_t running_action_set; /**< Actions in state SURF_ACTION_RUNNING */
92 xbt_swag_t failed_action_set; /**< Actions in state SURF_ACTION_FAILED */
93 xbt_swag_t done_action_set; /**< Actions in state SURF_ACTION_DONE */
94 } s_surf_action_state_t, *surf_action_state_t;
96 /***************************/
97 /* Generic resource object */
98 /***************************/
100 /** \brief Public data available on all resources
101 * \ingroup SURF_resources
103 * These functions are implemented by all resources.
105 typedef struct surf_resource_public {
106 s_surf_action_state_t states; /**< Any living action on this resource */
107 void *(*name_service) (const char *name); /**< Return a resource given its name */
108 const char *(*get_resource_name) (void *resource_id); /**< Return the name of a resource */
110 e_surf_action_state_t(*action_get_state) (surf_action_t action); /**< Return the state of an action */
111 double (*action_get_start_time) (surf_action_t action); /**< Return the start time of an action */
112 double (*action_get_finish_time) (surf_action_t action); /**< Return the finish time of an action */
113 void (*action_use) (surf_action_t action); /**< Set an action used */
114 int (*action_free) (surf_action_t action); /**< Free an action */
115 void (*action_cancel) (surf_action_t action); /**< Cancel a running action */
116 void (*action_recycle) (surf_action_t action); /**< Recycle an action */
117 void (*action_change_state) (surf_action_t action, /**< Change an action state*/
118 e_surf_action_state_t state);
119 void (*action_set_data) (surf_action_t action, void *data); /**< Set the user data of an action */
120 void (*suspend) (surf_action_t action); /**< Suspend an action */
121 void (*resume) (surf_action_t action); /**< Resume a suspended action */
122 int (*is_suspended) (surf_action_t action); /**< Return whether an action is suspended */
123 void (*set_max_duration) (surf_action_t action, double duration); /**< Set the max duration of an action*/
124 void (*set_priority) (surf_action_t action, double priority); /**< Set the priority of an action */
125 const char *name; /**< Name of this resource */
126 } s_surf_resource_public_t, *surf_resource_public_t;
128 /** \brief Private data available on all resources
129 * \ingroup SURF_resources
131 typedef struct surf_resource_private *surf_resource_private_t;
133 /** \brief Resource datatype
134 * \ingroup SURF_resources
136 * Generic data structure for a resource. The workstations,
137 * the CPUs and the network links are examples of resources.
139 typedef struct surf_resource {
140 surf_resource_private_t common_private;
141 surf_resource_public_t common_public;
144 /**************************************/
145 /* Implementations of resource object */
146 /**************************************/
148 /** \brief Timer resource extension public
149 * \ingroup SURF_resource
151 * Additionnal functions specific to the timer resource
153 typedef struct surf_timer_resource_extension_public {
154 void (*set) (double date, void *function, void *arg);
155 int (*get) (void **function, void **arg);
156 } s_surf_timer_resource_extension_public_t,
157 *surf_timer_resource_extension_public_t;
159 /** \brief Timer resource
160 * \ingroup SURF_resources
162 typedef struct surf_timer_resource {
163 surf_resource_private_t common_private;
164 surf_resource_public_t common_public;
165 surf_timer_resource_extension_public_t extension_public;
166 } s_surf_timer_resource_t, *surf_timer_resource_t;
168 /** \brief The timer resource
169 * \ingroup SURF_resources
171 extern surf_timer_resource_t XBT_PUBLIC_DATA surf_timer_resource;
173 /** \brief Initializes the timer resource
174 * \ingroup SURF_resources
176 XBT_PUBLIC(void) surf_timer_resource_init(const char *filename);
181 * \ingroup SURF_resources
184 SURF_CPU_ON = 1, /**< Ready */
185 SURF_CPU_OFF = 0 /**< Running */
186 } e_surf_cpu_state_t;
188 /** \brief CPU resource extension public
189 * \ingroup SURF_resources
191 * Public functions specific to the CPU resource.
193 typedef struct surf_cpu_resource_extension_public {
194 surf_action_t(*execute) (void *cpu, double size);
195 surf_action_t(*sleep) (void *cpu, double duration);
196 e_surf_cpu_state_t(*get_state) (void *cpu);
197 double (*get_speed) (void *cpu, double load);
198 double (*get_available_speed) (void *cpu);
199 } s_surf_cpu_resource_extension_public_t,
200 *surf_cpu_resource_extension_public_t;
202 /** \brief CPU resource datatype
203 * \ingroup SURF_resources
205 typedef struct surf_cpu_resource {
206 surf_resource_private_t common_private;
207 surf_resource_public_t common_public;
208 surf_cpu_resource_extension_public_t extension_public;
209 } s_surf_cpu_resource_t, *surf_cpu_resource_t;
211 /** \brief The CPU resource
212 * \ingroup SURF_resources
214 extern surf_cpu_resource_t XBT_PUBLIC_DATA surf_cpu_resource;
216 /** \brief Initializes the CPU resource with the model Cas01
217 * \ingroup SURF_resources
219 * This function is called by surf_workstation_resource_init_CLM03
220 * so you shouldn't have to call it by yourself.
222 * \see surf_workstation_resource_init_CLM03()
224 XBT_PUBLIC(void) surf_cpu_resource_init_Cas01(const char *filename);
226 /* Network resource */
228 /** \brief Network resource extension public
229 * \ingroup SURF_resources
231 * Public functions specific to the network resource
233 typedef struct surf_network_resource_extension_public {
234 surf_action_t(*communicate) (void *src, void *dst, double size,
236 const void** (*get_route) (void *src, void *dst);
237 int (*get_route_size) (void *src, void *dst);
238 const char* (*get_link_name) (const void *link);
239 double (*get_link_bandwidth) (const void *link);
240 double (*get_link_latency) (const void *link);
241 } s_surf_network_resource_extension_public_t,
242 *surf_network_resource_extension_public_t;
244 /** \brief Network resource datatype
245 * \ingroup SURF_resources
247 typedef struct surf_network_resource {
248 surf_resource_private_t common_private;
249 surf_resource_public_t common_public;
250 surf_network_resource_extension_public_t extension_public;
251 } s_surf_network_resource_t, *surf_network_resource_t;
253 /** \brief The network resource
254 * \ingroup SURF_resources
256 * When creating a new API on top on SURF, you shouldn't use the
257 * network resource unless you know what you are doing. Only the workstation
258 * resource should be accessed because depending on the platform model,
259 * the network resource can be NULL.
261 extern surf_network_resource_t XBT_PUBLIC_DATA surf_network_resource;
263 /** \brief Initializes the platform with the network model CM02
264 * \ingroup SURF_resources
265 * \param filename XML platform file name
267 * This function is called by surf_workstation_resource_init_CLM03
268 * so you shouldn't call it by yourself.
270 * \see surf_workstation_resource_init_CLM03()
272 XBT_PUBLIC(void) surf_network_resource_init_CM02(const char *filename);
274 /** \brief Workstation resource extension public
275 * \ingroup SURF_resources
277 * Public functions specific to the workstation resource.
279 typedef struct surf_workstation_resource_extension_public {
280 surf_action_t(*execute) (void *workstation, double size); /**< Execute a computation amount on a workstation
281 and create the corresponding action */
282 surf_action_t(*sleep) (void *workstation, double duration); /**< Make a workstation sleep during a given duration */
283 e_surf_cpu_state_t(*get_state) (void *workstation); /**< Return the CPU state of a workstation */
284 double (*get_speed) (void *workstation, double load); /**< Return the speed of a workstation */
285 double (*get_available_speed) (void *workstation); /**< Return tha available speed of a workstation */
286 surf_action_t(*communicate) (void *workstation_src, /**< Execute a communication amount between two workstations */
287 void *workstation_dst, double size,
289 surf_action_t(*execute_parallel_task) (int workstation_nb, /**< Execute a parallel task on several workstations */
290 void **workstation_list,
291 double *computation_amount,
292 double *communication_amount,
295 const void** (*get_route) (void *src, void *dst); /**< Return the network link list between two workstations */
296 int (*get_route_size) (void *src, void *dst); /**< Return the route size between two workstations */
297 const char* (*get_link_name) (const void *link); /**< Return the name of a network link */
298 double (*get_link_bandwidth) (const void *link); /**< Return the current bandwidth of a network link */
299 double (*get_link_latency) (const void *link); /**< Return the current latency of a network link */
300 } s_surf_workstation_resource_extension_public_t,
301 *surf_workstation_resource_extension_public_t;
303 /** \brief Workstation resource datatype.
304 * \ingroup SURF_resources
307 typedef struct surf_workstation_resource {
308 surf_resource_private_t common_private;
309 surf_resource_public_t common_public;
310 surf_workstation_resource_extension_public_t extension_public;
311 } s_surf_workstation_resource_t, *surf_workstation_resource_t;
313 /** \brief The workstation resource
314 * \ingroup SURF_resources
316 * Note that when you create an API on top of SURF,
317 * the workstation resource should be the only one you use
318 * because depending on the platform model, the network resource and the CPU resource
321 extern surf_workstation_resource_t XBT_PUBLIC_DATA surf_workstation_resource;
323 /** \brief Initializes the platform with the workstation model CLM03
324 * \ingroup SURF_resources
325 * \param filename XML platform file name
327 * This platform model seperates the workstation resource and the network resource.
328 * The workstation resource will be initialized with the model CLM03, the network
329 * resource with the model CM02 and the CPU resource with the model Cas01.
330 * In future releases, some other network models will be implemented and will be
331 * combined with the workstation model CLM03.
333 * \see surf_workstation_resource_init_KCCFLN05()
335 XBT_PUBLIC(void) surf_workstation_resource_init_CLM03(const char *filename);
337 /** \brief Initializes the platform with the model KCCFLN05
338 * \ingroup SURF_resources
339 * \param filename XML platform file name
341 * With this model, the workstations and the network are handled together.
342 * There is no network resource. This platform model is the default one for
345 * \see surf_workstation_resource_init_CLM03()
348 XBT_PUBLIC(void) surf_workstation_resource_init_KCCFLN05(const char *filename);
351 XBT_PUBLIC(void) surf_workstation_resource_init_KCCFLN05_proportionnal(const char *filename);
355 XBT_PUBLIC(void) surf_workstation_resource_init_GTNETS(const char *filename);
358 /** \brief The network links
359 * \ingroup SURF_resources
361 * This dict contains all network links.
363 * \see workstation_set
365 extern xbt_dict_t XBT_PUBLIC_DATA network_link_set;
367 /** \brief The workstations
368 * \ingroup SURF_resources
370 * This dict contains all workstations.
372 * \see network_link_set
374 extern xbt_dict_t XBT_PUBLIC_DATA workstation_set;
376 /** \brief List of initialized resources
377 * \ingroup SURF_resources
379 extern xbt_dynar_t XBT_PUBLIC_DATA resource_list;
381 /*******************************************/
382 /*** SURF Globals **************************/
383 /*******************************************/
385 /** \brief Initialize SURF
386 * \ingroup SURF_simulation
387 * \param argc argument number
388 * \param argv arguments
390 * This function has to be called to initialize the common structures.
391 * Then you will have to create the environment by calling surf_timer_resource_init()
392 * and surf_workstation_resource_init_CLM03() or surf_workstation_resource_init_KCCFLN05().
394 * \see surf_timer_resource_init(), surf_workstation_resource_init_CLM03(),
395 * surf_workstation_resource_init_KCCFLN05(), surf_exit()
397 XBT_PUBLIC(void) surf_init(int *argc, char **argv); /* initialize common structures */
399 /** \brief Performs a part of the simulation
400 * \ingroup SURF_simulation
401 * \return the elapsed time, or -1.0 if no event could be executed
403 * This function execute all possible events, update the action states
404 * and returns the time elapsed.
405 * When you call execute or communicate on a resource, the corresponding actions
406 * are not executed immediately but only when you call surf_solve.
407 * Note that the returned elapsed time can be zero.
409 XBT_PUBLIC(double) surf_solve(void);
411 /** \brief Return the current time
412 * \ingroup SURF_simulation
414 * Return the current time in millisecond.
416 XBT_PUBLIC(double)surf_get_clock(void);
419 * \ingroup SURF_simulation
425 XBT_PUBLIC(void) surf_exit(void);
429 #endif /* _SURF_SURF_H */