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_request.h"
9 #include "mc_private.h"
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_request, mc,
13 "Logging specific to MC (request)");
15 static char *pointer_to_string(void *pointer);
16 static char *buff_size_to_string(size_t size);
18 int MC_request_depend(smx_simcall_t r1, smx_simcall_t r2)
20 if (mc_reduce_kind == e_mc_reduce_none)
23 if (r1->issuer == r2->issuer)
26 /* Wait with timeout transitions are not considered by the independance theorem, thus we consider them as dependant with all other transitions */
27 if ((r1->call == SIMCALL_COMM_WAIT && simcall_comm_wait__get__timeout(r1) > 0)
28 || (r2->call == SIMCALL_COMM_WAIT
29 && simcall_comm_wait__get__timeout(r2) > 0))
32 if (r1->call == SIMCALL_COMM_ISEND && r2->call == SIMCALL_COMM_IRECV)
35 if (r1->call == SIMCALL_COMM_IRECV && r2->call == SIMCALL_COMM_ISEND)
38 if ((r1->call == SIMCALL_COMM_ISEND || r1->call == SIMCALL_COMM_IRECV)
39 && r2->call == SIMCALL_COMM_WAIT) {
43 SIMCALL_COMM_ISEND ? simcall_comm_isend__get__rdv(r1) :
44 simcall_comm_irecv__get__rdv(r1);
46 // FIXME, remote access to comm object
48 if (rdv != simcall_comm_wait__get__comm(r2)->comm.rdv_cpy
49 && simcall_comm_wait__get__timeout(r2) <= 0)
52 if ((r1->issuer != simcall_comm_wait__get__comm(r2)->comm.src_proc)
53 && (r1->issuer != simcall_comm_wait__get__comm(r2)->comm.dst_proc)
54 && simcall_comm_wait__get__timeout(r2) <= 0)
57 if ((r1->call == SIMCALL_COMM_ISEND)
58 && (simcall_comm_wait__get__comm(r2)->comm.type == SIMIX_COMM_SEND)
59 && (simcall_comm_wait__get__comm(r2)->comm.src_buff !=
60 simcall_comm_isend__get__src_buff(r1))
61 && simcall_comm_wait__get__timeout(r2) <= 0)
64 if ((r1->call == SIMCALL_COMM_IRECV)
65 && (simcall_comm_wait__get__comm(r2)->comm.type == SIMIX_COMM_RECEIVE)
66 && (simcall_comm_wait__get__comm(r2)->comm.dst_buff !=
67 simcall_comm_irecv__get__dst_buff(r1))
68 && simcall_comm_wait__get__timeout(r2) <= 0)
72 if ((r2->call == SIMCALL_COMM_ISEND || r2->call == SIMCALL_COMM_IRECV)
73 && r1->call == SIMCALL_COMM_WAIT) {
77 SIMCALL_COMM_ISEND ? simcall_comm_isend__get__rdv(r2) :
78 simcall_comm_irecv__get__rdv(r2);
80 if (rdv != simcall_comm_wait__get__comm(r1)->comm.rdv_cpy
81 && simcall_comm_wait__get__timeout(r1) <= 0)
84 if ((r2->issuer != simcall_comm_wait__get__comm(r1)->comm.src_proc)
85 && (r2->issuer != simcall_comm_wait__get__comm(r1)->comm.dst_proc)
86 && simcall_comm_wait__get__timeout(r1) <= 0)
89 if ((r2->call == SIMCALL_COMM_ISEND)
90 && (simcall_comm_wait__get__comm(r1)->comm.type == SIMIX_COMM_SEND)
91 && (simcall_comm_wait__get__comm(r1)->comm.src_buff !=
92 simcall_comm_isend__get__src_buff(r2))
93 && simcall_comm_wait__get__timeout(r1) <= 0)
96 if ((r2->call == SIMCALL_COMM_IRECV)
97 && (simcall_comm_wait__get__comm(r1)->comm.type == SIMIX_COMM_RECEIVE)
98 && (simcall_comm_wait__get__comm(r1)->comm.dst_buff !=
99 simcall_comm_irecv__get__dst_buff(r2))
100 && simcall_comm_wait__get__timeout(r1) <= 0)
104 /* FIXME: the following rule assumes that the result of the
105 * isend/irecv call is not stored in a buffer used in the
107 /*if( (r1->call == SIMCALL_COMM_ISEND || r1->call == SIMCALL_COMM_IRECV)
108 && r2->call == SIMCALL_COMM_TEST)
111 /* FIXME: the following rule assumes that the result of the
112 * isend/irecv call is not stored in a buffer used in the
114 /*if( (r2->call == SIMCALL_COMM_ISEND || r2->call == SIMCALL_COMM_IRECV)
115 && r1->call == SIMCALL_COMM_TEST)
118 if (r1->call == SIMCALL_COMM_ISEND && r2->call == SIMCALL_COMM_ISEND
119 && simcall_comm_isend__get__rdv(r1) != simcall_comm_isend__get__rdv(r2))
122 if (r1->call == SIMCALL_COMM_IRECV && r2->call == SIMCALL_COMM_IRECV
123 && simcall_comm_irecv__get__rdv(r1) != simcall_comm_irecv__get__rdv(r2))
126 if (r1->call == SIMCALL_COMM_WAIT
127 && (r2->call == SIMCALL_COMM_WAIT || r2->call == SIMCALL_COMM_TEST)
128 && (simcall_comm_wait__get__comm(r1)->comm.src_proc == NULL
129 || simcall_comm_wait__get__comm(r1)->comm.dst_proc == NULL))
132 if (r2->call == SIMCALL_COMM_WAIT
133 && (r1->call == SIMCALL_COMM_WAIT || r1->call == SIMCALL_COMM_TEST)
134 && (simcall_comm_wait__get__comm(r2)->comm.src_proc == NULL
135 || simcall_comm_wait__get__comm(r2)->comm.dst_proc == NULL))
138 if (r1->call == SIMCALL_COMM_WAIT && r2->call == SIMCALL_COMM_WAIT
139 && simcall_comm_wait__get__comm(r1)->comm.src_buff ==
140 simcall_comm_wait__get__comm(r2)->comm.src_buff
141 && simcall_comm_wait__get__comm(r1)->comm.dst_buff ==
142 simcall_comm_wait__get__comm(r2)->comm.dst_buff)
145 if (r1->call == SIMCALL_COMM_WAIT && r2->call == SIMCALL_COMM_WAIT
146 && simcall_comm_wait__get__comm(r1)->comm.src_buff != NULL
147 && simcall_comm_wait__get__comm(r1)->comm.dst_buff != NULL
148 && simcall_comm_wait__get__comm(r2)->comm.src_buff != NULL
149 && simcall_comm_wait__get__comm(r2)->comm.dst_buff != NULL
150 && simcall_comm_wait__get__comm(r1)->comm.dst_buff !=
151 simcall_comm_wait__get__comm(r2)->comm.src_buff
152 && simcall_comm_wait__get__comm(r1)->comm.dst_buff !=
153 simcall_comm_wait__get__comm(r2)->comm.dst_buff
154 && simcall_comm_wait__get__comm(r2)->comm.dst_buff !=
155 simcall_comm_wait__get__comm(r1)->comm.src_buff)
158 if (r1->call == SIMCALL_COMM_TEST &&
159 (simcall_comm_test__get__comm(r1) == NULL
160 || simcall_comm_test__get__comm(r1)->comm.src_buff == NULL
161 || simcall_comm_test__get__comm(r1)->comm.dst_buff == NULL))
164 if (r2->call == SIMCALL_COMM_TEST &&
165 (simcall_comm_test__get__comm(r2) == NULL
166 || simcall_comm_test__get__comm(r2)->comm.src_buff == NULL
167 || simcall_comm_test__get__comm(r2)->comm.dst_buff == NULL))
170 if (r1->call == SIMCALL_COMM_TEST && r2->call == SIMCALL_COMM_WAIT
171 && simcall_comm_test__get__comm(r1)->comm.src_buff ==
172 simcall_comm_wait__get__comm(r2)->comm.src_buff
173 && simcall_comm_test__get__comm(r1)->comm.dst_buff ==
174 simcall_comm_wait__get__comm(r2)->comm.dst_buff)
177 if (r1->call == SIMCALL_COMM_WAIT && r2->call == SIMCALL_COMM_TEST
178 && simcall_comm_wait__get__comm(r1)->comm.src_buff ==
179 simcall_comm_test__get__comm(r2)->comm.src_buff
180 && simcall_comm_wait__get__comm(r1)->comm.dst_buff ==
181 simcall_comm_test__get__comm(r2)->comm.dst_buff)
184 if (r1->call == SIMCALL_COMM_WAIT && r2->call == SIMCALL_COMM_TEST
185 && simcall_comm_wait__get__comm(r1)->comm.src_buff != NULL
186 && simcall_comm_wait__get__comm(r1)->comm.dst_buff != NULL
187 && simcall_comm_test__get__comm(r2)->comm.src_buff != NULL
188 && simcall_comm_test__get__comm(r2)->comm.dst_buff != NULL
189 && simcall_comm_wait__get__comm(r1)->comm.dst_buff !=
190 simcall_comm_test__get__comm(r2)->comm.src_buff
191 && simcall_comm_wait__get__comm(r1)->comm.dst_buff !=
192 simcall_comm_test__get__comm(r2)->comm.dst_buff
193 && simcall_comm_test__get__comm(r2)->comm.dst_buff !=
194 simcall_comm_wait__get__comm(r1)->comm.src_buff)
197 if (r1->call == SIMCALL_COMM_TEST && r2->call == SIMCALL_COMM_WAIT
198 && simcall_comm_test__get__comm(r1)->comm.src_buff != NULL
199 && simcall_comm_test__get__comm(r1)->comm.dst_buff != NULL
200 && simcall_comm_wait__get__comm(r2)->comm.src_buff != NULL
201 && simcall_comm_wait__get__comm(r2)->comm.dst_buff != NULL
202 && simcall_comm_test__get__comm(r1)->comm.dst_buff !=
203 simcall_comm_wait__get__comm(r2)->comm.src_buff
204 && simcall_comm_test__get__comm(r1)->comm.dst_buff !=
205 simcall_comm_wait__get__comm(r2)->comm.dst_buff
206 && simcall_comm_wait__get__comm(r2)->comm.dst_buff !=
207 simcall_comm_test__get__comm(r1)->comm.src_buff)
214 static char *pointer_to_string(void *pointer)
217 if (XBT_LOG_ISENABLED(mc_request, xbt_log_priority_verbose))
218 return bprintf("%p", pointer);
220 return xbt_strdup("(verbose only)");
223 static char *buff_size_to_string(size_t buff_size)
226 if (XBT_LOG_ISENABLED(mc_request, xbt_log_priority_verbose))
227 return bprintf("%zu", buff_size);
229 return xbt_strdup("(verbose only)");
233 char *MC_request_to_string(smx_simcall_t req, int value)
235 char *type = NULL, *args = NULL, *str = NULL, *p = NULL, *bs = NULL;
236 smx_synchro_t act = NULL;
239 smx_process_t issuer = MC_smx_simcall_get_issuer(req);
242 case SIMCALL_COMM_ISEND:
243 type = xbt_strdup("iSend");
244 p = pointer_to_string(simcall_comm_isend__get__src_buff(req));
245 bs = buff_size_to_string(simcall_comm_isend__get__src_buff_size(req));
246 if (issuer->smx_host)
248 bprintf("src=(%lu)%s (%s), buff=%s, size=%s", issuer->pid,
249 MC_smx_process_get_host_name(issuer),
250 MC_smx_process_get_name(issuer),
254 bprintf("src=(%lu)%s, buff=%s, size=%s", issuer->pid,
255 MC_smx_process_get_name(issuer), p, bs);
257 case SIMCALL_COMM_IRECV:
259 simcall_comm_irecv__get__dst_buff_size(req) ?
260 *simcall_comm_irecv__get__dst_buff_size(req) : 0;
261 type = xbt_strdup("iRecv");
262 p = pointer_to_string(simcall_comm_irecv__get__dst_buff(req));
263 bs = buff_size_to_string(size);
264 if (issuer->smx_host)
266 bprintf("dst=(%lu)%s (%s), buff=%s, size=%s", issuer->pid,
267 MC_smx_process_get_host_name(issuer),
268 MC_smx_process_get_name(issuer),
272 bprintf("dst=(%lu)%s, buff=%s, size=%s", issuer->pid,
273 MC_smx_process_get_name(issuer),
276 case SIMCALL_COMM_WAIT:
277 act = simcall_comm_wait__get__comm(req);
279 type = xbt_strdup("WaitTimeout");
280 p = pointer_to_string(act);
281 args = bprintf("comm=%s", p);
283 type = xbt_strdup("Wait");
284 p = pointer_to_string(act);
285 // TODO, fix remote access to comm
286 smx_process_t src_proc = MC_smx_resolve_process(act->comm.src_proc);
287 smx_process_t dst_proc = MC_smx_resolve_process(act->comm.dst_proc);
288 args = bprintf("comm=%s [(%lu)%s (%s)-> (%lu)%s (%s)]", p,
289 src_proc ? src_proc->pid : 0,
290 src_proc ? MC_smx_process_get_host_name(src_proc) : "",
291 src_proc ? MC_smx_process_get_name(src_proc) : "",
292 dst_proc ? dst_proc->pid : 0,
293 dst_proc ? MC_smx_process_get_host_name(dst_proc) : "",
294 dst_proc ? MC_smx_process_get_name(dst_proc) : "");
297 case SIMCALL_COMM_TEST:
298 act = simcall_comm_test__get__comm(req);
299 if (act->comm.src_proc == NULL || act->comm.dst_proc == NULL) {
300 type = xbt_strdup("Test FALSE");
301 p = pointer_to_string(act);
302 args = bprintf("comm=%s", p);
304 type = xbt_strdup("Test TRUE");
305 p = pointer_to_string(act);
306 // TODO, get process, get process name
307 smx_process_t src_proc = MC_smx_resolve_process(act->comm.src_proc);
308 smx_process_t dst_proc = MC_smx_resolve_process(act->comm.dst_proc);
309 args = bprintf("comm=%s [(%lu)%s (%s) -> (%lu)%s (%s)]", p,
311 MC_smx_process_get_name(src_proc),
312 MC_smx_process_get_host_name(src_proc),
314 MC_smx_process_get_name(dst_proc),
315 MC_smx_process_get_host_name(dst_proc));
319 case SIMCALL_COMM_WAITANY:
320 type = xbt_strdup("WaitAny");
321 if (!xbt_dynar_is_empty(simcall_comm_waitany__get__comms(req))) {
322 p = pointer_to_string(xbt_dynar_get_as
323 (simcall_comm_waitany__get__comms(req), value,
326 bprintf("comm=%s (%d of %lu)", p, value + 1,
327 xbt_dynar_length(simcall_comm_waitany__get__comms(req)));
329 args = bprintf("comm at idx %d", value);
333 case SIMCALL_COMM_TESTANY:
335 type = xbt_strdup("TestAny FALSE");
336 args = xbt_strdup("-");
338 type = xbt_strdup("TestAny");
340 bprintf("(%d of %lu)", value + 1,
341 xbt_dynar_length(simcall_comm_testany__get__comms(req)));
345 case SIMCALL_MC_SNAPSHOT:
346 type = xbt_strdup("MC_SNAPSHOT");
350 case SIMCALL_MC_COMPARE_SNAPSHOTS:
351 type = xbt_strdup("MC_COMPARE_SNAPSHOTS");
355 case SIMCALL_MC_RANDOM:
356 type = xbt_strdup("MC_RANDOM");
357 args = bprintf("%d", value);
365 // FIXME, get process name
367 bprintf("[(%lu)%s (%s)] %s(%s)", issuer->pid,
368 MC_smx_process_get_host_name(issuer),
369 MC_smx_process_get_name(issuer),
372 // FIXME, get process name
374 bprintf("[(%lu)%s (%s)] %s ", issuer->pid,
375 MC_smx_process_get_host_name(issuer),
376 MC_smx_process_get_name(issuer),
387 unsigned int MC_request_testany_fail(smx_simcall_t req)
390 smx_synchro_t action;
392 xbt_dynar_foreach(simcall_comm_testany__get__comms(req), cursor, action) {
393 // FIXME, remote access to comm object
394 if (action->comm.src_proc && action->comm.dst_proc)
401 int MC_request_is_enabled_by_idx(smx_simcall_t req, unsigned int idx)
405 // FIXME, remote access to comm object
409 case SIMCALL_COMM_WAIT:
410 /* FIXME: check also that src and dst processes are not suspended */
411 act = simcall_comm_wait__get__comm(req);
412 return (act->comm.src_proc && act->comm.dst_proc);
415 case SIMCALL_COMM_WAITANY:
417 xbt_dynar_get_as(simcall_comm_waitany__get__comms(req), idx,
419 return (act->comm.src_proc && act->comm.dst_proc);
422 case SIMCALL_COMM_TESTANY:
424 xbt_dynar_get_as(simcall_comm_testany__get__comms(req), idx,
426 return (act->comm.src_proc && act->comm.dst_proc);
434 int MC_process_is_enabled(smx_process_t process)
436 return MC_request_is_enabled(&process->simcall);
439 char *MC_request_get_dot_output(smx_simcall_t req, int value)
441 char *str = NULL, *label = NULL;
442 smx_synchro_t act = NULL;
444 const smx_process_t issuer = MC_smx_simcall_get_issuer(req);
447 case SIMCALL_COMM_ISEND:
448 if (issuer->smx_host)
450 bprintf("[(%lu)%s] iSend", issuer->pid,
451 MC_smx_process_get_host_name(issuer));
453 label = bprintf("[(%lu)] iSend", issuer->pid);
456 case SIMCALL_COMM_IRECV:
457 if (issuer->smx_host)
459 bprintf("[(%lu)%s] iRecv", issuer->pid,
460 MC_smx_process_get_host_name(issuer));
462 label = bprintf("[(%lu)] iRecv", issuer->pid);
465 case SIMCALL_COMM_WAIT:
466 act = simcall_comm_wait__get__comm(req);
468 if (issuer->smx_host)
470 bprintf("[(%lu)%s] WaitTimeout", issuer->pid,
471 MC_smx_process_get_host_name(issuer));
473 label = bprintf("[(%lu)] WaitTimeout", issuer->pid);
475 if (issuer->smx_host)
477 bprintf("[(%lu)%s] Wait [(%lu)->(%lu)]", issuer->pid,
478 MC_smx_process_get_host_name(issuer),
479 act->comm.src_proc ? act->comm.src_proc->pid : 0,
480 act->comm.dst_proc ? act->comm.dst_proc->pid : 0);
483 bprintf("[(%lu)] Wait [(%lu)->(%lu)]", issuer->pid,
484 act->comm.src_proc ? act->comm.src_proc->pid : 0,
485 act->comm.dst_proc ? act->comm.dst_proc->pid : 0);
489 case SIMCALL_COMM_TEST:
490 act = simcall_comm_test__get__comm(req);
491 if (act->comm.src_proc == NULL || act->comm.dst_proc == NULL) {
492 if (issuer->smx_host)
494 bprintf("[(%lu)%s] Test FALSE", issuer->pid,
495 MC_smx_process_get_host_name(issuer));
497 label = bprintf("[(%lu)] Test FALSE", issuer->pid);
499 if (issuer->smx_host)
501 bprintf("[(%lu)%s] Test TRUE", issuer->pid,
502 MC_smx_process_get_host_name(issuer));
504 label = bprintf("[(%lu)] Test TRUE", issuer->pid);
508 case SIMCALL_COMM_WAITANY:
509 if (issuer->smx_host)
511 bprintf("[(%lu)%s] WaitAny [%d of %lu]", issuer->pid,
512 MC_smx_process_get_host_name(issuer), value + 1,
513 xbt_dynar_length(simcall_comm_waitany__get__comms(req)));
516 bprintf("[(%lu)] WaitAny [%d of %lu]", issuer->pid, value + 1,
517 xbt_dynar_length(simcall_comm_waitany__get__comms(req)));
520 case SIMCALL_COMM_TESTANY:
522 if (issuer->smx_host)
524 bprintf("[(%lu)%s] TestAny FALSE", issuer->pid,
525 MC_smx_process_get_host_name(issuer));
527 label = bprintf("[(%lu)] TestAny FALSE", issuer->pid);
529 if (issuer->smx_host)
531 bprintf("[(%lu)%s] TestAny TRUE [%d of %lu]", issuer->pid,
532 MC_smx_process_get_host_name(issuer), value + 1,
533 xbt_dynar_length(simcall_comm_testany__get__comms(req)));
536 bprintf("[(%lu)] TestAny TRUE [%d of %lu]", issuer->pid,
538 xbt_dynar_length(simcall_comm_testany__get__comms(req)));
542 case SIMCALL_MC_RANDOM:
543 if (issuer->smx_host)
545 bprintf("[(%lu)%s] MC_RANDOM (%d)", issuer->pid,
546 MC_smx_process_get_host_name(issuer), value);
548 label = bprintf("[(%lu)] MC_RANDOM (%d)", issuer->pid, value);
551 case SIMCALL_MC_SNAPSHOT:
552 if (issuer->smx_host)
554 bprintf("[(%lu)%s] MC_SNAPSHOT", issuer->pid,
555 MC_smx_process_get_host_name(issuer));
557 label = bprintf("[(%lu)] MC_SNAPSHOT", issuer->pid);
560 case SIMCALL_MC_COMPARE_SNAPSHOTS:
561 if (issuer->smx_host)
563 bprintf("[(%lu)%s] MC_COMPARE_SNAPSHOTS", issuer->pid,
564 MC_smx_process_get_host_name(issuer));
566 label = bprintf("[(%lu)] MC_COMPARE_SNAPSHOTS", issuer->pid);
574 bprintf("label = \"%s\", color = %s, fontcolor = %s", label,
575 colors[issuer->pid - 1], colors[issuer->pid - 1]);