1 /* Copyright (c) 2007-2009 Da SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #ifndef SIMDAG_PRIVATE_H
7 #define SIMDAG_PRIVATE_H
10 #include "xbt/dynar.h"
12 #include "simdag/simdag.h"
13 #include "simdag/datatypes.h"
14 #include "surf/surf.h"
16 #define SD_INITIALISED() (sd_global != NULL)
17 #define SD_CHECK_INIT_DONE() xbt_assert0(SD_INITIALISED(), "Call SD_init() first");
19 /* Global variables */
21 typedef struct SD_global {
22 xbt_dict_t workstations; /* workstation dictionary */
23 int workstation_count; /* number of workstations */
24 SD_workstation_t *workstation_list; /* array of workstations, created only if
25 necessary in SD_workstation_get_list */
27 xbt_dict_t links; /* links */
28 int link_count; /* number of links */
29 SD_link_t *link_list; /* array of links, created only if
30 necessary in SD_link_get_list */
31 SD_link_t *recyclable_route; /* array returned by SD_route_get_list
32 and mallocated only once */
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 scheduled_task_set;
39 xbt_swag_t ready_task_set;
40 xbt_swag_t in_fifo_task_set;
41 xbt_swag_t running_task_set;
42 xbt_swag_t done_task_set;
43 xbt_swag_t failed_task_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 struct SD_workstation {
60 void *surf_workstation; /* surf object */
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 */
69 typedef struct SD_task {
70 s_xbt_swag_hookup_t state_hookup;
72 e_SD_task_state_t state;
73 void *data; /* user data */
80 surf_action_t surf_action;
81 unsigned short watch_points; /* bit field xor()ed with masks */
83 int fifo_checked; /* used by SD_task_just_done to make sure we evaluate
87 xbt_dynar_t tasks_before;
88 xbt_dynar_t tasks_after;
90 /* scheduling parameters (only exist in state SD_SCHEDULED) */
92 SD_workstation_t *workstation_list; /* surf workstations */
93 double *computation_amount;
94 double *communication_amount;
98 /* Task dependencies */
99 typedef struct SD_dependency {
104 /* src must be finished before dst can start */
105 } s_SD_dependency_t, *SD_dependency_t;
107 /* SimDag private functions */
109 SD_link_t __SD_link_create(void *surf_link, void *data);
110 void __SD_link_destroy(void *link);
112 SD_workstation_t __SD_workstation_create(void *surf_workstation, void *data);
113 void __SD_workstation_destroy(void *workstation);
114 int __SD_workstation_is_busy(SD_workstation_t workstation);
116 void __SD_task_set_state(SD_task_t task, e_SD_task_state_t new_state);
117 void __SD_task_really_run(SD_task_t task);
118 int __SD_task_try_to_run(SD_task_t task);
119 void __SD_task_just_done(SD_task_t task);
121 /* Functions to test if the task is in a given state. */
123 /* Returns whether the given task is scheduled or ready. */
124 static XBT_INLINE int __SD_task_is_scheduled_or_ready(SD_task_t task)
126 return task->state_set == sd_global->scheduled_task_set ||
127 task->state_set == sd_global->ready_task_set;
130 /* Returns whether the state of the given task is SD_NOT_SCHEDULED. */
131 static XBT_INLINE int __SD_task_is_not_scheduled(SD_task_t task)
133 return task->state_set == sd_global->not_scheduled_task_set;
136 /* Returns whether the state of the given task is SD_SCHEDULED. */
137 static XBT_INLINE int __SD_task_is_scheduled(SD_task_t task)
139 return task->state_set == sd_global->scheduled_task_set;
142 /* Returns whether the state of the given task is SD_READY. */
143 static XBT_INLINE int __SD_task_is_ready(SD_task_t task)
145 return task->state_set == sd_global->ready_task_set;
148 /* Returns whether the state of the given task is SD_IN_FIFO. */
149 static XBT_INLINE int __SD_task_is_in_fifo(SD_task_t task)
151 return task->state_set == sd_global->in_fifo_task_set;
154 /* Returns whether the state of the given task is SD_READY or SD_IN_FIFO. */
155 static XBT_INLINE int __SD_task_is_ready_or_in_fifo(SD_task_t task)
157 return task->state_set == sd_global->ready_task_set ||
158 task->state_set == sd_global->in_fifo_task_set;
161 /* Returns whether the state of the given task is SD_RUNNING. */
162 static XBT_INLINE int __SD_task_is_running(SD_task_t task)
164 return task->state_set == sd_global->running_task_set;