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"
14 /* Actions and resources are higly connected structures... */
15 typedef struct surf_action *surf_action_t;
16 typedef struct surf_resource *surf_resource_t;
22 SURF_ACTION_READY = 0, /* Ready */
23 SURF_ACTION_RUNNING, /* Running */
24 SURF_ACTION_FAILED, /* Task Failure */
25 SURF_ACTION_DONE, /* Completed */
26 SURF_ACTION_NOT_IN_THE_SYSTEM /* Not in the system anymore. Why did you ask ? */
27 } e_surf_action_state_t;
29 typedef struct surf_action_state {
30 xbt_swag_t ready_action_set;
31 xbt_swag_t running_action_set;
32 xbt_swag_t failed_action_set;
33 xbt_swag_t done_action_set;
34 } s_surf_action_state_t, *surf_action_state_t;
36 /* Never create s_surf_action_t by yourself !!!! */
37 /* Use action_new from the corresponding resource */
38 typedef struct surf_action {
39 s_xbt_swag_hookup_t state_hookup;
41 xbt_maxmin_float_t cost; /* cost */
42 xbt_maxmin_float_t max_duration; /* max_duration (may fluctuate until
43 the task is completed) */
44 xbt_maxmin_float_t remains; /* How much of that cost remains to
45 * be done in the currently running task */
46 xbt_heap_float_t start; /* start time */
47 xbt_heap_float_t finish; /* finish time : this is modified during the run
48 * and fluctuates until the task is completed */
49 void *callback; /* for your convenience */
50 surf_resource_t resource_type;
53 /***************************/
54 /* Generic resource object */
55 /***************************/
57 typedef struct surf_resource_private *surf_resource_private_t;
58 typedef struct surf_resource_public {
59 s_surf_action_state_t states; /* Any living action on this resource */
60 void *(*name_service) (const char *name);
61 const char *(*get_resource_name) (void *resource_id);
63 e_surf_action_state_t(*action_get_state) (surf_action_t action);
64 void (*action_free) (surf_action_t action);
65 void (*action_cancel) (surf_action_t action);
66 void (*action_recycle) (surf_action_t action);
67 void (*action_change_state) (surf_action_t action,
68 e_surf_action_state_t state);
70 } s_surf_resource_public_t, *surf_resource_public_t;
72 typedef struct surf_resource {
73 surf_resource_private_t common_private;
74 surf_resource_public_t common_public;
77 typedef struct surf_resource_object {
78 surf_resource_t resource;
79 } s_surf_resource_object_t, *surf_resource_object_t;
81 /**************************************/
82 /* Implementations of resource object */
83 /**************************************/
86 SURF_CPU_ON = 1, /* Ready */
87 SURF_CPU_OFF = 0 /* Running */
90 typedef struct surf_cpu_resource_extension_private
91 *surf_cpu_resource_extension_private_t;
92 typedef struct surf_cpu_resource_extension_public {
93 surf_action_t(*execute) (void *cpu, xbt_maxmin_float_t size);
94 surf_action_t(*sleep) (void *cpu, xbt_maxmin_float_t duration);
95 void (*suspend) (surf_action_t action);
96 void (*resume) (surf_action_t action);
97 e_surf_cpu_state_t(*get_state) (void *cpu);
98 } s_surf_cpu_resource_extension_public_t,
99 *surf_cpu_resource_extension_public_t;
101 typedef struct surf_cpu_resource {
102 surf_resource_private_t common_private;
103 surf_resource_public_t common_public;
104 surf_cpu_resource_extension_public_t extension_public;
105 } s_surf_cpu_resource_t, *surf_cpu_resource_t;
106 extern surf_cpu_resource_t surf_cpu_resource;
107 void surf_cpu_resource_init(const char *filename);
109 /* Network resource */
110 typedef struct surf_network_resource_extension_private
111 *surf_network_resource_extension_private_t;
112 typedef struct surf_network_resource_extension_public {
113 surf_action_t(*communicate) (void *src, void *dst,
114 xbt_maxmin_float_t size);
115 } s_surf_network_resource_extension_public_t,
116 *surf_network_resource_extension_public_t;
118 typedef struct surf_network_resource {
119 surf_resource_private_t common_private;
120 surf_resource_public_t common_public;
121 surf_network_resource_extension_public_t extension_public;
122 } s_surf_network_resource_t, *surf_network_resource_t;
124 extern surf_network_resource_t surf_network_resource;
125 void surf_network_resource_init(const char *filename);
127 /* Workstation resource */
128 typedef struct surf_workstation_resource_extension_private
129 *surf_workstation_resource_extension_private_t;
130 typedef struct surf_workstation_resource_extension_public {
131 surf_action_t(*execute) (void *workstation, xbt_maxmin_float_t size);
132 surf_action_t(*sleep) (void *workstation, xbt_maxmin_float_t duration);
133 void (*suspend) (surf_action_t action);
134 void (*resume) (surf_action_t action);
135 e_surf_cpu_state_t(*get_state) (void *workstation);
136 surf_action_t(*communicate) (void *workstation_src,
137 void *workstation_dst,
138 xbt_maxmin_float_t size);
139 } s_surf_workstation_resource_extension_public_t,
140 *surf_workstation_resource_extension_public_t;
142 typedef struct surf_workstation_resource {
143 surf_resource_private_t common_private;
144 surf_resource_public_t common_public;
145 surf_workstation_resource_extension_public_t extension_public;
146 } s_surf_workstation_resource_t, *surf_workstation_resource_t;
148 extern surf_workstation_resource_t surf_workstation_resource;
149 void surf_workstation_resource_init(const char *filename);
151 /*******************************************/
152 /*** SURF Globals **************************/
153 /*******************************************/
155 void surf_init(int *argc, char **argv); /* initialize common structures */
157 extern xbt_dynar_t resource_list; /* list of initialized resources */
159 xbt_heap_float_t surf_solve(void); /* update all states and returns
160 the time elapsed since last
162 xbt_heap_float_t surf_get_clock(void);
163 void surf_finalize(void); /* clean everything */
165 #endif /* _SURF_SURF_H */