Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
4c8b4f5b7a919ef056170c0617e4d96b50f86c4d
[simgrid.git] / src / mc / mc_request.cpp
1 /* Copyright (c) 2008-2017. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #include <cassert>
7
8 #include "src/include/mc/mc.h"
9 #include "src/mc/ModelChecker.hpp"
10 #include "src/mc/mc_request.h"
11 #include "src/mc/mc_smx.h"
12 #include "src/mc/mc_xbt.hpp"
13
14 using simgrid::mc::remote;
15
16 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_request, mc,
17                                 "Logging specific to MC (request)");
18
19 static char *pointer_to_string(void *pointer);
20 static char *buff_size_to_string(size_t size);
21
22 static inline simgrid::kernel::activity::CommImpl* MC_get_comm(smx_simcall_t r)
23 {
24   switch (r->call ) {
25   case SIMCALL_COMM_WAIT:
26     return static_cast<simgrid::kernel::activity::CommImpl*>(simcall_comm_wait__getraw__comm(r));
27   case SIMCALL_COMM_TEST:
28     return static_cast<simgrid::kernel::activity::CommImpl*>(simcall_comm_test__getraw__comm(r));
29   default:
30     return nullptr;
31   }
32 }
33
34 static inline
35 smx_mailbox_t MC_get_mbox(smx_simcall_t r)
36 {
37   switch(r->call) {
38   case SIMCALL_COMM_ISEND:
39     return simcall_comm_isend__get__mbox(r);
40   case SIMCALL_COMM_IRECV:
41     return simcall_comm_irecv__get__mbox(r);
42   default:
43     return nullptr;
44   }
45 }
46
47 namespace simgrid {
48 namespace mc {
49
50 // Does half the job
51 static inline
52 bool request_depend_asymmetric(smx_simcall_t r1, smx_simcall_t r2)
53 {
54   if (r1->call == SIMCALL_COMM_ISEND && r2->call == SIMCALL_COMM_IRECV)
55     return false;
56
57   if (r1->call == SIMCALL_COMM_IRECV && r2->call == SIMCALL_COMM_ISEND)
58     return false;
59
60   // Those are internal requests, we do not need indirection
61   // because those objects are copies:
62   simgrid::kernel::activity::CommImpl* synchro1 = MC_get_comm(r1);
63   simgrid::kernel::activity::CommImpl* synchro2 = MC_get_comm(r2);
64
65   if ((r1->call == SIMCALL_COMM_ISEND || r1->call == SIMCALL_COMM_IRECV)
66       && r2->call == SIMCALL_COMM_WAIT) {
67
68     smx_mailbox_t mbox = MC_get_mbox(r1);
69
70     if (mbox != synchro2->mbox_cpy
71         && simcall_comm_wait__get__timeout(r2) <= 0)
72       return false;
73
74     if ((r1->issuer != synchro2->src_proc)
75         && (r1->issuer != synchro2->dst_proc)
76         && simcall_comm_wait__get__timeout(r2) <= 0)
77       return false;
78
79     if ((r1->call == SIMCALL_COMM_ISEND)
80         && (synchro2->type == SIMIX_COMM_SEND)
81         && (synchro2->src_buff !=
82             simcall_comm_isend__get__src_buff(r1))
83         && simcall_comm_wait__get__timeout(r2) <= 0)
84       return false;
85
86     if ((r1->call == SIMCALL_COMM_IRECV)
87         && (synchro2->type == SIMIX_COMM_RECEIVE)
88         && (synchro2->dst_buff != simcall_comm_irecv__get__dst_buff(r1))
89         && simcall_comm_wait__get__timeout(r2) <= 0)
90       return false;
91   }
92
93   /* FIXME: the following rule assumes that the result of the
94    * isend/irecv call is not stored in a buffer used in the
95    * test call. */
96 #if 0
97   if((r1->call == SIMCALL_COMM_ISEND || r1->call == SIMCALL_COMM_IRECV)
98      &&  r2->call == SIMCALL_COMM_TEST)
99      return FALSE;
100 #endif
101
102   if (r1->call == SIMCALL_COMM_WAIT
103       && (r2->call == SIMCALL_COMM_WAIT || r2->call == SIMCALL_COMM_TEST)
104       && (synchro1->src_proc == nullptr || synchro1->dst_proc == nullptr))
105     return false;
106
107   if (r1->call == SIMCALL_COMM_TEST &&
108       (simcall_comm_test__get__comm(r1) == nullptr
109        || synchro1->src_buff == nullptr
110        || synchro1->dst_buff == nullptr))
111     return false;
112
113   if (r1->call == SIMCALL_COMM_TEST && r2->call == SIMCALL_COMM_WAIT
114       && synchro1->src_buff == synchro2->src_buff
115       && synchro1->dst_buff == synchro2->dst_buff)
116     return false;
117
118   if (r1->call == SIMCALL_COMM_WAIT && r2->call == SIMCALL_COMM_TEST
119       && synchro1->src_buff != nullptr
120       && synchro1->dst_buff != nullptr
121       && synchro2->src_buff != nullptr
122       && synchro2->dst_buff != nullptr
123       && synchro1->dst_buff != synchro2->src_buff
124       && synchro1->dst_buff != synchro2->dst_buff
125       && synchro2->dst_buff != synchro1->src_buff)
126     return false;
127
128   return true;
129 }
130
131 // Those are internal_req
132 bool request_depend(smx_simcall_t r1, smx_simcall_t r2)
133 {
134   if (r1->issuer == r2->issuer)
135     return false;
136
137   /* Wait with timeout transitions are not considered by the independence theorem, thus we consider them as dependent with all other transitions */
138   if ((r1->call == SIMCALL_COMM_WAIT && simcall_comm_wait__get__timeout(r1) > 0)
139       || (r2->call == SIMCALL_COMM_WAIT
140           && simcall_comm_wait__get__timeout(r2) > 0))
141     return TRUE;
142
143   if (r1->call != r2->call)
144     return request_depend_asymmetric(r1, r2)
145       && request_depend_asymmetric(r2, r1);
146
147   // Those are internal requests, we do not need indirection
148   // because those objects are copies:
149   simgrid::kernel::activity::CommImpl* synchro1 = MC_get_comm(r1);
150   simgrid::kernel::activity::CommImpl* synchro2 = MC_get_comm(r2);
151
152   switch(r1->call) {
153   case SIMCALL_COMM_ISEND:
154     return simcall_comm_isend__get__mbox(r1)
155       == simcall_comm_isend__get__mbox(r2);
156   case SIMCALL_COMM_IRECV:
157     return simcall_comm_irecv__get__mbox(r1)
158       == simcall_comm_irecv__get__mbox(r2);
159   case SIMCALL_COMM_WAIT:
160     if (synchro1->src_buff == synchro2->src_buff
161         && synchro1->dst_buff == synchro2->dst_buff)
162       return false;
163     else if (synchro1->src_buff != nullptr
164         && synchro1->dst_buff != nullptr
165         && synchro2->src_buff != nullptr
166         && synchro2->dst_buff != nullptr
167         && synchro1->dst_buff != synchro2->src_buff
168         && synchro1->dst_buff != synchro2->dst_buff
169         && synchro2->dst_buff != synchro1->src_buff)
170       return false;
171     else
172       return true;
173   default:
174     return true;
175   }
176 }
177
178 }
179 }
180
181 static char *pointer_to_string(void *pointer)
182 {
183
184   if (XBT_LOG_ISENABLED(mc_request, xbt_log_priority_verbose))
185     return bprintf("%p", pointer);
186
187   return xbt_strdup("(verbose only)");
188 }
189
190 static char *buff_size_to_string(size_t buff_size)
191 {
192
193   if (XBT_LOG_ISENABLED(mc_request, xbt_log_priority_verbose))
194     return bprintf("%zu", buff_size);
195
196   return xbt_strdup("(verbose only)");
197 }
198
199
200 std::string simgrid::mc::request_to_string(smx_simcall_t req, int value, simgrid::mc::RequestType request_type)
201 {
202   xbt_assert(mc_model_checker != nullptr);
203
204   bool use_remote_comm = true;
205   switch(request_type) {
206   case simgrid::mc::RequestType::simix:
207     use_remote_comm = true;
208     break;
209   case simgrid::mc::RequestType::executed:
210   case simgrid::mc::RequestType::internal:
211     use_remote_comm = false;
212     break;
213   }
214
215   const char* type = nullptr;
216   char *args = nullptr;
217
218   smx_actor_t issuer = MC_smx_simcall_get_issuer(req);
219
220   switch (req->call) {
221
222   case SIMCALL_COMM_ISEND: {
223     type = "iSend";
224     char* p = pointer_to_string(simcall_comm_isend__get__src_buff(req));
225     char* bs = buff_size_to_string(simcall_comm_isend__get__src_buff_size(req));
226     if (issuer->host)
227       args = bprintf("src=(%lu)%s (%s), buff=%s, size=%s", issuer->pid, MC_smx_actor_get_host_name(issuer),
228                      MC_smx_actor_get_name(issuer), p, bs);
229     else
230       args = bprintf("src=(%lu)%s, buff=%s, size=%s", issuer->pid, MC_smx_actor_get_name(issuer), p, bs);
231     xbt_free(bs);
232     xbt_free(p);
233     break;
234   }
235
236   case SIMCALL_COMM_IRECV: {
237     size_t* remote_size = simcall_comm_irecv__get__dst_buff_size(req);
238
239     // size_t size = size_pointer ? *size_pointer : 0;
240     size_t size = 0;
241     if (remote_size)
242       mc_model_checker->process().read_bytes(&size, sizeof(size),
243         remote(remote_size));
244
245     type = "iRecv";
246     char* p = pointer_to_string(simcall_comm_irecv__get__dst_buff(req));
247     char* bs = buff_size_to_string(size);
248     if (issuer->host)
249       args = bprintf("dst=(%lu)%s (%s), buff=%s, size=%s", issuer->pid, MC_smx_actor_get_host_name(issuer),
250                      MC_smx_actor_get_name(issuer), p, bs);
251     else
252       args = bprintf("dst=(%lu)%s, buff=%s, size=%s", issuer->pid, MC_smx_actor_get_name(issuer), p, bs);
253     xbt_free(bs);
254     xbt_free(p);
255     break;
256   }
257
258   case SIMCALL_COMM_WAIT: {
259     simgrid::kernel::activity::CommImpl* remote_act =
260         static_cast<simgrid::kernel::activity::CommImpl*>(simcall_comm_wait__getraw__comm(req));
261     char* p;
262     if (value == -1) {
263       type = "WaitTimeout";
264       p = pointer_to_string(remote_act);
265       args = bprintf("comm=%s", p);
266     } else {
267       type = "Wait";
268       p = pointer_to_string(remote_act);
269
270       simgrid::mc::Remote<simgrid::kernel::activity::CommImpl> temp_synchro;
271       simgrid::kernel::activity::CommImpl* act;
272       if (use_remote_comm) {
273         mc_model_checker->process().read(temp_synchro,
274                                          remote(static_cast<simgrid::kernel::activity::CommImpl*>(remote_act)));
275         act = temp_synchro.getBuffer();
276       } else
277         act = remote_act;
278
279       smx_actor_t src_proc = mc_model_checker->process().resolveActor(simgrid::mc::remote(act->src_proc));
280       smx_actor_t dst_proc = mc_model_checker->process().resolveActor(simgrid::mc::remote(act->dst_proc));
281       args =
282           bprintf("comm=%s [(%lu)%s (%s)-> (%lu)%s (%s)]", p, src_proc ? src_proc->pid : 0,
283                   src_proc ? MC_smx_actor_get_host_name(src_proc) : "", src_proc ? MC_smx_actor_get_name(src_proc) : "",
284                   dst_proc ? dst_proc->pid : 0, dst_proc ? MC_smx_actor_get_host_name(dst_proc) : "",
285                   dst_proc ? MC_smx_actor_get_name(dst_proc) : "");
286     }
287     xbt_free(p);
288     break;
289   }
290
291   case SIMCALL_COMM_TEST: {
292     simgrid::kernel::activity::CommImpl* remote_act =
293         static_cast<simgrid::kernel::activity::CommImpl*>(simcall_comm_test__getraw__comm(req));
294     simgrid::mc::Remote<simgrid::kernel::activity::CommImpl> temp_synchro;
295     simgrid::kernel::activity::CommImpl* act;
296     if (use_remote_comm) {
297       mc_model_checker->process().read(temp_synchro,
298                                        remote(static_cast<simgrid::kernel::activity::CommImpl*>(remote_act)));
299       act = temp_synchro.getBuffer();
300     } else
301       act = remote_act;
302
303     char* p;
304     if (act->src_proc == nullptr || act->dst_proc == nullptr) {
305       type = "Test FALSE";
306       p = pointer_to_string(remote_act);
307       args = bprintf("comm=%s", p);
308     } else {
309       type = "Test TRUE";
310       p = pointer_to_string(remote_act);
311
312       smx_actor_t src_proc = mc_model_checker->process().resolveActor(simgrid::mc::remote(act->src_proc));
313       smx_actor_t dst_proc = mc_model_checker->process().resolveActor(simgrid::mc::remote(act->dst_proc));
314       args = bprintf("comm=%s [(%lu)%s (%s) -> (%lu)%s (%s)]", p, src_proc->pid, MC_smx_actor_get_name(src_proc),
315                      MC_smx_actor_get_host_name(src_proc), dst_proc->pid, MC_smx_actor_get_name(dst_proc),
316                      MC_smx_actor_get_host_name(dst_proc));
317     }
318     xbt_free(p);
319     break;
320   }
321
322   case SIMCALL_COMM_WAITANY: {
323     type = "WaitAny";
324     s_xbt_dynar_t comms;
325     mc_model_checker->process().read_bytes(
326       &comms, sizeof(comms), remote(simcall_comm_waitany__get__comms(req)));
327     if (not xbt_dynar_is_empty(&comms)) {
328       smx_activity_t remote_sync;
329       read_element(mc_model_checker->process(),
330         &remote_sync, remote(simcall_comm_waitany__get__comms(req)), value,
331         sizeof(remote_sync));
332       char* p = pointer_to_string(&*remote_sync);
333       args = bprintf("comm=%s (%d of %lu)",
334         p, value + 1, xbt_dynar_length(&comms));
335       xbt_free(p);
336     } else
337       args = bprintf("comm at idx %d", value);
338     break;
339   }
340
341   case SIMCALL_COMM_TESTANY:
342     if (value == -1) {
343       type = "TestAny FALSE";
344       args = xbt_strdup("-");
345     } else {
346       type = "TestAny";
347       args =
348           bprintf("(%d of %zu)", value + 1,
349                     simcall_comm_testany__get__count(req));
350     }
351     break;
352
353   case SIMCALL_MUTEX_TRYLOCK:
354   case SIMCALL_MUTEX_LOCK: {
355     if (req->call == SIMCALL_MUTEX_LOCK)
356       type = "Mutex LOCK";
357     else
358       type = "Mutex TRYLOCK";
359
360     simgrid::mc::Remote<simgrid::simix::MutexImpl> mutex;
361     mc_model_checker->process().read_bytes(mutex.getBuffer(), sizeof(mutex),
362       remote(
363         req->call == SIMCALL_MUTEX_LOCK
364         ? simcall_mutex_lock__get__mutex(req)
365         : simcall_mutex_trylock__get__mutex(req)
366       ));
367     s_xbt_swag_t mutex_sleeping;
368     mc_model_checker->process().read_bytes(&mutex_sleeping, sizeof(mutex_sleeping),
369       remote(mutex.getBuffer()->sleeping));
370
371     args =
372         bprintf("locked = %d, owner = %d, sleeping = %d", mutex.getBuffer()->locked,
373                 mutex.getBuffer()->owner != nullptr
374                     ? (int)mc_model_checker->process().resolveActor(simgrid::mc::remote(mutex.getBuffer()->owner))->pid
375                     : -1,
376                 mutex_sleeping.count);
377     break;
378   }
379
380   case SIMCALL_MC_RANDOM:
381     type = "MC_RANDOM";
382     args = bprintf("%d", value);
383     break;
384
385   default:
386     type = SIMIX_simcall_name(req->call);
387     args = bprintf("??");
388     break;
389   }
390
391   std::string str;
392   if (args != nullptr)
393     str = simgrid::xbt::string_printf("[(%lu)%s (%s)] %s(%s)", issuer->pid, MC_smx_actor_get_host_name(issuer),
394                                       MC_smx_actor_get_name(issuer), type, args);
395   else
396     str = simgrid::xbt::string_printf("[(%lu)%s (%s)] %s ", issuer->pid, MC_smx_actor_get_host_name(issuer),
397                                       MC_smx_actor_get_name(issuer), type);
398   xbt_free(args);
399   return str;
400 }
401
402 namespace simgrid {
403 namespace mc {
404
405 bool request_is_enabled_by_idx(smx_simcall_t req, unsigned int idx)
406 {
407   simgrid::kernel::activity::ActivityImpl* remote_act = nullptr;
408   switch (req->call) {
409
410   case SIMCALL_COMM_WAIT:
411     /* FIXME: check also that src and dst processes are not suspended */
412     remote_act = simcall_comm_wait__getraw__comm(req);
413     break;
414
415   case SIMCALL_COMM_WAITANY: {
416     read_element(mc_model_checker->process(), &remote_act, remote(simcall_comm_waitany__getraw__comms(req)), idx,
417                  sizeof(remote_act));
418     }
419     break;
420
421   case SIMCALL_COMM_TESTANY:
422     remote_act = mc_model_checker->process().read(remote(simcall_comm_testany__getraw__comms(req) + idx));
423     break;
424
425   default:
426     return true;
427   }
428
429   simgrid::mc::Remote<simgrid::kernel::activity::CommImpl> temp_comm;
430   mc_model_checker->process().read(temp_comm, remote(static_cast<simgrid::kernel::activity::CommImpl*>(remote_act)));
431   simgrid::kernel::activity::CommImpl* comm = temp_comm.getBuffer();
432   return comm->src_proc && comm->dst_proc;
433 }
434
435 /** @brief returns if there this transition can proceed in a finite amount of time
436  *
437  * It is used in the model-checker to not get into self-deadlock where it would execute a never ending transition.
438  *
439  * Only WAIT operations (on comm, on mutex, etc) can ever return false because they could lock the MC exploration.
440  * Wait operations are OK and return true in only two situations:
441  *  - if the wait will succeed immediately (if both peer of the comm are there already or if the mutex is available)
442  *  - if a timeout is provided, because we can fire the timeout if the transition is not ready without blocking in this
443  * transition for ever.
444  *
445  */
446 // Called from both MCer and MCed:
447 bool actor_is_enabled(smx_actor_t actor)
448 {
449   smx_simcall_t req = &actor->simcall;
450   // TODO, add support for the subtypes?
451
452   switch (req->call) {
453     case SIMCALL_NONE:
454       return false;
455
456     case SIMCALL_COMM_WAIT: {
457       /* FIXME: check also that src and dst processes are not suspended */
458       simgrid::kernel::activity::CommImpl* act =
459           static_cast<simgrid::kernel::activity::CommImpl*>(simcall_comm_wait__getraw__comm(req));
460
461 #if SIMGRID_HAVE_MC
462       // Fetch from MCed memory:
463       // HACK, type puning
464       if (mc_model_checker != nullptr) {
465         simgrid::mc::Remote<simgrid::kernel::activity::CommImpl> temp_comm;
466         mc_model_checker->process().read(temp_comm, remote(act));
467         act = static_cast<simgrid::kernel::activity::CommImpl*>(temp_comm.getBuffer());
468       }
469 #endif
470
471       if (act->src_timeout || act->dst_timeout) {
472         /* If it has a timeout it will be always be enabled (regardless of who declared the timeout),
473          * because even if the communication is not ready, it can timeout and won't block. */
474         if (_sg_mc_timeout == 1)
475           return true;
476       }
477       /* On the other hand if it hasn't a timeout, check if the comm is ready.*/
478       else if (act->detached && act->src_proc == nullptr && act->type == SIMIX_COMM_READY)
479         return (act->dst_proc != nullptr);
480       return (act->src_proc && act->dst_proc);
481     }
482
483     case SIMCALL_COMM_WAITANY: {
484       xbt_dynar_t comms;
485       simgrid::kernel::activity::CommImpl* act =
486           static_cast<simgrid::kernel::activity::CommImpl*>(simcall_comm_wait__getraw__comm(req));
487
488 #if SIMGRID_HAVE_MC
489       s_xbt_dynar_t comms_buffer;
490       size_t buffer_size = 0;
491       if (mc_model_checker != nullptr) {
492         // Read dynar:
493         mc_model_checker->process().read(&comms_buffer, remote(simcall_comm_waitany__get__comms(req)));
494         assert(comms_buffer.elmsize == sizeof(act));
495         buffer_size = comms_buffer.elmsize * comms_buffer.used;
496         comms       = &comms_buffer;
497       } else
498         comms = simcall_comm_waitany__get__comms(req);
499
500       // Read all the dynar buffer:
501       char buffer[buffer_size];
502       if (mc_model_checker != nullptr)
503         mc_model_checker->process().read_bytes(buffer, sizeof(buffer), remote(comms->data));
504 #else
505       comms = simcall_comm_waitany__get__comms(req);
506 #endif
507
508       for (unsigned int index = 0; index < comms->used; ++index) {
509 #if SIMGRID_HAVE_MC
510         // Fetch act from MCed memory:
511         // HACK, type puning
512         simgrid::mc::Remote<simgrid::kernel::activity::CommImpl> temp_comm;
513         if (mc_model_checker != nullptr) {
514           memcpy(&act, buffer + comms->elmsize * index, sizeof(act));
515           mc_model_checker->process().read(temp_comm, remote(act));
516           act = static_cast<simgrid::kernel::activity::CommImpl*>(temp_comm.getBuffer());
517         } else
518 #endif
519           act = xbt_dynar_get_as(comms, index, simgrid::kernel::activity::CommImpl*);
520         if (act->src_proc && act->dst_proc)
521           return true;
522       }
523       return false;
524     }
525
526     case SIMCALL_MUTEX_LOCK: {
527       smx_mutex_t mutex = simcall_mutex_lock__get__mutex(req);
528 #if SIMGRID_HAVE_MC
529       simgrid::mc::Remote<simgrid::simix::MutexImpl> temp_mutex;
530       if (mc_model_checker != nullptr) {
531         mc_model_checker->process().read(temp_mutex.getBuffer(), remote(mutex));
532         mutex = temp_mutex.getBuffer();
533       }
534 #endif
535
536       if (mutex->owner == nullptr)
537         return true;
538 #if SIMGRID_HAVE_MC
539       else if (mc_model_checker != nullptr) {
540         simgrid::mc::RemoteClient& modelchecked = mc_model_checker->process();
541         // TODO, *(mutex->owner) :/
542         return modelchecked.resolveActor(simgrid::mc::remote(mutex->owner))->pid ==
543                modelchecked.resolveActor(simgrid::mc::remote(req->issuer))->pid;
544       }
545 #endif
546       else
547         return mutex->owner->pid == req->issuer->pid;
548     }
549
550     case SIMCALL_SEM_ACQUIRE: {
551       static int warned = 0;
552       if (not warned)
553         XBT_INFO("Using semaphore in model-checked code is still experimental. Use at your own risk");
554       warned = 1;
555       return true;
556     }
557
558     case SIMCALL_COND_WAIT: {
559       static int warned = 0;
560       if (not warned)
561         XBT_INFO("Using condition variables in model-checked code is still experimental. Use at your own risk");
562       warned = 1;
563       return true;
564     }
565
566     default:
567       /* The rest of the requests are always enabled */
568       return true;
569   }
570 }
571
572 static const char* colors[] = {
573   "blue",
574   "red",
575   "green3",
576   "goldenrod",
577   "brown",
578   "purple",
579   "magenta",
580   "turquoise4",
581   "gray25",
582   "forestgreen",
583   "hotpink",
584   "lightblue",
585   "tan",
586 };
587
588 static inline const char* get_color(int id)
589 {
590   return colors[id % (sizeof(colors) / sizeof(colors[0])) ];
591 }
592
593 std::string request_get_dot_output(smx_simcall_t req, int value)
594 {
595   std::string label;
596
597   const smx_actor_t issuer = MC_smx_simcall_get_issuer(req);
598
599   switch (req->call) {
600   case SIMCALL_COMM_ISEND:
601     if (issuer->host)
602       label = simgrid::xbt::string_printf("[(%lu)%s] iSend", issuer->pid, MC_smx_actor_get_host_name(issuer));
603     else
604       label = bprintf("[(%lu)] iSend", issuer->pid);
605     break;
606
607   case SIMCALL_COMM_IRECV:
608     if (issuer->host)
609       label = simgrid::xbt::string_printf("[(%lu)%s] iRecv", issuer->pid, MC_smx_actor_get_host_name(issuer));
610     else
611       label = simgrid::xbt::string_printf("[(%lu)] iRecv", issuer->pid);
612     break;
613
614   case SIMCALL_COMM_WAIT: {
615     if (value == -1) {
616       if (issuer->host)
617         label = simgrid::xbt::string_printf("[(%lu)%s] WaitTimeout", issuer->pid, MC_smx_actor_get_host_name(issuer));
618       else
619         label = simgrid::xbt::string_printf("[(%lu)] WaitTimeout", issuer->pid);
620     } else {
621       simgrid::kernel::activity::ActivityImpl* remote_act = simcall_comm_wait__getraw__comm(req);
622       simgrid::mc::Remote<simgrid::kernel::activity::CommImpl> temp_comm;
623       mc_model_checker->process().read(temp_comm,
624                                        remote(static_cast<simgrid::kernel::activity::CommImpl*>(remote_act)));
625       simgrid::kernel::activity::CommImpl* comm = temp_comm.getBuffer();
626
627       smx_actor_t src_proc = mc_model_checker->process().resolveActor(simgrid::mc::remote(comm->src_proc));
628       smx_actor_t dst_proc = mc_model_checker->process().resolveActor(simgrid::mc::remote(comm->dst_proc));
629       if (issuer->host)
630         label = simgrid::xbt::string_printf("[(%lu)%s] Wait [(%lu)->(%lu)]", issuer->pid,
631                                             MC_smx_actor_get_host_name(issuer), src_proc ? src_proc->pid : 0,
632                                             dst_proc ? dst_proc->pid : 0);
633       else
634         label = simgrid::xbt::string_printf("[(%lu)] Wait [(%lu)->(%lu)]",
635                     issuer->pid,
636                     src_proc ? src_proc->pid : 0,
637                     dst_proc ? dst_proc->pid : 0);
638     }
639     break;
640   }
641
642   case SIMCALL_COMM_TEST: {
643     simgrid::kernel::activity::ActivityImpl* remote_act = simcall_comm_test__getraw__comm(req);
644     simgrid::mc::Remote<simgrid::kernel::activity::CommImpl> temp_comm;
645     mc_model_checker->process().read(temp_comm, remote(static_cast<simgrid::kernel::activity::CommImpl*>(remote_act)));
646     simgrid::kernel::activity::CommImpl* comm = temp_comm.getBuffer();
647     if (comm->src_proc == nullptr || comm->dst_proc == nullptr) {
648       if (issuer->host)
649         label = simgrid::xbt::string_printf("[(%lu)%s] Test FALSE", issuer->pid, MC_smx_actor_get_host_name(issuer));
650       else
651         label = bprintf("[(%lu)] Test FALSE", issuer->pid);
652     } else {
653       if (issuer->host)
654         label = simgrid::xbt::string_printf("[(%lu)%s] Test TRUE", issuer->pid, MC_smx_actor_get_host_name(issuer));
655       else
656         label = simgrid::xbt::string_printf("[(%lu)] Test TRUE", issuer->pid);
657     }
658     break;
659   }
660
661   case SIMCALL_COMM_WAITANY: {
662     unsigned long comms_size = read_length(
663       mc_model_checker->process(), remote(simcall_comm_waitany__get__comms(req)));
664     if (issuer->host)
665       label = simgrid::xbt::string_printf("[(%lu)%s] WaitAny [%d of %lu]", issuer->pid,
666                                           MC_smx_actor_get_host_name(issuer), value + 1, comms_size);
667     else
668       label = simgrid::xbt::string_printf("[(%lu)] WaitAny [%d of %lu]",
669                   issuer->pid, value + 1, comms_size);
670     break;
671   }
672
673   case SIMCALL_COMM_TESTANY:
674     if (value == -1) {
675       if (issuer->host)
676         label = simgrid::xbt::string_printf("[(%lu)%s] TestAny FALSE", issuer->pid, MC_smx_actor_get_host_name(issuer));
677       else
678         label = simgrid::xbt::string_printf("[(%lu)] TestAny FALSE", issuer->pid);
679     } else {
680       if (issuer->host)
681         label = simgrid::xbt::string_printf("[(%lu)%s] TestAny TRUE [%d of %lu]", issuer->pid,
682                                             MC_smx_actor_get_host_name(issuer), value + 1,
683                                             simcall_comm_testany__get__count(req));
684       else
685         label = simgrid::xbt::string_printf("[(%lu)] TestAny TRUE [%d of %lu]",
686                     issuer->pid,
687                     value + 1,
688                     simcall_comm_testany__get__count(req));
689     }
690     break;
691
692   case SIMCALL_MUTEX_TRYLOCK:
693     label = simgrid::xbt::string_printf("[(%lu)] Mutex TRYLOCK", issuer->pid);
694     break;
695
696   case SIMCALL_MUTEX_LOCK:
697     label = simgrid::xbt::string_printf("[(%lu)] Mutex LOCK", issuer->pid);
698     break;
699
700   case SIMCALL_MC_RANDOM:
701     if (issuer->host)
702       label = simgrid::xbt::string_printf("[(%lu)%s] MC_RANDOM (%d)", issuer->pid, MC_smx_actor_get_host_name(issuer),
703                                           value);
704     else
705       label = simgrid::xbt::string_printf("[(%lu)] MC_RANDOM (%d)", issuer->pid, value);
706     break;
707
708   default:
709     THROW_UNIMPLEMENTED;
710   }
711
712   const char* color = get_color(issuer->pid - 1);
713   return  simgrid::xbt::string_printf(
714         "label = \"%s\", color = %s, fontcolor = %s", label.c_str(),
715         color, color);
716 }
717
718 }
719 }