1 #include "smx_private.h"
3 #include "xbt/xbt_os_thread.h"
5 #include "mc/mc_private.h"
8 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_smurf, simix,
9 "Logging specific to SIMIX (SMURF)");
11 XBT_INLINE smx_simcall_t SIMIX_simcall_mine()
13 smx_process_t issuer = SIMIX_process_self();
14 return &issuer->simcall;
18 * \brief Makes the current process do a simcall to the kernel and yields
19 * until completion. If the current thread is maestro, we don't yield and
20 * execute the simcall directly.
21 * \param self the current process
23 void SIMIX_simcall_push(smx_process_t self)
25 if (self != simix_global->maestro_process) {
26 XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name,
27 SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call);
28 SIMIX_process_yield(self);
30 XBT_DEBUG("I'm the maestro, execute the simcall directly");
31 SIMIX_simcall_pre(&self->simcall, 0);
35 void SIMIX_simcall_answer(smx_simcall_t simcall)
37 if (simcall->issuer != simix_global->maestro_process){
38 XBT_DEBUG("Answer simcall %s (%d) issued by %s (%p)", SIMIX_simcall_name(simcall->call), (int)simcall->call,
39 simcall->issuer->name, simcall->issuer);
40 simcall->issuer->simcall.call = SIMCALL_NONE;
41 /* This check should be useless and slows everyone. Reactivate if you see something
42 * weird in process scheduling.
44 /* if(!xbt_dynar_member(simix_global->process_to_run, &(simcall->issuer))) */
45 xbt_dynar_push_as(simix_global->process_to_run, smx_process_t, simcall->issuer);
46 /* else DIE_IMPOSSIBLE; */
50 void SIMIX_simcall_pre(smx_simcall_t simcall, int value)
52 XBT_DEBUG("Handling simcall %p: %s", simcall, SIMIX_simcall_name(simcall->call));
53 simcall->mc_value = value;
54 if (simcall->issuer->context->iwannadie && simcall->call != SIMCALL_PROCESS_CLEANUP)
56 switch (simcall->call) {
57 SIMCALL_LIST(SIMCALL_CASE, SIMCALL_SEP_NOTHING)
61 THROWF(arg_error,0,"Asked to do the noop syscall on %s@%s",
62 SIMIX_process_get_name(simcall->issuer),
63 SIMIX_host_get_name(SIMIX_process_get_host(simcall->issuer))
67 /* ****************************************************************************************** */
68 /* TUTORIAL: New API */
69 /* ****************************************************************************************** */
70 case SIMCALL_NEW_API_INIT:
71 SIMIX_pre_new_api_fct(simcall);
76 void SIMIX_simcall_post(smx_action_t action)
78 switch (action->type) {
80 case SIMIX_ACTION_EXECUTE:
81 case SIMIX_ACTION_PARALLEL_EXECUTE:
82 SIMIX_post_host_execute(action);
85 case SIMIX_ACTION_COMMUNICATE:
86 SIMIX_post_comm(action);
89 case SIMIX_ACTION_SLEEP:
90 SIMIX_post_process_sleep(action);
93 case SIMIX_ACTION_SYNCHRO:
94 SIMIX_post_synchro(action);
98 SIMIX_post_io(action);
101 /* ****************************************************************************************** */
102 /* TUTORIAL: New API */
103 /* ****************************************************************************************** */
104 case SIMIX_ACTION_NEW_API:
105 SIMIX_post_new_api(action);
110 /* New Simcal interface */
112 /* FIXME: add types for every simcall */
113 //const char *simcall_types[NUM_SIMCALLS] = { [SIMCALL_HOST_EXECUTE] = "%s%p%f%f%p" };
114 /* FIXME find a way to make this work
115 simcall_handler_t simcall_table[NUM_SIMCALLS] = {
116 #undef SIMCALL_ENUM_ELEMENT
117 #define SIMCALL_ENUM_ELEMENT(x,y) &y // generate strings from the enumeration values
119 #undef SIMCALL_ENUM_ELEMENT
122 /* New Simcal interface */
124 /* FIXME: add types for every simcall */
125 //const char *simcall_types[NUM_SIMCALLS] = { [SIMCALL_HOST_EXECUTE] = "%s%p%f%f%p", [SIMCALL_HOST_EXECUTION_WAIT] = "%p%p" };
128 /*TOFIX find a way to make this work
129 simcall_handler_t simcall_table[NUM_SIMCALLS] = {
130 #undef SIMCALL_ENUM_ELEMENT
131 #define SIMCALL_ENUM_ELEMENT(x,y) &y // generate strings from the enumeration values
133 #undef SIMCALL_ENUM_ELEMENT