Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'hypervisor' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid into hypervisor
[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 #include "../mc/mc_private.h"
5
6 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_smurf, simix,
7                                 "Logging specific to SIMIX (SMURF)");
8
9 XBT_INLINE smx_simcall_t SIMIX_simcall_mine()
10 {
11   smx_process_t issuer = SIMIX_process_self();
12   return &issuer->simcall;
13 }
14
15 /**
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
20  */
21 void SIMIX_simcall_push(smx_process_t self)
22 {
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);
27   } else {
28     XBT_DEBUG("I'm the maestro, execute the simcall directly");
29     SIMIX_simcall_pre(&self->simcall, 0);
30   }
31 }
32
33 void SIMIX_simcall_answer(smx_simcall_t simcall)
34 {
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.
41  */
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; */
45   }
46 }
47
48 void SIMIX_simcall_pre(smx_simcall_t simcall, int value)
49 {
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)
53     return;
54   switch (simcall->call) {
55 SIMCALL_LIST(SIMCALL_CASE, SIMCALL_SEP_NOTHING)
56     case NUM_SIMCALLS:;
57       break;
58     case SIMCALL_NONE:;
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))
62           );
63       break;
64
65     /* ****************************************************************************************** */
66     /* TUTORIAL: New API                                                                        */
67     /* ****************************************************************************************** */
68     case SIMCALL_NEW_API_INIT:
69       SIMIX_pre_new_api_fct(simcall);
70       break;
71   }
72 }
73
74 void SIMIX_simcall_post(smx_action_t action)
75 {
76   switch (action->type) {
77
78     case SIMIX_ACTION_EXECUTE:
79     case SIMIX_ACTION_PARALLEL_EXECUTE:
80       SIMIX_post_host_execute(action);
81       break;
82
83     case SIMIX_ACTION_COMMUNICATE:
84       SIMIX_post_comm(action);
85       break;
86
87     case SIMIX_ACTION_SLEEP:
88       SIMIX_post_process_sleep(action);
89       break;
90
91     case SIMIX_ACTION_SYNCHRO:
92       SIMIX_post_synchro(action);
93       break;
94
95     case SIMIX_ACTION_IO:
96       SIMIX_post_io(action);
97       break;
98
99     /* ****************************************************************************************** */
100     /* TUTORIAL: New API                                                                        */
101     /* ****************************************************************************************** */
102     case SIMIX_ACTION_NEW_API:
103       SIMIX_post_new_api(action);
104       break;
105   }
106 }
107
108 /* New Simcal interface */
109
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 
116 SIMCALL_LIST
117 #undef SIMCALL_ENUM_ELEMENT
118 };*/
119
120 /* New Simcal interface */
121
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" };
124
125
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
130 SIMCALL_LIST
131 #undef SIMCALL_ENUM_ELEMENT
132 };*/
133