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 /* Actions and resources are higly connected structures... */
16 typedef struct surf_action *surf_action_t;
17 typedef struct surf_resource *surf_resource_t;
23 SURF_ACTION_READY = 0, /* Ready */
24 SURF_ACTION_RUNNING, /* Running */
25 SURF_ACTION_FAILED, /* Task Failure */
26 SURF_ACTION_DONE, /* Completed */
27 SURF_ACTION_NOT_IN_THE_SYSTEM /* Not in the system anymore. Why did you ask ? */
28 } e_surf_action_state_t;
30 typedef struct surf_action_state {
31 xbt_swag_t ready_action_set;
32 xbt_swag_t running_action_set;
33 xbt_swag_t failed_action_set;
34 xbt_swag_t done_action_set;
35 } s_surf_action_state_t, *surf_action_state_t;
37 /* Never create s_surf_action_t by yourself !!!! */
38 /* Use action_new from the corresponding resource */
39 typedef struct surf_action {
40 s_xbt_swag_hookup_t state_hookup;
42 double cost; /* cost */
43 double max_duration; /* max_duration (may fluctuate until
44 the task is completed) */
45 double remains; /* How much of that cost remains to
46 * be done in the currently running task */
47 double start; /* start time */
48 double finish; /* finish time : this is modified during the run
49 * and fluctuates until the task is completed */
50 void *data; /* for your convenience */
51 surf_resource_t resource_type;
54 /***************************/
55 /* Generic resource object */
56 /***************************/
58 typedef struct surf_resource_private *surf_resource_private_t;
59 typedef struct surf_resource_public {
60 s_surf_action_state_t states; /* Any living action on this resource */
61 void *(*name_service) (const char *name);
62 const char *(*get_resource_name) (void *resource_id);
64 e_surf_action_state_t(*action_get_state) (surf_action_t action);
65 void (*action_free) (surf_action_t action);
66 void (*action_cancel) (surf_action_t action);
67 void (*action_recycle) (surf_action_t action);
68 void (*action_change_state) (surf_action_t action,
69 e_surf_action_state_t state);
70 void (*action_set_data) (surf_action_t action, void *data);
71 void (*suspend) (surf_action_t action);
72 void (*resume) (surf_action_t action);
73 int (*is_suspended) (surf_action_t action);
75 } s_surf_resource_public_t, *surf_resource_public_t;
77 typedef struct surf_resource {
78 surf_resource_private_t common_private;
79 surf_resource_public_t common_public;
82 /**************************************/
83 /* Implementations of resource object */
84 /**************************************/
86 typedef struct surf_timer_resource_extension_private
87 *surf_timer_resource_extension_private_t;
88 typedef struct surf_timer_resource_extension_public {
89 void (*set) (double date, void *function, void *arg);
90 int (*get) (void **function, void **arg);
91 } s_surf_timer_resource_extension_public_t,
92 *surf_timer_resource_extension_public_t;
94 typedef struct surf_timer_resource {
95 surf_resource_private_t common_private;
96 surf_resource_public_t common_public;
97 surf_timer_resource_extension_public_t extension_public;
98 } s_surf_timer_resource_t, *surf_timer_resource_t;
99 extern surf_timer_resource_t surf_timer_resource;
100 void surf_timer_resource_init(const char *filename);
104 SURF_CPU_ON = 1, /* Ready */
105 SURF_CPU_OFF = 0 /* Running */
106 } e_surf_cpu_state_t;
108 typedef struct surf_cpu_resource_extension_private
109 *surf_cpu_resource_extension_private_t;
110 typedef struct surf_cpu_resource_extension_public {
111 surf_action_t(*execute) (void *cpu, double size);
112 surf_action_t(*sleep) (void *cpu, double duration);
113 e_surf_cpu_state_t(*get_state) (void *cpu);
114 } s_surf_cpu_resource_extension_public_t,
115 *surf_cpu_resource_extension_public_t;
117 typedef struct surf_cpu_resource {
118 surf_resource_private_t common_private;
119 surf_resource_public_t common_public;
120 surf_cpu_resource_extension_public_t extension_public;
121 } s_surf_cpu_resource_t, *surf_cpu_resource_t;
122 extern surf_cpu_resource_t surf_cpu_resource;
123 void surf_cpu_resource_init_Cas01(const char *filename);
125 /* Network resource */
126 typedef struct surf_network_resource_extension_private
127 *surf_network_resource_extension_private_t;
128 typedef struct surf_network_resource_extension_public {
129 surf_action_t(*communicate) (void *src, void *dst, double size,
131 } s_surf_network_resource_extension_public_t,
132 *surf_network_resource_extension_public_t;
134 typedef struct surf_network_resource {
135 surf_resource_private_t common_private;
136 surf_resource_public_t common_public;
137 surf_network_resource_extension_public_t extension_public;
138 } s_surf_network_resource_t, *surf_network_resource_t;
140 extern surf_network_resource_t surf_network_resource;
141 void surf_network_resource_init_CM02(const char *filename);
143 /* Workstation resource */
144 typedef struct surf_workstation_resource_extension_private
145 *surf_workstation_resource_extension_private_t;
146 typedef struct surf_workstation_resource_extension_public {
147 surf_action_t(*execute) (void *workstation, double size);
148 surf_action_t(*sleep) (void *workstation, double duration);
149 e_surf_cpu_state_t(*get_state) (void *workstation);
150 surf_action_t(*communicate) (void *workstation_src,
151 void *workstation_dst, double size,
153 } s_surf_workstation_resource_extension_public_t,
154 *surf_workstation_resource_extension_public_t;
156 typedef struct surf_workstation_resource {
157 surf_resource_private_t common_private;
158 surf_resource_public_t common_public;
159 surf_workstation_resource_extension_public_t extension_public;
160 } s_surf_workstation_resource_t, *surf_workstation_resource_t;
162 extern surf_workstation_resource_t surf_workstation_resource;
163 void surf_workstation_resource_init_CLM03(const char *filename);
164 void surf_workstation_resource_init_KCCFLN05(const char *filename);
165 extern xbt_dict_t workstation_set;
167 /*******************************************/
168 /*** SURF Globals **************************/
169 /*******************************************/
171 void surf_init(int *argc, char **argv); /* initialize common structures */
173 extern xbt_dynar_t resource_list; /* list of initialized resources */
175 double surf_solve(void); /* update all states and returns
176 the time elapsed since last
178 double surf_get_clock(void);
179 void surf_finalize(void); /* clean everything */
181 #endif /* _SURF_SURF_H */