(less redirections, less function to write when defining a model)
* Unify the types of models in a uniq s_surf_model_t (using an union)
* Embeed every fields of common_public directly into s_surf_model_t
-
+ * Implement a generic resource; use it as ancestor to specific ones
+ Allows to kill duplicated code in models
+ The drawback is that network cards are more fat since they don't
+ use the model field of their ancestor.
+ But hell, we wont fight for 8 bytes per host, will we?
+ TODO: integrate the properties into that ancestor
+
XBT:
* Add xbt_set_get_by_name_or_null() [Silas De Munck]
* Add xbt_graph_node_get_outedges() [Silas De Munck]
SURF_SRC= \
surf/model.c \
+ surf/surf_resource.c \
surf/surf_config.c \
surf/maxmin.c \
surf/fair_bottleneck.c \
/* Generic model object */
/***************************/
-/** \brief Public data available on all models
- * \ingroup SURF_models
- *
- * These functions are implemented by all models.
- */
- typedef struct surf_model_public {
- } s_surf_model_public_t, *surf_model_public_t;
-
/** \brief Private data available on all models
* \ingroup SURF_models
*/
double max_rate);
const void **(*get_route) (void *src, void *dst);
int (*get_route_size) (void *src, void *dst);
- const char *(*get_link_name) (const void *link);
double (*get_link_bandwidth) (const void *link);
double (*get_link_latency) (const void *link);
int (*link_shared) (const void *link);
double amount, double rate);
const void **(*get_route) (void *src, void *dst); /**< Return the network link list between two workstations */
int (*get_route_size) (void *src, void *dst); /**< Return the route size between two workstations */
- const char *(*get_link_name) (const void *link); /**< Return the name of a network link */
double (*get_link_bandwidth) (const void *link); /**< Return the current bandwidth of a network link */
double (*get_link_latency) (const void *link); /**< Return the current latency of a network link */
int (*link_shared) (const void *link);
typedef struct surf_model {
const char *name;/**< Name of this model */
s_surf_action_state_t states; /**< Any living action on this model */
- const char *(*get_resource_name) (void *resource_id);/**< Return the name of a resource */
e_surf_action_state_t(*action_get_state) (surf_action_t action);/**< Return the state of an action */
double (*action_get_start_time) (surf_action_t action);/**< Return the start time of an action */
typedef struct surf_resource {
surf_model_t model;
+ char *name;
} s_surf_resource_t, *surf_resource_t;
+XBT_PUBLIC(const char*) surf_resource_name(const void *resource);
+XBT_PUBLIC(void) surf_resource_free(void* resource);
/**************************************/
/* Implementations of model object */
/**************************************/
{
SD_CHECK_INIT_DONE();
xbt_assert0(link != NULL, "Invalid parameter");
- return surf_workstation_model->extension.workstation.
- get_link_name(link->surf_link);
+ return surf_resource_name(link->surf_link);
}
/**
{
SD_CHECK_INIT_DONE();
xbt_assert0(workstation != NULL, "Invalid parameter");
- return surf_workstation_model->get_resource_name(workstation->
- surf_workstation);
+ return surf_resource_name(workstation->surf_workstation);
}
/**
for (i = 0; i < route_size; i++) {
- link_name =
- surf_workstation_model->extension.workstation.
- get_link_name(surf_route[i]);
+ link_name = surf_resource_name(surf_route[i]);
sd_global->recyclable_route[i] =
xbt_dict_get(sd_global->links, link_name);
}
static void cpu_free(void *cpu)
{
- free(((cpu_Cas01_t) cpu)->name);
xbt_dict_free(&(((cpu_Cas01_t) cpu)->properties));
- free(cpu);
+ surf_resource_free(cpu);
}
static cpu_Cas01_t cpu_new(char *name, double power_scale,
cpu_Cas01_t cpu = xbt_new0(s_cpu_Cas01_t, 1);
xbt_assert1(!surf_model_resource_by_name(surf_cpu_model, name),
"Host '%s' declared several times in the platform file", name);
- cpu->model = surf_cpu_model;
- cpu->name = name;
+ cpu->generic_resource.model = surf_cpu_model;
+ cpu->generic_resource.name = name;
cpu->power_scale = power_scale;
xbt_assert0(cpu->power_scale > 0, "Power has to be >0");
cpu->power_current = power_initial;
surfxml_add_callback(STag_surfxml_host_cb_list, parse_cpu_init);
}
-static const char *get_resource_name(void *resource_id)
-{
- return ((cpu_Cas01_t) resource_id)->name;
-}
-
static int resource_used(void *resource_id)
{
return lmm_constraint_used(cpu_maxmin_system,
running_action_set_that_does_not_need_being_checked =
xbt_swag_new(xbt_swag_offset(action, state_hookup));
- surf_cpu_model->get_resource_name = get_resource_name;
surf_cpu_model->action_get_state = surf_action_get_state;
surf_cpu_model->action_get_start_time = surf_action_get_start_time;
surf_cpu_model->action_get_finish_time = surf_action_get_finish_time;
} s_surf_action_cpu_Cas01_t, *surf_action_cpu_Cas01_t;
typedef struct cpu_Cas01 {
- surf_model_t model; /* Any such object, added in a trace
- should start by this field!!! */
+ s_surf_resource_t generic_resource;
char *name;
double power_scale;
double power_current;
static void link_free(void *nw_link)
{
- free(((link_CM02_t) nw_link)->name);
xbt_dict_free(&(((link_CM02_t) nw_link)->properties));
- free(nw_link);
+ surf_resource_free(nw_link);
}
static link_CM02_t link_new(char *name,
xbt_assert1(!xbt_dict_get_or_null(link_set, name),
"Link '%s' declared several times in the platform file.", name);
- nw_link->model = surf_network_model;
- nw_link->name = name;
+ nw_link->generic_resource.model = surf_network_model;
+ nw_link->generic_resource.name = name;
nw_link->bw_current = bw_initial;
if (bw_trace)
nw_link->bw_event =
return nw_link;
}
-static void network_card_free(void *nw_card)
-{
- free(((network_card_CM02_t) nw_card)->name);
- free(nw_card);
-}
-
static int network_card_new(const char *card_name)
{
network_card_CM02_t card =
if (!card) {
card = xbt_new0(s_network_card_CM02_t, 1);
- card->name = xbt_strdup(card_name);
+ card->generic_resource.name = xbt_strdup(card_name);
card->id = host_number++;
xbt_dict_set(surf_model_resource_set(surf_network_model), card_name, card,
- network_card_free);
+ surf_resource_free);
}
return card->id;
}
surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_loopback);
}
-static const char *get_resource_name(void *resource_id)
-{
- return ((network_card_CM02_t) resource_id)->name;
-}
-
static int resource_used(void *resource_id)
{
return lmm_constraint_used(network_maxmin_system,
total_route_size = route_size + src->link_nb + dst->nb */
int i;
- XBT_IN4("(%s,%s,%g,%g)", card_src->name, card_dst->name, size, rate);
+ XBT_IN4("(%s,%s,%g,%g)", card_src->generic_resource.name, card_dst->generic_resource.name, size, rate);
/* LARGE PLATFORMS HACK:
assert on total_route_size */
xbt_assert2(route_size,
"You're trying to send data from %s to %s but there is no connexion between these two cards.",
- card_src->name, card_dst->name);
+ card_src->generic_resource.name, card_dst->generic_resource.name);
action = xbt_new0(s_surf_action_network_CM02_t, 1);
return ROUTE_SIZE(card_src->id, card_dst->id);
}
-static const char *get_link_name(const void *link)
-{
- return ((link_CM02_t) link)->name;
-}
-
static double get_link_bandwidth(const void *link)
{
return ((link_CM02_t) link)->bw_current;
{
surf_network_model = surf_model_init();
- surf_network_model->get_resource_name = get_resource_name;
surf_network_model->action_get_state = surf_action_get_state;
surf_network_model->action_get_start_time = surf_action_get_start_time;
surf_network_model->action_get_finish_time = surf_action_get_finish_time;
surf_network_model->extension.network.communicate = communicate;
surf_network_model->extension.network.get_route = get_route;
surf_network_model->extension.network.get_route_size = get_route_size;
- surf_network_model->extension.network.get_link_name = get_link_name;
surf_network_model->extension.network.get_link_bandwidth =
get_link_bandwidth;
surf_network_model->extension.network.get_link_latency = get_link_latency;
#include "xbt/log.h"
typedef struct network_card_Constant {
- char *name;
+ s_surf_resource_t generic_resource;
int id;
} s_network_card_Constant_t, *network_card_Constant_t;
static int card_number = 0;
static int host_number = 0;
-static void network_card_free(void *nw_card)
-{
- free(((network_card_Constant_t) nw_card)->name);
- free(nw_card);
-}
-
static int network_card_new(const char *card_name)
{
network_card_Constant_t card =
if (!card) {
card = xbt_new0(s_network_card_Constant_t, 1);
- card->name = xbt_strdup(card_name);
+ card->generic_resource.name = xbt_strdup(card_name);
card->id = card_number++;
xbt_dict_set(surf_model_resource_set(surf_network_model), card_name, card,
- network_card_free);
+ surf_resource_free);
}
return card->id;
}
surfxml_add_callback(ETag_surfxml_route_cb_list, &parse_route_set_route);
}
-static const char *get_resource_name(void *resource_id)
-{
- return ((network_card_Constant_t) resource_id)->name;
-}
-
static int resource_used(void *resource_id)
{
return 0;
network_card_Constant_t card_src = src;
network_card_Constant_t card_dst = dst;
- XBT_IN4("(%s,%s,%g,%g)", card_src->name, card_dst->name, size, rate);
+ XBT_IN4("(%s,%s,%g,%g)", card_src->generic_resource.name, card_dst->generic_resource.name, size, rate);
action = xbt_new0(s_surf_action_network_Constant_t, 1);
return 0;
}
-static const char *get_link_name(const void *link)
-{
- DIE_IMPOSSIBLE;
-}
-
static double get_link_bandwidth(const void *link)
{
DIE_IMPOSSIBLE;
{
surf_network_model = surf_model_init();
- surf_network_model->get_resource_name = get_resource_name;
surf_network_model->action_get_state = surf_action_get_state;
surf_network_model->action_get_start_time = surf_action_get_start_time;
surf_network_model->action_get_finish_time = surf_action_get_finish_time;
surf_network_model->extension.network.communicate = communicate;
surf_network_model->extension.network.get_route = get_route;
surf_network_model->extension.network.get_route_size = get_route_size;
- surf_network_model->extension.network.get_link_name = get_link_name;
surf_network_model->extension.network.get_link_bandwidth =
get_link_bandwidth;
surf_network_model->extension.network.get_link_latency = get_link_latency;
/* Free memory for a network link */
static void link_free(void *nw_link)
{
- free(((network_link_GTNETS_t) nw_link)->name);
xbt_dict_free(&(((network_link_GTNETS_t) nw_link)->properties));
- free(nw_link);
+ surf_resource_free(nw_link);
}
/* Instantiate a new network link */
/* KF: Insert entry in the dictionary */
gtnets_link = xbt_new0(s_network_link_GTNETS_t, 1);
- gtnets_link->name = name;
+ gtnets_link->generic_resource.name = name;
gtnets_link->bw_current = bw;
gtnets_link->lat_current = lat;
gtnets_link->id = link_count;
return;
}
-/* free the network card */
-static void network_card_free(void *nw_card)
-{
- free(((network_card_GTNETS_t) nw_card)->name);
- free(nw_card);
-}
-
/* Instantiate a new network card: MODIFYED BY KF */
static int network_card_new(const char *name)
{
/* KF: just use the dictionary to map link names to link indices */
card = xbt_new0(s_network_card_GTNETS_t, 1);
- card->name = xbt_strdup(name);
+ card->generic_resource.name = xbt_strdup(name);
card->id = card_count;
xbt_dict_set(surf_model_resource_set(surf_network_model), name, card,
- network_card_free);
+ surf_resource_free);
}
LOG1(xbt_log_priority_trace, " return %d", card->id);
surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_route);
}
-static const char *get_resource_name(void *resource_id)
-{
- return ((network_card_GTNETS_t) resource_id)->name;
-}
-
static xbt_dict_t get_properties(void *link)
{
return ((network_card_GTNETS_t) link)->properties;
/* KF: Add a flow to the GTNets Simulation, associated to this action */
if (gtnets_create_flow(card_src->id, card_dst->id, size, (void *) action)
< 0) {
- xbt_assert2(0, "Not route between host %s and host %s", card_src->name,
- card_dst->name);
+ xbt_assert2(0, "Not route between host %s and host %s", card_src->generic_resource.name,
+ card_dst->generic_resource.name);
}
return (surf_action_t) action;
/* Suspend a flow() */
static void action_suspend(surf_action_t action)
{
- xbt_assert0(0,
- "action_suspend() not supported for the GTNets network model");
+ THROW_UNIMPLEMENTED;
}
/* Resume a flow() */
static void action_resume(surf_action_t action)
{
- xbt_assert0(0,
- "action_resume() not supported for the GTNets network model");
+ THROW_UNIMPLEMENTED;
}
/* Test whether a flow is suspended */
surf_model_init(surf_network_model);
- surf_network_model->common_public.name_service = name_service;
- surf_network_model->common_public.get_resource_name = get_resource_name;
surf_network_model->common_public.action_get_state = surf_action_get_state;
surf_network_model->common_public.action_use = action_use;
surf_network_model->common_public.action_free = action_free;
#include "xbt/dict.h"
typedef struct network_link_GTNETS {
- surf_model_t model; /* Any such object, added in a trace
- should start by this field!!! */
+ s_surf_resource_t generic_resource; /* Must remain first to allow casting */
/* Using this object with the public part of
model does not make sense */
- char *name;
double bw_current;
double lat_current;
int id;
#include "xbt/dict.h"
typedef struct network_link_CM02 {
- surf_model_t model; /* Any such object, added in a trace
- should start by this field!!! */
+ s_surf_resource_t generic_resource; /* must remain first to be added to a trace */
+
xbt_dict_t properties;
/* Using this object with the public part of
model does not make sense */
- char *name;
double bw_current;
tmgr_trace_event_t bw_event;
double lat_current;
typedef struct network_card_CM02 {
- char *name;
+ s_surf_resource_t generic_resource; /* must remain first to allow casts */
int id;
} s_network_card_CM02_t, *network_card_CM02_t;
static xbt_swag_t command_to_run = NULL;
static xbt_heap_t timer_heap = NULL;
-static void timer_free(void *timer)
-{
- free(timer);
-}
-
static command_t command_new(void *fun, void *args)
{
command_t command = xbt_new0(s_command_t, 1);
- command->model = surf_timer_model;
+ command->generic_resource.model = surf_timer_model;
command->function = fun;
command->args = args;
xbt_swag_insert(command, command_pending);
static void command_free(command_t command)
{
- free(command);
-
if (xbt_swag_belongs(command, command_to_run)) {
xbt_swag_remove(command, command_to_run);
} else if (xbt_swag_belongs(command, command_pending)) {
xbt_swag_remove(command, command_pending);
}
+ surf_resource_free((surf_resource_t)command);
return;
}
{
}
-static const char *get_resource_name(void *resource_id)
-{
- DIE_IMPOSSIBLE;
- return "";
-}
-
static int resource_used(void *resource_id)
{
return 1;
{
surf_timer_model = surf_model_init();
- surf_timer_model->get_resource_name = get_resource_name;
surf_timer_model->action_get_state = surf_action_get_state;
surf_timer_model->action_change_state = action_change_state;
surf_timer_model->action_set_data = surf_action_set_data;
#include "surf_private.h"
#include "xbt/dict.h"
-/* typedef struct surf_action_timer_Cas01 { */
-/* s_surf_action_t generic_action; */
-/* lmm_variable_t variable; */
-/* } s_surf_action_timer_t, *surf_action_timer_t; */
-
typedef struct command {
- surf_model_t model; /* Any such object, added in a trace
- should start by this field!!! */
+ s_surf_resource_t generic_resource; /* Must remain first, since we add this to a trace */
void *function;
void *args;
s_xbt_swag_hookup_t command_set_hookup;
surf_model_t surf_workstation_model = NULL;
-static void workstation_free(void *workstation)
-{
- free(((workstation_CLM03_t) workstation)->name);
- free(workstation);
-}
-
static workstation_CLM03_t workstation_new(const char *name,
void *cpu, void *card)
{
workstation_CLM03_t workstation = xbt_new0(s_workstation_CLM03_t, 1);
- workstation->model = surf_workstation_model;
- workstation->name = xbt_strdup(name);
+ workstation->generic_resource.model = surf_workstation_model;
+ workstation->generic_resource.name = xbt_strdup(name);
workstation->cpu = cpu;
workstation->network_card = card;
xbt_dict_set(surf_model_resource_set(surf_workstation_model), name,
- workstation, workstation_free);
+ workstation, surf_resource_free);
return workstation;
}
}
}
-static const char *get_resource_name(void *resource_id)
-{
- return ((workstation_CLM03_t) resource_id)->name;
-}
-
static int resource_used(void *resource_id)
{
THROW_IMPOSSIBLE; /* This model does not implement parallel tasks */
workstation_dst->network_card);
}
-static const char *get_link_name(const void *link)
-{
- return surf_network_model->extension.network.get_link_name(link);
-}
-
static double get_link_bandwidth(const void *link)
{
return surf_network_model->extension.network.get_link_bandwidth(link);
surf_workstation_model = surf_model_init();
/* surf_workstation_model->extension_private = xbt_new0(s_surf_workstation_model_extension_private_t,1); */
- surf_workstation_model->get_resource_name = get_resource_name;
surf_workstation_model->action_get_state = surf_action_get_state;
surf_workstation_model->action_get_start_time = surf_action_get_start_time;
surf_workstation_model->action_get_finish_time =
surf_workstation_model->extension.workstation.get_route = get_route;
surf_workstation_model->extension.workstation.get_route_size =
get_route_size;
- surf_workstation_model->extension.workstation.get_link_name = get_link_name;
surf_workstation_model->extension.workstation.get_link_bandwidth =
get_link_bandwidth;
surf_workstation_model->extension.workstation.get_link_latency =
#include "surf_private.h"
typedef struct workstation_CLM03 {
- surf_model_t model; /* Any such object, added in a trace
- should start by this field!!! */
- char *name;
+ s_surf_resource_t generic_resource; /* Must remain first to add this to a trace */
void *cpu;
void *network_card;
} s_workstation_CLM03_t, *workstation_CLM03_t;
/********* cpu object *****************/
/**************************************/
typedef struct cpu_L07 {
- surf_model_t model; /* Do not move this field: must match model_obj_t */
+ s_surf_resource_t generic_resource; /* Do not move this field: must match surf_resource_t */
xbt_dict_t properties; /* Do not move this field: must match link_L07_t */
e_surf_workstation_model_type_t type; /* Do not move this field: must match link_L07_t */
- char *name; /* Do not move this field: must match link_L07_t */
lmm_constraint_t constraint; /* Do not move this field: must match link_L07_t */
double power_scale;
double power_current;
/**************************************/
typedef struct link_L07 {
- surf_model_t model; /* Do not move this field: must match model_obj_t */
+ s_surf_resource_t generic_resource; /* Do not move this field: must match surf_resource_t */
xbt_dict_t properties; /* Do not move this field: must match link_L07_t */
e_surf_workstation_model_type_t type; /* Do not move this field: must match cpu_L07_t */
- char *name; /* Do not move this field: must match cpu_L07_t */
lmm_constraint_t constraint; /* Do not move this field: must match cpu_L07_t */
double lat_current;
tmgr_trace_event_t lat_event;
/******* Resource Public **********/
/**************************************/
-static const char *get_resource_name(void *resource_id)
-{
- /* We can freely cast as a cpu_L07_t because it has the same
- prefix as link_L07_t. However, only cpu_L07_t
- will theoretically be given as an argument here. */
-
- return ((cpu_L07_t) resource_id)->name;
-}
-
static xbt_dict_t get_properties(void *r)
{
/* We can freely cast as a cpu_L07_t since it has the same prefix than link_L07_t */
link_L07_t nw_link = id;
if (nw_link->type == SURF_WORKSTATION_RESOURCE_LINK) {
- DEBUG2("Updating link %s (%p)", nw_link->name, nw_link);
+ DEBUG2("Updating link %s (%p)", nw_link->generic_resource.name, nw_link);
if (event_type == nw_link->bw_event) {
nw_link->bw_current = value;
lmm_update_constraint_bound(ptask_maxmin_system, nw_link->constraint,
}
return;
} else if (cpu->type == SURF_WORKSTATION_RESOURCE_CPU) {
- DEBUG3("Updating cpu %s (%p) with value %g", cpu->name, cpu, value);
+ DEBUG3("Updating cpu %s (%p) with value %g", cpu->generic_resource.name, cpu, value);
if (event_type == cpu->power_event) {
cpu->power_current = value;
lmm_update_constraint_bound(ptask_maxmin_system, cpu->constraint,
if (communication_amount[i * workstation_nb + j] > 0)
for (k = 0; k < route_size; k++) {
lat += route[k]->lat_current;
- xbt_dict_set(parallel_task_link_set, route[k]->name,
+ xbt_dict_set(parallel_task_link_set, route[k]->generic_resource.name,
route[k], NULL);
}
latency = MAX(latency, lat);
{
surf_action_workstation_L07_t action = NULL;
- XBT_IN2("(%s,%g)", ((cpu_L07_t) cpu)->name, duration);
+ XBT_IN2("(%s,%g)", ((cpu_L07_t) cpu)->generic_resource.name, duration);
action = (surf_action_workstation_L07_t) execute(cpu, 1.0);
action->generic_action.max_duration = duration;
return route->size;
}
-static const char *get_link_name(const void *link)
-{
- return ((link_L07_t) link)->name;
-}
-
static double get_link_bandwidth(const void *link)
{
return ((link_L07_t) link)->bw_current;
static void cpu_free(void *cpu)
{
- free(((cpu_L07_t) cpu)->name);
xbt_dict_free(&(((cpu_L07_t) cpu)->properties));
- free(cpu);
+ surf_resource_free(cpu);
}
static cpu_L07_t cpu_new(const char *name, double power_scale,
xbt_assert1(!surf_model_resource_by_name(surf_workstation_model, name),
"Host '%s' declared several times in the platform file.", name);
- cpu->model = surf_workstation_model;
+ cpu->generic_resource.model = surf_workstation_model;
cpu->type = SURF_WORKSTATION_RESOURCE_CPU;
- cpu->name = xbt_strdup(name);
+ cpu->generic_resource.name = xbt_strdup(name);
cpu->id = nb_workstation++;
cpu->power_scale = power_scale;
static void link_free(void *nw_link)
{
- free(((link_L07_t) nw_link)->name);
xbt_dict_free(&(((link_L07_t) nw_link)->properties));
- free(nw_link);
+ surf_resource_free(nw_link);
}
static link_L07_t link_new(char *name,
xbt_assert1(!xbt_dict_get_or_null(link_set, name),
"Link '%s' declared several times in the platform file.", name);
- nw_link->model = surf_workstation_model;
+ nw_link->generic_resource.model = surf_workstation_model;
nw_link->type = SURF_WORKSTATION_RESOURCE_LINK;
- nw_link->name = name;
+ nw_link->generic_resource.name = name;
nw_link->bw_current = bw_initial;
if (bw_trace)
nw_link->bw_event =
{
surf_workstation_model = surf_model_init();
- surf_workstation_model->get_resource_name = get_resource_name;
surf_workstation_model->action_get_state = surf_action_get_state;
surf_workstation_model->action_get_start_time = surf_action_get_start_time;
surf_workstation_model->action_get_finish_time =
surf_workstation_model->extension.workstation.get_route = get_route;
surf_workstation_model->extension.workstation.get_route_size =
get_route_size;
- surf_workstation_model->extension.workstation.get_link_name = get_link_name;
surf_workstation_model->extension.workstation.get_link_bandwidth =
get_link_bandwidth;
surf_workstation_model->extension.workstation.get_link_latency =