Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add MSG_host_on and MSG_host_off
authorPaul Bédaride <paul.bedaride@gmail.com>
Mon, 17 Jun 2013 15:43:08 +0000 (17:43 +0200)
committerPaul Bédaride <paul.bedaride@gmail.com>
Mon, 17 Jun 2013 15:43:08 +0000 (17:43 +0200)
include/msg/msg.h
src/include/surf/surf.h
src/msg/msg_host.c
src/simix/smx_host.c
src/simix/smx_smurf_private.h
src/simix/smx_user.c
src/surf/cpu_cas01.c
src/surf/cpu_ti.c
src/surf/workstation.c

index 154fc39..89d70d6 100644 (file)
@@ -97,6 +97,8 @@ XBT_PUBLIC(void) MSG_as_router_set_property_value(const char* asr, const char *n
 XBT_PUBLIC(msg_error_t) MSG_host_set_data(msg_host_t host, void *data);
 XBT_PUBLIC(void *) MSG_host_get_data(msg_host_t host);
 XBT_PUBLIC(const char *) MSG_host_get_name(msg_host_t host);
 XBT_PUBLIC(msg_error_t) MSG_host_set_data(msg_host_t host, void *data);
 XBT_PUBLIC(void *) MSG_host_get_data(msg_host_t host);
 XBT_PUBLIC(const char *) MSG_host_get_name(msg_host_t host);
+XBT_PUBLIC(void) MSG_host_on(msg_host_t host);
+XBT_PUBLIC(void) MSG_host_off(msg_host_t host);
 XBT_PUBLIC(msg_host_t) MSG_host_self(void);
 XBT_PUBLIC(int) MSG_get_host_msgload(msg_host_t host);
 /* int MSG_get_msgload(void); This function lacks specification; discard it */
 XBT_PUBLIC(msg_host_t) MSG_host_self(void);
 XBT_PUBLIC(int) MSG_get_host_msgload(msg_host_t host);
 /* int MSG_get_msgload(void); This function lacks specification; discard it */
index 0ce4624..68597e2 100644 (file)
@@ -208,6 +208,8 @@ typedef struct surf_cpu_model_extension_public {
   surf_action_t(*execute) (void *cpu, double size);
   surf_action_t(*sleep) (void *cpu, double duration);
   e_surf_resource_state_t(*get_state) (void *cpu);
   surf_action_t(*execute) (void *cpu, double size);
   surf_action_t(*sleep) (void *cpu, double duration);
   e_surf_resource_state_t(*get_state) (void *cpu);
+  void(*set_state) (void *cpu, e_surf_resource_state_t state);
+
   double (*get_speed) (void *cpu, double load);
   double (*get_available_speed) (void *cpu);
   void (*add_traces) (void);
   double (*get_speed) (void *cpu, double load);
   double (*get_available_speed) (void *cpu);
   void (*add_traces) (void);
@@ -262,6 +264,7 @@ typedef struct surf_workstation_model_extension_public {
                                       and create the corresponding action */
   surf_action_t(*sleep) (void *workstation, double duration);                              /**< Make a workstation sleep during a given duration */
   e_surf_resource_state_t(*get_state) (void *workstation);                                      /**< Return the CPU state of a workstation */
                                       and create the corresponding action */
   surf_action_t(*sleep) (void *workstation, double duration);                              /**< Make a workstation sleep during a given duration */
   e_surf_resource_state_t(*get_state) (void *workstation);                                      /**< Return the CPU state of a workstation */
+  void(*set_state) (void *workstation, e_surf_resource_state_t state);
   double (*get_speed) (void *workstation, double load);                                    /**< Return the speed of a workstation */
   double (*get_available_speed) (void *workstation);                                       /**< Return tha available speed of a workstation */
    surf_action_t(*communicate) (void *workstation_src,                                     /**< Execute a communication amount between two workstations */
   double (*get_speed) (void *workstation, double load);                                    /**< Return the speed of a workstation */
   double (*get_available_speed) (void *workstation);                                       /**< Return tha available speed of a workstation */
    surf_action_t(*communicate) (void *workstation_src,                                     /**< Execute a communication amount between two workstations */
index 4cced2c..cd959e8 100644 (file)
@@ -116,6 +116,23 @@ msg_host_t MSG_host_self(void)
   return MSG_process_get_host(NULL);
 }
 
   return MSG_process_get_host(NULL);
 }
 
+
+/*
+ * \brief Start the host if it is off
+ */
+void MSG_host_on(msg_host_t host)
+{
+  simcall_host_on(host);
+}
+
+/*
+ * \brief Stop the host if it is on
+ */
+void MSG_host_off(msg_host_t host)
+{ 
+  simcall_host_off(host);
+}
+
 /*
  * \brief Frees private data of a host (internal call only)
  */
 /*
  * \brief Frees private data of a host (internal call only)
  */
index 86eef31..c94a0fb 100644 (file)
@@ -38,6 +38,62 @@ smx_host_t SIMIX_host_create(const char *name,
   return xbt_lib_get_elm_or_null(host_lib, name);
 }
 
   return xbt_lib_get_elm_or_null(host_lib, name);
 }
 
+void SIMIX_pre_host_on(smx_host_t h)
+{
+  SIMIX_host_on(h);
+}
+
+/**
+ * \brief Start the host if it is off
+ *
+ */
+void SIMIX_host_on(smx_host_t h)
+{
+  smx_host_priv_t host = (smx_host_priv_t) h;
+
+  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);
+}
+
+void SIMIX_pre_host_off(smx_host_t h)
+{
+  SIMIX_host_off(h);
+}
+
+/**
+ * \brief Stop the host if it is on
+ *
+ */
+void SIMIX_host_off(smx_host_t h)
+{
+  smx_host_priv_t host = (smx_host_priv_t) h;
+
+  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;
+    }
+    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);
+}
+
 /**
  * \brief Internal function to destroy a SIMIX host.
  *
 /**
  * \brief Internal function to destroy a SIMIX host.
  *
index 6e075a9..b25104b 100644 (file)
 #define SIMCALL_LIST1(ACTION, sep) \
 ACTION(SIMCALL_HOST_GET_BY_NAME, host_get_by_name, WITH_ANSWER, TSPEC(result, smx_host_t), TSTRING(name)) sep \
 ACTION(SIMCALL_HOST_GET_NAME, host_get_name, WITH_ANSWER, TSTRING(result), TSPEC(host, smx_host_t)) sep \
 #define SIMCALL_LIST1(ACTION, sep) \
 ACTION(SIMCALL_HOST_GET_BY_NAME, host_get_by_name, WITH_ANSWER, TSPEC(result, smx_host_t), TSTRING(name)) sep \
 ACTION(SIMCALL_HOST_GET_NAME, host_get_name, WITH_ANSWER, TSTRING(result), TSPEC(host, smx_host_t)) sep \
+ACTION(SIMCALL_HOST_ON, host_on, WITH_ANSWER, TVOID(result), TSPEC(host, smx_host_t)) sep \
+ACTION(SIMCALL_HOST_OFF, host_off, WITH_ANSWER, TVOID(result), TSPEC(host, smx_host_t)) sep \
 ACTION(SIMCALL_HOST_GET_PROPERTIES, host_get_properties, WITH_ANSWER, TSPEC(result, xbt_dict_t), TSPEC(host, smx_host_t)) sep \
 ACTION(SIMCALL_HOST_GET_SPEED, host_get_speed, WITH_ANSWER, TDOUBLE(result), TSPEC(host, smx_host_t)) sep \
 ACTION(SIMCALL_HOST_GET_AVAILABLE_SPEED, host_get_available_speed, WITH_ANSWER, TDOUBLE(result), TSPEC(host, smx_host_t)) sep \
 ACTION(SIMCALL_HOST_GET_PROPERTIES, host_get_properties, WITH_ANSWER, TSPEC(result, xbt_dict_t), TSPEC(host, smx_host_t)) sep \
 ACTION(SIMCALL_HOST_GET_SPEED, host_get_speed, WITH_ANSWER, TDOUBLE(result), TSPEC(host, smx_host_t)) sep \
 ACTION(SIMCALL_HOST_GET_AVAILABLE_SPEED, host_get_available_speed, WITH_ANSWER, TDOUBLE(result), TSPEC(host, smx_host_t)) sep \
index 2b09caa..6103afb 100644 (file)
@@ -44,6 +44,28 @@ const char* simcall_host_get_name(smx_host_t host)
   return simcall_BODY_host_get_name(host);
 }
 
   return simcall_BODY_host_get_name(host);
 }
 
+/**
+ * \ingroup simix_host_management
+ * \brief Start the host if it is off
+ *
+ * \param host A SIMIX host
+ */
+void simcall_host_on(smx_host_t host)
+{
+  simcall_BODY_host_on(host);
+}
+
+/**
+ * \ingroup simix_host_management
+ * \brief Stop the host if it is on
+ *
+ * \param host A SIMIX host
+ */
+void simcall_host_off(smx_host_t host)
+{
+  simcall_BODY_host_off(host);
+}
+
 /**
  * \ingroup simix_host_management
  * \brief Returns a dict of the properties assigned to a host.
 /**
  * \ingroup simix_host_management
  * \brief Returns a dict of the properties assigned to a host.
index d85dc73..f6c48fc 100644 (file)
@@ -294,6 +294,11 @@ static e_surf_resource_state_t cpu_get_state(void *cpu)
   return ((cpu_Cas01_t)surf_cpu_resource_priv(cpu))->state_current;
 }
 
   return ((cpu_Cas01_t)surf_cpu_resource_priv(cpu))->state_current;
 }
 
+static void cpu_set_state(void *cpu, e_surf_resource_state_t state)
+{
+  ((cpu_Cas01_t)surf_cpu_resource_priv(cpu))->state_current = state;
+}
+
 static double cpu_get_speed(void *cpu, double load)
 {
   return load * ((cpu_Cas01_t)surf_cpu_resource_priv(cpu))->power_peak;
 static double cpu_get_speed(void *cpu, double load)
 {
   return load * ((cpu_Cas01_t)surf_cpu_resource_priv(cpu))->power_peak;
@@ -391,6 +396,7 @@ static surf_model_t surf_cpu_model_init_cas01(void)
   cpu_model->extension.cpu.sleep = cpu_action_sleep;
 
   cpu_model->extension.cpu.get_state = cpu_get_state;
   cpu_model->extension.cpu.sleep = cpu_action_sleep;
 
   cpu_model->extension.cpu.get_state = cpu_get_state;
+  cpu_model->extension.cpu.set_state = cpu_set_state;
   cpu_model->extension.cpu.get_speed = cpu_get_speed;
   cpu_model->extension.cpu.get_available_speed =
       cpu_get_available_speed;
   cpu_model->extension.cpu.get_speed = cpu_get_speed;
   cpu_model->extension.cpu.get_available_speed =
       cpu_get_available_speed;
index 01ba42f..8ba0f40 100644 (file)
@@ -705,6 +705,11 @@ static e_surf_resource_state_t cpu_ti_get_state(void *cpu)
   return ((cpu_ti_t)surf_cpu_resource_priv(cpu))->state_current;
 }
 
   return ((cpu_ti_t)surf_cpu_resource_priv(cpu))->state_current;
 }
 
+static void cpu_ti_set_state(void *cpu, e_surf_resource_state_t state)
+{
+  ((cpu_ti_t)surf_cpu_resource_priv(cpu))->state_current = state;
+}
+
 static double cpu_ti_get_speed(void *cpu, double load)
 {
   return load * ((cpu_ti_t)surf_cpu_resource_priv(cpu))->power_peak;
 static double cpu_ti_get_speed(void *cpu, double load)
 {
   return load * ((cpu_ti_t)surf_cpu_resource_priv(cpu))->power_peak;
@@ -809,6 +814,7 @@ static surf_model_t surf_cpu_ti_model_init_internal(void)
   cpu_model->extension.cpu.sleep = cpu_ti_action_sleep;
 
   cpu_model->extension.cpu.get_state = cpu_ti_get_state;
   cpu_model->extension.cpu.sleep = cpu_ti_action_sleep;
 
   cpu_model->extension.cpu.get_state = cpu_ti_get_state;
+  cpu_model->extension.cpu.set_state = cpu_ti_set_state;
   cpu_model->extension.cpu.get_speed = cpu_ti_get_speed;
   cpu_model->extension.cpu.get_available_speed =
       cpu_ti_get_available_speed;
   cpu_model->extension.cpu.get_speed = cpu_ti_get_speed;
   cpu_model->extension.cpu.get_available_speed =
       cpu_ti_get_available_speed;
index 1748f2b..5e2271c 100644 (file)
@@ -332,6 +332,12 @@ e_surf_resource_state_t ws_get_state(void *workstation)
   return cpu->model->extension.cpu.get_state(workstation);
 }
 
   return cpu->model->extension.cpu.get_state(workstation);
 }
 
+void ws_set_state(void *workstation, e_surf_resource_state_t state)
+{
+  surf_resource_t cpu = ((surf_resource_t) surf_cpu_resource_priv(workstation));
+  cpu->model->extension.cpu.set_state(workstation, state);
+}
+
 double ws_get_speed(void *workstation, double load)
 {
   surf_resource_t cpu = ((surf_resource_t) surf_cpu_resource_priv(workstation));
 double ws_get_speed(void *workstation, double load)
 {
   surf_resource_t cpu = ((surf_resource_t) surf_cpu_resource_priv(workstation));
@@ -565,6 +571,7 @@ static void surf_workstation_model_init_internal(void)
   model->extension.workstation.execute   = ws_execute;
   model->extension.workstation.sleep     = ws_action_sleep;
   model->extension.workstation.get_state = ws_get_state;
   model->extension.workstation.execute   = ws_execute;
   model->extension.workstation.sleep     = ws_action_sleep;
   model->extension.workstation.get_state = ws_get_state;
+  model->extension.workstation.set_state = ws_set_state;
   model->extension.workstation.get_speed = ws_get_speed;
   model->extension.workstation.get_available_speed = ws_get_available_speed;
 
   model->extension.workstation.get_speed = ws_get_speed;
   model->extension.workstation.get_available_speed = ws_get_available_speed;