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 SIMIX_simcall_pre(&self->simcall, 0);
32 void SIMIX_simcall_answer(smx_simcall_t simcall)
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.
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; */
47 void SIMIX_simcall_pre(smx_simcall_t simcall, int value)
49 XBT_DEBUG("Handling simcall %p: %s", simcall, SIMIX_simcall_name(simcall->call));
51 switch (simcall->call) {
52 case SIMCALL_COMM_TEST:
53 SIMIX_pre_comm_test(simcall);
56 case SIMCALL_COMM_TESTANY:
57 SIMIX_pre_comm_testany(simcall, value);
60 case SIMCALL_COMM_WAIT:
61 SIMIX_pre_comm_wait(simcall,
62 simcall->comm_wait.comm,
63 simcall->comm_wait.timeout,
67 case SIMCALL_COMM_WAITANY:
68 SIMIX_pre_comm_waitany(simcall, value);
71 case SIMCALL_COMM_SEND:
73 smx_action_t comm = SIMIX_comm_isend(
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,
84 SIMIX_pre_comm_wait(simcall, comm, simcall->comm_send.timeout, 0);
88 case SIMCALL_COMM_ISEND:
89 simcall->comm_isend.result = SIMIX_comm_isend(
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);
103 case SIMCALL_COMM_RECV:
105 smx_action_t comm = SIMIX_comm_irecv(
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);
116 case SIMCALL_COMM_IRECV:
117 simcall->comm_irecv.result = SIMIX_comm_irecv(
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);
127 case SIMCALL_COMM_IPROBE:
128 simcall->comm_iprobe.result = SIMIX_comm_iprobe(
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);
138 case SIMCALL_COMM_DESTROY:
139 SIMIX_comm_destroy(simcall->comm_destroy.comm);
140 SIMIX_simcall_answer(simcall);
143 case SIMCALL_COMM_CANCEL:
144 SIMIX_comm_cancel(simcall->comm_cancel.comm);
145 SIMIX_simcall_answer(simcall);
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);
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);
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);
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);
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);
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);
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);
190 case SIMCALL_RDV_CREATE:
191 simcall->rdv_create.result = SIMIX_rdv_create(simcall->rdv_create.name);
192 SIMIX_simcall_answer(simcall);
195 case SIMCALL_RDV_DESTROY:
196 SIMIX_rdv_destroy(simcall->rdv_destroy.rdv);
197 SIMIX_simcall_answer(simcall);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
294 case SIMCALL_HOST_EXECUTION_DESTROY:
295 SIMIX_host_execution_destroy(simcall->host_execution_destroy.execution);
296 SIMIX_simcall_answer(simcall);
299 case SIMCALL_HOST_EXECUTION_CANCEL:
300 SIMIX_host_execution_cancel(simcall->host_execution_cancel.execution);
301 SIMIX_simcall_answer(simcall);
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);
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);
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);
323 case SIMCALL_HOST_EXECUTION_WAIT:
324 SIMIX_pre_host_execution_wait(simcall);
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);
342 case SIMCALL_PROCESS_KILL:
343 SIMIX_process_kill(simcall->process_kill.process,simcall->issuer);
344 SIMIX_simcall_answer(simcall);
347 case SIMCALL_PROCESS_KILLALL:
348 SIMIX_process_killall(simcall->issuer);
349 SIMIX_simcall_answer(simcall);
352 case SIMCALL_PROCESS_CLEANUP:
353 SIMIX_process_cleanup(simcall->process_cleanup.process);
354 SIMIX_simcall_answer(simcall);
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);
364 case SIMCALL_PROCESS_SUSPEND:
365 SIMIX_pre_process_suspend(simcall);
368 case SIMCALL_PROCESS_RESUME:
369 SIMIX_process_resume(simcall->process_resume.process, simcall->issuer);
370 SIMIX_simcall_answer(simcall);
373 case SIMCALL_PROCESS_COUNT:
374 simcall->process_count.result = SIMIX_process_count();
375 SIMIX_simcall_answer(simcall);
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);
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);
389 case SIMCALL_PROCESS_RESTART:
390 simcall->process_restart.result = SIMIX_process_restart(simcall->process_restart.process, simcall->issuer);
391 SIMIX_simcall_answer(simcall);
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);
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);
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);
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);
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);
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);
426 case SIMCALL_PROCESS_SLEEP:
427 SIMIX_pre_process_sleep(simcall);
431 case SIMCALL_SET_CATEGORY:
433 simcall->set_category.action,
434 simcall->set_category.category);
435 SIMIX_simcall_answer(simcall);
439 case SIMCALL_MUTEX_INIT:
440 simcall->mutex_init.result = SIMIX_mutex_init();
441 SIMIX_simcall_answer(simcall);
444 case SIMCALL_MUTEX_DESTROY:
445 SIMIX_mutex_destroy(simcall->mutex_destroy.mutex);
446 SIMIX_simcall_answer(simcall);
449 case SIMCALL_MUTEX_LOCK:
450 SIMIX_pre_mutex_lock(simcall);
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);
459 case SIMCALL_MUTEX_UNLOCK:
460 SIMIX_mutex_unlock(simcall->mutex_unlock.mutex, simcall->issuer);
461 SIMIX_simcall_answer(simcall);
464 case SIMCALL_COND_INIT:
465 simcall->cond_init.result = SIMIX_cond_init();
466 SIMIX_simcall_answer(simcall);
469 case SIMCALL_COND_DESTROY:
470 SIMIX_cond_destroy(simcall->cond_destroy.cond);
471 SIMIX_simcall_answer(simcall);
474 case SIMCALL_COND_SIGNAL:
475 SIMIX_cond_signal(simcall->cond_signal.cond);
476 SIMIX_simcall_answer(simcall);
479 case SIMCALL_COND_WAIT:
480 SIMIX_pre_cond_wait(simcall);
483 case SIMCALL_COND_WAIT_TIMEOUT:
484 SIMIX_pre_cond_wait_timeout(simcall);
487 case SIMCALL_COND_BROADCAST:
488 SIMIX_cond_broadcast(simcall->cond_broadcast.cond);
489 SIMIX_simcall_answer(simcall);
492 case SIMCALL_SEM_INIT:
493 simcall->sem_init.result = SIMIX_sem_init(simcall->sem_init.capacity);
494 SIMIX_simcall_answer(simcall);
497 case SIMCALL_SEM_DESTROY:
498 SIMIX_sem_destroy(simcall->sem_destroy.sem);
499 SIMIX_simcall_answer(simcall);
502 case SIMCALL_SEM_RELEASE:
503 SIMIX_sem_release(simcall->sem_release.sem);
504 SIMIX_simcall_answer(simcall);
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);
513 case SIMCALL_SEM_ACQUIRE:
514 SIMIX_pre_sem_acquire(simcall);
517 case SIMCALL_SEM_ACQUIRE_TIMEOUT:
518 SIMIX_pre_sem_acquire_timeout(simcall);
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);
527 case SIMCALL_FILE_READ:
528 SIMIX_pre_file_read(simcall);
531 case SIMCALL_FILE_WRITE:
532 SIMIX_pre_file_write(simcall);
535 case SIMCALL_FILE_OPEN:
536 SIMIX_pre_file_open(simcall);
539 case SIMCALL_FILE_CLOSE:
540 SIMIX_pre_file_close(simcall);
543 case SIMCALL_FILE_STAT:
544 SIMIX_pre_file_stat(simcall);
547 case SIMCALL_FILE_UNLINK:
548 SIMIX_pre_file_unlink(simcall);
551 case SIMCALL_FILE_LS:
552 SIMIX_pre_file_ls(simcall);
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);
562 case SIMCALL_MC_SNAPSHOT:
563 simcall->mc_snapshot.s = MC_take_snapshot_liveness();
564 SIMIX_simcall_answer(simcall);
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);
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))
581 /* ****************************************************************************************** */
582 /* TUTORIAL: New API */
583 /* ****************************************************************************************** */
584 case SIMCALL_NEW_API_INIT:
585 SIMIX_pre_new_api_fct(simcall);
590 void SIMIX_simcall_post(smx_action_t action)
592 switch (action->type) {
594 case SIMIX_ACTION_EXECUTE:
595 case SIMIX_ACTION_PARALLEL_EXECUTE:
596 SIMIX_post_host_execute(action);
599 case SIMIX_ACTION_COMMUNICATE:
600 SIMIX_post_comm(action);
603 case SIMIX_ACTION_SLEEP:
604 SIMIX_post_process_sleep(action);
607 case SIMIX_ACTION_SYNCHRO:
608 SIMIX_post_synchro(action);
611 case SIMIX_ACTION_IO:
612 SIMIX_post_io(action);
615 /* ****************************************************************************************** */
616 /* TUTORIAL: New API */
617 /* ****************************************************************************************** */
618 case SIMIX_ACTION_NEW_API:
619 SIMIX_post_new_api(action);