Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge cpu_update_actions_state_lazy and net_update_actions_state_lazy
[simgrid.git] / src / surf / surf_private.h
1 /* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. 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 #ifndef _SURF_SURF_PRIVATE_H
7 #define _SURF_SURF_PRIVATE_H
8
9 #include "surf/surf.h"
10 #include "surf/maxmin.h"
11 #include "surf/trace_mgr.h"
12 #include "xbt/log.h"
13 #include "surf/surfxml_parse.h"
14 #include "surf/random_mgr.h"
15 #include "instr/instr_private.h"
16 #include "surf/surfxml_parse_values.h"
17
18 #define NO_MAX_DURATION -1.0
19
20 /* user-visible parameters */
21 extern double sg_tcp_gamma;
22 extern double sg_sender_gap;
23 extern double sg_latency_factor;
24 extern double sg_bandwidth_factor;
25 extern double sg_weight_S_parameter;
26 extern int sg_maxmin_selective_update;
27 extern int sg_network_crosstraffic;
28 #ifdef HAVE_GTNETS
29 extern double sg_gtnets_jitter;
30 extern int sg_gtnets_jitter_seed;
31 #endif
32
33
34 extern const char *surf_action_state_names[6];
35
36 typedef enum {
37   UM_FULL,
38   UM_LAZY,
39   UM_UNDEFINED
40 } e_UM_t;
41
42 typedef struct surf_model_private {
43   int (*resource_used) (void *resource_id);
44   /* Share the resources to the actions and return in how much time
45      the next action may terminate */
46   double (*share_resources) (double now);
47   /* Update the actions' state */
48   void (*update_actions_state) (double now, double delta);
49   void (*update_resource_state) (void *id, tmgr_trace_event_t event_type,
50                                  double value, double time);
51   void (*finalize) (void);
52
53   lmm_system_t maxmin_system;
54   e_UM_t update_mechanism;
55   xbt_swag_t modified_set;
56   xbt_heap_t action_heap;
57   int selective_update;
58
59 } s_surf_model_private_t;
60
61 double generic_maxmin_share_resources(xbt_swag_t running_actions,
62                                       size_t offset,
63                                       lmm_system_t sys,
64                                       void (*solve) (lmm_system_t));
65 double generic_share_resources_lazy(double now, surf_model_t model);
66
67 /* Generic functions common to all models */
68 void surf_action_init(void);
69 void surf_action_exit(void);
70 e_surf_action_state_t surf_action_state_get(surf_action_t action);      /* cannot declare inline since we use a pointer to it */
71 double surf_action_get_start_time(surf_action_t action);        /* cannot declare inline since we use a pointer to it */
72 double surf_action_get_finish_time(surf_action_t action);       /* cannot declare inline since we use a pointer to it */
73 void surf_action_free(surf_action_t * action);
74 void surf_action_state_set(surf_action_t action,
75                            e_surf_action_state_t state);
76 void surf_action_data_set(surf_action_t action, void *data);    /* cannot declare inline since we use a pointer to it */
77
78 void surf_action_lmm_update_index_heap(void *action, int i); /* callback for heap management shared by cpu and net models */
79 void surf_action_lmm_heap_insert(xbt_heap_t heap, surf_action_lmm_t action,
80     double key, enum heap_action_type hat);
81 void surf_action_lmm_heap_remove(xbt_heap_t heap,surf_action_lmm_t action);
82
83 void surf_action_cancel(surf_action_t action);
84 int surf_action_unref(surf_action_t action);
85 void surf_action_suspend(surf_action_t action);
86 void surf_action_resume(surf_action_t action);
87 int surf_action_is_suspended(surf_action_t action);
88 void surf_action_set_max_duration(surf_action_t action, double duration);
89 void surf_action_set_priority(surf_action_t action, double priority);
90 #ifdef HAVE_TRACING
91 void surf_action_set_category(surf_action_t action,
92                                     const char *category);
93 #endif
94 double surf_action_get_remains(surf_action_t action);
95 void generic_update_action_remaining_lazy( surf_action_lmm_t action, double now);
96 void generic_update_actions_state_lazy(double now, double delta, surf_model_t model);
97
98 FILE *surf_fopen(const char *name, const char *mode);
99
100 extern tmgr_history_t history;
101 extern xbt_dynar_t surf_path;
102
103 void surf_config_init(int *argc, char **argv);
104 void surf_config_finalize(void);
105 void surf_config(const char *name, va_list pa);
106
107 void net_action_recycle(surf_action_t action);
108 double net_action_get_remains(surf_action_t action);
109 #ifdef HAVE_LATENCY_BOUND_TRACKING
110 int net_get_link_latency_limited(surf_action_t action);
111 #endif
112
113 /*
114  * Returns the initial path. On Windows the initial path is
115  * the current directory for the current process in the other
116  * case the function returns "./" that represents the current
117  * directory on Unix/Linux platforms.
118  */
119 const char *__surf_get_initial_path(void);
120
121 /* The __surf_is_absolute_file_path() returns 1 if
122  * file_path is a absolute file path, in the other
123  * case the function returns 0.
124  */
125 int __surf_is_absolute_file_path(const char *file_path);
126
127 typedef struct s_as *AS_t;
128 typedef struct s_routing_edge {
129   AS_t rc_component;
130   e_surf_network_element_type_t rc_type;
131   int id;
132   char *name;
133 } s_network_element_t;
134
135 /*
136  * Link of lenght 1, alongside with its source and destination. This is mainly usefull in the bindings to gtnets and ns3
137  */
138 typedef struct s_onelink {
139   sg_routing_edge_t src;
140   sg_routing_edge_t dst;
141   void *link_ptr;
142 } s_onelink_t, *onelink_t;
143
144 /**
145  * Routing logic
146  */
147
148 typedef struct s_model_type {
149   const char *name;
150   const char *desc;
151   AS_t (*create) ();
152   void (*end) (AS_t as);
153 } s_routing_model_description_t, *routing_model_description_t;
154
155 typedef struct s_route {
156   xbt_dynar_t link_list;
157   sg_routing_edge_t src_gateway;
158   sg_routing_edge_t dst_gateway;
159 } s_route_t, *route_t;
160
161 /* This enum used in the routing structure helps knowing in which situation we are. */
162 typedef enum {
163   SURF_ROUTING_NULL = 0,   /**< Undefined type                                   */
164   SURF_ROUTING_BASE,       /**< Base case: use simple link lists for routing     */
165   SURF_ROUTING_RECURSIVE   /**< Recursive case: also return gateway informations */
166 } e_surf_routing_hierarchy_t;
167
168 typedef struct s_as {
169   xbt_dynar_t index_network_elm;
170   xbt_dict_t bypassRoutes;              /* store bypass routes */
171   routing_model_description_t model_desc;
172   e_surf_routing_hierarchy_t hierarchy;
173   char *name;
174   struct s_as *routing_father;
175   xbt_dict_t routing_sons;
176   sg_routing_edge_t net_elem;
177   xbt_dynar_t link_up_down_list;
178
179   void (*get_route_and_latency) (AS_t as, sg_routing_edge_t src, sg_routing_edge_t dst, route_t into, double *latency);
180
181   xbt_dynar_t(*get_onelink_routes) (AS_t as);
182   route_t(*get_bypass_route) (AS_t as, sg_routing_edge_t src, sg_routing_edge_t dst, double *lat);
183   void (*finalize) (AS_t as);
184
185
186   /* The parser calls the following functions to inform the routing models
187    * that a new element is added to the AS currently built.
188    *
189    * Of course, only the routing model of this AS is informed, not every ones */
190   int (*parse_PU) (AS_t as, sg_routing_edge_t elm); /* A host or a router, whatever */
191   int (*parse_AS) (AS_t as, sg_routing_edge_t elm);
192   void (*parse_route) (AS_t as, const char *src,
193                      const char *dst, route_t route);
194   void (*parse_ASroute) (AS_t as, const char *src,
195                        const char *dst, route_t route);
196   void (*parse_bypassroute) (AS_t as, const char *src,
197                            const char *dst, route_t e_route);
198 } s_as_t;
199
200 struct s_routing_platf {
201   AS_t root;
202   void *loopback;
203   xbt_dynar_t last_route;
204   xbt_dynar_t(*get_onelink_routes) (void);
205 };
206
207 XBT_PUBLIC(void) routing_model_create(void *loopback);
208 XBT_PUBLIC(void) routing_exit(void);
209 XBT_PUBLIC(void) storage_register_callbacks(void);
210 XBT_PUBLIC(void) routing_register_callbacks(void);
211 XBT_PUBLIC(void) generic_free_route(route_t route); // FIXME rename to routing_route_free
212  // FIXME: make previous function private to routing again?
213
214
215 XBT_PUBLIC(void) routing_get_route_and_latency(sg_routing_edge_t src, sg_routing_edge_t dst,
216                               xbt_dynar_t * route, double *latency);
217
218 /**
219  * Resource protected methods
220  */
221 static XBT_INLINE xbt_dict_t surf_resource_properties(const void *resource);
222
223 XBT_PUBLIC(void) surfxml_bufferstack_push(int new);
224 XBT_PUBLIC(void) surfxml_bufferstack_pop(int new);
225
226 XBT_PUBLIC_DATA(int) surfxml_bufferstack_size;
227
228 #endif                          /* _SURF_SURF_PRIVATE_H */