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 */
79 surf_action_t surf_action;
80 unsigned short watch_points;
82 int fifo_checked; /* used by SD_task_just_done to make sure we evaluate
86 xbt_dynar_t tasks_before;
87 xbt_dynar_t tasks_after;
89 /* scheduling parameters (only exist in state SD_SCHEDULED) */
91 SD_workstation_t *workstation_list; /* surf workstations */
92 double *computation_amount;
93 double *communication_amount;
97 /* Task dependencies */
98 typedef struct SD_dependency {
103 /* src must be finished before dst can start */
104 } s_SD_dependency_t, *SD_dependency_t;
106 /* SimDag private functions */
108 SD_link_t __SD_link_create(void *surf_link, void *data);
109 void __SD_link_destroy(void *link);
111 SD_workstation_t __SD_workstation_create(void *surf_workstation, void *data);
112 void __SD_workstation_destroy(void *workstation);
113 int __SD_workstation_is_busy(SD_workstation_t workstation);
115 void __SD_task_set_state(SD_task_t task, e_SD_task_state_t new_state);
116 void __SD_task_really_run(SD_task_t task);
117 int __SD_task_try_to_run(SD_task_t task);
118 void __SD_task_just_done(SD_task_t task);
120 /* Functions to test if the task is in a given state. */
122 /* Returns whether the given task is scheduled or ready. */
123 static XBT_INLINE int __SD_task_is_scheduled_or_ready(SD_task_t task)
125 return task->state_set == sd_global->scheduled_task_set ||
126 task->state_set == sd_global->ready_task_set;
129 /* Returns whether the state of the given task is SD_NOT_SCHEDULED. */
130 static XBT_INLINE int __SD_task_is_not_scheduled(SD_task_t task)
132 return task->state_set == sd_global->not_scheduled_task_set;
135 /* Returns whether the state of the given task is SD_SCHEDULED. */
136 static XBT_INLINE int __SD_task_is_scheduled(SD_task_t task)
138 return task->state_set == sd_global->scheduled_task_set;
141 /* Returns whether the state of the given task is SD_READY. */
142 static XBT_INLINE int __SD_task_is_ready(SD_task_t task)
144 return task->state_set == sd_global->ready_task_set;
147 /* Returns whether the state of the given task is SD_IN_FIFO. */
148 static XBT_INLINE int __SD_task_is_in_fifo(SD_task_t task)
150 return task->state_set == sd_global->in_fifo_task_set;
153 /* Returns whether the state of the given task is SD_READY or SD_IN_FIFO. */
154 static XBT_INLINE int __SD_task_is_ready_or_in_fifo(SD_task_t task)
156 return task->state_set == sd_global->ready_task_set ||
157 task->state_set == sd_global->in_fifo_task_set;
160 /* Returns whether the state of the given task is SD_RUNNING. */
161 static XBT_INLINE int __SD_task_is_running(SD_task_t task)
163 return task->state_set == sd_global->running_task_set;