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 // Read object from MCed memory:
39 s_smx_synchro_t synchro1, synchro2;
40 if (r1->call == SIMCALL_COMM_WAIT) {
41 MC_process_read_simple(&mc_model_checker->process, &synchro1,
42 simcall_comm_wait__get__comm(r1), sizeof(synchro1));
44 if (r2->call == SIMCALL_COMM_WAIT) {
45 MC_process_read_simple(&mc_model_checker->process, &synchro2,
46 simcall_comm_wait__get__comm(r2), sizeof(synchro2));
48 if (r1->call == SIMCALL_COMM_TEST) {
49 MC_process_read_simple(&mc_model_checker->process, &synchro1,
50 simcall_comm_test__get__comm(r1), sizeof(synchro1));
52 if (r2->call == SIMCALL_COMM_TEST) {
53 MC_process_read_simple(&mc_model_checker->process, &synchro2,
54 simcall_comm_test__get__comm(r2), sizeof(synchro2));
57 if ((r1->call == SIMCALL_COMM_ISEND || r1->call == SIMCALL_COMM_IRECV)
58 && r2->call == SIMCALL_COMM_WAIT) {
62 SIMCALL_COMM_ISEND ? simcall_comm_isend__get__rdv(r1) :
63 simcall_comm_irecv__get__rdv(r1);
65 // FIXME, remote access to comm object
67 if (rdv != synchro2.comm.rdv_cpy
68 && simcall_comm_wait__get__timeout(r2) <= 0)
71 if ((r1->issuer != synchro2.comm.src_proc)
72 && (r1->issuer != synchro2.comm.dst_proc)
73 && simcall_comm_wait__get__timeout(r2) <= 0)
76 if ((r1->call == SIMCALL_COMM_ISEND)
77 && (synchro2.comm.type == SIMIX_COMM_SEND)
78 && (synchro2.comm.src_buff !=
79 simcall_comm_isend__get__src_buff(r1))
80 && simcall_comm_wait__get__timeout(r2) <= 0)
83 if ((r1->call == SIMCALL_COMM_IRECV)
84 && (synchro2.comm.type == SIMIX_COMM_RECEIVE)
85 && (synchro2.comm.dst_buff != simcall_comm_irecv__get__dst_buff(r1))
86 && simcall_comm_wait__get__timeout(r2) <= 0)
90 if ((r2->call == SIMCALL_COMM_ISEND || r2->call == SIMCALL_COMM_IRECV)
91 && r1->call == SIMCALL_COMM_WAIT) {
95 SIMCALL_COMM_ISEND ? simcall_comm_isend__get__rdv(r2) :
96 simcall_comm_irecv__get__rdv(r2);
98 if (rdv != synchro1.comm.rdv_cpy
99 && simcall_comm_wait__get__timeout(r1) <= 0)
102 if ((r2->issuer != synchro1.comm.src_proc)
103 && (r2->issuer != synchro1.comm.dst_proc)
104 && simcall_comm_wait__get__timeout(r1) <= 0)
107 if ((r2->call == SIMCALL_COMM_ISEND)
108 && (synchro1.comm.type == SIMIX_COMM_SEND)
109 && (synchro1.comm.src_buff !=
110 simcall_comm_isend__get__src_buff(r2))
111 && simcall_comm_wait__get__timeout(r1) <= 0)
114 if ((r2->call == SIMCALL_COMM_IRECV)
115 && (synchro1.comm.type == SIMIX_COMM_RECEIVE)
116 && (synchro1.comm.dst_buff !=
117 simcall_comm_irecv__get__dst_buff(r2))
118 && simcall_comm_wait__get__timeout(r1) <= 0)
122 /* FIXME: the following rule assumes that the result of the
123 * isend/irecv call is not stored in a buffer used in the
125 /*if( (r1->call == SIMCALL_COMM_ISEND || r1->call == SIMCALL_COMM_IRECV)
126 && r2->call == SIMCALL_COMM_TEST)
129 /* FIXME: the following rule assumes that the result of the
130 * isend/irecv call is not stored in a buffer used in the
132 /*if( (r2->call == SIMCALL_COMM_ISEND || r2->call == SIMCALL_COMM_IRECV)
133 && r1->call == SIMCALL_COMM_TEST)
136 if (r1->call == SIMCALL_COMM_ISEND && r2->call == SIMCALL_COMM_ISEND
137 && simcall_comm_isend__get__rdv(r1) != simcall_comm_isend__get__rdv(r2))
140 if (r1->call == SIMCALL_COMM_IRECV && r2->call == SIMCALL_COMM_IRECV
141 && simcall_comm_irecv__get__rdv(r1) != simcall_comm_irecv__get__rdv(r2))
144 if (r1->call == SIMCALL_COMM_WAIT
145 && (r2->call == SIMCALL_COMM_WAIT || r2->call == SIMCALL_COMM_TEST)
146 && (synchro1.comm.src_proc == NULL || synchro1.comm.dst_proc == NULL))
149 if (r2->call == SIMCALL_COMM_WAIT
150 && (r1->call == SIMCALL_COMM_WAIT || r1->call == SIMCALL_COMM_TEST)
151 && (synchro2.comm.src_proc == NULL || synchro2.comm.dst_proc == NULL))
154 if (r1->call == SIMCALL_COMM_WAIT && r2->call == SIMCALL_COMM_WAIT
155 && synchro1.comm.src_buff == synchro2.comm.src_buff
156 && synchro2.comm.dst_buff == synchro2.comm.dst_buff)
159 if (r1->call == SIMCALL_COMM_WAIT && r2->call == SIMCALL_COMM_WAIT
160 && synchro1.comm.src_buff != NULL
161 && synchro1.comm.dst_buff != NULL
162 && synchro2.comm.src_buff != NULL
163 && synchro2.comm.dst_buff != NULL
164 && synchro1.comm.dst_buff != synchro2.comm.src_buff
165 && synchro1.comm.dst_buff != synchro2.comm.dst_buff
166 && synchro2.comm.dst_buff != synchro1.comm.src_buff)
169 if (r1->call == SIMCALL_COMM_TEST &&
170 (simcall_comm_test__get__comm(r1) == NULL
171 || synchro1.comm.src_buff == NULL
172 || synchro1.comm.dst_buff == NULL))
175 if (r2->call == SIMCALL_COMM_TEST &&
176 (simcall_comm_test__get__comm(r2) == NULL
177 || synchro2.comm.src_buff == NULL
178 || synchro2.comm.dst_buff == NULL))
181 if (r1->call == SIMCALL_COMM_TEST && r2->call == SIMCALL_COMM_WAIT
182 && synchro1.comm.src_buff == synchro2.comm.src_buff
183 && synchro1.comm.dst_buff == synchro2.comm.dst_buff)
186 if (r1->call == SIMCALL_COMM_WAIT && r2->call == SIMCALL_COMM_TEST
187 && synchro1.comm.src_buff == synchro2.comm.src_buff
188 && synchro1.comm.dst_buff == synchro2.comm.dst_buff)
191 if (r1->call == SIMCALL_COMM_WAIT && r2->call == SIMCALL_COMM_TEST
192 && synchro1.comm.src_buff != NULL
193 && synchro1.comm.dst_buff != NULL
194 && synchro2.comm.src_buff != NULL
195 && synchro2.comm.dst_buff != NULL
196 && synchro1.comm.dst_buff != synchro2.comm.src_buff
197 && synchro1.comm.dst_buff != synchro2.comm.dst_buff
198 && synchro2.comm.dst_buff != synchro1.comm.src_buff)
201 if (r1->call == SIMCALL_COMM_TEST && r2->call == SIMCALL_COMM_WAIT
202 && synchro1.comm.src_buff != NULL
203 && synchro1.comm.dst_buff != NULL
204 && synchro2.comm.src_buff != NULL
205 && synchro2.comm.dst_buff != NULL
206 && synchro1.comm.dst_buff != synchro2.comm.src_buff
207 && synchro1.comm.dst_buff != synchro2.comm.dst_buff
208 && synchro2.comm.dst_buff != synchro1.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;
237 smx_mutex_t mutex = NULL;
240 smx_process_t issuer = MC_smx_simcall_get_issuer(req);
243 case SIMCALL_COMM_ISEND:
244 type = xbt_strdup("iSend");
245 p = pointer_to_string(simcall_comm_isend__get__src_buff(req));
246 bs = buff_size_to_string(simcall_comm_isend__get__src_buff_size(req));
247 if (issuer->smx_host)
249 bprintf("src=(%lu)%s (%s), buff=%s, size=%s", issuer->pid,
250 MC_smx_process_get_host_name(issuer),
251 MC_smx_process_get_name(issuer),
255 bprintf("src=(%lu)%s, buff=%s, size=%s", issuer->pid,
256 MC_smx_process_get_name(issuer), p, bs);
258 case SIMCALL_COMM_IRECV:
260 simcall_comm_irecv__get__dst_buff_size(req) ?
261 *simcall_comm_irecv__get__dst_buff_size(req) : 0;
262 type = xbt_strdup("iRecv");
263 p = pointer_to_string(simcall_comm_irecv__get__dst_buff(req));
264 bs = buff_size_to_string(size);
265 if (issuer->smx_host)
267 bprintf("dst=(%lu)%s (%s), buff=%s, size=%s", issuer->pid,
268 MC_smx_process_get_host_name(issuer),
269 MC_smx_process_get_name(issuer),
273 bprintf("dst=(%lu)%s, buff=%s, size=%s", issuer->pid,
274 MC_smx_process_get_name(issuer),
277 case SIMCALL_COMM_WAIT:
278 act = simcall_comm_wait__get__comm(req);
280 type = xbt_strdup("WaitTimeout");
281 p = pointer_to_string(act);
282 args = bprintf("comm=%s", p);
284 type = xbt_strdup("Wait");
285 p = pointer_to_string(act);
286 // TODO, fix remote access to comm
287 smx_process_t src_proc = MC_smx_resolve_process(act->comm.src_proc);
288 smx_process_t dst_proc = MC_smx_resolve_process(act->comm.dst_proc);
289 args = bprintf("comm=%s [(%lu)%s (%s)-> (%lu)%s (%s)]", p,
290 src_proc ? src_proc->pid : 0,
291 src_proc ? MC_smx_process_get_host_name(src_proc) : "",
292 src_proc ? MC_smx_process_get_name(src_proc) : "",
293 dst_proc ? dst_proc->pid : 0,
294 dst_proc ? MC_smx_process_get_host_name(dst_proc) : "",
295 dst_proc ? MC_smx_process_get_name(dst_proc) : "");
298 case SIMCALL_COMM_TEST:
299 act = simcall_comm_test__get__comm(req);
300 if (act->comm.src_proc == NULL || act->comm.dst_proc == NULL) {
301 type = xbt_strdup("Test FALSE");
302 p = pointer_to_string(act);
303 args = bprintf("comm=%s", p);
305 type = xbt_strdup("Test TRUE");
306 p = pointer_to_string(act);
307 // TODO, get process, get process name
308 smx_process_t src_proc = MC_smx_resolve_process(act->comm.src_proc);
309 smx_process_t dst_proc = MC_smx_resolve_process(act->comm.dst_proc);
310 args = bprintf("comm=%s [(%lu)%s (%s) -> (%lu)%s (%s)]", p,
312 MC_smx_process_get_name(src_proc),
313 MC_smx_process_get_host_name(src_proc),
315 MC_smx_process_get_name(dst_proc),
316 MC_smx_process_get_host_name(dst_proc));
320 case SIMCALL_COMM_WAITANY:
321 type = xbt_strdup("WaitAny");
322 if (!xbt_dynar_is_empty(simcall_comm_waitany__get__comms(req))) {
323 p = pointer_to_string(xbt_dynar_get_as
324 (simcall_comm_waitany__get__comms(req), value,
327 bprintf("comm=%s (%d of %lu)", p, value + 1,
328 xbt_dynar_length(simcall_comm_waitany__get__comms(req)));
330 args = bprintf("comm at idx %d", value);
334 case SIMCALL_COMM_TESTANY:
336 type = xbt_strdup("TestAny FALSE");
337 args = xbt_strdup("-");
339 type = xbt_strdup("TestAny");
341 bprintf("(%d of %lu)", value + 1,
342 xbt_dynar_length(simcall_comm_testany__get__comms(req)));
346 case SIMCALL_MUTEX_LOCK:
347 mutex = simcall_mutex_lock__get__mutex(req);
348 type = xbt_strdup("Mutex LOCK");
349 args = bprintf("locked = %d, owner = %d, sleeping = %d", mutex->locked, mutex->owner != NULL ? (int)mutex->owner->pid : -1, xbt_swag_size(mutex->sleeping));
352 case SIMCALL_MC_SNAPSHOT:
353 type = xbt_strdup("MC_SNAPSHOT");
357 case SIMCALL_MC_COMPARE_SNAPSHOTS:
358 type = xbt_strdup("MC_COMPARE_SNAPSHOTS");
362 case SIMCALL_MC_RANDOM:
363 type = xbt_strdup("MC_RANDOM");
364 args = bprintf("%d", value);
372 // FIXME, get process name
374 bprintf("[(%lu)%s (%s)] %s(%s)", issuer->pid,
375 MC_smx_process_get_host_name(issuer),
376 MC_smx_process_get_name(issuer),
379 // FIXME, get process name
381 bprintf("[(%lu)%s (%s)] %s ", issuer->pid,
382 MC_smx_process_get_host_name(issuer),
383 MC_smx_process_get_name(issuer),
394 unsigned int MC_request_testany_fail(smx_simcall_t req)
397 smx_synchro_t action;
399 xbt_dynar_foreach(simcall_comm_testany__get__comms(req), cursor, action) {
400 // FIXME, remote access to comm object
401 if (action->comm.src_proc && action->comm.dst_proc)
408 int MC_request_is_enabled_by_idx(smx_simcall_t req, unsigned int idx)
412 // FIXME, remote access to comm object
416 case SIMCALL_COMM_WAIT:
417 /* FIXME: check also that src and dst processes are not suspended */
418 act = simcall_comm_wait__get__comm(req);
419 return (act->comm.src_proc && act->comm.dst_proc);
422 case SIMCALL_COMM_WAITANY:
424 xbt_dynar_get_as(simcall_comm_waitany__get__comms(req), idx,
426 return (act->comm.src_proc && act->comm.dst_proc);
429 case SIMCALL_COMM_TESTANY:
431 xbt_dynar_get_as(simcall_comm_testany__get__comms(req), idx,
433 return (act->comm.src_proc && act->comm.dst_proc);
441 int MC_process_is_enabled(smx_process_t process)
443 return MC_request_is_enabled(&process->simcall);
446 char *MC_request_get_dot_output(smx_simcall_t req, int value)
448 char *str = NULL, *label = NULL;
449 smx_synchro_t act = NULL;
451 const smx_process_t issuer = MC_smx_simcall_get_issuer(req);
454 case SIMCALL_COMM_ISEND:
455 if (issuer->smx_host)
457 bprintf("[(%lu)%s] iSend", issuer->pid,
458 MC_smx_process_get_host_name(issuer));
460 label = bprintf("[(%lu)] iSend", issuer->pid);
463 case SIMCALL_COMM_IRECV:
464 if (issuer->smx_host)
466 bprintf("[(%lu)%s] iRecv", issuer->pid,
467 MC_smx_process_get_host_name(issuer));
469 label = bprintf("[(%lu)] iRecv", issuer->pid);
472 case SIMCALL_COMM_WAIT:
473 act = simcall_comm_wait__get__comm(req);
475 if (issuer->smx_host)
477 bprintf("[(%lu)%s] WaitTimeout", issuer->pid,
478 MC_smx_process_get_host_name(issuer));
480 label = bprintf("[(%lu)] WaitTimeout", issuer->pid);
482 // FIXME, remote access to act->comm
483 smx_process_t src_proc = MC_smx_resolve_process(act->comm.src_proc);
484 smx_process_t dst_proc = MC_smx_resolve_process(act->comm.dst_proc);
485 if (issuer->smx_host)
487 bprintf("[(%lu)%s] Wait [(%lu)->(%lu)]", issuer->pid,
488 MC_smx_process_get_host_name(issuer),
489 src_proc ? src_proc->pid : 0,
490 dst_proc ? dst_proc->pid : 0);
493 bprintf("[(%lu)] Wait [(%lu)->(%lu)]", issuer->pid,
494 src_proc ? src_proc->pid : 0,
495 dst_proc ? dst_proc->pid : 0);
499 case SIMCALL_COMM_TEST:
500 act = simcall_comm_test__get__comm(req);
501 if (act->comm.src_proc == NULL || act->comm.dst_proc == NULL) {
502 if (issuer->smx_host)
504 bprintf("[(%lu)%s] Test FALSE", issuer->pid,
505 MC_smx_process_get_host_name(issuer));
507 label = bprintf("[(%lu)] Test FALSE", issuer->pid);
509 if (issuer->smx_host)
511 bprintf("[(%lu)%s] Test TRUE", issuer->pid,
512 MC_smx_process_get_host_name(issuer));
514 label = bprintf("[(%lu)] Test TRUE", issuer->pid);
518 case SIMCALL_COMM_WAITANY:
519 if (issuer->smx_host)
521 bprintf("[(%lu)%s] WaitAny [%d of %lu]", issuer->pid,
522 MC_smx_process_get_host_name(issuer), value + 1,
523 xbt_dynar_length(simcall_comm_waitany__get__comms(req)));
526 bprintf("[(%lu)] WaitAny [%d of %lu]", issuer->pid, value + 1,
527 xbt_dynar_length(simcall_comm_waitany__get__comms(req)));
530 case SIMCALL_COMM_TESTANY:
532 if (issuer->smx_host)
534 bprintf("[(%lu)%s] TestAny FALSE", issuer->pid,
535 MC_smx_process_get_host_name(issuer));
537 label = bprintf("[(%lu)] TestAny FALSE", issuer->pid);
539 if (issuer->smx_host)
541 bprintf("[(%lu)%s] TestAny TRUE [%d of %lu]", issuer->pid,
542 MC_smx_process_get_host_name(issuer), value + 1,
543 xbt_dynar_length(simcall_comm_testany__get__comms(req)));
546 bprintf("[(%lu)] TestAny TRUE [%d of %lu]", issuer->pid,
548 xbt_dynar_length(simcall_comm_testany__get__comms(req)));
552 case SIMCALL_MUTEX_LOCK:
553 label = bprintf("[(%lu)] Mutex LOCK", req->issuer->pid);
556 case SIMCALL_MC_RANDOM:
557 if (issuer->smx_host)
559 bprintf("[(%lu)%s] MC_RANDOM (%d)", issuer->pid,
560 MC_smx_process_get_host_name(issuer), value);
562 label = bprintf("[(%lu)] MC_RANDOM (%d)", issuer->pid, value);
565 case SIMCALL_MC_SNAPSHOT:
566 if (issuer->smx_host)
568 bprintf("[(%lu)%s] MC_SNAPSHOT", issuer->pid,
569 MC_smx_process_get_host_name(issuer));
571 label = bprintf("[(%lu)] MC_SNAPSHOT", issuer->pid);
574 case SIMCALL_MC_COMPARE_SNAPSHOTS:
575 if (issuer->smx_host)
577 bprintf("[(%lu)%s] MC_COMPARE_SNAPSHOTS", issuer->pid,
578 MC_smx_process_get_host_name(issuer));
580 label = bprintf("[(%lu)] MC_COMPARE_SNAPSHOTS", issuer->pid);
588 bprintf("label = \"%s\", color = %s, fontcolor = %s", label,
589 colors[issuer->pid - 1], colors[issuer->pid - 1]);