From aef8ad40dbb075883c0b147319cd73ed813f8cb9 Mon Sep 17 00:00:00 2001 From: mquinson Date: Mon, 13 Jul 2009 18:03:42 +0000 Subject: [PATCH] simdata cleanup from smx_action_t. Now all SIMIX's data structures [Cristian] git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@6492 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- src/gras/Virtu/sg_process.c | 13 ++----- src/include/simix/datatypes.h | 12 ------ src/include/simix/simix.h | 5 ++- src/msg/global.c | 16 ++------ src/msg/mailbox.h | 3 +- src/simix/private.h | 14 ++++--- src/simix/smx_action.c | 71 +++++++++++++++++------------------ src/simix/smx_process.c | 6 +-- src/smpi/smpi_global.c | 13 ++----- 9 files changed, 64 insertions(+), 89 deletions(-) diff --git a/src/gras/Virtu/sg_process.c b/src/gras/Virtu/sg_process.c index 975c627ffd..c001c00fde 100644 --- a/src/gras/Virtu/sg_process.c +++ b/src/gras/Virtu/sg_process.c @@ -237,7 +237,6 @@ void gras_function_register(const char *name, xbt_main_func_t code) void gras_main() { - smx_cond_t cond = NULL; smx_action_t action; xbt_fifo_t actions_done = xbt_fifo_new(); xbt_fifo_t actions_failed = xbt_fifo_new(); @@ -249,19 +248,15 @@ void gras_main() while (SIMIX_solve(actions_done, actions_failed) != -1.0) { while ((action = xbt_fifo_pop(actions_failed))) { - DEBUG1("** %s failed **", action->name); - while ((cond = xbt_fifo_pop(action->cond_list))) { - SIMIX_cond_broadcast(cond); - } + DEBUG1("** %s failed **", SIMIX_action_get_name(action)); + SIMIX_action_signal_all (action); /* action finished, destroy it */ // SIMIX_action_destroy(action); } while ((action = xbt_fifo_pop(actions_done))) { - DEBUG1("** %s done **", action->name); - while ((cond = xbt_fifo_pop(action->cond_list))) { - SIMIX_cond_broadcast(cond); - } + DEBUG1("** %s done **", SIMIX_action_get_name(action)); + SIMIX_action_signal_all (action); /* action finished, destroy it */ //SIMIX_action_destroy(action); } diff --git a/src/include/simix/datatypes.h b/src/include/simix/datatypes.h index f1eb1939e5..28e1be2241 100644 --- a/src/include/simix/datatypes.h +++ b/src/include/simix/datatypes.h @@ -39,18 +39,6 @@ SG_BEGIN_DECL() /********************************** Action *************************************/ - typedef struct s_smx_simdata_action *smx_simdata_action_t; -/** @brief Action datatype - @ingroup m_datatypes_management_details */ - typedef struct s_smx_action { - char *name; /**< @brief action name if any */ - smx_simdata_action_t simdata; - /**< @brief simulator data */ - xbt_fifo_t cond_list; /*< conditional variables that must be signaled when the action finish. */ - void *data; /**< @brief user data */ - int refcount; /**< @brief reference counter */ - } s_smx_action_t; - typedef struct s_smx_action *smx_action_t; diff --git a/src/include/simix/simix.h b/src/include/simix/simix.h index a9c0780686..5226ceeb65 100644 --- a/src/include/simix/simix.h +++ b/src/include/simix/simix.h @@ -175,7 +175,10 @@ XBT_PUBLIC(smx_action_t) SIMIX_action_parallel_execute(char *name, double amount, double rate); - void SIMIX_display_process_status(void); +XBT_PUBLIC(char *) SIMIX_action_get_name(smx_action_t action); +XBT_PUBLIC(void) SIMIX_action_signal_all(smx_action_t action); + +void SIMIX_display_process_status(void); SG_END_DECL() diff --git a/src/msg/global.c b/src/msg/global.c index d5de0ca9d6..431996b89d 100644 --- a/src/msg/global.c +++ b/src/msg/global.c @@ -146,7 +146,6 @@ int MSG_get_channel_number(void) */ MSG_error_t MSG_main(void) { - smx_cond_t cond = NULL; smx_action_t smx_action; xbt_fifo_t actions_done = xbt_fifo_new(); xbt_fifo_t actions_failed = xbt_fifo_new(); @@ -162,20 +161,13 @@ MSG_error_t MSG_main(void) while (SIMIX_solve(actions_done, actions_failed) != -1.0) { while ((smx_action = xbt_fifo_pop(actions_failed))) { - - - DEBUG1("** %s failed **", smx_action->name); - while ((cond = xbt_fifo_pop(smx_action->cond_list))) { - SIMIX_cond_broadcast(cond); - } + DEBUG1("** %s failed **", SIMIX_action_get_name(smx_action)); + SIMIX_action_signal_all(smx_action); } while ((smx_action = xbt_fifo_pop(actions_done))) { - - DEBUG1("** %s done **", smx_action->name); - while ((cond = xbt_fifo_pop(smx_action->cond_list))) { - SIMIX_cond_broadcast(cond); - } + DEBUG1("** %s done **", SIMIX_action_get_name(smx_action)); + SIMIX_action_signal_all(smx_action); } } xbt_fifo_free(actions_failed); diff --git a/src/msg/mailbox.h b/src/msg/mailbox.h index e7c00fd205..c742cc2190 100644 --- a/src/msg/mailbox.h +++ b/src/msg/mailbox.h @@ -2,9 +2,10 @@ #define SMX_MAILBOX_H #include "xbt/fifo.h" -#include "simix/private.h" +#include "simix/simix.h" #include "msg/datatypes.h" + SG_BEGIN_DECL() #define MAX_ALIAS_NAME ((size_t)260) /* diff --git a/src/simix/private.h b/src/simix/private.h index bcf61c9dca..bb65a42de3 100644 --- a/src/simix/private.h +++ b/src/simix/private.h @@ -108,14 +108,16 @@ typedef struct s_smx_cond { /********************************* Action **************************************/ -typedef struct s_smx_simdata_action { +/** @brief Action datatype + @ingroup m_datatypes_management_details */ +typedef struct s_smx_action { + char *name; /**< @brief action name if any */ + xbt_fifo_t cond_list; /*< conditional variables that must be signaled when the action finish. */ + void *data; /**< @brief user data */ + int refcount; /**< @brief reference counter */ surf_action_t surf_action; /* SURF modeling of computation */ - smx_host_t source; - -} s_smx_simdata_action_t; - - +} s_smx_action_t; /******************************* Other **********************************/ diff --git a/src/simix/smx_action.c b/src/simix/smx_action.c index b5a4cd251d..39e981c483 100644 --- a/src/simix/smx_action.c +++ b/src/simix/smx_action.c @@ -29,7 +29,6 @@ smx_action_t SIMIX_action_communicate(smx_host_t sender, double size, double rate) { smx_action_t act; - smx_simdata_action_t simdata; /* check if the host is active */ if (surf_workstation_model->extension. @@ -45,19 +44,17 @@ smx_action_t SIMIX_action_communicate(smx_host_t sender, /* alloc structures */ act = xbt_new0(s_smx_action_t, 1); - act->simdata = xbt_new0(s_smx_simdata_action_t, 1); - simdata = act->simdata; act->cond_list = xbt_fifo_new(); /* initialize them */ act->name = xbt_strdup(name); - simdata->source = sender; + act->source = sender; - simdata->surf_action = + act->surf_action = surf_workstation_model->extension.workstation. communicate(sender->host, receiver->host, size, rate); - surf_workstation_model->action_data_set(simdata->surf_action, act); + surf_workstation_model->action_data_set(act->surf_action, act); DEBUG1("Create communicate action %p", act); return act; @@ -75,7 +72,6 @@ smx_action_t SIMIX_action_execute(smx_host_t host, const char *name, double amount) { smx_action_t act; - smx_simdata_action_t simdata; /* check if the host is active */ if (surf_workstation_model->extension. @@ -86,20 +82,18 @@ smx_action_t SIMIX_action_execute(smx_host_t host, const char *name, /* alloc structures */ act = xbt_new0(s_smx_action_t, 1); - act->simdata = xbt_new0(s_smx_simdata_action_t, 1); - simdata = act->simdata; act->cond_list = xbt_fifo_new(); /* initialize them */ - simdata->source = host; + act->source = host; act->name = xbt_strdup(name); /* set communication */ - simdata->surf_action = + act->surf_action = surf_workstation_model->extension.workstation.execute(host->host, amount); - surf_workstation_model->action_data_set(simdata->surf_action, act); + surf_workstation_model->action_data_set(act->surf_action, act); DEBUG1("Create execute action %p", act); return act; @@ -115,7 +109,6 @@ smx_action_t SIMIX_action_execute(smx_host_t host, const char *name, smx_action_t SIMIX_action_sleep(smx_host_t host, double duration) { char name[] = "sleep"; - smx_simdata_action_t simdata; smx_action_t act; /* check if the host is active */ @@ -127,19 +120,17 @@ smx_action_t SIMIX_action_sleep(smx_host_t host, double duration) /* alloc structures */ act = xbt_new0(s_smx_action_t, 1); - act->simdata = xbt_new0(s_smx_simdata_action_t, 1); - simdata = act->simdata; act->cond_list = xbt_fifo_new(); /* initialize them */ - simdata->source = host; + act->source = host; act->name = xbt_strdup(name); - simdata->surf_action = + act->surf_action = surf_workstation_model->extension.workstation.sleep(host->host, duration); - surf_workstation_model->action_data_set(simdata->surf_action, act); + surf_workstation_model->action_data_set(act->surf_action, act); DEBUG1("Create sleep action %p", act); return act; @@ -156,8 +147,8 @@ void SIMIX_action_cancel(smx_action_t action) xbt_assert0((action != NULL), "Invalid parameter"); DEBUG1("Cancel action %p", action); - if (action->simdata->surf_action) { - surf_workstation_model->action_cancel(action->simdata->surf_action); + if (action->surf_action) { + surf_workstation_model->action_cancel(action->surf_action); } return; } @@ -171,10 +162,9 @@ void SIMIX_action_cancel(smx_action_t action) */ void SIMIX_action_set_priority(smx_action_t action, double priority) { - xbt_assert0((action != NULL) - && (action->simdata != NULL), "Invalid parameter"); + xbt_assert0((action != NULL), "Invalid parameter"); - surf_workstation_model->set_priority(action->simdata->surf_action, + surf_workstation_model->set_priority(action->surf_action, priority); return; } @@ -204,11 +194,9 @@ int SIMIX_action_destroy(smx_action_t action) xbt_fifo_free(action->cond_list); - if (action->simdata->surf_action) - action->simdata->surf_action->model_type->action_unref(action-> - simdata->surf_action); + if (action->surf_action) + action->surf_action->model_type->action_unref(action->surf_action); - xbt_free(action->simdata); xbt_free(action); return 1; } @@ -270,8 +258,7 @@ void SIMIX_register_action_to_condition(smx_action_t action, smx_cond_t cond) * \param action SIMIX action * \param cond SIMIX cond */ -void SIMIX_unregister_action_to_condition(smx_action_t action, - smx_cond_t cond) +void SIMIX_unregister_action_to_condition(smx_action_t action, smx_cond_t cond) { xbt_assert0((action != NULL) && (cond != NULL), "Invalid parameters"); @@ -292,7 +279,7 @@ void SIMIX_unregister_action_to_condition(smx_action_t action, double SIMIX_action_get_remains(smx_action_t action) { xbt_assert0((action != NULL), "Invalid parameter"); - return action->simdata->surf_action->remains; + return action->surf_action->remains; } smx_action_t SIMIX_action_parallel_execute(char *name, int host_nb, @@ -302,14 +289,11 @@ smx_action_t SIMIX_action_parallel_execute(char *name, int host_nb, double amount, double rate) { void **workstation_list = NULL; - smx_simdata_action_t simdata; smx_action_t act; int i; /* alloc structures */ act = xbt_new0(s_smx_action_t, 1); - act->simdata = xbt_new0(s_smx_simdata_action_t, 1); - simdata = act->simdata; act->cond_list = xbt_fifo_new(); /* initialize them */ @@ -321,7 +305,7 @@ smx_action_t SIMIX_action_parallel_execute(char *name, int host_nb, for (i = 0; i < host_nb; i++) workstation_list[i] = host_list[i]->host; - simdata->surf_action = + act->surf_action = surf_workstation_model->extension. workstation.execute_parallel_task(host_nb, workstation_list, computation_amount, @@ -335,9 +319,8 @@ smx_action_t SIMIX_action_parallel_execute(char *name, int host_nb, e_surf_action_state_t SIMIX_action_get_state(smx_action_t action) { xbt_assert0((action != NULL), "Invalid parameter"); - return surf_workstation_model->action_state_get(action->simdata-> + return surf_workstation_model->action_state_get(action-> surf_action); - } void __SIMIX_cond_display_actions(smx_cond_t cond) @@ -359,3 +342,19 @@ void __SIMIX_action_display_conditions(smx_action_t action) xbt_fifo_foreach(action->cond_list, item, cond, smx_cond_t) DEBUG1("\t %p", cond); } + +char * SIMIX_action_get_name(smx_action_t action) +{ + xbt_assert0((action != NULL), "Invalid parameter"); + return action->name; +} + +void SIMIX_action_signal_all(smx_action_t action) +{ + smx_cond_t cond; + + while((cond = xbt_fifo_pop(action->cond_list))) + SIMIX_cond_broadcast(cond); + + return; +} \ No newline at end of file diff --git a/src/simix/smx_process.c b/src/simix/smx_process.c index d7a9f44986..cd0487e7db 100644 --- a/src/simix/smx_process.c +++ b/src/simix/smx_process.c @@ -307,7 +307,7 @@ void SIMIX_process_suspend(smx_process_t process) process->suspended = 1; c = process->cond; xbt_fifo_foreach(c->actions, i, act, smx_action_t) { - surf_workstation_model->suspend(act->surf_action); + surf_workstation_model->suspend(act->surf_action); } } else { process->suspended = 1; @@ -321,7 +321,7 @@ void SIMIX_process_suspend(smx_process_t process) cond = SIMIX_cond_init(); dummy = SIMIX_action_execute(SIMIX_process_get_host(process), name, 0); - surf_workstation_model->suspend(dummy->simdata->surf_action); + surf_workstation_model->suspend(dummy->surf_action); SIMIX_register_action_to_condition(dummy, cond); __SIMIX_cond_wait(cond); SIMIX_unregister_action_to_condition(dummy, cond); @@ -358,7 +358,7 @@ void SIMIX_process_resume(smx_process_t process) process->suspended = 0; c = process->cond; xbt_fifo_foreach(c->actions, i, act, smx_action_t) { - surf_workstation_model->resume(act->simdata->surf_action); + surf_workstation_model->resume(act->surf_action); } SIMIX_cond_signal(c); return; diff --git a/src/smpi/smpi_global.c b/src/smpi/smpi_global.c index 62f7e7d0d7..c8550fea16 100644 --- a/src/smpi/smpi_global.c +++ b/src/smpi/smpi_global.c @@ -291,7 +291,6 @@ static void smpi_cfg_cb_host_speed(const char *name, int pos) int smpi_run_simulation(int *argc, char **argv) { - smx_cond_t cond = NULL; smx_action_t action = NULL; xbt_fifo_t actions_failed = xbt_fifo_new(); @@ -329,16 +328,12 @@ int smpi_run_simulation(int *argc, char **argv) while (SIMIX_solve(actions_done, actions_failed) != -1.0) { while ((action = xbt_fifo_pop(actions_failed))) { - DEBUG1("** %s failed **", action->name); - while ((cond = xbt_fifo_pop(action->cond_list))) { - SIMIX_cond_broadcast(cond); - } + DEBUG1("** %s failed **", SIMIX_action_get_name(action)); + SIMIX_action_signal_all(action); } while ((action = xbt_fifo_pop(actions_done))) { - DEBUG1("** %s done **", action->name); - while ((cond = xbt_fifo_pop(action->cond_list))) { - SIMIX_cond_broadcast(cond); - } + DEBUG1("** %s done **", SIMIX_action_get_name(action)); + SIMIX_action_signal_all(action); } } -- 2.20.1