Logo AND Algorithmique Numérique Distribuée

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