Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
model-checker : add ignore mechanism for global variables (data + bss segments) in...
[simgrid.git] / src / simix / smx_smurf.c
1 #include "smx_private.h"
2 #include "xbt/fifo.h"
3 #include "xbt/xbt_os_thread.h"
4 #include "../mc/mc_private.h"
5
6 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_smurf, simix,
7                                 "Logging specific to SIMIX (SMURF)");
8
9 XBT_INLINE smx_simcall_t SIMIX_simcall_mine()
10 {
11   smx_process_t issuer = SIMIX_process_self();
12   return &issuer->simcall;
13 }
14
15 /**
16  * \brief Makes the current process do a simcall to the kernel and yields
17  * until completion. If the current thread is maestro, we don't yield and
18  * execute the simcall directly.
19  * \param self the current process
20  */
21 void SIMIX_simcall_push(smx_process_t self)
22 {
23   if (self != simix_global->maestro_process) {
24     XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name,
25               SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call);
26     SIMIX_process_yield(self);
27   } else {
28     SIMIX_simcall_pre(&self->simcall, 0);
29   }
30 }
31
32 void SIMIX_simcall_answer(smx_simcall_t simcall)
33 {
34   if (simcall->issuer != simix_global->maestro_process){
35     XBT_DEBUG("Answer simcall %s (%d) issued by %s (%p)", SIMIX_simcall_name(simcall->call), (int)simcall->call,
36         simcall->issuer->name, simcall->issuer);
37     simcall->issuer->simcall.call = SIMCALL_NONE;
38 /*    This check should be useless and slows everyone. Reactivate if you see something
39  *    weird in process scheduling.
40  */
41 /*    if(!xbt_dynar_member(simix_global->process_to_run, &(simcall->issuer))) */
42     xbt_dynar_push_as(simix_global->process_to_run, smx_process_t, simcall->issuer);
43 /*    else DIE_IMPOSSIBLE; */
44   }
45 }
46
47 void SIMIX_simcall_pre(smx_simcall_t simcall, int value)
48 {
49   XBT_DEBUG("Handling simcall %p: %s", simcall, SIMIX_simcall_name(simcall->call));
50
51   switch (simcall->call) {
52     case SIMCALL_COMM_TEST:
53       SIMIX_pre_comm_test(simcall);
54       break;
55
56     case SIMCALL_COMM_TESTANY:
57       SIMIX_pre_comm_testany(simcall, value);
58       break;
59
60     case SIMCALL_COMM_WAIT:
61       SIMIX_pre_comm_wait(simcall,
62           simcall->comm_wait.comm,
63           simcall->comm_wait.timeout,
64           value);
65       break;
66
67     case SIMCALL_COMM_WAITANY:
68       SIMIX_pre_comm_waitany(simcall, value);
69       break;
70
71     case SIMCALL_COMM_SEND:
72     {
73       smx_action_t comm = SIMIX_comm_isend(
74           simcall->issuer,
75           simcall->comm_send.rdv,
76           simcall->comm_send.task_size,
77           simcall->comm_send.rate,
78           simcall->comm_send.src_buff,
79           simcall->comm_send.src_buff_size,
80           simcall->comm_send.match_fun,
81           NULL, /* no clean function since it's not detached */
82           simcall->comm_send.data,
83           0);
84       SIMIX_pre_comm_wait(simcall, comm, simcall->comm_send.timeout, 0);
85       break;
86     }
87
88     case SIMCALL_COMM_ISEND:
89       simcall->comm_isend.result = SIMIX_comm_isend(
90           simcall->issuer,
91           simcall->comm_isend.rdv,
92           simcall->comm_isend.task_size,
93           simcall->comm_isend.rate,
94           simcall->comm_isend.src_buff,
95           simcall->comm_isend.src_buff_size,
96           simcall->comm_isend.match_fun,
97           simcall->comm_isend.clean_fun,
98           simcall->comm_isend.data,
99           simcall->comm_isend.detached);
100       SIMIX_simcall_answer(simcall);
101       break;
102
103     case SIMCALL_COMM_RECV:
104     {
105       smx_action_t comm = SIMIX_comm_irecv(
106           simcall->issuer,
107           simcall->comm_recv.rdv,
108           simcall->comm_recv.dst_buff,
109           simcall->comm_recv.dst_buff_size,
110           simcall->comm_recv.match_fun,
111           simcall->comm_recv.data);
112       SIMIX_pre_comm_wait(simcall, comm, simcall->comm_recv.timeout, 0);
113       break;
114     }
115
116     case SIMCALL_COMM_IRECV:
117       simcall->comm_irecv.result = SIMIX_comm_irecv(
118           simcall->issuer,
119           simcall->comm_irecv.rdv,
120           simcall->comm_irecv.dst_buff,
121           simcall->comm_irecv.dst_buff_size,
122           simcall->comm_irecv.match_fun,
123           simcall->comm_irecv.data);
124       SIMIX_simcall_answer(simcall);
125       break;
126
127     case SIMCALL_COMM_IPROBE:
128       simcall->comm_iprobe.result = SIMIX_comm_iprobe(
129           simcall->issuer,
130           simcall->comm_iprobe.rdv,
131           simcall->comm_iprobe.src,
132           simcall->comm_iprobe.tag,
133           simcall->comm_iprobe.match_fun,
134           simcall->comm_iprobe.data);
135       SIMIX_simcall_answer(simcall);
136       break;
137
138     case SIMCALL_COMM_DESTROY:
139       SIMIX_comm_destroy(simcall->comm_destroy.comm);
140       SIMIX_simcall_answer(simcall);
141       break;
142
143     case SIMCALL_COMM_CANCEL:
144       SIMIX_comm_cancel(simcall->comm_cancel.comm);
145       SIMIX_simcall_answer(simcall);
146       break;
147
148     case SIMCALL_COMM_GET_REMAINS:
149       simcall->comm_get_remains.result =
150           SIMIX_comm_get_remains(simcall->comm_get_remains.comm);
151       SIMIX_simcall_answer(simcall);
152       break;
153
154     case SIMCALL_COMM_GET_STATE:
155       simcall->comm_get_state.result =
156           SIMIX_comm_get_state(simcall->comm_get_state.comm);
157       SIMIX_simcall_answer(simcall);
158       break;
159
160     case SIMCALL_COMM_GET_SRC_DATA:
161       simcall->comm_get_src_data.result = SIMIX_comm_get_src_data(simcall->comm_get_src_data.comm);
162       SIMIX_simcall_answer(simcall);
163       break;
164
165     case SIMCALL_COMM_GET_DST_DATA:
166       simcall->comm_get_dst_data.result = SIMIX_comm_get_dst_data(simcall->comm_get_dst_data.comm);
167       SIMIX_simcall_answer(simcall);
168       break;
169
170     case SIMCALL_COMM_GET_SRC_PROC:
171       simcall->comm_get_src_proc.result =
172           SIMIX_comm_get_src_proc(simcall->comm_get_src_proc.comm);
173       SIMIX_simcall_answer(simcall);
174       break;
175
176     case SIMCALL_COMM_GET_DST_PROC:
177       simcall->comm_get_dst_proc.result =
178           SIMIX_comm_get_dst_proc(simcall->comm_get_dst_proc.comm);
179       SIMIX_simcall_answer(simcall);
180       break;
181
182 #ifdef HAVE_LATENCY_BOUND_TRACKING
183     case SIMCALL_COMM_IS_LATENCY_BOUNDED:
184       simcall->comm_is_latency_bounded.result =
185           SIMIX_comm_is_latency_bounded(simcall->comm_is_latency_bounded.comm);
186       SIMIX_simcall_answer(simcall);
187       break;
188 #endif
189
190     case SIMCALL_RDV_CREATE:
191       simcall->rdv_create.result = SIMIX_rdv_create(simcall->rdv_create.name);
192       SIMIX_simcall_answer(simcall);
193       break;
194
195     case SIMCALL_RDV_DESTROY:
196       SIMIX_rdv_destroy(simcall->rdv_destroy.rdv);
197       SIMIX_simcall_answer(simcall);
198       break;
199
200     case SIMCALL_RDV_GEY_BY_NAME:
201       simcall->rdv_get_by_name.result =
202         SIMIX_rdv_get_by_name(simcall->rdv_get_by_name.name);
203       SIMIX_simcall_answer(simcall);
204       break;
205
206     case SIMCALL_RDV_COMM_COUNT_BY_HOST:
207       simcall->rdv_comm_count_by_host.result = SIMIX_rdv_comm_count_by_host(
208           simcall->rdv_comm_count_by_host.rdv,
209           simcall->rdv_comm_count_by_host.host);
210       SIMIX_simcall_answer(simcall);
211       break;
212
213     case SIMCALL_RDV_GET_HEAD:
214       simcall->rdv_get_head.result = SIMIX_rdv_get_head(simcall->rdv_get_head.rdv);
215       SIMIX_simcall_answer(simcall);
216       break;
217
218     case SIMCALL_RDV_SET_RECV:
219       SIMIX_rdv_set_receiver(simcall->rdv_set_rcv_proc.rdv, simcall->rdv_set_rcv_proc.receiver);
220       SIMIX_simcall_answer(simcall);
221       break;
222
223     case SIMCALL_RDV_GET_RECV:
224       simcall->rdv_get_rcv_proc.result = SIMIX_rdv_get_receiver(simcall->rdv_set_rcv_proc.rdv);
225       SIMIX_simcall_answer(simcall);
226       break;
227
228     case SIMCALL_HOST_GET_BY_NAME:
229       simcall->host_get_by_name.result =
230         SIMIX_host_get_by_name(simcall->host_get_by_name.name);
231       SIMIX_simcall_answer(simcall);
232       break;
233
234     case SIMCALL_HOST_GET_NAME:
235       simcall->host_get_name.result =  SIMIX_host_get_name(simcall->host_get_name.host);
236       SIMIX_simcall_answer(simcall);
237       break;
238
239     case SIMCALL_HOST_GET_PROPERTIES:
240       simcall->host_get_properties.result =
241         SIMIX_host_get_properties(simcall->host_get_properties.host);
242       SIMIX_simcall_answer(simcall);
243       break;
244
245     case SIMCALL_HOST_GET_SPEED:
246       simcall->host_get_speed.result = 
247         SIMIX_host_get_speed(simcall->host_get_speed.host);
248       SIMIX_simcall_answer(simcall);
249       break;
250
251     case SIMCALL_HOST_GET_AVAILABLE_SPEED:
252       simcall->host_get_available_speed.result =
253         SIMIX_host_get_available_speed(simcall->host_get_available_speed.host);
254       SIMIX_simcall_answer(simcall);
255       break;
256
257     case SIMCALL_HOST_GET_STATE:
258       simcall->host_get_state.result = 
259         SIMIX_host_get_state(simcall->host_get_state.host);
260       SIMIX_simcall_answer(simcall);
261       break;
262
263     case SIMCALL_HOST_GET_DATA:
264       simcall->host_get_data.result =  SIMIX_host_get_data(simcall->host_get_data.host);
265       SIMIX_simcall_answer(simcall);
266       break;
267
268     case SIMCALL_HOST_SET_DATA:
269       SIMIX_host_set_data(simcall->host_set_data.host, simcall->host_set_data.data);
270       SIMIX_simcall_answer(simcall);
271       break;
272
273     case SIMCALL_HOST_EXECUTE:
274       simcall->host_execute.result = SIMIX_host_execute(
275     simcall->host_execute.name,
276     simcall->host_execute.host,
277     simcall->host_execute.computation_amount,
278     simcall->host_execute.priority);
279       SIMIX_simcall_answer(simcall);
280       break;
281
282     case SIMCALL_HOST_PARALLEL_EXECUTE:
283       simcall->host_parallel_execute.result = SIMIX_host_parallel_execute(
284     simcall->host_parallel_execute.name,
285     simcall->host_parallel_execute.host_nb,
286     simcall->host_parallel_execute.host_list,
287     simcall->host_parallel_execute.computation_amount,
288     simcall->host_parallel_execute.communication_amount,
289     simcall->host_parallel_execute.amount,
290     simcall->host_parallel_execute.rate);
291       SIMIX_simcall_answer(simcall);
292       break;
293
294     case SIMCALL_HOST_EXECUTION_DESTROY:
295       SIMIX_host_execution_destroy(simcall->host_execution_destroy.execution);
296       SIMIX_simcall_answer(simcall);
297       break;
298
299     case SIMCALL_HOST_EXECUTION_CANCEL:
300       SIMIX_host_execution_cancel(simcall->host_execution_cancel.execution);
301       SIMIX_simcall_answer(simcall);
302       break;
303
304     case SIMCALL_HOST_EXECUTION_GET_REMAINS:
305       simcall->host_execution_get_remains.result =
306         SIMIX_host_execution_get_remains(simcall->host_execution_get_remains.execution);
307       SIMIX_simcall_answer(simcall);
308       break;
309
310     case SIMCALL_HOST_EXECUTION_GET_STATE:
311       simcall->host_execution_get_state.result =
312         SIMIX_host_execution_get_state(simcall->host_execution_get_state.execution);
313       SIMIX_simcall_answer(simcall);
314       break;
315
316     case SIMCALL_HOST_EXECUTION_SET_PRIORITY:
317       SIMIX_host_execution_set_priority(
318     simcall->host_execution_set_priority.execution,
319     simcall->host_execution_set_priority.priority);
320       SIMIX_simcall_answer(simcall);
321       break;
322
323     case SIMCALL_HOST_EXECUTION_WAIT:
324       SIMIX_pre_host_execution_wait(simcall);
325       break;
326
327     case SIMCALL_PROCESS_CREATE:
328       SIMIX_process_create(
329           simcall->process_create.process,
330     simcall->process_create.name,
331     simcall->process_create.code,
332     simcall->process_create.data,
333     simcall->process_create.hostname,
334     simcall->process_create.kill_time,
335     simcall->process_create.argc,
336     simcall->process_create.argv,
337     simcall->process_create.properties,
338     simcall->process_create.auto_restart);
339       SIMIX_simcall_answer(simcall);
340       break;
341
342     case SIMCALL_PROCESS_KILL:
343       SIMIX_process_kill(simcall->process_kill.process,simcall->issuer);
344       SIMIX_simcall_answer(simcall);
345       break;
346
347     case SIMCALL_PROCESS_KILLALL:
348       SIMIX_process_killall(simcall->issuer);
349       SIMIX_simcall_answer(simcall);
350       break;
351
352     case SIMCALL_PROCESS_CLEANUP:
353       SIMIX_process_cleanup(simcall->process_cleanup.process);
354       SIMIX_simcall_answer(simcall);
355       break;
356
357     case SIMCALL_PROCESS_CHANGE_HOST:
358       SIMIX_pre_process_change_host(
359           simcall->process_change_host.process,
360           simcall->process_change_host.dest);
361       SIMIX_simcall_answer(simcall);
362       break;
363
364     case SIMCALL_PROCESS_SUSPEND:
365       SIMIX_pre_process_suspend(simcall);
366       break;
367
368     case SIMCALL_PROCESS_RESUME:
369       SIMIX_process_resume(simcall->process_resume.process, simcall->issuer);
370       SIMIX_simcall_answer(simcall);
371       break;
372
373     case SIMCALL_PROCESS_COUNT:
374       simcall->process_count.result = SIMIX_process_count();
375       SIMIX_simcall_answer(simcall);
376       break;
377
378     case SIMCALL_PROCESS_GET_DATA:
379       simcall->process_get_data.result =
380         SIMIX_process_get_data(simcall->process_get_data.process);
381       SIMIX_simcall_answer(simcall);
382       break;
383     case SIMCALL_PROCESS_ON_EXIT:
384       SIMIX_process_on_exit(simcall->process_on_exit.process,
385                             simcall->process_on_exit.fun,
386                             simcall->process_on_exit.data);
387       SIMIX_simcall_answer(simcall);
388     break;
389     case SIMCALL_PROCESS_RESTART:
390       simcall->process_restart.result = SIMIX_process_restart(simcall->process_restart.process, simcall->issuer);
391       SIMIX_simcall_answer(simcall);
392     break;
393     case SIMCALL_PROCESS_AUTO_RESTART_SET:
394       SIMIX_process_auto_restart_set(simcall->process_auto_restart.process,simcall->process_auto_restart.auto_restart);
395       SIMIX_simcall_answer(simcall);
396     break;
397     case SIMCALL_PROCESS_SET_DATA:
398       SIMIX_process_set_data(
399     simcall->process_set_data.process,
400     simcall->process_set_data.data);
401       SIMIX_simcall_answer(simcall);
402       break;
403
404     case SIMCALL_PROCESS_GET_HOST:
405       simcall->process_get_host.result = SIMIX_process_get_host(simcall->process_get_host.process);
406       SIMIX_simcall_answer(simcall);
407       break;
408
409     case SIMCALL_PROCESS_GET_NAME:
410       simcall->process_get_name.result = SIMIX_process_get_name(simcall->process_get_name.process);
411       SIMIX_simcall_answer(simcall);
412       break;
413
414     case SIMCALL_PROCESS_IS_SUSPENDED:
415       simcall->process_is_suspended.result =
416         SIMIX_process_is_suspended(simcall->process_is_suspended.process);
417       SIMIX_simcall_answer(simcall);
418       break;
419
420     case SIMCALL_PROCESS_GET_PROPERTIES:
421       simcall->process_get_properties.result =
422         SIMIX_process_get_properties(simcall->process_get_properties.process);
423       SIMIX_simcall_answer(simcall);
424       break;
425
426     case SIMCALL_PROCESS_SLEEP:
427       SIMIX_pre_process_sleep(simcall);
428       break;
429
430 #ifdef HAVE_TRACING
431     case SIMCALL_SET_CATEGORY:
432       SIMIX_set_category(
433           simcall->set_category.action,
434           simcall->set_category.category);
435       SIMIX_simcall_answer(simcall);
436       break;
437 #endif
438
439     case SIMCALL_MUTEX_INIT:
440       simcall->mutex_init.result = SIMIX_mutex_init();
441       SIMIX_simcall_answer(simcall);
442       break;
443
444     case SIMCALL_MUTEX_DESTROY:
445       SIMIX_mutex_destroy(simcall->mutex_destroy.mutex);
446       SIMIX_simcall_answer(simcall);
447       break;
448
449     case SIMCALL_MUTEX_LOCK:
450       SIMIX_pre_mutex_lock(simcall);
451       break;
452
453     case SIMCALL_MUTEX_TRYLOCK:
454       simcall->mutex_trylock.result =
455         SIMIX_mutex_trylock(simcall->mutex_trylock.mutex, simcall->issuer);
456       SIMIX_simcall_answer(simcall);
457       break;
458
459     case SIMCALL_MUTEX_UNLOCK:
460       SIMIX_mutex_unlock(simcall->mutex_unlock.mutex, simcall->issuer);
461       SIMIX_simcall_answer(simcall);
462       break;
463
464     case SIMCALL_COND_INIT:
465       simcall->cond_init.result = SIMIX_cond_init();
466       SIMIX_simcall_answer(simcall);
467       break;
468
469     case SIMCALL_COND_DESTROY:
470       SIMIX_cond_destroy(simcall->cond_destroy.cond);
471       SIMIX_simcall_answer(simcall);
472       break;
473
474     case SIMCALL_COND_SIGNAL:
475       SIMIX_cond_signal(simcall->cond_signal.cond);
476       SIMIX_simcall_answer(simcall);
477       break;
478
479     case SIMCALL_COND_WAIT:
480       SIMIX_pre_cond_wait(simcall);
481       break;
482
483     case SIMCALL_COND_WAIT_TIMEOUT:
484       SIMIX_pre_cond_wait_timeout(simcall);
485       break;
486
487     case SIMCALL_COND_BROADCAST:
488       SIMIX_cond_broadcast(simcall->cond_broadcast.cond);
489       SIMIX_simcall_answer(simcall);
490       break;
491
492     case SIMCALL_SEM_INIT:
493       simcall->sem_init.result = SIMIX_sem_init(simcall->sem_init.capacity);
494       SIMIX_simcall_answer(simcall);
495       break;
496
497     case SIMCALL_SEM_DESTROY:
498       SIMIX_sem_destroy(simcall->sem_destroy.sem);
499       SIMIX_simcall_answer(simcall);
500       break;
501
502     case SIMCALL_SEM_RELEASE:
503       SIMIX_sem_release(simcall->sem_release.sem);
504       SIMIX_simcall_answer(simcall);
505       break;
506
507     case SIMCALL_SEM_WOULD_BLOCK:
508       simcall->sem_would_block.result =
509         SIMIX_sem_would_block(simcall->sem_would_block.sem);
510       SIMIX_simcall_answer(simcall);
511       break;
512
513     case SIMCALL_SEM_ACQUIRE:
514       SIMIX_pre_sem_acquire(simcall);
515       break;
516
517     case SIMCALL_SEM_ACQUIRE_TIMEOUT:
518       SIMIX_pre_sem_acquire_timeout(simcall);
519       break;
520
521     case SIMCALL_SEM_GET_CAPACITY:
522       simcall->sem_get_capacity.result = 
523         SIMIX_sem_get_capacity(simcall->sem_get_capacity.sem);
524       SIMIX_simcall_answer(simcall);
525       break;
526
527     case SIMCALL_FILE_READ:
528       SIMIX_pre_file_read(simcall);
529       break;
530
531     case SIMCALL_FILE_WRITE:
532       SIMIX_pre_file_write(simcall);
533       break;
534
535     case SIMCALL_FILE_OPEN:
536       SIMIX_pre_file_open(simcall);
537       break;
538
539     case SIMCALL_FILE_CLOSE:
540       SIMIX_pre_file_close(simcall);
541       break;
542
543     case SIMCALL_FILE_STAT:
544       SIMIX_pre_file_stat(simcall);
545       break;
546
547     case SIMCALL_FILE_UNLINK:
548       SIMIX_pre_file_unlink(simcall);
549       break;
550
551     case SIMCALL_FILE_LS:
552       SIMIX_pre_file_ls(simcall);
553       break;
554
555     case SIMCALL_ASR_GET_PROPERTIES:
556       simcall->asr_get_properties.result =
557         SIMIX_asr_get_properties(simcall->asr_get_properties.name);
558       SIMIX_simcall_answer(simcall);
559       break;
560
561 #ifdef HAVE_MC
562     case SIMCALL_MC_SNAPSHOT:
563       simcall->mc_snapshot.s = MC_take_snapshot_liveness();
564       SIMIX_simcall_answer(simcall);
565       break;
566
567     case SIMCALL_MC_COMPARE_SNAPSHOTS:
568       simcall->mc_compare_snapshots.result =
569         snapshot_compare(simcall->mc_compare_snapshots.snapshot1, simcall->mc_compare_snapshots.snapshot2);
570       SIMIX_simcall_answer(simcall);
571       break;
572 #endif /* HAVE_MC */
573
574     case SIMCALL_NONE:
575       THROWF(arg_error,0,"Asked to do the noop syscall on %s@%s",
576           SIMIX_process_get_name(simcall->issuer),
577           SIMIX_host_get_name(SIMIX_process_get_host(simcall->issuer))
578           );
579       break;
580
581     /* ****************************************************************************************** */
582     /* TUTORIAL: New API                                                                        */
583     /* ****************************************************************************************** */
584     case SIMCALL_NEW_API_INIT:
585       SIMIX_pre_new_api_fct(simcall);
586       break;
587   }
588 }
589
590 void SIMIX_simcall_post(smx_action_t action)
591 {
592   switch (action->type) {
593
594     case SIMIX_ACTION_EXECUTE:
595     case SIMIX_ACTION_PARALLEL_EXECUTE:
596       SIMIX_post_host_execute(action);
597       break;
598
599     case SIMIX_ACTION_COMMUNICATE:
600       SIMIX_post_comm(action);
601       break;
602
603     case SIMIX_ACTION_SLEEP:
604       SIMIX_post_process_sleep(action);
605       break;
606
607     case SIMIX_ACTION_SYNCHRO:
608       SIMIX_post_synchro(action);
609       break;
610
611     case SIMIX_ACTION_IO:
612       SIMIX_post_io(action);
613       break;
614
615     /* ****************************************************************************************** */
616     /* TUTORIAL: New API                                                                        */
617     /* ****************************************************************************************** */
618     case SIMIX_ACTION_NEW_API:
619       SIMIX_post_new_api(action);
620       break;
621   }
622 }