Logo AND Algorithmique Numérique Distribuée

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