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 */
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);
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 */
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)
*/
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.
*
#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 \
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.
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;
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;
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;
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;
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));
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;