X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/a3141b2111e49b104c2c6b59fe9e61146a688d38..13c5da75068f441142fcf93d4d78124a7885d116:/src/surf/workstation_ptask_L07.c diff --git a/src/surf/workstation_ptask_L07.c b/src/surf/workstation_ptask_L07.c index 774d540c13..989379e83b 100644 --- a/src/surf/workstation_ptask_L07.c +++ b/src/surf/workstation_ptask_L07.c @@ -6,6 +6,7 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "xbt/ex.h" +#include "xbt/str.h" #include "xbt/dict.h" #include "surf_private.h" /* extern lmm_system_t maxmin_system; */ @@ -19,17 +20,17 @@ typedef enum { /********* cpu object *****************/ /**************************************/ typedef struct cpu_L07 { - surf_model_t model; /* Do not move this field */ - e_surf_workstation_model_type_t type; /* Do not move this field */ - char *name; /* Do not move this field */ - lmm_constraint_t constraint; /* Do not move this field */ + 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 */ + 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; tmgr_trace_event_t power_event; e_surf_cpu_state_t state_current; tmgr_trace_event_t state_event; int id; /* cpu and network card are a single object... */ - xbt_dict_t properties; } s_cpu_L07_t, *cpu_L07_t; /**************************************/ @@ -37,18 +38,17 @@ typedef struct cpu_L07 { /**************************************/ typedef struct link_L07 { - surf_model_t model; /* Do not move this field */ - e_surf_workstation_model_type_t type; /* Do not move this field */ - char *name; /* Do not move this field */ - lmm_constraint_t constraint; /* Do not move this field */ + 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 */ + 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; double bw_current; tmgr_trace_event_t bw_event; e_surf_link_state_t state_current; tmgr_trace_event_t state_event; - /*holds the property list that can be associated with the link*/ - xbt_dict_t properties; } s_link_L07_t, *link_L07_t; @@ -135,20 +135,24 @@ static const char *get_resource_name(void *resource_id) 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->using++; + action->refcount ++; return; } static int action_free(surf_action_t action) { - action->using--; + action->refcount --; - if (!action->using) { + if (!action->refcount ) { xbt_swag_remove(action, action->state_set); if (((surf_action_workstation_L07_t) action)->variable) lmm_variable_free(ptask_maxmin_system, @@ -357,7 +361,7 @@ static void update_actions_state(double now, double delta) static void update_resource_state(void *id, tmgr_trace_event_t event_type, - double value) + double value, double date) { cpu_L07_t cpu = id; link_L07_t nw_link = id; @@ -371,10 +375,11 @@ static void update_resource_state(void *id, } else if (event_type == nw_link->lat_event) { lmm_variable_t var = NULL; surf_action_workstation_L07_t action = NULL; + lmm_element_t elem = NULL; nw_link->lat_current = value; - while (lmm_get_var_from_cnst - (ptask_maxmin_system, nw_link->constraint, &var)) { + while ((var = lmm_get_var_from_cnst + (ptask_maxmin_system, nw_link->constraint, &elem))) { action = lmm_variable_id(var); @@ -396,7 +401,7 @@ static void update_resource_state(void *id, if (event_type == cpu->power_event) { cpu->power_current = value; lmm_update_constraint_bound(ptask_maxmin_system, cpu->constraint, - cpu->power_current); + cpu->power_current * cpu->power_scale); } else if (event_type == cpu->state_event) { if (value > 0) cpu->state_current = SURF_CPU_ON; @@ -470,12 +475,6 @@ static double get_available_speed(void *cpu) return ((cpu_L07_t) cpu)->power_current; } -static xbt_dict_t get_properties(void *cpu) -{ - return ((cpu_L07_t) cpu)->properties; -} - - static surf_action_t execute_parallel_task(int workstation_nb, void **workstation_list, double *computation_amount, @@ -488,10 +487,8 @@ static surf_action_t execute_parallel_task(int workstation_nb, int nb_host = 0; double latency = 0.0; - if (parallel_task_link_set == NULL) { - parallel_task_link_set = - xbt_dict_new_ext(workstation_nb * workstation_nb * 10); - } + if (parallel_task_link_set == NULL) + parallel_task_link_set = xbt_dict_new(); xbt_dict_reset(parallel_task_link_set); @@ -524,7 +521,7 @@ static surf_action_t execute_parallel_task(int workstation_nb, action = xbt_new0(s_surf_action_workstation_L07_t, 1); DEBUG3("Creating a parallel task (%p) with %d cpus and %d links.", action, workstation_nb, nb_link); - action->generic_action.using = 1; + action->generic_action.refcount = 1; action->generic_action.cost = amount; action->generic_action.remains = amount; action->generic_action.max_duration = NO_MAX_DURATION; @@ -545,14 +542,10 @@ static surf_action_t execute_parallel_task(int workstation_nb, xbt_swag_insert(action, action->generic_action.state_set); action->rate = rate; - if (action->rate > 0) - action->variable = - lmm_variable_new(ptask_maxmin_system, action, 1.0, -1.0, - workstation_nb + nb_link); - else - action->variable = - lmm_variable_new(ptask_maxmin_system, action, 1.0, action->rate, - workstation_nb + nb_link); + action->variable = + lmm_variable_new(ptask_maxmin_system, action, 1.0, + (action->rate>0)?action->rate:-1.0, + workstation_nb + nb_link); if (action->latency > 0) lmm_update_variable_weight(ptask_maxmin_system,action->variable,0.0); @@ -668,13 +661,11 @@ static double get_link_latency(const void *link) return ((link_L07_t) link)->lat_current; } - -static xbt_dict_t get_link_properties(void *link) +static int link_shared(const void *link) { - return ((link_L07_t) link)->properties; + return lmm_constraint_is_shared(((link_L07_t) link)->constraint); } - /**************************************/ /*** Resource Creation & Destruction **/ /**************************************/ @@ -682,6 +673,7 @@ static xbt_dict_t get_link_properties(void *link) static void cpu_free(void *cpu) { free(((cpu_L07_t) cpu)->name); + xbt_dict_free(&(((cpu_L07_t)cpu)->properties)); free(cpu); } @@ -693,6 +685,8 @@ static cpu_L07_t cpu_new(const char *name, double power_scale, 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), + "Host '%s' declared several times in the platform file.",name); cpu->model = (surf_model_t) surf_workstation_model; cpu->type = SURF_WORKSTATION_RESOURCE_CPU; @@ -720,6 +714,7 @@ static cpu_L07_t cpu_new(const char *name, double power_scale, cpu->properties = current_property_set; xbt_dict_set(workstation_set, name, cpu, cpu_free); + return cpu; } @@ -736,7 +731,7 @@ static void parse_cpu_init(void) e_surf_cpu_state_t state_initial = SURF_CPU_OFF; tmgr_trace_t state_trace = NULL; - surf_parse_get_double(&power_scale, A_surfxml_host_power); + power_scale = get_cpu_power(A_surfxml_host_power); surf_parse_get_double(&power_initial, A_surfxml_host_availability); surf_parse_get_trace(&power_trace, A_surfxml_host_availability_file); @@ -751,28 +746,30 @@ static void parse_cpu_init(void) current_property_set = xbt_dict_new(); cpu_new(A_surfxml_host_id, power_scale, power_initial, power_trace, - state_initial, state_trace,/*add the properties*/current_property_set); + 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, - double lat_initial, - tmgr_trace_t lat_trace, - e_surf_link_state_t - state_initial, - tmgr_trace_t state_trace, - e_surf_link_sharing_policy_t - policy, xbt_dict_t properties) -{ + double bw_initial, + tmgr_trace_t bw_trace, + double lat_initial, + tmgr_trace_t lat_trace, + e_surf_link_state_t + state_initial, + tmgr_trace_t state_trace, + e_surf_link_sharing_policy_t + 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), + "Link '%s' declared several times in the platform file.",name); nw_link->model = (surf_model_t) surf_workstation_model; nw_link->type = SURF_WORKSTATION_RESOURCE_LINK; @@ -843,33 +840,25 @@ static void parse_link_init(void) current_property_set = xbt_dict_new(); link_new(name_link, bw_initial, bw_trace, lat_initial, lat_trace, state_initial_link, state_trace, policy_initial_link, current_property_set); - } static void route_new(int src_id, int dst_id, - link_L07_t * link_list, int nb_link) + 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); + route->links = link_list = xbt_realloc(link_list, sizeof(link_L07_t) * nb_link); } -static int nb_link; -static int link_list_capacity; -static link_L07_t *link_list = NULL; + static int src_id = -1; static int dst_id = -1; -static int is_first =0; static void parse_route_set_endpoints(void) { cpu_L07_t cpu_tmp = NULL; - if (!is_first) create_routing_table(); - is_first = 1; - cpu_tmp = (cpu_L07_t) name_service(A_surfxml_route_src); xbt_assert1(cpu_tmp, "Invalid cpu %s", A_surfxml_route_src); if (cpu_tmp != NULL) @@ -880,54 +869,23 @@ static void parse_route_set_endpoints(void) if (cpu_tmp != NULL) dst_id = cpu_tmp->id; - nb_link = 0; - link_list_capacity = 1; - link_list = xbt_new(link_L07_t, link_list_capacity); -} - -static void parse_route_elem(void) -{ - xbt_ex_t e; - if (nb_link == link_list_capacity) { - link_list_capacity *= 2; - link_list = - xbt_realloc(link_list, - (link_list_capacity) * sizeof(link_L07_t)); - } - TRY { - link_list[nb_link++] = - xbt_dict_get(link_set, A_surfxml_link_c_ctn_id); - } - CATCH(e) { - RETHROW1("Link %s not found (dict raised this exception: %s)", - A_surfxml_link_c_ctn_id); - } + route_action = A_surfxml_route_action; } static void parse_route_set_route(void) { - if (src_id != -1 && dst_id != -1) - route_new(src_id, dst_id, link_list, nb_link); + 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 parse_file(const char *file) +static void add_loopback(void) { int i; - /* Adding callback functions */ - surf_parse_reset_parser(); - surfxml_add_callback(STag_surfxml_host_cb_list, &parse_cpu_init); - surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties); - 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_link_c_ctn_cb_list, &parse_route_elem); - surfxml_add_callback(ETag_surfxml_route_cb_list, &parse_route_set_route); - - /* Parse the file */ - surf_parse_open(file); - xbt_assert1((!surf_parse()), "Parse error in %s", file); - surf_parse_close(); - /* Adding loopback if needed */ for (i = 0; i < nb_workstation; i++) if (!ROUTE(i, i).size) { @@ -943,6 +901,146 @@ static void parse_file(const char *file) } } +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); + + 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; + char *trace_name,*elm; + + if (!trace_connect_list_host_avail) return; + + /* 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); + + xbt_assert1(host, "Host %s undefined", elm); + xbt_assert1(trace, "Trace %s undefined", trace_name); + + host->state_event = tmgr_history_add_trace(history, trace, 0.0, 0, host); + } + + 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); + + xbt_assert1(host, "Host %s undefined", elm); + xbt_assert1(trace, "Trace %s undefined", trace_name); + + host->power_event = tmgr_history_add_trace(history, trace, 0.0, 0, host); + } + + /* 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); + + xbt_assert1(link, "Link %s undefined", elm); + xbt_assert1(trace, "Trace %s undefined", trace_name); + + link->state_event = tmgr_history_add_trace(history, trace, 0.0, 0, link); + } + + 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); + + xbt_assert1(link, "Link %s undefined", elm); + xbt_assert1(trace, "Trace %s undefined", trace_name); + + link->bw_event = tmgr_history_add_trace(history, trace, 0.0, 0, link); + } + + 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); + + xbt_assert1(link, "Link %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) +{ + /* Adding callback functions */ + 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); +} + + /**************************************/ /********* Module creation ***********/ /**************************************/ @@ -1025,9 +1123,10 @@ static void model_init_internal(void) get_link_bandwidth; surf_workstation_model->extension_public->get_link_latency = get_link_latency; + surf_workstation_model->extension_public->link_shared = + link_shared; - surf_workstation_model->common_public->get_link_properties = get_link_properties; - surf_workstation_model->common_public->get_cpu_properties = get_properties; + surf_workstation_model->common_public->get_properties = get_properties; workstation_set = xbt_dict_new(); link_set = xbt_dict_new(); @@ -1045,11 +1144,10 @@ void surf_workstation_model_init_ptask_L07(const char *filename) xbt_assert0(!surf_network_model, "network model type already defined"); model_init_internal(); - parse_file(filename); + define_callbacks(filename); update_model_description(surf_workstation_model_description, - surf_workstation_model_description_size, - "ptask_L07", - (surf_model_t) surf_workstation_model); + "ptask_L07", + (surf_model_t) surf_workstation_model); xbt_dynar_push(model_list, &surf_workstation_model); }