1 /* Copyright (c) 2006-2014. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #ifndef SIMDAG_PRIVATE_H
8 #define SIMDAG_PRIVATE_H
11 #include "xbt/dynar.h"
13 #include "simgrid/simdag.h"
14 #include "surf/surf.h"
16 #include "xbt/mallocator.h"
19 /* Global variables */
21 typedef struct SD_global {
22 SD_workstation_t *workstation_list; /* array of workstations, created only if
23 necessary in SD_workstation_get_list */
24 SD_link_t *link_list; /* array of links, created only if
25 necessary in SD_link_get_list */
26 SD_link_t *recyclable_route; /* array returned by SD_route_get_list
27 and mallocated only once */
29 xbt_mallocator_t task_mallocator; /* to not remalloc new tasks */
31 int watch_point_reached; /* has a task just reached a watch point? */
34 xbt_swag_t not_scheduled_task_set;
35 xbt_swag_t schedulable_task_set;
36 xbt_swag_t scheduled_task_set;
37 xbt_swag_t runnable_task_set;
38 xbt_swag_t in_fifo_task_set;
39 xbt_swag_t running_task_set;
40 xbt_swag_t done_task_set;
41 xbt_swag_t failed_task_set;
43 xbt_swag_t return_set;
46 } s_SD_global_t, *SD_global_t;
48 extern SD_global_t sd_global;
51 typedef struct SD_link {
52 void *surf_link; /* surf object */
53 void *data; /* user data */
54 e_SD_link_sharing_policy_t sharing_policy;
58 typedef s_xbt_dictelm_t s_SD_workstation_t;
59 typedef struct SD_workstation {
60 void *data; /* user data */
61 e_SD_workstation_access_mode_t access_mode;
63 xbt_fifo_t task_fifo; /* only used in sequential mode */
64 SD_task_t current_task; /* only used in sequential mode */
65 } s_SD_workstation_priv_t, *SD_workstation_priv_t;
67 static inline SD_workstation_priv_t SD_workstation_priv(SD_workstation_t host){
68 return xbt_lib_get_level(host, SD_HOST_LEVEL);
72 typedef s_xbt_dictelm_t s_SD_storage_t;
73 typedef struct SD_storage {
74 void *data; /* user data */
76 } s_SD_storage_priv_t, *SD_storage_priv_t;
78 static inline SD_storage_priv_t SD_storage_priv(SD_storage_t storage){
79 return xbt_lib_get_level(storage, SD_STORAGE_LEVEL);
83 typedef struct SD_task {
84 s_xbt_swag_hookup_t state_hookup;
85 s_xbt_swag_hookup_t return_hookup;
87 e_SD_task_state_t state;
88 void *data; /* user data */
92 double alpha; /* used by typed parallel tasks */
96 surf_action_t surf_action;
97 unsigned short watch_points; /* bit field xor()ed with masks */
99 int fifo_checked; /* used by SD_task_just_done to make sure we evaluate
100 the task only once */
101 int marked; /* used to check if the task DAG has some cycle*/
104 xbt_dynar_t tasks_before;
105 xbt_dynar_t tasks_after;
106 int unsatisfied_dependencies;
107 unsigned int is_not_ready;
109 /* scheduling parameters (only exist in state SD_SCHEDULED) */
111 SD_workstation_t *workstation_list; /* surf workstations */
112 double *flops_amount;
113 double *bytes_amount;
116 long long int counter; /* task unique identifier for instrumentation */
117 char *category; /* sd task category for instrumentation */
120 /* Task dependencies */
121 typedef struct SD_dependency {
126 /* src must be finished before dst can start */
127 } s_SD_dependency_t, *SD_dependency_t;
129 /* SimDag private functions */
130 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 */
133 SD_link_t __SD_link_create(void *surf_link, void *data);
134 #define __SD_link_destroy xbt_free_f
136 SD_workstation_t __SD_workstation_create(void *surf_workstation,
138 void __SD_workstation_destroy(void *workstation);
139 int __SD_workstation_is_busy(SD_workstation_t workstation);
141 void __SD_task_set_state(SD_task_t task, e_SD_task_state_t new_state);
142 void __SD_task_really_run(SD_task_t task);
143 int __SD_task_try_to_run(SD_task_t task);
144 void __SD_task_just_done(SD_task_t task);
145 bool acyclic_graph_detail(xbt_dynar_t dag);
147 /* Task mallocator functions */
148 void* SD_task_new_f(void);
149 void SD_task_recycle_f(void *t);
150 void SD_task_free_f(void *t);
152 /* Functions to test if the task is in a given state. */
154 /* Returns whether the given task is scheduled or runnable. */
155 static XBT_INLINE int __SD_task_is_scheduled_or_runnable(SD_task_t task)
157 return task->state_set == sd_global->scheduled_task_set ||
158 task->state_set == sd_global->runnable_task_set;
161 /* Returns whether the given task is scheduled or runnable. */
162 static XBT_INLINE int __SD_task_is_schedulable_or_done(SD_task_t task)
164 return task->state_set == sd_global->schedulable_task_set ||
165 task->state_set == sd_global->done_task_set;
168 /* Returns whether the state of the given task is SD_NOT_SCHEDULED. */
169 static XBT_INLINE int __SD_task_is_not_scheduled(SD_task_t task)
171 return task->state_set == sd_global->not_scheduled_task_set;
174 /* Returns whether the state of the given task is SD_SCHEDULED. */
175 static XBT_INLINE int __SD_task_is_schedulable(SD_task_t task)
177 return task->state_set == sd_global->schedulable_task_set;
180 /* Returns whether the state of the given task is SD_SCHEDULED. */
181 static XBT_INLINE int __SD_task_is_scheduled(SD_task_t task)
183 return task->state_set == sd_global->scheduled_task_set;
186 /* Returns whether the state of the given task is SD_RUNNABLE. */
187 static XBT_INLINE int __SD_task_is_runnable(SD_task_t task)
189 return task->state_set == sd_global->runnable_task_set;
192 /* Returns whether the state of the given task is SD_IN_FIFO. */
193 static XBT_INLINE int __SD_task_is_in_fifo(SD_task_t task)
195 return task->state_set == sd_global->in_fifo_task_set;
198 /* Returns whether the state of the given task is SD_RUNNABLE or SD_IN_FIFO. */
199 static XBT_INLINE int __SD_task_is_runnable_or_in_fifo(SD_task_t task)
201 return task->state_set == sd_global->runnable_task_set ||
202 task->state_set == sd_global->in_fifo_task_set;
205 /* Returns whether the state of the given task is SD_RUNNING. */
206 static XBT_INLINE int __SD_task_is_running(SD_task_t task)
208 return task->state_set == sd_global->running_task_set;
211 /********** Storage **********/
212 SD_storage_t __SD_storage_create(void *surf_storage, void *data);
213 void __SD_storage_destroy(void *storage);
215 /********** Tracing **********/
216 /* declaration of instrumentation functions from sd_task_instr.c */
217 void TRACE_sd_task_create(SD_task_t task);
218 void TRACE_sd_task_execute_start(SD_task_t task);
219 void TRACE_sd_task_execute_end(SD_task_t task);
220 void TRACE_sd_task_destroy(SD_task_t task);