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"
19 /**************** datatypes **********************************/
21 typedef struct simdata_host {
22 void *host; /* SURF modeling */
23 xbt_fifo_t *mbox; /* array of FIFOs used as a mailboxes */
24 m_process_t *sleeping; /* array of process used to know whether a local process is
25 waiting for a communication on a channel */
26 xbt_fifo_t process_list;
29 /********************************* Task **************************************/
31 typedef struct simdata_task {
32 surf_action_t compute; /* SURF modeling of computation */
33 surf_action_t comm; /* SURF modeling of communication */
34 double message_size; /* Data size */
35 double computation_amount; /* Computation size */
36 xbt_dynar_t sleeping; /* process to wake-up */
42 /******************************* Process *************************************/
44 typedef struct simdata_process {
45 m_host_t host; /* the host on which the process is running */
46 xbt_context_t context; /* the context that executes the scheduler fonction */
47 int PID; /* used for debugging purposes */
48 int PPID; /* The parent PID */
49 m_task_t waiting_task;
52 m_host_t put_host; /* used for debugging purposes */
53 m_channel_t put_channel; /* used for debugging purposes */
54 int argc; /* arguments number if any */
55 char **argv; /* arguments table if any */
56 MSG_error_t last_errno; /* the last value returned by a MSG_function */
57 int paje_state; /* the number of state stacked with Paje */
58 } s_simdata_process_t;
60 /************************** Global variables ********************************/
61 typedef struct MSG_Global {
63 xbt_fifo_t process_to_run;
64 xbt_fifo_t process_list;
66 m_process_t current_process;
67 xbt_dict_t registered_functions;
72 } s_MSG_Global_t, *MSG_Global_t;
74 extern MSG_Global_t msg_global;
76 /*************************************************************/
78 #define PROCESS_SET_ERRNO(val) (MSG_process_self()->simdata->last_errno=val)
79 #define PROCESS_GET_ERRNO() (MSG_process_self()->simdata->last_errno)
80 #define MSG_RETURN(val) do {PROCESS_SET_ERRNO(val);return(val);} while(0)
81 /* #define CHECK_ERRNO() ASSERT((PROCESS_GET_ERRNO()!=MSG_HOST_FAILURE),"Host failed, you cannot call this function.") */
83 #define CHECK_HOST() xbt_assert0(surf_workstation_resource->extension_public-> \
84 get_state(MSG_host_self()->simdata->host)==SURF_CPU_ON,\
85 "Host failed, you cannot call this function.")
87 m_host_t __MSG_host_create(const char *name, void *workstation,
89 void __MSG_host_destroy(m_host_t host);
90 void __MSG_task_execute(m_process_t process, m_task_t task);
91 MSG_error_t __MSG_wait_for_computation(m_process_t process, m_task_t task);
92 MSG_error_t __MSG_task_wait_event(m_process_t process, m_task_t task);
94 MSG_error_t __MSG_process_block(void);
95 MSG_error_t __MSG_process_unblock(m_process_t process);
96 int __MSG_process_isBlocked(m_process_t process);
98 #ifdef ALVIN_SPECIAL_LOGING
99 #define PAJE_PROCESS_STATE(process,state)\
100 if(msg_global->paje_output) \
101 fprintf(msg_global->paje_output,"10 %lg S_t P%d %s\n",\
102 surf_get_clock(), (process)->simdata->PID,(state))
103 #define PAJE_PROCESS_PUSH_STATE(process,state)\
104 if(msg_global->paje_output) { \
105 fprintf(msg_global->paje_output,"11 %lg S_t P%d %s\n",\
106 surf_get_clock(), (process)->simdata->PID,(state));\
107 (process)->simdata->paje_state++; \
109 #define PAJE_PROCESS_POP_STATE(process)\
110 if(msg_global->paje_output) { \
111 fprintf(msg_global->paje_output,"12 %lg S_t P%d\n",\
112 surf_get_clock(), (process)->simdata->PID); \
113 (process)->simdata->paje_state--; \
115 #define PAJE_PROCESS_FREE(process)
116 #define PAJE_PROCESS_NEW(process)\
117 if((msg_global->paje_output)) {\
118 if((msg_global->session==0) || ((msg_global->session>0) && ((process)->simdata->PID > msg_global->paje_maxPID))) \
119 fprintf(msg_global->paje_output,"7 %lg P%d P_t %p \"%s %d (%d)\"\n", \
120 surf_get_clock(), (process)->simdata->PID, (process)->simdata->host, \
121 (process)->name, (process)->simdata->PID, msg_global->session);\
122 if(msg_global->paje_maxPID<(process)->simdata->PID) msg_global->paje_maxPID=(process)->simdata->PID;\
124 #define PAJE_COMM_START(process,task,channel)\
125 if(msg_global->paje_output) \
126 fprintf(msg_global->paje_output,\
127 "16 %lg Comm CUR COMM_%d P%d %p\n", \
128 surf_get_clock(), channel, (process)->simdata->PID, task)
129 #define PAJE_COMM_STOP(process,task,channel)\
130 if(msg_global->paje_output) \
131 fprintf(msg_global->paje_output,\
132 "17 %lg Comm CUR COMM_%d P%d %p\n", \
133 surf_get_clock(), channel, (process)->simdata->PID, task)
134 #define PAJE_HOST_NEW(host)\
135 if(msg_global->paje_output)\
136 fprintf(msg_global->paje_output,"7 %lg %p H_t CUR \"%s\"\n",surf_get_clock(), \
138 #define PAJE_HOST_FREE(host)\
139 if(msg_global->paje_output)\
140 fprintf(msg_global->paje_output,"8 %lg %p H_t\n",surf_get_clock(), host)
144 #define PAJE_PROCESS_STATE(process,state)\
145 if(msg_global->paje_output) \
146 fprintf(msg_global->paje_output,"10 %lg S_t %p %s\n",\
147 surf_get_clock(), (process),(state))
148 #define PAJE_PROCESS_PUSH_STATE(process,state)\
149 if(msg_global->paje_output) \
150 fprintf(msg_global->paje_output,"11 %lg S_t %p %s\n",\
151 surf_get_clock(), (process),(state))
152 #define PAJE_PROCESS_POP_STATE(process)\
153 if(msg_global->paje_output) \
154 fprintf(msg_global->paje_output,"12 %lg S_t %p\n",\
155 surf_get_clock(), (process))
157 #define PAJE_PROCESS_FREE(process)\
158 if(msg_global->paje_output) \
159 fprintf(msg_global->paje_output,"8 %lg %p P_t\n", \
160 surf_get_clock(), (process))
161 #define PAJE_PROCESS_NEW(process)\
162 if(msg_global->paje_output) \
163 fprintf(msg_global->paje_output,"7 %lg %p P_t %p \"%s %d (%d)\"\n", \
164 surf_get_clock(), (process), (process)->simdata->host, \
165 (process)->name, (process)->simdata->PID, msg_global->session)
166 #define PAJE_COMM_START(process,task,channel)\
167 if(msg_global->paje_output) \
168 fprintf(msg_global->paje_output,\
169 "16 %lg Comm CUR COMM_%d %p %p\n", \
170 surf_get_clock(), channel, (process), task)
171 #define PAJE_COMM_STOP(process,task,channel)\
172 if(msg_global->paje_output) \
173 fprintf(msg_global->paje_output,\
174 "17 %lg Comm CUR COMM_%d %p %p\n", \
175 surf_get_clock(), channel, (process), task)
176 #define PAJE_HOST_NEW(host)\
177 if(msg_global->paje_output)\
178 fprintf(msg_global->paje_output,"7 %lg %p H_t CUR \"%s\"\n",surf_get_clock(), \
180 #define PAJE_HOST_FREE(host)\
181 if(msg_global->paje_output)\
182 fprintf(msg_global->paje_output,"8 %lg %p H_t\n",surf_get_clock(), host);
184 #endif /* Alvin_Special_Loging */