Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
change the way we identify opened files. The same process on the same
[simgrid.git] / src / msg / msg_private.h
1 /* Copyright (c) 2004-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 METASIMGRID_PRIVATE_H
8 #define METASIMGRID_PRIVATE_H
9
10 #include "simgrid/msg.h"
11 #include "simgrid/simix.h"
12 #include "surf/surf.h"
13 #include "xbt/fifo.h"
14 #include "xbt/dynar.h"
15 #include "xbt/swag.h"
16 #include "xbt/dict.h"
17 #include "xbt/config.h"
18 #include "instr/instr_private.h"
19 SG_BEGIN_DECL()
20
21 /**************** datatypes **********************************/
22
23 /********************************* Task **************************************/
24
25
26 #define MSG_BT(ptr, m)                              \
27   do {xbt_ex_t *_xbt_ex_t = xbt_new0(xbt_ex_t, 1); \
28   /* build the exception */                                             \
29   _xbt_ex_t->msg      = (bprintf(m));                                 \
30   _xbt_ex_t->category = (xbt_errcat_t)(0);                   \
31   _xbt_ex_t->value    = (0);                                 \
32   _xbt_ex_t->procname = (char*)xbt_procname();               \
33   _xbt_ex_t->pid      = xbt_getpid();                        \
34   _xbt_ex_t->file     = (char*)__FILE__;                     \
35   _xbt_ex_t->line     = __LINE__;                            \
36   _xbt_ex_t->func     = (char*)_XBT_FUNCTION;                \
37   _xbt_ex_t->bt_strings = NULL;                              \
38   xbt_backtrace_current(_xbt_ex_t); \
39   ptr = _xbt_ex_t; } while(0)
40
41 typedef struct simdata_task {
42   smx_synchro_t compute;         /* SIMIX modeling of computation */
43   smx_synchro_t comm;            /* SIMIX modeling of communication */
44   double bytes_amount;    /* Data size */
45   double flops_amount;    /* Computation size */
46   msg_process_t sender;
47   msg_process_t receiver;
48   msg_host_t source;
49   double priority;
50   double bound; /* Capping for CPU resource */
51   double rate;  /* Capping for network resource */
52
53   /* CPU affinity database of this task */
54   xbt_dict_t affinity_mask_db; /* smx_host_t host => unsigned long mask */
55
56   void *isused;  /* Indicates whether the task is used in SIMIX currently */
57   int host_nb;                  /* ==0 if sequential task; parallel task if not */
58   /*******  Parallel Tasks Only !!!! *******/
59   sg_host_t *host_list;
60   double *flops_parallel_amount;
61   double *bytes_parallel_amount;
62 } s_simdata_task_t;
63
64 /********************************* File **************************************/
65 typedef struct simdata_file {
66   smx_file_t smx_file;
67 } s_simdata_file_t;
68
69 int __MSG_host_get_file_descriptor_id(msg_host_t host);
70 void __MSG_host_release_file_descriptor_id(msg_host_t host, int id);
71
72 /*************** Begin GPU ***************/
73 typedef struct simdata_gpu_task {
74   double flops_amount;    /* Computation size */
75   double dispatch_latency;
76   double collect_latency;
77   int isused;  /* Indicates whether the task is used in SIMIX currently */
78 } s_simdata_gpu_task_t;
79 /*************** End GPU ***************/
80
81 /******************************* Process *************************************/
82
83 typedef struct simdata_process {
84   msg_host_t m_host;              /* the host on which the process is running */
85   msg_host_t put_host;            /* used for debugging purposes */
86 #ifdef MSG_USE_DEPRECATED
87   m_channel_t put_channel;      /* used for debugging purposes */
88 #endif
89   smx_synchro_t waiting_action;
90   msg_task_t waiting_task;
91   char **argv;                  /* arguments table if any */
92   int argc;                     /* arguments number if any */
93   msg_error_t last_errno;       /* the last value returned by a MSG_function */
94
95   void* data;                   /* user data */
96 } s_simdata_process_t, *simdata_process_t;
97
98 typedef struct process_arg {
99   const char *name;
100   xbt_main_func_t code;
101   void *data;
102   msg_host_t m_host;
103   int argc;
104   char **argv;
105   double kill_time;
106 } s_process_arg_t, *process_arg_t;
107
108 typedef struct msg_comm {
109   smx_synchro_t s_comm;          /* SIMIX communication object encapsulated (the same for both processes) */
110   msg_task_t task_sent;           /* task sent (NULL for the receiver) */
111   msg_task_t *task_received;      /* where the task will be received (NULL for the sender) */
112   msg_error_t status;           /* status of the communication once finished */
113 } s_msg_comm_t;
114
115
116 /******************************* VM *************************************/
117 typedef struct dirty_page {
118   double prev_clock;
119   double prev_remaining;
120   msg_task_t task;
121 } s_dirty_page, *dirty_page_t;
122
123 XBT_PUBLIC_DATA(const char*) MSG_vm_get_property_value(msg_vm_t vm, const char *name);
124 XBT_PUBLIC_DATA(xbt_dict_t) MSG_vm_get_properties(msg_vm_t vm);
125 XBT_PUBLIC_DATA(void) MSG_vm_set_property_value(msg_vm_t vm, const char *name, void *value, void_f_pvoid_t free_ctn);
126 XBT_PUBLIC_DATA(msg_vm_t) MSG_vm_get_by_name(const char *name);
127 XBT_PUBLIC_DATA(const char*) MSG_vm_get_name(msg_vm_t vm);
128
129 /************************** Global variables ********************************/
130 typedef struct MSG_Global {
131   xbt_fifo_t host;
132 #ifdef MSG_USE_DEPRECATED
133   int max_channel;
134 #endif
135   int session;
136   int debug_multiple_use;
137   unsigned long int sent_msg;   /* Total amount of messages sent during the simulation */
138   void (*task_copy_callback) (msg_task_t task, msg_process_t src, msg_process_t dst);
139   void_f_pvoid_t process_data_cleanup;
140 } s_MSG_Global_t, *MSG_Global_t;
141
142 /*extern MSG_Global_t msg_global;*/
143 XBT_PUBLIC_DATA(MSG_Global_t) msg_global;
144
145
146 /*************************************************************/
147
148 #ifdef MSG_USE_DEPRECATED
149 #  define PROCESS_SET_ERRNO(val) \
150   (((simdata_process_t) SIMIX_process_self_get_data(SIMIX_process_self()))->last_errno=val)
151 #  define PROCESS_GET_ERRNO() \
152   (((simdata_process_t) SIMIX_process_self_get_data(SIMIX_process_self()))->last_errno)
153 #define MSG_RETURN(val) do {PROCESS_SET_ERRNO(val);return(val);} while(0)
154 /* #define CHECK_ERRNO()  ASSERT((PROCESS_GET_ERRNO()!=MSG_HOST_FAILURE),"Host failed, you cannot call this function.") */
155
156 #else
157 #  define MSG_RETURN(val) return(val)
158 #endif
159
160 msg_host_t __MSG_host_create(sg_host_t host);
161 msg_storage_t __MSG_storage_create(smx_storage_t storage);
162 void __MSG_host_destroy(msg_host_t host);
163 void __MSG_host_priv_free(msg_host_priv_t priv);
164 void __MSG_storage_destroy(msg_storage_priv_t host);
165 void __MSG_file_destroy(msg_file_priv_t host);
166
167 void MSG_process_cleanup_from_SIMIX(smx_process_t smx_proc);
168 smx_process_t MSG_process_create_from_SIMIX(const char *name,
169                                    xbt_main_func_t code, void *data,
170                                    const char *hostname, double kill_time,
171                                    int argc, char **argv,
172                                    xbt_dict_t properties, int auto_restart,
173                                    smx_process_t parent_process);
174 void MSG_comm_copy_data_from_SIMIX(smx_synchro_t comm, void* buff, size_t buff_size);
175
176 void MSG_post_create_environment(void);
177
178 void MSG_host_add_task(msg_host_t host, msg_task_t task);
179 void MSG_host_del_task(msg_host_t host, msg_task_t task);
180
181 /********** Tracing **********/
182 /* declaration of instrumentation functions from msg_task_instr.c */
183 void TRACE_msg_set_task_category(msg_task_t task, const char *category);
184 void TRACE_msg_task_create(msg_task_t task);
185 void TRACE_msg_task_execute_start(msg_task_t task);
186 void TRACE_msg_task_execute_end(msg_task_t task);
187 void TRACE_msg_task_destroy(msg_task_t task);
188 void TRACE_msg_task_get_start(void);
189 void TRACE_msg_task_get_end(double start_time, msg_task_t task);
190 int TRACE_msg_task_put_start(msg_task_t task);    //returns TRUE if the task_put_end must be called
191 void TRACE_msg_task_put_end(void);
192
193 /* declaration of instrumentation functions from msg_process_instr.c */
194 char *instr_process_id (msg_process_t proc, char *str, int len);
195 char *instr_process_id_2 (const char *process_name, int process_pid, char *str, int len);
196 void TRACE_msg_process_change_host(msg_process_t process, msg_host_t old_host,
197                                    msg_host_t new_host);
198 void TRACE_msg_process_create (const char *process_name, int process_pid, msg_host_t host);
199 void TRACE_msg_process_destroy (const char *process_name, int process_pid, msg_host_t host);
200 void TRACE_msg_process_kill(smx_process_exit_status_t status, msg_process_t process);
201 void TRACE_msg_process_suspend(msg_process_t process);
202 void TRACE_msg_process_resume(msg_process_t process);
203 void TRACE_msg_process_sleep_in(msg_process_t process);   //called from msg/gos.c
204 void TRACE_msg_process_sleep_out(msg_process_t process);
205 void TRACE_msg_process_end(msg_process_t process);
206
207 /* declaration of instrumentation functions from instr_msg_vm.c */
208 char *instr_vm_id(msg_vm_t vm, char *str, int len);
209 char *instr_vm_id_2(const char *vm_name, char *str, int len);
210 void TRACE_msg_vm_change_host(msg_vm_t vm, msg_host_t old_host,
211                                    msg_host_t new_host);
212 void TRACE_msg_vm_start(msg_vm_t vm);
213 void TRACE_msg_vm_create(const char *vm_name, msg_host_t host);
214 void TRACE_msg_vm_kill(msg_vm_t process);
215 void TRACE_msg_vm_suspend(msg_vm_t vm);
216 void TRACE_msg_vm_resume(msg_vm_t vm);
217 void TRACE_msg_vm_save(msg_vm_t vm);
218 void TRACE_msg_vm_restore(msg_vm_t vm);
219 void TRACE_msg_vm_end(msg_vm_t vm);
220
221 SG_END_DECL()
222 #endif