3 /* Copyright (c) 2002,2004,2004 Arnaud Legrand. All rights reserved. */
5 /* This program is free software; you can redistribute it and/or modify it
6 * under the terms of the license (GNU LGPL) which comes with this package. */
8 #ifndef METASIMGRID_PRIVATE_H
9 #define METASIMGRID_PRIVATE_H
12 #include "surf/surf.h"
14 #include "xbt/dynar.h"
17 #include "xbt/context.h"
18 #include "xbt/config.h"
20 /**************** datatypes **********************************/
22 typedef struct simdata_host {
23 void *host; /* SURF modeling */
24 xbt_fifo_t *mbox; /* array of FIFOs used as a mailboxes */
25 m_process_t *sleeping; /* array of process used to know whether a local process is
26 waiting for a communication on a channel */
27 xbt_fifo_t process_list;
30 /********************************* Task **************************************/
32 typedef struct simdata_task {
33 surf_action_t compute; /* SURF modeling of computation */
34 surf_action_t comm; /* SURF modeling of communication */
35 double message_size; /* Data size */
36 double computation_amount; /* Computation size */
37 xbt_dynar_t sleeping; /* process to wake-up */
43 /******* Parallel Tasks Only !!!! *******/
45 void * *host_list; /* SURF modeling */
50 /******************************* Process *************************************/
52 typedef struct simdata_process {
53 m_host_t host; /* the host on which the process is running */
54 xbt_context_t context; /* the context that executes the scheduler fonction */
55 int PID; /* used for debugging purposes */
56 int PPID; /* The parent PID */
57 m_task_t waiting_task;
60 m_host_t put_host; /* used for debugging purposes */
61 m_channel_t put_channel; /* used for debugging purposes */
62 int argc; /* arguments number if any */
63 char **argv; /* arguments table if any */
64 MSG_error_t last_errno; /* the last value returned by a MSG_function */
65 int paje_state; /* the number of states stacked with Paje */
66 } s_simdata_process_t;
68 typedef struct process_arg {
70 m_process_code_t code;
76 } s_process_arg_t, *process_arg_t;
78 /************************** Global variables ********************************/
79 typedef struct MSG_Global {
81 xbt_fifo_t process_to_run;
82 xbt_fifo_t process_list;
84 m_process_t current_process;
85 xbt_dict_t registered_functions;
90 } s_MSG_Global_t, *MSG_Global_t;
92 extern MSG_Global_t msg_global;
94 /************************** Configuration support ********************************/
95 void msg_config_init(void); /* create the config set, call this before use! */
96 extern int _msg_init_status; /* 0: beginning of time;
97 1: pre-inited (cfg_set created);
98 2: inited (running) */
99 extern xbt_cfg_t _msg_cfg_set;
101 /*************************************************************/
103 #define PROCESS_SET_ERRNO(val) (MSG_process_self()->simdata->last_errno=val)
104 #define PROCESS_GET_ERRNO() (MSG_process_self()->simdata->last_errno)
105 #define MSG_RETURN(val) do {PROCESS_SET_ERRNO(val);return(val);} while(0)
106 /* #define CHECK_ERRNO() ASSERT((PROCESS_GET_ERRNO()!=MSG_HOST_FAILURE),"Host failed, you cannot call this function.") */
108 #define CHECK_HOST() xbt_assert0(surf_workstation_resource->extension_public-> \
109 get_state(MSG_host_self()->simdata->host)==SURF_CPU_ON,\
110 "Host failed, you cannot call this function.")
112 m_host_t __MSG_host_create(const char *name, void *workstation,
114 void __MSG_host_destroy(m_host_t host);
115 void __MSG_task_execute(m_process_t process, m_task_t task);
116 MSG_error_t __MSG_wait_for_computation(m_process_t process, m_task_t task);
117 MSG_error_t __MSG_task_wait_event(m_process_t process, m_task_t task);
119 int __MSG_process_block(double max_duration);
120 MSG_error_t __MSG_process_unblock(m_process_t process);
121 int __MSG_process_isBlocked(m_process_t process);
123 #ifdef ALVIN_SPECIAL_LOGING
124 #define PAJE_PROCESS_STATE(process,state)\
125 if(msg_global->paje_output) \
126 fprintf(msg_global->paje_output,"10 %g S_t P%d %s\n",\
127 surf_get_clock(), (process)->simdata->PID,(state))
128 #define PAJE_PROCESS_PUSH_STATE(process,state)\
129 if(msg_global->paje_output) { \
130 fprintf(msg_global->paje_output,"11 %g S_t P%d %s\n",\
131 surf_get_clock(), (process)->simdata->PID,(state));\
132 (process)->simdata->paje_state++; \
134 #define PAJE_PROCESS_POP_STATE(process)\
135 if(msg_global->paje_output) { \
136 fprintf(msg_global->paje_output,"12 %g S_t P%d\n",\
137 surf_get_clock(), (process)->simdata->PID); \
138 (process)->simdata->paje_state--; \
140 #define PAJE_PROCESS_FREE(process)
141 #define PAJE_PROCESS_NEW(process)\
142 if((msg_global->paje_output)) {\
143 if((msg_global->session==0) || ((msg_global->session>0) && ((process)->simdata->PID > msg_global->paje_maxPID))) \
144 fprintf(msg_global->paje_output,"7 %g P%d P_t %p \"%s %d (%d)\"\n", \
145 surf_get_clock(), (process)->simdata->PID, (process)->simdata->host, \
146 (process)->name, (process)->simdata->PID, msg_global->session);\
147 if(msg_global->paje_maxPID<(process)->simdata->PID) msg_global->paje_maxPID=(process)->simdata->PID;\
149 #define PAJE_COMM_START(process,task,channel)\
150 if(msg_global->paje_output) \
151 fprintf(msg_global->paje_output,\
152 "16 %g Comm CUR COMM_%d P%d %p\n", \
153 surf_get_clock(), channel, (process)->simdata->PID, task)
154 #define PAJE_COMM_STOP(process,task,channel)\
155 if(msg_global->paje_output) \
156 fprintf(msg_global->paje_output,\
157 "17 %g Comm CUR COMM_%d P%d %p\n", \
158 surf_get_clock(), channel, (process)->simdata->PID, task)
159 #define PAJE_HOST_NEW(host)\
160 if(msg_global->paje_output)\
161 fprintf(msg_global->paje_output,"7 %g %p H_t CUR \"%s\"\n",surf_get_clock(), \
163 #define PAJE_HOST_FREE(host)\
164 if(msg_global->paje_output)\
165 fprintf(msg_global->paje_output,"8 %g %p H_t\n",surf_get_clock(), host)
169 #define PAJE_PROCESS_STATE(process,state)\
170 if(msg_global->paje_output) \
171 fprintf(msg_global->paje_output,"10 %g S_t %p %s\n",\
172 surf_get_clock(), (process),(state))
173 #define PAJE_PROCESS_PUSH_STATE(process,state)\
174 if(msg_global->paje_output) \
175 fprintf(msg_global->paje_output,"11 %g S_t %p %s\n",\
176 surf_get_clock(), (process),(state))
177 #define PAJE_PROCESS_POP_STATE(process)\
178 if(msg_global->paje_output) \
179 fprintf(msg_global->paje_output,"12 %g S_t %p\n",\
180 surf_get_clock(), (process))
182 #define PAJE_PROCESS_FREE(process)\
183 if(msg_global->paje_output) \
184 fprintf(msg_global->paje_output,"8 %g %p P_t\n", \
185 surf_get_clock(), (process))
186 #define PAJE_PROCESS_NEW(process)\
187 if(msg_global->paje_output) \
188 fprintf(msg_global->paje_output,"7 %g %p P_t %p \"%s %d (%d)\"\n", \
189 surf_get_clock(), (process), (process)->simdata->host, \
190 (process)->name, (process)->simdata->PID, msg_global->session)
191 #define PAJE_COMM_START(process,task,channel)\
192 if(msg_global->paje_output) \
193 fprintf(msg_global->paje_output,\
194 "16 %g Comm CUR COMM_%d %p %p\n", \
195 surf_get_clock(), channel, (process), task)
196 #define PAJE_COMM_STOP(process,task,channel)\
197 if(msg_global->paje_output) \
198 fprintf(msg_global->paje_output,\
199 "17 %g Comm CUR COMM_%d %p %p\n", \
200 surf_get_clock(), channel, (process), task)
201 #define PAJE_HOST_NEW(host)\
202 if(msg_global->paje_output)\
203 fprintf(msg_global->paje_output,"7 %g %p H_t CUR \"%s\"\n",surf_get_clock(), \
205 #define PAJE_HOST_FREE(host)\
206 if(msg_global->paje_output)\
207 fprintf(msg_global->paje_output,"8 %g %p H_t\n",surf_get_clock(), host);
209 #endif /* Alvin_Special_Loging */