Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
c998d3e2b8fd9b86082ff2dd39af93a66afb3bf0
[simgrid.git] / src / include / surf / surf.h
1 /* Authors: Arnaud Legrand                                                  */
2
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. */
5
6
7 #ifndef _SURF_SURF_H
8 #define _SURF_SURF_H
9
10 #include "xbt/swag.h"
11 #include "xbt/heap.h" /* for xbt_heap_float_t only */
12 #include "surf/maxmin.h" /* for xbt_maxmin_float_t only  */
13
14 /* Actions and resources are higly connected structures... */
15 typedef struct surf_action *surf_action_t;
16 typedef struct surf_resource *surf_resource_t;
17
18 /*****************/
19 /* Action object */
20 /*****************/
21 typedef enum {
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;
28
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;
33   xbt_swag_t state_set;
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;
42 } s_surf_action_t;
43
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
51   surf_action_t (*action_new)(void *callback);
52   e_surf_action_state_t (*action_get_state)(surf_action_t action);
53   void (*action_free)(surf_action_t * action);  /* Call it when you're done with this action */
54   void (*action_cancel)(surf_action_t action); /* remove the variables from the linear system if needed */
55   void (*action_recycle)(surf_action_t action); /* More efficient than free/new */
56   void (*action_change_state)(surf_action_t action, e_surf_action_state_t state);
57
58   xbt_heap_float_t (*share_resources)(void); /* Share the resources to the 
59                                                 actions and return the potential 
60                                                 next action termination */
61   void (*solve)(xbt_heap_float_t date); /* Advance time to "date" and update
62                                            the actions' state*/
63 } s_surf_resource_t;
64
65 /**************************************/
66 /* Implementations of resource object */
67 /**************************************/
68 /* Host resource */
69 typedef enum {
70   SURF_HOST_ON = 1,             /* Ready        */
71   SURF_HOST_OFF = 0,            /* Running      */
72 } e_surf_host_state_t;
73
74 typedef struct surf_host_resource {
75   s_surf_resource_t resource;
76   void (*execute)(void *host, xbt_maxmin_float_t size, surf_action_t action);
77   e_surf_host_state_t (*get_state)(void *host);
78 } s_surf_host_resource_t, *surf_host_resource_t;
79 extern surf_host_resource_t surf_host_resource;
80
81 /* Network resource */
82 typedef struct surf_network_resource {
83   s_surf_resource_t resource;
84   surf_action_t (*communicate)(void *src, void *dst, xbt_maxmin_float_t size,
85                                surf_action_t action);
86 } s_surf_network_resource_t, surf_network_resource_t;
87 extern surf_network_resource_t surf_network_resource;
88
89 /* Timer resource */
90 typedef struct surf_timer_resource {
91   s_surf_resource_t resource;
92   surf_action_t (*wait)(void *host, void *dst, xbt_maxmin_float_t size,
93                         surf_action_t surf);
94 } s_surf_timer_resource_t, surf_timer_resource_t;
95 extern surf_timer_resource_t surf_timer_resource;
96
97 /*******************************************/
98 /*** SURF Globals **************************/
99 /*******************************************/
100 typedef struct surf_global {
101   xbt_swag_t ready_action_set;
102   xbt_swag_t running_action_set;
103   xbt_swag_t failed_action_set;
104   xbt_swag_t done_action_set;
105 } s_surf_global_t;
106 /* The main function */
107 extern s_surf_global_t surf_global;
108
109 void surf_init(void); /* initialize all resource objects */
110 xbt_heap_float_t surf_solve(void); /* returns the next date */
111
112 #endif                          /* _SURF_SURF_H */