1 #include "smx_private.h"
3 #include "xbt/xbt_os_thread.h"
4 #include "../mc/mc_private.h"
6 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_smurf, simix,
7 "Logging specific to SIMIX (SMURF)");
9 XBT_INLINE smx_simcall_t SIMIX_simcall_mine()
11 smx_process_t issuer = SIMIX_process_self();
12 return &issuer->simcall;
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
21 void SIMIX_simcall_push(smx_process_t self)
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);
28 XBT_DEBUG("I'm the maestro, execute the simcall directly");
29 SIMIX_simcall_pre(&self->simcall, 0);
33 void SIMIX_simcall_answer(smx_simcall_t simcall)
35 if (simcall->issuer != simix_global->maestro_process){
36 XBT_DEBUG("Answer simcall %s (%d) issued by %s (%p)", SIMIX_simcall_name(simcall->call), (int)simcall->call,
37 simcall->issuer->name, simcall->issuer);
38 simcall->issuer->simcall.call = SIMCALL_NONE;
39 /* This check should be useless and slows everyone. Reactivate if you see something
40 * weird in process scheduling.
42 /* if(!xbt_dynar_member(simix_global->process_to_run, &(simcall->issuer))) */
43 xbt_dynar_push_as(simix_global->process_to_run, smx_process_t, simcall->issuer);
44 /* else DIE_IMPOSSIBLE; */
48 void SIMIX_simcall_pre(smx_simcall_t simcall, int value)
50 XBT_DEBUG("Handling simcall %p: %s", simcall, SIMIX_simcall_name(simcall->call));
52 switch (simcall->call) {
53 case SIMCALL_COMM_TEST:
54 SIMIX_pre_comm_test(simcall);
57 case SIMCALL_COMM_TESTANY:
58 SIMIX_pre_comm_testany(simcall, value);
61 case SIMCALL_COMM_WAIT:
62 SIMIX_pre_comm_wait(simcall,
63 simcall->comm_wait.comm,
64 simcall->comm_wait.timeout,
68 case SIMCALL_COMM_WAITANY:
69 SIMIX_pre_comm_waitany(simcall, value);
72 case SIMCALL_COMM_SEND:
74 smx_action_t comm = SIMIX_comm_isend(
76 simcall->comm_send.rdv,
77 simcall->comm_send.task_size,
78 simcall->comm_send.rate,
79 simcall->comm_send.src_buff,
80 simcall->comm_send.src_buff_size,
81 simcall->comm_send.match_fun,
82 NULL, /* no clean function since it's not detached */
83 simcall->comm_send.data,
85 SIMIX_pre_comm_wait(simcall, comm, simcall->comm_send.timeout, 0);
89 case SIMCALL_COMM_ISEND:
90 simcall->comm_isend.result = SIMIX_comm_isend(
92 simcall->comm_isend.rdv,
93 simcall->comm_isend.task_size,
94 simcall->comm_isend.rate,
95 simcall->comm_isend.src_buff,
96 simcall->comm_isend.src_buff_size,
97 simcall->comm_isend.match_fun,
98 simcall->comm_isend.clean_fun,
99 simcall->comm_isend.data,
100 simcall->comm_isend.detached);
101 SIMIX_simcall_answer(simcall);
104 case SIMCALL_COMM_RECV:
106 smx_action_t comm = SIMIX_comm_irecv(
108 simcall->comm_recv.rdv,
109 simcall->comm_recv.dst_buff,
110 simcall->comm_recv.dst_buff_size,
111 simcall->comm_recv.match_fun,
112 simcall->comm_recv.data);
113 SIMIX_pre_comm_wait(simcall, comm, simcall->comm_recv.timeout, 0);
117 case SIMCALL_COMM_IRECV:
118 simcall->comm_irecv.result = SIMIX_comm_irecv(
120 simcall->comm_irecv.rdv,
121 simcall->comm_irecv.dst_buff,
122 simcall->comm_irecv.dst_buff_size,
123 simcall->comm_irecv.match_fun,
124 simcall->comm_irecv.data);
125 SIMIX_simcall_answer(simcall);
128 case SIMCALL_COMM_IPROBE:
129 simcall->comm_iprobe.result = SIMIX_comm_iprobe(
131 simcall->comm_iprobe.rdv,
132 simcall->comm_iprobe.src,
133 simcall->comm_iprobe.tag,
134 simcall->comm_iprobe.match_fun,
135 simcall->comm_iprobe.data);
136 SIMIX_simcall_answer(simcall);
139 case SIMCALL_COMM_DESTROY:
140 SIMIX_comm_destroy(simcall->comm_destroy.comm);
141 SIMIX_simcall_answer(simcall);
144 case SIMCALL_COMM_CANCEL:
145 SIMIX_comm_cancel(simcall->comm_cancel.comm);
146 SIMIX_simcall_answer(simcall);
149 case SIMCALL_COMM_GET_REMAINS:
150 simcall->comm_get_remains.result =
151 SIMIX_comm_get_remains(simcall->comm_get_remains.comm);
152 SIMIX_simcall_answer(simcall);
155 case SIMCALL_COMM_GET_STATE:
156 simcall->comm_get_state.result =
157 SIMIX_comm_get_state(simcall->comm_get_state.comm);
158 SIMIX_simcall_answer(simcall);
161 case SIMCALL_COMM_GET_SRC_DATA:
162 simcall->comm_get_src_data.result = SIMIX_comm_get_src_data(simcall->comm_get_src_data.comm);
163 SIMIX_simcall_answer(simcall);
166 case SIMCALL_COMM_GET_DST_DATA:
167 simcall->comm_get_dst_data.result = SIMIX_comm_get_dst_data(simcall->comm_get_dst_data.comm);
168 SIMIX_simcall_answer(simcall);
171 case SIMCALL_COMM_GET_SRC_PROC:
172 simcall->comm_get_src_proc.result =
173 SIMIX_comm_get_src_proc(simcall->comm_get_src_proc.comm);
174 SIMIX_simcall_answer(simcall);
177 case SIMCALL_COMM_GET_DST_PROC:
178 simcall->comm_get_dst_proc.result =
179 SIMIX_comm_get_dst_proc(simcall->comm_get_dst_proc.comm);
180 SIMIX_simcall_answer(simcall);
183 #ifdef HAVE_LATENCY_BOUND_TRACKING
184 case SIMCALL_COMM_IS_LATENCY_BOUNDED:
185 simcall->comm_is_latency_bounded.result =
186 SIMIX_comm_is_latency_bounded(simcall->comm_is_latency_bounded.comm);
187 SIMIX_simcall_answer(simcall);
191 case SIMCALL_RDV_CREATE:
192 simcall->rdv_create.result = SIMIX_rdv_create(simcall->rdv_create.name);
193 SIMIX_simcall_answer(simcall);
196 case SIMCALL_RDV_DESTROY:
197 SIMIX_rdv_destroy(simcall->rdv_destroy.rdv);
198 SIMIX_simcall_answer(simcall);
201 case SIMCALL_RDV_GET_BY_NAME:
202 simcall->rdv_get_by_name.result =
203 SIMIX_rdv_get_by_name(simcall->rdv_get_by_name.name);
204 SIMIX_simcall_answer(simcall);
207 case SIMCALL_RDV_COMM_COUNT_BY_HOST:
208 simcall->rdv_comm_count_by_host.result = SIMIX_rdv_comm_count_by_host(
209 simcall->rdv_comm_count_by_host.rdv,
210 simcall->rdv_comm_count_by_host.host);
211 SIMIX_simcall_answer(simcall);
214 case SIMCALL_RDV_GET_HEAD:
215 simcall->rdv_get_head.result = SIMIX_rdv_get_head(simcall->rdv_get_head.rdv);
216 SIMIX_simcall_answer(simcall);
219 case SIMCALL_RDV_SET_RECV:
220 SIMIX_rdv_set_receiver(simcall->rdv_set_rcv_proc.rdv, simcall->rdv_set_rcv_proc.receiver);
221 SIMIX_simcall_answer(simcall);
224 case SIMCALL_RDV_GET_RECV:
225 simcall->rdv_get_rcv_proc.result = SIMIX_rdv_get_receiver(simcall->rdv_set_rcv_proc.rdv);
226 SIMIX_simcall_answer(simcall);
229 case SIMCALL_HOST_GET_BY_NAME:
230 simcall->host_get_by_name.result =
231 SIMIX_host_get_by_name(simcall->args);
232 SIMIX_simcall_answer(simcall);
235 case SIMCALL_HOST_GET_NAME:
236 simcall->host_get_name.result = SIMIX_host_get_name(simcall->args);
237 SIMIX_simcall_answer(simcall);
240 case SIMCALL_HOST_GET_PROPERTIES:
241 simcall->host_get_properties.result =
242 SIMIX_host_get_properties(simcall->args);
243 SIMIX_simcall_answer(simcall);
246 case SIMCALL_HOST_GET_SPEED:
247 simcall->host_get_speed.result =
248 SIMIX_host_get_speed(simcall->args);
249 SIMIX_simcall_answer(simcall);
252 case SIMCALL_HOST_GET_AVAILABLE_SPEED:
253 simcall->host_get_available_speed.result =
254 SIMIX_host_get_available_speed(simcall->args);
255 SIMIX_simcall_answer(simcall);
258 case SIMCALL_HOST_GET_STATE:
259 simcall->host_get_state.result =
260 SIMIX_host_get_state(simcall->args);
261 SIMIX_simcall_answer(simcall);
264 case SIMCALL_HOST_GET_DATA:
265 simcall->host_get_data.result = SIMIX_host_get_data(simcall->args);
266 SIMIX_simcall_answer(simcall);
269 case SIMCALL_HOST_SET_DATA:
270 SIMIX_host_set_data(SIMIX_pack_args(PTR(simcall->host_set_data.host), PTR(simcall->host_set_data.data)));
271 SIMIX_simcall_answer(simcall);
274 case SIMCALL_HOST_EXECUTE:
275 simcall->host_execute.result = simcall_table[simcall->call](simcall->args);
276 SIMIX_simcall_answer(simcall);
279 case SIMCALL_HOST_PARALLEL_EXECUTE:
280 simcall->host_parallel_execute.result = SIMIX_host_parallel_execute(simcall->args);
281 SIMIX_simcall_answer(simcall);
284 case SIMCALL_HOST_EXECUTION_DESTROY:
285 SIMIX_host_execution_destroy(simcall->args);
286 SIMIX_simcall_answer(simcall);
289 case SIMCALL_HOST_EXECUTION_CANCEL:
290 SIMIX_host_execution_cancel(simcall->args);
291 SIMIX_simcall_answer(simcall);
294 case SIMCALL_HOST_EXECUTION_GET_REMAINS:
295 simcall->host_execution_get_remains.result =
296 SIMIX_host_execution_get_remains(simcall->args);
297 SIMIX_simcall_answer(simcall);
300 case SIMCALL_HOST_EXECUTION_GET_STATE:
301 simcall->host_execution_get_state.result =
302 SIMIX_host_execution_get_state(simcall->args);
303 SIMIX_simcall_answer(simcall);
306 case SIMCALL_HOST_EXECUTION_SET_PRIORITY:
307 SIMIX_host_execution_set_priority(simcall->args);
308 SIMIX_simcall_answer(simcall);
311 case SIMCALL_HOST_EXECUTION_WAIT:
312 SIMIX_pre_host_execution_wait(simcall->args);
315 case SIMCALL_PROCESS_CREATE:
316 SIMIX_process_create(
317 simcall->process_create.process,
318 simcall->process_create.name,
319 simcall->process_create.code,
320 simcall->process_create.data,
321 simcall->process_create.hostname,
322 simcall->process_create.kill_time,
323 simcall->process_create.argc,
324 simcall->process_create.argv,
325 simcall->process_create.properties,
326 simcall->process_create.auto_restart);
327 SIMIX_simcall_answer(simcall);
330 case SIMCALL_PROCESS_KILL:
331 SIMIX_process_kill(simcall->process_kill.process,simcall->issuer);
332 SIMIX_simcall_answer(simcall);
335 case SIMCALL_PROCESS_KILLALL:
336 SIMIX_process_killall(simcall->issuer);
337 SIMIX_simcall_answer(simcall);
340 case SIMCALL_PROCESS_CLEANUP:
341 SIMIX_process_cleanup(simcall->process_cleanup.process);
342 SIMIX_simcall_answer(simcall);
345 case SIMCALL_PROCESS_CHANGE_HOST:
346 SIMIX_pre_process_change_host(
347 simcall->process_change_host.process,
348 simcall->process_change_host.dest);
349 SIMIX_simcall_answer(simcall);
352 case SIMCALL_PROCESS_SUSPEND:
353 SIMIX_pre_process_suspend(simcall);
356 case SIMCALL_PROCESS_RESUME:
357 SIMIX_process_resume(simcall->process_resume.process, simcall->issuer);
358 SIMIX_simcall_answer(simcall);
361 case SIMCALL_PROCESS_COUNT:
362 simcall->process_count.result = SIMIX_process_count();
363 SIMIX_simcall_answer(simcall);
366 case SIMCALL_PROCESS_GET_DATA:
367 simcall->process_get_data.result =
368 SIMIX_process_get_data(simcall->process_get_data.process);
369 SIMIX_simcall_answer(simcall);
371 case SIMCALL_PROCESS_ON_EXIT:
372 SIMIX_process_on_exit(simcall->process_on_exit.process,
373 simcall->process_on_exit.fun,
374 simcall->process_on_exit.data);
375 SIMIX_simcall_answer(simcall);
377 case SIMCALL_PROCESS_RESTART:
378 simcall->process_restart.result = SIMIX_process_restart(simcall->process_restart.process, simcall->issuer);
379 SIMIX_simcall_answer(simcall);
381 case SIMCALL_PROCESS_AUTO_RESTART_SET:
382 SIMIX_process_auto_restart_set(simcall->process_auto_restart.process,simcall->process_auto_restart.auto_restart);
383 SIMIX_simcall_answer(simcall);
385 case SIMCALL_PROCESS_SET_DATA:
386 SIMIX_process_set_data(
387 simcall->process_set_data.process,
388 simcall->process_set_data.data);
389 SIMIX_simcall_answer(simcall);
392 case SIMCALL_PROCESS_GET_HOST:
393 simcall->process_get_host.result = SIMIX_process_get_host(simcall->process_get_host.process);
394 SIMIX_simcall_answer(simcall);
397 case SIMCALL_PROCESS_GET_NAME:
398 simcall->process_get_name.result = SIMIX_process_get_name(simcall->process_get_name.process);
399 SIMIX_simcall_answer(simcall);
402 case SIMCALL_PROCESS_IS_SUSPENDED:
403 simcall->process_is_suspended.result =
404 SIMIX_process_is_suspended(simcall->process_is_suspended.process);
405 SIMIX_simcall_answer(simcall);
408 case SIMCALL_PROCESS_GET_PROPERTIES:
409 simcall->process_get_properties.result =
410 SIMIX_process_get_properties(simcall->process_get_properties.process);
411 SIMIX_simcall_answer(simcall);
414 case SIMCALL_PROCESS_SLEEP:
415 SIMIX_pre_process_sleep(simcall);
419 case SIMCALL_SET_CATEGORY:
421 simcall->set_category.action,
422 simcall->set_category.category);
423 SIMIX_simcall_answer(simcall);
427 case SIMCALL_MUTEX_INIT:
428 simcall->mutex_init.result = SIMIX_mutex_init();
429 SIMIX_simcall_answer(simcall);
432 case SIMCALL_MUTEX_DESTROY:
433 SIMIX_mutex_destroy(simcall->mutex_destroy.mutex);
434 SIMIX_simcall_answer(simcall);
437 case SIMCALL_MUTEX_LOCK:
438 SIMIX_pre_mutex_lock(simcall);
441 case SIMCALL_MUTEX_TRYLOCK:
442 simcall->mutex_trylock.result =
443 SIMIX_mutex_trylock(simcall->mutex_trylock.mutex, simcall->issuer);
444 SIMIX_simcall_answer(simcall);
447 case SIMCALL_MUTEX_UNLOCK:
448 SIMIX_mutex_unlock(simcall->mutex_unlock.mutex, simcall->issuer);
449 SIMIX_simcall_answer(simcall);
452 case SIMCALL_COND_INIT:
453 simcall->cond_init.result = SIMIX_cond_init();
454 SIMIX_simcall_answer(simcall);
457 case SIMCALL_COND_DESTROY:
458 SIMIX_cond_destroy(simcall->cond_destroy.cond);
459 SIMIX_simcall_answer(simcall);
462 case SIMCALL_COND_SIGNAL:
463 SIMIX_cond_signal(simcall->cond_signal.cond);
464 SIMIX_simcall_answer(simcall);
467 case SIMCALL_COND_WAIT:
468 SIMIX_pre_cond_wait(simcall);
471 case SIMCALL_COND_WAIT_TIMEOUT:
472 SIMIX_pre_cond_wait_timeout(simcall);
475 case SIMCALL_COND_BROADCAST:
476 SIMIX_cond_broadcast(simcall->cond_broadcast.cond);
477 SIMIX_simcall_answer(simcall);
480 case SIMCALL_SEM_INIT:
481 simcall->sem_init.result = SIMIX_sem_init(simcall->sem_init.capacity);
482 SIMIX_simcall_answer(simcall);
485 case SIMCALL_SEM_DESTROY:
486 SIMIX_sem_destroy(simcall->sem_destroy.sem);
487 SIMIX_simcall_answer(simcall);
490 case SIMCALL_SEM_RELEASE:
491 SIMIX_sem_release(simcall->sem_release.sem);
492 SIMIX_simcall_answer(simcall);
495 case SIMCALL_SEM_WOULD_BLOCK:
496 simcall->sem_would_block.result =
497 SIMIX_sem_would_block(simcall->sem_would_block.sem);
498 SIMIX_simcall_answer(simcall);
501 case SIMCALL_SEM_ACQUIRE:
502 SIMIX_pre_sem_acquire(simcall);
505 case SIMCALL_SEM_ACQUIRE_TIMEOUT:
506 SIMIX_pre_sem_acquire_timeout(simcall);
509 case SIMCALL_SEM_GET_CAPACITY:
510 simcall->sem_get_capacity.result =
511 SIMIX_sem_get_capacity(simcall->sem_get_capacity.sem);
512 SIMIX_simcall_answer(simcall);
515 case SIMCALL_FILE_READ:
516 SIMIX_pre_file_read(simcall);
519 case SIMCALL_FILE_WRITE:
520 SIMIX_pre_file_write(simcall);
523 case SIMCALL_FILE_OPEN:
524 SIMIX_pre_file_open(simcall);
527 case SIMCALL_FILE_CLOSE:
528 SIMIX_pre_file_close(simcall);
531 case SIMCALL_FILE_STAT:
532 SIMIX_pre_file_stat(simcall);
535 case SIMCALL_FILE_UNLINK:
536 SIMIX_pre_file_unlink(simcall);
539 case SIMCALL_FILE_LS:
540 SIMIX_pre_file_ls(simcall);
543 case SIMCALL_ASR_GET_PROPERTIES:
544 simcall->asr_get_properties.result =
545 SIMIX_asr_get_properties(simcall->asr_get_properties.name);
546 SIMIX_simcall_answer(simcall);
550 case SIMCALL_MC_SNAPSHOT:
551 simcall->mc_snapshot.s = MC_take_snapshot();
552 SIMIX_simcall_answer(simcall);
555 case SIMCALL_MC_COMPARE_SNAPSHOTS:
556 simcall->mc_compare_snapshots.result =
557 snapshot_compare(simcall->mc_compare_snapshots.snapshot1, simcall->mc_compare_snapshots.snapshot2, NULL, NULL);
558 SIMIX_simcall_answer(simcall);
563 THROWF(arg_error,0,"Asked to do the noop syscall on %s@%s",
564 SIMIX_process_get_name(simcall->issuer),
565 SIMIX_host_get_name(SIMIX_process_get_host(simcall->issuer))
569 /* ****************************************************************************************** */
570 /* TUTORIAL: New API */
571 /* ****************************************************************************************** */
572 case SIMCALL_NEW_API_INIT:
573 SIMIX_pre_new_api_fct(simcall);
578 void SIMIX_simcall_post(smx_action_t action)
580 switch (action->type) {
582 case SIMIX_ACTION_EXECUTE:
583 case SIMIX_ACTION_PARALLEL_EXECUTE:
584 SIMIX_post_host_execute(action);
587 case SIMIX_ACTION_COMMUNICATE:
588 SIMIX_post_comm(action);
591 case SIMIX_ACTION_SLEEP:
592 SIMIX_post_process_sleep(action);
595 case SIMIX_ACTION_SYNCHRO:
596 SIMIX_post_synchro(action);
599 case SIMIX_ACTION_IO:
600 SIMIX_post_io(action);
603 /* ****************************************************************************************** */
604 /* TUTORIAL: New API */
605 /* ****************************************************************************************** */
606 case SIMIX_ACTION_NEW_API:
607 SIMIX_post_new_api(action);
612 /* New Simcal interface */
614 /* FIXME: add types for every simcall */
615 const char *simcall_types[NUM_SIMCALLS] = { [SIMCALL_HOST_EXECUTE] = "%s%p%f%f%p" };
617 simcall_handler_t simcall_table[NUM_SIMCALLS] = {
618 #undef SIMCALL_ENUM_ELEMENT
619 #define SIMCALL_ENUM_ELEMENT(x,y) &y /* generate strings from the enumeration values */
621 #undef SIMCALL_ENUM_ELEMENT
625 void SIMIX_simcall_typecheck(const char *fmt, ...)
630 void __SIMIX_simcall(e_smx_simcall_t simcall_id, u_smx_scalar_t *args)
632 smx_process_t self = SIMIX_process_self();
633 self->simcall.call = simcall_id;
634 self->simcall.args = args;
636 if (self != simix_global->maestro_process) {
637 XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name,
638 SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call);
640 SIMIX_process_yield(self);
643 SIMIX_simcall_pre(&self->simcall, 0);
647 /* New Simcal interface */
649 /* FIXME: add types for every simcall */
650 const char *simcall_types[NUM_SIMCALLS] = { [SIMCALL_HOST_EXECUTE] = "%s%p%f%f%p", [SIMCALL_HOST_EXECUTION_WAIT] = "%p%p" };
653 simcall_handler_t simcall_table[NUM_SIMCALLS] = {
654 #undef SIMCALL_ENUM_ELEMENT
655 #define SIMCALL_ENUM_ELEMENT(x,y) &y /* generate strings from the enumeration values */
657 #undef SIMCALL_ENUM_ELEMENT
661 void SIMIX_simcall_typecheck(const char *fmt, ...)
666 void __SIMIX_simcall(e_smx_simcall_t simcall_id, u_smx_scalar_t *args)
668 smx_process_t self = SIMIX_process_self();
669 self->simcall.call = simcall_id;
670 self->simcall.args = args;
672 if (self != simix_global->maestro_process) {
673 XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name,
674 SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call);
676 SIMIX_process_yield(self);
679 SIMIX_simcall_pre(&self->simcall, 0);