From: mquinson Date: Thu, 2 Jul 2009 07:59:18 +0000 (+0000) Subject: Integrate properties into surf_resource_t X-Git-Tag: SVN~1205 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/8308c42874c76edaffd662b81eaacc6ad87b36e4?ds=sidebyside Integrate properties into surf_resource_t git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@6436 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/ChangeLog b/ChangeLog index 6b8bc0689f..78a962dbde 100644 --- a/ChangeLog +++ b/ChangeLog @@ -30,7 +30,9 @@ SimGrid (3.3.2-svn) unstable; urgency=low * Implement a generic resource; use it as ancestor to specific ones (allows to kill duplicated code in models) - TODO: integrate the properties into that ancestor + Drawback: timer command don't need no name nor properties; + workstation_CLM03 don't need no properties + (but I guess we can live with those few bytes wasted) XBT: * Add xbt_set_get_by_name_or_null() [Silas De Munck] diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index 3f17b78073..2790d9bce6 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -230,7 +230,6 @@ XBT_PUBLIC(int) find_model_description(s_surf_model_description_t * table, void (*set_max_duration) (surf_action_t action, double duration);/**< Set the max duration of an action*/ void (*set_priority) (surf_action_t action, double priority);/**< Set the priority of an action */ - xbt_dict_t(*get_properties) (void *resource_id);/**< Return the properties dictionary */ xbt_dict_t resource_set; @@ -256,9 +255,11 @@ XBT_PUBLIC(int) find_model_description(s_surf_model_description_t * table, typedef struct surf_resource { surf_model_t model; char *name; + xbt_dict_t properties; } s_surf_resource_t, *surf_resource_t; -XBT_PUBLIC(const char*) surf_resource_name(const void *resource); + XBT_PUBLIC(const char*) surf_resource_name(const void *resource); + XBT_PUBLIC(xbt_dict_t) surf_resource_properties(const void *resource); XBT_PUBLIC(void) surf_resource_free(void* resource); /**************************************/ /* Implementations of model object */ diff --git a/src/simdag/sd_link.c b/src/simdag/sd_link.c index 27b2d8bbc7..5cc896b82a 100644 --- a/src/simdag/sd_link.c +++ b/src/simdag/sd_link.c @@ -153,7 +153,7 @@ xbt_dict_t SD_link_get_properties(SD_link_t link) SD_CHECK_INIT_DONE(); xbt_assert0((link != NULL), "Invalid parameters"); - return (surf_workstation_model->get_properties(link->surf_link)); + return surf_resource_properties(link->surf_link); } diff --git a/src/simdag/sd_workstation.c b/src/simdag/sd_workstation.c index f8bf3c05fa..cad1f73705 100644 --- a/src/simdag/sd_workstation.c +++ b/src/simdag/sd_workstation.c @@ -162,8 +162,7 @@ xbt_dict_t SD_workstation_get_properties(SD_workstation_t workstation) SD_CHECK_INIT_DONE(); xbt_assert0((workstation != NULL), "Invalid parameters"); - return (surf_workstation_model->get_properties - (workstation->surf_workstation)); + return surf_resource_properties(workstation->surf_workstation); } diff --git a/src/simix/smx_host.c b/src/simix/smx_host.c index cfb76cfb4c..73f4cfb730 100644 --- a/src/simix/smx_host.c +++ b/src/simix/smx_host.c @@ -233,7 +233,7 @@ xbt_dict_t SIMIX_host_get_properties(smx_host_t host) { xbt_assert0((host != NULL), "Invalid parameters"); - return (surf_workstation_model->get_properties(host->simdata->host)); + return surf_resource_properties(host->simdata->host); } diff --git a/src/surf/cpu.c b/src/surf/cpu.c index ba3fa0cf5f..ca63f90633 100644 --- a/src/surf/cpu.c +++ b/src/surf/cpu.c @@ -21,8 +21,6 @@ typedef struct cpu_Cas01 { e_surf_cpu_state_t state_current; tmgr_trace_event_t state_event; lmm_constraint_t constraint; - /*Handles the properties that can be added to cpu's */ - xbt_dict_t properties; } s_cpu_Cas01_t, *cpu_Cas01_t; XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_cpu, surf, @@ -36,12 +34,6 @@ lmm_system_t cpu_maxmin_system = NULL; static xbt_swag_t running_action_set_that_does_not_need_being_checked = NULL; -static void cpu_free(void *cpu) -{ - xbt_dict_free(&(((cpu_Cas01_t) cpu)->properties)); - surf_resource_free(cpu); -} - static cpu_Cas01_t cpu_new(char *name, double power_scale, double power_initial, tmgr_trace_t power_trace, @@ -54,6 +46,7 @@ static cpu_Cas01_t cpu_new(char *name, double power_scale, "Host '%s' declared several times in the platform file", name); cpu->generic_resource.model = surf_cpu_model; cpu->generic_resource.name = name; + current_property_set = cpu->generic_resource.properties = cpu_properties; cpu->power_scale = power_scale; xbt_assert0(cpu->power_scale > 0, "Power has to be >0"); cpu->power_current = power_initial; @@ -70,12 +63,7 @@ static cpu_Cas01_t cpu_new(char *name, double power_scale, lmm_constraint_new(cpu_maxmin_system, cpu, cpu->power_current * cpu->power_scale); - /*add the property set */ - cpu->properties = cpu_properties; - - current_property_set = cpu_properties; - - xbt_dict_set(surf_model_resource_set(surf_cpu_model), name, cpu, cpu_free); + xbt_dict_set(surf_model_resource_set(surf_cpu_model), name, cpu, surf_resource_free); return cpu; } @@ -388,11 +376,6 @@ static double get_available_speed(void *cpu) return ((cpu_Cas01_t) cpu)->power_current; } -static xbt_dict_t get_properties(void *cpu) -{ - return ((cpu_Cas01_t) cpu)->properties; -} - static void finalize(void) { lmm_system_free(cpu_maxmin_system); @@ -438,8 +421,6 @@ static void surf_cpu_model_init_internal(void) surf_cpu_model->extension.cpu.get_state = get_state; surf_cpu_model->extension.cpu.get_speed = get_speed; surf_cpu_model->extension.cpu.get_available_speed = get_available_speed; - /*manage the properties of the cpu */ - surf_cpu_model->get_properties = get_properties; if (!cpu_maxmin_system) cpu_maxmin_system = lmm_system_new(); diff --git a/src/surf/network.c b/src/surf/network.c index a5edbe0512..d55e71b072 100644 --- a/src/surf/network.c +++ b/src/surf/network.c @@ -25,11 +25,6 @@ int host_count = 0; double sg_tcp_gamma = 0.0; -static void link_free(void *nw_link) -{ - xbt_dict_free(&(((link_CM02_t) nw_link)->properties)); - surf_resource_free(nw_link); -} static link_CM02_t link_new(char *name, double bw_initial, @@ -48,6 +43,7 @@ static link_CM02_t link_new(char *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 = @@ -68,11 +64,7 @@ static link_CM02_t link_new(char *name, if (policy == SURF_LINK_FATPIPE) lmm_constraint_shared(nw_link->constraint); - nw_link->properties = properties; - - current_property_set = properties; - - xbt_dict_set(surf_network_model->resource_set, name, nw_link, link_free); + xbt_dict_set(surf_network_model->resource_set, name, nw_link, surf_resource_free); return nw_link; } @@ -464,11 +456,6 @@ static int link_shared(const void *link) return lmm_constraint_is_shared(((link_CM02_t) link)->constraint); } -static xbt_dict_t get_properties(void *link) -{ - return ((link_CM02_t) link)->properties; -} - static void action_suspend(surf_action_t action) { ((surf_action_network_CM02_t) action)->suspended = 1; @@ -537,8 +524,6 @@ static void surf_network_model_init_internal(void) surf_network_model->extension.network.get_link_latency = get_link_latency; surf_network_model->extension.network.link_shared = link_shared; - surf_network_model->get_properties = get_properties; - if (!network_maxmin_system) network_maxmin_system = lmm_system_new(); diff --git a/src/surf/network_constant.c b/src/surf/network_constant.c index c75fb23d50..7ed8284b37 100644 --- a/src/surf/network_constant.c +++ b/src/surf/network_constant.c @@ -175,11 +175,6 @@ static int link_shared(const void *link) DIE_IMPOSSIBLE; } -static xbt_dict_t get_properties(void *link) -{ - DIE_IMPOSSIBLE; -} - static void action_suspend(surf_action_t action) { ((surf_action_network_Constant_t) action)->suspended = 1; @@ -237,8 +232,6 @@ static void surf_network_model_init_internal(void) surf_network_model->extension.network.get_link_latency = get_link_latency; surf_network_model->extension.network.link_shared = link_shared; - surf_network_model->get_properties = get_properties; - if (!random_latency) random_latency = random_new(RAND, 100, 0.0, 1.0, .125, .034); } diff --git a/src/surf/network_gtnets_private.h b/src/surf/network_gtnets_private.h index 0687521ca9..c7375f1816 100644 --- a/src/surf/network_gtnets_private.h +++ b/src/surf/network_gtnets_private.h @@ -18,16 +18,12 @@ typedef struct network_link_GTNETS { double bw_current; double lat_current; int id; - /*holds the properties associated with the link */ - xbt_dict_t properties; } s_network_link_GTNETS_t, *network_link_GTNETS_t; typedef struct network_card_GTNETS { char *name; int id; - /*holds the properties associated with the card */ - xbt_dict_t properties; } s_network_card_GTNETS_t, *network_card_GTNETS_t; typedef struct surf_action_network_GTNETS { diff --git a/src/surf/network_private.h b/src/surf/network_private.h index eeac6d0a4e..98f984d3c2 100644 --- a/src/surf/network_private.h +++ b/src/surf/network_private.h @@ -15,7 +15,6 @@ typedef struct network_link_CM02 { 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 */ double bw_current; diff --git a/src/surf/surf_resource.c b/src/surf/surf_resource.c index 111408b7ae..4c2e821411 100644 --- a/src/surf/surf_resource.c +++ b/src/surf/surf_resource.c @@ -11,6 +11,8 @@ void surf_resource_free(void* r) { surf_resource_t resource = r; if (resource->name) free(resource->name); + if (resource->properties) + xbt_dict_free(&resource->properties); free(resource); } diff --git a/src/surf/workstation.c b/src/surf/workstation.c index ce87967565..92e8a9dc8f 100644 --- a/src/surf/workstation.c +++ b/src/surf/workstation.c @@ -216,12 +216,6 @@ static double get_available_speed(void *workstation) workstation)->cpu); } -static xbt_dict_t get_properties(void *workstation) -{ - return surf_cpu_model->get_properties(((workstation_CLM03_t) workstation)-> - cpu); -} - static surf_action_t execute_parallel_task(int workstation_nb, void **workstation_list, double *computation_amount, @@ -292,9 +286,6 @@ static void surf_workstation_model_init_internal(void) surf_workstation_model->extension.workstation.get_available_speed = get_available_speed; - /*manage the properties of the workstation */ - surf_workstation_model->get_properties = get_properties; - surf_workstation_model->extension.workstation.communicate = communicate; surf_workstation_model->extension.workstation.get_route = get_route; surf_workstation_model->extension.workstation.execute_parallel_task = diff --git a/src/surf/workstation_ptask_L07.c b/src/surf/workstation_ptask_L07.c index 5d98c7bbaf..7793af265e 100644 --- a/src/surf/workstation_ptask_L07.c +++ b/src/surf/workstation_ptask_L07.c @@ -20,7 +20,6 @@ typedef enum { /**************************************/ typedef struct cpu_L07 { 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 */ lmm_constraint_t constraint; /* Do not move this field: must match link_L07_t */ double power_scale; @@ -37,7 +36,6 @@ typedef struct cpu_L07 { typedef struct link_L07 { 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 */ lmm_constraint_t constraint; /* Do not move this field: must match cpu_L07_t */ double lat_current; @@ -113,12 +111,6 @@ static void update_action_bound(surf_action_workstation_L07_t action) /******* Resource Public **********/ /**************************************/ -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; -} - static int action_unref(surf_action_t action) { action->refcount--; @@ -599,12 +591,6 @@ static int link_shared(const void *link) /*** Resource Creation & Destruction **/ /**************************************/ -static void cpu_free(void *cpu) -{ - xbt_dict_free(&(((cpu_L07_t) cpu)->properties)); - surf_resource_free(cpu); -} - static cpu_L07_t cpu_new(const char *name, double power_scale, double power_initial, tmgr_trace_t power_trace, @@ -618,6 +604,7 @@ static cpu_L07_t cpu_new(const char *name, double power_scale, cpu->generic_resource.model = surf_workstation_model; cpu->type = SURF_WORKSTATION_RESOURCE_CPU; cpu->generic_resource.name = xbt_strdup(name); + cpu->generic_resource.properties = current_property_set; cpu->id = host_count++; cpu->power_scale = power_scale; @@ -637,11 +624,8 @@ static cpu_L07_t cpu_new(const char *name, double power_scale, 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; } @@ -672,12 +656,6 @@ static void parse_cpu_init(void) state_initial, state_trace, current_property_set); } -static void link_free(void *nw_link) -{ - xbt_dict_free(&(((link_L07_t) nw_link)->properties)); - surf_resource_free(nw_link); -} - static link_L07_t link_new(char *name, double bw_initial, tmgr_trace_t bw_trace, @@ -694,8 +672,9 @@ static link_L07_t link_new(char *name, "Link '%s' declared several times in the platform file.", name); nw_link->generic_resource.model = surf_workstation_model; - nw_link->type = SURF_WORKSTATION_RESOURCE_LINK; + nw_link->generic_resource.properties = properties; nw_link->generic_resource.name = name; + nw_link->type = SURF_WORKSTATION_RESOURCE_LINK; nw_link->bw_current = bw_initial; if (bw_trace) nw_link->bw_event = @@ -715,9 +694,8 @@ static link_L07_t link_new(char *name, if (policy == SURF_LINK_FATPIPE) lmm_constraint_shared(nw_link->constraint); - nw_link->properties = properties; - xbt_dict_set(surf_network_model->resource_set, name, nw_link, link_free); + xbt_dict_set(surf_network_model->resource_set, name, nw_link, surf_resource_free); return nw_link; } @@ -875,8 +853,6 @@ static void model_init_internal(void) get_link_latency; surf_workstation_model->extension.workstation.link_shared = link_shared; - surf_workstation_model->get_properties = get_properties; - if (!ptask_maxmin_system) ptask_maxmin_system = lmm_system_new();