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]
#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
*
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
*/
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
*
#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;
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),
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);
"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;
surf_network_model->action_state_set((surf_action_t) action, SURF_ACTION_DONE);
}
}
-
- return;
}
static void update_resource_state(void *id,
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;
}
/* 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) {
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_kernel);
+/*
+ * Generic action
+ */
+
const char *surf_action_state_names[6] = {
"SURF_ACTION_READY",
"SURF_ACTION_RUNNING",
"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);
{
action->refcount++;
}
+/*
+void surf_action_suspend(surf_action_t action)
+{
+ action->suspended = 1;
+}*/
+
+/*
+ * Maxmin action
+ */
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;
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 =