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_GEY_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->host_get_by_name.name);
232 SIMIX_simcall_answer(simcall);
235 case SIMCALL_HOST_GET_NAME:
236 simcall->host_get_name.result = SIMIX_host_get_name(simcall->host_get_name.host);
237 SIMIX_simcall_answer(simcall);
240 case SIMCALL_HOST_GET_PROPERTIES:
241 simcall->host_get_properties.result =
242 SIMIX_host_get_properties(simcall->host_get_properties.host);
243 SIMIX_simcall_answer(simcall);
246 case SIMCALL_HOST_GET_SPEED:
247 simcall->host_get_speed.result =
248 SIMIX_host_get_speed(simcall->host_get_speed.host);
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->host_get_available_speed.host);
255 SIMIX_simcall_answer(simcall);
258 case SIMCALL_HOST_GET_STATE:
259 simcall->host_get_state.result =
260 SIMIX_host_get_state(simcall->host_get_state.host);
261 SIMIX_simcall_answer(simcall);
264 case SIMCALL_HOST_GET_DATA:
265 simcall->host_get_data.result = SIMIX_host_get_data(simcall->host_get_data.host);
266 SIMIX_simcall_answer(simcall);
269 case SIMCALL_HOST_SET_DATA:
270 SIMIX_host_set_data(simcall->host_set_data.host, simcall->host_set_data.data);
271 SIMIX_simcall_answer(simcall);
274 case SIMCALL_HOST_EXECUTE:
275 simcall->host_execute.result = SIMIX_host_execute(
276 simcall->host_execute.name,
277 simcall->host_execute.host,
278 simcall->host_execute.computation_amount,
279 simcall->host_execute.priority);
280 SIMIX_simcall_answer(simcall);
283 case SIMCALL_HOST_PARALLEL_EXECUTE:
284 simcall->host_parallel_execute.result = SIMIX_host_parallel_execute(
285 simcall->host_parallel_execute.name,
286 simcall->host_parallel_execute.host_nb,
287 simcall->host_parallel_execute.host_list,
288 simcall->host_parallel_execute.computation_amount,
289 simcall->host_parallel_execute.communication_amount,
290 simcall->host_parallel_execute.amount,
291 simcall->host_parallel_execute.rate);
292 SIMIX_simcall_answer(simcall);
295 case SIMCALL_HOST_EXECUTION_DESTROY:
296 SIMIX_host_execution_destroy(simcall->host_execution_destroy.execution);
297 SIMIX_simcall_answer(simcall);
300 case SIMCALL_HOST_EXECUTION_CANCEL:
301 SIMIX_host_execution_cancel(simcall->host_execution_cancel.execution);
302 SIMIX_simcall_answer(simcall);
305 case SIMCALL_HOST_EXECUTION_GET_REMAINS:
306 simcall->host_execution_get_remains.result =
307 SIMIX_host_execution_get_remains(simcall->host_execution_get_remains.execution);
308 SIMIX_simcall_answer(simcall);
311 case SIMCALL_HOST_EXECUTION_GET_STATE:
312 simcall->host_execution_get_state.result =
313 SIMIX_host_execution_get_state(simcall->host_execution_get_state.execution);
314 SIMIX_simcall_answer(simcall);
317 case SIMCALL_HOST_EXECUTION_SET_PRIORITY:
318 SIMIX_host_execution_set_priority(
319 simcall->host_execution_set_priority.execution,
320 simcall->host_execution_set_priority.priority);
321 SIMIX_simcall_answer(simcall);
324 case SIMCALL_HOST_EXECUTION_WAIT:
325 SIMIX_pre_host_execution_wait(simcall);
328 case SIMCALL_PROCESS_CREATE:
329 SIMIX_process_create(
330 simcall->process_create.process,
331 simcall->process_create.name,
332 simcall->process_create.code,
333 simcall->process_create.data,
334 simcall->process_create.hostname,
335 simcall->process_create.kill_time,
336 simcall->process_create.argc,
337 simcall->process_create.argv,
338 simcall->process_create.properties,
339 simcall->process_create.auto_restart);
340 SIMIX_simcall_answer(simcall);
343 case SIMCALL_PROCESS_KILL:
344 SIMIX_process_kill(simcall->process_kill.process,simcall->issuer);
345 SIMIX_simcall_answer(simcall);
348 case SIMCALL_PROCESS_KILLALL:
349 SIMIX_process_killall(simcall->issuer);
350 SIMIX_simcall_answer(simcall);
353 case SIMCALL_PROCESS_CLEANUP:
354 SIMIX_process_cleanup(simcall->process_cleanup.process);
355 SIMIX_simcall_answer(simcall);
358 case SIMCALL_PROCESS_CHANGE_HOST:
359 SIMIX_pre_process_change_host(
360 simcall->process_change_host.process,
361 simcall->process_change_host.dest);
362 SIMIX_simcall_answer(simcall);
365 case SIMCALL_PROCESS_SUSPEND:
366 SIMIX_pre_process_suspend(simcall);
369 case SIMCALL_PROCESS_RESUME:
370 SIMIX_process_resume(simcall->process_resume.process, simcall->issuer);
371 SIMIX_simcall_answer(simcall);
374 case SIMCALL_PROCESS_COUNT:
375 simcall->process_count.result = SIMIX_process_count();
376 SIMIX_simcall_answer(simcall);
379 case SIMCALL_PROCESS_GET_DATA:
380 simcall->process_get_data.result =
381 SIMIX_process_get_data(simcall->process_get_data.process);
382 SIMIX_simcall_answer(simcall);
384 case SIMCALL_PROCESS_ON_EXIT:
385 SIMIX_process_on_exit(simcall->process_on_exit.process,
386 simcall->process_on_exit.fun,
387 simcall->process_on_exit.data);
388 SIMIX_simcall_answer(simcall);
390 case SIMCALL_PROCESS_RESTART:
391 simcall->process_restart.result = SIMIX_process_restart(simcall->process_restart.process, simcall->issuer);
392 SIMIX_simcall_answer(simcall);
394 case SIMCALL_PROCESS_AUTO_RESTART_SET:
395 SIMIX_process_auto_restart_set(simcall->process_auto_restart.process,simcall->process_auto_restart.auto_restart);
396 SIMIX_simcall_answer(simcall);
398 case SIMCALL_PROCESS_SET_DATA:
399 SIMIX_process_set_data(
400 simcall->process_set_data.process,
401 simcall->process_set_data.data);
402 SIMIX_simcall_answer(simcall);
405 case SIMCALL_PROCESS_GET_HOST:
406 simcall->process_get_host.result = SIMIX_process_get_host(simcall->process_get_host.process);
407 SIMIX_simcall_answer(simcall);
410 case SIMCALL_PROCESS_GET_NAME:
411 simcall->process_get_name.result = SIMIX_process_get_name(simcall->process_get_name.process);
412 SIMIX_simcall_answer(simcall);
415 case SIMCALL_PROCESS_IS_SUSPENDED:
416 simcall->process_is_suspended.result =
417 SIMIX_process_is_suspended(simcall->process_is_suspended.process);
418 SIMIX_simcall_answer(simcall);
421 case SIMCALL_PROCESS_GET_PROPERTIES:
422 simcall->process_get_properties.result =
423 SIMIX_process_get_properties(simcall->process_get_properties.process);
424 SIMIX_simcall_answer(simcall);
427 case SIMCALL_PROCESS_SLEEP:
428 SIMIX_pre_process_sleep(simcall);
432 case SIMCALL_SET_CATEGORY:
434 simcall->set_category.action,
435 simcall->set_category.category);
436 SIMIX_simcall_answer(simcall);
440 case SIMCALL_MUTEX_INIT:
441 simcall->mutex_init.result = SIMIX_mutex_init();
442 SIMIX_simcall_answer(simcall);
445 case SIMCALL_MUTEX_DESTROY:
446 SIMIX_mutex_destroy(simcall->mutex_destroy.mutex);
447 SIMIX_simcall_answer(simcall);
450 case SIMCALL_MUTEX_LOCK:
451 SIMIX_pre_mutex_lock(simcall);
454 case SIMCALL_MUTEX_TRYLOCK:
455 simcall->mutex_trylock.result =
456 SIMIX_mutex_trylock(simcall->mutex_trylock.mutex, simcall->issuer);
457 SIMIX_simcall_answer(simcall);
460 case SIMCALL_MUTEX_UNLOCK:
461 SIMIX_mutex_unlock(simcall->mutex_unlock.mutex, simcall->issuer);
462 SIMIX_simcall_answer(simcall);
465 case SIMCALL_COND_INIT:
466 simcall->cond_init.result = SIMIX_cond_init();
467 SIMIX_simcall_answer(simcall);
470 case SIMCALL_COND_DESTROY:
471 SIMIX_cond_destroy(simcall->cond_destroy.cond);
472 SIMIX_simcall_answer(simcall);
475 case SIMCALL_COND_SIGNAL:
476 SIMIX_cond_signal(simcall->cond_signal.cond);
477 SIMIX_simcall_answer(simcall);
480 case SIMCALL_COND_WAIT:
481 SIMIX_pre_cond_wait(simcall);
484 case SIMCALL_COND_WAIT_TIMEOUT:
485 SIMIX_pre_cond_wait_timeout(simcall);
488 case SIMCALL_COND_BROADCAST:
489 SIMIX_cond_broadcast(simcall->cond_broadcast.cond);
490 SIMIX_simcall_answer(simcall);
493 case SIMCALL_SEM_INIT:
494 simcall->sem_init.result = SIMIX_sem_init(simcall->sem_init.capacity);
495 SIMIX_simcall_answer(simcall);
498 case SIMCALL_SEM_DESTROY:
499 SIMIX_sem_destroy(simcall->sem_destroy.sem);
500 SIMIX_simcall_answer(simcall);
503 case SIMCALL_SEM_RELEASE:
504 SIMIX_sem_release(simcall->sem_release.sem);
505 SIMIX_simcall_answer(simcall);
508 case SIMCALL_SEM_WOULD_BLOCK:
509 simcall->sem_would_block.result =
510 SIMIX_sem_would_block(simcall->sem_would_block.sem);
511 SIMIX_simcall_answer(simcall);
514 case SIMCALL_SEM_ACQUIRE:
515 SIMIX_pre_sem_acquire(simcall);
518 case SIMCALL_SEM_ACQUIRE_TIMEOUT:
519 SIMIX_pre_sem_acquire_timeout(simcall);
522 case SIMCALL_SEM_GET_CAPACITY:
523 simcall->sem_get_capacity.result =
524 SIMIX_sem_get_capacity(simcall->sem_get_capacity.sem);
525 SIMIX_simcall_answer(simcall);
528 case SIMCALL_FILE_READ:
529 SIMIX_pre_file_read(simcall);
532 case SIMCALL_FILE_WRITE:
533 SIMIX_pre_file_write(simcall);
536 case SIMCALL_FILE_OPEN:
537 SIMIX_pre_file_open(simcall);
540 case SIMCALL_FILE_CLOSE:
541 SIMIX_pre_file_close(simcall);
544 case SIMCALL_FILE_STAT:
545 SIMIX_pre_file_stat(simcall);
548 case SIMCALL_FILE_UNLINK:
549 SIMIX_pre_file_unlink(simcall);
552 case SIMCALL_FILE_LS:
553 SIMIX_pre_file_ls(simcall);
556 case SIMCALL_ASR_GET_PROPERTIES:
557 simcall->asr_get_properties.result =
558 SIMIX_asr_get_properties(simcall->asr_get_properties.name);
559 SIMIX_simcall_answer(simcall);
563 case SIMCALL_MC_SNAPSHOT:
564 simcall->mc_snapshot.s = MC_take_snapshot();
565 SIMIX_simcall_answer(simcall);
568 case SIMCALL_MC_COMPARE_SNAPSHOTS:
569 simcall->mc_compare_snapshots.result =
570 snapshot_compare(simcall->mc_compare_snapshots.snapshot1, simcall->mc_compare_snapshots.snapshot2, NULL, NULL);
571 SIMIX_simcall_answer(simcall);
576 THROWF(arg_error,0,"Asked to do the noop syscall on %s@%s",
577 SIMIX_process_get_name(simcall->issuer),
578 SIMIX_host_get_name(SIMIX_process_get_host(simcall->issuer))
582 /* ****************************************************************************************** */
583 /* TUTORIAL: New API */
584 /* ****************************************************************************************** */
585 case SIMCALL_NEW_API_INIT:
586 SIMIX_pre_new_api_fct(simcall);
591 void SIMIX_simcall_post(smx_action_t action)
593 switch (action->type) {
595 case SIMIX_ACTION_EXECUTE:
596 case SIMIX_ACTION_PARALLEL_EXECUTE:
597 SIMIX_post_host_execute(action);
600 case SIMIX_ACTION_COMMUNICATE:
601 SIMIX_post_comm(action);
604 case SIMIX_ACTION_SLEEP:
605 SIMIX_post_process_sleep(action);
608 case SIMIX_ACTION_SYNCHRO:
609 SIMIX_post_synchro(action);
612 case SIMIX_ACTION_IO:
613 SIMIX_post_io(action);
616 /* ****************************************************************************************** */
617 /* TUTORIAL: New API */
618 /* ****************************************************************************************** */
619 case SIMIX_ACTION_NEW_API:
620 SIMIX_post_new_api(action);