Logo AND Algorithmique Numérique Distribuée

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