From 93ca92954ae02f94f5df3d1a3b9f7b6ff5bd9cd2 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Fri, 4 Nov 2011 10:41:34 +0100 Subject: [PATCH 1/1] ensure that the create_resource functions do call strdup by themselves Also, ensure that the CPU models use surf_resource_new() instead of dupplicating its code --- src/include/surf/surf.h | 8 ++++---- src/include/surf/surf_resource.h | 4 ++-- src/include/surf/surf_resource_lmm.h | 2 +- src/surf/cpu.c | 9 ++++----- src/surf/cpu_im.c | 12 +++++------- src/surf/cpu_ti.c | 9 ++++----- src/surf/network.c | 2 +- src/surf/network_im.c | 2 +- src/surf/workstation_ptask_L07.c | 14 +++++++------- 9 files changed, 29 insertions(+), 33 deletions(-) diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index 52d11f3966..062d9ea9f8 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -169,7 +169,7 @@ typedef struct surf_cpu_model_extension_public { e_surf_resource_state_t(*get_state) (void *cpu); double (*get_speed) (void *cpu, double load); double (*get_available_speed) (void *cpu); - void* (*create_resource) (char *name, double power_peak, + void* (*create_resource) (const char *name, double power_peak, double power_scale, tmgr_trace_t power_trace, int core, @@ -195,7 +195,7 @@ typedef struct surf_network_model_extension_public { double (*get_link_latency) (const void *link); int (*link_shared) (const void *link); void (*add_traces) (void); - void* (*create_resource) (char *name, + void* (*create_resource) (const char *name, double bw_initial, tmgr_trace_t bw_trace, double lat_initial, @@ -233,7 +233,7 @@ typedef struct surf_workstation_model_extension_public { double (*get_link_latency) (const void *link); /**< Return the current latency of a network link */ int (*link_shared) (const void *link); xbt_dict_t(*get_properties) (const void *resource); - void* (*link_create_resource) (char *name, + void* (*link_create_resource) (const char *name, double bw_initial, tmgr_trace_t bw_trace, double lat_initial, @@ -243,7 +243,7 @@ typedef struct surf_workstation_model_extension_public { tmgr_trace_t state_trace, e_surf_link_sharing_policy_t policy, xbt_dict_t properties); - void* (*cpu_create_resource) (char *name, double power_peak, + void* (*cpu_create_resource) (const char *name, double power_peak, double power_scale, tmgr_trace_t power_trace, e_surf_resource_state_t state_initial, diff --git a/src/include/surf/surf_resource.h b/src/include/surf/surf_resource.h index 625fd9ff9e..d0a14d53d5 100644 --- a/src/include/surf/surf_resource.h +++ b/src/include/surf/surf_resource.h @@ -11,12 +11,12 @@ static XBT_INLINE surf_resource_t surf_resource_new(size_t childsize, - surf_model_t model, char *name, + surf_model_t model, const char *name, xbt_dict_t props) { surf_resource_t res = xbt_malloc0(childsize); res->model = model; - res->name = name; + res->name = xbt_strdup(name); res->properties = props; return res; } diff --git a/src/include/surf/surf_resource_lmm.h b/src/include/surf/surf_resource_lmm.h index 237c7b1bfd..e1c3a0b11b 100644 --- a/src/include/surf/surf_resource_lmm.h +++ b/src/include/surf/surf_resource_lmm.h @@ -14,7 +14,7 @@ static XBT_INLINE surf_resource_lmm_t surf_resource_lmm_new(size_t childsize, /* for superclass */ surf_model_t model, - char *name, xbt_dict_t props, + const char *name, xbt_dict_t props, lmm_system_t system, double constraint_value, tmgr_history_t history, diff --git a/src/surf/cpu.c b/src/surf/cpu.c index 3be6a3f85c..2124426359 100644 --- a/src/surf/cpu.c +++ b/src/surf/cpu.c @@ -32,7 +32,7 @@ lmm_system_t cpu_maxmin_system = NULL; static xbt_swag_t cpu_running_action_set_that_does_not_need_being_checked = NULL; -static void* cpu_create_resource(char *name, double power_peak, +static void* cpu_create_resource(const char *name, double power_peak, double power_scale, tmgr_trace_t power_trace, int core, @@ -41,13 +41,12 @@ static void* cpu_create_resource(char *name, double power_peak, xbt_dict_t cpu_properties) { - cpu_Cas01_t cpu = xbt_new0(s_cpu_Cas01_t, 1); + cpu_Cas01_t cpu = NULL; xbt_assert(!surf_cpu_resource_by_name(name), "Host '%s' declared several times in the platform file", name); - cpu->generic_resource.model = surf_cpu_model; - cpu->generic_resource.name = name; - cpu->generic_resource.properties = cpu_properties; + cpu = (cpu_Cas01_t) surf_resource_new(sizeof(s_cpu_Cas01_t), + surf_cpu_model, name,cpu_properties); cpu->power_peak = power_peak; xbt_assert(cpu->power_peak > 0, "Power has to be >0"); cpu->power_scale = power_scale; diff --git a/src/surf/cpu_im.c b/src/surf/cpu_im.c index ccf3e5655a..caa3a9d284 100644 --- a/src/surf/cpu_im.c +++ b/src/surf/cpu_im.c @@ -47,7 +47,7 @@ extern int sg_maxmin_selective_update; static xbt_swag_t cpu_im_running_action_set_that_does_not_need_being_checked = NULL; -static void* cpu_im_create_resource(char *name, double power_peak, +static void* cpu_im_create_resource(const char *name, double power_peak, double power_scale, tmgr_trace_t power_trace, int core, @@ -57,14 +57,12 @@ static void* cpu_im_create_resource(char *name, double power_peak, { cpu_Cas01_im_t cpu = NULL; s_surf_action_cpu_Cas01_im_t action; - cpu = xbt_new0(s_cpu_Cas01_im_t, 1); xbt_assert(!surf_cpu_resource_by_name(name), "Host '%s' declared several times in the platform file", name); - cpu->generic_resource.model = surf_cpu_model; - cpu->generic_resource.name = name; - cpu->generic_resource.properties = cpu_properties; + cpu = (cpu_Cas01_im_t) surf_resource_new(sizeof(s_cpu_Cas01_im_t), + surf_cpu_model, name,cpu_properties); cpu->power_peak = power_peak; xbt_assert(cpu->power_peak > 0, "Power has to be >0"); cpu->power_scale = power_scale; @@ -143,10 +141,10 @@ static void cpu_im_define_callbacks() &cpu_im_add_traces_cpu); } -static int cpu_im_resource_used(void *resource_id) +static int cpu_im_resource_used(void *resource) { return lmm_constraint_used(cpu_im_maxmin_system, - ((cpu_Cas01_im_t) resource_id)->constraint); + ((cpu_Cas01_im_t) resource)->constraint); } static int cpu_im_action_unref(surf_action_t action) diff --git a/src/surf/cpu_ti.c b/src/surf/cpu_ti.c index 41e3bc1afe..b18b735c25 100644 --- a/src/surf/cpu_ti.c +++ b/src/surf/cpu_ti.c @@ -143,7 +143,7 @@ static surf_cpu_ti_tgmr_t cpu_ti_parse_trace(tmgr_trace_t power_trace, } -static void* cpu_ti_create_resource(char *name, double power_peak, +static void* cpu_ti_create_resource(const char *name, double power_peak, double power_scale, tmgr_trace_t power_trace, int core, @@ -153,18 +153,17 @@ static void* cpu_ti_create_resource(char *name, double power_peak, { tmgr_trace_t empty_trace; s_tmgr_event_t val; - cpu_ti_t cpu = xbt_new0(s_cpu_ti_t, 1); + cpu_ti_t cpu = NULL; s_surf_action_cpu_ti_t ti_action; xbt_assert(core==1,"Multi-core not handled with this model yet"); xbt_assert(!surf_cpu_resource_by_name(name), "Host '%s' declared several times in the platform file", name); xbt_assert(core==1,"Multi-core not handled with this model yet"); + cpu = (cpu_ti_t) surf_resource_new(sizeof(s_cpu_ti_t), + surf_cpu_model, name,cpu_properties); cpu->action_set = xbt_swag_new(xbt_swag_offset(ti_action, cpu_list_hookup)); - cpu->generic_resource.model = surf_cpu_model; - cpu->generic_resource.name = name; - cpu->generic_resource.properties = cpu_properties; cpu->power_peak = power_peak; xbt_assert(cpu->power_peak > 0, "Power has to be >0"); XBT_DEBUG("power scale %lf", power_scale); diff --git a/src/surf/network.c b/src/surf/network.c index 8984b41109..2d4158cda3 100644 --- a/src/surf/network.c +++ b/src/surf/network.c @@ -155,7 +155,7 @@ static double (*bandwidth_constraint_callback) (double, double, double) = &constant_bandwidth_constraint; -static void* net_create_resource(char *name, +static void* net_create_resource(const char *name, double bw_initial, tmgr_trace_t bw_trace, double lat_initial, diff --git a/src/surf/network_im.c b/src/surf/network_im.c index 668c2f2b93..7a4887c2f2 100644 --- a/src/surf/network_im.c +++ b/src/surf/network_im.c @@ -150,7 +150,7 @@ static double (*im_bandwidth_constraint_callback) (double, double, double) = &im_constant_bandwidth_constraint; -static void* im_net_create_resource(char *name, +static void* im_net_create_resource(const char *name, double bw_initial, tmgr_trace_t bw_trace, double lat_initial, diff --git a/src/surf/workstation_ptask_L07.c b/src/surf/workstation_ptask_L07.c index 709e1a95ef..1878ea44c2 100644 --- a/src/surf/workstation_ptask_L07.c +++ b/src/surf/workstation_ptask_L07.c @@ -614,22 +614,22 @@ static int ptask_link_shared(const void *link) /*** Resource Creation & Destruction **/ /**************************************/ -static void* ptask_cpu_create_resource(char *name, double power_scale, +static void* ptask_cpu_create_resource(const char *name, double power_scale, double power_initial, tmgr_trace_t power_trace, e_surf_resource_state_t state_initial, tmgr_trace_t state_trace, xbt_dict_t cpu_properties) { - cpu_L07_t cpu = xbt_new0(s_cpu_L07_t, 1); + cpu_L07_t cpu = NULL; xbt_assert(!surf_workstation_resource_by_name(name), "Host '%s' declared several times in the platform file.", name); - cpu->generic_resource.model = surf_workstation_model; + cpu = (cpu_L07_t) surf_resource_new(sizeof(s_cpu_L07_t), + surf_workstation_model, name,cpu_properties); + cpu->type = SURF_WORKSTATION_RESOURCE_CPU; - cpu->generic_resource.name = xbt_strdup(name); - cpu->generic_resource.properties = cpu_properties; cpu->id = ptask_host_count++; cpu->power_scale = power_scale; @@ -667,7 +667,7 @@ static void ptask_parse_cpu_init(void) current_property_set=NULL; } -static void* ptask_link_create_resource(char *name, +static void* ptask_link_create_resource(const char *name, double bw_initial, tmgr_trace_t bw_trace, double lat_initial, @@ -685,7 +685,7 @@ static void* ptask_link_create_resource(char *name, nw_link->generic_resource.model = surf_workstation_model; nw_link->generic_resource.properties = properties; - nw_link->generic_resource.name = name; + nw_link->generic_resource.name = xbt_strdup(name); nw_link->type = SURF_WORKSTATION_RESOURCE_LINK; nw_link->bw_current = bw_initial; if (bw_trace) -- 2.20.1