1 /* Authors: Arnaud Legrand */
3 /* This program is free software; you can redistribute it and/or modify it
4 under the terms of the license (GNU LGPL) which comes with this package. */
11 #include "xbt/heap.h" /* for xbt_heap_float_t only */
12 #include "surf/maxmin.h" /* for xbt_maxmin_float_t only */
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 remains; /* How much of that cost remains to
43 * be done in the currently running task */
44 xbt_heap_float_t start; /* start time */
45 xbt_heap_float_t finish; /* finish time : this is modified during the run
46 * and fluctuates until the task is completed */
47 void *callback; /* for your convenience */
48 surf_resource_t resource_type;
51 /***************************/
52 /* Generic resource object */
53 /***************************/
55 typedef struct surf_resource_private *surf_resource_private_t;
56 typedef struct surf_resource_public {
57 s_surf_action_state_t states; /* Any living action on this resource */
58 void *(*name_service)(const char *name);
59 const char *(*get_resource_name)(void *resource_id);
60 int (*resource_used)(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 *surf_cpu_resource_extension_private_t;
89 typedef struct surf_cpu_resource_extension_public {
90 surf_action_t(*execute) (void *cpu, xbt_maxmin_float_t size);
91 surf_action_t(*wait) (void *cpu, xbt_maxmin_float_t size);
92 e_surf_cpu_state_t(*get_state) (void *cpu);
93 } s_surf_cpu_resource_extension_public_t, *surf_cpu_resource_extension_public_t;
95 typedef struct surf_cpu_resource {
96 surf_resource_private_t common_private;
97 surf_resource_public_t common_public;
98 /* surf_cpu_resource_extension_private_t extension_private; */
99 surf_cpu_resource_extension_public_t extension_public;
100 } s_surf_cpu_resource_t, *surf_cpu_resource_t;
101 extern surf_cpu_resource_t surf_cpu_resource;
102 void surf_cpu_resource_init(const char *filename);
104 /* Network resource */
105 typedef struct surf_network_resource_extension_private *surf_network_resource_extension_private_t;
106 typedef struct surf_network_resource_extension_public {
107 surf_action_t(*communicate) (void *src, void *dst,
108 xbt_maxmin_float_t size);
109 } s_surf_network_resource_extension_public_t, *surf_network_resource_extension_public_t;
111 typedef struct surf_network_resource {
112 surf_resource_private_t common_private;
113 surf_resource_public_t common_public;
114 /* surf_network_resource_extension_private_t extension_private; */
115 surf_network_resource_extension_public_t extension_public;
116 } s_surf_network_resource_t, *surf_network_resource_t;
118 extern surf_network_resource_t surf_network_resource;
119 void surf_network_resource_init(const char *filename);
121 /*******************************************/
122 /*** SURF Globals **************************/
123 /*******************************************/
125 void surf_init(void); /* initialize common structures */
126 xbt_heap_float_t surf_solve(void); /* update all states and returns
127 the time elapsed since last
129 xbt_heap_float_t surf_get_clock(void);
130 void surf_finalize(void); /* clean everything */
132 #endif /* _SURF_SURF_H */