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));
51 simcall->mc_value = value;
52 if (simcall->issuer->context->iwannadie && simcall->call != SIMCALL_PROCESS_CLEANUP)
54 switch (simcall->call) {
55 SIMCALL_LIST(SIMCALL_CASE, SIMCALL_SEP_NOTHING)
59 THROWF(arg_error,0,"Asked to do the noop syscall on %s@%s",
60 SIMIX_process_get_name(simcall->issuer),
61 SIMIX_host_get_name(SIMIX_process_get_host(simcall->issuer))
65 /* ****************************************************************************************** */
66 /* TUTORIAL: New API */
67 /* ****************************************************************************************** */
68 case SIMCALL_NEW_API_INIT:
69 SIMIX_pre_new_api_fct(simcall);
74 void SIMIX_simcall_post(smx_action_t action)
76 switch (action->type) {
78 case SIMIX_ACTION_EXECUTE:
79 case SIMIX_ACTION_PARALLEL_EXECUTE:
80 SIMIX_post_host_execute(action);
83 case SIMIX_ACTION_COMMUNICATE:
84 SIMIX_post_comm(action);
87 case SIMIX_ACTION_SLEEP:
88 SIMIX_post_process_sleep(action);
91 case SIMIX_ACTION_SYNCHRO:
92 SIMIX_post_synchro(action);
96 SIMIX_post_io(action);
99 /* ****************************************************************************************** */
100 /* TUTORIAL: New API */
101 /* ****************************************************************************************** */
102 case SIMIX_ACTION_NEW_API:
103 SIMIX_post_new_api(action);
108 /* New Simcal interface */
110 /* FIXME: add types for every simcall */
111 //const char *simcall_types[NUM_SIMCALLS] = { [SIMCALL_HOST_EXECUTE] = "%s%p%f%f%p" };
112 /* FIXME find a way to make this work
113 simcall_handler_t simcall_table[NUM_SIMCALLS] = {
114 #undef SIMCALL_ENUM_ELEMENT
115 #define SIMCALL_ENUM_ELEMENT(x,y) &y // generate strings from the enumeration values
117 #undef SIMCALL_ENUM_ELEMENT
120 /* New Simcal interface */
122 /* FIXME: add types for every simcall */
123 //const char *simcall_types[NUM_SIMCALLS] = { [SIMCALL_HOST_EXECUTE] = "%s%p%f%f%p", [SIMCALL_HOST_EXECUTION_WAIT] = "%p%p" };
126 /*TOFIX find a way to make this work
127 simcall_handler_t simcall_table[NUM_SIMCALLS] = {
128 #undef SIMCALL_ENUM_ELEMENT
129 #define SIMCALL_ENUM_ELEMENT(x,y) &y // generate strings from the enumeration values
131 #undef SIMCALL_ENUM_ELEMENT