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 /* Never create s_surf_action_t by yourself !!!! */
30 /* Use action_new from the corresponding resource */
31 typedef struct surf_action {
32 s_xbt_swag_hookup_t state_hookup;
34 xbt_maxmin_float_t cost; /* cost */
35 xbt_maxmin_float_t remains; /* How much of that cost remains to
36 * be done in the currently running task */
37 xbt_heap_float_t start; /* start time */
38 xbt_heap_float_t finish; /* finish time : this is modified during the run
39 * and fluctuates until the task is completed */
40 void *callback; /* for your convenience */
41 surf_resource_t resource_type;
44 /***************************/
45 /* Generic resource object */
46 /***************************/
47 typedef struct surf_resource {
48 void (*parse_file)(const char *file);
49 void *(*name_service)(const char *name);
50 const char *(*get_resource_name)(void *resource_id);
52 /* surf_action_t (*action_new)(void *callback); */
53 /* Not defined here. Actions have to be created by actually
54 performing it and prototype may therefore vary with the resource
57 e_surf_action_state_t (*action_get_state)(surf_action_t action);
58 void (*action_free)(surf_action_t * action); /* Call it when you're done with this action */
59 void (*action_cancel)(surf_action_t action); /* remove the variables from the linear system if needed */
60 void (*action_recycle)(surf_action_t action); /* More efficient than free/new */
61 void (*action_change_state)(surf_action_t action, e_surf_action_state_t state);
63 xbt_heap_float_t (*share_resources)(void); /* Share the resources to the
64 actions and return the potential
65 next action termination */
66 void (*solve)(xbt_heap_float_t date); /* Advance time to "date" and update
70 /**************************************/
71 /* Implementations of resource object */
72 /**************************************/
75 SURF_CPU_ON = 1, /* Ready */
76 SURF_CPU_OFF = 0, /* Running */
79 typedef struct surf_cpu_resource {
80 s_surf_resource_t resource;
81 surf_action_t (*execute)(void *cpu, xbt_maxmin_float_t size);
82 e_surf_cpu_state_t (*get_state)(void *cpu);
83 } s_surf_cpu_resource_t, *surf_cpu_resource_t;
84 extern surf_cpu_resource_t surf_cpu_resource;
86 /* Network resource */
87 typedef struct surf_network_resource {
88 s_surf_resource_t resource;
89 surf_action_t (*communicate)(void *src, void *dst, xbt_maxmin_float_t size);
90 } s_surf_network_resource_t, surf_network_resource_t;
91 extern surf_network_resource_t surf_network_resource;
94 typedef struct surf_timer_resource {
95 s_surf_resource_t resource;
96 surf_action_t (*wait)(void *cpu, void *dst, xbt_maxmin_float_t size);
97 } s_surf_timer_resource_t, surf_timer_resource_t;
98 extern surf_timer_resource_t surf_timer_resource;
100 /*******************************************/
101 /*** SURF Globals **************************/
102 /*******************************************/
103 typedef struct surf_global {
104 xbt_swag_t ready_action_set;
105 xbt_swag_t running_action_set;
106 xbt_swag_t failed_action_set;
107 xbt_swag_t done_action_set;
109 /* The main function */
110 extern s_surf_global_t surf_global;
112 void surf_init(void); /* initialize all resource objects */
113 xbt_heap_float_t surf_solve(void); /* returns the next date */
115 #endif /* _SURF_SURF_H */