From 7c8772e246f9958e172ada583011fcee1bf58a93 Mon Sep 17 00:00:00 2001 From: mquinson Date: Thu, 2 Jul 2009 08:00:07 +0000 Subject: [PATCH] implement a constructor for surf_action_t; draft a surf_action_maxmin_t for actions using maxmin git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@6439 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- ChangeLog | 4 ++++ src/include/surf/surf.h | 30 ++++++++++++++++++++-------- src/surf/cpu.c | 32 ++++-------------------------- src/surf/network.c | 19 +++--------------- src/surf/network_constant.c | 21 ++++---------------- src/surf/network_gtnets.c | 17 ++-------------- src/surf/surf_action.c | 34 ++++++++++++++++++++++++++++++++ src/surf/workstation_ptask_L07.c | 13 +----------- 8 files changed, 74 insertions(+), 96 deletions(-) diff --git a/ChangeLog b/ChangeLog index 78a962dbde..898566b0d8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -34,6 +34,10 @@ SimGrid (3.3.2-svn) unstable; urgency=low workstation_CLM03 don't need no properties (but I guess we can live with those few bytes wasted) + * Improve the action object model + - implement a constructor avoiding dupplicated code about field + initialization in generic_action part. + XBT: * Add xbt_set_get_by_name_or_null() [Silas De Munck] * Add xbt_graph_node_get_outedges() [Silas De Munck] diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index 2790d9bce6..ce16cd1cb0 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -16,10 +16,18 @@ #include "xbt/config.h" SG_BEGIN_DECL() +/* Actions and models are higly connected structures... */ + +/** \brief Model datatype + * \ingroup SURF_models + * + * Generic data structure for a model. The workstations, + * the CPUs and the network links are examples of models. + */ + typedef struct surf_model *surf_model_t; -/* Actions and models are higly connected structures... */ /** \brief Action datatype * \ingroup SURF_actions * @@ -31,15 +39,16 @@ SG_BEGIN_DECL() typedef struct surf_action *surf_action_t; /** @Brief Specify that we use that action */ XBT_PUBLIC(void) surf_action_ref(surf_action_t action); - - -/** \brief Model datatype - * \ingroup SURF_models +/** @brief Creates a new action. * - * Generic data structure for a model. The workstations, - * the CPUs and the network links are examples of models. + * @param size The size is the one of the subtype you want to create + * @param cost initial value + * @param model to which model we should attach this action + * @param failed whether we should start this action in failed mode */ - typedef struct surf_model *surf_model_t; +XBT_PUBLIC(void*) surf_action_new(size_t size,double cost,surf_model_t model, int failed); + + /** \brief Resource model description */ @@ -81,6 +90,11 @@ XBT_PUBLIC(int) find_model_description(s_surf_model_description_t * table, surf_model_t model_type; } s_surf_action_t; + typedef struct { + s_surf_action_t generic_action; + void *variable; /* of type lmm_variable_t, which is only visible by loading maxmin */ + int suspended; + } s_surf_action_maxmin_t,*surf_action_maxmin_t; /** \brief Action states * \ingroup SURF_actions * diff --git a/src/surf/cpu.c b/src/surf/cpu.c index ca63f90633..388e1c201f 100644 --- a/src/surf/cpu.c +++ b/src/surf/cpu.c @@ -7,11 +7,7 @@ #include "surf_private.h" -typedef struct surf_action_cpu_Cas01 { - s_surf_action_t generic_action; - lmm_variable_t variable; - int suspended; -} s_surf_action_cpu_Cas01_t, *surf_action_cpu_Cas01_t; +typedef s_surf_action_maxmin_t s_surf_action_cpu_Cas01_t, *surf_action_cpu_Cas01_t; typedef struct cpu_Cas01 { s_surf_resource_t generic_resource; @@ -189,10 +185,6 @@ static void update_actions_state(double now, double delta) surf_action_cpu_Cas01_t action = NULL; surf_action_cpu_Cas01_t next_action = NULL; xbt_swag_t running_actions = surf_cpu_model->states.running_action_set; - /* FIXME: UNUSED - xbt_swag_t failed_actions = - surf_cpu_model->states.failed_action_set; - */ xbt_swag_foreach_safe(action, next_action, running_actions) { double_update(&(action->generic_action.remains), @@ -258,28 +250,12 @@ static surf_action_t execute(void *cpu, double size) cpu_Cas01_t CPU = cpu; XBT_IN2("(%s,%g)", CPU->generic_resource.name, size); - action = xbt_new0(s_surf_action_cpu_Cas01_t, 1); - - action->generic_action.refcount = 1; - action->generic_action.cost = size; - action->generic_action.remains = size; - action->generic_action.priority = 1.0; - action->generic_action.max_duration = NO_MAX_DURATION; - action->generic_action.start = surf_get_clock(); - action->generic_action.finish = -1.0; - action->generic_action.model_type = surf_cpu_model; + action = surf_action_new(sizeof(s_surf_action_cpu_Cas01_t),size,surf_cpu_model, + CPU->state_current != SURF_CPU_ON); + action->suspended = 0; /* Should be useless because of the calloc but it seems to help valgrind... */ - if (CPU->state_current == SURF_CPU_ON) - action->generic_action.state_set = - surf_cpu_model->states.running_action_set; - else - action->generic_action.state_set = - surf_cpu_model->states.failed_action_set; - - xbt_swag_insert(action, action->generic_action.state_set); - action->variable = lmm_variable_new(cpu_maxmin_system, action, action->generic_action.priority, -1.0, 1); diff --git a/src/surf/network.c b/src/surf/network.c index d55e71b072..6a6984bebc 100644 --- a/src/surf/network.c +++ b/src/surf/network.c @@ -364,28 +364,15 @@ static surf_action_t communicate(const char *src_name, const char *dst_name,int "You're trying to send data from %s to %s but there is no connection between these two hosts.", src_name, dst_name); - action = xbt_new0(s_surf_action_network_CM02_t, 1); - - action->generic_action.refcount = 1; - action->generic_action.cost = size; - action->generic_action.remains = size; - action->generic_action.max_duration = NO_MAX_DURATION; - action->generic_action.start = surf_get_clock(); - action->generic_action.finish = -1.0; - action->generic_action.model_type = surf_network_model; - action->suspended = 0; /* Should be useless because of the - calloc but it seems to help valgrind... */ - action->generic_action.state_set = - surf_network_model->states.running_action_set; - link_CM02_t link; + int failed=0; xbt_dynar_foreach(route,i,link) { if (link->state_current == SURF_LINK_OFF) { - action->generic_action.state_set = - surf_network_model->states.failed_action_set; + failed = 1; break; } } + action = surf_action_new(sizeof(s_surf_action_network_CM02_t),size,surf_network_model,failed); xbt_swag_insert(action, action->generic_action.state_set); action->rate = rate; diff --git a/src/surf/network_constant.c b/src/surf/network_constant.c index 7ed8284b37..2b0b2edf62 100644 --- a/src/surf/network_constant.c +++ b/src/surf/network_constant.c @@ -107,8 +107,6 @@ static void update_actions_state(double now, double delta) surf_network_model->action_state_set((surf_action_t) action, SURF_ACTION_DONE); } } - - return; } static void update_resource_state(void *id, @@ -125,29 +123,18 @@ static surf_action_t communicate(const char *src_name,const char *dst_name,int s XBT_IN4("(%s,%s,%g,%g)", src_name, dst_name, size, rate); - action = xbt_new0(s_surf_action_network_Constant_t, 1); + action = surf_action_new(sizeof(s_surf_action_network_Constant_t),size,surf_network_model,0); - action->generic_action.refcount = 1; - action->generic_action.cost = size; - action->generic_action.remains = size; - action->generic_action.max_duration = NO_MAX_DURATION; - action->generic_action.start = surf_get_clock(); - action->generic_action.finish = -1.0; - action->generic_action.model_type = surf_network_model; action->suspended = 0; action->latency = random_generate(random_latency); action->lat_init = action->latency; - if (action->latency <= 0.0) + if (action->latency <= 0.0) { action->generic_action.state_set = surf_network_model->states.done_action_set; - else - action->generic_action.state_set = - surf_network_model->states.running_action_set; - - xbt_swag_insert(action, action->generic_action.state_set); - + xbt_swag_insert(action, action->generic_action.state_set); + } XBT_OUT; diff --git a/src/surf/network_gtnets.c b/src/surf/network_gtnets.c index ec361a979e..eb561fad42 100644 --- a/src/surf/network_gtnets.c +++ b/src/surf/network_gtnets.c @@ -433,26 +433,13 @@ static void update_resource_state(void *id, } /* KF: Rate not supported */ +/* Max durations are not supported */ static surf_action_t communicate(const char *src_name, const char *dst_name,int src, int dst, double size, double rate) { surf_action_network_GTNETS_t action = NULL; - action = xbt_new0(s_surf_action_network_GTNETS_t, 1); - - action->generic_action.refcount = 1; - action->generic_action.cost = size; - action->generic_action.remains = size; - /* Max durations are not supported */ - action->generic_action.max_duration = NO_MAX_DURATION; - action->generic_action.start = surf_get_clock(); - action->generic_action.finish = -1.0; - action->generic_action.model_type = surf_network_model; - - action->generic_action.state_set = - surf_network_model->states.running_action_set; - - xbt_swag_insert(action, action->generic_action.state_set); + action = surf_action_new(sizeof(s_surf_action_network_GTNETS_t),size,surf_network_model,0); /* KF: Add a flow to the GTNets Simulation, associated to this action */ if (gtnets_create_flow(src, dst, size, (void *) action) < 0) { diff --git a/src/surf/surf_action.c b/src/surf/surf_action.c index 431baa6cad..a3d5d55870 100644 --- a/src/surf/surf_action.c +++ b/src/surf/surf_action.c @@ -7,6 +7,10 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_kernel); +/* + * Generic action + */ + const char *surf_action_state_names[6] = { "SURF_ACTION_READY", "SURF_ACTION_RUNNING", @@ -16,6 +20,27 @@ const char *surf_action_state_names[6] = { "SURF_ACTION_NOT_IN_THE_SYSTEM" }; +void* surf_action_new(size_t size,double cost,surf_model_t model,int failed) { + surf_action_t action = xbt_malloc0(size); + action->refcount = 1; + action->cost = cost; + action->remains = cost; + action->priority = 1.0; + action->max_duration = NO_MAX_DURATION; + action->start = surf_get_clock(); + action->finish = -1.0; + action->model_type = model; + + if (failed) + action->state_set = model->states.failed_action_set; + else + action->state_set = model->states.running_action_set; + + xbt_swag_insert(action, action->state_set); + + return action; +} + e_surf_action_state_t surf_action_state_get(surf_action_t action) { surf_action_state_t action_state = &(action->model_type->states); @@ -80,3 +105,12 @@ void surf_action_ref(surf_action_t action) { action->refcount++; } +/* +void surf_action_suspend(surf_action_t action) +{ + action->suspended = 1; +}*/ + +/* + * Maxmin action + */ diff --git a/src/surf/workstation_ptask_L07.c b/src/surf/workstation_ptask_L07.c index 7793af265e..1256da696d 100644 --- a/src/surf/workstation_ptask_L07.c +++ b/src/surf/workstation_ptask_L07.c @@ -455,16 +455,9 @@ static surf_action_t execute_parallel_task(int workstation_nb, if (computation_amount[i] > 0) nb_host++; - action = xbt_new0(s_surf_action_workstation_L07_t, 1); + action=surf_action_new(sizeof(s_surf_action_workstation_L07_t),amount,surf_workstation_model,0); DEBUG3("Creating a parallel task (%p) with %d cpus and %d links.", action, workstation_nb, nb_link); - action->generic_action.refcount = 1; - action->generic_action.cost = amount; - action->generic_action.remains = amount; - action->generic_action.max_duration = NO_MAX_DURATION; - action->generic_action.start = surf_get_clock(); - action->generic_action.finish = -1.0; - action->generic_action.model_type = surf_workstation_model; action->suspended = 0; /* Should be useless because of the calloc but it seems to help valgrind... */ action->workstation_nb = workstation_nb; @@ -472,10 +465,6 @@ static surf_action_t execute_parallel_task(int workstation_nb, action->computation_amount = computation_amount; action->communication_amount = communication_amount; action->latency = latency; - action->generic_action.state_set = - surf_workstation_model->states.running_action_set; - - xbt_swag_insert(action, action->generic_action.state_set); action->rate = rate; action->variable = -- 2.20.1