From b65f44359644f1fdbe91077e7d379453a16f857a Mon Sep 17 00:00:00 2001 From: cristianrosa Date: Tue, 29 Mar 2011 15:32:44 +0000 Subject: [PATCH] Merge branch 'master', remote branch 'git-hub-cristian/master' git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@9887 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- examples/msg/migration/migration.c | 26 +++++++++++++++++-------- examples/msg/migration/migration.deploy | 1 + examples/msg/migration/migration.tesh | 5 ++++- examples/msg/tracing/procmig.c | 2 +- include/msg/msg.h | 5 ++--- include/simix/simix.h | 2 +- src/msg/m_process.c | 9 ++++----- src/simix/process_private.h | 6 +++++- src/simix/smurf_private.h | 3 +-- src/simix/smx_process.c | 22 +++++++++++++-------- src/simix/smx_smurf.c | 3 +-- src/simix/smx_user.c | 3 +-- 12 files changed, 53 insertions(+), 34 deletions(-) diff --git a/examples/msg/migration/migration.c b/examples/msg/migration/migration.c index 5abb763008..2fc714db07 100644 --- a/examples/msg/migration/migration.c +++ b/examples/msg/migration/migration.c @@ -12,33 +12,42 @@ 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 */ @@ -62,6 +71,7 @@ int main(int argc, char *argv[]) /* Application deployment */ MSG_function_register("emigrant", emigrant); + MSG_function_register("policeman", policeman); MSG_launch_application(argv[2]); /* Run the simulation */ diff --git a/examples/msg/migration/migration.deploy b/examples/msg/migration/migration.deploy index ddff236f12..272bbaf234 100644 --- a/examples/msg/migration/migration.deploy +++ b/examples/msg/migration/migration.deploy @@ -2,4 +2,5 @@ + diff --git a/examples/msg/migration/migration.tesh b/examples/msg/migration/migration.tesh index a75120d021..40b247f590 100644 --- a/examples/msg/migration/migration.tesh +++ b/examples/msg/migration/migration.tesh @@ -6,6 +6,9 @@ p Testing the migration feature of MSG $ $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 diff --git a/examples/msg/tracing/procmig.c b/examples/msg/tracing/procmig.c index 1878229bbe..5ee80cab50 100644 --- a/examples/msg/tracing/procmig.c +++ b/examples/msg/tracing/procmig.c @@ -26,7 +26,7 @@ static int emigrant(int argc, char *argv[]) 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); diff --git a/include/msg/msg.h b/include/msg/msg.h index 1c538337d5..b982de17df 100644 --- a/include/msg/msg.h +++ b/include/msg/msg.h @@ -80,7 +80,7 @@ XBT_PUBLIC(m_process_t) MSG_process_create_with_environment(const char 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, @@ -227,13 +227,13 @@ XBT_PUBLIC(void) MSG_action_register(const char *action_name, 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" @@ -242,6 +242,5 @@ MSG_error_t MSG_action_trace_run(char *path); #include "simix/simix.h" XBT_PUBLIC(smx_context_t) MSG_process_get_smx_ctx(m_process_t process); - SG_END_DECL() #endif diff --git a/include/simix/simix.h b/include/simix/simix.h index 967dd5dbe2..7c6a70a66a 100644 --- a/include/simix/simix.h +++ b/include/simix/simix.h @@ -134,7 +134,7 @@ XBT_PUBLIC(void) SIMIX_req_process_killall(void); /* 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); diff --git a/src/msg/m_process.c b/src/msg/m_process.c index 66cafcb688..99e606ae8f 100644 --- a/src/msg/m_process.c +++ b/src/msg/m_process.c @@ -213,16 +213,15 @@ void MSG_process_kill(m_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; } diff --git a/src/simix/process_private.h b/src/simix/process_private.h index cb391c30bf..8df718cf89 100644 --- a/src/simix/process_private.h +++ b/src/simix/process_private.h @@ -27,6 +27,7 @@ typedef struct s_smx_process { 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; @@ -61,8 +62,11 @@ void SIMIX_process_empty_trash(void); 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); diff --git a/src/simix/smurf_private.h b/src/simix/smurf_private.h index 7c2dd90ce2..1c15a37e59 100644 --- a/src/simix/smurf_private.h +++ b/src/simix/smurf_private.h @@ -233,8 +233,7 @@ typedef struct s_smx_req { struct { smx_process_t process; - const char *source; - const char *dest; + smx_host_t dest; } process_change_host; struct { diff --git a/src/simix/smx_process.c b/src/simix/smx_process.c index 54e7555c76..3296198782 100644 --- a/src/simix/smx_process.c +++ b/src/simix/smx_process.c @@ -234,16 +234,17 @@ void SIMIX_process_killall(smx_process_t issuer) } 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) @@ -518,6 +519,11 @@ void SIMIX_process_yield(void) self->doexception = 0; RETHROW; } + + if (self->new_host) { + SIMIX_process_change_host(self, self->new_host); + self->new_host = NULL; + } } /* callback: context fetching */ diff --git a/src/simix/smx_smurf.c b/src/simix/smx_smurf.c index cc612ae01a..840166ae69 100644 --- a/src/simix/smx_smurf.c +++ b/src/simix/smx_smurf.c @@ -377,9 +377,8 @@ void SIMIX_request_pre(smx_req_t req, int value) 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; diff --git a/src/simix/smx_user.c b/src/simix/smx_user.c index 9a5cb0babe..5b58220cc7 100644 --- a/src/simix/smx_user.c +++ b/src/simix/smx_user.c @@ -376,13 +376,12 @@ void SIMIX_req_process_cleanup(smx_process_t process) * \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(); } -- 2.20.1