1 /* Copyright (c) 2006-2015. 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
12 #include "xbt/dynar.h"
14 #include "simgrid/simdag.h"
15 #include "surf/surf.h"
17 #include "xbt/mallocator.h"
22 /* Global variables */
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 */
32 xbt_mallocator_t task_mallocator; /* to not remalloc new tasks */
34 int watch_point_reached; /* has a task just reached a watch point? */
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;
46 xbt_swag_t return_set;
49 } s_SD_global_t, *SD_global_t;
51 extern XBT_PRIVATE SD_global_t sd_global;
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;
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;
64 typedef s_xbt_dictelm_t s_SD_storage_t;
65 typedef struct SD_storage {
66 void *data; /* user data */
68 } s_SD_storage_priv_t, *SD_storage_priv_t;
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);
75 typedef struct SD_task {
76 s_xbt_swag_hookup_t state_hookup;
77 s_xbt_swag_hookup_t return_hookup;
79 e_SD_task_state_t state;
80 void *data; /* user data */
84 double alpha; /* used by typed parallel tasks */
88 surf_action_t surf_action;
89 unsigned short watch_points; /* bit field xor()ed with masks */
91 int fifo_checked; /* used by SD_task_just_done to make sure we evaluate
93 int marked; /* used to check if the task DAG has some cycle*/
96 xbt_dynar_t tasks_before;
97 xbt_dynar_t tasks_after;
98 int unsatisfied_dependencies;
99 unsigned int is_not_ready;
101 /* scheduling parameters (only exist in state SD_SCHEDULED) */
103 SD_workstation_t *workstation_list; /* surf workstations */
104 double *flops_amount;
105 double *bytes_amount;
108 long long int counter; /* task unique identifier for instrumentation */
109 char *category; /* sd task category for instrumentation */
112 /* Task dependencies */
113 typedef struct SD_dependency {
118 /* src must be finished before dst can start */
119 } s_SD_dependency_t, *SD_dependency_t;
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 */
125 XBT_PRIVATE SD_workstation_t __SD_workstation_create(void *surf_workstation,
127 XBT_PRIVATE void __SD_workstation_destroy(void *workstation);
128 XBT_PRIVATE int __SD_workstation_is_busy(SD_workstation_t workstation);
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);
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);
141 /* Functions to test if the task is in a given state. */
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)
146 return task->state_set == sd_global->scheduled_task_set ||
147 task->state_set == sd_global->runnable_task_set;
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)
153 return task->state_set == sd_global->schedulable_task_set ||
154 task->state_set == sd_global->done_task_set;
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)
160 return task->state_set == sd_global->not_scheduled_task_set;
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)
166 return task->state_set == sd_global->schedulable_task_set;
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)
172 return task->state_set == sd_global->scheduled_task_set;
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)
178 return task->state_set == sd_global->runnable_task_set;
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)
184 return task->state_set == sd_global->in_fifo_task_set;
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)
190 return task->state_set == sd_global->runnable_task_set ||
191 task->state_set == sd_global->in_fifo_task_set;
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)
197 return task->state_set == sd_global->running_task_set;
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);
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);