XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
"Messages specific for this msg example");
+#define SLEEP(duration) \
+ if (MSG_process_sleep(duration) != MSG_OK) \
+ xbt_die("What's going on??? I failed to sleep!"); \
+ else \
+ (void)0
+
/** @addtogroup MSG_examples
*
* - <b>suspend/suspend.c</b>: Demonstrates how to suspend and resume processes using @ref MSG_process_suspend and @ref MSG_process_resume.
XBT_INFO("Nobody's watching me ? Let's go to sleep.");
MSG_process_suspend(MSG_process_self());
XBT_INFO("Uuuh ? Did somebody call me ?");
+
+ XBT_INFO("Going to sleep...");
+ SLEEP(10.0);
+ XBT_INFO("Mmm... waking up.");
+
+ XBT_INFO("Going to sleep one more time...");
+ SLEEP(10.0);
+ XBT_INFO("Waking up once for all!");
+
XBT_INFO("Mmmh, goodbye now.");
return 0;
} /* end_of_lazy_guy */
XBT_INFO("Let's create a lazy guy.");
lazy = MSG_process_create("Lazy", lazy_guy, NULL, MSG_host_self());
XBT_INFO("Let's wait a little bit...");
- MSG_process_sleep(10.0);
+ SLEEP(10.0);
XBT_INFO("Let's wake the lazy guy up! >:) BOOOOOUUUHHH!!!!");
MSG_process_resume(lazy);
+
+ SLEEP(5.0);
+ XBT_INFO("Suspend the lazy guy while he's sleeping...");
+ MSG_process_suspend(lazy);
+ XBT_INFO("Let him finish his siesta.");
+ SLEEP(10.0);
+ XBT_INFO("Wake up, lazy guy!");
+ MSG_process_resume(lazy);
+
+ SLEEP(5.0);
+ XBT_INFO("Suspend again the lazy guy while he's sleeping...");
+ MSG_process_suspend(lazy);
+ XBT_INFO("This time, don't let him finish his siesta.");
+ SLEEP(2.0);
+ XBT_INFO("Wake up, lazy guy!");
+ MSG_process_resume(lazy);
+
XBT_INFO("OK, goodbye now.");
return 0;
} /* end_of_dram_master */
> [ 0.000000] (1:dream_master@Jacquelin) Let's create a lazy guy.
> [ 0.000000] (1:dream_master@Jacquelin) Let's wait a little bit...
> [ 0.000000] (2:Lazy@Jacquelin) Nobody's watching me ? Let's go to sleep.
-> [ 10.000000] (0:@) Simulation time 10
> [ 10.000000] (1:dream_master@Jacquelin) Let's wake the lazy guy up! >:) BOOOOOUUUHHH!!!!
-> [ 10.000000] (1:dream_master@Jacquelin) OK, goodbye now.
> [ 10.000000] (2:Lazy@Jacquelin) Uuuh ? Did somebody call me ?
-> [ 10.000000] (2:Lazy@Jacquelin) Mmmh, goodbye now.
+> [ 10.000000] (2:Lazy@Jacquelin) Going to sleep...
+> [ 15.000000] (1:dream_master@Jacquelin) Suspend the lazy guy while he's sleeping...
+> [ 15.000000] (1:dream_master@Jacquelin) Let him finish his siesta.
+> [ 25.000000] (1:dream_master@Jacquelin) Wake up, lazy guy!
+> [ 25.000000] (2:Lazy@Jacquelin) Mmm... waking up.
+> [ 25.000000] (2:Lazy@Jacquelin) Going to sleep one more time...
+> [ 30.000000] (1:dream_master@Jacquelin) Suspend again the lazy guy while he's sleeping...
+> [ 30.000000] (1:dream_master@Jacquelin) This time, don't let him finish his siesta.
+> [ 32.000000] (1:dream_master@Jacquelin) Wake up, lazy guy!
+> [ 32.000000] (1:dream_master@Jacquelin) OK, goodbye now.
+> [ 35.000000] (0:@) Simulation time 35
+> [ 35.000000] (2:Lazy@Jacquelin) Waking up once for all!
+> [ 35.000000] (2:Lazy@Jacquelin) Mmmh, goodbye now.
/* argc */ int,
/* argv */ char**,
/* props */ xbt_dict_t,
- /* auto_restart */ int);
+ /* auto_restart */ int,
+ /* parent_process */ smx_process_t);
/******************************* Networking ***********************************/
void MSG_process_cleanup_from_SIMIX(smx_process_t smx_proc);
void MSG_process_create_from_SIMIX(smx_process_t *process, const char *name,
xbt_main_func_t code, void *data,
- const char *hostname, double kill_time, int argc,
- char **argv, xbt_dict_t properties, int auto_restart);
+ const char *hostname, double kill_time,
+ int argc, char **argv,
+ xbt_dict_t properties, int auto_restart,
+ smx_process_t parent_process);
void MSG_comm_copy_data_from_SIMIX(smx_action_t comm, void* buff, size_t buff_size);
void _MSG_action_init(void);
/* This function creates a MSG process. It has the prototype enforced by SIMIX_function_register_process_create */
void MSG_process_create_from_SIMIX(smx_process_t* process, const char *name,
- xbt_main_func_t code, void *data,
- const char *hostname, double kill_time, int argc, char **argv,
- xbt_dict_t properties, int auto_restart)
+ xbt_main_func_t code, void *data,
+ const char *hostname, double kill_time,
+ int argc, char **argv,
+ xbt_dict_t properties, int auto_restart,
+ smx_process_t parent_process)
{
msg_host_t host = MSG_get_host_by_name(hostname);
msg_process_t p = MSG_process_create_with_environment(name, code, data,
process->argc,
(char**)(process->argv),
current_property_set,
- auto_restart);
+ auto_restart, NULL);
else
simcall_process_create(&process_created, (char*)(process->argv)[0], parse_code, NULL, sg_host_name(host), kill_time, process->argc,
(char**)process->argv, current_property_set,auto_restart);
xbt_assert((host != NULL), "Invalid parameters");
if (surf_resource_get_state(surf_workstation_resource_priv(h))==SURF_RESOURCE_OFF) {
- surf_resource_set_state(surf_workstation_resource_priv(h), SURF_RESOURCE_ON);
+ surf_resource_set_state(surf_workstation_resource_priv(h), SURF_RESOURCE_ON);
unsigned int cpt;
smx_process_arg_t arg;
xbt_dynar_foreach(host->boot_processes,cpt,arg) {
arg->argc,
arg->argv,
arg->properties,
- arg->auto_restart);
- }
- else {
+ arg->auto_restart,
+ NULL);
+ } else {
simcall_process_create(&process,
- arg->argv[0],
- arg->code,
- NULL,
- arg->hostname,
- arg->kill_time,
- arg->argc,
- arg->argv,
- arg->properties,
- arg->auto_restart);
+ arg->argv[0],
+ arg->code,
+ NULL,
+ arg->hostname,
+ arg->kill_time,
+ arg->argc,
+ arg->argv,
+ arg->properties,
+ arg->auto_restart);
}
}
}
arg->argc,
arg->argv,
arg->properties,
- arg->auto_restart);
+ arg->auto_restart,
+ NULL);
} else {
simcall_process_create(&process,
arg->argv[0],
}
}
- XBT_DEBUG("Create execute action %p", action);
+ XBT_DEBUG("Create execute action %p: %s", action, action->name);
return action;
}
smx_action_t comm = SIMIX_comm_isend(simcall->issuer, rdv, task_size, rate,
src_buff, src_buff_size, match_fun, NULL,
data, 0);
- simcall->mc_value = 0;
+ SIMCALL_SET_MC_VALUE(simcall, 0);
SIMIX_pre_comm_wait(simcall, comm, timeout);
}
smx_action_t SIMIX_pre_comm_isend(smx_simcall_t simcall, smx_rdv_t rdv,
{
smx_action_t comm = SIMIX_comm_irecv(simcall->issuer, rdv, dst_buff,
dst_buff_size, match_fun, data, rate);
- simcall->mc_value = 0;
+ SIMCALL_SET_MC_VALUE(simcall, 0);
SIMIX_pre_comm_wait(simcall, comm, timeout);
}
simcall->issuer->waiting_action = action;
if (MC_is_active()) {
- int idx = simcall->mc_value;
+ int idx = SIMCALL_GET_MC_VALUE(simcall);
if (idx == 0) {
action->state = SIMIX_DONE;
} else {
simcall_comm_testany__set__result(simcall, -1);
if (MC_is_active()){
- int idx = simcall->mc_value;
+ int idx = SIMCALL_GET_MC_VALUE(simcall);
if(idx == -1){
SIMIX_simcall_answer(simcall);
}else{
unsigned int cursor = 0;
if (MC_is_active()){
- int idx = simcall->mc_value;
+ int idx = SIMCALL_GET_MC_VALUE(simcall);
action = xbt_dynar_get_as(actions, idx, smx_action_t);
xbt_fifo_push(action->simcalls, simcall);
simcall_comm_waitany__set__result(simcall, idx);
/* Create maestro process and intilialize it */
maestro = xbt_new0(s_smx_process_t, 1);
maestro->pid = simix_process_maxpid++;
+ maestro->ppid = -1;
maestro->name = (char *) "";
maestro->running_ctx = xbt_new(xbt_running_ctx_t, 1);
XBT_RUNNING_CTX_INITIALIZE(maestro->running_ctx);
maestro->context = SIMIX_context_new(NULL, 0, NULL, NULL, maestro);
maestro->simcall.issuer = maestro;
-
- if (SIMIX_process_self()) {
- maestro->ppid = SIMIX_process_get_PID(SIMIX_process_self());
- } else {
- maestro->ppid = -1;
- }
-
simix_global->maestro_process = maestro;
return;
}
smx_process_t SIMIX_process_create_from_wrapper(smx_process_arg_t args) {
smx_process_t process;
- simix_global->create_process_function(
- &process,
- args->name,
- args->code,
- args->data,
- args->hostname,
- args->kill_time,
- args->argc,
- args->argv,
- args->properties,
- args->auto_restart);
+ simix_global->create_process_function(&process,
+ args->name,
+ args->code,
+ args->data,
+ args->hostname,
+ args->kill_time,
+ args->argc,
+ args->argv,
+ args->properties,
+ args->auto_restart,
+ NULL);
xbt_free(args);
return process;
}
int argc, char **argv,
xbt_dict_t properties,
int auto_restart){
- SIMIX_process_create_with_parent(process, name, code, data, hostname,
- kill_time, argc, argv, properties, auto_restart,
- simcall->issuer);
+ SIMIX_process_create(process, name, code, data, hostname,
+ kill_time, argc, argv, properties, auto_restart,
+ simcall->issuer);
}
/**
* \brief Internal function to create a process.
double kill_time,
int argc, char **argv,
xbt_dict_t properties,
- int auto_restart) {
- SIMIX_process_create_with_parent(process, name, code, data, hostname,
- kill_time, argc, argv, properties, auto_restart, NULL);
-}
-
-void SIMIX_process_create_with_parent(smx_process_t *process,
- const char *name,
- xbt_main_func_t code,
- void *data,
- const char *hostname,
- double kill_time,
- int argc, char **argv,
- xbt_dict_t properties,
- int auto_restart,
- smx_process_t parent_process) {
+ int auto_restart,
+ smx_process_t parent_process)
+{
*process = NULL;
smx_host_t host = SIMIX_host_get_by_name(hostname);
}
simcall_process_sleep__set__result(simcall, state);
simcall->issuer->waiting_action = NULL;
- SIMIX_simcall_answer(simcall);
+ if (simcall->issuer->suspended) {
+ XBT_DEBUG("Wait! This process is suspended and can't wake up now.");
+ simcall->issuer->suspended = 0;
+ SIMIX_pre_process_suspend(simcall, simcall->issuer);
+ } else {
+ SIMIX_simcall_answer(simcall);
+ }
}
SIMIX_process_sleep_destroy(action);
void SIMIX_process_sleep_resume(smx_action_t action)
{
+ XBT_DEBUG("Action state is %d on process_sleep_resume.", action->state);
xbt_assert(action->type == SIMIX_ACTION_SLEEP);
surf_action_resume(action->sleep.surf_sleep);
}
SIMIX_process_stop(self);
}
- if(self->suspended) {
+ if (self->suspended) {
+ XBT_DEBUG("Hey! I'm suspended.");
xbt_assert(!self->doexception, "Gloups! This exception may be lost by subsequent calls.");
self->suspended = 0;
- SIMIX_process_suspend(self,self);
+ SIMIX_process_suspend(self, self);
}
if (self->doexception) {
arg.argc,
arg.argv,
arg.properties,
- arg.auto_restart);
- }
- else {
+ arg.auto_restart,
+ NULL);
+ } else {
simcall_process_create(&new_process,
- arg.argv[0],
- arg.code,
- arg.data,
- arg.hostname,
- arg.kill_time,
- arg.argc,
- arg.argv,
- arg.properties,
- arg.auto_restart);
+ arg.argv[0],
+ arg.code,
+ arg.data,
+ arg.hostname,
+ arg.kill_time,
+ arg.argc,
+ arg.argv,
+ arg.properties,
+ arg.auto_restart);
}
return new_process;
double kill_time,
int argc, char **argv,
xbt_dict_t properties,
- int auto_restart);
-void SIMIX_process_create_with_parent(smx_process_t *process,
- const char *name,
- xbt_main_func_t code,
- void *data,
- const char *hostname,
- double kill_time,
- int argc, char **argv,
- xbt_dict_t properties,
- int auto_restart,
- smx_process_t parent_process);
+ int auto_restart,
+ smx_process_t parent_process);
void SIMIX_process_runall(void);
void SIMIX_process_kill(smx_process_t process, smx_process_t issuer);
void SIMIX_process_killall(smx_process_t issuer, int reset_pid);
void SIMIX_simcall_pre(smx_simcall_t simcall, int value)
{
XBT_DEBUG("Handling simcall %p: %s", simcall, SIMIX_simcall_name(simcall->call));
- simcall->mc_value = value;
+ SIMCALL_SET_MC_VALUE(simcall, value);
if (simcall->issuer->context->iwannadie && simcall->call != SIMCALL_PROCESS_CLEANUP)
return;
switch (simcall->call) {
typedef struct s_smx_simcall {
e_smx_simcall_t call;
smx_process_t issuer;
+#ifdef HAVE_MC
int mc_value;
+#endif
union u_smx_scalar args[10];
union u_smx_scalar result;
//FIXME: union u_smx_scalar retval;
};
} s_smx_simcall_t, *smx_simcall_t;
+#if HAVE_MC
+#define SIMCALL_SET_MC_VALUE(simcall, value) ((simcall)->mc_value = (value))
+#define SIMCALL_GET_MC_VALUE(simcall) ((simcall)->mc_value)
+#else
+#define SIMCALL_SET_MC_VALUE(simcall, value) ((void)0)
+#define SIMCALL_GET_MC_VALUE(simcall) 0
+#endif
+
#include "simcalls_generated_res_getter_setter.h"
#include "simcalls_generated_args_getter_setter.h"
set(tesh_files
${tesh_files}
${CMAKE_CURRENT_SOURCE_DIR}/get_sender.tesh
- ${CMAKE_CURRENT_SOURCE_DIR}/pid.tesh
${CMAKE_CURRENT_SOURCE_DIR}/host_on_off.tesh
- ${CMAKE_CURRENT_SOURCE_DIR}/task_destroy_cancel.tesh
+ ${CMAKE_CURRENT_SOURCE_DIR}/pid.tesh
${CMAKE_CURRENT_SOURCE_DIR}/process.tesh
+ ${CMAKE_CURRENT_SOURCE_DIR}/task_destroy_cancel.tesh
PARENT_SCOPE
)
set(xml_files
${xml_files}
${CMAKE_CURRENT_SOURCE_DIR}/get_sender_d.xml
${CMAKE_CURRENT_SOURCE_DIR}/get_sender_p.xml
- ${CMAKE_CURRENT_SOURCE_DIR}/pid_d.xml
- ${CMAKE_CURRENT_SOURCE_DIR}/pid_p.xml
${CMAKE_CURRENT_SOURCE_DIR}/host_on_off_d.xml
${CMAKE_CURRENT_SOURCE_DIR}/host_on_off_p.xml
+ ${CMAKE_CURRENT_SOURCE_DIR}/pid_d.xml
+ ${CMAKE_CURRENT_SOURCE_DIR}/pid_p.xml
+ ${CMAKE_CURRENT_SOURCE_DIR}/process_d.xml
+ ${CMAKE_CURRENT_SOURCE_DIR}/process_p.xml
${CMAKE_CURRENT_SOURCE_DIR}/task_destroy_cancel_d.xml
${CMAKE_CURRENT_SOURCE_DIR}/task_destroy_cancel_p.xml
- ${CMAKE_CURRENT_SOURCE_DIR}/process.xml
PARENT_SCOPE
)
set(teshsuite_src
${teshsuite_src}
${CMAKE_CURRENT_SOURCE_DIR}/get_sender.c
- ${CMAKE_CURRENT_SOURCE_DIR}/pid.c
${CMAKE_CURRENT_SOURCE_DIR}/host_on_off.c
- ${CMAKE_CURRENT_SOURCE_DIR}/task_destroy_cancel.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/pid.c
${CMAKE_CURRENT_SOURCE_DIR}/process.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/task_destroy_cancel.c
PARENT_SCOPE
)
set(bin_files
msg_process_t process = NULL;
MSG_process_sleep(1);
xbt_swag_foreach(process, process_list) {
- XBT_INFO("Process(pid=%d, ppid=%d, name=%s)", MSG_process_get_PID(process), MSG_process_get_PPID(process), MSG_process_get_name(process));
- if (MSG_process_self_PID()!=MSG_process_get_PID(process))
+ XBT_INFO("Process(pid=%d, ppid=%d, name=%s)",
+ MSG_process_get_PID(process), MSG_process_get_PPID(process),
+ MSG_process_get_name(process));
+ if (MSG_process_self_PID() != MSG_process_get_PID(process))
MSG_process_kill(process);
}
- process = MSG_process_create("slave from master", slave, NULL, MSG_host_self());
+ process = MSG_process_create("slave from master",
+ slave, NULL, MSG_host_self());
MSG_process_sleep(2);
XBT_INFO("Suspend Process(pid=%d)", MSG_process_get_PID(process));
MSG_process_suspend(process);
- XBT_INFO("Process(pid=%d) is %ssuspended"
- ,MSG_process_get_PID(process)
- ,(MSG_process_is_suspended(process)) ? "" : "not ");
+ XBT_INFO("Process(pid=%d) is %ssuspended",
+ MSG_process_get_PID(process),
+ (MSG_process_is_suspended(process)) ? "" : "not ");
MSG_process_sleep(2);
XBT_INFO("Resume Process(pid=%d)", MSG_process_get_PID(process));
MSG_process_resume(process);
- XBT_INFO("Process(pid=%d) is %ssuspended"
- ,MSG_process_get_PID(process)
- ,(MSG_process_is_suspended(process)) ? "" : "not ");
+ XBT_INFO("Process(pid=%d) is %ssuspended",
+ MSG_process_get_PID(process),
+ (MSG_process_is_suspended(process)) ? "" : "not ");
MSG_process_sleep(2);
MSG_process_kill(process);
int slave(int argc, char *argv[])
{
MSG_process_sleep(.5);
- XBT_INFO("Slave started (PID:%d, PPID:%d)", MSG_process_self_PID(), MSG_process_self_PPID());
+ XBT_INFO("Slave started (PID:%d, PPID:%d)",
+ MSG_process_self_PID(), MSG_process_self_PPID());
while(1){
- XBT_INFO("Plop i am %ssuspended", (MSG_process_is_suspended(MSG_process_self())) ? "" : "not ");
+ XBT_INFO("Plop i am %ssuspended",
+ (MSG_process_is_suspended(MSG_process_self())) ? "" : "not ");
MSG_process_sleep(1);
- //MSG_process_suspend(MSG_process_self());
}
XBT_INFO("I'm done. See you!");
return 0;
const char *application_file;
MSG_init(&argc, argv);
- if (argc < 2) {
+ if (argc != 3) {
printf("Usage: %s platform_file deployment_file\n", argv[0]);
printf("example: %s msg_platform.xml msg_deployment.xml\n", argv[0]);
exit(1);
}
platform_file = argv[1];
- application_file = argv[1];
+ application_file = argv[2];
/* MSG_config("workstation/model","KCCFLN05"); */
{ /* Simulation setting */
-$ msg/process ${srcdir:=.}/msg/process.xml
+$ msg/process ${srcdir:=.}/msg/process_p.xml ${srcdir:=.}/msg/process_d.xml
> [Tremblay:slave:(2) 0.500000] [msg_test/INFO] Slave started (PID:2, PPID:0)
> [Tremblay:slave:(2) 0.500000] [msg_test/INFO] Plop i am not suspended
> [Tremblay:master:(1) 1.000000] [msg_test/INFO] Process(pid=1, ppid=0, name=master)
> [Tremblay:master:(1) 3.000000] [msg_test/INFO] Process(pid=3) is suspended
> [Tremblay:master:(1) 5.000000] [msg_test/INFO] Resume Process(pid=3)
> [Tremblay:master:(1) 5.000000] [msg_test/INFO] Process(pid=3) is not suspended
-> [Tremblay:slave from master:(3) 5.500000] [msg_test/INFO] Plop i am not suspended
-> [Tremblay:slave from master:(3) 6.500000] [msg_test/INFO] Plop i am not suspended
+> [Tremblay:slave from master:(3) 5.000000] [msg_test/INFO] Plop i am not suspended
+> [Tremblay:slave from master:(3) 6.000000] [msg_test/INFO] Plop i am not suspended
> [Tremblay:master:(1) 7.000000] [msg_test/INFO] Goodbye now!
> [7.000000] [msg_test/INFO] Simulation time 7
<?xml version='1.0'?>
<!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
<platform version="3">
- <!-- The hosts -->
- <AS id="AS0" routing="Full">
- <host id="Tremblay" power="98.095Mf"/>
- </AS>
-
<!-- The master process (with some arguments) -->
<process host="Tremblay" function="master">
</process>
-
+
<!-- The slave processes (with mailbox to listen on as argument) -->
<process host="Tremblay" function="slave">
</process>
- </platform>
\ No newline at end of file
+</platform>
\ No newline at end of file
--- /dev/null
+<?xml version='1.0'?>
+<!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
+<platform version="3">
+ <!-- The hosts -->
+ <AS id="AS0" routing="Full">
+ <host id="Tremblay" power="98.095Mf"/>
+ </AS>
+</platform>
\ No newline at end of file