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/heap.h" /* for xbt_heap_float_t only */
13 #include "surf/maxmin.h" /* for xbt_maxmin_float_t only */
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 xbt_maxmin_float_t cost; /* cost */
43 xbt_maxmin_float_t remains; /* How much of that cost remains to
44 * be done in the currently running task */
45 xbt_heap_float_t start; /* start time */
46 xbt_heap_float_t finish; /* finish time : this is modified during the run
47 * and fluctuates until the task is completed */
48 void *callback; /* for your convenience */
49 surf_resource_t resource_type;
52 /***************************/
53 /* Generic resource object */
54 /***************************/
56 typedef struct surf_resource_private *surf_resource_private_t;
57 typedef struct surf_resource_public {
58 s_surf_action_state_t states; /* Any living action on this resource */
59 void *(*name_service) (const char *name);
60 const char *(*get_resource_name) (void *resource_id);
62 e_surf_action_state_t(*action_get_state) (surf_action_t action);
63 void (*action_free) (surf_action_t action);
64 void (*action_cancel) (surf_action_t action);
65 void (*action_recycle) (surf_action_t action);
66 void (*action_change_state) (surf_action_t action,
67 e_surf_action_state_t state);
68 } s_surf_resource_public_t, *surf_resource_public_t;
70 typedef struct surf_resource {
71 surf_resource_private_t common_private;
72 surf_resource_public_t common_public;
75 typedef struct surf_resource_object {
76 surf_resource_t resource;
77 } s_surf_resource_object_t, *surf_resource_object_t;
79 /**************************************/
80 /* Implementations of resource object */
81 /**************************************/
84 SURF_CPU_ON = 1, /* Ready */
85 SURF_CPU_OFF = 0 /* Running */
88 typedef struct surf_cpu_resource_extension_private
89 *surf_cpu_resource_extension_private_t;
90 typedef struct surf_cpu_resource_extension_public {
91 surf_action_t(*execute) (void *cpu, xbt_maxmin_float_t size);
92 surf_action_t(*wait) (void *cpu, xbt_maxmin_float_t size);
93 e_surf_cpu_state_t(*get_state) (void *cpu);
94 } s_surf_cpu_resource_extension_public_t,
95 *surf_cpu_resource_extension_public_t;
97 typedef struct surf_cpu_resource {
98 surf_resource_private_t common_private;
99 surf_resource_public_t common_public;
100 surf_cpu_resource_extension_public_t extension_public;
101 } s_surf_cpu_resource_t, *surf_cpu_resource_t;
102 extern surf_cpu_resource_t surf_cpu_resource;
103 void surf_cpu_resource_init(const char *filename);
105 /* Network resource */
106 typedef struct surf_network_resource_extension_private
107 *surf_network_resource_extension_private_t;
108 typedef struct surf_network_resource_extension_public {
109 surf_action_t(*communicate) (void *src, void *dst,
110 xbt_maxmin_float_t size);
111 } s_surf_network_resource_extension_public_t,
112 *surf_network_resource_extension_public_t;
114 typedef struct surf_network_resource {
115 surf_resource_private_t common_private;
116 surf_resource_public_t common_public;
117 surf_network_resource_extension_public_t extension_public;
118 } s_surf_network_resource_t, *surf_network_resource_t;
120 extern surf_network_resource_t surf_network_resource;
121 void surf_network_resource_init(const char *filename);
123 /* Workstation resource */
124 typedef struct surf_workstation_resource_extension_private
125 *surf_workstation_resource_extension_private_t;
126 typedef struct surf_workstation_resource_extension_public {
127 surf_action_t(*execute) (void *workstation, xbt_maxmin_float_t size);
128 surf_action_t(*wait) (void *workstation, xbt_maxmin_float_t size);
129 e_surf_cpu_state_t(*get_state) (void *workstation);
130 surf_action_t(*communicate) (void *workstation_src,
131 void *workstation_dst,
132 xbt_maxmin_float_t size);
133 } s_surf_workstation_resource_extension_public_t,
134 *surf_workstation_resource_extension_public_t;
136 typedef struct surf_workstation_resource {
137 surf_resource_private_t common_private;
138 surf_resource_public_t common_public;
139 surf_workstation_resource_extension_public_t extension_public;
140 } s_surf_workstation_resource_t, *surf_workstation_resource_t;
142 extern surf_workstation_resource_t surf_workstation_resource;
143 void surf_workstation_resource_init(const char *filename);
145 /*******************************************/
146 /*** SURF Globals **************************/
147 /*******************************************/
149 void surf_init(int *argc, char **argv); /* initialize common structures */
150 xbt_heap_float_t surf_solve(void); /* update all states and returns
151 the time elapsed since last
153 xbt_heap_float_t surf_get_clock(void);
154 void surf_finalize(void); /* clean everything */
156 #endif /* _SURF_SURF_H */