X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/90750b2b8f84e51c766470561fbaed1de51e91b0..f8f0be85ee23b69476ce45197e33bb96bfdbdd98:/src/surf/workstation_KCCFLN05.c diff --git a/src/surf/workstation_KCCFLN05.c b/src/surf/workstation_KCCFLN05.c index f6a709e265..49173ae975 100644 --- a/src/surf/workstation_KCCFLN05.c +++ b/src/surf/workstation_KCCFLN05.c @@ -9,15 +9,19 @@ #include "xbt/dict.h" #include "workstation_KCCFLN05_private.h" -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(workstation_KCCFLN05, surf, +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_workstation, surf, "Logging specific to the SURF workstation module (KCCFLN05)"); static int nb_workstation = 0; static s_route_KCCFLN05_t *routing_table = NULL; #define ROUTE(i,j) routing_table[(i)+(j)*nb_workstation] static network_link_KCCFLN05_t loopback = NULL; +static xbt_dict_t parallel_task_network_link_set = NULL; +//added to work with GTNETS +static xbt_dict_t router_set = NULL; + +/*xbt_dict_t network_link_set = NULL;*/ -static xbt_dict_t network_link_set = NULL; /* convenient function */ static void __update_cpu_usage(cpu_KCCFLN05_t cpu) @@ -75,7 +79,31 @@ static void __update_cpu_usage(cpu_KCCFLN05_t cpu) static void *name_service(const char *name) { - return xbt_dict_get_or_null(workstation_set, name); + xbt_ex_t e; + void *res=NULL; + + + + TRY { + res = xbt_dict_get_or_null(workstation_set, name); + } CATCH(e) { + WARN1("Host '%s' not found, verifing if it is a router", name); + res = NULL; + } + + + if(res == NULL){ + TRY { + res = xbt_dict_get_or_null(router_set, name); + } CATCH(e) { + if (e.category != not_found_error) + RETHROW; + xbt_ex_free(e); + res = NULL; + } + } + + return res; } static const char *get_resource_name(void *resource_id) @@ -151,32 +179,36 @@ static void action_recycle(surf_action_t action) static void action_suspend(surf_action_t action) { XBT_IN1("(%p))",action); - ((surf_action_workstation_KCCFLN05_t) action)->suspended = 1; - lmm_update_variable_weight(maxmin_system, - ((surf_action_workstation_KCCFLN05_t) - action)->variable, 0.0); + if(((surf_action_workstation_KCCFLN05_t) action)->suspended != 2) { + ((surf_action_workstation_KCCFLN05_t) action)->suspended = 1; + lmm_update_variable_weight(maxmin_system, + ((surf_action_workstation_KCCFLN05_t) + action)->variable, 0.0); + } XBT_OUT; } static void action_resume(surf_action_t action) { XBT_IN1("(%p)",action); - if(((surf_action_workstation_KCCFLN05_t)action)->lat_current==0.0) - lmm_update_variable_weight(maxmin_system, - ((surf_action_workstation_KCCFLN05_t) - action)->variable, 1.0); - else - lmm_update_variable_weight(maxmin_system, - ((surf_action_workstation_KCCFLN05_t) action)->variable, - ((surf_action_workstation_KCCFLN05_t) action)->lat_current); - - ((surf_action_workstation_KCCFLN05_t) action)->suspended = 0; + if(((surf_action_workstation_KCCFLN05_t) action)->suspended !=2) { + if(((surf_action_workstation_KCCFLN05_t)action)->lat_current==0.0) + lmm_update_variable_weight(maxmin_system, + ((surf_action_workstation_KCCFLN05_t) + action)->variable, 1.0); + else + lmm_update_variable_weight(maxmin_system, + ((surf_action_workstation_KCCFLN05_t) action)->variable, + ((surf_action_workstation_KCCFLN05_t) action)->lat_current); + + ((surf_action_workstation_KCCFLN05_t) action)->suspended = 0; + } XBT_OUT; } static int action_is_suspended(surf_action_t action) { - return (((surf_action_workstation_KCCFLN05_t) action)->suspended); + return (((surf_action_workstation_KCCFLN05_t) action)->suspended==1); } static void action_set_max_duration(surf_action_t action, double duration) @@ -228,15 +260,22 @@ static double share_resources(double now) xbt_swag_foreach(action, running_actions) { if(action->latency>0) { - if(min<0) min = action->latency; - else if (action->latencylatency; + if(min<0) { + min = action->latency; + DEBUG3("Updating min (value) with %p (start %f): %f",action, + action->generic_action.start, min); + } + else if (action->latencylatency; + DEBUG3("Updating min (latency) with %p (start %f): %f",action, + action->generic_action.start, min); + } } } + DEBUG1("min value : %f",min); + return min; -/* return generic_maxmin_share_resources(surf_workstation_resource->common_public-> */ -/* states.running_action_set, */ -/* xbt_swag_offset(action, variable)); */ } static void update_actions_state(double now, double delta) @@ -251,13 +290,13 @@ static void update_actions_state(double now, double delta) deltap = delta; if (action->latency > 0) { if (action->latency > deltap) { - surf_double_update(&(action->latency), deltap); + double_update(&(action->latency), deltap); deltap = 0.0; } else { - surf_double_update(&(deltap), action->latency); + double_update(&(deltap), action->latency); action->latency = 0.0; } - if ((action->latency == 0.0) && !(action->suspended)) { + if ((action->latency == 0.0) && (action->suspended==0)) { if((action)->lat_current==0.0) lmm_update_variable_weight(maxmin_system,action->variable, 1.0); else @@ -265,10 +304,14 @@ static void update_actions_state(double now, double delta) action->lat_current); } } - surf_double_update(&(action->generic_action.remains), + DEBUG3("Action (%p) : remains (%g) updated by %g.", + action, action->generic_action.remains, + lmm_variable_getvalue(action->variable) * deltap); + double_update(&(action->generic_action.remains), lmm_variable_getvalue(action->variable) * deltap); + if (action->generic_action.max_duration != NO_MAX_DURATION) - surf_double_update(&(action->generic_action.max_duration), delta); + double_update(&(action->generic_action.max_duration), delta); /* if(action->generic_action.remains<.00001) action->generic_action.remains=0; */ @@ -334,9 +377,12 @@ static void update_resource_state(void *id, else lmm_update_variable_bound(maxmin_system, action->variable, min(action->rate,SG_TCP_CTE_GAMMA / (2.0 * action->lat_current))); - if(!(action->suspended)) + if(action->suspended==0) lmm_update_variable_weight(maxmin_system, action->variable, action->lat_current); + lmm_update_variable_latency(maxmin_system, action->variable, delta); + + } } else if (event_type == nw_link->state_event) { if (value > 0) @@ -374,6 +420,10 @@ static void finalize(void) xbt_dict_free(&network_link_set); xbt_dict_free(&workstation_set); + xbt_dict_free(&router_set); + if (parallel_task_network_link_set != NULL) { + xbt_dict_free(¶llel_task_network_link_set); + } xbt_swag_free(surf_workstation_resource->common_public->states. ready_action_set); xbt_swag_free(surf_workstation_resource->common_public->states. @@ -450,6 +500,7 @@ static surf_action_t action_sleep(void *cpu, double duration) action = (surf_action_workstation_KCCFLN05_t) execute(cpu, 1.0); action->generic_action.max_duration = duration; + action->suspended = 2; lmm_update_variable_weight(maxmin_system, action->variable, 0.0); XBT_OUT; @@ -466,6 +517,12 @@ static double get_speed(void *cpu, double load) return load*(((cpu_KCCFLN05_t) cpu)->power_scale); } +static double get_available_speed(void *cpu) +{ + return ((cpu_KCCFLN05_t) cpu)->power_current; +} + + static surf_action_t communicate(void *src, void *dst, double size, double rate) { surf_action_workstation_KCCFLN05_t action = NULL; @@ -484,7 +541,7 @@ static surf_action_t communicate(void *src, void *dst, double size, double rate) action->generic_action.cost = size; action->generic_action.remains = size; action->generic_action.max_duration = NO_MAX_DURATION; - action->generic_action.start = -1.0; + action->generic_action.start = surf_get_clock(); action->generic_action.finish = -1.0; action->src = src; action->dst = dst; @@ -530,6 +587,8 @@ static surf_action_t communicate(void *src, void *dst, double size, double rate) lmm_update_variable_bound(maxmin_system, action->variable, action->rate); } + lmm_update_variable_latency(maxmin_system, action->variable, action->latency); + for (i = 0; i < route_size; i++) lmm_expand(maxmin_system, route->links[i]->constraint, action->variable, 1.0); if (card_src->bus) @@ -543,23 +602,155 @@ static surf_action_t communicate(void *src, void *dst, double size, double rate) return (surf_action_t) action; } -/* FIXME: execute_parallel_task */ -static surf_action_t execute_parallel_task(int cpu_nb, - void **cpu_list, +static surf_action_t execute_parallel_task(int workstation_nb, + void **workstation_list, double *computation_amount, double *communication_amount, double amount, double rate) { - DIE_IMPOSSIBLE; - return NULL; + surf_action_workstation_KCCFLN05_t action = NULL; + int i, j, k; + int nb_link = 0; + int nb_host = 0; + + if (parallel_task_network_link_set == NULL) { + parallel_task_network_link_set = xbt_dict_new_ext(workstation_nb * workstation_nb * 10); + } + + /* Compute the number of affected resources... */ + for(i=0; i< workstation_nb; i++) { + for(j=0; j< workstation_nb; j++) { + cpu_KCCFLN05_t card_src = workstation_list[i]; + cpu_KCCFLN05_t card_dst = workstation_list[j]; + int route_size = ROUTE(card_src->id, card_dst->id).size; + network_link_KCCFLN05_t *route = ROUTE(card_src->id, card_dst->id).links; + + if(communication_amount[i*workstation_nb+j]>0) + for(k=0; k< route_size; k++) { + xbt_dict_set(parallel_task_network_link_set, route[k]->name, route[k], NULL); + } + } + } + nb_link = xbt_dict_length(parallel_task_network_link_set); + xbt_dict_reset(parallel_task_network_link_set); + + + for (i = 0; i0) nb_host++; + + + if(nb_link + nb_host == 0) /* was workstation_nb... */ + return NULL; + + action = xbt_new0(s_surf_action_workstation_KCCFLN05_t, 1); + DEBUG3("Creating a parallel task (%p) with %d cpus and %d links.", + action, nb_host, nb_link); + action->generic_action.using = 1; + action->generic_action.cost = amount; + action->generic_action.remains = amount; + action->generic_action.max_duration = NO_MAX_DURATION; + action->generic_action.start = -1.0; + action->generic_action.finish = -1.0; + action->generic_action.resource_type = + (surf_resource_t) surf_workstation_resource; + action->suspended = 0; /* Should be useless because of the + calloc but it seems to help valgrind... */ + action->generic_action.state_set = + surf_workstation_resource->common_public->states.running_action_set; + + xbt_swag_insert(action, action->generic_action.state_set); + action->rate = rate; + + if(action->rate>0) + action->variable = lmm_variable_new(maxmin_system, action, 1.0, -1.0, + nb_host + nb_link); + else + action->variable = lmm_variable_new(maxmin_system, action, 1.0, action->rate, + nb_host + nb_link); + + for (i = 0; i0) + lmm_expand(maxmin_system, ((cpu_KCCFLN05_t) workstation_list[i])->constraint, + action->variable, computation_amount[i]); + + for (i=0; iid, card_dst->id).size; + network_link_KCCFLN05_t *route = ROUTE(card_src->id, card_dst->id).links; + + for(k=0; k< route_size; k++) { + if(communication_amount[i*workstation_nb+j]>0) { + lmm_expand_add(maxmin_system, route[k]->constraint, + action->variable, communication_amount[i*workstation_nb+j]); + } + } + } + } + + return (surf_action_t) action; } +/* returns an array of network_link_KCCFLN05_t */ +static const void** get_route(void *src, void *dst) { + cpu_KCCFLN05_t card_src = src; + cpu_KCCFLN05_t card_dst = dst; + route_KCCFLN05_t route = &(ROUTE(card_src->id, card_dst->id)); + + return (const void**) route->links; +} + +static int get_route_size(void *src, void *dst) { + cpu_KCCFLN05_t card_src = src; + cpu_KCCFLN05_t card_dst = dst; + route_KCCFLN05_t route = &(ROUTE(card_src->id, card_dst->id)); + return route->size; +} + +static const char *get_link_name(const void *link) { + return ((network_link_KCCFLN05_t) link)->name; +} + +static double get_link_bandwidth(const void *link) { + return ((network_link_KCCFLN05_t) link)->bw_current; +} + +static double get_link_latency(const void *link) { + return ((network_link_KCCFLN05_t) link)->lat_current; +} /**************************************/ /*** Resource Creation & Destruction **/ /**************************************/ + +static void router_free(void *router) +{ + free( ((router_KCCFLN05_t) router)->name ); +} + +static void router_new(const char *name) +{ + static unsigned int nb_routers = 0; + + INFO1("Creating a router %s", name); + + cpu_KCCFLN05_t router; + router = xbt_new0(s_cpu_KCCFLN05_t, 1); + + router->name = xbt_strdup(name); + router->id = nb_routers++; + xbt_dict_set(router_set, name, router, router_free); +} + +static void parse_route_set_routers(void) +{ + //add a dumb router just to be GTNETS compatible + router_new(A_surfxml_router_name); +} + static void cpu_free(void *cpu) { free(((cpu_KCCFLN05_t) cpu)->name); @@ -746,30 +937,24 @@ static void parse_network_link(void) policy_initial); } -static void route_new(int src_id, int dst_id, char **links, int nb_link, +static void route_new(int src_id, int dst_id, network_link_KCCFLN05_t *link_list, int nb_link, double impact_on_src, double impact_on_dst, double impact_on_src_with_other_recv, double impact_on_dst_with_other_send) { - network_link_KCCFLN05_t *link_list = NULL; - int i; route_KCCFLN05_t route = &(ROUTE(src_id, dst_id)); route->size = nb_link; - link_list = route->links = xbt_new0(network_link_KCCFLN05_t, nb_link); - for (i = 0; i < nb_link; i++) { - link_list[i] = xbt_dict_get_or_null(network_link_set, links[i]); - free(links[i]); - } - free(links); + route->links = link_list = xbt_realloc(link_list, sizeof(network_link_KCCFLN05_t) * nb_link); route->impact_on_src = impact_on_src; route->impact_on_dst = impact_on_src; route->impact_on_src_with_other_recv = impact_on_src_with_other_recv; route->impact_on_dst_with_other_send = impact_on_dst_with_other_send; } -static int nb_link = 0; -static char **link_name = NULL; +static int nb_link; +static int link_list_capacity; +static network_link_KCCFLN05_t *link_list = NULL; static int src_id = -1; static int dst_id = -1; static double impact_on_src; @@ -789,26 +974,34 @@ static void parse_route_set_endpoints(void) A_surfxml_route_impact_on_dst_with_other_send); nb_link = 0; - link_name = NULL; + link_list_capacity = 20; + link_list = xbt_new(network_link_KCCFLN05_t, link_list_capacity); } static void parse_route_elem(void) { - nb_link++; - link_name = xbt_realloc(link_name, (nb_link) * sizeof(char *)); - link_name[(nb_link) - 1] = xbt_strdup(A_surfxml_route_element_name); + xbt_ex_t e; + if (nb_link == link_list_capacity) { + link_list_capacity *= 2; + link_list = xbt_realloc(link_list, (link_list_capacity) * sizeof(network_link_KCCFLN05_t)); + } + TRY { + link_list[nb_link++] = xbt_dict_get(network_link_set, A_surfxml_route_element_name); + } CATCH(e) { + RETHROW1("Link %s not found (dict raised this exception: %s)",A_surfxml_route_element_name); + } } static void parse_route_set_route(void) { - route_new(src_id, dst_id, link_name, nb_link, impact_on_src, + route_new(src_id, dst_id, link_list, nb_link, impact_on_src, impact_on_dst, impact_on_src_with_other_recv, impact_on_dst_with_other_send); } static void parse_file(const char *file) { - int i ; + int i; /* Figuring out the cpus */ surf_parse_reset_parser(); @@ -819,6 +1012,13 @@ static void parse_file(const char *file) create_routing_table(); + /* Figuring out the router (added after GTNETS) */ + surf_parse_reset_parser(); + STag_surfxml_router_fun=parse_route_set_routers; + surf_parse_open(file); + xbt_assert1((!surf_parse()),"Parse error in %s",file); + surf_parse_close(); + /* Figuring out the network links */ surf_parse_reset_parser(); ETag_surfxml_network_link_fun = parse_network_link; @@ -840,7 +1040,7 @@ static void parse_file(const char *file) if(!ROUTE(i,i).size) { if(!loopback) loopback = network_link_new(xbt_strdup("__MSG_loopback__"), - 498.00, NULL, 0.000015, NULL, + 498000000, NULL, 0.000015, NULL, SURF_NETWORK_LINK_ON, NULL, SURF_NETWORK_LINK_FATPIPE); ROUTE(i,i).size=1; @@ -879,6 +1079,10 @@ static void resource_init_internal(void) surf_workstation_resource->common_public->name_service = name_service; surf_workstation_resource->common_public->get_resource_name = get_resource_name; surf_workstation_resource->common_public->action_get_state = surf_action_get_state; + surf_workstation_resource->common_public->action_get_start_time = + surf_action_get_start_time; + surf_workstation_resource->common_public->action_get_finish_time = + surf_action_get_finish_time; surf_workstation_resource->common_public->action_use = action_use; surf_workstation_resource->common_public->action_free = action_free; surf_workstation_resource->common_public->action_cancel = action_cancel; @@ -902,10 +1106,17 @@ static void resource_init_internal(void) surf_workstation_resource->extension_public->sleep = action_sleep; surf_workstation_resource->extension_public->get_state = resource_get_state; surf_workstation_resource->extension_public->get_speed = get_speed; + surf_workstation_resource->extension_public->get_available_speed = get_available_speed; surf_workstation_resource->extension_public->communicate = communicate; surf_workstation_resource->extension_public->execute_parallel_task = execute_parallel_task; - - workstation_set = xbt_dict_new(); + surf_workstation_resource->extension_public->get_route = get_route; + surf_workstation_resource->extension_public->get_route_size = get_route_size; + surf_workstation_resource->extension_public->get_link_name = get_link_name; + surf_workstation_resource->extension_public->get_link_bandwidth = get_link_bandwidth; + surf_workstation_resource->extension_public->get_link_latency = get_link_latency; + + workstation_set = xbt_dict_new(); + router_set = xbt_dict_new(); network_link_set = xbt_dict_new(); xbt_assert0(maxmin_system, "surf_init has to be called first!"); @@ -923,3 +1134,46 @@ void surf_workstation_resource_init_KCCFLN05(const char *filename) xbt_dynar_push(resource_list, &surf_workstation_resource); } + +void surf_workstation_resource_init_KCCFLN05_proportional(const char *filename) +{ + xbt_assert0(!surf_cpu_resource, "CPU resource type already defined"); + xbt_assert0(!surf_network_resource, "network resource type already defined"); + resource_init_internal(); + parse_file(filename); + + surf_workstation_resource->common_public->name = "Workstation KCCFLN05 (proportional)"; + use_sdp_solver=1; + xbt_dynar_push(resource_list, &surf_workstation_resource); +} + +void surf_workstation_resource_init_KCCFLN05_Vegas(const char *filename) +{ + xbt_assert0(!surf_cpu_resource, "CPU resource type already defined"); + xbt_assert0(!surf_network_resource, "network resource type already defined"); + resource_init_internal(); + parse_file(filename); + + lmm_set_default_protocol_function(func_vegas_f, func_vegas_fp, func_vegas_fpi); + + surf_workstation_resource->common_public->name = "Workstation KCCFLN05 (Vegas)"; + use_lagrange_solver=1; + xbt_dynar_push(resource_list, &surf_workstation_resource); +} + +void surf_workstation_resource_init_KCCFLN05_Reno(const char *filename) +{ + xbt_assert0(!surf_cpu_resource, "CPU resource type already defined"); + xbt_assert0(!surf_network_resource, "network resource type already defined"); + resource_init_internal(); + parse_file(filename); + + lmm_set_default_protocol_function(func_reno_f, func_reno_fp, func_reno_fpi); + + surf_workstation_resource->common_public->name = "Workstation KCCFLN05 (Reno)"; + use_lagrange_solver=1; + xbt_dynar_push(resource_list, &surf_workstation_resource); +} + + +