Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Coding Sprint : Synchronize SVN with GitHub
authorPierre-Nicolas Clauss <pini@tuxfamily.org>
Tue, 29 Mar 2011 15:35:50 +0000 (17:35 +0200)
committerPierre-Nicolas Clauss <pini@tuxfamily.org>
Tue, 29 Mar 2011 15:35:50 +0000 (17:35 +0200)
12 files changed:
examples/msg/migration/migration.c
examples/msg/migration/migration.deploy
examples/msg/migration/migration.tesh
examples/msg/tracing/procmig.c
include/msg/msg.h
include/simix/simix.h
src/msg/m_process.c
src/simix/process_private.h
src/simix/smurf_private.h
src/simix/smx_process.c
src/simix/smx_smurf.c
src/simix/smx_user.c

index 5abb763..2fc714d 100644 (file)
 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 */
index ddff236..272bbaf 100644 (file)
@@ -2,4 +2,5 @@
 <!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
 <platform version="3">
   <process host="Jacquelin" function="emigrant"/>
+  <process host="Boivin" function="policeman"/>
 </platform>
index a75120d..40b247f 100644 (file)
@@ -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
index 1878229..5ee80ca 100644 (file)
@@ -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);
index 1c53833..b982de1 100644 (file)
@@ -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
index 967dd5d..7c6a70a 100644 (file)
@@ -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);
 
index 66cafcb..99e606a 100644 (file)
@@ -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;
 }
 
index cb391c3..8df718c 100644 (file)
@@ -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);
index 7c2dd90..1c15a37 100644 (file)
@@ -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 {
index 54e7555..3296198 100644 (file)
@@ -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 */
index cc612ae..840166a 100644 (file)
@@ -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;
index 9a5cb0b..5b58220 100644 (file)
@@ -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();
 }