1 /* Copyright (c) 2008-2014. 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 /* Wait with timeout transitions are not considered by the independance theorem, thus we consider them as dependant with all other transitions */
23 if((r1->call == SIMCALL_COMM_WAIT && simcall_comm_wait__get__timeout(r1) > 0) || (r2->call == SIMCALL_COMM_WAIT && simcall_comm_wait__get__timeout(r2) > 0))
26 if(r1->call == SIMCALL_COMM_ISEND && r2->call == SIMCALL_COMM_IRECV)
29 if(r1->call == SIMCALL_COMM_IRECV && r2->call == SIMCALL_COMM_ISEND)
32 if((r1->call == SIMCALL_COMM_ISEND || r1->call == SIMCALL_COMM_IRECV)
33 && r2->call == SIMCALL_COMM_WAIT){
35 smx_rdv_t rdv = r1->call == SIMCALL_COMM_ISEND ? simcall_comm_isend__get__rdv(r1) : simcall_comm_irecv__get__rdv(r1);
37 if(rdv != simcall_comm_wait__get__comm(r2)->comm.rdv_cpy && simcall_comm_wait__get__timeout(r2) <= 0)
40 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)
43 if((r1->call == SIMCALL_COMM_ISEND) && (simcall_comm_wait__get__comm(r2)->comm.type == SIMIX_COMM_SEND)
44 && (simcall_comm_wait__get__comm(r2)->comm.src_buff != simcall_comm_isend__get__src_buff(r1)) && simcall_comm_wait__get__timeout(r2) <= 0)
47 if((r1->call == SIMCALL_COMM_IRECV) && (simcall_comm_wait__get__comm(r2)->comm.type == SIMIX_COMM_RECEIVE)
48 && (simcall_comm_wait__get__comm(r2)->comm.dst_buff != simcall_comm_irecv__get__dst_buff(r1)) && simcall_comm_wait__get__timeout(r2) <= 0)
52 if((r2->call == SIMCALL_COMM_ISEND || r2->call == SIMCALL_COMM_IRECV)
53 && r1->call == SIMCALL_COMM_WAIT){
55 smx_rdv_t rdv = r2->call == SIMCALL_COMM_ISEND ? simcall_comm_isend__get__rdv(r2) : simcall_comm_irecv__get__rdv(r2);
57 if(rdv != simcall_comm_wait__get__comm(r1)->comm.rdv_cpy && simcall_comm_wait__get__timeout(r1) <= 0)
60 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)
63 if((r2->call == SIMCALL_COMM_ISEND) && (simcall_comm_wait__get__comm(r1)->comm.type == SIMIX_COMM_SEND)
64 && (simcall_comm_wait__get__comm(r1)->comm.src_buff != simcall_comm_isend__get__src_buff(r2)) && simcall_comm_wait__get__timeout(r1) <= 0)
67 if((r2->call == SIMCALL_COMM_IRECV) && (simcall_comm_wait__get__comm(r1)->comm.type == SIMIX_COMM_RECEIVE)
68 && (simcall_comm_wait__get__comm(r1)->comm.dst_buff != simcall_comm_irecv__get__dst_buff(r2)) && simcall_comm_wait__get__timeout(r1) <= 0)
72 /* FIXME: the following rule assumes that the result of the
73 * isend/irecv call is not stored in a buffer used in the
75 /*if( (r1->call == SIMCALL_COMM_ISEND || r1->call == SIMCALL_COMM_IRECV)
76 && r2->call == SIMCALL_COMM_TEST)
79 /* FIXME: the following rule assumes that the result of the
80 * isend/irecv call is not stored in a buffer used in the
82 /*if( (r2->call == SIMCALL_COMM_ISEND || r2->call == SIMCALL_COMM_IRECV)
83 && r1->call == SIMCALL_COMM_TEST)
86 if(r1->call == SIMCALL_COMM_ISEND && r2->call == SIMCALL_COMM_ISEND
87 && simcall_comm_isend__get__rdv(r1) != simcall_comm_isend__get__rdv(r2))
90 if(r1->call == SIMCALL_COMM_IRECV && r2->call == SIMCALL_COMM_IRECV
91 && simcall_comm_irecv__get__rdv(r1) != simcall_comm_irecv__get__rdv(r2))
94 if(r1->call == SIMCALL_COMM_WAIT && (r2->call == SIMCALL_COMM_WAIT || r2->call == SIMCALL_COMM_TEST)
95 && (simcall_comm_wait__get__comm(r1)->comm.src_proc == NULL
96 || simcall_comm_wait__get__comm(r1)->comm.dst_proc == NULL))
99 if(r2->call == SIMCALL_COMM_WAIT && (r1->call == SIMCALL_COMM_WAIT || r1->call == SIMCALL_COMM_TEST)
100 && (simcall_comm_wait__get__comm(r2)->comm.src_proc == NULL
101 || simcall_comm_wait__get__comm(r2)->comm.dst_proc == NULL))
104 if(r1->call == SIMCALL_COMM_WAIT && r2->call == SIMCALL_COMM_WAIT
105 && simcall_comm_wait__get__comm(r1)->comm.src_buff == simcall_comm_wait__get__comm(r2)->comm.src_buff
106 && simcall_comm_wait__get__comm(r1)->comm.dst_buff == simcall_comm_wait__get__comm(r2)->comm.dst_buff)
109 if (r1->call == SIMCALL_COMM_WAIT && r2->call == SIMCALL_COMM_WAIT
110 && simcall_comm_wait__get__comm(r1)->comm.src_buff != NULL
111 && simcall_comm_wait__get__comm(r1)->comm.dst_buff != NULL
112 && simcall_comm_wait__get__comm(r2)->comm.src_buff != NULL
113 && simcall_comm_wait__get__comm(r2)->comm.dst_buff != NULL
114 && simcall_comm_wait__get__comm(r1)->comm.dst_buff != simcall_comm_wait__get__comm(r2)->comm.src_buff
115 && simcall_comm_wait__get__comm(r1)->comm.dst_buff != simcall_comm_wait__get__comm(r2)->comm.dst_buff
116 && simcall_comm_wait__get__comm(r2)->comm.dst_buff != simcall_comm_wait__get__comm(r1)->comm.src_buff)
119 if(r1->call == SIMCALL_COMM_TEST &&
120 (simcall_comm_test__get__comm(r1) == NULL
121 || simcall_comm_test__get__comm(r1)->comm.src_buff == NULL
122 || simcall_comm_test__get__comm(r1)->comm.dst_buff == NULL))
125 if(r2->call == SIMCALL_COMM_TEST &&
126 (simcall_comm_test__get__comm(r2) == NULL
127 || simcall_comm_test__get__comm(r2)->comm.src_buff == NULL
128 || simcall_comm_test__get__comm(r2)->comm.dst_buff == NULL))
131 if(r1->call == SIMCALL_COMM_TEST && r2->call == SIMCALL_COMM_WAIT
132 && simcall_comm_test__get__comm(r1)->comm.src_buff == simcall_comm_wait__get__comm(r2)->comm.src_buff
133 && simcall_comm_test__get__comm(r1)->comm.dst_buff == simcall_comm_wait__get__comm(r2)->comm.dst_buff)
136 if(r1->call == SIMCALL_COMM_WAIT && r2->call == SIMCALL_COMM_TEST
137 && simcall_comm_wait__get__comm(r1)->comm.src_buff == simcall_comm_test__get__comm(r2)->comm.src_buff
138 && simcall_comm_wait__get__comm(r1)->comm.dst_buff == simcall_comm_test__get__comm(r2)->comm.dst_buff)
141 if (r1->call == SIMCALL_COMM_WAIT && r2->call == SIMCALL_COMM_TEST
142 && simcall_comm_wait__get__comm(r1)->comm.src_buff != NULL
143 && simcall_comm_wait__get__comm(r1)->comm.dst_buff != NULL
144 && simcall_comm_test__get__comm(r2)->comm.src_buff != NULL
145 && simcall_comm_test__get__comm(r2)->comm.dst_buff != NULL
146 && simcall_comm_wait__get__comm(r1)->comm.dst_buff != simcall_comm_test__get__comm(r2)->comm.src_buff
147 && simcall_comm_wait__get__comm(r1)->comm.dst_buff != simcall_comm_test__get__comm(r2)->comm.dst_buff
148 && simcall_comm_test__get__comm(r2)->comm.dst_buff != simcall_comm_wait__get__comm(r1)->comm.src_buff)
151 if (r1->call == SIMCALL_COMM_TEST && r2->call == SIMCALL_COMM_WAIT
152 && simcall_comm_test__get__comm(r1)->comm.src_buff != NULL
153 && simcall_comm_test__get__comm(r1)->comm.dst_buff != NULL
154 && simcall_comm_wait__get__comm(r2)->comm.src_buff != NULL
155 && simcall_comm_wait__get__comm(r2)->comm.dst_buff != NULL
156 && simcall_comm_test__get__comm(r1)->comm.dst_buff != simcall_comm_wait__get__comm(r2)->comm.src_buff
157 && simcall_comm_test__get__comm(r1)->comm.dst_buff != simcall_comm_wait__get__comm(r2)->comm.dst_buff
158 && simcall_comm_wait__get__comm(r2)->comm.dst_buff != simcall_comm_test__get__comm(r1)->comm.src_buff)
165 static char* pointer_to_string(void* pointer) {
167 if (XBT_LOG_ISENABLED(mc_request, xbt_log_priority_verbose))
168 return bprintf("%p", pointer);
170 return xbt_strdup("(verbose only)");
173 static char* buff_size_to_string(size_t buff_size) {
175 if (XBT_LOG_ISENABLED(mc_request, xbt_log_priority_verbose))
176 return bprintf("%zu", buff_size);
178 return xbt_strdup("(verbose only)");
182 char *MC_request_to_string(smx_simcall_t req, int value)
184 char *type = NULL, *args = NULL, *str = NULL, *p = NULL, *bs = NULL;
185 smx_action_t act = NULL;
189 case SIMCALL_COMM_ISEND:
190 type = xbt_strdup("iSend");
191 p = pointer_to_string(simcall_comm_isend__get__src_buff(req));
192 bs = buff_size_to_string(simcall_comm_isend__get__src_buff_size(req));
193 if(req->issuer->smx_host)
194 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);
196 args = bprintf("src=(%lu)%s, buff=%s, size=%s", req->issuer->pid, req->issuer->name, p, bs);
198 case SIMCALL_COMM_IRECV:
199 size = simcall_comm_irecv__get__dst_buff_size(req) ? *simcall_comm_irecv__get__dst_buff_size(req) : 0;
200 type = xbt_strdup("iRecv");
201 p = pointer_to_string(simcall_comm_irecv__get__dst_buff(req));
202 bs = buff_size_to_string(size);
203 if(req->issuer->smx_host)
204 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);
206 args = bprintf("dst=(%lu)%s, buff=%s, size=%s", req->issuer->pid, req->issuer->name, p, bs);
208 case SIMCALL_COMM_WAIT:
209 act = simcall_comm_wait__get__comm(req);
211 type = xbt_strdup("WaitTimeout");
212 p = pointer_to_string(act);
213 args = bprintf("comm=%s", p);
215 type = xbt_strdup("Wait");
216 p = pointer_to_string(act);
217 args = bprintf("comm=%s [(%lu)%s (%s)-> (%lu)%s (%s)]", p,
218 act->comm.src_proc ? act->comm.src_proc->pid : 0,
219 act->comm.src_proc ? MSG_host_get_name(act->comm.src_proc->smx_host) : "",
220 act->comm.src_proc ? act->comm.src_proc->name : "",
221 act->comm.dst_proc ? act->comm.dst_proc->pid : 0,
222 act->comm.dst_proc ? MSG_host_get_name(act->comm.dst_proc->smx_host) : "",
223 act->comm.dst_proc ? act->comm.dst_proc->name : "");
226 case SIMCALL_COMM_TEST:
227 act = simcall_comm_test__get__comm(req);
228 if(act->comm.src_proc == NULL || act->comm.dst_proc == NULL){
229 type = xbt_strdup("Test FALSE");
230 p = pointer_to_string(act);
231 args = bprintf("comm=%s", p);
233 type = xbt_strdup("Test TRUE");
234 p = pointer_to_string(act);
235 args = bprintf("comm=%s [(%lu)%s (%s) -> (%lu)%s (%s)]", p,
236 act->comm.src_proc->pid, act->comm.src_proc->name, MSG_host_get_name(act->comm.src_proc->smx_host),
237 act->comm.dst_proc->pid, act->comm.dst_proc->name, MSG_host_get_name(act->comm.dst_proc->smx_host));
241 case SIMCALL_COMM_WAITANY:
242 type = xbt_strdup("WaitAny");
243 if(!xbt_dynar_is_empty(simcall_comm_waitany__get__comms(req))){
244 p = pointer_to_string(xbt_dynar_get_as(simcall_comm_waitany__get__comms(req), value, smx_action_t));
245 args = bprintf("comm=%s (%d of %lu)", p,
246 value+1, xbt_dynar_length(simcall_comm_waitany__get__comms(req)));
248 args = bprintf("comm at idx %d", value);
252 case SIMCALL_COMM_TESTANY:
254 type = xbt_strdup("TestAny FALSE");
255 args = xbt_strdup("-");
257 type = xbt_strdup("TestAny");
258 args = bprintf("(%d of %lu)", value+1, xbt_dynar_length(simcall_comm_testany__get__comms(req)));
262 case SIMCALL_MC_SNAPSHOT:
263 type = xbt_strdup("MC_SNAPSHOT");
267 case SIMCALL_MC_COMPARE_SNAPSHOTS:
268 type = xbt_strdup("MC_COMPARE_SNAPSHOTS");
272 case SIMCALL_MC_RANDOM:
273 type = xbt_strdup("MC_RANDOM");
274 args = bprintf("%d", value);
282 str = bprintf("[(%lu)%s (%s)] %s(%s)", req->issuer->pid , MSG_host_get_name(req->issuer->smx_host), req->issuer->name, type, args);
284 str = bprintf("[(%lu)%s (%s)] %s ", req->issuer->pid , MSG_host_get_name(req->issuer->smx_host), req->issuer->name, type);
294 unsigned int MC_request_testany_fail(smx_simcall_t req)
299 xbt_dynar_foreach(simcall_comm_testany__get__comms(req), cursor, action){
300 if(action->comm.src_proc && action->comm.dst_proc)
307 int MC_request_is_visible(smx_simcall_t req)
309 return req->call == SIMCALL_COMM_ISEND
310 || req->call == SIMCALL_COMM_IRECV
311 || req->call == SIMCALL_COMM_WAIT
312 || req->call == SIMCALL_COMM_WAITANY
313 || req->call == SIMCALL_COMM_TEST
314 || req->call == SIMCALL_COMM_TESTANY
315 || req->call == SIMCALL_MC_RANDOM
316 || req->call == SIMCALL_MC_SNAPSHOT
317 || req->call == SIMCALL_MC_COMPARE_SNAPSHOTS;
320 int MC_request_is_enabled(smx_simcall_t req)
322 unsigned int index = 0;
327 case SIMCALL_COMM_WAIT:
328 /* FIXME: check also that src and dst processes are not suspended */
330 /* If it has a timeout it will be always be enabled, because even if the
331 * communication is not ready, it can timeout and won't block.
332 * On the other hand if it hasn't a timeout, check if the comm is ready.*/
333 if(simcall_comm_wait__get__timeout(req) >= 0){
334 if(_sg_mc_timeout == 1){
337 act = simcall_comm_wait__get__comm(req);
338 return (act->comm.src_proc && act->comm.dst_proc);
341 act = simcall_comm_wait__get__comm(req);
342 if(act->comm.detached && act->comm.src_proc == NULL && act->comm.type == SIMIX_COMM_READY)
343 return (act->comm.dst_proc != NULL);
344 return (act->comm.src_proc && act->comm.dst_proc);
348 case SIMCALL_COMM_WAITANY:
349 /* Check if it has at least one communication ready */
350 xbt_dynar_foreach(simcall_comm_waitany__get__comms(req), index, act) {
351 if (act->comm.src_proc && act->comm.dst_proc){
359 /* The rest of the request are always enabled */
364 int MC_request_is_enabled_by_idx(smx_simcall_t req, unsigned int idx)
370 case SIMCALL_COMM_WAIT:
371 /* FIXME: check also that src and dst processes are not suspended */
372 act = simcall_comm_wait__get__comm(req);
373 return (act->comm.src_proc && act->comm.dst_proc);
376 case SIMCALL_COMM_WAITANY:
377 act = xbt_dynar_get_as(simcall_comm_waitany__get__comms(req), idx, smx_action_t);
378 return (act->comm.src_proc && act->comm.dst_proc);
381 case SIMCALL_COMM_TESTANY:
382 act = xbt_dynar_get_as(simcall_comm_testany__get__comms(req), idx, smx_action_t);
383 return (act->comm.src_proc && act->comm.dst_proc);
391 int MC_process_is_enabled(smx_process_t process)
393 if (process->simcall.call != SIMCALL_NONE && MC_request_is_enabled(&process->simcall))
399 char *MC_request_get_dot_output(smx_simcall_t req, int value){
401 char *str = NULL, *label = NULL;
402 smx_action_t act = NULL;
405 case SIMCALL_COMM_ISEND:
406 if(req->issuer->smx_host)
407 label = bprintf("[(%lu)%s] iSend", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host));
409 label = bprintf("[(%lu)] iSend", req->issuer->pid);
412 case SIMCALL_COMM_IRECV:
413 if(req->issuer->smx_host)
414 label = bprintf("[(%lu)%s] iRecv", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host));
416 label = bprintf("[(%lu)] iRecv", req->issuer->pid);
419 case SIMCALL_COMM_WAIT:
420 act = simcall_comm_wait__get__comm(req);
422 if(req->issuer->smx_host)
423 label = bprintf("[(%lu)%s] WaitTimeout", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host));
425 label = bprintf("[(%lu)] WaitTimeout", req->issuer->pid);
427 if(req->issuer->smx_host)
428 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);
430 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);
434 case SIMCALL_COMM_TEST:
435 act = simcall_comm_test__get__comm(req);
436 if(act->comm.src_proc == NULL || act->comm.dst_proc == NULL){
437 if(req->issuer->smx_host)
438 label = bprintf("[(%lu)%s] Test FALSE", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host));
440 label = bprintf("[(%lu)] Test FALSE", req->issuer->pid);
442 if(req->issuer->smx_host)
443 label = bprintf("[(%lu)%s] Test TRUE", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host));
445 label = bprintf("[(%lu)] Test TRUE", req->issuer->pid);
449 case SIMCALL_COMM_WAITANY:
450 if(req->issuer->smx_host)
451 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)));
453 label = bprintf("[(%lu)] WaitAny [%d of %lu]", req->issuer->pid, value+1, xbt_dynar_length(simcall_comm_waitany__get__comms(req)));
456 case SIMCALL_COMM_TESTANY:
458 if(req->issuer->smx_host)
459 label = bprintf("[(%lu)%s] TestAny FALSE", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host));
461 label = bprintf("[(%lu)] TestAny FALSE", req->issuer->pid);
463 if(req->issuer->smx_host)
464 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)));
466 label = bprintf("[(%lu)] TestAny TRUE [%d of %lu]", req->issuer->pid, value+1, xbt_dynar_length(simcall_comm_testany__get__comms(req)));
470 case SIMCALL_MC_RANDOM:
471 if(req->issuer->smx_host)
472 label = bprintf("[(%lu)%s] MC_RANDOM (%d)", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host), value);
474 label = bprintf("[(%lu)] MC_RANDOM (%d)", req->issuer->pid, value);
477 case SIMCALL_MC_SNAPSHOT:
478 if(req->issuer->smx_host)
479 label = bprintf("[(%lu)%s] MC_SNAPSHOT", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host));
481 label = bprintf("[(%lu)] MC_SNAPSHOT", req->issuer->pid);
484 case SIMCALL_MC_COMPARE_SNAPSHOTS:
485 if(req->issuer->smx_host)
486 label = bprintf("[(%lu)%s] MC_COMPARE_SNAPSHOTS", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host));
488 label = bprintf("[(%lu)] MC_COMPARE_SNAPSHOTS", req->issuer->pid);
495 str = bprintf("label = \"%s\", color = %s, fontcolor = %s", label, colors[req->issuer->pid-1], colors[req->issuer->pid-1]);