1 /* Copyright (c) 2008-2013 Da SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "mc_private.h"
8 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_request, mc,
9 "Logging specific to MC (request)");
11 static char* pointer_to_string(void* pointer);
12 static char* buff_size_to_string(size_t size);
14 int MC_request_depend(smx_simcall_t r1, smx_simcall_t r2) {
15 if(mc_reduce_kind == e_mc_reduce_none)
18 if (r1->issuer == r2->issuer)
21 if(r1->call == SIMCALL_COMM_ISEND && r2->call == SIMCALL_COMM_IRECV)
24 if(r1->call == SIMCALL_COMM_IRECV && r2->call == SIMCALL_COMM_ISEND)
27 if((r1->call == SIMCALL_COMM_ISEND || r1->call == SIMCALL_COMM_IRECV)
28 && r2->call == SIMCALL_COMM_WAIT){
30 smx_rdv_t rdv = r1->call == SIMCALL_COMM_ISEND ? simcall_comm_isend__get__rdv(r1) : simcall_comm_irecv__get__rdv(r1);
32 if(rdv != simcall_comm_wait__get__comm(r2)->comm.rdv_cpy && simcall_comm_wait__get__timeout(r2) <= 0)
35 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)
38 if((r1->call == SIMCALL_COMM_ISEND) && (simcall_comm_wait__get__comm(r2)->comm.type == SIMIX_COMM_SEND)
39 && (simcall_comm_wait__get__comm(r2)->comm.src_buff != simcall_comm_isend__get__src_buff(r1)) && simcall_comm_wait__get__timeout(r2) <= 0)
42 if((r1->call == SIMCALL_COMM_IRECV) && (simcall_comm_wait__get__comm(r2)->comm.type == SIMIX_COMM_RECEIVE)
43 && (simcall_comm_wait__get__comm(r2)->comm.dst_buff != simcall_comm_irecv__get__dst_buff(r1)) && simcall_comm_wait__get__timeout(r2) <= 0)
47 if((r2->call == SIMCALL_COMM_ISEND || r2->call == SIMCALL_COMM_IRECV)
48 && r1->call == SIMCALL_COMM_WAIT){
50 smx_rdv_t rdv = r2->call == SIMCALL_COMM_ISEND ? simcall_comm_isend__get__rdv(r2) : simcall_comm_irecv__get__rdv(r2);
52 if(rdv != simcall_comm_wait__get__comm(r1)->comm.rdv_cpy && simcall_comm_wait__get__timeout(r1) <= 0)
55 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)
58 if((r2->call == SIMCALL_COMM_ISEND) && (simcall_comm_wait__get__comm(r1)->comm.type == SIMIX_COMM_SEND)
59 && (simcall_comm_wait__get__comm(r1)->comm.src_buff != simcall_comm_isend__get__src_buff(r2)) && simcall_comm_wait__get__timeout(r1) <= 0)
62 if((r2->call == SIMCALL_COMM_IRECV) && (simcall_comm_wait__get__comm(r1)->comm.type == SIMIX_COMM_RECEIVE)
63 && (simcall_comm_wait__get__comm(r1)->comm.dst_buff != simcall_comm_irecv__get__dst_buff(r2)) && simcall_comm_wait__get__timeout(r1) <= 0)
67 /* FIXME: the following rule assumes that the result of the
68 * isend/irecv call is not stored in a buffer used in the
70 /*if( (r1->call == SIMCALL_COMM_ISEND || r1->call == SIMCALL_COMM_IRECV)
71 && r2->call == SIMCALL_COMM_TEST)
74 /* FIXME: the following rule assumes that the result of the
75 * isend/irecv call is not stored in a buffer used in the
77 /*if( (r2->call == SIMCALL_COMM_ISEND || r2->call == SIMCALL_COMM_IRECV)
78 && r1->call == SIMCALL_COMM_TEST)
81 if(r1->call == SIMCALL_COMM_ISEND && r2->call == SIMCALL_COMM_ISEND
82 && simcall_comm_isend__get__rdv(r1) != simcall_comm_isend__get__rdv(r2))
85 if(r1->call == SIMCALL_COMM_IRECV && r2->call == SIMCALL_COMM_IRECV
86 && simcall_comm_irecv__get__rdv(r1) != simcall_comm_irecv__get__rdv(r2))
89 if(r1->call == SIMCALL_COMM_WAIT && (r2->call == SIMCALL_COMM_WAIT || r2->call == SIMCALL_COMM_TEST)
90 && (simcall_comm_wait__get__comm(r1)->comm.src_proc == NULL
91 || simcall_comm_wait__get__comm(r1)->comm.dst_proc == NULL))
94 if(r2->call == SIMCALL_COMM_WAIT && (r1->call == SIMCALL_COMM_WAIT || r1->call == SIMCALL_COMM_TEST)
95 && (simcall_comm_wait__get__comm(r2)->comm.src_proc == NULL
96 || simcall_comm_wait__get__comm(r2)->comm.dst_proc == NULL))
99 if(r1->call == SIMCALL_COMM_WAIT && r2->call == SIMCALL_COMM_WAIT
100 && simcall_comm_wait__get__comm(r1)->comm.src_buff == simcall_comm_wait__get__comm(r2)->comm.src_buff
101 && simcall_comm_wait__get__comm(r1)->comm.dst_buff == simcall_comm_wait__get__comm(r2)->comm.dst_buff)
104 if (r1->call == SIMCALL_COMM_WAIT && r2->call == SIMCALL_COMM_WAIT
105 && simcall_comm_wait__get__comm(r1)->comm.src_buff != NULL
106 && simcall_comm_wait__get__comm(r1)->comm.dst_buff != NULL
107 && simcall_comm_wait__get__comm(r2)->comm.src_buff != NULL
108 && simcall_comm_wait__get__comm(r2)->comm.dst_buff != NULL
109 && simcall_comm_wait__get__comm(r1)->comm.dst_buff != simcall_comm_wait__get__comm(r2)->comm.src_buff
110 && simcall_comm_wait__get__comm(r1)->comm.dst_buff != simcall_comm_wait__get__comm(r2)->comm.dst_buff
111 && simcall_comm_wait__get__comm(r2)->comm.dst_buff != simcall_comm_wait__get__comm(r1)->comm.src_buff)
114 if(r1->call == SIMCALL_COMM_TEST &&
115 (simcall_comm_test__get__comm(r1) == NULL
116 || simcall_comm_test__get__comm(r1)->comm.src_buff == NULL
117 || simcall_comm_test__get__comm(r1)->comm.dst_buff == NULL))
120 if(r2->call == SIMCALL_COMM_TEST &&
121 (simcall_comm_test__get__comm(r2) == NULL
122 || simcall_comm_test__get__comm(r2)->comm.src_buff == NULL
123 || simcall_comm_test__get__comm(r2)->comm.dst_buff == NULL))
126 if(r1->call == SIMCALL_COMM_TEST && r2->call == SIMCALL_COMM_WAIT
127 && simcall_comm_test__get__comm(r1)->comm.src_buff == simcall_comm_wait__get__comm(r2)->comm.src_buff
128 && simcall_comm_test__get__comm(r1)->comm.dst_buff == simcall_comm_wait__get__comm(r2)->comm.dst_buff)
131 if(r1->call == SIMCALL_COMM_WAIT && r2->call == SIMCALL_COMM_TEST
132 && simcall_comm_wait__get__comm(r1)->comm.src_buff == simcall_comm_test__get__comm(r2)->comm.src_buff
133 && simcall_comm_wait__get__comm(r1)->comm.dst_buff == simcall_comm_test__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 != NULL
138 && simcall_comm_wait__get__comm(r1)->comm.dst_buff != NULL
139 && simcall_comm_test__get__comm(r2)->comm.src_buff != NULL
140 && simcall_comm_test__get__comm(r2)->comm.dst_buff != NULL
141 && simcall_comm_wait__get__comm(r1)->comm.dst_buff != simcall_comm_test__get__comm(r2)->comm.src_buff
142 && simcall_comm_wait__get__comm(r1)->comm.dst_buff != simcall_comm_test__get__comm(r2)->comm.dst_buff
143 && simcall_comm_test__get__comm(r2)->comm.dst_buff != simcall_comm_wait__get__comm(r1)->comm.src_buff)
146 if (r1->call == SIMCALL_COMM_TEST && r2->call == SIMCALL_COMM_WAIT
147 && simcall_comm_test__get__comm(r1)->comm.src_buff != NULL
148 && simcall_comm_test__get__comm(r1)->comm.dst_buff != NULL
149 && simcall_comm_wait__get__comm(r2)->comm.src_buff != NULL
150 && simcall_comm_wait__get__comm(r2)->comm.dst_buff != NULL
151 && simcall_comm_test__get__comm(r1)->comm.dst_buff != simcall_comm_wait__get__comm(r2)->comm.src_buff
152 && simcall_comm_test__get__comm(r1)->comm.dst_buff != simcall_comm_wait__get__comm(r2)->comm.dst_buff
153 && simcall_comm_wait__get__comm(r2)->comm.dst_buff != simcall_comm_test__get__comm(r1)->comm.src_buff)
160 static char* pointer_to_string(void* pointer) {
162 if (XBT_LOG_ISENABLED(mc_request, xbt_log_priority_verbose))
163 return bprintf("%p", pointer);
165 return xbt_strdup("(verbose only)");
168 static char* buff_size_to_string(size_t buff_size) {
170 if (XBT_LOG_ISENABLED(mc_request, xbt_log_priority_verbose))
171 return bprintf("%zu", buff_size);
173 return xbt_strdup("(verbose only)");
177 char *MC_request_to_string(smx_simcall_t req, int value)
179 char *type = NULL, *args = NULL, *str = NULL, *p = NULL, *bs = NULL;
180 smx_action_t act = NULL;
184 case SIMCALL_COMM_ISEND:
185 type = xbt_strdup("iSend");
186 p = pointer_to_string(simcall_comm_isend__get__src_buff(req));
187 bs = buff_size_to_string(simcall_comm_isend__get__src_buff_size(req));
188 if(req->issuer->smx_host)
189 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);
191 args = bprintf("src=(%lu)%s, buff=%s, size=%s", req->issuer->pid, req->issuer->name, p, bs);
193 case SIMCALL_COMM_IRECV:
194 size = simcall_comm_irecv__get__dst_buff_size(req) ? *simcall_comm_irecv__get__dst_buff_size(req) : 0;
195 type = xbt_strdup("iRecv");
196 p = pointer_to_string(simcall_comm_irecv__get__dst_buff(req));
197 bs = buff_size_to_string(size);
198 if(req->issuer->smx_host)
199 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);
201 args = bprintf("dst=(%lu)%s, buff=%s, size=%s", req->issuer->pid, req->issuer->name, p, bs);
203 case SIMCALL_COMM_WAIT:
204 act = simcall_comm_wait__get__comm(req);
206 type = xbt_strdup("WaitTimeout");
207 p = pointer_to_string(act);
208 args = bprintf("comm=%s", p);
210 type = xbt_strdup("Wait");
211 p = pointer_to_string(act);
212 args = bprintf("comm=%s [(%lu)%s (%s)-> (%lu)%s (%s)]", p,
213 act->comm.src_proc ? act->comm.src_proc->pid : 0,
214 act->comm.src_proc ? MSG_host_get_name(act->comm.src_proc->smx_host) : "",
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 ? MSG_host_get_name(act->comm.dst_proc->smx_host) : "",
218 act->comm.dst_proc ? act->comm.dst_proc->name : "");
221 case SIMCALL_COMM_TEST:
222 act = simcall_comm_test__get__comm(req);
223 if(act->comm.src_proc == NULL || act->comm.dst_proc == NULL){
224 type = xbt_strdup("Test FALSE");
225 p = pointer_to_string(act);
226 args = bprintf("comm=%s", p);
228 type = xbt_strdup("Test TRUE");
229 p = pointer_to_string(act);
230 args = bprintf("comm=%s [(%lu)%s (%s) -> (%lu)%s (%s)]", p,
231 act->comm.src_proc->pid, act->comm.src_proc->name, MSG_host_get_name(act->comm.src_proc->smx_host),
232 act->comm.dst_proc->pid, act->comm.dst_proc->name, MSG_host_get_name(act->comm.dst_proc->smx_host));
236 case SIMCALL_COMM_WAITANY:
237 type = xbt_strdup("WaitAny");
238 if(!xbt_dynar_is_empty(simcall_comm_waitany__get__comms(req))){
239 p = pointer_to_string(xbt_dynar_get_as(simcall_comm_waitany__get__comms(req), value, smx_action_t));
240 args = bprintf("comm=%s (%d of %lu)", p,
241 value+1, xbt_dynar_length(simcall_comm_waitany__get__comms(req)));
243 args = bprintf("comm at idx %d", value);
247 case SIMCALL_COMM_TESTANY:
249 type = xbt_strdup("TestAny FALSE");
250 args = xbt_strdup("-");
252 type = xbt_strdup("TestAny");
253 args = bprintf("(%d of %lu)", value+1, xbt_dynar_length(simcall_comm_testany__get__comms(req)));
257 case SIMCALL_MC_SNAPSHOT:
258 type = xbt_strdup("MC_SNAPSHOT");
262 case SIMCALL_MC_COMPARE_SNAPSHOTS:
263 type = xbt_strdup("MC_COMPARE_SNAPSHOTS");
267 case SIMCALL_MC_RANDOM:
268 type = xbt_strdup("MC_RANDOM");
269 args = bprintf("%d", value);
277 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);
279 str = bprintf("[(%lu)%s (%s)] %s (%d) ", req->issuer->pid , MSG_host_get_name(req->issuer->smx_host), req->issuer->name, type, req->call);
289 unsigned int MC_request_testany_fail(smx_simcall_t req)
294 xbt_dynar_foreach(simcall_comm_testany__get__comms(req), cursor, action){
295 if(action->comm.src_proc && action->comm.dst_proc)
302 int MC_request_is_visible(smx_simcall_t req)
304 return req->call == SIMCALL_COMM_ISEND
305 || req->call == SIMCALL_COMM_IRECV
306 || req->call == SIMCALL_COMM_WAIT
307 || req->call == SIMCALL_COMM_WAITANY
308 || req->call == SIMCALL_COMM_TEST
309 || req->call == SIMCALL_COMM_TESTANY
310 || req->call == SIMCALL_MC_RANDOM
311 || req->call == SIMCALL_MC_SNAPSHOT
312 || req->call == SIMCALL_MC_COMPARE_SNAPSHOTS;
315 int MC_request_is_enabled(smx_simcall_t req)
317 unsigned int index = 0;
322 case SIMCALL_COMM_WAIT:
323 /* FIXME: check also that src and dst processes are not suspended */
325 /* If it has a timeout it will be always be enabled, because even if the
326 * communication is not ready, it can timeout and won't block.
327 * On the other hand if it hasn't a timeout, check if the comm is ready.*/
328 if(simcall_comm_wait__get__timeout(req) >= 0){
329 if(_sg_mc_timeout == 1){
332 act = simcall_comm_wait__get__comm(req);
333 return (act->comm.src_proc && act->comm.dst_proc);
336 act = simcall_comm_wait__get__comm(req);
337 return (act->comm.src_proc && act->comm.dst_proc);
341 case SIMCALL_COMM_WAITANY:
342 /* Check if it has at least one communication ready */
343 xbt_dynar_foreach(simcall_comm_waitany__get__comms(req), index, act) {
344 if (act->comm.src_proc && act->comm.dst_proc){
352 /* The rest of the request are always enabled */
357 int MC_request_is_enabled_by_idx(smx_simcall_t req, unsigned int idx)
363 case SIMCALL_COMM_WAIT:
364 /* FIXME: check also that src and dst processes are not suspended */
365 act = simcall_comm_wait__get__comm(req);
366 return (act->comm.src_proc && act->comm.dst_proc);
369 case SIMCALL_COMM_WAITANY:
370 act = xbt_dynar_get_as(simcall_comm_waitany__get__comms(req), idx, smx_action_t);
371 return (act->comm.src_proc && act->comm.dst_proc);
374 case SIMCALL_COMM_TESTANY:
375 act = xbt_dynar_get_as(simcall_comm_testany__get__comms(req), idx, smx_action_t);
376 return (act->comm.src_proc && act->comm.dst_proc);
384 int MC_process_is_enabled(smx_process_t process)
386 if (process->simcall.call != SIMCALL_NONE && MC_request_is_enabled(&process->simcall))
392 char *MC_request_get_dot_output(smx_simcall_t req, int value){
394 char *str = NULL, *label = NULL;
395 smx_action_t act = NULL;
398 case SIMCALL_COMM_ISEND:
399 if(req->issuer->smx_host)
400 label = bprintf("[(%lu)%s] iSend", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host));
402 label = bprintf("[(%lu)] iSend", req->issuer->pid);
405 case SIMCALL_COMM_IRECV:
406 if(req->issuer->smx_host)
407 label = bprintf("[(%lu)%s] iRecv", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host));
409 label = bprintf("[(%lu)] iRecv", req->issuer->pid);
412 case SIMCALL_COMM_WAIT:
413 act = simcall_comm_wait__get__comm(req);
415 if(req->issuer->smx_host)
416 label = bprintf("[(%lu)%s] WaitTimeout", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host));
418 label = bprintf("[(%lu)] WaitTimeout", req->issuer->pid);
420 if(req->issuer->smx_host)
421 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);
423 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);
427 case SIMCALL_COMM_TEST:
428 act = simcall_comm_test__get__comm(req);
429 if(act->comm.src_proc == NULL || act->comm.dst_proc == NULL){
430 if(req->issuer->smx_host)
431 label = bprintf("[(%lu)%s] Test FALSE", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host));
433 label = bprintf("[(%lu)] Test FALSE", req->issuer->pid);
435 if(req->issuer->smx_host)
436 label = bprintf("[(%lu)%s] Test TRUE", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host));
438 label = bprintf("[(%lu)] Test TRUE", req->issuer->pid);
442 case SIMCALL_COMM_WAITANY:
443 if(req->issuer->smx_host)
444 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)));
446 label = bprintf("[(%lu)] WaitAny [%d of %lu]", req->issuer->pid, value+1, xbt_dynar_length(simcall_comm_waitany__get__comms(req)));
449 case SIMCALL_COMM_TESTANY:
451 if(req->issuer->smx_host)
452 label = bprintf("[(%lu)%s] TestAny FALSE", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host));
454 label = bprintf("[(%lu)] TestAny FALSE", req->issuer->pid);
456 if(req->issuer->smx_host)
457 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)));
459 label = bprintf("[(%lu)] TestAny TRUE [%d of %lu]", req->issuer->pid, value+1, xbt_dynar_length(simcall_comm_testany__get__comms(req)));
463 case SIMCALL_MC_RANDOM:
464 if(req->issuer->smx_host)
465 label = bprintf("[(%lu)%s] MC_RANDOM (%d)", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host), value);
467 label = bprintf("[(%lu)] MC_RANDOM (%d)", req->issuer->pid, value);
470 case SIMCALL_MC_SNAPSHOT:
471 if(req->issuer->smx_host)
472 label = bprintf("[(%lu)%s] MC_SNAPSHOT", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host));
474 label = bprintf("[(%lu)] MC_SNAPSHOT", req->issuer->pid);
477 case SIMCALL_MC_COMPARE_SNAPSHOTS:
478 if(req->issuer->smx_host)
479 label = bprintf("[(%lu)%s] MC_COMPARE_SNAPSHOTS", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host));
481 label = bprintf("[(%lu)] MC_COMPARE_SNAPSHOTS", req->issuer->pid);
488 str = bprintf("label = \"%s\", color = %s, fontcolor = %s", label, colors[req->issuer->pid-1], colors[req->issuer->pid-1]);