Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add MSG_process_join [#13601]
[simgrid.git] / src / simix / smx_smurf.c
1 /* Copyright (c) 2010-2014. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #include "smx_private.h"
8 #include "xbt/fifo.h"
9 #include "xbt/xbt_os_thread.h"
10 #ifdef HAVE_MC
11 #include "mc/mc_private.h"
12 #endif
13
14 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_smurf, simix,
15                                 "Logging specific to SIMIX (SMURF)");
16
17 XBT_INLINE smx_simcall_t SIMIX_simcall_mine()
18 {
19   smx_process_t issuer = SIMIX_process_self();
20   return &issuer->simcall;
21 }
22
23 /**
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
28  */
29 void SIMIX_simcall_push(smx_process_t self)
30 {
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);
35   } else {
36     XBT_DEBUG("I'm the maestro, execute the simcall directly");
37     SIMIX_simcall_pre(&self->simcall, 0);
38   }
39 }
40
41 void SIMIX_simcall_answer(smx_simcall_t simcall)
42 {
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.
49  */
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; */
53   }
54 }
55
56 void SIMIX_simcall_pre(smx_simcall_t simcall, int value)
57 {
58   XBT_DEBUG("Handling simcall %p: %s", simcall, SIMIX_simcall_name(simcall->call));
59   SIMCALL_SET_MC_VALUE(simcall, value);
60   if (simcall->issuer->context->iwannadie && simcall->call != SIMCALL_PROCESS_CLEANUP)
61     return;
62   switch (simcall->call) {
63 #include "simcalls_generated_case.c"
64     case NUM_SIMCALLS:
65       break;
66     case SIMCALL_NONE:
67       THROWF(arg_error,0,"Asked to do the noop syscall on %s@%s",
68           SIMIX_process_get_name(simcall->issuer),
69           SIMIX_host_get_name(SIMIX_process_get_host(simcall->issuer))
70           );
71       break;
72
73     /* ****************************************************************************************** */
74     /* TUTORIAL: New API                                                                        */
75     /* ****************************************************************************************** */
76     case SIMCALL_NEW_API_INIT:
77       SIMIX_pre_new_api_fct(simcall);
78       break;
79   }
80 }
81
82 void SIMIX_simcall_post(smx_action_t action)
83 {
84   switch (action->type) {
85
86     case SIMIX_ACTION_EXECUTE:
87     case SIMIX_ACTION_PARALLEL_EXECUTE:
88       SIMIX_post_host_execute(action);
89       break;
90
91     case SIMIX_ACTION_COMMUNICATE:
92       SIMIX_post_comm(action);
93       break;
94
95     case SIMIX_ACTION_SLEEP:
96       SIMIX_post_process_sleep(action);
97       break;
98
99     case SIMIX_ACTION_JOIN:
100       SIMIX_post_process_sleep(action);
101       break;
102
103     case SIMIX_ACTION_SYNCHRO:
104       SIMIX_post_synchro(action);
105       break;
106
107     case SIMIX_ACTION_IO:
108       SIMIX_post_io(action);
109       break;
110
111     /* ****************************************************************************************** */
112     /* TUTORIAL: New API                                                                        */
113     /* ****************************************************************************************** */
114     case SIMIX_ACTION_NEW_API:
115       SIMIX_post_new_api(action);
116       break;
117   }
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" };
124 /* FIXME 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 /* New Simcal interface */
133
134 /* FIXME: add types for every simcall */
135 //const char *simcall_types[NUM_SIMCALLS] = { [SIMCALL_HOST_EXECUTE] = "%s%p%f%f%p", [SIMCALL_HOST_EXECUTION_WAIT] = "%p%p" };
136
137
138 /*TOFIX find a way to make this work
139 simcall_handler_t simcall_table[NUM_SIMCALLS] = {
140 #undef SIMCALL_ENUM_ELEMENT
141 #define SIMCALL_ENUM_ELEMENT(x,y) &y // generate strings from the enumeration values
142 SIMCALL_LIST
143 #undef SIMCALL_ENUM_ELEMENT
144 };*/
145