1 /* Copyright (c) 2006-2013. 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 "simdag/simdag.h"
14 #include "simdag/datatypes.h"
15 #include "surf/surf.h"
17 #include "xbt/mallocator.h"
20 /* Global variables */
22 typedef struct SD_global {
23 SD_workstation_t *workstation_list; /* array of workstations, created only if
24 necessary in SD_workstation_get_list */
25 SD_link_t *link_list; /* array of links, created only if
26 necessary in SD_link_get_list */
27 SD_link_t *recyclable_route; /* array returned by SD_route_get_list
28 and mallocated only once */
30 xbt_mallocator_t task_mallocator; /* to not remalloc new tasks */
32 int watch_point_reached; /* has a task just reached a watch point? */
35 xbt_swag_t not_scheduled_task_set;
36 xbt_swag_t schedulable_task_set;
37 xbt_swag_t scheduled_task_set;
38 xbt_swag_t runnable_task_set;
39 xbt_swag_t in_fifo_task_set;
40 xbt_swag_t running_task_set;
41 xbt_swag_t done_task_set;
42 xbt_swag_t failed_task_set;
44 xbt_swag_t return_set;
47 } s_SD_global_t, *SD_global_t;
49 extern SD_global_t sd_global;
52 typedef struct SD_link {
53 void *surf_link; /* surf object */
54 void *data; /* user data */
55 e_SD_link_sharing_policy_t sharing_policy;
59 typedef s_xbt_dictelm_t s_SD_workstation_t;
60 typedef struct SD_workstation {
61 void *data; /* user data */
62 e_SD_workstation_access_mode_t access_mode;
64 xbt_fifo_t task_fifo; /* only used in sequential mode */
65 SD_task_t current_task; /* only used in sequential mode */
66 } s_SD_workstation_priv_t, *SD_workstation_priv_t;
68 static inline SD_workstation_priv_t SD_workstation_priv(SD_workstation_t host){
69 return xbt_lib_get_level(host, SD_HOST_LEVEL);
73 typedef s_xbt_dictelm_t s_SD_storage_t;
74 typedef struct SD_storage {
75 void *data; /* user data */
76 } s_SD_storage_priv_t, *SD_storage_priv_t;
80 typedef struct SD_task {
81 s_xbt_swag_hookup_t state_hookup;
82 s_xbt_swag_hookup_t return_hookup;
84 e_SD_task_state_t state;
85 void *data; /* user data */
89 double alpha; /* used by typed parallel tasks */
93 surf_action_t surf_action;
94 unsigned short watch_points; /* bit field xor()ed with masks */
96 int fifo_checked; /* used by SD_task_just_done to make sure we evaluate
98 int marked; /* used to check if the task DAG has some cycle*/
101 xbt_dynar_t tasks_before;
102 xbt_dynar_t tasks_after;
103 int unsatisfied_dependencies;
104 unsigned int is_not_ready;
106 /* scheduling parameters (only exist in state SD_SCHEDULED) */
108 SD_workstation_t *workstation_list; /* surf workstations */
109 double *computation_amount;
110 double *communication_amount;
114 long long int counter; /* task unique identifier for instrumentation */
115 char *category; /* sd task category for instrumentation */
119 /* Task dependencies */
120 typedef struct SD_dependency {
125 /* src must be finished before dst can start */
126 } s_SD_dependency_t, *SD_dependency_t;
128 /* SimDag private functions */
129 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 */
132 SD_link_t __SD_link_create(void *surf_link, void *data);
133 #define __SD_link_destroy xbt_free_f
135 SD_workstation_t __SD_workstation_create(void *surf_workstation,
137 void __SD_workstation_destroy(void *workstation);
138 int __SD_workstation_is_busy(SD_workstation_t workstation);
140 void __SD_task_set_state(SD_task_t task, e_SD_task_state_t new_state);
141 void __SD_task_really_run(SD_task_t task);
142 int __SD_task_try_to_run(SD_task_t task);
143 void __SD_task_just_done(SD_task_t task);
144 bool acyclic_graph_detail(xbt_dynar_t dag);
146 /* Task mallocator functions */
147 void* SD_task_new_f(void);
148 void SD_task_recycle_f(void *t);
149 void SD_task_free_f(void *t);
151 /* Functions to test if the task is in a given state. */
153 /* Returns whether the given task is scheduled or runnable. */
154 static XBT_INLINE int __SD_task_is_scheduled_or_runnable(SD_task_t task)
156 return task->state_set == sd_global->scheduled_task_set ||
157 task->state_set == sd_global->runnable_task_set;
160 /* Returns whether the given task is scheduled or runnable. */
161 static XBT_INLINE int __SD_task_is_schedulable_or_done(SD_task_t task)
163 return task->state_set == sd_global->schedulable_task_set ||
164 task->state_set == sd_global->done_task_set;
167 /* Returns whether the state of the given task is SD_NOT_SCHEDULED. */
168 static XBT_INLINE int __SD_task_is_not_scheduled(SD_task_t task)
170 return task->state_set == sd_global->not_scheduled_task_set;
173 /* Returns whether the state of the given task is SD_SCHEDULED. */
174 static XBT_INLINE int __SD_task_is_schedulable(SD_task_t task)
176 return task->state_set == sd_global->schedulable_task_set;
179 /* Returns whether the state of the given task is SD_SCHEDULED. */
180 static XBT_INLINE int __SD_task_is_scheduled(SD_task_t task)
182 return task->state_set == sd_global->scheduled_task_set;
185 /* Returns whether the state of the given task is SD_RUNNABLE. */
186 static XBT_INLINE int __SD_task_is_runnable(SD_task_t task)
188 return task->state_set == sd_global->runnable_task_set;
191 /* Returns whether the state of the given task is SD_IN_FIFO. */
192 static XBT_INLINE int __SD_task_is_in_fifo(SD_task_t task)
194 return task->state_set == sd_global->in_fifo_task_set;
197 /* Returns whether the state of the given task is SD_RUNNABLE or SD_IN_FIFO. */
198 static XBT_INLINE int __SD_task_is_runnable_or_in_fifo(SD_task_t task)
200 return task->state_set == sd_global->runnable_task_set ||
201 task->state_set == sd_global->in_fifo_task_set;
204 /* Returns whether the state of the given task is SD_RUNNING. */
205 static XBT_INLINE int __SD_task_is_running(SD_task_t task)
207 return task->state_set == sd_global->running_task_set;
210 /********** Storage **********/
211 SD_storage_t __SD_storage_create(void *surf_storage, void *data);
212 void __SD_storage_destroy(void *storage);
214 /********** Tracing **********/
215 /* declaration of instrumentation functions from sd_task_instr.c */
216 void TRACE_sd_task_create(SD_task_t task);
217 void TRACE_sd_task_execute_start(SD_task_t task);
218 void TRACE_sd_task_execute_end(SD_task_t task);
219 void TRACE_sd_task_destroy(SD_task_t task);