XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
"Messages specific for this msg example");
+static m_process_t process_to_migrate = NULL;
+
/** The guy we will move from host to host. It move alone and then is moved by policeman back */
static int emigrant(int argc, char *argv[])
{
m_task_t task;
XBT_INFO
("I'll look for a new job on another machine where the grass is greener.");
- MSG_process_change_host(MSG_get_host_by_name("Boivin"));
+ MSG_process_migrate(MSG_process_self(), MSG_get_host_by_name("Boivin"));
+
XBT_INFO("Yeah, found something to do");
task = MSG_task_create("job", 98095000, 0, NULL);
MSG_task_execute(task);
MSG_task_destroy(task);
MSG_process_sleep(2);
XBT_INFO("Moving back home after work");
- MSG_process_change_host(MSG_get_host_by_name("Jacquelin"));
- MSG_process_change_host(MSG_get_host_by_name("Boivin"));
+ MSG_process_migrate(MSG_process_self(), MSG_get_host_by_name("Jacquelin"));
+ MSG_process_migrate(MSG_process_self(), MSG_get_host_by_name("Boivin"));
MSG_process_sleep(4);
+ process_to_migrate = MSG_process_self();
+ MSG_process_suspend(MSG_process_self());
+ m_host_t h = MSG_process_get_host(MSG_process_self());
+ XBT_INFO("I've been moved on this new host: %s", h->name);
XBT_INFO("Uh, nothing to do here. Stopping now");
return 0;
} /* end_of_emigrant */
-/* This function would move the emigrant back home, if it were possible to do so in the MSG API.
- * Nothing for now.
- */
+
+/* This function move the emigrant on Jacquelin */
static int policeman(int argc, char *argv[])
{
- XBT_INFO
- ("No function in the API to move the emigrant back, so do nothing.");
+ XBT_INFO("Wait a bit before migrating the emigrant.");
+ while (process_to_migrate == NULL) MSG_process_sleep(1);
+ MSG_process_migrate(process_to_migrate, MSG_get_host_by_name("Jacquelin"));
+ XBT_INFO("I moved the emigrant");
+ MSG_process_resume(process_to_migrate);
return 0;
} /* end_of_policeman */
/* Application deployment */
MSG_function_register("emigrant", emigrant);
+ MSG_function_register("policeman", policeman);
MSG_launch_application(argv[2]);
/* Run the simulation */
<!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
<platform version="3">
<process host="Jacquelin" function="emigrant"/>
+ <process host="Boivin" function="policeman"/>
</platform>
$ $SG_TEST_EXENV migration/migration ${srcdir:=.}/msg_platform.xml ${srcdir:=.}/migration/migration.deploy "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
> [ 0.000000] (1:emigrant@Jacquelin) I'll look for a new job on another machine where the grass is greener.
> [ 0.000000] (1:emigrant@Boivin) Yeah, found something to do
+> [ 0.000000] (2:policeman@Boivin) Wait a bit before migrating the emigrant.
> [ 3.000000] (1:emigrant@Boivin) Moving back home after work
> [ 7.000000] (0:@) Simulation time 7
-> [ 7.000000] (1:emigrant@Boivin) Uh, nothing to do here. Stopping now
+> [ 7.000000] (1:emigrant@Jacquelin) I've been moved on this new host: Jacquelin
+> [ 7.000000] (1:emigrant@Jacquelin) Uh, nothing to do here. Stopping now
+> [ 7.000000] (2:policeman@Boivin) I moved the emigrant
destination = (char*)MSG_task_get_data (task);
if (!destination) break; //there is no destination, die
XBT_INFO("Migrating to %s", destination);
- MSG_process_change_host(MSG_get_host_by_name(destination));
+ MSG_process_migrate(MSG_process_self(), MSG_get_host_by_name(destination));
MSG_process_sleep(2); // I am tired, have to sleep for 2 seconds
xbt_free (destination);
MSG_task_destroy (task);
XBT_PUBLIC(void) MSG_process_kill(m_process_t process);
XBT_PUBLIC(int) MSG_process_killall(int reset_PIDs);
-XBT_PUBLIC(MSG_error_t) MSG_process_change_host(m_host_t host);
+XBT_PUBLIC(MSG_error_t) MSG_process_migrate(m_process_t process, m_host_t host);
XBT_PUBLIC(void *) MSG_process_get_data(m_process_t process);
XBT_PUBLIC(MSG_error_t) MSG_process_set_data(m_process_t process,
XBT_PUBLIC(void) MSG_action_unregister(const char *action_name);
MSG_error_t MSG_action_trace_run(char *path);
-
#ifdef MSG_USE_DEPRECATED
/* these are the functions which are deprecated. Do not use them, they may get removed in future releases */
#define MSG_TIMEOUT_FAILURE MSG_TIMEOUT
#define MSG_mailbox_put_with_time_out(mailbox, task, timeout) \
MSG_mailbox_put_with_timeout(mailbox, task, timeout)
+#define MSG_process_change_host(h) MSG_process_migrate(MSG_process_self(),h);
#endif
#include "instr/instr.h"
#include "simix/simix.h"
XBT_PUBLIC(smx_context_t) MSG_process_get_smx_ctx(m_process_t process);
-
SG_END_DECL()
#endif
/* Process handling */
XBT_PUBLIC(void) SIMIX_req_process_cleanup(smx_process_t process);
XBT_PUBLIC(void) SIMIX_req_process_change_host(smx_process_t process,
- const char *source, const char *dest);
+ smx_host_t dest);
XBT_PUBLIC(void) SIMIX_req_process_suspend(smx_process_t process);
XBT_PUBLIC(void) SIMIX_req_process_resume(smx_process_t process);
* This function checks whether \a process and \a host are valid pointers
and change the value of the #m_host_t on which \a process is running.
*/
-MSG_error_t MSG_process_change_host(m_host_t host)
+MSG_error_t MSG_process_migrate(m_process_t process, m_host_t host)
{
- m_process_t process = MSG_process_self();
- simdata_process_t simdata = SIMIX_process_self_get_data();
- m_host_t now = simdata->m_host;
+ simdata_process_t simdata = SIMIX_req_process_get_data(process);
simdata->m_host = host;
#ifdef HAVE_TRACING
+ m_host_t now = simdata->m_host;
TRACE_msg_process_change_host(process, now, host);
#endif
- SIMIX_req_process_change_host(process, now->name, host->name);
+ SIMIX_req_process_change_host(process, host->simdata->smx_host);
return MSG_OK;
}
int doexception:1;
int blocked:1;
int suspended:1;
+ smx_host_t new_host; /* if not null, the host on which the process must migrate to */
smx_action_t waiting_action;
xbt_dict_t properties;
s_smx_req_t request;
void SIMIX_process_yield(void);
xbt_running_ctx_t *SIMIX_process_get_running_context(void);
void SIMIX_process_exception_terminate(xbt_ex_t * e);
+void SIMIX_pre_process_change_host(smx_process_t process,
+ smx_host_t dest);
void SIMIX_process_change_host(smx_process_t process,
- const char *source, const char *dest);
+ smx_host_t dest);
+void SIMIX_pre_process_change_host(smx_process_t process, smx_host_t host);
void SIMIX_pre_process_suspend(smx_req_t req);
void SIMIX_process_suspend(smx_process_t process, smx_process_t issuer);
void SIMIX_process_resume(smx_process_t process, smx_process_t issuer);
struct {
smx_process_t process;
- const char *source;
- const char *dest;
+ smx_host_t dest;
} process_change_host;
struct {
}
void SIMIX_process_change_host(smx_process_t process,
- const char *source, const char *dest)
+ smx_host_t dest)
{
- smx_host_t h1 = NULL;
- smx_host_t h2 = NULL;
xbt_assert((process != NULL), "Invalid parameters");
- h1 = SIMIX_host_get_by_name(source);
- h2 = SIMIX_host_get_by_name(dest);
- process->smx_host = h2;
- xbt_swag_remove(process, h1->process_list);
- xbt_swag_insert(process, h2->process_list);
+ xbt_swag_remove(process, process->smx_host->process_list);
+ process->smx_host = dest;
+ xbt_swag_insert(process, dest->process_list);
+}
+
+void SIMIX_pre_process_change_host(smx_process_t process, smx_host_t dest)
+{
+ process->new_host = dest;
}
void SIMIX_pre_process_suspend(smx_req_t req)
self->doexception = 0;
RETHROW;
}
+
+ if (self->new_host) {
+ SIMIX_process_change_host(self, self->new_host);
+ self->new_host = NULL;
+ }
}
/* callback: context fetching */
break;
case REQ_PROCESS_CHANGE_HOST:
- SIMIX_process_change_host(
+ SIMIX_pre_process_change_host(
req->process_change_host.process,
- req->process_change_host.source,
req->process_change_host.dest);
SIMIX_request_answer(req);
break;
* \param source name of the previous host
* \param dest name of the new host
*/
-void SIMIX_req_process_change_host(smx_process_t process, const char *source, const char *dest)
+void SIMIX_req_process_change_host(smx_process_t process, smx_host_t dest)
{
smx_req_t req = SIMIX_req_mine();
req->call = REQ_PROCESS_CHANGE_HOST;
req->process_change_host.process = process;
- req->process_change_host.source = source;
req->process_change_host.dest = dest;
SIMIX_request_push();
}