From 71ea76af2f6b151aaf1dc69eddee3cd47bafa5f0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20B=C3=A9daride?= Date: Wed, 26 Jun 2013 17:17:08 +0200 Subject: [PATCH] Fix problems on host on/off --- include/simgrid/simix.h | 2 +- src/bindings/java/jmsg_host.c | 13 ++++ src/bindings/java/jmsg_host.h | 18 +++++ src/bindings/java/org/simgrid/msg/Host.java | 12 ++++ src/msg/msg_host.c | 2 +- src/simix/smx_deployment.c | 19 ++++- src/simix/smx_host.c | 79 ++++++++++++++------- src/simix/smx_host_private.h | 4 +- src/simix/smx_smurf.c | 2 + 9 files changed, 121 insertions(+), 30 deletions(-) diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index 8254d46ca3..301adeded9 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -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(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); diff --git a/src/bindings/java/jmsg_host.c b/src/bindings/java/jmsg_host.c index b32b9b5d7d..07c908c25c 100644 --- a/src/bindings/java/jmsg_host.c +++ b/src/bindings/java/jmsg_host.c @@ -154,6 +154,19 @@ Java_org_simgrid_msg_Host_currentHost(JNIEnv * env, jclass cls) { 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(); diff --git a/src/bindings/java/jmsg_host.h b/src/bindings/java/jmsg_host.h index 401d53b9c3..e132ce1bb6 100644 --- a/src/bindings/java/jmsg_host.h +++ b/src/bindings/java/jmsg_host.h @@ -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); +/** + * 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 diff --git a/src/bindings/java/org/simgrid/msg/Host.java b/src/bindings/java/org/simgrid/msg/Host.java index 3a4c666516..d8c46f35d0 100644 --- a/src/bindings/java/org/simgrid/msg/Host.java +++ b/src/bindings/java/org/simgrid/msg/Host.java @@ -128,6 +128,7 @@ public class Host { public String getName() { return name; } + /** * Sets the data of the host. * @param data @@ -153,6 +154,17 @@ public class Host { 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. diff --git a/src/msg/msg_host.c b/src/msg/msg_host.c index 3a64215081..ccfc8805e4 100644 --- a/src/msg/msg_host.c +++ b/src/msg/msg_host.c @@ -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) -{ +{ simcall_host_off(host); } diff --git a/src/simix/smx_deployment.c b/src/simix/smx_deployment.c index 5b34af3432..72072a3e40 100644 --- a/src/simix/smx_deployment.c +++ b/src/simix/smx_deployment.c @@ -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; + 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; iargc; 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]; @@ -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); - + /* 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; diff --git a/src/simix/smx_host.c b/src/simix/smx_host.c index 08ecdf3cd4..cf11967d1a 100644 --- a/src/simix/smx_host.c +++ b/src/simix/smx_host.c @@ -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) { - 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"); - - 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) { - SIMIX_host_off(h); + SIMIX_host_off(h, simcall->issuer); } /** * \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"); - - /* 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); + xbt_dynar_free(&host->boot_processes); 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; } -void _SIMIX_host_free_process_arg(void *); + void _SIMIX_host_free_process_arg(void *data) { smx_process_arg_t arg = *(void**)data; diff --git a/src/simix/smx_host_private.h b/src/simix/smx_host_private.h index 4ed05a1918..7fd525e426 100644 --- a/src/simix/smx_host_private.h +++ b/src/simix/smx_host_private.h @@ -14,6 +14,7 @@ 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; @@ -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); } +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); @@ -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); -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, diff --git a/src/simix/smx_smurf.c b/src/simix/smx_smurf.c index aec3439312..a5a3e27681 100644 --- a/src/simix/smx_smurf.c +++ b/src/simix/smx_smurf.c @@ -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; + if (simcall->issuer->context->iwannadie && simcall->call != SIMCALL_PROCESS_CLEANUP) + return; switch (simcall->call) { SIMCALL_LIST(SIMCALL_CASE, SIMCALL_SEP_NOTHING) case NUM_SIMCALLS:; -- 2.20.1