Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
b99e9924aac8a4f255b1efd8cf4c0041a9cb041d
[simgrid.git] / src / simdag / private.h
1 /* Copyright (c) 2006-2015. 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/base.h"
11 #include "xbt/dict.h"
12 #include "xbt/dynar.h"
13 #include "xbt/fifo.h"
14 #include "simgrid/simdag.h"
15 #include "surf/surf.h"
16 #include "xbt/swag.h"
17 #include "xbt/mallocator.h"
18 #include <stdbool.h>
19
20 SG_BEGIN_DECL()
21
22 /* Global variables */
23
24 typedef struct SD_global {
25   SD_workstation_t *workstation_list;   /* array of workstations, created only if
26                                            necessary in SD_workstation_get_list */
27   SD_link_t *link_list;         /* array of links, created only if
28                                    necessary in SD_link_get_list */
29   SD_link_t *recyclable_route;  /* array returned by SD_route_get_list
30                                    and mallocated only once */
31
32   xbt_mallocator_t task_mallocator; /* to not remalloc new tasks */
33
34   int watch_point_reached;      /* has a task just reached a watch point? */
35
36   /* task state sets */
37   xbt_swag_t not_scheduled_task_set;
38   xbt_swag_t schedulable_task_set;
39   xbt_swag_t scheduled_task_set;
40   xbt_swag_t runnable_task_set;
41   xbt_swag_t in_fifo_task_set;
42   xbt_swag_t running_task_set;
43   xbt_swag_t done_task_set;
44   xbt_swag_t failed_task_set;
45
46   xbt_swag_t return_set;
47   int task_number;
48
49 } s_SD_global_t, *SD_global_t;
50
51 extern XBT_PRIVATE SD_global_t sd_global;
52
53 /* Workstation */
54 typedef s_xbt_dictelm_t s_SD_workstation_t;
55 typedef struct SD_workstation {
56   void *data;                   /* user data */
57   e_SD_workstation_access_mode_t access_mode;
58
59   xbt_fifo_t task_fifo;         /* only used in sequential mode */
60   SD_task_t current_task;       /* only used in sequential mode */
61 } s_SD_workstation_priv_t, *SD_workstation_priv_t;
62
63 /* Storage */
64 typedef s_xbt_dictelm_t s_SD_storage_t;
65 typedef struct SD_storage {
66   void *data;                   /* user data */
67   const char *host;
68 } s_SD_storage_priv_t, *SD_storage_priv_t;
69
70 static inline SD_storage_priv_t SD_storage_priv(SD_storage_t storage){
71   return (SD_storage_priv_t)xbt_lib_get_level(storage, SD_STORAGE_LEVEL);
72 }
73
74 /* Task */
75 typedef struct SD_task {
76   s_xbt_swag_hookup_t state_hookup;
77   s_xbt_swag_hookup_t return_hookup;
78   xbt_swag_t state_set;
79   e_SD_task_state_t state;
80   void *data;                   /* user data */
81   char *name;
82   int kind;
83   double amount;
84   double alpha;          /* used by typed parallel tasks */
85   double remains;
86   double start_time;
87   double finish_time;
88   surf_action_t surf_action;
89   unsigned short watch_points;  /* bit field xor()ed with masks */
90
91   int fifo_checked;             /* used by SD_task_just_done to make sure we evaluate
92                                    the task only once */
93   int marked;                   /* used to check if the task DAG has some cycle*/
94
95   /* dependencies */
96   xbt_dynar_t tasks_before;
97   xbt_dynar_t tasks_after;
98   int unsatisfied_dependencies;
99   unsigned int is_not_ready;
100
101   /* scheduling parameters (only exist in state SD_SCHEDULED) */
102   int workstation_nb;
103   SD_workstation_t *workstation_list;   /* surf workstations */
104   double *flops_amount;
105   double *bytes_amount;
106   double rate;
107
108   long long int counter;        /* task unique identifier for instrumentation */
109   char *category;               /* sd task category for instrumentation */
110 } s_SD_task_t;
111
112 /* Task dependencies */
113 typedef struct SD_dependency {
114   char *name;
115   void *data;
116   SD_task_t src;
117   SD_task_t dst;
118   /* src must be finished before dst can start */
119 } s_SD_dependency_t, *SD_dependency_t;
120
121 /* SimDag private functions */
122 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 */
123
124
125 XBT_PRIVATE SD_workstation_t __SD_workstation_create(void *surf_workstation,
126                                          void *data);
127 XBT_PRIVATE void __SD_workstation_destroy(void *workstation);
128 XBT_PRIVATE int __SD_workstation_is_busy(SD_workstation_t workstation);
129
130 XBT_PRIVATE void __SD_task_set_state(SD_task_t task, e_SD_task_state_t new_state);
131 XBT_PRIVATE void __SD_task_really_run(SD_task_t task);
132 XBT_PRIVATE void __SD_task_just_done(SD_task_t task);
133 XBT_PRIVATE int __SD_task_try_to_run(SD_task_t task);
134 XBT_PRIVATE bool acyclic_graph_detail(xbt_dynar_t dag);
135
136 /* Task mallocator functions */
137 XBT_PRIVATE void* SD_task_new_f(void);
138 XBT_PRIVATE void SD_task_recycle_f(void *t);
139 XBT_PRIVATE 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 /********** Storage **********/
201 XBT_PRIVATE SD_storage_t __SD_storage_create(void *surf_storage, void *data);
202 XBT_PRIVATE void __SD_storage_destroy(void *storage);
203
204 /********** Tracing **********/
205 /* declaration of instrumentation functions from sd_task_instr.c */
206 XBT_PRIVATE void TRACE_sd_task_create(SD_task_t task);
207 XBT_PRIVATE void TRACE_sd_task_execute_start(SD_task_t task);
208 XBT_PRIVATE void TRACE_sd_task_execute_end(SD_task_t task);
209 XBT_PRIVATE void TRACE_sd_task_destroy(SD_task_t task);
210
211 SG_END_DECL()
212
213 #endif