1 /* Copyright (c) 2004-2014. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #ifndef METASIMGRID_PRIVATE_H
8 #define METASIMGRID_PRIVATE_H
10 #include "simgrid/msg.h"
11 #include "simgrid/simix.h"
12 #include "surf/surf.h"
14 #include "xbt/dynar.h"
17 #include "xbt/config.h"
18 #include "instr/instr_private.h"
21 /**************** datatypes **********************************/
23 /********************************* Task **************************************/
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)
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 */
47 msg_process_t receiver;
50 double bound; /* Capping for CPU resource */
51 double rate; /* Capping for network resource */
53 /* CPU affinity database of this task */
54 xbt_dict_t affinity_mask_db; /* smx_host_t host => unsigned long mask */
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 smx_host_t *host_list;
60 double *flops_parallel_amount;
61 double *bytes_parallel_amount;
64 /********************************* File **************************************/
65 typedef struct simdata_file {
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 ***************/
78 /******************************* Process *************************************/
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 */
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 */
92 void* data; /* user data */
93 } s_simdata_process_t, *simdata_process_t;
95 typedef struct process_arg {
103 } s_process_arg_t, *process_arg_t;
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 */
113 /******************************* VM *************************************/
114 typedef struct dirty_page {
116 double prev_remaining;
118 } s_dirty_page, *dirty_page_t;
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);
126 /************************** Global variables ********************************/
127 typedef struct MSG_Global {
129 #ifdef MSG_USE_DEPRECATED
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;
139 /*extern MSG_Global_t msg_global;*/
140 XBT_PUBLIC_DATA(MSG_Global_t) msg_global;
143 /*************************************************************/
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.") */
154 # define MSG_RETURN(val) return(val)
157 msg_host_t __MSG_host_create(smx_host_t workstation);
158 msg_storage_t __MSG_storage_create(smx_storage_t storage);
159 void __MSG_host_destroy(msg_host_t host);
160 void __MSG_storage_destroy(msg_storage_priv_t host);
161 void __MSG_file_destroy(msg_file_priv_t host);
163 void MSG_process_cleanup_from_SIMIX(smx_process_t smx_proc);
164 void MSG_process_create_from_SIMIX(smx_process_t *process, const char *name,
165 xbt_main_func_t code, void *data,
166 const char *hostname, double kill_time,
167 int argc, char **argv,
168 xbt_dict_t properties, int auto_restart,
169 smx_process_t parent_process);
170 void MSG_comm_copy_data_from_SIMIX(smx_synchro_t comm, void* buff, size_t buff_size);
172 void MSG_post_create_environment(void);
174 static inline void *msg_host_resource_priv(const void *host) {
175 return xbt_lib_get_level((void *)host, MSG_HOST_LEVEL);
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);
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);
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);
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);