Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git] / src / simix / smx_smurf.c
1 #include "smx_private.h"
2 #include "xbt/fifo.h"
3 #include "xbt/xbt_os_thread.h"
4 #ifdef HAVE_MC
5 #include "mc/mc_private.h"
6 #endif
7
8 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_smurf, simix,
9                                 "Logging specific to SIMIX (SMURF)");
10
11 XBT_INLINE smx_simcall_t SIMIX_simcall_mine()
12 {
13   smx_process_t issuer = SIMIX_process_self();
14   return &issuer->simcall;
15 }
16
17 /**
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
22  */
23 void SIMIX_simcall_push(smx_process_t self)
24 {
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);
29   } else {
30     XBT_DEBUG("I'm the maestro, execute the simcall directly");
31     SIMIX_simcall_pre(&self->simcall, 0);
32   }
33 }
34
35 void SIMIX_simcall_answer(smx_simcall_t simcall)
36 {
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.
43  */
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; */
47   }
48 }
49
50 void SIMIX_simcall_pre(smx_simcall_t simcall, int value)
51 {
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)
55     return;
56   switch (simcall->call) {
57 SIMCALL_LIST(SIMCALL_CASE, SIMCALL_SEP_NOTHING)
58     case NUM_SIMCALLS:;
59       break;
60     case SIMCALL_NONE:;
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))
64           );
65       break;
66
67     /* ****************************************************************************************** */
68     /* TUTORIAL: New API                                                                        */
69     /* ****************************************************************************************** */
70     case SIMCALL_NEW_API_INIT:
71       SIMIX_pre_new_api_fct(simcall);
72       break;
73   }
74 }
75
76 void SIMIX_simcall_post(smx_action_t action)
77 {
78   switch (action->type) {
79
80     case SIMIX_ACTION_EXECUTE:
81     case SIMIX_ACTION_PARALLEL_EXECUTE:
82       SIMIX_post_host_execute(action);
83       break;
84
85     case SIMIX_ACTION_COMMUNICATE:
86       SIMIX_post_comm(action);
87       break;
88
89     case SIMIX_ACTION_SLEEP:
90       SIMIX_post_process_sleep(action);
91       break;
92
93     case SIMIX_ACTION_SYNCHRO:
94       SIMIX_post_synchro(action);
95       break;
96
97     case SIMIX_ACTION_IO:
98       SIMIX_post_io(action);
99       break;
100
101     /* ****************************************************************************************** */
102     /* TUTORIAL: New API                                                                        */
103     /* ****************************************************************************************** */
104     case SIMIX_ACTION_NEW_API:
105       SIMIX_post_new_api(action);
106       break;
107   }
108 }
109
110 /* New Simcal interface */
111
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 
118 SIMCALL_LIST
119 #undef SIMCALL_ENUM_ELEMENT
120 };*/
121
122 /* New Simcal interface */
123
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" };
126
127
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
132 SIMCALL_LIST
133 #undef SIMCALL_ENUM_ELEMENT
134 };*/
135