Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
make SD_HOST_LEVEL private
[simgrid.git] / src / simdag / private.h
1 /* Copyright (c) 2006-2014. 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 "simgrid/simdag.h"
14 #include "surf/surf.h"
15 #include "xbt/swag.h"
16 #include "xbt/mallocator.h"
17 #include <stdbool.h>
18
19 SG_BEGIN_DECL()
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 /* Storage */
70 typedef s_xbt_dictelm_t s_SD_storage_t;
71 typedef struct SD_storage {
72   void *data;                   /* user data */
73   const char *host;
74 } s_SD_storage_priv_t, *SD_storage_priv_t;
75
76 static inline SD_storage_priv_t SD_storage_priv(SD_storage_t storage){
77   return (SD_storage_priv_t)xbt_lib_get_level(storage, SD_STORAGE_LEVEL);
78 }
79
80 /* Task */
81 typedef struct SD_task {
82   s_xbt_swag_hookup_t state_hookup;
83   s_xbt_swag_hookup_t return_hookup;
84   xbt_swag_t state_set;
85   e_SD_task_state_t state;
86   void *data;                   /* user data */
87   char *name;
88   int kind;
89   double amount;
90   double alpha;          /* used by typed parallel tasks */
91   double remains;
92   double start_time;
93   double finish_time;
94   surf_action_t surf_action;
95   unsigned short watch_points;  /* bit field xor()ed with masks */
96
97   int fifo_checked;             /* used by SD_task_just_done to make sure we evaluate
98                                    the task only once */
99   int marked;                   /* used to check if the task DAG has some cycle*/
100
101   /* dependencies */
102   xbt_dynar_t tasks_before;
103   xbt_dynar_t tasks_after;
104   int unsatisfied_dependencies;
105   unsigned int is_not_ready;
106
107   /* scheduling parameters (only exist in state SD_SCHEDULED) */
108   int workstation_nb;
109   SD_workstation_t *workstation_list;   /* surf workstations */
110   double *flops_amount;
111   double *bytes_amount;
112   double rate;
113
114   long long int counter;        /* task unique identifier for instrumentation */
115   char *category;               /* sd task category for instrumentation */
116 } s_SD_task_t;
117
118 /* Task dependencies */
119 typedef struct SD_dependency {
120   char *name;
121   void *data;
122   SD_task_t src;
123   SD_task_t dst;
124   /* src must be finished before dst can start */
125 } s_SD_dependency_t, *SD_dependency_t;
126
127 /* SimDag private functions */
128 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 */
129
130
131 SD_link_t __SD_link_create(void *surf_link, void *data);
132 #define __SD_link_destroy xbt_free_f
133
134 SD_workstation_t __SD_workstation_create(void *surf_workstation,
135                                          void *data);
136 void __SD_workstation_destroy(void *workstation);
137 int __SD_workstation_is_busy(SD_workstation_t workstation);
138
139 void __SD_task_set_state(SD_task_t task, e_SD_task_state_t new_state);
140 void __SD_task_really_run(SD_task_t task);
141 int __SD_task_try_to_run(SD_task_t task);
142 void __SD_task_just_done(SD_task_t task);
143 bool acyclic_graph_detail(xbt_dynar_t dag);
144
145 /* Task mallocator functions */
146 void* SD_task_new_f(void);
147 void SD_task_recycle_f(void *t);
148 void SD_task_free_f(void *t);
149
150 /* Functions to test if the task is in a given state. */
151
152 /* Returns whether the given task is scheduled or runnable. */
153 static XBT_INLINE int __SD_task_is_scheduled_or_runnable(SD_task_t task)
154 {
155   return task->state_set == sd_global->scheduled_task_set ||
156       task->state_set == sd_global->runnable_task_set;
157 }
158
159 /* Returns whether the given task is scheduled or runnable. */
160 static XBT_INLINE int __SD_task_is_schedulable_or_done(SD_task_t task)
161 {
162   return task->state_set == sd_global->schedulable_task_set ||
163       task->state_set == sd_global->done_task_set;
164 }
165
166 /* Returns whether the state of the given task is SD_NOT_SCHEDULED. */
167 static XBT_INLINE int __SD_task_is_not_scheduled(SD_task_t task)
168 {
169   return task->state_set == sd_global->not_scheduled_task_set;
170 }
171
172 /* Returns whether the state of the given task is SD_SCHEDULED. */
173 static XBT_INLINE int __SD_task_is_schedulable(SD_task_t task)
174 {
175   return task->state_set == sd_global->schedulable_task_set;
176 }
177
178 /* Returns whether the state of the given task is SD_SCHEDULED. */
179 static XBT_INLINE int __SD_task_is_scheduled(SD_task_t task)
180 {
181   return task->state_set == sd_global->scheduled_task_set;
182 }
183
184 /* Returns whether the state of the given task is SD_RUNNABLE. */
185 static XBT_INLINE int __SD_task_is_runnable(SD_task_t task)
186 {
187   return task->state_set == sd_global->runnable_task_set;
188 }
189
190 /* Returns whether the state of the given task is SD_IN_FIFO. */
191 static XBT_INLINE int __SD_task_is_in_fifo(SD_task_t task)
192 {
193   return task->state_set == sd_global->in_fifo_task_set;
194 }
195
196 /* Returns whether the state of the given task is SD_RUNNABLE or SD_IN_FIFO. */
197 static XBT_INLINE int __SD_task_is_runnable_or_in_fifo(SD_task_t task)
198 {
199   return task->state_set == sd_global->runnable_task_set ||
200       task->state_set == sd_global->in_fifo_task_set;
201 }
202
203 /* Returns whether the state of the given task is SD_RUNNING. */
204 static XBT_INLINE int __SD_task_is_running(SD_task_t task)
205 {
206   return task->state_set == sd_global->running_task_set;
207 }
208
209 /********** Storage **********/
210 SD_storage_t __SD_storage_create(void *surf_storage, void *data);
211 void __SD_storage_destroy(void *storage);
212
213 /********** Tracing **********/
214 /* declaration of instrumentation functions from sd_task_instr.c */
215 void TRACE_sd_task_create(SD_task_t task);
216 void TRACE_sd_task_execute_start(SD_task_t task);
217 void TRACE_sd_task_execute_end(SD_task_t task);
218 void TRACE_sd_task_destroy(SD_task_t task);
219
220 SG_END_DECL()
221
222 #endif