Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
c3bc5c984f90d43fd4eb6d3afe18bd33431eac47
[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_TO_FREE,          /* Action to free in next cleanup */
28   SURF_ACTION_NOT_IN_THE_SYSTEM /* Not in the system anymore. Why did you ask ? */
29 } e_surf_action_state_t;
30
31 typedef struct surf_action_state {
32   xbt_swag_t ready_action_set;
33   xbt_swag_t running_action_set;
34   xbt_swag_t failed_action_set;
35   xbt_swag_t done_action_set;
36 } s_surf_action_state_t, *surf_action_state_t;
37
38 /* Never create s_surf_action_t by yourself !!!! */
39 /* Use action_new from the corresponding resource */
40 typedef struct surf_action {
41   s_xbt_swag_hookup_t state_hookup;
42   xbt_swag_t state_set;
43   double cost;                  /* cost        */
44   double max_duration;          /* max_duration (may fluctuate until
45                                    the task is completed) */
46   double remains;               /* How much of that cost remains to
47                                  * be done in the currently running task */
48   double start;                 /* start time  */
49   double finish;                /* finish time : this is modified during the run
50                                  * and fluctuates until the task is completed */
51   void *data;                   /* for your convenience */
52   int using;
53   surf_resource_t resource_type;
54 } s_surf_action_t;
55
56 /***************************/
57 /* Generic resource object */
58 /***************************/
59
60 typedef struct surf_resource_private *surf_resource_private_t;
61 typedef struct surf_resource_public {
62   s_surf_action_state_t states; /* Any living action on this resource */
63   void *(*name_service) (const char *name);
64   const char *(*get_resource_name) (void *resource_id);
65
66    e_surf_action_state_t(*action_get_state) (surf_action_t action);
67   void (*action_use) (surf_action_t action);
68   int  (*action_free) (surf_action_t action);
69   void (*action_cancel) (surf_action_t action);
70   void (*action_recycle) (surf_action_t action);
71   void (*action_change_state) (surf_action_t action,
72                                e_surf_action_state_t state);
73   void (*action_set_data) (surf_action_t action, void *data);
74   void (*suspend) (surf_action_t action);
75   void (*resume) (surf_action_t action);
76   int (*is_suspended) (surf_action_t action);
77   const char *name;
78 } s_surf_resource_public_t, *surf_resource_public_t;
79
80 typedef struct surf_resource {
81   surf_resource_private_t common_private;
82   surf_resource_public_t common_public;
83 } s_surf_resource_t;
84
85 /**************************************/
86 /* Implementations of resource object */
87 /**************************************/
88 /* Timer resource */
89 typedef struct surf_timer_resource_extension_private
90 *surf_timer_resource_extension_private_t;
91 typedef struct surf_timer_resource_extension_public {
92   void (*set) (double date, void *function, void *arg);
93   int (*get)  (void **function, void **arg);
94 } s_surf_timer_resource_extension_public_t,
95   *surf_timer_resource_extension_public_t;
96
97 typedef struct surf_timer_resource {
98   surf_resource_private_t common_private;
99   surf_resource_public_t common_public;
100   surf_timer_resource_extension_public_t extension_public;
101 } s_surf_timer_resource_t, *surf_timer_resource_t;
102 extern surf_timer_resource_t surf_timer_resource;
103 void surf_timer_resource_init(const char *filename);
104
105 /* Cpu resource */
106 typedef enum {
107   SURF_CPU_ON = 1,              /* Ready        */
108   SURF_CPU_OFF = 0              /* Running      */
109 } e_surf_cpu_state_t;
110
111 typedef struct surf_cpu_resource_extension_private
112 *surf_cpu_resource_extension_private_t;
113 typedef struct surf_cpu_resource_extension_public {
114   surf_action_t(*execute) (void *cpu, double size);
115   surf_action_t(*sleep) (void *cpu, double duration);
116   e_surf_cpu_state_t(*get_state) (void *cpu);
117 } s_surf_cpu_resource_extension_public_t,
118     *surf_cpu_resource_extension_public_t;
119
120 typedef struct surf_cpu_resource {
121   surf_resource_private_t common_private;
122   surf_resource_public_t common_public;
123   surf_cpu_resource_extension_public_t extension_public;
124 } s_surf_cpu_resource_t, *surf_cpu_resource_t;
125 extern surf_cpu_resource_t surf_cpu_resource;
126 void surf_cpu_resource_init_Cas01(const char *filename);
127
128 /* Network resource */
129 typedef struct surf_network_resource_extension_private
130 *surf_network_resource_extension_private_t;
131 typedef struct surf_network_resource_extension_public {
132   surf_action_t(*communicate) (void *src, void *dst, double size,
133                                double max_rate);
134 } s_surf_network_resource_extension_public_t,
135     *surf_network_resource_extension_public_t;
136
137 typedef struct surf_network_resource {
138   surf_resource_private_t common_private;
139   surf_resource_public_t common_public;
140   surf_network_resource_extension_public_t extension_public;
141 } s_surf_network_resource_t, *surf_network_resource_t;
142
143 extern surf_network_resource_t surf_network_resource;
144 void surf_network_resource_init_CM02(const char *filename);
145
146 /* Workstation resource */
147 typedef struct surf_workstation_resource_extension_private
148 *surf_workstation_resource_extension_private_t;
149 typedef struct surf_workstation_resource_extension_public {
150   surf_action_t(*execute) (void *workstation, double size);
151   surf_action_t(*sleep) (void *workstation, double duration);
152   e_surf_cpu_state_t(*get_state) (void *workstation);
153   surf_action_t(*communicate) (void *workstation_src,
154                                void *workstation_dst, double size,
155                                double max_rate);
156 } s_surf_workstation_resource_extension_public_t,
157     *surf_workstation_resource_extension_public_t;
158
159 typedef struct surf_workstation_resource {
160   surf_resource_private_t common_private;
161   surf_resource_public_t common_public;
162   surf_workstation_resource_extension_public_t extension_public;
163 } s_surf_workstation_resource_t, *surf_workstation_resource_t;
164
165 extern surf_workstation_resource_t surf_workstation_resource;
166 void surf_workstation_resource_init_CLM03(const char *filename);
167 void surf_workstation_resource_init_KCCFLN05(const char *filename);
168 extern xbt_dict_t workstation_set;
169
170 /*******************************************/
171 /*** SURF Globals **************************/
172 /*******************************************/
173
174 void surf_init(int *argc, char **argv); /* initialize common structures */
175
176 extern xbt_dynar_t resource_list;       /* list of initialized resources */
177
178 double surf_solve(void);        /*  update all states and returns
179                                    the time elapsed since last
180                                    event */
181 double surf_get_clock(void);
182 void surf_finalize(void);       /* clean everything */
183
184 #endif                          /* _SURF_SURF_H */