Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
debug debug debug
[simgrid.git] / src / include / surf / surf.h
1 /*      $Id$     */
2
3 /* Copyright (c) 2004 Arnaud Legrand. All rights reserved.                  */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 #ifndef _SURF_SURF_H
9 #define _SURF_SURF_H
10
11 #include "xbt/swag.h"
12 #include "xbt/dynar.h"
13 #include "xbt/dict.h"
14
15 /* Actions and resources are higly connected structures... */
16 typedef struct surf_action *surf_action_t;
17 typedef struct surf_resource *surf_resource_t;
18
19 /*****************/
20 /* Action object */
21 /*****************/
22 typedef enum {
23   SURF_ACTION_READY = 0,        /* Ready        */
24   SURF_ACTION_RUNNING,          /* Running      */
25   SURF_ACTION_FAILED,           /* Task Failure */
26   SURF_ACTION_DONE,             /* Completed    */
27   SURF_ACTION_NOT_IN_THE_SYSTEM /* Not in the system anymore. Why did you ask ? */
28 } e_surf_action_state_t;
29
30 typedef struct surf_action_state {
31   xbt_swag_t ready_action_set;
32   xbt_swag_t running_action_set;
33   xbt_swag_t failed_action_set;
34   xbt_swag_t done_action_set;
35 } s_surf_action_state_t, *surf_action_state_t;
36
37 /* Never create s_surf_action_t by yourself !!!! */
38 /* Use action_new from the corresponding resource */
39 typedef struct surf_action {
40   s_xbt_swag_hookup_t state_hookup;
41   xbt_swag_t state_set;
42   double cost;                  /* cost        */
43   double max_duration;          /* max_duration (may fluctuate until
44                                    the task is completed) */
45   double remains;               /* How much of that cost remains to
46                                  * be done in the currently running task */
47   double start;                 /* start time  */
48   double finish;                /* finish time : this is modified during the run
49                                  * and fluctuates until the task is completed */
50   void *callback;               /* for your convenience */
51   surf_resource_t resource_type;
52 } s_surf_action_t;
53
54 /***************************/
55 /* Generic resource object */
56 /***************************/
57
58 typedef struct surf_resource_private *surf_resource_private_t;
59 typedef struct surf_resource_public {
60   s_surf_action_state_t states; /* Any living action on this resource */
61   void *(*name_service) (const char *name);
62   const char *(*get_resource_name) (void *resource_id);
63
64    e_surf_action_state_t(*action_get_state) (surf_action_t action);
65   void (*action_free) (surf_action_t action);
66   void (*action_cancel) (surf_action_t action);
67   void (*action_recycle) (surf_action_t action);
68   void (*action_change_state) (surf_action_t action,
69                                e_surf_action_state_t state);
70   const char *name;
71 } s_surf_resource_public_t, *surf_resource_public_t;
72
73 typedef struct surf_resource {
74   surf_resource_private_t common_private;
75   surf_resource_public_t common_public;
76 } s_surf_resource_t;
77
78 typedef struct surf_resource_object {
79   surf_resource_t resource;
80 } s_surf_resource_object_t, *surf_resource_object_t;
81
82 /**************************************/
83 /* Implementations of resource object */
84 /**************************************/
85 /* Cpu resource */
86 typedef enum {
87   SURF_CPU_ON = 1,              /* Ready        */
88   SURF_CPU_OFF = 0              /* Running      */
89 } e_surf_cpu_state_t;
90
91 typedef struct surf_cpu_resource_extension_private
92 *surf_cpu_resource_extension_private_t;
93 typedef struct surf_cpu_resource_extension_public {
94   surf_action_t(*execute) (void *cpu, double size);
95   surf_action_t(*sleep) (void *cpu, double duration);
96   void (*suspend) (surf_action_t action);
97   void (*resume) (surf_action_t action);
98   int (*is_suspended) (surf_action_t action);
99    e_surf_cpu_state_t(*get_state) (void *cpu);
100 } s_surf_cpu_resource_extension_public_t,
101     *surf_cpu_resource_extension_public_t;
102
103 typedef struct surf_cpu_resource {
104   surf_resource_private_t common_private;
105   surf_resource_public_t common_public;
106   surf_cpu_resource_extension_public_t extension_public;
107 } s_surf_cpu_resource_t, *surf_cpu_resource_t;
108 extern surf_cpu_resource_t surf_cpu_resource;
109 void surf_cpu_resource_init(const char *filename);
110
111 /* Network resource */
112 typedef struct surf_network_resource_extension_private
113 *surf_network_resource_extension_private_t;
114 typedef struct surf_network_resource_extension_public {
115   surf_action_t(*communicate) (void *src, void *dst, double size);
116 } s_surf_network_resource_extension_public_t,
117     *surf_network_resource_extension_public_t;
118
119 typedef struct surf_network_resource {
120   surf_resource_private_t common_private;
121   surf_resource_public_t common_public;
122   surf_network_resource_extension_public_t extension_public;
123 } s_surf_network_resource_t, *surf_network_resource_t;
124
125 extern surf_network_resource_t surf_network_resource;
126 void surf_network_resource_init(const char *filename);
127
128 /* Workstation resource */
129 typedef struct surf_workstation_resource_extension_private
130 *surf_workstation_resource_extension_private_t;
131 typedef struct surf_workstation_resource_extension_public {
132   surf_action_t(*execute) (void *workstation, double size);
133   surf_action_t(*sleep) (void *workstation, double duration);
134   void (*suspend) (surf_action_t action);
135   void (*resume) (surf_action_t action);
136   int (*is_suspended) (surf_action_t action);
137    e_surf_cpu_state_t(*get_state) (void *workstation);
138    surf_action_t(*communicate) (void *workstation_src,
139                                 void *workstation_dst, double size);
140 } s_surf_workstation_resource_extension_public_t,
141     *surf_workstation_resource_extension_public_t;
142
143 typedef struct surf_workstation_resource {
144   surf_resource_private_t common_private;
145   surf_resource_public_t common_public;
146   surf_workstation_resource_extension_public_t extension_public;
147 } s_surf_workstation_resource_t, *surf_workstation_resource_t;
148
149 extern surf_workstation_resource_t surf_workstation_resource;
150 void surf_workstation_resource_init(const char *filename);
151 extern xbt_dict_t workstation_set;
152
153 /*******************************************/
154 /*** SURF Globals **************************/
155 /*******************************************/
156
157 void surf_init(int *argc, char **argv); /* initialize common structures */
158
159 extern xbt_dynar_t resource_list;       /* list of initialized resources */
160
161 double surf_solve(void);        /*  update all states and returns
162                                    the time elapsed since last
163                                    event */
164 double surf_get_clock(void);
165 void surf_finalize(void);       /* clean everything */
166
167 #endif                          /* _SURF_SURF_H */