Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove sg_platf_*_add_cb, use the signal<T> directly
[simgrid.git] / src / simdag / simdag_private.h
1 /* Copyright (c) 2006-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #ifndef SIMDAG_PRIVATE_H
8 #define SIMDAG_PRIVATE_H
9
10 #include "xbt/base.h"
11 #include "xbt/dict.h"
12 #include "xbt/dynar.h"
13 #include "xbt/fifo.h"
14 #include "simgrid/simdag.h"
15 #include "surf/surf.h"
16 #include "xbt/mallocator.h"
17 #include <stdbool.h>
18
19 SG_BEGIN_DECL()
20
21 /* Global variables */
22
23 typedef struct SD_global {
24   SD_workstation_t *workstation_list;   /* array of workstations, created only if
25                                            necessary in SD_workstation_get_list */
26   SD_link_t *link_list;         /* array of links, created only if
27                                    necessary in SD_link_get_list */
28   SD_link_t *recyclable_route;  /* array returned by SD_route_get_list
29                                    and mallocated only once */
30
31   xbt_mallocator_t task_mallocator; /* to not remalloc new tasks */
32
33   int watch_point_reached;      /* has a task just reached a watch point? */
34
35   xbt_dynar_t initial_task_set;
36   xbt_dynar_t executable_task_set;
37   xbt_dynar_t completed_task_set;
38
39   xbt_dynar_t return_set;
40   int task_number;
41
42 } s_SD_global_t, *SD_global_t;
43
44 extern XBT_PRIVATE SD_global_t sd_global;
45
46 /* Workstation */
47 typedef s_xbt_dictelm_t s_SD_workstation_t;
48 typedef struct SD_workstation {
49   e_SD_workstation_access_mode_t access_mode;
50
51   xbt_fifo_t task_fifo;         /* only used in sequential mode */
52   SD_task_t current_task;       /* only used in sequential mode */
53 } s_SD_workstation_priv_t, *SD_workstation_priv_t;
54
55 /* Storage */
56 typedef s_xbt_dictelm_t s_SD_storage_t;
57 typedef struct SD_storage {
58   void *data;                   /* user data */
59   const char *host;
60 } s_SD_storage_priv_t, *SD_storage_priv_t;
61
62 static inline SD_storage_priv_t SD_storage_priv(SD_storage_t storage){
63   return (SD_storage_priv_t)xbt_lib_get_level(storage, SD_STORAGE_LEVEL);
64 }
65
66 /* Task */
67 typedef struct SD_task {
68   e_SD_task_state_t state;
69   void *data;                   /* user data */
70   char *name;
71   e_SD_task_kind_t kind;
72   double amount;
73   double alpha;          /* used by typed parallel tasks */
74   double remains;
75   double start_time;
76   double finish_time;
77   surf_action_t surf_action;
78   unsigned short watch_points;  /* bit field xor()ed with masks */
79
80   int fifo_checked;             /* used by SD_task_just_done to make sure we evaluate
81                                    the task only once */
82   int marked;                   /* used to check if the task DAG has some cycle*/
83
84   /* dependencies */
85   xbt_dynar_t tasks_before;
86   xbt_dynar_t tasks_after;
87   int unsatisfied_dependencies;
88   unsigned int is_not_ready;
89
90   /* scheduling parameters (only exist in state SD_SCHEDULED) */
91   int workstation_nb;
92   SD_workstation_t *workstation_list;   /* surf workstations */
93   double *flops_amount;
94   double *bytes_amount;
95   double rate;
96
97   long long int counter;        /* task unique identifier for instrumentation */
98   char *category;               /* sd task category for instrumentation */
99 } s_SD_task_t;
100
101 /* Task dependencies */
102 typedef struct SD_dependency {
103   char *name;
104   void *data;
105   SD_task_t src;
106   SD_task_t dst;
107   /* src must be finished before dst can start */
108 } s_SD_dependency_t, *SD_dependency_t;
109
110 /* SimDag private functions */
111 XBT_PRIVATE SD_workstation_t __SD_workstation_create(const char* name);
112 XBT_PRIVATE void __SD_workstation_destroy(void *workstation);
113 XBT_PRIVATE int __SD_workstation_is_busy(SD_workstation_t workstation);
114
115 XBT_PRIVATE void SD_task_set_state(SD_task_t task, e_SD_task_state_t new_state);
116 XBT_PRIVATE void __SD_task_really_run(SD_task_t task);
117 XBT_PRIVATE void __SD_task_just_done(SD_task_t task);
118 XBT_PRIVATE int __SD_task_try_to_run(SD_task_t task);
119 XBT_PRIVATE bool acyclic_graph_detail(xbt_dynar_t dag);
120
121 /* Task mallocator functions */
122 XBT_PRIVATE void* SD_task_new_f(void);
123 XBT_PRIVATE void SD_task_recycle_f(void *t);
124 XBT_PRIVATE void SD_task_free_f(void *t);
125
126 /* Functions to test if the task is in a given state. */
127
128 /* Returns whether the given task is scheduled or runnable. */
129 static XBT_INLINE int __SD_task_is_scheduled_or_runnable(SD_task_t task)
130 {
131   return task->state == SD_SCHEDULED || task->state == SD_RUNNABLE;
132 }
133
134 /* Returns whether the given task is scheduled or runnable. */
135 static XBT_INLINE int __SD_task_is_schedulable_or_done(SD_task_t task)
136 {
137   return task->state == SD_SCHEDULABLE || task->state == SD_DONE;
138 }
139
140 /* Returns whether the state of the given task is SD_RUNNABLE or SD_IN_FIFO. */
141 static XBT_INLINE int __SD_task_is_runnable_or_in_fifo(SD_task_t task)
142 {
143   return task->state == SD_RUNNABLE || task->state == SD_IN_FIFO;
144 }
145
146 /********** Storage **********/
147 XBT_PRIVATE SD_storage_t __SD_storage_create(void *surf_storage, void *data);
148 XBT_PRIVATE void __SD_storage_destroy(void *storage);
149
150 /********** Tracing **********/
151 /* declaration of instrumentation functions from sd_task_instr.c */
152 XBT_PRIVATE void TRACE_sd_task_create(SD_task_t task);
153 XBT_PRIVATE void TRACE_sd_task_execute_start(SD_task_t task);
154 XBT_PRIVATE void TRACE_sd_task_execute_end(SD_task_t task);
155 XBT_PRIVATE void TRACE_sd_task_destroy(SD_task_t task);
156
157 SG_END_DECL()
158
159 #endif