Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
88bb0a92d3848f159b2c9bf83ff00ad45e101d72
[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/surf.h"
16 #include "xbt/swag.h"
17 #include "xbt/mallocator.h"
18 #include <stdbool.h>
19
20 #define SD_INITIALISED() (sd_global != NULL)
21 #define SD_CHECK_INIT_DONE() xbt_assert(SD_INITIALISED(), "Call SD_init() first");
22
23 /* Global variables */
24
25 typedef struct SD_global {
26   SD_workstation_t *workstation_list;   /* array of workstations, created only if
27                                            necessary in SD_workstation_get_list */
28   SD_link_t *link_list;         /* array of links, created only if
29                                    necessary in SD_link_get_list */
30   SD_link_t *recyclable_route;  /* array returned by SD_route_get_list
31                                    and mallocated only once */
32
33   xbt_mallocator_t task_mallocator; /* to not remalloc new tasks */
34
35   int watch_point_reached;      /* has a task just reached a watch point? */
36
37   /* task state sets */
38   xbt_swag_t not_scheduled_task_set;
39   xbt_swag_t schedulable_task_set;
40   xbt_swag_t scheduled_task_set;
41   xbt_swag_t runnable_task_set;
42   xbt_swag_t in_fifo_task_set;
43   xbt_swag_t running_task_set;
44   xbt_swag_t done_task_set;
45   xbt_swag_t failed_task_set;
46
47   xbt_swag_t return_set;
48   int task_number;
49
50 } s_SD_global_t, *SD_global_t;
51
52 extern SD_global_t sd_global;
53
54 /* Link */
55 typedef struct SD_link {
56   void *surf_link;              /* surf object */
57   void *data;                   /* user data */
58   e_SD_link_sharing_policy_t sharing_policy;
59 } s_SD_link_t;
60
61 /* Workstation */
62 typedef struct SD_workstation {
63   void *surf_workstation;       /* surf object */
64   void *data;                   /* user data */
65   e_SD_workstation_access_mode_t access_mode;
66
67   xbt_fifo_t task_fifo;         /* only used in sequential mode */
68   SD_task_t current_task;       /* only used in sequential mode */
69 } s_SD_workstation_t;
70
71 /* Task */
72 typedef struct SD_task {
73   s_xbt_swag_hookup_t state_hookup;
74   s_xbt_swag_hookup_t return_hookup;
75   xbt_swag_t state_set;
76   e_SD_task_state_t state;
77   void *data;                   /* user data */
78   char *name;
79   int kind;
80   double amount;
81   double remains;
82   double start_time;
83   double finish_time;
84   surf_action_t surf_action;
85   unsigned short watch_points;  /* bit field xor()ed with masks */
86
87   int fifo_checked;             /* used by SD_task_just_done to make sure we evaluate
88                                    the task only once */
89   int marked;                   /* used to check if the task DAG has some cycle*/
90
91   /* dependencies */
92   xbt_dynar_t tasks_before;
93   xbt_dynar_t tasks_after;
94   unsigned int unsatisfied_dependencies;
95   unsigned int is_not_ready;
96
97   /* scheduling parameters (only exist in state SD_SCHEDULED) */
98   int workstation_nb;
99   SD_workstation_t *workstation_list;   /* surf workstations */
100   double *computation_amount;
101   double *communication_amount;
102   double rate;
103
104 #ifdef HAVE_TRACING
105   char *category;               /* sd task category for instrumentation */
106 #endif
107 } s_SD_task_t;
108
109 /* Task dependencies */
110 typedef struct SD_dependency {
111   char *name;
112   void *data;
113   SD_task_t src;
114   SD_task_t dst;
115   /* src must be finished before dst can start */
116 } s_SD_dependency_t, *SD_dependency_t;
117
118 /* SimDag private functions */
119 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 */
120
121
122 SD_link_t __SD_link_create(void *surf_link, void *data);
123 void __SD_link_destroy(void *link);
124
125 SD_workstation_t __SD_workstation_create(void *surf_workstation,
126                                          void *data);
127 void __SD_workstation_destroy(void *workstation);
128 int __SD_workstation_is_busy(SD_workstation_t workstation);
129
130 void __SD_task_set_state(SD_task_t task, e_SD_task_state_t new_state);
131 void __SD_task_really_run(SD_task_t task);
132 int __SD_task_try_to_run(SD_task_t task);
133 void __SD_task_just_done(SD_task_t task);
134 bool acyclic_graph_detail(xbt_dynar_t dag);
135
136 /* Task mallocator functions */
137 void* SD_task_new_f(void);
138 void SD_task_recycle_f(void *t);
139 void SD_task_free_f(void *t);
140
141 /* Functions to test if the task is in a given state. */
142
143 /* Returns whether the given task is scheduled or runnable. */
144 static XBT_INLINE int __SD_task_is_scheduled_or_runnable(SD_task_t task)
145 {
146   return task->state_set == sd_global->scheduled_task_set ||
147       task->state_set == sd_global->runnable_task_set;
148 }
149
150 /* Returns whether the given task is scheduled or runnable. */
151 static XBT_INLINE int __SD_task_is_schedulable_or_done(SD_task_t task)
152 {
153   return task->state_set == sd_global->schedulable_task_set ||
154       task->state_set == sd_global->done_task_set;
155 }
156
157 /* Returns whether the state of the given task is SD_NOT_SCHEDULED. */
158 static XBT_INLINE int __SD_task_is_not_scheduled(SD_task_t task)
159 {
160   return task->state_set == sd_global->not_scheduled_task_set;
161 }
162
163 /* Returns whether the state of the given task is SD_SCHEDULED. */
164 static XBT_INLINE int __SD_task_is_schedulable(SD_task_t task)
165 {
166   return task->state_set == sd_global->schedulable_task_set;
167 }
168
169 /* Returns whether the state of the given task is SD_SCHEDULED. */
170 static XBT_INLINE int __SD_task_is_scheduled(SD_task_t task)
171 {
172   return task->state_set == sd_global->scheduled_task_set;
173 }
174
175 /* Returns whether the state of the given task is SD_RUNNABLE. */
176 static XBT_INLINE int __SD_task_is_runnable(SD_task_t task)
177 {
178   return task->state_set == sd_global->runnable_task_set;
179 }
180
181 /* Returns whether the state of the given task is SD_IN_FIFO. */
182 static XBT_INLINE int __SD_task_is_in_fifo(SD_task_t task)
183 {
184   return task->state_set == sd_global->in_fifo_task_set;
185 }
186
187 /* Returns whether the state of the given task is SD_RUNNABLE or SD_IN_FIFO. */
188 static XBT_INLINE int __SD_task_is_runnable_or_in_fifo(SD_task_t task)
189 {
190   return task->state_set == sd_global->runnable_task_set ||
191       task->state_set == sd_global->in_fifo_task_set;
192 }
193
194 /* Returns whether the state of the given task is SD_RUNNING. */
195 static XBT_INLINE int __SD_task_is_running(SD_task_t task)
196 {
197   return task->state_set == sd_global->running_task_set;
198 }
199
200 #endif