#include "xbt/str.h"
#include "xbt/dict.h"
#include "surf_private.h"
-/* extern lmm_system_t maxmin_system; */
typedef enum {
SURF_WORKSTATION_RESOURCE_CPU,
/********* 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 void *name_service(const char *name)
-{
- return xbt_dict_get_or_null(workstation_set, name);
-}
-
-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;
}
surf_action_workstation_L07_t action = NULL;
xbt_swag_t running_actions =
- surf_workstation_model->common_public.states.running_action_set;
+ surf_workstation_model->states.running_action_set;
double min = generic_maxmin_share_resources(running_actions,
xbt_swag_offset(s_action,
variable),
surf_action_workstation_L07_t action = NULL;
surf_action_workstation_L07_t next_action = NULL;
xbt_swag_t running_actions =
- surf_workstation_model->common_public.states.running_action_set;
+ surf_workstation_model->states.running_action_set;
xbt_swag_foreach_safe(action, next_action, running_actions) {
deltap = delta;
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,
int i, j;
xbt_dict_free(&link_set);
- xbt_dict_free(&workstation_set);
if (parallel_task_link_set != NULL) {
xbt_dict_free(¶llel_task_link_set);
}
- surf_model_exit((surf_model_t)surf_workstation_model);
-
- free(surf_workstation_model->extension_public);
-
- free(surf_workstation_model);
+ surf_model_exit(surf_workstation_model);
surf_workstation_model = NULL;
for (i = 0; i < nb_workstation; i++)
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);
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_model_t) surf_workstation_model;
+ 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->communication_amount = communication_amount;
action->latency = latency;
action->generic_action.state_set =
- surf_workstation_model->common_public.states.running_action_set;
+ surf_workstation_model->states.running_action_set;
xbt_swag_insert(action, action->generic_action.state_set);
action->rate = rate;
{
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,
tmgr_trace_t state_trace, xbt_dict_t cpu_properties)
{
cpu_L07_t cpu = xbt_new0(s_cpu_L07_t, 1);
- xbt_assert1(!xbt_dict_get_or_null(workstation_set, name),
+ xbt_assert1(!surf_model_resource_by_name(surf_workstation_model, name),
"Host '%s' declared several times in the platform file.", name);
- cpu->model = (surf_model_t) 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;
/*add the property set */
cpu->properties = current_property_set;
- xbt_dict_set(workstation_set, name, cpu, cpu_free);
+ xbt_dict_set(surf_model_resource_set(surf_workstation_model), name, cpu,
+ cpu_free);
return cpu;
}
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_model_t) 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 =
{
cpu_L07_t cpu_tmp = NULL;
- cpu_tmp = (cpu_L07_t) name_service(A_surfxml_route_src);
+ 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) name_service(A_surfxml_route_dst);
+ 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;
/* Connect traces relative to cpu */
xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) {
tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
- cpu_L07_t host = xbt_dict_get_or_null(workstation_set, elm);
+ cpu_L07_t host = surf_model_resource_by_name(surf_workstation_model, elm);
xbt_assert1(host, "Host %s undefined", elm);
xbt_assert1(trace, "Trace %s undefined", trace_name);
xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
- cpu_L07_t host = xbt_dict_get_or_null(workstation_set, elm);
+ cpu_L07_t host = surf_model_resource_by_name(surf_workstation_model, elm);
xbt_assert1(host, "Host %s undefined", elm);
xbt_assert1(trace, "Trace %s undefined", trace_name);
link->lat_event = tmgr_history_add_trace(history, trace, 0.0, 0, link);
}
-/*
-
- xbt_dynar_foreach (traces_connect_list, cpt, value) {
- trace_connect = xbt_str_split_str(value, "#");
- trace_id = xbt_dynar_get_as(trace_connect, 0, char*);
- connect_element = atoi(xbt_dynar_get_as(trace_connect, 1, char*));
- connect_kind = atoi(xbt_dynar_get_as(trace_connect, 2, char*));
- connector_id = xbt_dynar_get_as(trace_connect, 3, char*);
-
- xbt_assert1((trace = xbt_dict_get_or_null(traces_set_list, trace_id)), "Trace %s undefined", trace_id);
-
- if (connect_element == A_surfxml_trace_c_connect_element_HOST) {
- xbt_assert1((host = xbt_dict_get_or_null(workstation_set, connector_id)), "Host %s undefined", connector_id);
- switch (connect_kind) {
- case A_surfxml_trace_c_connect_kind_AVAILABILITY: host->state_event = tmgr_history_add_trace(history, trace, 0.0, 0, host); break;
- case A_surfxml_trace_c_connect_kind_POWER: host->power_event = tmgr_history_add_trace(history, trace, 0.0, 0, host); break;
- }
- }
- else {
- xbt_assert1((link = xbt_dict_get_or_null(link_set, connector_id)), "Link %s undefined", connector_id);
- switch (connect_kind) {
- case A_surfxml_trace_c_connect_kind_AVAILABILITY: link->state_event = tmgr_history_add_trace(history, trace, 0.0, 0, link); break;
- case A_surfxml_trace_c_connect_kind_BANDWIDTH: link->bw_event = tmgr_history_add_trace(history, trace, 0.0, 0, link); break;
- case A_surfxml_trace_c_connect_kind_LATENCY: link->lat_event = tmgr_history_add_trace(history, trace, 0.0, 0, link); break;
- }
- }
- }
-*/
}
static void define_callbacks(const char *file)
static void model_init_internal(void)
{
- surf_workstation_model = xbt_new0(s_surf_workstation_model_t, 1);
-
- surf_model_init((surf_model_t)surf_workstation_model);
- surf_workstation_model->extension_public =
- xbt_new0(s_surf_workstation_model_extension_public_t, 1);
-
- surf_workstation_model->common_public.name_service = name_service;
- surf_workstation_model->common_public.get_resource_name =
- get_resource_name;
- surf_workstation_model->common_public.action_get_state =
- surf_action_get_state;
- surf_workstation_model->common_public.action_get_start_time =
- surf_action_get_start_time;
- surf_workstation_model->common_public.action_get_finish_time =
- surf_action_get_finish_time;
- surf_workstation_model->common_public.action_use = action_use;
- surf_workstation_model->common_public.action_free = action_free;
- surf_workstation_model->common_public.action_cancel = action_cancel;
- surf_workstation_model->common_public.action_change_state =
- surf_action_change_state;
- surf_workstation_model->common_public.action_set_data =
- surf_action_set_data;
- surf_workstation_model->common_public.suspend = action_suspend;
- surf_workstation_model->common_public.resume = action_resume;
- surf_workstation_model->common_public.is_suspended = action_is_suspended;
- surf_workstation_model->common_public.set_max_duration =
- action_set_max_duration;
- surf_workstation_model->common_public.set_priority = action_set_priority;
- surf_workstation_model->common_public.name = "Workstation ptask_L07";
-
- surf_workstation_model->common_private->resource_used = resource_used;
- surf_workstation_model->common_private->share_resources = share_resources;
- surf_workstation_model->common_private->update_actions_state =
+ surf_workstation_model = surf_model_init();
+
+ surf_workstation_model->action_unref = action_unref;
+ surf_workstation_model->action_cancel = action_cancel;
+ 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->set_max_duration = action_set_max_duration;
+ surf_workstation_model->set_priority = action_set_priority;
+ surf_workstation_model->name = "Workstation ptask_L07";
+
+ surf_workstation_model->model_private->resource_used = resource_used;
+ surf_workstation_model->model_private->share_resources = share_resources;
+ surf_workstation_model->model_private->update_actions_state =
update_actions_state;
- surf_workstation_model->common_private->update_resource_state =
+ surf_workstation_model->model_private->update_resource_state =
update_resource_state;
- surf_workstation_model->common_private->finalize = finalize;
-
- surf_workstation_model->extension_public->execute = execute;
- surf_workstation_model->extension_public->sleep = action_sleep;
- surf_workstation_model->extension_public->get_state = resource_get_state;
- surf_workstation_model->extension_public->get_speed = get_speed;
- surf_workstation_model->extension_public->get_available_speed =
+ surf_workstation_model->model_private->finalize = finalize;
+
+ surf_workstation_model->extension.workstation.execute = execute;
+ surf_workstation_model->extension.workstation.sleep = action_sleep;
+ surf_workstation_model->extension.workstation.get_state =
+ resource_get_state;
+ surf_workstation_model->extension.workstation.get_speed = get_speed;
+ surf_workstation_model->extension.workstation.get_available_speed =
get_available_speed;
- surf_workstation_model->extension_public->communicate = communicate;
- surf_workstation_model->extension_public->execute_parallel_task =
+ surf_workstation_model->extension.workstation.communicate = communicate;
+ surf_workstation_model->extension.workstation.execute_parallel_task =
execute_parallel_task;
- surf_workstation_model->extension_public->get_route = get_route;
- surf_workstation_model->extension_public->get_route_size = get_route_size;
- surf_workstation_model->extension_public->get_link_name = get_link_name;
- surf_workstation_model->extension_public->get_link_bandwidth =
+ 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_bandwidth =
get_link_bandwidth;
- surf_workstation_model->extension_public->get_link_latency =
+ surf_workstation_model->extension.workstation.get_link_latency =
get_link_latency;
- surf_workstation_model->extension_public->link_shared = link_shared;
+ surf_workstation_model->extension.workstation.link_shared = link_shared;
- surf_workstation_model->common_public.get_properties = get_properties;
+ surf_workstation_model->get_properties = get_properties;
- workstation_set = xbt_dict_new();
link_set = xbt_dict_new();
if (!ptask_maxmin_system)
define_callbacks(filename);
update_model_description(surf_workstation_model_description,
- "ptask_L07",
- (surf_model_t) surf_workstation_model);
+ "ptask_L07", surf_workstation_model);
xbt_dynar_push(model_list, &surf_workstation_model);
}