Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix debug message in simix
[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   switch (simcall->call) {
53 SIMCALL_LIST(SIMCALL_CASE, SIMCALL_SEP_NOTHING)
54     case NUM_SIMCALLS:;
55       break;
56     case SIMCALL_NONE:;
57       THROWF(arg_error,0,"Asked to do the noop syscall on %s@%s",
58           SIMIX_process_get_name(simcall->issuer),
59           SIMIX_host_get_name(SIMIX_process_get_host(simcall->issuer))
60           );
61       break;
62
63     /* ****************************************************************************************** */
64     /* TUTORIAL: New API                                                                        */
65     /* ****************************************************************************************** */
66     case SIMCALL_NEW_API_INIT:
67       SIMIX_pre_new_api_fct(simcall);
68       break;
69   }
70 }
71
72 void SIMIX_simcall_post(smx_action_t action)
73 {
74   switch (action->type) {
75
76     case SIMIX_ACTION_EXECUTE:
77     case SIMIX_ACTION_PARALLEL_EXECUTE:
78       SIMIX_post_host_execute(action);
79       break;
80
81     case SIMIX_ACTION_COMMUNICATE:
82       SIMIX_post_comm(action);
83       break;
84
85     case SIMIX_ACTION_SLEEP:
86       SIMIX_post_process_sleep(action);
87       break;
88
89     case SIMIX_ACTION_SYNCHRO:
90       SIMIX_post_synchro(action);
91       break;
92
93     case SIMIX_ACTION_IO:
94       SIMIX_post_io(action);
95       break;
96
97     /* ****************************************************************************************** */
98     /* TUTORIAL: New API                                                                        */
99     /* ****************************************************************************************** */
100     case SIMIX_ACTION_NEW_API:
101       SIMIX_post_new_api(action);
102       break;
103   }
104 }
105
106 /* New Simcal interface */
107
108 /* FIXME: add types for every simcall */
109 //const char *simcall_types[NUM_SIMCALLS] = { [SIMCALL_HOST_EXECUTE] = "%s%p%f%f%p" };
110 /* FIXME find a way to make this work
111 simcall_handler_t simcall_table[NUM_SIMCALLS] = {
112 #undef SIMCALL_ENUM_ELEMENT
113 #define SIMCALL_ENUM_ELEMENT(x,y) &y // generate strings from the enumeration values 
114 SIMCALL_LIST
115 #undef SIMCALL_ENUM_ELEMENT
116 };*/
117
118 /* New Simcal interface */
119
120 /* FIXME: add types for every simcall */
121 //const char *simcall_types[NUM_SIMCALLS] = { [SIMCALL_HOST_EXECUTE] = "%s%p%f%f%p", [SIMCALL_HOST_EXECUTION_WAIT] = "%p%p" };
122
123
124 /*TOFIX find a way to make this work
125 simcall_handler_t simcall_table[NUM_SIMCALLS] = {
126 #undef SIMCALL_ENUM_ELEMENT
127 #define SIMCALL_ENUM_ELEMENT(x,y) &y // generate strings from the enumeration values
128 SIMCALL_LIST
129 #undef SIMCALL_ENUM_ELEMENT
130 };*/
131
132 smx_simcall_t __SIMIX_simcall(e_smx_simcall_t simcall_id, u_smx_scalar_t *args)
133 {
134   smx_process_t self = SIMIX_process_self();
135   self->simcall.call = simcall_id;
136   self->simcall.args = args;
137
138   if (self != simix_global->maestro_process) {
139     XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name,
140               SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call);
141
142     SIMIX_process_yield(self);
143   } else {
144
145     SIMIX_simcall_pre(&self->simcall, 0);
146   }
147   return &(self->simcall);
148 }