Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
e0bb1e0e1fb2156cd5c08d91c9e9b5290dc64e9b
[simgrid.git] / src / simdag / private.h
1 /* Copyright (c) 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #ifndef SIMDAG_PRIVATE_H
8 #define SIMDAG_PRIVATE_H
9
10 #include "xbt/dict.h"
11 #include "xbt/dynar.h"
12 #include "xbt/fifo.h"
13 #include "simdag/simdag.h"
14 #include "simdag/datatypes.h"
15 #include "surf/solver.h"
16 #include "surf/surf.h"
17 #include "xbt/swag.h"
18 #include "xbt/mallocator.h"
19 #include <stdbool.h>
20
21 /* Global variables */
22
23 typedef struct SD_global {
24   SD_workstation_t *workstation_list;   /* array of workstations, created only if
25                                            necessary in SD_workstation_get_list */
26   SD_link_t *link_list;         /* array of links, created only if
27                                    necessary in SD_link_get_list */
28   SD_link_t *recyclable_route;  /* array returned by SD_route_get_list
29                                    and mallocated only once */
30
31   xbt_mallocator_t task_mallocator; /* to not remalloc new tasks */
32
33   int watch_point_reached;      /* has a task just reached a watch point? */
34
35   /* task state sets */
36   xbt_swag_t not_scheduled_task_set;
37   xbt_swag_t schedulable_task_set;
38   xbt_swag_t scheduled_task_set;
39   xbt_swag_t runnable_task_set;
40   xbt_swag_t in_fifo_task_set;
41   xbt_swag_t running_task_set;
42   xbt_swag_t done_task_set;
43   xbt_swag_t failed_task_set;
44
45   xbt_swag_t return_set;
46   int task_number;
47
48 } s_SD_global_t, *SD_global_t;
49
50 extern SD_global_t sd_global;
51
52 /* Link */
53 typedef struct SD_link {
54   void *surf_link;              /* surf object */
55   void *data;                   /* user data */
56   e_SD_link_sharing_policy_t sharing_policy;
57 } s_SD_link_t;
58
59 /* Workstation */
60 typedef s_xbt_dictelm_t s_SD_workstation_t;
61 typedef struct SD_workstation {
62   void *data;                   /* user data */
63   e_SD_workstation_access_mode_t access_mode;
64
65   xbt_fifo_t task_fifo;         /* only used in sequential mode */
66   SD_task_t current_task;       /* only used in sequential mode */
67 } s_SD_workstation_priv_t, *SD_workstation_priv_t;
68
69 static inline SD_workstation_priv_t SD_workstation_priv(SD_workstation_t host){
70   return xbt_lib_get_level(host, SD_HOST_LEVEL);
71 }
72
73 /* Task */
74 typedef struct SD_task {
75   s_xbt_swag_hookup_t state_hookup;
76   s_xbt_swag_hookup_t return_hookup;
77   xbt_swag_t state_set;
78   e_SD_task_state_t state;
79   void *data;                   /* user data */
80   char *name;
81   int kind;
82   double amount;
83   double alpha;          /* used by typed parallel tasks */
84   double remains;
85   double start_time;
86   double finish_time;
87   surf_action_t surf_action;
88   unsigned short watch_points;  /* bit field xor()ed with masks */
89
90   int fifo_checked;             /* used by SD_task_just_done to make sure we evaluate
91                                    the task only once */
92   int marked;                   /* used to check if the task DAG has some cycle*/
93
94   /* dependencies */
95   xbt_dynar_t tasks_before;
96   xbt_dynar_t tasks_after;
97   int unsatisfied_dependencies;
98   unsigned int is_not_ready;
99
100   /* scheduling parameters (only exist in state SD_SCHEDULED) */
101   int workstation_nb;
102   SD_workstation_t *workstation_list;   /* surf workstations */
103   double *computation_amount;
104   double *communication_amount;
105   double rate;
106
107 #ifdef HAVE_TRACING
108   long long int counter;        /* task unique identifier for instrumentation */
109   char *category;               /* sd task category for instrumentation */
110 #endif
111 } s_SD_task_t;
112
113 /* Task dependencies */
114 typedef struct SD_dependency {
115   char *name;
116   void *data;
117   SD_task_t src;
118   SD_task_t dst;
119   /* src must be finished before dst can start */
120 } s_SD_dependency_t, *SD_dependency_t;
121
122 /* SimDag private functions */
123 XBT_PUBLIC(xbt_swag_t) SD_simulate_swag(double how_long); /* could be public, but you need to see the internals of the SD_task_t to use it */
124
125
126 SD_link_t __SD_link_create(void *surf_link, void *data);
127 #define __SD_link_destroy xbt_free_f
128
129 SD_workstation_t __SD_workstation_create(void *surf_workstation,
130                                          void *data);
131 void __SD_workstation_destroy(void *workstation);
132 int __SD_workstation_is_busy(SD_workstation_t workstation);
133
134 void __SD_task_set_state(SD_task_t task, e_SD_task_state_t new_state);
135 void __SD_task_really_run(SD_task_t task);
136 int __SD_task_try_to_run(SD_task_t task);
137 void __SD_task_just_done(SD_task_t task);
138 bool acyclic_graph_detail(xbt_dynar_t dag);
139
140 /* Task mallocator functions */
141 void* SD_task_new_f(void);
142 void SD_task_recycle_f(void *t);
143 void SD_task_free_f(void *t);
144
145 /* Functions to test if the task is in a given state. */
146
147 /* Returns whether the given task is scheduled or runnable. */
148 static XBT_INLINE int __SD_task_is_scheduled_or_runnable(SD_task_t task)
149 {
150   return task->state_set == sd_global->scheduled_task_set ||
151       task->state_set == sd_global->runnable_task_set;
152 }
153
154 /* Returns whether the given task is scheduled or runnable. */
155 static XBT_INLINE int __SD_task_is_schedulable_or_done(SD_task_t task)
156 {
157   return task->state_set == sd_global->schedulable_task_set ||
158       task->state_set == sd_global->done_task_set;
159 }
160
161 /* Returns whether the state of the given task is SD_NOT_SCHEDULED. */
162 static XBT_INLINE int __SD_task_is_not_scheduled(SD_task_t task)
163 {
164   return task->state_set == sd_global->not_scheduled_task_set;
165 }
166
167 /* Returns whether the state of the given task is SD_SCHEDULED. */
168 static XBT_INLINE int __SD_task_is_schedulable(SD_task_t task)
169 {
170   return task->state_set == sd_global->schedulable_task_set;
171 }
172
173 /* Returns whether the state of the given task is SD_SCHEDULED. */
174 static XBT_INLINE int __SD_task_is_scheduled(SD_task_t task)
175 {
176   return task->state_set == sd_global->scheduled_task_set;
177 }
178
179 /* Returns whether the state of the given task is SD_RUNNABLE. */
180 static XBT_INLINE int __SD_task_is_runnable(SD_task_t task)
181 {
182   return task->state_set == sd_global->runnable_task_set;
183 }
184
185 /* Returns whether the state of the given task is SD_IN_FIFO. */
186 static XBT_INLINE int __SD_task_is_in_fifo(SD_task_t task)
187 {
188   return task->state_set == sd_global->in_fifo_task_set;
189 }
190
191 /* Returns whether the state of the given task is SD_RUNNABLE or SD_IN_FIFO. */
192 static XBT_INLINE int __SD_task_is_runnable_or_in_fifo(SD_task_t task)
193 {
194   return task->state_set == sd_global->runnable_task_set ||
195       task->state_set == sd_global->in_fifo_task_set;
196 }
197
198 /* Returns whether the state of the given task is SD_RUNNING. */
199 static XBT_INLINE int __SD_task_is_running(SD_task_t task)
200 {
201   return task->state_set == sd_global->running_task_set;
202 }
203 /********** Tracing **********/
204 /* declaration of instrumentation functions from sd_task_instr.c */
205 void TRACE_sd_task_create(SD_task_t task);
206 void TRACE_sd_task_execute_start(SD_task_t task);
207 void TRACE_sd_task_execute_end(SD_task_t task);
208 void TRACE_sd_task_destroy(SD_task_t task);
209
210
211 #endif