Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use a mallocator for MSG tasks
[simgrid.git] / src / msg / private.h
1 /*      $Id$     */
2
3 /* Copyright (c) 2002,2004,2004 Arnaud Legrand. All rights reserved.        */
4
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. */
7
8 #ifndef METASIMGRID_PRIVATE_H
9 #define METASIMGRID_PRIVATE_H
10
11 #include "msg/msg.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/context.h"
18 #include "xbt/config.h"
19 #include "xbt/mallocator.h"
20
21 /**************** datatypes **********************************/
22
23 typedef struct simdata_host {
24   void *host;                   /* SURF modeling */
25   xbt_fifo_t *mbox;             /* array of FIFOs used as a mailboxes  */
26   m_process_t *sleeping;        /* array of process used to know whether a local process is
27                                    waiting for a communication on a channel */
28   xbt_fifo_t process_list;
29 } s_simdata_host_t;
30
31 /********************************* Task **************************************/
32
33 typedef struct simdata_task {
34   surf_action_t compute;        /* SURF modeling of computation  */
35   surf_action_t comm;           /* SURF modeling of communication  */
36   double message_size;          /* Data size  */
37   double computation_amount;    /* Computation size  */
38   xbt_dynar_t sleeping;         /* process to wake-up */
39   m_process_t sender;
40   m_host_t source;
41   double priority;
42   double rate;
43   int using;
44   /*******  Parallel Tasks Only !!!! *******/
45   int host_nb;
46   void * *host_list;            /* SURF modeling */
47   double *comp_amount;
48   double *comm_amount;
49 } s_simdata_task_t;
50
51 /******************************* Process *************************************/
52
53 typedef struct simdata_process {
54   m_host_t host;                /* the host on which the process is running */
55   xbt_context_t context;                /* the context that executes the scheduler fonction */
56   int PID;                      /* used for debugging purposes */
57   int PPID;                     /* The parent PID */
58   m_task_t waiting_task;        
59   int blocked;
60   int suspended;
61   m_host_t put_host;            /* used for debugging purposes */
62   m_channel_t put_channel;      /* used for debugging purposes */
63   int argc;                     /* arguments number if any */
64   char **argv;                  /* arguments table if any */
65   MSG_error_t last_errno;       /* the last value returned by a MSG_function */
66   int paje_state;               /* the number of states stacked with Paje */
67 } s_simdata_process_t;
68
69 typedef struct process_arg {
70   const char *name;
71   m_process_code_t code;
72   void *data;
73   m_host_t host;
74   int argc;
75   char **argv;
76   double kill_time;
77 } s_process_arg_t, *process_arg_t;
78
79 /************************** Global variables ********************************/
80 typedef struct MSG_Global {
81   xbt_fifo_t host;
82   xbt_fifo_t process_to_run;
83   xbt_fifo_t process_list;
84   int max_channel;
85   m_process_t current_process;
86   xbt_dict_t registered_functions;
87   FILE *paje_output;
88   int paje_maxPID;
89   int PID;
90   int session;
91   xbt_mallocator_t task_mallocator;
92   xbt_mallocator_t task_simdata_mallocator;
93 } s_MSG_Global_t, *MSG_Global_t;
94
95 extern MSG_Global_t msg_global;
96       
97 /************************** Configuration support ********************************/
98 void msg_config_init(void); /* create the config set, call this before use! */
99 void msg_config_finalize(void); /* destroy the config set, call this at cleanup. */
100 extern int _msg_init_status; /* 0: beginning of time; 
101                                 1: pre-inited (cfg_set created); 
102                                 2: inited (running) */
103 extern xbt_cfg_t _msg_cfg_set;
104
105 /*************************************************************/
106
107 #define PROCESS_SET_ERRNO(val) (MSG_process_self()->simdata->last_errno=val)
108 #define PROCESS_GET_ERRNO() (MSG_process_self()->simdata->last_errno)
109 #define MSG_RETURN(val) do {PROCESS_SET_ERRNO(val);return(val);} while(0)
110 /* #define CHECK_ERRNO()  ASSERT((PROCESS_GET_ERRNO()!=MSG_HOST_FAILURE),"Host failed, you cannot call this function.") */
111
112 #define CHECK_HOST()  xbt_assert0(surf_workstation_resource->extension_public-> \
113                                   get_state(MSG_host_self()->simdata->host)==SURF_CPU_ON,\
114                                   "Host failed, you cannot call this function.")
115
116 m_host_t __MSG_host_create(const char *name, void *workstation,
117                            void *data);
118 void __MSG_host_destroy(m_host_t host);
119 void __MSG_task_execute(m_process_t process, m_task_t task);
120 MSG_error_t __MSG_wait_for_computation(m_process_t process, m_task_t task);
121 MSG_error_t __MSG_task_wait_event(m_process_t process, m_task_t task);
122
123 int __MSG_process_block(double max_duration, const char *info);
124 MSG_error_t __MSG_process_unblock(m_process_t process);
125 int __MSG_process_isBlocked(m_process_t process);
126
127 void __MSG_display_process_status(void);
128
129 m_task_t task_mallocator_new_f(void);
130 void task_mallocator_free_f(m_task_t task);
131 void task_mallocator_reset_f(m_task_t task);
132
133 #ifdef ALVIN_SPECIAL_LOGING
134 #define PAJE_PROCESS_STATE(process,state)\
135   if(msg_global->paje_output) \
136     fprintf(msg_global->paje_output,"10 %f S_t P%d %s\n",\
137             surf_get_clock(), (process)->simdata->PID,(state))
138 #define PAJE_PROCESS_PUSH_STATE(process,state)\
139   if(msg_global->paje_output) { \
140     fprintf(msg_global->paje_output,"11 %f S_t P%d %s\n",\
141             surf_get_clock(), (process)->simdata->PID,(state));\
142     (process)->simdata->paje_state++; \
143   }
144 #define PAJE_PROCESS_POP_STATE(process)\
145   if(msg_global->paje_output) { \
146     fprintf(msg_global->paje_output,"12 %f S_t P%d\n",\
147             surf_get_clock(), (process)->simdata->PID); \
148     (process)->simdata->paje_state--; \
149   }
150 #define PAJE_PROCESS_FREE(process)
151 #define PAJE_PROCESS_NEW(process)\
152   if((msg_global->paje_output)) {\
153     if((msg_global->session==0) || ((msg_global->session>0) && ((process)->simdata->PID > msg_global->paje_maxPID))) \
154     fprintf(msg_global->paje_output,"7 %f P%d P_t %p \"%s %d (%d)\"\n", \
155             surf_get_clock(), (process)->simdata->PID, (process)->simdata->host, \
156             (process)->name, (process)->simdata->PID, msg_global->session);\
157     if(msg_global->paje_maxPID<(process)->simdata->PID) msg_global->paje_maxPID=(process)->simdata->PID;\
158     }
159 #define PAJE_COMM_START(process,task,channel)\
160   if(msg_global->paje_output) \
161     fprintf(msg_global->paje_output,\
162             "16 %f      Comm    CUR     COMM_%d P%d     %p\n", \
163             surf_get_clock(), channel, (process)->simdata->PID, task)
164 #define PAJE_COMM_STOP(process,task,channel)\
165   if(msg_global->paje_output) \
166     fprintf(msg_global->paje_output,\
167             "17 %f      Comm    CUR     COMM_%d P%d     %p\n", \
168             surf_get_clock(), channel, (process)->simdata->PID, task)
169 #define PAJE_HOST_NEW(host)\
170   if(msg_global->paje_output)\
171     fprintf(msg_global->paje_output,"7 %f %p H_t CUR \"%s\"\n",surf_get_clock(), \
172             host, host->name)
173 #define PAJE_HOST_FREE(host)\
174   if(msg_global->paje_output)\
175     fprintf(msg_global->paje_output,"8 %f %p H_t\n",surf_get_clock(), host)
176
177 #else
178
179 #define PAJE_PROCESS_STATE(process,state)\
180   if(msg_global->paje_output) \
181     fprintf(msg_global->paje_output,"10 %f S_t %p %s\n",\
182             surf_get_clock(), (process),(state))
183 #define PAJE_PROCESS_PUSH_STATE(process,state,task)\
184   if(msg_global->paje_output) \
185     fprintf(msg_global->paje_output,"11 %f S_t %p %s \"%s\"\n",\
186             surf_get_clock(), (process),(state),(task)?((m_task_t)(task))->name:"")
187 #define PAJE_PROCESS_POP_STATE(process)\
188   if(msg_global->paje_output) \
189     fprintf(msg_global->paje_output,"12 %f S_t %p\n",\
190             surf_get_clock(), (process))
191
192 #define PAJE_PROCESS_FREE(process)\
193   if(msg_global->paje_output) \
194     fprintf(msg_global->paje_output,"8 %f %p P_t\n", \
195             surf_get_clock(), (process))
196 #define PAJE_PROCESS_NEW(process)\
197   if(msg_global->paje_output) \
198     fprintf(msg_global->paje_output,"7 %f %p P_t %p \"%s %d (%d)\"\n", \
199             surf_get_clock(), (process), (process)->simdata->host, \
200             (process)->name, (process)->simdata->PID, msg_global->session)
201 #define PAJE_COMM_START(process,task,channel)\
202   if(msg_global->paje_output) \
203     fprintf(msg_global->paje_output,\
204             "16 %f      Comm    CUR     \"CHANNEL_%d %s\"       %p      %p\n", \
205             surf_get_clock(), channel, task->name, (process), task)
206 #define PAJE_COMM_STOP(process,task,channel)\
207   if(msg_global->paje_output) \
208     fprintf(msg_global->paje_output,\
209             "17 %f      Comm    CUR     \"CHANNEL_%d %s\"       %p      %p\n", \
210             surf_get_clock(), channel, task->name, (process), task)
211 #define PAJE_HOST_NEW(host)\
212   if(msg_global->paje_output)\
213     fprintf(msg_global->paje_output,"7 %f %p H_t CUR \"%s\"\n",surf_get_clock(), \
214             host, host->name)
215 #define PAJE_HOST_FREE(host)\
216   if(msg_global->paje_output)\
217     fprintf(msg_global->paje_output,"8 %f %p H_t\n",surf_get_clock(), host);
218
219 #endif /* Alvin_Special_Loging */
220 #endif