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 {
56 s_surf_action_state_t states; /* Any living action on this resource */
58 /* Moved to the initialization function */
59 /* void (*parse_file)(const char *filename); */
61 void *(*name_service)(const char *name);
62 const char *(*get_resource_name)(void *resource_id);
63 int (*resource_used)(void *resource_id);
65 /* surf_action_t (*action_new)(void *callback); */
66 /* Not defined here. Actions have to be created by actually
67 performing it and prototype may therefore vary with the resource
70 e_surf_action_state_t (*action_get_state)(surf_action_t action);
71 void (*action_free)(surf_action_t * action); /* Call it when you're done with this action */
72 void (*action_cancel)(surf_action_t action); /* remove the variables from the linear system if needed */
73 void (*action_recycle)(surf_action_t action); /* More efficient than free/new */
74 void (*action_change_state)(surf_action_t action, e_surf_action_state_t state);
76 xbt_heap_float_t (*share_resources)(xbt_heap_float_t now); /* Share the resources to the
77 actions and return in hom much time
78 the next action may terminate */
79 void (*update_state)(xbt_heap_float_t now,
80 xbt_heap_float_t delta); /* Update the actions' state*/
84 /**************************************/
85 /* Implementations of resource object */
86 /**************************************/
89 SURF_CPU_ON = 1, /* Ready */
90 SURF_CPU_OFF = 0, /* Running */
93 typedef struct surf_cpu_resource {
94 s_surf_resource_t resource;
95 surf_action_t (*execute)(void *cpu, xbt_maxmin_float_t size);
96 e_surf_cpu_state_t (*get_state)(void *cpu);
97 } s_surf_cpu_resource_t, *surf_cpu_resource_t;
98 extern surf_cpu_resource_t surf_cpu_resource;
99 void surf_cpu_resource_init(const char* filename);
101 /* Network resource */
102 typedef struct surf_network_resource {
103 s_surf_resource_t resource;
104 surf_action_t (*communicate)(void *src, void *dst, xbt_maxmin_float_t size);
105 } s_surf_network_resource_t, surf_network_resource_t;
106 extern surf_network_resource_t surf_network_resource;
107 void surf_network_resource_init(const char* filename);
110 typedef struct surf_timer_resource {
111 s_surf_resource_t resource;
112 surf_action_t (*wait)(void *cpu, void *dst, xbt_maxmin_float_t size);
113 } s_surf_timer_resource_t, surf_timer_resource_t;
114 extern surf_timer_resource_t surf_timer_resource;
115 void surf_timer_resource_init(const char* filename);
117 /*******************************************/
118 /*** SURF Globals **************************/
119 /*******************************************/
121 void surf_init(void); /* initialize common structures */
122 xbt_heap_float_t surf_solve(void); /* update all states and returns
123 the time elapsed since last
125 xbt_heap_float_t surf_get_clock(void);
127 #endif /* _SURF_SURF_H */