Logo AND Algorithmique Numérique Distribuée

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