Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
implement a constructor for surf_action_t; draft a surf_action_maxmin_t for actions...
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 2 Jul 2009 08:00:07 +0000 (08:00 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 2 Jul 2009 08:00:07 +0000 (08:00 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@6439 48e7efb5-ca39-0410-a469-dd3cf9ba447f

ChangeLog
src/include/surf/surf.h
src/surf/cpu.c
src/surf/network.c
src/surf/network_constant.c
src/surf/network_gtnets.c
src/surf/surf_action.c
src/surf/workstation_ptask_L07.c

index 78a962d..898566b 100644 (file)
--- 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)
     
               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]
  XBT:
   * Add xbt_set_get_by_name_or_null() [Silas De Munck]
   * Add xbt_graph_node_get_outedges() [Silas De Munck]
index 2790d9b..ce16cd1 100644 (file)
 #include "xbt/config.h"
 
 SG_BEGIN_DECL()
 #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
  *
 /** \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);
 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
  */
 
 /** \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;
 
        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
  *
 /** \brief Action states
  *  \ingroup SURF_actions
  *
index ca63f90..388e1c2 100644 (file)
@@ -7,11 +7,7 @@
 
 #include "surf_private.h"
 
 
 #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;
 
 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;
   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),
 
   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);
   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... */
 
   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);
   action->variable = lmm_variable_new(cpu_maxmin_system, action,
                                       action->generic_action.priority,
                                       -1.0, 1);
index d55e71b..6a6984b 100644 (file)
@@ -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);
 
               "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;
   link_CM02_t link;
+  int failed=0;
   xbt_dynar_foreach(route,i,link) {
     if (link->state_current == SURF_LINK_OFF) {
   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;
     }
   }
       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;
 
   xbt_swag_insert(action, action->generic_action.state_set);
   action->rate = rate;
index 7ed8284..2b0b2ed 100644 (file)
@@ -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);
     }
   }
       surf_network_model->action_state_set((surf_action_t) action, SURF_ACTION_DONE);
     }
   }
-
-  return;
 }
 
 static void update_resource_state(void *id,
 }
 
 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);
 
 
   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;
 
   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;
     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;
 
 
   XBT_OUT;
 
index ec361a9..eb561fa 100644 (file)
@@ -433,26 +433,13 @@ static void update_resource_state(void *id,
 }
 
 /* KF: Rate not supported */
 }
 
 /* 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;
 
 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) {
 
   /* KF: Add a flow to the GTNets Simulation, associated to this action */
   if (gtnets_create_flow(src, dst, size, (void *) action) < 0) {
index 431baa6..a3d5d55 100644 (file)
@@ -7,6 +7,10 @@
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_kernel);
 
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_kernel);
 
+/*
+ * Generic action
+ */
+
 const char *surf_action_state_names[6] = {
   "SURF_ACTION_READY",
   "SURF_ACTION_RUNNING",
 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"
 };
 
   "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);
 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++;
 }
 {
   action->refcount++;
 }
+/*
+void surf_action_suspend(surf_action_t action)
+{
+  action->suspended = 1;
+}*/
+
+/*
+ * Maxmin action
+ */
index 7793af2..1256da6 100644 (file)
@@ -455,16 +455,9 @@ static surf_action_t execute_parallel_task(int workstation_nb,
     if (computation_amount[i] > 0)
       nb_host++;
 
     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);
   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;
   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->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 =
   action->rate = rate;
 
   action->variable =