1 /* Copyright (c) 2010-2014. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "smx_private.h"
9 #include "xbt/xbt_os_thread.h"
11 #include "mc/mc_private.h"
14 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_smurf, simix,
15 "Logging specific to SIMIX (SMURF)");
17 XBT_INLINE smx_simcall_t SIMIX_simcall_mine()
19 smx_process_t issuer = SIMIX_process_self();
20 return &issuer->simcall;
24 * \brief Makes the current process do a simcall to the kernel and yields
25 * until completion. If the current thread is maestro, we don't yield and
26 * execute the simcall directly.
27 * \param self the current process
29 void SIMIX_simcall_push(smx_process_t self)
31 if (self != simix_global->maestro_process) {
32 XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name,
33 SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call);
34 SIMIX_process_yield(self);
36 XBT_DEBUG("I'm the maestro, execute the simcall directly");
37 SIMIX_simcall_enter(&self->simcall, 0);
41 void SIMIX_simcall_answer(smx_simcall_t simcall)
43 if (simcall->issuer != simix_global->maestro_process){
44 XBT_DEBUG("Answer simcall %s (%d) issued by %s (%p)", SIMIX_simcall_name(simcall->call), (int)simcall->call,
45 simcall->issuer->name, simcall->issuer);
46 simcall->issuer->simcall.call = SIMCALL_NONE;
47 /* This check should be useless and slows everyone. Reactivate if you see something
48 * weird in process scheduling.
50 /* if(!xbt_dynar_member(simix_global->process_to_run, &(simcall->issuer))) */
51 xbt_dynar_push_as(simix_global->process_to_run, smx_process_t, simcall->issuer);
52 /* else DIE_IMPOSSIBLE; */
56 void SIMIX_simcall_exit(smx_action_t action)
58 switch (action->type) {
60 case SIMIX_ACTION_EXECUTE:
61 case SIMIX_ACTION_PARALLEL_EXECUTE:
62 SIMIX_post_host_execute(action);
65 case SIMIX_ACTION_COMMUNICATE:
66 SIMIX_post_comm(action);
69 case SIMIX_ACTION_SLEEP:
70 SIMIX_post_process_sleep(action);
73 case SIMIX_ACTION_JOIN:
74 SIMIX_post_process_sleep(action);
77 case SIMIX_ACTION_SYNCHRO:
78 SIMIX_post_synchro(action);
82 SIMIX_post_io(action);
85 /* ****************************************************************************************** */
86 /* TUTORIAL: New API */
87 /* ****************************************************************************************** */
88 case SIMIX_ACTION_NEW_API:
89 SIMIX_post_new_api(action);
94 /* New Simcal interface */
96 /* FIXME: add types for every simcall */
97 //const char *simcall_types[NUM_SIMCALLS] = { [SIMCALL_HOST_EXECUTE] = "%s%p%f%f%p" };
98 /* FIXME find a way to make this work
99 simcall_handler_t simcall_table[NUM_SIMCALLS] = {
100 #undef SIMCALL_ENUM_ELEMENT
101 #define SIMCALL_ENUM_ELEMENT(x,y) &y // generate strings from the enumeration values
103 #undef SIMCALL_ENUM_ELEMENT
106 /* New Simcal interface */
108 /* FIXME: add types for every simcall */
109 //const char *simcall_types[NUM_SIMCALLS] = { [SIMCALL_HOST_EXECUTE] = "%s%p%f%f%p", [SIMCALL_HOST_EXECUTION_WAIT] = "%p%p" };
112 /*TOFIX 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