Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix problems on host on/off
authorPaul Bédaride <paul.bedaride@gmail.com>
Wed, 26 Jun 2013 15:17:08 +0000 (17:17 +0200)
committerPaul Bédaride <paul.bedaride@gmail.com>
Wed, 26 Jun 2013 15:17:08 +0000 (17:17 +0200)
include/simgrid/simix.h
src/bindings/java/jmsg_host.c
src/bindings/java/jmsg_host.h
src/bindings/java/org/simgrid/msg/Host.java
src/msg/msg_host.c
src/simix/smx_deployment.c
src/simix/smx_host.c
src/simix/smx_host_private.h
src/simix/smx_smurf.c

index 8254d46..301aded 100644 (file)
@@ -257,7 +257,7 @@ XBT_PUBLIC(smx_host_t) SIMIX_host_self(void);
 XBT_PUBLIC(const char*) SIMIX_host_self_get_name(void);
 XBT_PUBLIC(const char*) SIMIX_host_get_name(smx_host_t host); /* FIXME: make private: only the name of SIMIX_host_self() should be public without request */
 XBT_PUBLIC(void) SIMIX_host_on(smx_host_t host);
 XBT_PUBLIC(const char*) SIMIX_host_self_get_name(void);
 XBT_PUBLIC(const char*) SIMIX_host_get_name(smx_host_t host); /* FIXME: make private: only the name of SIMIX_host_self() should be public without request */
 XBT_PUBLIC(void) SIMIX_host_on(smx_host_t host);
-XBT_PUBLIC(void) SIMIX_host_off(smx_host_t host);
+XBT_PUBLIC(void) SIMIX_host_off(smx_host_t host, smx_process_t issuer);
 XBT_PUBLIC(void) SIMIX_host_self_set_data(void *data);
 XBT_PUBLIC(void*) SIMIX_host_self_get_data(void);
 XBT_PUBLIC(void*) SIMIX_host_get_data(smx_host_t host);
 XBT_PUBLIC(void) SIMIX_host_self_set_data(void *data);
 XBT_PUBLIC(void*) SIMIX_host_self_get_data(void);
 XBT_PUBLIC(void*) SIMIX_host_get_data(smx_host_t host);
index b32b9b5..07c908c 100644 (file)
@@ -154,6 +154,19 @@ Java_org_simgrid_msg_Host_currentHost(JNIEnv * env, jclass cls) {
 
   return jhost;
 }
 
   return jhost;
 }
+
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Host_on(JNIEnv *env, jobject jhost) {
+  msg_host_t host = jhost_get_native(env, jhost);
+  MSG_host_on(host);
+}
+
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Host_off(JNIEnv *env, jobject jhost) {
+  msg_host_t host = jhost_get_native(env, jhost);
+  MSG_host_off(host);
+}
+
 JNIEXPORT jint JNICALL
 Java_org_simgrid_msg_Host_getCount(JNIEnv * env, jclass cls) {
   xbt_dynar_t hosts =  MSG_hosts_as_dynar();
 JNIEXPORT jint JNICALL
 Java_org_simgrid_msg_Host_getCount(JNIEnv * env, jclass cls) {
   xbt_dynar_t hosts =  MSG_hosts_as_dynar();
index 401d53b..e132ce1 100644 (file)
@@ -112,6 +112,24 @@ Java_org_simgrid_msg_Host_nativeInit(JNIEnv *env, jclass cls);
 JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_getByName
     (JNIEnv *, jclass, jstring);
 
 JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_getByName
     (JNIEnv *, jclass, jstring);
 
+/**
+ * This function start the host if it is off
+ *
+ * @param jhost                        The host to test the validity.
+ * @param env                  The environment of the current thread
+ *
+ */
+JNIEXPORT void JNICALL Java_org_simgrid_msg_Host_on(JNIEnv *env, jobject jhost);
+
+/**
+ * This function stop the host if it is on
+ *
+ * @param jhost                        The host to test the validity.
+ * @param env                  The environment of the current thread
+ *
+ */
+JNIEXPORT void JNICALL Java_org_simgrid_msg_Host_off(JNIEnv *env, jobject jhost);
+
 /*
  * Class               org_simgrid_msg_Host
  * Method              currentHost
 /*
  * Class               org_simgrid_msg_Host
  * Method              currentHost
index 3a4c666..d8c46f3 100644 (file)
@@ -128,6 +128,7 @@ public class Host {
        public String getName() {
                return name;
        }
        public String getName() {
                return name;
        }
+
        /**
         * Sets the data of the host.
      * @param data
        /**
         * Sets the data of the host.
      * @param data
@@ -153,6 +154,17 @@ public class Host {
                return null != this.data;
        }
 
                return null != this.data;
        }
 
+       /**
+        * This method start the host if it is off
+        */ 
+       public native void on();
+
+       /**
+        * This method stop the host if it is on
+        */ 
+       public native void off();
+
+
        /**
         * This method returns the number of tasks currently running on a host.
         * The external load is not taken in account.
        /**
         * This method returns the number of tasks currently running on a host.
         * The external load is not taken in account.
index 3a64215..ccfc880 100644 (file)
@@ -129,7 +129,7 @@ void MSG_host_on(msg_host_t host)
  * \brief Stop the host if it is on
  */
 void MSG_host_off(msg_host_t host)
  * \brief Stop the host if it is on
  */
 void MSG_host_off(msg_host_t host)
-{ 
+{
   simcall_host_off(host);
 }
 
   simcall_host_off(host);
 }
 
index 5b34af3..72072a3 100644 (file)
@@ -36,6 +36,23 @@ static void parse_process(sg_platf_process_cbarg_t process)
   smx_process_arg_t arg = NULL;
   smx_process_t process_created = NULL;
 
   smx_process_arg_t arg = NULL;
   smx_process_t process_created = NULL;
 
+  arg = xbt_new0(s_smx_process_arg_t, 1);
+  arg->code = parse_code;
+  arg->data = NULL;
+  arg->hostname = sg_host_name(host);
+  arg->argc = process->argc;
+  arg->argv = xbt_new(char *,process->argc);
+  int i;
+  for (i=0; i<process->argc; i++)
+    arg->argv[i] = xbt_strdup(process->argv[i]);
+  arg->name = (char*)(arg->argv)[0];
+  arg->kill_time = kill_time;
+  arg->properties = current_property_set;
+  if (!SIMIX_host_priv(host)->boot_processes) {
+    SIMIX_host_priv(host)->boot_processes = xbt_dynar_new(sizeof(smx_process_arg_t), _SIMIX_host_free_process_arg);
+  }
+  xbt_dynar_push_as(SIMIX_host_priv(host)->boot_processes,smx_process_arg_t,arg);
+
   if (start_time > SIMIX_get_clock()) {
     arg = xbt_new0(s_smx_process_arg_t, 1);
     arg->name = (char*)(process->argv)[0];
   if (start_time > SIMIX_get_clock()) {
     arg = xbt_new0(s_smx_process_arg_t, 1);
     arg->name = (char*)(process->argv)[0];
@@ -67,7 +84,7 @@ static void parse_process(sg_platf_process_cbarg_t process)
     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);
     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);
-
+    
     /* verify if process has been created (won't be the case if the host is currently dead, but that's fine) */
     if (!process_created) {
       return;
     /* verify if process has been created (won't be the case if the host is currently dead, but that's fine) */
     if (!process_created) {
       return;
index 08ecdf3..cf11967 100644 (file)
@@ -49,49 +49,75 @@ void SIMIX_pre_host_on(smx_simcall_t simcall, smx_host_t h)
  */
 void SIMIX_host_on(smx_host_t h)
 {
  */
 void SIMIX_host_on(smx_host_t h)
 {
-  smx_host_priv_t host = (smx_host_priv_t) h;
+  smx_host_priv_t host = SIMIX_host_priv(h);
 
   xbt_assert((host != NULL), "Invalid parameters");
 
   xbt_assert((host != NULL), "Invalid parameters");
-  
-  surf_model_t ws_model = surf_resource_model(h, SURF_WKS_LEVEL);
-  ws_model->extension.workstation.set_state(host, SURF_RESOURCE_ON);
 
 
-  SIMIX_host_restart_processes(h);
+  surf_model_t ws_model = surf_resource_model(h, SURF_WKS_LEVEL);
+  if (ws_model->extension.workstation.get_state(h)==SURF_RESOURCE_OFF) {
+    ws_model->extension.workstation.set_state(h, SURF_RESOURCE_ON);
+    unsigned int cpt;
+    smx_process_arg_t arg;
+    xbt_dynar_foreach(host->boot_processes,cpt,arg) {
+      smx_process_t process;
+
+      XBT_DEBUG("Booting Process %s(%s) right now", arg->argv[0], arg->hostname);
+      if (simix_global->create_process_function) {
+        simix_global->create_process_function(&process,
+                                              arg->argv[0],
+                                              arg->code,
+                                              NULL,
+                                              arg->hostname,
+                                              arg->kill_time,
+                                              arg->argc,
+                                              arg->argv,
+                                              arg->properties,
+                                              arg->auto_restart);
+      }
+      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);
+      }
+    }
+  }
 }
 
 void SIMIX_pre_host_off(smx_simcall_t simcall, smx_host_t h)
 {
 }
 
 void SIMIX_pre_host_off(smx_simcall_t simcall, smx_host_t h)
 {
-  SIMIX_host_off(h);
+  SIMIX_host_off(h, simcall->issuer);
 }
 
 /**
  * \brief Stop the host if it is on
  *
  */
 }
 
 /**
  * \brief Stop the host if it is on
  *
  */
-void SIMIX_host_off(smx_host_t h)
+void SIMIX_host_off(smx_host_t h, smx_process_t issuer)
 {
 {
-  smx_host_priv_t host = (smx_host_priv_t) h;
+  smx_host_priv_t host = SIMIX_host_priv(h);
 
   xbt_assert((host != NULL), "Invalid parameters");
 
   xbt_assert((host != NULL), "Invalid parameters");
-
-  /* Clean Simulator data */
-  if (xbt_swag_size(host->process_list) != 0) {
-    char *msg = xbt_strdup("Shutting down host, but it's not empty:");
-    char *tmp;
-    smx_process_t process = NULL;
-
-    xbt_swag_foreach(process, host->process_list) {
-      tmp = bprintf("%s\n\t%s", msg, process->name);
-      free(msg);
-      msg = tmp;
+  
+  surf_model_t ws_model = surf_resource_model(h, SURF_WKS_LEVEL);
+  if (ws_model->extension.workstation.get_state(h)==SURF_RESOURCE_ON) {
+    ws_model->extension.workstation.set_state(h, SURF_RESOURCE_OFF);
+
+    /* Clean Simulator data */
+    if (xbt_swag_size(host->process_list) != 0) {
+      smx_process_t process = NULL;
+      xbt_swag_foreach(process, host->process_list) {
+        SIMIX_process_kill(process, issuer);
+       XBT_DEBUG("Killing %s on %s by %s", process->name,  sg_host_name(process->smx_host), issuer->name);
+      }
     }
     }
-    SIMIX_display_process_status();
-    THROWF(arg_error, 0, "%s", msg);
   }
   }
-  xbt_swag_free(host->process_list);
-
-  surf_model_t ws_model = surf_resource_model(h, SURF_WKS_LEVEL);
-  ws_model->extension.workstation.set_state(host, SURF_RESOURCE_OFF);
 }
 
 /**
 }
 
 /**
@@ -120,6 +146,7 @@ void SIMIX_host_destroy(void *h)
     THROWF(arg_error, 0, "%s", msg);
   }
   xbt_dynar_free(&host->auto_restart_processes);
     THROWF(arg_error, 0, "%s", msg);
   }
   xbt_dynar_free(&host->auto_restart_processes);
+  xbt_dynar_free(&host->boot_processes);
   xbt_swag_free(host->process_list);
 
   /* Clean host structure */
   xbt_swag_free(host->process_list);
 
   /* Clean host structure */
@@ -260,7 +287,7 @@ void* SIMIX_host_get_data(smx_host_t host){
 
   return SIMIX_host_priv(host)->data;
 }
 
   return SIMIX_host_priv(host)->data;
 }
-void _SIMIX_host_free_process_arg(void *);
+
 void _SIMIX_host_free_process_arg(void *data)
 {
   smx_process_arg_t arg = *(void**)data;
 void _SIMIX_host_free_process_arg(void *data)
 {
   smx_process_arg_t arg = *(void**)data;
index 4ed05a1..7fd525e 100644 (file)
@@ -14,6 +14,7 @@
 typedef struct s_smx_host_priv {
   xbt_swag_t process_list;
   xbt_dynar_t auto_restart_processes;
 typedef struct s_smx_host_priv {
   xbt_swag_t process_list;
   xbt_dynar_t auto_restart_processes;
+  xbt_dynar_t boot_processes; 
   void *data;              /**< @brief user data */
 } s_smx_host_priv_t;
 
   void *data;              /**< @brief user data */
 } s_smx_host_priv_t;
 
@@ -21,6 +22,7 @@ static inline smx_host_priv_t SIMIX_host_priv(smx_host_t host){
   return xbt_lib_get_level(host, SIMIX_HOST_LEVEL);
 }
 
   return xbt_lib_get_level(host, SIMIX_HOST_LEVEL);
 }
 
+void _SIMIX_host_free_process_arg(void *);
 
 smx_host_t SIMIX_host_create(const char *name, void *workstation, void *data);
 void SIMIX_host_destroy(void *host);
 
 smx_host_t SIMIX_host_create(const char *name, void *workstation, void *data);
 void SIMIX_host_destroy(void *host);
@@ -43,7 +45,7 @@ double SIMIX_host_get_speed(smx_host_t host);
 double SIMIX_host_get_available_speed(smx_host_t host);
 int SIMIX_host_get_state(smx_host_t host);
 void SIMIX_host_on(smx_host_t host);
 double SIMIX_host_get_available_speed(smx_host_t host);
 int SIMIX_host_get_state(smx_host_t host);
 void SIMIX_host_on(smx_host_t host);
-void SIMIX_host_off(smx_host_t host);
+void SIMIX_host_off(smx_host_t host, smx_process_t issuer);
 smx_action_t SIMIX_host_execute(const char *name,
     smx_host_t host, double computation_amount, double priority, double bound);
 smx_action_t SIMIX_host_parallel_execute(const char *name,
 smx_action_t SIMIX_host_execute(const char *name,
     smx_host_t host, double computation_amount, double priority, double bound);
 smx_action_t SIMIX_host_parallel_execute(const char *name,
index aec3439..a5a3e27 100644 (file)
@@ -49,6 +49,8 @@ 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;
 {
   XBT_DEBUG("Handling simcall %p: %s", simcall, SIMIX_simcall_name(simcall->call));
   simcall->mc_value = value;
+  if (simcall->issuer->context->iwannadie && simcall->call != SIMCALL_PROCESS_CLEANUP)
+    return;
   switch (simcall->call) {
 SIMCALL_LIST(SIMCALL_CASE, SIMCALL_SEP_NOTHING)
     case NUM_SIMCALLS:;
   switch (simcall->call) {
 SIMCALL_LIST(SIMCALL_CASE, SIMCALL_SEP_NOTHING)
     case NUM_SIMCALLS:;