1 #include "smx_private.h"
3 #include "xbt/xbt_os_thread.h"
5 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_smurf, simix,
6 "Logging specific to SIMIX (SMURF)");
8 XBT_INLINE smx_simcall_t SIMIX_simcall_mine()
10 smx_process_t issuer = SIMIX_process_self();
11 return &issuer->simcall;
15 * \brief Makes the current process do a simcall to the kernel and yields
16 * until completion. If the current thread is maestro, we don't yield and
17 * execute the simcall directly.
18 * \param self the current process
20 void SIMIX_simcall_push(smx_process_t self)
22 if (self != simix_global->maestro_process) {
23 XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name,
24 SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call);
25 SIMIX_process_yield(self);
27 SIMIX_simcall_pre(&self->simcall, 0);
31 void SIMIX_simcall_answer(smx_simcall_t simcall)
33 if (simcall->issuer != simix_global->maestro_process){
34 XBT_DEBUG("Answer simcall %s (%d) issued by %s (%p)", SIMIX_simcall_name(simcall->call), (int)simcall->call,
35 simcall->issuer->name, simcall->issuer);
36 simcall->issuer->simcall.call = SIMCALL_NONE;
37 /* This check should be useless and slows everyone. Reactivate if you see something
38 * weird in process scheduling.
40 /* if(!xbt_dynar_member(simix_global->process_to_run, &(simcall->issuer))) */
41 xbt_dynar_push_as(simix_global->process_to_run, smx_process_t, simcall->issuer);
42 /* else DIE_IMPOSSIBLE; */
46 void SIMIX_simcall_pre(smx_simcall_t simcall, int value)
48 XBT_DEBUG("Handling simcall %p: %s", simcall, SIMIX_simcall_name(simcall->call));
50 switch (simcall->call) {
51 case SIMCALL_COMM_TEST:
52 SIMIX_pre_comm_test(simcall);
55 case SIMCALL_COMM_TESTANY:
56 SIMIX_pre_comm_testany(simcall, value);
59 case SIMCALL_COMM_WAIT:
60 SIMIX_pre_comm_wait(simcall,
61 simcall->comm_wait.comm,
62 simcall->comm_wait.timeout,
66 case SIMCALL_COMM_WAITANY:
67 SIMIX_pre_comm_waitany(simcall, value);
70 case SIMCALL_COMM_SEND:
72 smx_action_t comm = SIMIX_comm_isend(
74 simcall->comm_send.rdv,
75 simcall->comm_send.task_size,
76 simcall->comm_send.rate,
77 simcall->comm_send.src_buff,
78 simcall->comm_send.src_buff_size,
79 simcall->comm_send.match_fun,
80 NULL, /* no clean function since it's not detached */
81 simcall->comm_send.data,
83 SIMIX_pre_comm_wait(simcall, comm, simcall->comm_send.timeout, 0);
87 case SIMCALL_COMM_ISEND:
88 simcall->comm_isend.result = SIMIX_comm_isend(
90 simcall->comm_isend.rdv,
91 simcall->comm_isend.task_size,
92 simcall->comm_isend.rate,
93 simcall->comm_isend.src_buff,
94 simcall->comm_isend.src_buff_size,
95 simcall->comm_isend.match_fun,
96 simcall->comm_isend.clean_fun,
97 simcall->comm_isend.data,
98 simcall->comm_isend.detached);
99 SIMIX_simcall_answer(simcall);
102 case SIMCALL_COMM_RECV:
104 smx_action_t comm = SIMIX_comm_irecv(
106 simcall->comm_recv.rdv,
107 simcall->comm_recv.dst_buff,
108 simcall->comm_recv.dst_buff_size,
109 simcall->comm_recv.match_fun,
110 simcall->comm_recv.data);
111 SIMIX_pre_comm_wait(simcall, comm, simcall->comm_recv.timeout, 0);
115 case SIMCALL_COMM_IRECV:
116 simcall->comm_irecv.result = SIMIX_comm_irecv(
118 simcall->comm_irecv.rdv,
119 simcall->comm_irecv.dst_buff,
120 simcall->comm_irecv.dst_buff_size,
121 simcall->comm_irecv.match_fun,
122 simcall->comm_irecv.data);
123 SIMIX_simcall_answer(simcall);
126 case SIMCALL_COMM_DESTROY:
127 SIMIX_comm_destroy(simcall->comm_destroy.comm);
128 SIMIX_simcall_answer(simcall);
131 case SIMCALL_COMM_CANCEL:
132 SIMIX_comm_cancel(simcall->comm_cancel.comm);
133 SIMIX_simcall_answer(simcall);
136 case SIMCALL_COMM_GET_REMAINS:
137 simcall->comm_get_remains.result =
138 SIMIX_comm_get_remains(simcall->comm_get_remains.comm);
139 SIMIX_simcall_answer(simcall);
142 case SIMCALL_COMM_GET_STATE:
143 simcall->comm_get_state.result =
144 SIMIX_comm_get_state(simcall->comm_get_state.comm);
145 SIMIX_simcall_answer(simcall);
148 case SIMCALL_COMM_GET_SRC_DATA:
149 simcall->comm_get_src_data.result = SIMIX_comm_get_src_data(simcall->comm_get_src_data.comm);
150 SIMIX_simcall_answer(simcall);
153 case SIMCALL_COMM_GET_DST_DATA:
154 simcall->comm_get_dst_data.result = SIMIX_comm_get_dst_data(simcall->comm_get_dst_data.comm);
155 SIMIX_simcall_answer(simcall);
158 case SIMCALL_COMM_GET_SRC_PROC:
159 simcall->comm_get_src_proc.result =
160 SIMIX_comm_get_src_proc(simcall->comm_get_src_proc.comm);
161 SIMIX_simcall_answer(simcall);
164 case SIMCALL_COMM_GET_DST_PROC:
165 simcall->comm_get_dst_proc.result =
166 SIMIX_comm_get_dst_proc(simcall->comm_get_dst_proc.comm);
167 SIMIX_simcall_answer(simcall);
170 #ifdef HAVE_LATENCY_BOUND_TRACKING
171 case SIMCALL_COMM_IS_LATENCY_BOUNDED:
172 simcall->comm_is_latency_bounded.result =
173 SIMIX_comm_is_latency_bounded(simcall->comm_is_latency_bounded.comm);
174 SIMIX_simcall_answer(simcall);
178 case SIMCALL_RDV_CREATE:
179 simcall->rdv_create.result = SIMIX_rdv_create(simcall->rdv_create.name);
180 SIMIX_simcall_answer(simcall);
183 case SIMCALL_RDV_DESTROY:
184 SIMIX_rdv_destroy(simcall->rdv_destroy.rdv);
185 SIMIX_simcall_answer(simcall);
188 case SIMCALL_RDV_GEY_BY_NAME:
189 simcall->rdv_get_by_name.result =
190 SIMIX_rdv_get_by_name(simcall->rdv_get_by_name.name);
191 SIMIX_simcall_answer(simcall);
194 case SIMCALL_RDV_COMM_COUNT_BY_HOST:
195 simcall->rdv_comm_count_by_host.result = SIMIX_rdv_comm_count_by_host(
196 simcall->rdv_comm_count_by_host.rdv,
197 simcall->rdv_comm_count_by_host.host);
198 SIMIX_simcall_answer(simcall);
201 case SIMCALL_RDV_GET_HEAD:
202 simcall->rdv_get_head.result = SIMIX_rdv_get_head(simcall->rdv_get_head.rdv);
203 SIMIX_simcall_answer(simcall);
206 case SIMCALL_RDV_SET_RECV:
207 SIMIX_rdv_set_receiver(simcall->rdv_set_rcv_proc.rdv, simcall->rdv_set_rcv_proc.receiver);
208 SIMIX_simcall_answer(simcall);
211 case SIMCALL_RDV_GET_RECV:
212 simcall->rdv_get_rcv_proc.result = SIMIX_rdv_get_receiver(simcall->rdv_set_rcv_proc.rdv);
213 SIMIX_simcall_answer(simcall);
216 case SIMCALL_HOST_GET_BY_NAME:
217 simcall->host_get_by_name.result =
218 SIMIX_host_get_by_name(simcall->host_get_by_name.name);
219 SIMIX_simcall_answer(simcall);
222 case SIMCALL_HOST_GET_NAME:
223 simcall->host_get_name.result = SIMIX_host_get_name(simcall->host_get_name.host);
224 SIMIX_simcall_answer(simcall);
227 case SIMCALL_HOST_GET_PROPERTIES:
228 simcall->host_get_properties.result =
229 SIMIX_host_get_properties(simcall->host_get_properties.host);
230 SIMIX_simcall_answer(simcall);
233 case SIMCALL_HOST_GET_SPEED:
234 simcall->host_get_speed.result =
235 SIMIX_host_get_speed(simcall->host_get_speed.host);
236 SIMIX_simcall_answer(simcall);
239 case SIMCALL_HOST_GET_AVAILABLE_SPEED:
240 simcall->host_get_available_speed.result =
241 SIMIX_host_get_available_speed(simcall->host_get_available_speed.host);
242 SIMIX_simcall_answer(simcall);
245 case SIMCALL_HOST_GET_STATE:
246 simcall->host_get_state.result =
247 SIMIX_host_get_state(simcall->host_get_state.host);
248 SIMIX_simcall_answer(simcall);
251 case SIMCALL_HOST_GET_DATA:
252 simcall->host_get_data.result = SIMIX_host_get_data(simcall->host_get_data.host);
253 SIMIX_simcall_answer(simcall);
256 case SIMCALL_HOST_SET_DATA:
257 SIMIX_host_set_data(simcall->host_set_data.host, simcall->host_set_data.data);
258 SIMIX_simcall_answer(simcall);
261 case SIMCALL_HOST_EXECUTE:
262 simcall->host_execute.result = SIMIX_host_execute(
263 simcall->host_execute.name,
264 simcall->host_execute.host,
265 simcall->host_execute.computation_amount,
266 simcall->host_execute.priority);
267 SIMIX_simcall_answer(simcall);
270 case SIMCALL_HOST_PARALLEL_EXECUTE:
271 simcall->host_parallel_execute.result = SIMIX_host_parallel_execute(
272 simcall->host_parallel_execute.name,
273 simcall->host_parallel_execute.host_nb,
274 simcall->host_parallel_execute.host_list,
275 simcall->host_parallel_execute.computation_amount,
276 simcall->host_parallel_execute.communication_amount,
277 simcall->host_parallel_execute.amount,
278 simcall->host_parallel_execute.rate);
279 SIMIX_simcall_answer(simcall);
282 case SIMCALL_HOST_EXECUTION_DESTROY:
283 SIMIX_host_execution_destroy(simcall->host_execution_destroy.execution);
284 SIMIX_simcall_answer(simcall);
287 case SIMCALL_HOST_EXECUTION_CANCEL:
288 SIMIX_host_execution_cancel(simcall->host_execution_cancel.execution);
289 SIMIX_simcall_answer(simcall);
292 case SIMCALL_HOST_EXECUTION_GET_REMAINS:
293 simcall->host_execution_get_remains.result =
294 SIMIX_host_execution_get_remains(simcall->host_execution_get_remains.execution);
295 SIMIX_simcall_answer(simcall);
298 case SIMCALL_HOST_EXECUTION_GET_STATE:
299 simcall->host_execution_get_state.result =
300 SIMIX_host_execution_get_state(simcall->host_execution_get_state.execution);
301 SIMIX_simcall_answer(simcall);
304 case SIMCALL_HOST_EXECUTION_SET_PRIORITY:
305 SIMIX_host_execution_set_priority(
306 simcall->host_execution_set_priority.execution,
307 simcall->host_execution_set_priority.priority);
308 SIMIX_simcall_answer(simcall);
311 case SIMCALL_HOST_EXECUTION_WAIT:
312 SIMIX_pre_host_execution_wait(simcall);
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);
540 THROWF(arg_error,0,"Asked to do the noop syscall on %s@%s",
541 SIMIX_process_get_name(simcall->issuer),
542 SIMIX_host_get_name(SIMIX_process_get_host(simcall->issuer))
548 void SIMIX_simcall_post(smx_action_t action)
550 switch (action->type) {
552 case SIMIX_ACTION_EXECUTE:
553 case SIMIX_ACTION_PARALLEL_EXECUTE:
554 SIMIX_post_host_execute(action);
557 case SIMIX_ACTION_COMMUNICATE:
558 SIMIX_post_comm(action);
561 case SIMIX_ACTION_SLEEP:
562 SIMIX_post_process_sleep(action);
565 case SIMIX_ACTION_SYNCHRO:
566 SIMIX_post_synchro(action);
569 case SIMIX_ACTION_IO:
570 SIMIX_post_io(action);