From: Paul Bédaride Date: Mon, 17 Jun 2013 15:43:08 +0000 (+0200) Subject: Add MSG_host_on and MSG_host_off X-Git-Tag: v3_11_beta~297^2^2~28^2~2 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/054ee8581cc1b4c22fcf66c5b3f0c6e7267a3e65 Add MSG_host_on and MSG_host_off --- diff --git a/include/msg/msg.h b/include/msg/msg.h index 154fc39cc3..89d70d6627 100644 --- a/include/msg/msg.h +++ b/include/msg/msg.h @@ -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(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 */ diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index 0ce4624690..68597e2b6f 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -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); + 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); @@ -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 */ + 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 */ diff --git a/src/msg/msg_host.c b/src/msg/msg_host.c index 4cced2cf02..cd959e8d9d 100644 --- a/src/msg/msg_host.c +++ b/src/msg/msg_host.c @@ -116,6 +116,23 @@ msg_host_t MSG_host_self(void) 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) */ diff --git a/src/simix/smx_host.c b/src/simix/smx_host.c index 86eef31829..c94a0fbd79 100644 --- a/src/simix/smx_host.c +++ b/src/simix/smx_host.c @@ -38,6 +38,62 @@ smx_host_t SIMIX_host_create(const char *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. * diff --git a/src/simix/smx_smurf_private.h b/src/simix/smx_smurf_private.h index 6e075a9b91..b25104bb62 100644 --- a/src/simix/smx_smurf_private.h +++ b/src/simix/smx_smurf_private.h @@ -261,6 +261,8 @@ #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 \ diff --git a/src/simix/smx_user.c b/src/simix/smx_user.c index 2b09caa21e..6103afb927 100644 --- a/src/simix/smx_user.c +++ b/src/simix/smx_user.c @@ -44,6 +44,28 @@ const char* simcall_host_get_name(smx_host_t 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. diff --git a/src/surf/cpu_cas01.c b/src/surf/cpu_cas01.c index d85dc7374a..f6c48fc17b 100644 --- a/src/surf/cpu_cas01.c +++ b/src/surf/cpu_cas01.c @@ -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; } +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; @@ -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.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; diff --git a/src/surf/cpu_ti.c b/src/surf/cpu_ti.c index 01ba42f883..8ba0f400c5 100644 --- a/src/surf/cpu_ti.c +++ b/src/surf/cpu_ti.c @@ -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; } +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; @@ -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.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; diff --git a/src/surf/workstation.c b/src/surf/workstation.c index 1748f2b42f..5e2271c018 100644 --- a/src/surf/workstation.c +++ b/src/surf/workstation.c @@ -332,6 +332,12 @@ e_surf_resource_state_t ws_get_state(void *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)); @@ -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.set_state = ws_set_state; model->extension.workstation.get_speed = ws_get_speed; model->extension.workstation.get_available_speed = ws_get_available_speed;