Logo AND Algorithmique Numérique Distribuée

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