Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright notices
[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 /*************** Begin GPU ***************/
70 typedef struct simdata_gpu_task {
71   double flops_amount;    /* Computation size */
72   double dispatch_latency;
73   double collect_latency;
74   int isused;  /* Indicates whether the task is used in SIMIX currently */
75 } s_simdata_gpu_task_t;
76 /*************** End GPU ***************/
77
78 /******************************* Process *************************************/
79
80 typedef struct simdata_process {
81   msg_host_t m_host;              /* the host on which the process is running */
82   msg_host_t put_host;            /* used for debugging purposes */
83 #ifdef MSG_USE_DEPRECATED
84   m_channel_t put_channel;      /* used for debugging purposes */
85 #endif
86   smx_synchro_t waiting_action;
87   msg_task_t waiting_task;
88   char **argv;                  /* arguments table if any */
89   int argc;                     /* arguments number if any */
90   msg_error_t last_errno;       /* the last value returned by a MSG_function */
91
92   void* data;                   /* user data */
93 } s_simdata_process_t, *simdata_process_t;
94
95 typedef struct process_arg {
96   const char *name;
97   xbt_main_func_t code;
98   void *data;
99   msg_host_t m_host;
100   int argc;
101   char **argv;
102   double kill_time;
103 } s_process_arg_t, *process_arg_t;
104
105 typedef struct msg_comm {
106   smx_synchro_t s_comm;          /* SIMIX communication object encapsulated (the same for both processes) */
107   msg_task_t task_sent;           /* task sent (NULL for the receiver) */
108   msg_task_t *task_received;      /* where the task will be received (NULL for the sender) */
109   msg_error_t status;           /* status of the communication once finished */
110 } s_msg_comm_t;
111
112
113 /******************************* VM *************************************/
114 typedef struct dirty_page {
115   double prev_clock;
116   double prev_remaining;
117   msg_task_t task;
118 } s_dirty_page, *dirty_page_t;
119
120 XBT_PUBLIC_DATA(const char*) MSG_vm_get_property_value(msg_vm_t vm, const char *name);
121 XBT_PUBLIC_DATA(xbt_dict_t) MSG_vm_get_properties(msg_vm_t vm);
122 XBT_PUBLIC_DATA(void) MSG_vm_set_property_value(msg_vm_t vm, const char *name, void *value, void_f_pvoid_t free_ctn);
123 XBT_PUBLIC_DATA(msg_vm_t) MSG_vm_get_by_name(const char *name);
124 XBT_PUBLIC_DATA(const char*) MSG_vm_get_name(msg_vm_t vm);
125
126 /************************** Global variables ********************************/
127 typedef struct MSG_Global {
128   xbt_fifo_t host;
129 #ifdef MSG_USE_DEPRECATED
130   int max_channel;
131 #endif
132   int session;
133   int debug_multiple_use;
134   unsigned long int sent_msg;   /* Total amount of messages sent during the simulation */
135   void (*task_copy_callback) (msg_task_t task, msg_process_t src, msg_process_t dst);
136   void_f_pvoid_t process_data_cleanup;
137 } s_MSG_Global_t, *MSG_Global_t;
138
139 /*extern MSG_Global_t msg_global;*/
140 XBT_PUBLIC_DATA(MSG_Global_t) msg_global;
141
142
143 /*************************************************************/
144
145 #ifdef MSG_USE_DEPRECATED
146 #  define PROCESS_SET_ERRNO(val) \
147   (((simdata_process_t) SIMIX_process_self_get_data(SIMIX_process_self()))->last_errno=val)
148 #  define PROCESS_GET_ERRNO() \
149   (((simdata_process_t) SIMIX_process_self_get_data(SIMIX_process_self()))->last_errno)
150 #define MSG_RETURN(val) do {PROCESS_SET_ERRNO(val);return(val);} while(0)
151 /* #define CHECK_ERRNO()  ASSERT((PROCESS_GET_ERRNO()!=MSG_HOST_FAILURE),"Host failed, you cannot call this function.") */
152
153 #else
154 #  define MSG_RETURN(val) return(val)
155 #endif
156
157 msg_host_t __MSG_host_create(sg_host_t host);
158 msg_storage_t __MSG_storage_create(smx_storage_t storage);
159 void __MSG_host_destroy(msg_host_t host);
160 void __MSG_host_priv_free(msg_host_priv_t priv);
161 void __MSG_storage_destroy(msg_storage_priv_t host);
162 void __MSG_file_destroy(msg_file_priv_t host);
163
164 void MSG_process_cleanup_from_SIMIX(smx_process_t smx_proc);
165 smx_process_t MSG_process_create_from_SIMIX(const char *name,
166                                    xbt_main_func_t code, void *data,
167                                    const char *hostname, double kill_time,
168                                    int argc, char **argv,
169                                    xbt_dict_t properties, int auto_restart,
170                                    smx_process_t parent_process);
171 void MSG_comm_copy_data_from_SIMIX(smx_synchro_t comm, void* buff, size_t buff_size);
172
173 void MSG_post_create_environment(void);
174
175 void MSG_host_add_task(msg_host_t host, msg_task_t task);
176 void MSG_host_del_task(msg_host_t host, msg_task_t task);
177
178 /********** Tracing **********/
179 /* declaration of instrumentation functions from msg_task_instr.c */
180 void TRACE_msg_set_task_category(msg_task_t task, const char *category);
181 void TRACE_msg_task_create(msg_task_t task);
182 void TRACE_msg_task_execute_start(msg_task_t task);
183 void TRACE_msg_task_execute_end(msg_task_t task);
184 void TRACE_msg_task_destroy(msg_task_t task);
185 void TRACE_msg_task_get_start(void);
186 void TRACE_msg_task_get_end(double start_time, msg_task_t task);
187 int TRACE_msg_task_put_start(msg_task_t task);    //returns TRUE if the task_put_end must be called
188 void TRACE_msg_task_put_end(void);
189
190 /* declaration of instrumentation functions from msg_process_instr.c */
191 char *instr_process_id (msg_process_t proc, char *str, int len);
192 char *instr_process_id_2 (const char *process_name, int process_pid, char *str, int len);
193 void TRACE_msg_process_change_host(msg_process_t process, msg_host_t old_host,
194                                    msg_host_t new_host);
195 void TRACE_msg_process_create (const char *process_name, int process_pid, msg_host_t host);
196 void TRACE_msg_process_destroy (const char *process_name, int process_pid, msg_host_t host);
197 void TRACE_msg_process_kill(smx_process_exit_status_t status, msg_process_t process);
198 void TRACE_msg_process_suspend(msg_process_t process);
199 void TRACE_msg_process_resume(msg_process_t process);
200 void TRACE_msg_process_sleep_in(msg_process_t process);   //called from msg/gos.c
201 void TRACE_msg_process_sleep_out(msg_process_t process);
202 void TRACE_msg_process_end(msg_process_t process);
203
204 /* declaration of instrumentation functions from instr_msg_vm.c */
205 char *instr_vm_id(msg_vm_t vm, char *str, int len);
206 char *instr_vm_id_2(const char *vm_name, char *str, int len);
207 void TRACE_msg_vm_change_host(msg_vm_t vm, msg_host_t old_host,
208                                    msg_host_t new_host);
209 void TRACE_msg_vm_start(msg_vm_t vm);
210 void TRACE_msg_vm_create(const char *vm_name, msg_host_t host);
211 void TRACE_msg_vm_kill(msg_vm_t process);
212 void TRACE_msg_vm_suspend(msg_vm_t vm);
213 void TRACE_msg_vm_resume(msg_vm_t vm);
214 void TRACE_msg_vm_save(msg_vm_t vm);
215 void TRACE_msg_vm_restore(msg_vm_t vm);
216 void TRACE_msg_vm_end(msg_vm_t vm);
217
218 SG_END_DECL()
219 #endif