1 /* Copyright (c) 2008-2013. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "mc_private.h"
9 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_request, mc,
10 "Logging specific to MC (request)");
12 static char* pointer_to_string(void* pointer);
13 static char* buff_size_to_string(size_t size);
15 int MC_request_depend(smx_simcall_t r1, smx_simcall_t r2) {
16 if(mc_reduce_kind == e_mc_reduce_none)
19 if (r1->issuer == r2->issuer)
22 if(r1->call == SIMCALL_COMM_ISEND && r2->call == SIMCALL_COMM_IRECV)
25 if(r1->call == SIMCALL_COMM_IRECV && r2->call == SIMCALL_COMM_ISEND)
28 if((r1->call == SIMCALL_COMM_ISEND || r1->call == SIMCALL_COMM_IRECV)
29 && r2->call == SIMCALL_COMM_WAIT){
31 smx_rdv_t rdv = r1->call == SIMCALL_COMM_ISEND ? simcall_comm_isend__get__rdv(r1) : simcall_comm_irecv__get__rdv(r1);
33 if(rdv != simcall_comm_wait__get__comm(r2)->comm.rdv_cpy && simcall_comm_wait__get__timeout(r2) <= 0)
36 if((r1->issuer != simcall_comm_wait__get__comm(r2)->comm.src_proc) && (r1->issuer != simcall_comm_wait__get__comm(r2)->comm.dst_proc) && simcall_comm_wait__get__timeout(r2) <= 0)
39 if((r1->call == SIMCALL_COMM_ISEND) && (simcall_comm_wait__get__comm(r2)->comm.type == SIMIX_COMM_SEND)
40 && (simcall_comm_wait__get__comm(r2)->comm.src_buff != simcall_comm_isend__get__src_buff(r1)) && simcall_comm_wait__get__timeout(r2) <= 0)
43 if((r1->call == SIMCALL_COMM_IRECV) && (simcall_comm_wait__get__comm(r2)->comm.type == SIMIX_COMM_RECEIVE)
44 && (simcall_comm_wait__get__comm(r2)->comm.dst_buff != simcall_comm_irecv__get__dst_buff(r1)) && simcall_comm_wait__get__timeout(r2) <= 0)
48 if((r2->call == SIMCALL_COMM_ISEND || r2->call == SIMCALL_COMM_IRECV)
49 && r1->call == SIMCALL_COMM_WAIT){
51 smx_rdv_t rdv = r2->call == SIMCALL_COMM_ISEND ? simcall_comm_isend__get__rdv(r2) : simcall_comm_irecv__get__rdv(r2);
53 if(rdv != simcall_comm_wait__get__comm(r1)->comm.rdv_cpy && simcall_comm_wait__get__timeout(r1) <= 0)
56 if((r2->issuer != simcall_comm_wait__get__comm(r1)->comm.src_proc) && (r2->issuer != simcall_comm_wait__get__comm(r1)->comm.dst_proc) && simcall_comm_wait__get__timeout(r1) <= 0)
59 if((r2->call == SIMCALL_COMM_ISEND) && (simcall_comm_wait__get__comm(r1)->comm.type == SIMIX_COMM_SEND)
60 && (simcall_comm_wait__get__comm(r1)->comm.src_buff != simcall_comm_isend__get__src_buff(r2)) && simcall_comm_wait__get__timeout(r1) <= 0)
63 if((r2->call == SIMCALL_COMM_IRECV) && (simcall_comm_wait__get__comm(r1)->comm.type == SIMIX_COMM_RECEIVE)
64 && (simcall_comm_wait__get__comm(r1)->comm.dst_buff != simcall_comm_irecv__get__dst_buff(r2)) && simcall_comm_wait__get__timeout(r1) <= 0)
68 /* FIXME: the following rule assumes that the result of the
69 * isend/irecv call is not stored in a buffer used in the
71 /*if( (r1->call == SIMCALL_COMM_ISEND || r1->call == SIMCALL_COMM_IRECV)
72 && r2->call == SIMCALL_COMM_TEST)
75 /* FIXME: the following rule assumes that the result of the
76 * isend/irecv call is not stored in a buffer used in the
78 /*if( (r2->call == SIMCALL_COMM_ISEND || r2->call == SIMCALL_COMM_IRECV)
79 && r1->call == SIMCALL_COMM_TEST)
82 if(r1->call == SIMCALL_COMM_ISEND && r2->call == SIMCALL_COMM_ISEND
83 && simcall_comm_isend__get__rdv(r1) != simcall_comm_isend__get__rdv(r2))
86 if(r1->call == SIMCALL_COMM_IRECV && r2->call == SIMCALL_COMM_IRECV
87 && simcall_comm_irecv__get__rdv(r1) != simcall_comm_irecv__get__rdv(r2))
90 if(r1->call == SIMCALL_COMM_WAIT && (r2->call == SIMCALL_COMM_WAIT || r2->call == SIMCALL_COMM_TEST)
91 && (simcall_comm_wait__get__comm(r1)->comm.src_proc == NULL
92 || simcall_comm_wait__get__comm(r1)->comm.dst_proc == NULL))
95 if(r2->call == SIMCALL_COMM_WAIT && (r1->call == SIMCALL_COMM_WAIT || r1->call == SIMCALL_COMM_TEST)
96 && (simcall_comm_wait__get__comm(r2)->comm.src_proc == NULL
97 || simcall_comm_wait__get__comm(r2)->comm.dst_proc == NULL))
100 if(r1->call == SIMCALL_COMM_WAIT && r2->call == SIMCALL_COMM_WAIT
101 && simcall_comm_wait__get__comm(r1)->comm.src_buff == simcall_comm_wait__get__comm(r2)->comm.src_buff
102 && simcall_comm_wait__get__comm(r1)->comm.dst_buff == simcall_comm_wait__get__comm(r2)->comm.dst_buff)
105 if (r1->call == SIMCALL_COMM_WAIT && r2->call == SIMCALL_COMM_WAIT
106 && simcall_comm_wait__get__comm(r1)->comm.src_buff != NULL
107 && simcall_comm_wait__get__comm(r1)->comm.dst_buff != NULL
108 && simcall_comm_wait__get__comm(r2)->comm.src_buff != NULL
109 && simcall_comm_wait__get__comm(r2)->comm.dst_buff != NULL
110 && simcall_comm_wait__get__comm(r1)->comm.dst_buff != simcall_comm_wait__get__comm(r2)->comm.src_buff
111 && simcall_comm_wait__get__comm(r1)->comm.dst_buff != simcall_comm_wait__get__comm(r2)->comm.dst_buff
112 && simcall_comm_wait__get__comm(r2)->comm.dst_buff != simcall_comm_wait__get__comm(r1)->comm.src_buff)
115 if(r1->call == SIMCALL_COMM_TEST &&
116 (simcall_comm_test__get__comm(r1) == NULL
117 || simcall_comm_test__get__comm(r1)->comm.src_buff == NULL
118 || simcall_comm_test__get__comm(r1)->comm.dst_buff == NULL))
121 if(r2->call == SIMCALL_COMM_TEST &&
122 (simcall_comm_test__get__comm(r2) == NULL
123 || simcall_comm_test__get__comm(r2)->comm.src_buff == NULL
124 || simcall_comm_test__get__comm(r2)->comm.dst_buff == NULL))
127 if(r1->call == SIMCALL_COMM_TEST && r2->call == SIMCALL_COMM_WAIT
128 && simcall_comm_test__get__comm(r1)->comm.src_buff == simcall_comm_wait__get__comm(r2)->comm.src_buff
129 && simcall_comm_test__get__comm(r1)->comm.dst_buff == simcall_comm_wait__get__comm(r2)->comm.dst_buff)
132 if(r1->call == SIMCALL_COMM_WAIT && r2->call == SIMCALL_COMM_TEST
133 && simcall_comm_wait__get__comm(r1)->comm.src_buff == simcall_comm_test__get__comm(r2)->comm.src_buff
134 && simcall_comm_wait__get__comm(r1)->comm.dst_buff == simcall_comm_test__get__comm(r2)->comm.dst_buff)
137 if (r1->call == SIMCALL_COMM_WAIT && r2->call == SIMCALL_COMM_TEST
138 && simcall_comm_wait__get__comm(r1)->comm.src_buff != NULL
139 && simcall_comm_wait__get__comm(r1)->comm.dst_buff != NULL
140 && simcall_comm_test__get__comm(r2)->comm.src_buff != NULL
141 && simcall_comm_test__get__comm(r2)->comm.dst_buff != NULL
142 && simcall_comm_wait__get__comm(r1)->comm.dst_buff != simcall_comm_test__get__comm(r2)->comm.src_buff
143 && simcall_comm_wait__get__comm(r1)->comm.dst_buff != simcall_comm_test__get__comm(r2)->comm.dst_buff
144 && simcall_comm_test__get__comm(r2)->comm.dst_buff != simcall_comm_wait__get__comm(r1)->comm.src_buff)
147 if (r1->call == SIMCALL_COMM_TEST && r2->call == SIMCALL_COMM_WAIT
148 && simcall_comm_test__get__comm(r1)->comm.src_buff != NULL
149 && simcall_comm_test__get__comm(r1)->comm.dst_buff != NULL
150 && simcall_comm_wait__get__comm(r2)->comm.src_buff != NULL
151 && simcall_comm_wait__get__comm(r2)->comm.dst_buff != NULL
152 && simcall_comm_test__get__comm(r1)->comm.dst_buff != simcall_comm_wait__get__comm(r2)->comm.src_buff
153 && simcall_comm_test__get__comm(r1)->comm.dst_buff != simcall_comm_wait__get__comm(r2)->comm.dst_buff
154 && simcall_comm_wait__get__comm(r2)->comm.dst_buff != simcall_comm_test__get__comm(r1)->comm.src_buff)
161 static char* pointer_to_string(void* pointer) {
163 if (XBT_LOG_ISENABLED(mc_request, xbt_log_priority_verbose))
164 return bprintf("%p", pointer);
166 return xbt_strdup("(verbose only)");
169 static char* buff_size_to_string(size_t buff_size) {
171 if (XBT_LOG_ISENABLED(mc_request, xbt_log_priority_verbose))
172 return bprintf("%zu", buff_size);
174 return xbt_strdup("(verbose only)");
178 char *MC_request_to_string(smx_simcall_t req, int value)
180 char *type = NULL, *args = NULL, *str = NULL, *p = NULL, *bs = NULL;
181 smx_action_t act = NULL;
185 case SIMCALL_COMM_ISEND:
186 type = xbt_strdup("iSend");
187 p = pointer_to_string(simcall_comm_isend__get__src_buff(req));
188 bs = buff_size_to_string(simcall_comm_isend__get__src_buff_size(req));
189 if(req->issuer->smx_host)
190 args = bprintf("src=(%lu)%s (%s), buff=%s, size=%s", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host), req->issuer->name, p, bs);
192 args = bprintf("src=(%lu)%s, buff=%s, size=%s", req->issuer->pid, req->issuer->name, p, bs);
194 case SIMCALL_COMM_IRECV:
195 size = simcall_comm_irecv__get__dst_buff_size(req) ? *simcall_comm_irecv__get__dst_buff_size(req) : 0;
196 type = xbt_strdup("iRecv");
197 p = pointer_to_string(simcall_comm_irecv__get__dst_buff(req));
198 bs = buff_size_to_string(size);
199 if(req->issuer->smx_host)
200 args = bprintf("dst=(%lu)%s (%s), buff=%s, size=%s", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host), req->issuer->name, p, bs);
202 args = bprintf("dst=(%lu)%s, buff=%s, size=%s", req->issuer->pid, req->issuer->name, p, bs);
204 case SIMCALL_COMM_WAIT:
205 act = simcall_comm_wait__get__comm(req);
207 type = xbt_strdup("WaitTimeout");
208 p = pointer_to_string(act);
209 args = bprintf("comm=%s", p);
211 type = xbt_strdup("Wait");
212 p = pointer_to_string(act);
213 args = bprintf("comm=%s [(%lu)%s (%s)-> (%lu)%s (%s)]", p,
214 act->comm.src_proc ? act->comm.src_proc->pid : 0,
215 act->comm.src_proc ? MSG_host_get_name(act->comm.src_proc->smx_host) : "",
216 act->comm.src_proc ? act->comm.src_proc->name : "",
217 act->comm.dst_proc ? act->comm.dst_proc->pid : 0,
218 act->comm.dst_proc ? MSG_host_get_name(act->comm.dst_proc->smx_host) : "",
219 act->comm.dst_proc ? act->comm.dst_proc->name : "");
222 case SIMCALL_COMM_TEST:
223 act = simcall_comm_test__get__comm(req);
224 if(act->comm.src_proc == NULL || act->comm.dst_proc == NULL){
225 type = xbt_strdup("Test FALSE");
226 p = pointer_to_string(act);
227 args = bprintf("comm=%s", p);
229 type = xbt_strdup("Test TRUE");
230 p = pointer_to_string(act);
231 args = bprintf("comm=%s [(%lu)%s (%s) -> (%lu)%s (%s)]", p,
232 act->comm.src_proc->pid, act->comm.src_proc->name, MSG_host_get_name(act->comm.src_proc->smx_host),
233 act->comm.dst_proc->pid, act->comm.dst_proc->name, MSG_host_get_name(act->comm.dst_proc->smx_host));
237 case SIMCALL_COMM_WAITANY:
238 type = xbt_strdup("WaitAny");
239 if(!xbt_dynar_is_empty(simcall_comm_waitany__get__comms(req))){
240 p = pointer_to_string(xbt_dynar_get_as(simcall_comm_waitany__get__comms(req), value, smx_action_t));
241 args = bprintf("comm=%s (%d of %lu)", p,
242 value+1, xbt_dynar_length(simcall_comm_waitany__get__comms(req)));
244 args = bprintf("comm at idx %d", value);
248 case SIMCALL_COMM_TESTANY:
250 type = xbt_strdup("TestAny FALSE");
251 args = xbt_strdup("-");
253 type = xbt_strdup("TestAny");
254 args = bprintf("(%d of %lu)", value+1, xbt_dynar_length(simcall_comm_testany__get__comms(req)));
258 case SIMCALL_MC_SNAPSHOT:
259 type = xbt_strdup("MC_SNAPSHOT");
263 case SIMCALL_MC_COMPARE_SNAPSHOTS:
264 type = xbt_strdup("MC_COMPARE_SNAPSHOTS");
268 case SIMCALL_MC_RANDOM:
269 type = xbt_strdup("MC_RANDOM");
270 args = bprintf("%d", value);
278 str = bprintf("[(%lu)%s (%s)] %s(%s) (%d)", req->issuer->pid , MSG_host_get_name(req->issuer->smx_host), req->issuer->name, type, args, req->call);
280 str = bprintf("[(%lu)%s (%s)] %s (%d) ", req->issuer->pid , MSG_host_get_name(req->issuer->smx_host), req->issuer->name, type, req->call);
290 unsigned int MC_request_testany_fail(smx_simcall_t req)
295 xbt_dynar_foreach(simcall_comm_testany__get__comms(req), cursor, action){
296 if(action->comm.src_proc && action->comm.dst_proc)
303 int MC_request_is_visible(smx_simcall_t req)
305 return req->call == SIMCALL_COMM_ISEND
306 || req->call == SIMCALL_COMM_IRECV
307 || req->call == SIMCALL_COMM_WAIT
308 || req->call == SIMCALL_COMM_WAITANY
309 || req->call == SIMCALL_COMM_TEST
310 || req->call == SIMCALL_COMM_TESTANY
311 || req->call == SIMCALL_MC_RANDOM
312 || req->call == SIMCALL_MC_SNAPSHOT
313 || req->call == SIMCALL_MC_COMPARE_SNAPSHOTS;
316 int MC_request_is_enabled(smx_simcall_t req)
318 unsigned int index = 0;
323 case SIMCALL_COMM_WAIT:
324 /* FIXME: check also that src and dst processes are not suspended */
326 /* If it has a timeout it will be always be enabled, because even if the
327 * communication is not ready, it can timeout and won't block.
328 * On the other hand if it hasn't a timeout, check if the comm is ready.*/
329 if(simcall_comm_wait__get__timeout(req) >= 0){
330 if(_sg_mc_timeout == 1){
333 act = simcall_comm_wait__get__comm(req);
334 return (act->comm.src_proc && act->comm.dst_proc);
337 act = simcall_comm_wait__get__comm(req);
338 return (act->comm.src_proc && act->comm.dst_proc);
342 case SIMCALL_COMM_WAITANY:
343 /* Check if it has at least one communication ready */
344 xbt_dynar_foreach(simcall_comm_waitany__get__comms(req), index, act) {
345 if (act->comm.src_proc && act->comm.dst_proc){
353 /* The rest of the request are always enabled */
358 int MC_request_is_enabled_by_idx(smx_simcall_t req, unsigned int idx)
364 case SIMCALL_COMM_WAIT:
365 /* FIXME: check also that src and dst processes are not suspended */
366 act = simcall_comm_wait__get__comm(req);
367 return (act->comm.src_proc && act->comm.dst_proc);
370 case SIMCALL_COMM_WAITANY:
371 act = xbt_dynar_get_as(simcall_comm_waitany__get__comms(req), idx, smx_action_t);
372 return (act->comm.src_proc && act->comm.dst_proc);
375 case SIMCALL_COMM_TESTANY:
376 act = xbt_dynar_get_as(simcall_comm_testany__get__comms(req), idx, smx_action_t);
377 return (act->comm.src_proc && act->comm.dst_proc);
385 int MC_process_is_enabled(smx_process_t process)
387 if (process->simcall.call != SIMCALL_NONE && MC_request_is_enabled(&process->simcall))
393 char *MC_request_get_dot_output(smx_simcall_t req, int value){
395 char *str = NULL, *label = NULL;
396 smx_action_t act = NULL;
399 case SIMCALL_COMM_ISEND:
400 if(req->issuer->smx_host)
401 label = bprintf("[(%lu)%s] iSend", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host));
403 label = bprintf("[(%lu)] iSend", req->issuer->pid);
406 case SIMCALL_COMM_IRECV:
407 if(req->issuer->smx_host)
408 label = bprintf("[(%lu)%s] iRecv", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host));
410 label = bprintf("[(%lu)] iRecv", req->issuer->pid);
413 case SIMCALL_COMM_WAIT:
414 act = simcall_comm_wait__get__comm(req);
416 if(req->issuer->smx_host)
417 label = bprintf("[(%lu)%s] WaitTimeout", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host));
419 label = bprintf("[(%lu)] WaitTimeout", req->issuer->pid);
421 if(req->issuer->smx_host)
422 label = bprintf("[(%lu)%s] Wait [(%lu)->(%lu)]", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host), act->comm.src_proc ? act->comm.src_proc->pid : 0, act->comm.dst_proc ? act->comm.dst_proc->pid : 0);
424 label = bprintf("[(%lu)] Wait [(%lu)->(%lu)]", req->issuer->pid, act->comm.src_proc ? act->comm.src_proc->pid : 0, act->comm.dst_proc ? act->comm.dst_proc->pid : 0);
428 case SIMCALL_COMM_TEST:
429 act = simcall_comm_test__get__comm(req);
430 if(act->comm.src_proc == NULL || act->comm.dst_proc == NULL){
431 if(req->issuer->smx_host)
432 label = bprintf("[(%lu)%s] Test FALSE", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host));
434 label = bprintf("[(%lu)] Test FALSE", req->issuer->pid);
436 if(req->issuer->smx_host)
437 label = bprintf("[(%lu)%s] Test TRUE", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host));
439 label = bprintf("[(%lu)] Test TRUE", req->issuer->pid);
443 case SIMCALL_COMM_WAITANY:
444 if(req->issuer->smx_host)
445 label = bprintf("[(%lu)%s] WaitAny [%d of %lu]", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host), value+1, xbt_dynar_length(simcall_comm_waitany__get__comms(req)));
447 label = bprintf("[(%lu)] WaitAny [%d of %lu]", req->issuer->pid, value+1, xbt_dynar_length(simcall_comm_waitany__get__comms(req)));
450 case SIMCALL_COMM_TESTANY:
452 if(req->issuer->smx_host)
453 label = bprintf("[(%lu)%s] TestAny FALSE", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host));
455 label = bprintf("[(%lu)] TestAny FALSE", req->issuer->pid);
457 if(req->issuer->smx_host)
458 label = bprintf("[(%lu)%s] TestAny TRUE [%d of %lu]", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host), value+1, xbt_dynar_length(simcall_comm_testany__get__comms(req)));
460 label = bprintf("[(%lu)] TestAny TRUE [%d of %lu]", req->issuer->pid, value+1, xbt_dynar_length(simcall_comm_testany__get__comms(req)));
464 case SIMCALL_MC_RANDOM:
465 if(req->issuer->smx_host)
466 label = bprintf("[(%lu)%s] MC_RANDOM (%d)", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host), value);
468 label = bprintf("[(%lu)] MC_RANDOM (%d)", req->issuer->pid, value);
471 case SIMCALL_MC_SNAPSHOT:
472 if(req->issuer->smx_host)
473 label = bprintf("[(%lu)%s] MC_SNAPSHOT", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host));
475 label = bprintf("[(%lu)] MC_SNAPSHOT", req->issuer->pid);
478 case SIMCALL_MC_COMPARE_SNAPSHOTS:
479 if(req->issuer->smx_host)
480 label = bprintf("[(%lu)%s] MC_COMPARE_SNAPSHOTS", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host));
482 label = bprintf("[(%lu)] MC_COMPARE_SNAPSHOTS", req->issuer->pid);
489 str = bprintf("label = \"%s\", color = %s, fontcolor = %s", label, colors[req->issuer->pid-1], colors[req->issuer->pid-1]);