From: donassbr Date: Thu, 12 Apr 2007 15:23:43 +0000 (+0000) Subject: Functions added. X-Git-Tag: v3.3~1958 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/aa3325d81bd93ec9295958060072be318bd2fc93 Functions added. Bugs corrected. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@3402 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/src/include/simix/simix.h b/src/include/simix/simix.h index 83c9f33bab..08fbfcfed2 100644 --- a/src/include/simix/simix.h +++ b/src/include/simix/simix.h @@ -12,6 +12,7 @@ #include "xbt/misc.h" #include "xbt/fifo.h" #include "simix/datatypes.h" +#include "surf/surf.h" SG_BEGIN_DECL() @@ -103,6 +104,7 @@ XBT_PUBLIC(void) SIMIX_cond_wait_timeout(smx_cond_t cond,smx_mutex_t mutex, doub XBT_PUBLIC(void) SIMIX_cond_broadcast(smx_cond_t cond); XBT_PUBLIC(void) SIMIX_cond_destroy(smx_cond_t cond); XBT_PUBLIC(void) SIMIX_register_condition_to_action(smx_action_t action, smx_cond_t cond); +XBT_PUBLIC(xbt_fifo_t) SIMIX_cond_get_actions(smx_cond_t cond); /************************** Action handling ************************************/ @@ -116,6 +118,8 @@ XBT_PUBLIC(void) SIMIX_action_destroy(smx_action_t action); XBT_PUBLIC(void) SIMIX_register_action_to_condition(smx_action_t action, smx_cond_t cond); XBT_PUBLIC(double) SIMIX_action_get_remains(smx_action_t action); +XBT_PUBLIC(e_surf_action_state_t) SIMIX_action_get_state(smx_action_t action); + /*Not implemented yet */ XBT_PUBLIC(smx_action_t) SIMIX_action_parallel_execute(char * name, int workstation_nb, diff --git a/src/msg_simix/msg_simix_global.c b/src/msg_simix/msg_simix_global.c index 0296d16eed..837bef40b7 100644 --- a/src/msg_simix/msg_simix_global.c +++ b/src/msg_simix/msg_simix_global.c @@ -143,7 +143,7 @@ MSG_error_t MSG_main(void) SIMIX_cond_broadcast(cond); } /* action finished, destroy it */ - SIMIX_action_destroy(smx_action); + // SIMIX_action_destroy(smx_action); } while ( (smx_action = xbt_fifo_pop(actions_done)) ) { @@ -153,7 +153,7 @@ MSG_error_t MSG_main(void) SIMIX_cond_broadcast(cond); } /* action finished, destroy it */ - SIMIX_action_destroy(smx_action); + //SIMIX_action_destroy(smx_action); } } xbt_fifo_free(actions_failed); diff --git a/src/msg_simix/msg_simix_gos.c b/src/msg_simix/msg_simix_gos.c index f34fd64118..8d3a00eb5d 100644 --- a/src/msg_simix/msg_simix_gos.c +++ b/src/msg_simix/msg_simix_gos.c @@ -58,6 +58,9 @@ static MSG_error_t __MSG_task_get_with_time_out_from_host(m_task_t * task, if(max_duration>0) { if(!first_time) { + SIMIX_mutex_unlock(h->simdata->mutex); + h_simdata->sleeping[channel] = NULL; + SIMIX_cond_destroy(cond); MSG_RETURN(MSG_TRANSFER_FAILURE); } } @@ -70,6 +73,9 @@ static MSG_error_t __MSG_task_get_with_time_out_from_host(m_task_t * task, } else SIMIX_cond_wait(h_simdata->sleeping[channel],h->simdata->mutex); + if(SIMIX_host_get_state(h_simdata->host)==0) + MSG_RETURN(MSG_HOST_FAILURE); + first_time = 0; } SIMIX_mutex_unlock(h->simdata->mutex); @@ -108,13 +114,32 @@ static MSG_error_t __MSG_task_get_with_time_out_from_host(m_task_t * task, if (t->simdata->sender) { t->simdata->sender->simdata->waiting_task = NULL; /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */ - t->simdata->comm = NULL; - t->simdata->compute = NULL; + //t->simdata->comm = NULL; + //t->simdata->compute = NULL; } /* for this process, don't need to change in get function*/ t->simdata->receiver = NULL; SIMIX_mutex_unlock(t_simdata->mutex); - MSG_RETURN(MSG_OK); + + + DEBUG0("GET FREE ACTION"); + if(SIMIX_action_get_state(t_simdata->comm) == SURF_ACTION_DONE) { + //t_simdata->comm = NULL; + SIMIX_action_destroy(t_simdata->comm); + t_simdata->comm = NULL; + MSG_RETURN(MSG_OK); + } else if (SIMIX_host_get_state(h_simdata->host)==0) { + //t_simdata->comm = NULL; + SIMIX_action_destroy(t_simdata->comm); + t_simdata->comm = NULL; + MSG_RETURN(MSG_HOST_FAILURE); + } else { + //t_simdata->comm = NULL; + SIMIX_action_destroy(t_simdata->comm); + t_simdata->comm = NULL; + MSG_RETURN(MSG_TRANSFER_FAILURE); + } + } /** \ingroup msg_gos_functions @@ -416,10 +441,22 @@ MSG_error_t MSG_task_put_with_timeout(m_task_t task, m_host_t dest, process->simdata->waiting_task = task; if (max_duration >0) { SIMIX_cond_wait_timeout(task->simdata->cond,task->simdata->mutex,max_duration); + /* verify if the timeout happened and the communication didn't started yet */ + if (task->simdata->comm==NULL) { + task->simdata->using--; + process->simdata->waiting_task = NULL; + if (task->simdata->receiver) { + task->simdata->receiver->simdata->waiting_task = NULL; + } + task->simdata->sender = NULL; + SIMIX_mutex_unlock(task->simdata->mutex); + MSG_RETURN(MSG_TRANSFER_FAILURE); + } } else { SIMIX_cond_wait(task->simdata->cond,task->simdata->mutex); } + DEBUG1("Action terminated %s",task->name); task->simdata->using--; process->simdata->waiting_task = NULL; @@ -427,15 +464,19 @@ MSG_error_t MSG_task_put_with_timeout(m_task_t task, m_host_t dest, if (task->simdata->receiver) { task->simdata->receiver->simdata->waiting_task = NULL; /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */ - task->simdata->comm = NULL; - task->simdata->compute = NULL; + // task->simdata->comm = NULL; + //task->simdata->compute = NULL; } - /* for this process, don't need to change in get function*/ task->simdata->sender = NULL; SIMIX_mutex_unlock(task->simdata->mutex); - - MSG_RETURN(MSG_OK); + if(SIMIX_action_get_state(task->simdata->comm) == SURF_ACTION_DONE) { + MSG_RETURN(MSG_OK); + } else if (SIMIX_host_get_state(local_host->simdata->host)==0) { + MSG_RETURN(MSG_HOST_FAILURE); + } else { + MSG_RETURN(MSG_TRANSFER_FAILURE); + } } /** \ingroup msg_gos_functions @@ -518,13 +559,29 @@ MSG_error_t MSG_task_execute(m_task_t task) SIMIX_cond_wait(simdata->cond, simdata->mutex); self->simdata->waiting_task = NULL; - /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */ - simdata->comm = NULL; - simdata->compute = NULL; - SIMIX_mutex_unlock(simdata->mutex); simdata->using--; - MSG_RETURN(MSG_OK); + + if(SIMIX_action_get_state(task->simdata->compute) == SURF_ACTION_DONE) { + /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */ + SIMIX_action_destroy(task->simdata->compute); + simdata->computation_amount = 0.0; + simdata->comm = NULL; + simdata->compute = NULL; + MSG_RETURN(MSG_OK); + } else if (SIMIX_host_get_state(SIMIX_host_self())==0) { + /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */ + SIMIX_action_destroy(task->simdata->compute); + simdata->comm = NULL; + simdata->compute = NULL; + MSG_RETURN(MSG_HOST_FAILURE); + } else { + /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */ + SIMIX_action_destroy(task->simdata->compute); + simdata->comm = NULL; + simdata->compute = NULL; + MSG_RETURN(MSG_TASK_CANCELLED); + } } @@ -589,11 +646,6 @@ m_task_t MSG_parallel_task_create(const char *name, } -static void __MSG_parallel_task_execute(m_process_t process, m_task_t task) -{ - return; -} - MSG_error_t MSG_parallel_task_execute(m_task_t task) { simdata_task_t simdata = NULL; @@ -617,15 +669,31 @@ MSG_error_t MSG_parallel_task_execute(m_task_t task) SIMIX_cond_wait(simdata->cond, simdata->mutex); self->simdata->waiting_task = NULL; - /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */ - simdata->comm = NULL; - simdata->compute = NULL; SIMIX_mutex_unlock(simdata->mutex); simdata->using--; - MSG_RETURN(MSG_OK); - xbt_die("not implemented yet"); - return MSG_OK; + + if(SIMIX_action_get_state(task->simdata->compute) == SURF_ACTION_DONE) { + /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */ + SIMIX_action_destroy(task->simdata->compute); + simdata->computation_amount = 0.0; + simdata->comm = NULL; + simdata->compute = NULL; + MSG_RETURN(MSG_OK); + } else if (SIMIX_host_get_state(SIMIX_host_self())==0) { + /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */ + SIMIX_action_destroy(task->simdata->compute); + simdata->comm = NULL; + simdata->compute = NULL; + MSG_RETURN(MSG_HOST_FAILURE); + } else { + /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */ + SIMIX_action_destroy(task->simdata->compute); + simdata->comm = NULL; + simdata->compute = NULL; + MSG_RETURN(MSG_TASK_CANCELLED); + } + } @@ -659,6 +727,18 @@ MSG_error_t MSG_process_sleep(double nb_sec) SIMIX_cond_destroy(cond); SIMIX_mutex_destroy(mutex); + if(SIMIX_action_get_state(act_sleep) == SURF_ACTION_DONE) { + if(SIMIX_host_get_state(SIMIX_host_self()) == SURF_CPU_OFF) { + SIMIX_action_destroy(act_sleep); + MSG_RETURN(MSG_HOST_FAILURE); + } + } + else { + SIMIX_action_destroy(act_sleep); + MSG_RETURN(MSG_HOST_FAILURE); + } + + MSG_RETURN(MSG_OK); } diff --git a/src/msg_simix/msg_simix_private.h b/src/msg_simix/msg_simix_private.h index 897daf789c..4054b06142 100644 --- a/src/msg_simix/msg_simix_private.h +++ b/src/msg_simix/msg_simix_private.h @@ -11,6 +11,7 @@ #include #include "msg/msg.h" #include "simix/simix.h" +#include "surf/surf.h" #include "xbt/fifo.h" #include "xbt/dynar.h" #include "xbt/swag.h" diff --git a/src/simix/smx_action.c b/src/simix/smx_action.c index d20336abaa..8e7124ad06 100644 --- a/src/simix/smx_action.c +++ b/src/simix/smx_action.c @@ -225,3 +225,9 @@ smx_action_t SIMIX_action_parallel_execute(char *name, int workstation_nb, void return act; } +e_surf_action_state_t SIMIX_action_get_state(smx_action_t action) +{ + xbt_assert0((action != NULL), "Invalid parameter"); + return surf_workstation_resource->common_public->action_get_state(action->simdata->surf_action); + +} diff --git a/src/simix/smx_synchro.c b/src/simix/smx_synchro.c index f2feb6b61c..4e715105d5 100644 --- a/src/simix/smx_synchro.c +++ b/src/simix/smx_synchro.c @@ -199,6 +199,11 @@ void SIMIX_cond_wait(smx_cond_t cond,smx_mutex_t mutex) return; } +xbt_fifo_t SIMIX_cond_get_actions(smx_cond_t cond) +{ + xbt_assert0((cond != NULL), "Invalid parameters"); + return cond->actions; +} void __SIMIX_cond_wait(smx_cond_t cond) { @@ -238,8 +243,12 @@ void SIMIX_cond_wait_timeout(smx_cond_t cond,smx_mutex_t mutex, double max_durat act_sleep = SIMIX_action_sleep(SIMIX_host_self(), max_duration); SIMIX_register_action_to_condition(act_sleep,cond); SIMIX_register_condition_to_action(act_sleep,cond); + __SIMIX_cond_wait(cond); + xbt_fifo_remove(act_sleep->cond_list,cond); + SIMIX_action_destroy(act_sleep); } - __SIMIX_cond_wait(cond); + else + __SIMIX_cond_wait(cond); /* get the mutex again */ SIMIX_mutex_lock(cond->mutex);