Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Keep extending the DTD to handle an computation/communication interference model
[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,
71                            void *data);
72   const char *name;
73 } s_surf_resource_public_t, *surf_resource_public_t;
74
75 typedef struct surf_resource {
76   surf_resource_private_t common_private;
77   surf_resource_public_t common_public;
78 } s_surf_resource_t;
79
80 typedef struct surf_resource_object {
81   surf_resource_t resource;
82 } s_surf_resource_object_t, *surf_resource_object_t;
83
84 /**************************************/
85 /* Implementations of resource object */
86 /**************************************/
87 /* Cpu resource */
88 typedef enum {
89   SURF_CPU_ON = 1,              /* Ready        */
90   SURF_CPU_OFF = 0              /* Running      */
91 } e_surf_cpu_state_t;
92
93 typedef struct surf_cpu_resource_extension_private
94 *surf_cpu_resource_extension_private_t;
95 typedef struct surf_cpu_resource_extension_public {
96   surf_action_t(*execute) (void *cpu, double size);
97   surf_action_t(*sleep) (void *cpu, double duration);
98   void (*suspend) (surf_action_t action);
99   void (*resume) (surf_action_t action);
100   int (*is_suspended) (surf_action_t action);
101    e_surf_cpu_state_t(*get_state) (void *cpu);
102 } s_surf_cpu_resource_extension_public_t,
103     *surf_cpu_resource_extension_public_t;
104
105 typedef struct surf_cpu_resource {
106   surf_resource_private_t common_private;
107   surf_resource_public_t common_public;
108   surf_cpu_resource_extension_public_t extension_public;
109 } s_surf_cpu_resource_t, *surf_cpu_resource_t;
110 extern surf_cpu_resource_t surf_cpu_resource;
111 void surf_cpu_resource_init_Cas01(const char *filename);
112
113 /* Network resource */
114 typedef struct surf_network_resource_extension_private
115 *surf_network_resource_extension_private_t;
116 typedef struct surf_network_resource_extension_public {
117   surf_action_t(*communicate) (void *src, void *dst, double size);
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   void (*suspend) (surf_action_t action);
137   void (*resume) (surf_action_t action);
138   int (*is_suspended) (surf_action_t action);
139    e_surf_cpu_state_t(*get_state) (void *workstation);
140    surf_action_t(*communicate) (void *workstation_src,
141                                 void *workstation_dst, double size);
142 } s_surf_workstation_resource_extension_public_t,
143     *surf_workstation_resource_extension_public_t;
144
145 typedef struct surf_workstation_resource {
146   surf_resource_private_t common_private;
147   surf_resource_public_t common_public;
148   surf_workstation_resource_extension_public_t extension_public;
149 } s_surf_workstation_resource_t, *surf_workstation_resource_t;
150
151 extern surf_workstation_resource_t surf_workstation_resource;
152 void surf_workstation_resource_init_CLM03(const char *filename);
153 void surf_workstation_resource_init_resource_init_KCCFLN05(const char *filename);
154 extern xbt_dict_t workstation_set;
155
156 /*******************************************/
157 /*** SURF Globals **************************/
158 /*******************************************/
159
160 void surf_init(int *argc, char **argv); /* initialize common structures */
161
162 extern xbt_dynar_t resource_list;       /* list of initialized resources */
163
164 double surf_solve(void);        /*  update all states and returns
165                                    the time elapsed since last
166                                    event */
167 double surf_get_clock(void);
168 void surf_finalize(void);       /* clean everything */
169
170 #endif                          /* _SURF_SURF_H */