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 if(simcall_comm_wait__get__comm(r2)->comm.rdv == NULL)
33 smx_rdv_t rdv = r1->call == SIMCALL_COMM_ISEND ? simcall_comm_isend__get__rdv(r1) : simcall_comm_irecv__get__rdv(r1);
35 if((simcall_comm_wait__get__comm(r2)->comm.rdv != rdv) && (simcall_comm_wait__get__timeout(r2) <= 0))
38 if((simcall_comm_wait__get__comm(r2)->comm.type == SIMIX_COMM_SEND) && (r1->call == SIMCALL_COMM_ISEND) && (simcall_comm_wait__get__timeout(r2) <= 0))
41 if((simcall_comm_wait__get__comm(r2)->comm.type == SIMIX_COMM_RECEIVE) && (r1->call == SIMCALL_COMM_IRECV) && (simcall_comm_wait__get__timeout(r2) <= 0))
45 if( (r2->call == SIMCALL_COMM_ISEND || r2->call == SIMCALL_COMM_IRECV)
46 && r1->call == SIMCALL_COMM_WAIT){
48 if(simcall_comm_wait__get__comm(r1)->comm.rdv != NULL)
51 smx_rdv_t rdv = r2->call == SIMCALL_COMM_ISEND ? simcall_comm_isend__get__rdv(r2) : simcall_comm_irecv__get__rdv(r2);
53 if((simcall_comm_wait__get__comm(r1)->comm.rdv != rdv) && (simcall_comm_wait__get__timeout(r1) <= 0))
56 if((simcall_comm_wait__get__comm(r1)->comm.type == SIMIX_COMM_SEND) && (r2->call == SIMCALL_COMM_ISEND) && (simcall_comm_wait__get__timeout(r1) <= 0))
59 if((simcall_comm_wait__get__comm(r1)->comm.type == SIMIX_COMM_RECEIVE) && (r2->call == SIMCALL_COMM_IRECV) && (simcall_comm_wait__get__timeout(r1) <= 0))
63 /* FIXME: the following rule assumes that the result of the
64 * isend/irecv call is not stored in a buffer used in the
66 /*if( (r1->call == SIMCALL_COMM_ISEND || r1->call == SIMCALL_COMM_IRECV)
67 && r2->call == SIMCALL_COMM_TEST)
70 /* FIXME: the following rule assumes that the result of the
71 * isend/irecv call is not stored in a buffer used in the
73 /*if( (r2->call == SIMCALL_COMM_ISEND || r2->call == SIMCALL_COMM_IRECV)
74 && r1->call == SIMCALL_COMM_TEST)
77 if(r1->call == SIMCALL_COMM_ISEND && r2->call == SIMCALL_COMM_ISEND
78 && simcall_comm_isend__get__rdv(r1) != simcall_comm_isend__get__rdv(r2))
81 if(r1->call == SIMCALL_COMM_IRECV && r2->call == SIMCALL_COMM_IRECV
82 && simcall_comm_irecv__get__rdv(r1) != simcall_comm_irecv__get__rdv(r2))
85 if(r1->call == SIMCALL_COMM_WAIT && (r2->call == SIMCALL_COMM_WAIT || r2->call == SIMCALL_COMM_TEST)
86 && (simcall_comm_wait__get__comm(r1)->comm.src_proc == NULL
87 || simcall_comm_wait__get__comm(r1)->comm.dst_proc == NULL))
90 if(r2->call == SIMCALL_COMM_WAIT && (r1->call == SIMCALL_COMM_WAIT || r1->call == SIMCALL_COMM_TEST)
91 && (simcall_comm_wait__get__comm(r2)->comm.src_proc == NULL
92 || simcall_comm_wait__get__comm(r2)->comm.dst_proc == NULL))
95 if(r1->call == SIMCALL_COMM_WAIT && r2->call == SIMCALL_COMM_WAIT
96 && simcall_comm_wait__get__comm(r1)->comm.src_buff == simcall_comm_wait__get__comm(r2)->comm.src_buff
97 && simcall_comm_wait__get__comm(r1)->comm.dst_buff == simcall_comm_wait__get__comm(r2)->comm.dst_buff)
100 if (r1->call == SIMCALL_COMM_WAIT && r2->call == SIMCALL_COMM_WAIT
101 && simcall_comm_wait__get__comm(r1)->comm.src_buff != NULL
102 && simcall_comm_wait__get__comm(r1)->comm.dst_buff != NULL
103 && simcall_comm_wait__get__comm(r2)->comm.src_buff != NULL
104 && simcall_comm_wait__get__comm(r2)->comm.dst_buff != NULL
105 && simcall_comm_wait__get__comm(r1)->comm.dst_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
107 && simcall_comm_wait__get__comm(r2)->comm.dst_buff != simcall_comm_wait__get__comm(r1)->comm.src_buff)
110 if(r1->call == SIMCALL_COMM_TEST &&
111 (simcall_comm_test__get__comm(r1) == NULL
112 || simcall_comm_test__get__comm(r1)->comm.src_buff == NULL
113 || simcall_comm_test__get__comm(r1)->comm.dst_buff == NULL))
116 if(r2->call == SIMCALL_COMM_TEST &&
117 (simcall_comm_test__get__comm(r2) == NULL
118 || simcall_comm_test__get__comm(r2)->comm.src_buff == NULL
119 || simcall_comm_test__get__comm(r2)->comm.dst_buff == NULL))
122 if(r1->call == SIMCALL_COMM_TEST && r2->call == SIMCALL_COMM_WAIT
123 && simcall_comm_test__get__comm(r1)->comm.src_buff == simcall_comm_wait__get__comm(r2)->comm.src_buff
124 && simcall_comm_test__get__comm(r1)->comm.dst_buff == simcall_comm_wait__get__comm(r2)->comm.dst_buff)
127 if(r1->call == SIMCALL_COMM_WAIT && r2->call == SIMCALL_COMM_TEST
128 && simcall_comm_wait__get__comm(r1)->comm.src_buff == simcall_comm_test__get__comm(r2)->comm.src_buff
129 && simcall_comm_wait__get__comm(r1)->comm.dst_buff == simcall_comm_test__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 != NULL
134 && simcall_comm_wait__get__comm(r1)->comm.dst_buff != NULL
135 && simcall_comm_test__get__comm(r2)->comm.src_buff != NULL
136 && simcall_comm_test__get__comm(r2)->comm.dst_buff != NULL
137 && simcall_comm_wait__get__comm(r1)->comm.dst_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
139 && simcall_comm_test__get__comm(r2)->comm.dst_buff != simcall_comm_wait__get__comm(r1)->comm.src_buff)
142 if (r1->call == SIMCALL_COMM_TEST && r2->call == SIMCALL_COMM_WAIT
143 && simcall_comm_test__get__comm(r1)->comm.src_buff != NULL
144 && simcall_comm_test__get__comm(r1)->comm.dst_buff != NULL
145 && simcall_comm_wait__get__comm(r2)->comm.src_buff != NULL
146 && simcall_comm_wait__get__comm(r2)->comm.dst_buff != NULL
147 && simcall_comm_test__get__comm(r1)->comm.dst_buff != simcall_comm_wait__get__comm(r2)->comm.src_buff
148 && simcall_comm_test__get__comm(r1)->comm.dst_buff != simcall_comm_wait__get__comm(r2)->comm.dst_buff
149 && simcall_comm_wait__get__comm(r2)->comm.dst_buff != simcall_comm_test__get__comm(r1)->comm.src_buff)
156 static char* pointer_to_string(void* pointer) {
158 if (XBT_LOG_ISENABLED(mc_request, xbt_log_priority_verbose))
159 return bprintf("%p", pointer);
161 return xbt_strdup("(verbose only)");
164 static char* buff_size_to_string(size_t buff_size) {
166 if (XBT_LOG_ISENABLED(mc_request, xbt_log_priority_verbose))
167 return bprintf("%zu", buff_size);
169 return xbt_strdup("(verbose only)");
173 char *MC_request_to_string(smx_simcall_t req, int value)
175 char *type = NULL, *args = NULL, *str = NULL, *p = NULL, *bs = NULL;
176 smx_action_t act = NULL;
180 case SIMCALL_COMM_ISEND:
181 type = xbt_strdup("iSend");
182 p = pointer_to_string(simcall_comm_isend__get__src_buff(req));
183 bs = buff_size_to_string(simcall_comm_isend__get__src_buff_size(req));
184 if(req->issuer->smx_host)
185 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);
187 args = bprintf("src=(%lu)%s, buff=%s, size=%s", req->issuer->pid, req->issuer->name, p, bs);
189 case SIMCALL_COMM_IRECV:
190 size = simcall_comm_irecv__get__dst_buff_size(req) ? *simcall_comm_irecv__get__dst_buff_size(req) : 0;
191 type = xbt_strdup("iRecv");
192 p = pointer_to_string(simcall_comm_irecv__get__dst_buff(req));
193 bs = buff_size_to_string(size);
194 if(req->issuer->smx_host)
195 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);
197 args = bprintf("dst=(%lu)%s, buff=%s, size=%s", req->issuer->pid, req->issuer->name, p, bs);
199 case SIMCALL_COMM_WAIT:
200 act = simcall_comm_wait__get__comm(req);
202 type = xbt_strdup("WaitTimeout");
203 p = pointer_to_string(act);
204 args = bprintf("comm=%s", p);
206 type = xbt_strdup("Wait");
207 p = pointer_to_string(act);
208 args = bprintf("comm=%s [(%lu)%s (%s)-> (%lu)%s (%s)]", p,
209 act->comm.src_proc ? act->comm.src_proc->pid : 0,
210 act->comm.src_proc ? MSG_host_get_name(act->comm.src_proc->smx_host) : "",
211 act->comm.src_proc ? act->comm.src_proc->name : "",
212 act->comm.dst_proc ? act->comm.dst_proc->pid : 0,
213 act->comm.dst_proc ? MSG_host_get_name(act->comm.dst_proc->smx_host) : "",
214 act->comm.dst_proc ? act->comm.dst_proc->name : "");
217 case SIMCALL_COMM_TEST:
218 act = simcall_comm_test__get__comm(req);
219 if(act->comm.src_proc == NULL || act->comm.dst_proc == NULL){
220 type = xbt_strdup("Test FALSE");
221 p = pointer_to_string(act);
222 args = bprintf("comm=%s", p);
224 type = xbt_strdup("Test TRUE");
225 p = pointer_to_string(act);
226 args = bprintf("comm=%s [(%lu)%s (%s) -> (%lu)%s (%s)]", p,
227 act->comm.src_proc->pid, act->comm.src_proc->name, MSG_host_get_name(act->comm.src_proc->smx_host),
228 act->comm.dst_proc->pid, act->comm.dst_proc->name, MSG_host_get_name(act->comm.dst_proc->smx_host));
232 case SIMCALL_COMM_WAITANY:
233 type = xbt_strdup("WaitAny");
234 if(!xbt_dynar_is_empty(simcall_comm_waitany__get__comms(req))){
235 p = pointer_to_string(xbt_dynar_get_as(simcall_comm_waitany__get__comms(req), value, smx_action_t));
236 args = bprintf("comm=%s (%d of %lu)", p,
237 value+1, xbt_dynar_length(simcall_comm_waitany__get__comms(req)));
239 args = bprintf("comm at idx %d", value);
243 case SIMCALL_COMM_TESTANY:
245 type = xbt_strdup("TestAny FALSE");
246 args = xbt_strdup("-");
248 type = xbt_strdup("TestAny");
249 args = bprintf("(%d of %lu)", value+1, xbt_dynar_length(simcall_comm_testany__get__comms(req)));
253 case SIMCALL_MC_SNAPSHOT:
254 type = xbt_strdup("MC_SNAPSHOT");
258 case SIMCALL_MC_COMPARE_SNAPSHOTS:
259 type = xbt_strdup("MC_COMPARE_SNAPSHOTS");
263 case SIMCALL_MC_RANDOM:
264 type = xbt_strdup("MC_RANDOM");
265 args = bprintf("%d", value);
273 str = bprintf("[(%lu)%s (%s)] %s (%s)", req->issuer->pid , MSG_host_get_name(req->issuer->smx_host), req->issuer->name, type, args);
276 str = bprintf("[(%lu)%s (%s)] %s ", req->issuer->pid , MSG_host_get_name(req->issuer->smx_host), req->issuer->name, type);
284 unsigned int MC_request_testany_fail(smx_simcall_t req)
289 xbt_dynar_foreach(simcall_comm_testany__get__comms(req), cursor, action){
290 if(action->comm.src_proc && action->comm.dst_proc)
297 int MC_request_is_visible(smx_simcall_t req)
299 return req->call == SIMCALL_COMM_ISEND
300 || req->call == SIMCALL_COMM_IRECV
301 || req->call == SIMCALL_COMM_WAIT
302 || req->call == SIMCALL_COMM_WAITANY
303 || req->call == SIMCALL_COMM_TEST
304 || req->call == SIMCALL_COMM_TESTANY
305 || req->call == SIMCALL_MC_RANDOM
306 || req->call == SIMCALL_MC_SNAPSHOT
307 || req->call == SIMCALL_MC_COMPARE_SNAPSHOTS;
310 int MC_request_is_enabled(smx_simcall_t req)
312 unsigned int index = 0;
317 case SIMCALL_COMM_WAIT:
318 /* FIXME: check also that src and dst processes are not suspended */
320 /* If it has a timeout it will be always be enabled, because even if the
321 * communication is not ready, it can timeout and won't block.
322 * On the other hand if it hasn't a timeout, check if the comm is ready.*/
323 if(simcall_comm_wait__get__timeout(req) >= 0){
324 if(_sg_mc_timeout == 1){
327 act = simcall_comm_wait__get__comm(req);
328 return (act->comm.src_proc && act->comm.dst_proc);
331 act = simcall_comm_wait__get__comm(req);
332 return (act->comm.src_proc && act->comm.dst_proc);
336 case SIMCALL_COMM_WAITANY:
337 /* Check if it has at least one communication ready */
338 xbt_dynar_foreach(simcall_comm_waitany__get__comms(req), index, act) {
339 if (act->comm.src_proc && act->comm.dst_proc){
347 /* The rest of the request are always enabled */
352 int MC_request_is_enabled_by_idx(smx_simcall_t req, unsigned int idx)
358 case SIMCALL_COMM_WAIT:
359 /* FIXME: check also that src and dst processes are not suspended */
360 act = simcall_comm_wait__get__comm(req);
361 return (act->comm.src_proc && act->comm.dst_proc);
364 case SIMCALL_COMM_WAITANY:
365 act = xbt_dynar_get_as(simcall_comm_waitany__get__comms(req), idx, smx_action_t);
366 return (act->comm.src_proc && act->comm.dst_proc);
369 case SIMCALL_COMM_TESTANY:
370 act = xbt_dynar_get_as(simcall_comm_testany__get__comms(req), idx, smx_action_t);
371 return (act->comm.src_proc && act->comm.dst_proc);
379 int MC_process_is_enabled(smx_process_t process)
381 if (process->simcall.call != SIMCALL_NONE && MC_request_is_enabled(&process->simcall))
387 char *MC_request_get_dot_output(smx_simcall_t req, int value){
389 char *str = NULL, *label = NULL;
390 smx_action_t act = NULL;
393 case SIMCALL_COMM_ISEND:
394 if(req->issuer->smx_host)
395 label = bprintf("[(%lu)%s] iSend", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host));
397 label = bprintf("[(%lu)] iSend", req->issuer->pid);
400 case SIMCALL_COMM_IRECV:
401 if(req->issuer->smx_host)
402 label = bprintf("[(%lu)%s] iRecv", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host));
404 label = bprintf("[(%lu)] iRecv", req->issuer->pid);
407 case SIMCALL_COMM_WAIT:
408 act = simcall_comm_wait__get__comm(req);
410 if(req->issuer->smx_host)
411 label = bprintf("[(%lu)%s] WaitTimeout", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host));
413 label = bprintf("[(%lu)] WaitTimeout", req->issuer->pid);
415 if(req->issuer->smx_host)
416 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);
418 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);
422 case SIMCALL_COMM_TEST:
423 act = simcall_comm_test__get__comm(req);
424 if(act->comm.src_proc == NULL || act->comm.dst_proc == NULL){
425 if(req->issuer->smx_host)
426 label = bprintf("[(%lu)%s] Test FALSE", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host));
428 label = bprintf("[(%lu)] Test FALSE", req->issuer->pid);
430 if(req->issuer->smx_host)
431 label = bprintf("[(%lu)%s] Test TRUE", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host));
433 label = bprintf("[(%lu)] Test TRUE", req->issuer->pid);
437 case SIMCALL_COMM_WAITANY:
438 if(req->issuer->smx_host)
439 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)));
441 label = bprintf("[(%lu)] WaitAny [%d of %lu]", req->issuer->pid, value+1, xbt_dynar_length(simcall_comm_waitany__get__comms(req)));
444 case SIMCALL_COMM_TESTANY:
446 if(req->issuer->smx_host)
447 label = bprintf("[(%lu)%s] TestAny FALSE", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host));
449 label = bprintf("[(%lu)] TestAny FALSE", req->issuer->pid);
451 if(req->issuer->smx_host)
452 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)));
454 label = bprintf("[(%lu)] TestAny TRUE [%d of %lu]", req->issuer->pid, value+1, xbt_dynar_length(simcall_comm_testany__get__comms(req)));
458 case SIMCALL_MC_RANDOM:
460 if(req->issuer->smx_host)
461 label = bprintf("[(%lu)%s] MC_RANDOM (0)", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host));
463 label = bprintf("[(%lu)] MC_RANDOM (0)", req->issuer->pid);
465 if(req->issuer->smx_host)
466 label = bprintf("[(%lu)%s] MC_RANDOM (1)", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host));
468 label = bprintf("[(%lu)] MC_RANDOM (1)", req->issuer->pid);
472 case SIMCALL_MC_SNAPSHOT:
473 if(req->issuer->smx_host)
474 label = bprintf("[(%lu)%s] MC_SNAPSHOT", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host));
476 label = bprintf("[(%lu)] MC_SNAPSHOT", req->issuer->pid);
479 case SIMCALL_MC_COMPARE_SNAPSHOTS:
480 if(req->issuer->smx_host)
481 label = bprintf("[(%lu)%s] MC_COMPARE_SNAPSHOTS", req->issuer->pid, MSG_host_get_name(req->issuer->smx_host));
483 label = bprintf("[(%lu)] MC_COMPARE_SNAPSHOTS", req->issuer->pid);
490 str = bprintf("label = \"%s\", color = %s, fontcolor = %s", label, colors[req->issuer->pid-1], colors[req->issuer->pid-1]);