Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Typos : a lot of mecanism -> mechanism and functional -> functionnal
[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 *data;                   /* 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   void (*action_set_data) (surf_action_t action, void *data);
71   void (*suspend) (surf_action_t action);
72   void (*resume) (surf_action_t action);
73   int (*is_suspended) (surf_action_t action);
74   const char *name;
75 } s_surf_resource_public_t, *surf_resource_public_t;
76
77 typedef struct surf_resource {
78   surf_resource_private_t common_private;
79   surf_resource_public_t common_public;
80 } s_surf_resource_t;
81
82 typedef struct surf_resource_object {
83   surf_resource_t resource;
84 } s_surf_resource_object_t, *surf_resource_object_t;
85
86 /**************************************/
87 /* Implementations of resource object */
88 /**************************************/
89 /* Cpu resource */
90 typedef enum {
91   SURF_CPU_ON = 1,              /* Ready        */
92   SURF_CPU_OFF = 0              /* Running      */
93 } e_surf_cpu_state_t;
94
95 typedef struct surf_cpu_resource_extension_private
96 *surf_cpu_resource_extension_private_t;
97 typedef struct surf_cpu_resource_extension_public {
98   surf_action_t(*execute) (void *cpu, double size);
99   surf_action_t(*sleep) (void *cpu, double duration);
100   e_surf_cpu_state_t(*get_state) (void *cpu);
101 } s_surf_cpu_resource_extension_public_t,
102     *surf_cpu_resource_extension_public_t;
103
104 typedef struct surf_cpu_resource {
105   surf_resource_private_t common_private;
106   surf_resource_public_t common_public;
107   surf_cpu_resource_extension_public_t extension_public;
108 } s_surf_cpu_resource_t, *surf_cpu_resource_t;
109 extern surf_cpu_resource_t surf_cpu_resource;
110 void surf_cpu_resource_init_Cas01(const char *filename);
111
112 /* Network resource */
113 typedef struct surf_network_resource_extension_private
114 *surf_network_resource_extension_private_t;
115 typedef struct surf_network_resource_extension_public {
116   surf_action_t(*communicate) (void *src, void *dst, double size,
117                                double max_rate);
118 } s_surf_network_resource_extension_public_t,
119     *surf_network_resource_extension_public_t;
120
121 typedef struct surf_network_resource {
122   surf_resource_private_t common_private;
123   surf_resource_public_t common_public;
124   surf_network_resource_extension_public_t extension_public;
125 } s_surf_network_resource_t, *surf_network_resource_t;
126
127 extern surf_network_resource_t surf_network_resource;
128 void surf_network_resource_init_CM02(const char *filename);
129
130 /* Workstation resource */
131 typedef struct surf_workstation_resource_extension_private
132 *surf_workstation_resource_extension_private_t;
133 typedef struct surf_workstation_resource_extension_public {
134   surf_action_t(*execute) (void *workstation, double size);
135   surf_action_t(*sleep) (void *workstation, double duration);
136   e_surf_cpu_state_t(*get_state) (void *workstation);
137   surf_action_t(*communicate) (void *workstation_src,
138                                void *workstation_dst, double size,
139                                double max_rate);
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_CLM03(const char *filename);
151 void surf_workstation_resource_init_KCCFLN05(const char *filename);
152 extern xbt_dict_t workstation_set;
153
154 /*******************************************/
155 /*** SURF Globals **************************/
156 /*******************************************/
157
158 void surf_init(int *argc, char **argv); /* initialize common structures */
159
160 extern xbt_dynar_t resource_list;       /* list of initialized resources */
161
162 double surf_solve(void);        /*  update all states and returns
163                                    the time elapsed since last
164                                    event */
165 double surf_get_clock(void);
166 void surf_finalize(void);       /* clean everything */
167
168 #endif                          /* _SURF_SURF_H */