/********* cpu object *****************/
/**************************************/
typedef struct cpu_L07 {
- surf_model_t model; /* Do not move this field: must match model_obj_t */
- xbt_dict_t properties; /* Do not move this field: must match link_L07_t */
+ s_surf_resource_t generic_resource; /* Do not move this field: must match surf_resource_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 */
- xbt_dict_t properties; /* Do not move this field: must match link_L07_t */
+ s_surf_resource_t generic_resource; /* Do not move this field: must match surf_resource_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;
tmgr_trace_event_t state_event;
} s_link_L07_t, *link_L07_t;
-
-typedef struct s_route_L07 {
- link_L07_t *links;
- int size;
-} s_route_L07_t, *route_L07_t;
-
/**************************************/
/*************** actions **************/
/**************************************/
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_workstation);
-static int nb_workstation = 0;
-static s_route_L07_t *routing_table = NULL;
-#define ROUTE(i,j) routing_table[(i)+(j)*nb_workstation]
-static link_L07_t loopback = NULL;
+static int host_count = 0;
static xbt_dict_t parallel_task_link_set = NULL;
lmm_system_t ptask_maxmin_system = NULL;
int workstation_nb = action->workstation_nb;
double lat_current = 0.0;
double lat_bound = -1.0;
- int i, j, k;
+ int i, j;
+ unsigned int cpt;
+ link_L07_t link;
for (i = 0; i < workstation_nb; i++) {
for (j = 0; j < workstation_nb; j++) {
cpu_L07_t card_src = action->workstation_list[i];
cpu_L07_t card_dst = action->workstation_list[j];
- int route_size = ROUTE(card_src->id, card_dst->id).size;
- link_L07_t *route = ROUTE(card_src->id, card_dst->id).links;
+ xbt_dynar_t route = used_routing->get_route(card_src->id, card_dst->id);
double lat = 0.0;
if (action->communication_amount[i * workstation_nb + j] > 0) {
- for (k = 0; k < route_size; k++) {
- lat += route[k]->lat_current;
+ xbt_dynar_foreach(route,cpt,link) {
+ lat += link->lat_current;
}
lat_current =
MAX(lat_current,
/******* 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 */
- return ((cpu_L07_t) r)->properties;
-}
-
-/* action_get_state is inherited from the surf module */
-
-static void action_use(surf_action_t action)
-{
- action->refcount++;
- return;
-}
-
-static int action_free(surf_action_t action)
+static int action_unref(surf_action_t action)
{
action->refcount--;
static void action_cancel(surf_action_t action)
{
- surf_action_change_state(action, SURF_ACTION_FAILED);
+ surf_action_state_set(action, SURF_ACTION_FAILED);
return;
}
if ((action->generic_action.remains <= 0) &&
(lmm_get_variable_weight(action->variable) > 0)) {
action->generic_action.finish = surf_get_clock();
- surf_action_change_state((surf_action_t) action, SURF_ACTION_DONE);
+ surf_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
} else if ((action->generic_action.max_duration != NO_MAX_DURATION) &&
(action->generic_action.max_duration <= 0)) {
action->generic_action.finish = surf_get_clock();
- surf_action_change_state((surf_action_t) action, SURF_ACTION_DONE);
+ surf_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
} else {
/* Need to check that none of the model has failed */
lmm_constraint_t cnst = NULL;
(((cpu_L07_t) constraint_id)->state_current == SURF_CPU_OFF))) {
DEBUG1("Action (%p) Failed!!", action);
action->generic_action.finish = surf_get_clock();
- surf_action_change_state((surf_action_t) action,
+ surf_action_state_set((surf_action_t) action,
SURF_ACTION_FAILED);
break;
}
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,
static void finalize(void)
{
- int i, j;
-
- xbt_dict_free(&link_set);
- if (parallel_task_link_set != NULL) {
+ if (parallel_task_link_set != NULL)
xbt_dict_free(¶llel_task_link_set);
- }
surf_model_exit(surf_workstation_model);
-
- free(surf_workstation_model);
surf_workstation_model = NULL;
+ surf_model_exit(surf_network_model);
+ surf_network_model = NULL;
+ used_routing->finalize();
- for (i = 0; i < nb_workstation; i++)
- for (j = 0; j < nb_workstation; j++)
- free(ROUTE(i, j).links);
- free(routing_table);
- routing_table = NULL;
- nb_workstation = 0;
+ host_count = 0; // FIXME: KILLME?
if (ptask_maxmin_system) {
lmm_system_free(ptask_maxmin_system);
double amount, double rate)
{
surf_action_workstation_L07_t action = NULL;
- int i, j, k;
+ int i, j;
+ unsigned int cpt;
int nb_link = 0;
int nb_host = 0;
double latency = 0.0;
for (j = 0; j < workstation_nb; j++) {
cpu_L07_t card_src = workstation_list[i];
cpu_L07_t card_dst = workstation_list[j];
- int route_size = ROUTE(card_src->id, card_dst->id).size;
- link_L07_t *route = ROUTE(card_src->id, card_dst->id).links;
+ link_L07_t link;
+ xbt_dynar_t route = used_routing->get_route(card_src->id, card_dst->id);
double lat = 0.0;
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,
- route[k], NULL);
+ xbt_dynar_foreach(route,cpt,link) {
+ lat += link->lat_current;
+ xbt_dict_set(parallel_task_link_set, link->generic_resource.name,
+ link, NULL);
}
latency = MAX(latency, lat);
}
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 =
for (j = 0; j < workstation_nb; j++) {
cpu_L07_t card_src = workstation_list[i];
cpu_L07_t card_dst = workstation_list[j];
- int route_size = ROUTE(card_src->id, card_dst->id).size;
- link_L07_t *route = ROUTE(card_src->id, card_dst->id).links;
+ link_L07_t link;
+ xbt_dynar_t route = used_routing->get_route(card_src->id, card_dst->id);
if (communication_amount[i * workstation_nb + j] == 0.0)
continue;
- for (k = 0; k < route_size; k++) {
- lmm_expand_add(ptask_maxmin_system, route[k]->constraint,
+ xbt_dynar_foreach(route,cpt,link) {
+ lmm_expand_add(ptask_maxmin_system, link->constraint,
action->variable,
communication_amount[i * workstation_nb + j]);
}
{
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 (surf_action_t) action;
}
-/* returns an array of link_L07_t */
-static const void **get_route(void *src, void *dst)
-{
- cpu_L07_t card_src = src;
- cpu_L07_t card_dst = dst;
- route_L07_t route = &(ROUTE(card_src->id, card_dst->id));
-
- return (const void **) route->links;
-}
-
-static int get_route_size(void *src, void *dst)
+static xbt_dynar_t get_route(void *src, void *dst)
{
- cpu_L07_t card_src = src;
- cpu_L07_t card_dst = dst;
- route_L07_t route = &(ROUTE(card_src->id, card_dst->id));
- return route->size;
-}
+ cpu_L07_t host_src = src;
+ cpu_L07_t host_dst = dst;
-static const char *get_link_name(const void *link)
-{
- return ((link_L07_t) link)->name;
+ return used_routing->get_route(host_src->id, host_dst->id);
}
static double get_link_bandwidth(const void *link)
/*** Resource Creation & Destruction **/
/**************************************/
-static void cpu_free(void *cpu)
-{
- free(((cpu_L07_t) cpu)->name);
- xbt_dict_free(&(((cpu_L07_t) cpu)->properties));
- free(cpu);
-}
-
static cpu_L07_t cpu_new(const char *name, double power_scale,
double power_initial,
tmgr_trace_t power_trace,
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->id = nb_workstation++;
+ cpu->generic_resource.name = xbt_strdup(name);
+ cpu->generic_resource.properties = current_property_set;
+ cpu->id = host_count++;
cpu->power_scale = power_scale;
xbt_assert0(cpu->power_scale > 0, "Power has to be >0");
lmm_constraint_new(ptask_maxmin_system, cpu,
cpu->power_current * cpu->power_scale);
- /*add the property set */
- cpu->properties = current_property_set;
-
xbt_dict_set(surf_model_resource_set(surf_workstation_model), name, cpu,
- cpu_free);
+ surf_resource_free);
return cpu;
}
-static void create_routing_table(void)
-{
- routing_table = xbt_new0(s_route_L07_t, nb_workstation * nb_workstation);
-}
-
static void parse_cpu_init(void)
{
double power_scale = 0.0;
state_initial, state_trace, current_property_set);
}
-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);
-}
-
static link_L07_t link_new(char *name,
double bw_initial,
tmgr_trace_t bw_trace,
policy, xbt_dict_t properties)
{
link_L07_t nw_link = xbt_new0(s_link_L07_t, 1);
- xbt_assert1(!xbt_dict_get_or_null(link_set, name),
+ xbt_assert1(!xbt_dict_get_or_null(surf_network_model->resource_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->generic_resource.properties = properties;
+ nw_link->generic_resource.name = name;
nw_link->type = SURF_WORKSTATION_RESOURCE_LINK;
- nw_link->name = name;
nw_link->bw_current = bw_initial;
if (bw_trace)
nw_link->bw_event =
if (policy == SURF_LINK_FATPIPE)
lmm_constraint_shared(nw_link->constraint);
- nw_link->properties = properties;
- xbt_dict_set(link_set, name, nw_link, link_free);
+ xbt_dict_set(surf_network_model->resource_set, name, nw_link, surf_resource_free);
return nw_link;
}
current_property_set);
}
-static void route_new(int src_id, int dst_id,
- link_L07_t * link_list, int nb_link)
-{
- route_L07_t route = &(ROUTE(src_id, dst_id));
-
- route->size = nb_link;
- route->links = link_list =
- xbt_realloc(link_list, sizeof(link_L07_t) * nb_link);
-}
-
-
-static int src_id = -1;
-static int dst_id = -1;
-
-static void parse_route_set_endpoints(void)
-{
- cpu_L07_t cpu_tmp = NULL;
-
- cpu_tmp =
- (cpu_L07_t) surf_model_resource_by_name(surf_workstation_model,
- A_surfxml_route_src);
- xbt_assert1(cpu_tmp, "Invalid cpu %s", A_surfxml_route_src);
- if (cpu_tmp != NULL)
- src_id = cpu_tmp->id;
-
- cpu_tmp =
- (cpu_L07_t) surf_model_resource_by_name(surf_workstation_model,
- A_surfxml_route_dst);
- xbt_assert1(cpu_tmp, "Invalid cpu %s", A_surfxml_route_dst);
- if (cpu_tmp != NULL)
- dst_id = cpu_tmp->id;
-
- route_action = A_surfxml_route_action;
-}
-
-static void parse_route_set_route(void)
-{
- char *name;
- if (src_id != -1 && dst_id != -1) {
- name = bprintf("%x#%x", src_id, dst_id);
- manage_route(route_table, name, route_action, 0);
- free(name);
- }
-}
-
-static void add_loopback(void)
-{
- int i;
-
- /* Adding loopback if needed */
- for (i = 0; i < nb_workstation; i++)
- if (!ROUTE(i, i).size) {
- if (!loopback)
- loopback = link_new(xbt_strdup("__MSG_loopback__"),
- 498000000, NULL, 0.000015, NULL,
- SURF_LINK_ON, NULL, SURF_LINK_FATPIPE, NULL);
-
- ROUTE(i, i).size = 1;
- ROUTE(i, i).links = xbt_new0(link_L07_t, 1);
- ROUTE(i, i).links[0] = loopback;
- }
-}
-
-static void add_route(void)
-{
- xbt_ex_t e;
- int nb_link = 0;
- unsigned int cpt = 0;
- int link_list_capacity = 0;
- link_L07_t *link_list = NULL;
- xbt_dict_cursor_t cursor = NULL;
- char *key, *data, *end;
- const char *sep = "#";
- xbt_dynar_t links, keys;
- char *link = NULL;
-
- if (routing_table == NULL)
- create_routing_table();
-
- xbt_dict_foreach(route_table, cursor, key, data) {
- nb_link = 0;
- links = (xbt_dynar_t) data;
- keys = xbt_str_split_str(key, sep);
-
- src_id = strtol(xbt_dynar_get_as(keys, 0, char *), &end, 16);
- dst_id = strtol(xbt_dynar_get_as(keys, 1, char *), &end, 16);
- xbt_dynar_free(&keys);
-
- link_list_capacity = xbt_dynar_length(links);
- link_list = xbt_new(link_L07_t, link_list_capacity);
-
-
- xbt_dynar_foreach(links, cpt, link) {
- TRY {
- link_list[nb_link++] = xbt_dict_get(link_set, link);
- }
- CATCH(e) {
- RETHROW1("Link %s not found (dict raised this exception: %s)", link);
- }
- }
- route_new(src_id, dst_id, link_list, nb_link);
- }
-}
-
static void add_traces(void)
{
xbt_dict_cursor_t cursor = NULL;
/* Connect traces relative to network */
xbt_dict_foreach(trace_connect_list_link_avail, cursor, trace_name, elm) {
tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
- link_L07_t link = xbt_dict_get_or_null(link_set, elm);
+ link_L07_t link = xbt_dict_get_or_null(surf_network_model->resource_set, elm);
xbt_assert1(link, "Link %s undefined", elm);
xbt_assert1(trace, "Trace %s undefined", trace_name);
xbt_dict_foreach(trace_connect_list_bandwidth, cursor, trace_name, elm) {
tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
- link_L07_t link = xbt_dict_get_or_null(link_set, elm);
+ link_L07_t link = xbt_dict_get_or_null(surf_network_model->resource_set, elm);
xbt_assert1(link, "Link %s undefined", elm);
xbt_assert1(trace, "Trace %s undefined", trace_name);
xbt_dict_foreach(trace_connect_list_latency, cursor, trace_name, elm) {
tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
- link_L07_t link = xbt_dict_get_or_null(link_set, elm);
+ link_L07_t link = xbt_dict_get_or_null(surf_network_model->resource_set, elm);
xbt_assert1(link, "Link %s undefined", elm);
xbt_assert1(trace, "Trace %s undefined", trace_name);
surf_parse_reset_parser();
surfxml_add_callback(STag_surfxml_host_cb_list, &parse_cpu_init);
surfxml_add_callback(STag_surfxml_link_cb_list, &parse_link_init);
- surfxml_add_callback(STag_surfxml_route_cb_list,
- &parse_route_set_endpoints);
- surfxml_add_callback(ETag_surfxml_route_cb_list, &parse_route_set_route);
- surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_route);
- surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_loopback);
surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_traces);
}
static void model_init_internal(void)
{
- surf_workstation_model = xbt_new0(s_surf_model_t, 1);
+ surf_workstation_model = surf_model_init();
- surf_model_init(surf_workstation_model);
-
- 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_action_get_finish_time;
- surf_workstation_model->action_use = action_use;
- surf_workstation_model->action_free = action_free;
+ surf_workstation_model->action_unref = action_unref;
surf_workstation_model->action_cancel = action_cancel;
- surf_workstation_model->action_change_state = surf_action_change_state;
- surf_workstation_model->action_set_data = surf_action_set_data;
+ surf_workstation_model->action_state_set = surf_action_state_set;
surf_workstation_model->suspend = action_suspend;
surf_workstation_model->resume = action_resume;
surf_workstation_model->is_suspended = action_is_suspended;
surf_workstation_model->extension.workstation.get_available_speed =
get_available_speed;
surf_workstation_model->extension.workstation.communicate = communicate;
+ surf_workstation_model->extension.workstation.get_route = get_route;
surf_workstation_model->extension.workstation.execute_parallel_task =
execute_parallel_task;
- 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 =
get_link_latency;
surf_workstation_model->extension.workstation.link_shared = link_shared;
- surf_workstation_model->get_properties = get_properties;
-
- link_set = xbt_dict_new();
-
if (!ptask_maxmin_system)
ptask_maxmin_system = lmm_system_new();
+
+ routing_model_create(sizeof(link_L07_t),
+ link_new(xbt_strdup("__loopback__"),
+ 498000000, NULL, 0.000015, NULL,
+ SURF_LINK_ON, NULL, SURF_LINK_FATPIPE, NULL));
+
}
/**************************************/
{
xbt_assert0(!surf_cpu_model, "CPU model type already defined");
xbt_assert0(!surf_network_model, "network model type already defined");
- model_init_internal();
+ surf_network_model = surf_model_init();
define_callbacks(filename);
+ model_init_internal();
update_model_description(surf_workstation_model_description,
"ptask_L07", surf_workstation_model);