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
13 #include "surf/surf.h"
15 #include "xbt/dynar.h"
18 #include "xbt/context.h"
19 #include "xbt/config.h"
20 #include "xbt/mallocator.h"
22 /**************** datatypes **********************************/
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;
32 /********************************* Task **************************************/
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 */
45 /******* Parallel Tasks Only !!!! *******/
47 void * *host_list; /* SURF modeling */
52 /******************************* Process *************************************/
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;
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;
70 typedef struct process_arg {
72 m_process_code_t code;
78 } s_process_arg_t, *process_arg_t;
80 /************************** Global variables ********************************/
81 typedef struct MSG_Global {
83 xbt_fifo_t process_to_run;
84 xbt_fifo_t process_list;
86 m_process_t current_process;
87 xbt_dict_t registered_functions;
92 xbt_mallocator_t task_mallocator;
93 xbt_mallocator_t task_simdata_mallocator;
94 } s_MSG_Global_t, *MSG_Global_t;
96 extern MSG_Global_t msg_global;
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;
106 /*************************************************************/
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.") */
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.")
117 m_host_t __MSG_host_create(const char *name, void *workstation,
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);
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);
128 void __MSG_display_process_status(void);
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);
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))
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(), \
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);