From: mquinson Date: Sat, 4 Jul 2009 00:02:25 +0000 (+0000) Subject: Further work on objectification of resources: use s_surf_resource_lmm_t in s_link_CM02_t X-Git-Tag: SVN~1191 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/49865e9016967b29688098e17194859c937448fc?hp=0caba370ea99d7ba91606850d0ee8657f39bdbe1 Further work on objectification of resources: use s_surf_resource_lmm_t in s_link_CM02_t git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@6450 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index 43ab9a42b1..eb4ec5b555 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -253,16 +253,23 @@ XBT_PUBLIC(int) find_model_description(s_surf_model_description_t * table, xbt_dict_t properties; } s_surf_resource_t, *surf_resource_t; + + /** * Resource which have a metric handled by a maxmin system */ +typedef struct { + double current; + double max; + tmgr_trace_event_t event; +} s_surf_metric_t; + typedef struct surf_resource_lmm { s_surf_resource_t generic_resource; lmm_constraint_t constraint; e_surf_resource_state_t state_current; tmgr_trace_event_t state_event; - double metric_current; - tmgr_trace_event_t metric_event; + s_surf_metric_t power; }s_surf_resource_lmm_t, *surf_resource_lmm_t; /**************************************/ @@ -605,6 +612,7 @@ XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_latency; XBT_PUBLIC(double) get_cpu_power(const char *power); #include "surf/surf_resource.h" +#include "surf/surf_resource_lmm.h" SG_END_DECL() #endif /* _SURF_SURF_H */ diff --git a/src/include/surf/surf_resource.h b/src/include/surf/surf_resource.h index 8fb6861578..23847f4d66 100644 --- a/src/include/surf/surf_resource.h +++ b/src/include/surf/surf_resource.h @@ -8,6 +8,16 @@ #ifndef SURF_RESOURCE_H #define SURF_RESOURCE_H +static XBT_INLINE +surf_resource_t surf_resource_new(size_t childsize, + surf_model_t model, char *name, xbt_dict_t props) { + surf_resource_t res = xbt_malloc0(childsize); + res->model = model; + res->name = name; + res->properties = props; + return res; +} + static XBT_INLINE void surf_resource_free(void* r) { surf_resource_t resource = r; if (resource->name) diff --git a/src/surf/network.c b/src/surf/network.c index c3611b4b2d..f6f1f326ab 100644 --- a/src/surf/network.c +++ b/src/surf/network.c @@ -37,32 +37,24 @@ static link_CM02_t link_new(char *name, e_surf_link_sharing_policy_t policy, xbt_dict_t properties) { - link_CM02_t nw_link = xbt_new0(s_link_CM02_t, 1); + link_CM02_t nw_link = (link_CM02_t) + surf_resource_lmm_new(sizeof(s_link_CM02_t), + surf_network_model,name,properties, + lmm_constraint_new(network_maxmin_system, nw_link, bandwidth_factor * bw_initial), + history, + state_initial,state_trace, + bw_initial,bw_trace); + 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->generic_resource.model = surf_network_model; - nw_link->generic_resource.name = name; - current_property_set = nw_link->generic_resource.properties = properties; - nw_link->bw_current = bw_initial; - if (bw_trace) - nw_link->bw_event = - tmgr_history_add_trace(history, bw_trace, 0.0, 0, nw_link); nw_link->lat_current = lat_initial; if (lat_trace) nw_link->lat_event = tmgr_history_add_trace(history, lat_trace, 0.0, 0, nw_link); - nw_link->state_current = state_initial; - if (state_trace) - nw_link->state_event = - tmgr_history_add_trace(history, state_trace, 0.0, 0, nw_link); - - nw_link->constraint = - lmm_constraint_new(network_maxmin_system, nw_link, - bandwidth_factor * nw_link->bw_current); if (policy == SURF_LINK_FATPIPE) - lmm_constraint_shared(nw_link->constraint); + lmm_constraint_shared(nw_link->lmm_resource.constraint); xbt_dict_set(surf_network_model->resource_set, name, nw_link, surf_resource_free); @@ -128,7 +120,7 @@ static void add_traces(void) xbt_assert2(trace, "Cannot connect trace %s to link %s: trace undefined", trace_name, elm); - link->state_event = tmgr_history_add_trace(history, trace, 0.0, 0, link); + link->lmm_resource.state_event = tmgr_history_add_trace(history, trace, 0.0, 0, link); } xbt_dict_foreach(trace_connect_list_bandwidth, cursor, trace_name, elm) { @@ -140,7 +132,7 @@ static void add_traces(void) xbt_assert2(trace, "Cannot connect trace %s to link %s: trace undefined", trace_name, elm); - link->bw_event = tmgr_history_add_trace(history, trace, 0.0, 0, link); + link->lmm_resource.power.event = tmgr_history_add_trace(history, trace, 0.0, 0, link); } xbt_dict_foreach(trace_connect_list_latency, cursor, trace_name, elm) { @@ -166,7 +158,7 @@ static void define_callbacks(const char *file) static int resource_used(void *resource_id) { return lmm_constraint_used(network_maxmin_system, - ((link_CM02_t) resource_id)->constraint); + ((surf_resource_lmm_t) resource_id)->constraint); } static int action_unref(surf_action_t action) @@ -272,19 +264,19 @@ static void update_resource_state(void *id, /* "%lg" " for event %p\n", surf_get_clock(), nw_link->name, */ /* value, event_type); */ - if (event_type == nw_link->bw_event) { + if (event_type == nw_link->lmm_resource.power.event) { double delta = - weight_S_parameter / value - weight_S_parameter / nw_link->bw_current; + weight_S_parameter / value - weight_S_parameter / nw_link->lmm_resource.power.current; lmm_variable_t var = NULL; lmm_element_t elem = NULL; surf_action_network_CM02_t action = NULL; - nw_link->bw_current = value; - lmm_update_constraint_bound(network_maxmin_system, nw_link->constraint, - bandwidth_factor * nw_link->bw_current); + nw_link->lmm_resource.power.current = value; + lmm_update_constraint_bound(network_maxmin_system, nw_link->lmm_resource.constraint, + bandwidth_factor * nw_link->lmm_resource.power.current); if (weight_S_parameter > 0) { while ((var = lmm_get_var_from_cnst - (network_maxmin_system, nw_link->constraint, &elem))) { + (network_maxmin_system, nw_link->lmm_resource.constraint, &elem))) { action = lmm_variable_id(var); action->weight += delta; if (!(action->suspended)) @@ -300,7 +292,7 @@ static void update_resource_state(void *id, nw_link->lat_current = value; while ((var = lmm_get_var_from_cnst - (network_maxmin_system, nw_link->constraint, &elem))) { + (network_maxmin_system, nw_link->lmm_resource.constraint, &elem))) { action = lmm_variable_id(var); action->lat_current += delta; action->weight += delta; @@ -317,15 +309,15 @@ static void update_resource_state(void *id, action->weight); } - } else if (event_type == nw_link->state_event) { + } else if (event_type == nw_link->lmm_resource.state_event) { if (value > 0) - nw_link->state_current = SURF_RESOURCE_ON; + nw_link->lmm_resource.state_current = SURF_RESOURCE_ON; else { - lmm_constraint_t cnst = nw_link->constraint; + lmm_constraint_t cnst = nw_link->lmm_resource.constraint; lmm_variable_t var = NULL; lmm_element_t elem = NULL; - nw_link->state_current = SURF_RESOURCE_OFF; + nw_link->lmm_resource.state_current = SURF_RESOURCE_OFF; while ((var = lmm_get_var_from_cnst (network_maxmin_system, cnst, &elem))) { surf_action_t action = lmm_variable_id(var); @@ -367,7 +359,7 @@ static surf_action_t communicate(const char *src_name, const char *dst_name,int link_CM02_t link; int failed=0; xbt_dynar_foreach(route,i,link) { - if (link->state_current == SURF_RESOURCE_OFF) { + if (link->lmm_resource.state_current == SURF_RESOURCE_OFF) { failed = 1; break; } @@ -382,7 +374,7 @@ static surf_action_t communicate(const char *src_name, const char *dst_name,int xbt_dynar_foreach(route,i,link) { action->latency += link->lat_current; action->weight += - link->lat_current + weight_S_parameter / link->bw_current; + link->lat_current + weight_S_parameter / link->lmm_resource.power.current; } /* LARGE PLATFORMS HACK: Add src->link and dst->link latencies */ @@ -417,7 +409,7 @@ static surf_action_t communicate(const char *src_name, const char *dst_name,int } xbt_dynar_foreach(route,i,link) { - lmm_expand(network_maxmin_system, link->constraint, + lmm_expand(network_maxmin_system, link->lmm_resource.constraint, action->variable, 1.0); } /* LARGE PLATFORMS HACK: @@ -430,7 +422,7 @@ static surf_action_t communicate(const char *src_name, const char *dst_name,int static double get_link_bandwidth(const void *link) { - return ((link_CM02_t) link)->bw_current; + return ((link_CM02_t) link)->lmm_resource.power.current; } static double get_link_latency(const void *link) @@ -440,7 +432,7 @@ static double get_link_latency(const void *link) static int link_shared(const void *link) { - return lmm_constraint_is_shared(((link_CM02_t) link)->constraint); + return lmm_constraint_is_shared(((surf_resource_lmm_t) link)->constraint); } static void action_suspend(surf_action_t action) diff --git a/src/surf/network_private.h b/src/surf/network_private.h index a43e670db9..7120d4643d 100644 --- a/src/surf/network_private.h +++ b/src/surf/network_private.h @@ -13,17 +13,12 @@ #include "xbt/dict.h" typedef struct network_link_CM02 { - s_surf_resource_t generic_resource; /* must remain first to be added to a trace */ + s_surf_resource_lmm_t lmm_resource; /* must remain first to be added to a trace */ /* Using this object with the public part of model does not make sense */ - double bw_current; - tmgr_trace_event_t bw_event; double lat_current; tmgr_trace_event_t lat_event; - e_surf_resource_state_t state_current; - tmgr_trace_event_t state_event; - lmm_constraint_t constraint; } s_link_CM02_t, *link_CM02_t;