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);
61 e_surf_action_state_t (*action_get_state)(surf_action_t action);
62 void (*action_free)(surf_action_t action);
63 void (*action_cancel)(surf_action_t action);
64 void (*action_recycle)(surf_action_t action);
65 void (*action_change_state)(surf_action_t action,
66 e_surf_action_state_t state);
67 } s_surf_resource_public_t, *surf_resource_public_t;
69 typedef struct surf_resource {
70 surf_resource_private_t common_private;
71 surf_resource_public_t common_public;
74 typedef struct surf_resource_object {
75 surf_resource_t resource;
76 } s_surf_resource_object_t, *surf_resource_object_t;
78 /**************************************/
79 /* Implementations of resource object */
80 /**************************************/
83 SURF_CPU_ON = 1, /* Ready */
84 SURF_CPU_OFF = 0 /* Running */
87 typedef struct surf_cpu_resource_extension_private *surf_cpu_resource_extension_private_t;
88 typedef struct surf_cpu_resource_extension_public {
89 surf_action_t(*execute) (void *cpu, xbt_maxmin_float_t size);
90 surf_action_t(*wait) (void *cpu, xbt_maxmin_float_t size);
91 e_surf_cpu_state_t(*get_state) (void *cpu);
92 } s_surf_cpu_resource_extension_public_t, *surf_cpu_resource_extension_public_t;
94 typedef struct surf_cpu_resource {
95 surf_resource_private_t common_private;
96 surf_resource_public_t common_public;
97 /* surf_cpu_resource_extension_private_t extension_private; */
98 surf_cpu_resource_extension_public_t extension_public;
99 } s_surf_cpu_resource_t, *surf_cpu_resource_t;
100 extern surf_cpu_resource_t surf_cpu_resource;
101 void surf_cpu_resource_init(const char *filename);
103 /* Network resource */
104 typedef struct surf_network_resource_extension_private *surf_network_resource_extension_private_t;
105 typedef struct surf_network_resource_extension_public {
106 surf_action_t(*communicate) (void *src, void *dst,
107 xbt_maxmin_float_t size);
108 } s_surf_network_resource_extension_public_t, *surf_network_resource_extension_public_t;
110 typedef struct surf_network_resource {
111 surf_resource_private_t common_private;
112 surf_resource_public_t common_public;
113 /* surf_network_resource_extension_private_t extension_private; */
114 surf_network_resource_extension_public_t extension_public;
115 } s_surf_network_resource_t, *surf_network_resource_t;
117 extern surf_network_resource_t surf_network_resource;
118 void surf_network_resource_init(const char *filename);
120 /*******************************************/
121 /*** SURF Globals **************************/
122 /*******************************************/
124 void surf_init(void); /* initialize common structures */
125 xbt_heap_float_t surf_solve(void); /* update all states and returns
126 the time elapsed since last
128 xbt_heap_float_t surf_get_clock(void);
129 void surf_finalize(void); /* clean everything */
131 #endif /* _SURF_SURF_H */