3 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_request, mc,
4 "Logging specific to MC (request)");
6 static char* pointer_to_string(void* pointer);
7 static char* buff_size_to_string(size_t size);
9 int MC_request_depend(smx_req_t r1, smx_req_t r2)
11 if(_surf_do_model_check == 2)
14 if (r1->issuer == r2->issuer)
17 if(r1->call == REQ_COMM_ISEND && r2->call == REQ_COMM_IRECV)
20 if(r1->call == REQ_COMM_IRECV && r2->call == REQ_COMM_ISEND)
23 if( (r1->call == REQ_COMM_ISEND || r1->call == REQ_COMM_IRECV)
24 && r2->call == REQ_COMM_WAIT){
26 if(r2->comm_wait.comm->comm.rdv == NULL)
29 smx_rdv_t rdv = r1->call == REQ_COMM_ISEND ? r1->comm_isend.rdv : r1->comm_irecv.rdv;
31 if(r2->comm_wait.comm->comm.rdv != rdv)
34 if(r2->comm_wait.comm->comm.type == SIMIX_COMM_SEND && r1->call == REQ_COMM_ISEND)
37 if(r2->comm_wait.comm->comm.type == SIMIX_COMM_RECEIVE && r1->call == REQ_COMM_IRECV)
41 if( (r2->call == REQ_COMM_ISEND || r2->call == REQ_COMM_IRECV)
42 && r1->call == REQ_COMM_WAIT){
44 if(r1->comm_wait.comm->comm.rdv != NULL)
47 smx_rdv_t rdv = r2->call == REQ_COMM_ISEND ? r2->comm_isend.rdv : r2->comm_irecv.rdv;
49 if(r1->comm_wait.comm->comm.rdv != rdv)
52 if(r1->comm_wait.comm->comm.type == SIMIX_COMM_SEND && r2->call == REQ_COMM_ISEND)
55 if(r1->comm_wait.comm->comm.type == SIMIX_COMM_RECEIVE && r2->call == REQ_COMM_IRECV)
59 /* FIXME: the following rule assumes that the result of the
60 * isend/irecv call is not stored in a buffer used in the
62 if( (r1->call == REQ_COMM_ISEND || r1->call == REQ_COMM_IRECV)
63 && r2->call == REQ_COMM_TEST)
66 /* FIXME: the following rule assumes that the result of the
67 * isend/irecv call is not stored in a buffer used in the
69 if( (r2->call == REQ_COMM_ISEND || r2->call == REQ_COMM_IRECV)
70 && r1->call == REQ_COMM_TEST)
73 if(r1->call == REQ_COMM_ISEND && r2->call == REQ_COMM_ISEND
74 && r1->comm_isend.rdv != r2->comm_isend.rdv)
77 if(r1->call == REQ_COMM_IRECV && r2->call == REQ_COMM_IRECV
78 && r1->comm_irecv.rdv != r2->comm_irecv.rdv)
81 if(r1->call == REQ_COMM_WAIT && (r2->call == REQ_COMM_WAIT || r2->call == REQ_COMM_TEST)
82 && (r1->comm_wait.comm->comm.src_proc == NULL
83 || r1->comm_wait.comm->comm.dst_proc == NULL))
86 if(r2->call == REQ_COMM_WAIT && (r1->call == REQ_COMM_WAIT || r1->call == REQ_COMM_TEST)
87 && (r2->comm_wait.comm->comm.src_proc == NULL
88 || r2->comm_wait.comm->comm.dst_proc == NULL))
91 if(r1->call == REQ_COMM_WAIT && r2->call == REQ_COMM_WAIT
92 && r1->comm_wait.comm->comm.src_buff == r2->comm_wait.comm->comm.src_buff
93 && r1->comm_wait.comm->comm.dst_buff == r2->comm_wait.comm->comm.dst_buff)
96 if (r1->call == REQ_COMM_WAIT && r2->call == REQ_COMM_WAIT
97 && r1->comm_wait.comm->comm.src_buff != NULL
98 && r1->comm_wait.comm->comm.dst_buff != NULL
99 && r2->comm_wait.comm->comm.src_buff != NULL
100 && r2->comm_wait.comm->comm.dst_buff != NULL
101 && r1->comm_wait.comm->comm.dst_buff != r2->comm_wait.comm->comm.src_buff
102 && r1->comm_wait.comm->comm.dst_buff != r2->comm_wait.comm->comm.dst_buff
103 && r2->comm_wait.comm->comm.dst_buff != r1->comm_wait.comm->comm.src_buff)
106 if(r1->call == REQ_COMM_TEST &&
107 (r1->comm_test.comm == NULL
108 || r1->comm_test.comm->comm.src_buff == NULL
109 || r1->comm_test.comm->comm.dst_buff == NULL))
112 if(r2->call == REQ_COMM_TEST &&
113 (r2->comm_test.comm == NULL
114 || r2->comm_test.comm->comm.src_buff == NULL
115 || r2->comm_test.comm->comm.dst_buff == NULL))
118 if(r1->call == REQ_COMM_TEST && r2->call == REQ_COMM_WAIT
119 && r1->comm_test.comm->comm.src_buff == r2->comm_wait.comm->comm.src_buff
120 && r1->comm_test.comm->comm.dst_buff == r2->comm_wait.comm->comm.dst_buff)
123 if(r1->call == REQ_COMM_WAIT && r2->call == REQ_COMM_TEST
124 && r1->comm_wait.comm->comm.src_buff == r2->comm_test.comm->comm.src_buff
125 && r1->comm_wait.comm->comm.dst_buff == r2->comm_test.comm->comm.dst_buff)
128 if (r1->call == REQ_COMM_WAIT && r2->call == REQ_COMM_TEST
129 && r1->comm_wait.comm->comm.src_buff != NULL
130 && r1->comm_wait.comm->comm.dst_buff != NULL
131 && r2->comm_test.comm->comm.src_buff != NULL
132 && r2->comm_test.comm->comm.dst_buff != NULL
133 && r1->comm_wait.comm->comm.dst_buff != r2->comm_test.comm->comm.src_buff
134 && r1->comm_wait.comm->comm.dst_buff != r2->comm_test.comm->comm.dst_buff
135 && r2->comm_test.comm->comm.dst_buff != r1->comm_wait.comm->comm.src_buff)
138 if (r1->call == REQ_COMM_TEST && r2->call == REQ_COMM_WAIT
139 && r1->comm_test.comm->comm.src_buff != NULL
140 && r1->comm_test.comm->comm.dst_buff != NULL
141 && r2->comm_wait.comm->comm.src_buff != NULL
142 && r2->comm_wait.comm->comm.dst_buff != NULL
143 && r1->comm_test.comm->comm.dst_buff != r2->comm_wait.comm->comm.src_buff
144 && r1->comm_test.comm->comm.dst_buff != r2->comm_wait.comm->comm.dst_buff
145 && r2->comm_wait.comm->comm.dst_buff != r1->comm_test.comm->comm.src_buff)
151 static char* pointer_to_string(void* pointer) {
153 if (XBT_LOG_ISENABLED(mc_request, xbt_log_priority_verbose))
154 return bprintf("%p", pointer);
156 return xbt_strdup("(verbose only)");
159 static char* buff_size_to_string(size_t buff_size) {
161 if (XBT_LOG_ISENABLED(mc_request, xbt_log_priority_verbose))
162 return bprintf("%zu", buff_size);
164 return xbt_strdup("(verbose only)");
168 char *MC_request_to_string(smx_req_t req, int value)
170 char *type = NULL, *args = NULL, *str = NULL, *p = NULL, *bs = NULL;
171 smx_action_t act = NULL;
176 type = xbt_strdup("iSend");
177 p = pointer_to_string(req->comm_isend.src_buff);
178 bs = buff_size_to_string(req->comm_isend.src_buff_size);
179 args = bprintf("src=%s, buff=%s, size=%s", req->issuer->name, p, bs);
182 size = req->comm_irecv.dst_buff_size ? *req->comm_irecv.dst_buff_size : 0;
183 type = xbt_strdup("iRecv");
184 p = pointer_to_string(req->comm_irecv.dst_buff);
185 bs = buff_size_to_string(size);
186 args = bprintf("dst=%s, buff=%s, size=%s", req->issuer->name, p, bs);
189 act = req->comm_wait.comm;
191 type = xbt_strdup("WaitTimeout");
192 p = pointer_to_string(act);
193 args = bprintf("comm=%p", p);
195 type = xbt_strdup("Wait");
196 p = pointer_to_string(act);
197 args = bprintf("comm=%s [(%lu)%s -> (%lu)%s]", p,
198 act->comm.src_proc ? act->comm.src_proc->pid : 0,
199 act->comm.src_proc ? act->comm.src_proc->name : "",
200 act->comm.dst_proc ? act->comm.dst_proc->pid : 0,
201 act->comm.dst_proc ? act->comm.dst_proc->name : "");
205 act = req->comm_test.comm;
206 if(act->comm.src_proc == NULL || act->comm.src_proc == NULL){
207 type = xbt_strdup("Test FALSE");
208 p = pointer_to_string(act);
209 args = bprintf("comm=%s", p);
211 type = xbt_strdup("Test TRUE");
212 p = pointer_to_string(act);
213 args = bprintf("comm=%s [(%lu)%s -> (%lu)%s]", p,
214 act->comm.src_proc ? act->comm.src_proc->pid : 0,
215 act->comm.src_proc ? act->comm.src_proc->name : "",
216 act->comm.dst_proc ? act->comm.dst_proc->pid : 0,
217 act->comm.dst_proc ? act->comm.dst_proc->name : "");
221 case REQ_COMM_WAITANY:
222 type = xbt_strdup("WaitAny");
223 p = pointer_to_string(xbt_dynar_get_as(req->comm_waitany.comms, value, smx_action_t));
224 args = bprintf("comm=%s (%d of %lu)", p,
225 value+1, xbt_dynar_length(req->comm_waitany.comms));
228 case REQ_COMM_TESTANY:
230 type = xbt_strdup("TestAny FALSE");
231 args = xbt_strdup("-");
233 type = xbt_strdup("TestAny");
234 args = bprintf("(%d of %lu)", value+1, xbt_dynar_length(req->comm_testany.comms));
242 str = bprintf("[(%lu)%s] %s (%s)", req->issuer->pid ,req->issuer->name, type, args);
250 unsigned int MC_request_testany_fail(smx_req_t req)
255 xbt_dynar_foreach(req->comm_testany.comms, cursor, action){
256 if(action->comm.src_proc && action->comm.dst_proc)
263 int MC_request_is_visible(smx_req_t req)
265 return req->call == REQ_COMM_ISEND
266 || req->call == REQ_COMM_IRECV
267 || req->call == REQ_COMM_WAIT
268 || req->call == REQ_COMM_WAITANY
269 || req->call == REQ_COMM_TEST
270 || req->call == REQ_COMM_TESTANY;
273 int MC_request_is_enabled(smx_req_t req)
275 unsigned int index = 0;
281 /* FIXME: check also that src and dst processes are not suspended */
283 /* If it has a timeout it will be always be enabled, because even if the
284 * communication is not ready, it can timeout and won't block.
285 * On the other hand if it hasn't a timeout, check if the comm is ready.*/
286 if(req->comm_wait.timeout >= 0){
289 act = req->comm_wait.comm;
290 return (act->comm.src_proc && act->comm.dst_proc);
294 case REQ_COMM_WAITANY:
295 /* Check if it has at least one communication ready */
296 xbt_dynar_foreach(req->comm_waitany.comms, index, act) {
297 if (act->comm.src_proc && act->comm.dst_proc){
305 /* The rest of the request are always enabled */
310 int MC_request_is_enabled_by_idx(smx_req_t req, unsigned int idx)
317 /* FIXME: check also that src and dst processes are not suspended */
318 act = req->comm_wait.comm;
319 return (act->comm.src_proc && act->comm.dst_proc);
322 case REQ_COMM_WAITANY:
323 act = xbt_dynar_get_as(req->comm_waitany.comms, idx, smx_action_t);
324 return (act->comm.src_proc && act->comm.dst_proc);
327 case REQ_COMM_TESTANY:
328 act = xbt_dynar_get_as(req->comm_testany.comms, idx, smx_action_t);
329 return (act->comm.src_proc && act->comm.dst_proc);
337 int MC_process_is_enabled(smx_process_t process)
339 if (process->request.call != REQ_NO_REQ && MC_request_is_enabled(&process->request))