From: Paul Bédaride Date: Thu, 24 Oct 2013 15:31:27 +0000 (+0200) Subject: Remove c surf files X-Git-Tag: v3_11_beta~297^2~3 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/7ac272e25e5f27abe5c854124acb21a2d9bcc435 Remove c surf files --- diff --git a/buildtools/Cmake/DefinePackages.cmake b/buildtools/Cmake/DefinePackages.cmake index 2baafd1fe3..d279c1ad48 100644 --- a/buildtools/Cmake/DefinePackages.cmake +++ b/buildtools/Cmake/DefinePackages.cmake @@ -10,6 +10,7 @@ set(EXTRA_DIST src/include/simgrid/sg_config.h src/include/smpi/smpi_interface.h src/include/surf/datatypes.h + src/include/surf/maxmin.h src/include/surf/random_mgr.h src/include/surf/surf.h src/include/surf/surf_resource.h @@ -47,15 +48,13 @@ set(EXTRA_DIST src/surf/gtnets/gtnets_interface.h src/surf/gtnets/gtnets_simulator.h src/surf/gtnets/gtnets_topology.h - #src/surf/solver.hpp - #src/surf/solver.h src/surf/maxmin_private.h - #src/surf/maxmin_private_.h - src/surf/network_gtnets_private.h - #src/surf/network_gtnets.hpp + #src/surf/network_gtnets_private.h + src/surf/network_gtnets.hpp src/surf/network_ns3_private.h src/surf/network_private.h src/surf/network.hpp + src/surf/network_smpi.hpp src/surf/network_constant.hpp src/surf/ns3/my-point-to-point-helper.h src/surf/ns3/ns3_interface.h @@ -64,13 +63,24 @@ set(EXTRA_DIST src/surf/platf_generator_private.h src/surf/simgrid.dtd src/surf/simgrid_dtd.c + src/surf/storage.hpp src/surf/storage_private.h - src/surf/surf_c.h src/surf/surf.hpp src/surf/surf_private.h src/surf/surf_routing_private.h + src/surf/surf_routing_private.hpp + src/surf/surf_routing.hpp + src/surf/surf_routing_cluster.hpp + src/surf/surf_routing_dijkstra.hpp + src/surf/surf_routing_floyd.hpp + src/surf/surf_routing_full.hpp + src/surf/surf_routing_generic.hpp + src/surf/surf_routing_none.hpp + src/surf/surf_routing_vivaldi.hpp src/surf/surfxml_parse.c src/surf/trace_mgr_private.h + src/surf/workstation.hpp + src/surf/workstation_ptask_L07.hpp src/win32/config.h src/xbt/automaton/automaton_lexer.yy.c src/xbt/automaton/parserPromela.lex @@ -280,7 +290,7 @@ set(GTNETS_SRC src/surf/gtnets/gtnets_interface.cc src/surf/gtnets/gtnets_simulator.cc src/surf/gtnets/gtnets_topology.cc - src/surf/network_gtnets.c + src/surf/network_gtnets.cpp ) set(NS3_SRC @@ -385,11 +395,9 @@ set(SIMIX_SRC set(SURF_SRC ${SURF_SRC} - src/surf/new_model.c ) set(EXTRA_DIST ${EXTRA_DIST} - src/surf/new_model_private.h ) #* ****************************************************************************************** *# diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index 5c253a53b1..e1a727f75a 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -597,13 +597,6 @@ XBT_PUBLIC(void) surf_workstation_model_init_ptask_L07(void); XBT_PUBLIC_DATA(s_surf_model_description_t) surf_workstation_model_description[]; -/******************************************* - * TUTORIAL: New model - */ -XBT_PUBLIC(void) surf_new_model_init_default(void); - -XBT_PUBLIC_DATA(s_surf_model_description_t) surf_new_model_description[]; - /*******************************************/ /** \ingroup SURF_models @@ -672,6 +665,7 @@ XBT_PUBLIC(double) surf_solve(double max_date); * * Return the current time in millisecond. */ + XBT_PUBLIC(double) surf_get_clock(void); /** \ingroup SURF_simulation diff --git a/src/simgrid/sg_config.c b/src/simgrid/sg_config.c index 1726748132..56c1120c25 100644 --- a/src/simgrid/sg_config.c +++ b/src/simgrid/sg_config.c @@ -440,23 +440,6 @@ void sg_config_init(int *argc, char **argv) &default_value, 1, 1, &_sg_cfg_cb__storage_mode, NULL); - /* ********************************************************************* */ - /* TUTORIAL: New model */ - sprintf(description, - "The model to use for the New model. Possible values: "); - p = description; - while (*(++p) != '\0'); - for (i = 0; surf_new_model_description[i].name; i++) - p += sprintf(p, "%s%s", (i == 0 ? "" : ", "), - surf_new_model_description[i].name); - sprintf(p, - ".\n (use 'help' as a value to see the long description of each model)"); - default_value = xbt_strdup("default"); - xbt_cfg_register(&_sg_cfg_set, "new_model/model", description, xbt_cfgelm_string, - &default_value, 1, 1, &_sg_cfg_cb__storage_mode, - NULL); - /* ********************************************************************* */ - sprintf(description, "The model to use for the network. Possible values: "); p = description; @@ -920,15 +903,6 @@ void surf_config_models_setup() storage_id = find_model_description(surf_storage_model_description, storage_model_name); surf_storage_model_description[storage_id].model_init_preparse(); - /* ********************************************************************* */ - /* TUTORIAL: New model */ - /*FIXME:UPDATE: int new_model_id = -1; - char *new_model_name = NULL; - new_model_name = xbt_cfg_get_string(_sg_cfg_set, "new_model/model"); - XBT_DEBUG("Call new model_init"); - new_model_id = find_model_description(surf_new_model_description, new_model_name); - surf_new_model_description[new_model_id].model_init_preparse();*/ - /* ********************************************************************* */ } int sg_cfg_get_int(const char* name) diff --git a/src/surf/cpu_cas01.c b/src/surf/cpu_cas01.c deleted file mode 100644 index 27e759b4ca..0000000000 --- a/src/surf/cpu_cas01.c +++ /dev/null @@ -1,447 +0,0 @@ -/* Copyright (c) 2009-2011. The SimGrid Team. - * All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ - -#include "surf_private.h" -#include "surf/surf_resource.h" -#include "maxmin_private.h" -#include "simgrid/sg_config.h" - -surf_model_t surf_cpu_model = NULL; - -#undef GENERIC_LMM_ACTION -#undef GENERIC_ACTION -#undef ACTION_GET_CPU -#define GENERIC_LMM_ACTION(action) action->generic_lmm_action -#define GENERIC_ACTION(action) GENERIC_LMM_ACTION(action).generic_action -#define ACTION_GET_CPU(action) ((surf_action_cpu_Cas01_t) action)->cpu - -typedef struct surf_action_cpu_cas01 { - s_surf_action_lmm_t generic_lmm_action; -} s_surf_action_cpu_Cas01_t, *surf_action_cpu_Cas01_t; - -typedef struct cpu_Cas01 { - s_surf_resource_t generic_resource; - s_xbt_swag_hookup_t modified_cpu_hookup; - double power_peak; - double power_scale; - tmgr_trace_event_t power_event; - int core; - e_surf_resource_state_t state_current; - tmgr_trace_event_t state_event; - lmm_constraint_t constraint; -} s_cpu_Cas01_t, *cpu_Cas01_t; - -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_cpu, surf, - "Logging specific to the SURF CPU IMPROVED module"); - -static xbt_swag_t - cpu_running_action_set_that_does_not_need_being_checked = NULL; - - -/* This function is registered as a callback to sg_platf_new_host() and never called directly */ -static void *cpu_create_resource(const char *name, double power_peak, - double power_scale, - tmgr_trace_t power_trace, - int core, - e_surf_resource_state_t state_initial, - tmgr_trace_t state_trace, - xbt_dict_t cpu_properties) -{ - cpu_Cas01_t cpu = NULL; - - xbt_assert(!surf_cpu_resource_priv(surf_cpu_resource_by_name(name)), - "Host '%s' declared several times in the platform file", - name); - 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; - cpu->core = core; - xbt_assert(core > 0, "Invalid number of cores %d", core); - - if (power_trace) - cpu->power_event = - tmgr_history_add_trace(history, power_trace, 0.0, 0, static_cast(cpu)); - - cpu->state_current = state_initial; - if (state_trace) - cpu->state_event = - tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu); - - cpu->constraint = - lmm_constraint_new(surf_cpu_model->model_private->maxmin_system, cpu, - cpu->core * cpu->power_scale * cpu->power_peak); - - xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, cpu); - - return xbt_lib_get_elm_or_null(host_lib, name);; -} - - -static void parse_cpu_init(sg_platf_host_cbarg_t host) -{ - cpu_create_resource(host->id, - host->power_peak, - host->power_scale, - host->power_trace, - host->core_amount, - host->initial_state, - host->state_trace, host->properties); -} - -static void cpu_add_traces_cpu(void) -{ - xbt_dict_cursor_t cursor = NULL; - char *trace_name, *elm; - static int called = 0; - if (called) - return; - called = 1; - - /* connect all traces relative to hosts */ - 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_Cas01_t host = surf_cpu_resource_by_name(elm); - - xbt_assert(host, "Host %s undefined", elm); - xbt_assert(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_Cas01_t host = surf_cpu_resource_by_name(elm); - - xbt_assert(host, "Host %s undefined", elm); - xbt_assert(trace, "Trace %s undefined", trace_name); - - host->power_event = - tmgr_history_add_trace(history, trace, 0.0, 0, host); - } -} - -static void cpu_define_callbacks() -{ - sg_platf_host_add_cb(parse_cpu_init); - sg_platf_postparse_add_cb(cpu_add_traces_cpu); -} - -static int cpu_resource_used(void *resource) -{ - return lmm_constraint_used(surf_cpu_model->model_private->maxmin_system, - ((cpu_Cas01_t) resource)->constraint); -} - -static double cpu_share_resources_lazy(double now) -{ - return generic_share_resources_lazy(now, surf_cpu_model); -} - -static double cpu_share_resources_full(double now) -{ - s_surf_action_cpu_Cas01_t action; - return generic_maxmin_share_resources(surf_cpu_model->states. - running_action_set, - xbt_swag_offset(action, - generic_lmm_action. - variable), - surf_cpu_model->model_private->maxmin_system, lmm_solve); -} - -static void cpu_update_actions_state_lazy(double now, double delta) -{ - generic_update_actions_state_lazy(now, delta, surf_cpu_model); -} - -static void cpu_update_actions_state_full(double now, double delta) -{ - generic_update_actions_state_full(now, delta, surf_cpu_model); -} - -static void cpu_update_resource_state(void *id, - tmgr_trace_event_t event_type, - double value, double date) -{ - cpu_Cas01_t cpu = id; - lmm_variable_t var = NULL; - lmm_element_t elem = NULL; - - surf_watched_hosts(); - - if (event_type == cpu->power_event) { - cpu->power_scale = value; - lmm_update_constraint_bound(surf_cpu_model->model_private->maxmin_system, cpu->constraint, - cpu->core * cpu->power_scale * - cpu->power_peak); -#ifdef HAVE_TRACING - TRACE_surf_host_set_power(date, cpu->generic_resource.name, - cpu->core * cpu->power_scale * - cpu->power_peak); -#endif - while ((var = lmm_get_var_from_cnst - (surf_cpu_model->model_private->maxmin_system, cpu->constraint, &elem))) { - surf_action_cpu_Cas01_t action = lmm_variable_id(var); - lmm_update_variable_bound(surf_cpu_model->model_private->maxmin_system, - GENERIC_LMM_ACTION(action).variable, - cpu->power_scale * cpu->power_peak); - } - if (tmgr_trace_event_free(event_type)) - cpu->power_event = NULL; - } else if (event_type == cpu->state_event) { - if (value > 0) - cpu->state_current = SURF_RESOURCE_ON; - else { - lmm_constraint_t cnst = cpu->constraint; - - cpu->state_current = SURF_RESOURCE_OFF; - - while ((var = lmm_get_var_from_cnst(surf_cpu_model->model_private->maxmin_system, cnst, &elem))) { - surf_action_t action = lmm_variable_id(var); - - if (surf_action_state_get(action) == SURF_ACTION_RUNNING || - surf_action_state_get(action) == SURF_ACTION_READY || - surf_action_state_get(action) == - SURF_ACTION_NOT_IN_THE_SYSTEM) { - action->finish = date; - surf_action_state_set(action, SURF_ACTION_FAILED); - } - } - } - if (tmgr_trace_event_free(event_type)) - cpu->state_event = NULL; - } else { - XBT_CRITICAL("Unknown event ! \n"); - xbt_abort(); - } - - return; -} - -static surf_action_t cpu_execute(void *cpu, double size) -{ - surf_action_cpu_Cas01_t action = NULL; - cpu_Cas01_t CPU = surf_cpu_resource_priv(cpu); - - XBT_IN("(%s,%g)", surf_resource_name(CPU), size); - action = - surf_action_new(sizeof(s_surf_action_cpu_Cas01_t), size, - surf_cpu_model, - CPU->state_current != SURF_RESOURCE_ON); - - GENERIC_LMM_ACTION(action).suspended = 0; /* Should be useless because of the - calloc but it seems to help valgrind... */ - - GENERIC_LMM_ACTION(action).variable = - lmm_variable_new(surf_cpu_model->model_private->maxmin_system, action, - GENERIC_ACTION(action).priority, - CPU->power_scale * CPU->power_peak, 1); - if (surf_cpu_model->model_private->update_mechanism == UM_LAZY) { - GENERIC_LMM_ACTION(action).index_heap = -1; - GENERIC_LMM_ACTION(action).last_update = surf_get_clock(); - GENERIC_LMM_ACTION(action).last_value = 0.0; - } - lmm_expand(surf_cpu_model->model_private->maxmin_system, CPU->constraint, - GENERIC_LMM_ACTION(action).variable, 1.0); - XBT_OUT(); - return (surf_action_t) action; -} - -static surf_action_t cpu_action_sleep(void *cpu, double duration) -{ - surf_action_cpu_Cas01_t action = NULL; - - if (duration > 0) - duration = MAX(duration, MAXMIN_PRECISION); - - XBT_IN("(%s,%g)", surf_resource_name(surf_cpu_resource_priv(cpu)), duration); - action = (surf_action_cpu_Cas01_t) cpu_execute(cpu, 1.0); - // FIXME: sleep variables should not consume 1.0 in lmm_expand - GENERIC_ACTION(action).max_duration = duration; - GENERIC_LMM_ACTION(action).suspended = 2; - if (duration == NO_MAX_DURATION) { - /* Move to the *end* of the corresponding action set. This convention - is used to speed up update_resource_state */ - xbt_swag_remove(action, ((surf_action_t) action)->state_set); - ((surf_action_t) action)->state_set = - cpu_running_action_set_that_does_not_need_being_checked; - xbt_swag_insert(action, ((surf_action_t) action)->state_set); - } - - lmm_update_variable_weight(surf_cpu_model->model_private->maxmin_system, - GENERIC_LMM_ACTION(action).variable, 0.0); - if (surf_cpu_model->model_private->update_mechanism == UM_LAZY) { // remove action from the heap - surf_action_lmm_heap_remove(surf_cpu_model->model_private->action_heap,(surf_action_lmm_t)action); - // this is necessary for a variable with weight 0 since such - // variables are ignored in lmm and we need to set its max_duration - // correctly at the next call to share_resources - xbt_swag_insert_at_head(action,surf_cpu_model->model_private->modified_set); - } - - XBT_OUT(); - return (surf_action_t) action; -} - -static e_surf_resource_state_t cpu_get_state(void *cpu) -{ - return ((cpu_Cas01_t)surf_cpu_resource_priv(cpu))->state_current; -} - -static double cpu_get_speed(void *cpu, double load) -{ - return load * ((cpu_Cas01_t)surf_cpu_resource_priv(cpu))->power_peak; -} - -static int cpu_get_core(void *cpu) -{ - return ((cpu_Cas01_t)surf_cpu_resource_priv(cpu))->core; -} - - -static double cpu_get_available_speed(void *cpu) -{ - /* number between 0 and 1 */ - return ((cpu_Cas01_t)surf_cpu_resource_priv(cpu))->power_scale; -} - -static void cpu_finalize(void) -{ - lmm_system_free(surf_cpu_model->model_private->maxmin_system); - surf_cpu_model->model_private->maxmin_system = NULL; - - if (surf_cpu_model->model_private->action_heap) - xbt_heap_free(surf_cpu_model->model_private->action_heap); - xbt_swag_free(surf_cpu_model->model_private->modified_set); - - surf_model_exit(surf_cpu_model); - surf_cpu_model = NULL; - - xbt_swag_free(cpu_running_action_set_that_does_not_need_being_checked); - cpu_running_action_set_that_does_not_need_being_checked = NULL; -} - -static void surf_cpu_model_init_internal() -{ - s_surf_action_t action; - s_surf_action_cpu_Cas01_t comp; - - char *optim = xbt_cfg_get_string(_sg_cfg_set, "cpu/optim"); - int select = - xbt_cfg_get_boolean(_sg_cfg_set, "cpu/maxmin_selective_update"); - - surf_cpu_model = surf_model_init(); - - if (!strcmp(optim, "Full")) { - surf_cpu_model->model_private->update_mechanism = UM_FULL; - surf_cpu_model->model_private->selective_update = select; - } else if (!strcmp(optim, "Lazy")) { - surf_cpu_model->model_private->update_mechanism = UM_LAZY; - surf_cpu_model->model_private->selective_update = 1; - xbt_assert((select == 1) - || - (xbt_cfg_is_default_value - (_sg_cfg_set, "cpu/maxmin_selective_update")), - "Disabling selective update while using the lazy update mechanism is dumb!"); - } else { - xbt_die("Unsupported optimization (%s) for this model", optim); - } - - cpu_running_action_set_that_does_not_need_being_checked = - xbt_swag_new(xbt_swag_offset(action, state_hookup)); - - surf_cpu_model->name = "cpu"; - - surf_cpu_model->action_unref = surf_action_unref; - surf_cpu_model->action_cancel = surf_action_cancel; - surf_cpu_model->action_state_set = surf_action_state_set; - - surf_cpu_model->model_private->resource_used = cpu_resource_used; - - if (surf_cpu_model->model_private->update_mechanism == UM_LAZY) { - surf_cpu_model->model_private->share_resources = - cpu_share_resources_lazy; - surf_cpu_model->model_private->update_actions_state = - cpu_update_actions_state_lazy; - } else if (surf_cpu_model->model_private->update_mechanism == UM_FULL) { - surf_cpu_model->model_private->share_resources = - cpu_share_resources_full; - surf_cpu_model->model_private->update_actions_state = - cpu_update_actions_state_full; - } else - xbt_die("Invalid cpu update mechanism!"); - - surf_cpu_model->model_private->update_resource_state = - cpu_update_resource_state; - surf_cpu_model->model_private->finalize = cpu_finalize; - - surf_cpu_model->suspend = surf_action_suspend; - surf_cpu_model->resume = surf_action_resume; - surf_cpu_model->is_suspended = surf_action_is_suspended; - surf_cpu_model->set_max_duration = surf_action_set_max_duration; - surf_cpu_model->set_priority = surf_action_set_priority; -#ifdef HAVE_TRACING - surf_cpu_model->set_category = surf_action_set_category; -#endif - surf_cpu_model->get_remains = surf_action_get_remains; - - surf_cpu_model->extension.cpu.execute = cpu_execute; - surf_cpu_model->extension.cpu.sleep = cpu_action_sleep; - - surf_cpu_model->extension.cpu.get_state = cpu_get_state; - surf_cpu_model->extension.cpu.get_core = cpu_get_core; - surf_cpu_model->extension.cpu.get_speed = cpu_get_speed; - surf_cpu_model->extension.cpu.get_available_speed = - cpu_get_available_speed; - surf_cpu_model->extension.cpu.add_traces = cpu_add_traces_cpu; - - if (!surf_cpu_model->model_private->maxmin_system) { - surf_cpu_model->model_private->maxmin_system = lmm_system_new(surf_cpu_model->model_private->selective_update); - } - if (surf_cpu_model->model_private->update_mechanism == UM_LAZY) { - surf_cpu_model->model_private->action_heap = xbt_heap_new(8, NULL); - xbt_heap_set_update_callback(surf_cpu_model->model_private->action_heap, - surf_action_lmm_update_index_heap); - surf_cpu_model->model_private->modified_set = - xbt_swag_new(xbt_swag_offset(comp, generic_lmm_action.action_list_hookup)); - surf_cpu_model->model_private->maxmin_system->keep_track = surf_cpu_model->model_private->modified_set; - } -} - -/*********************************************************************/ -/* Basic sharing model for CPU: that is where all this started... ;) */ -/*********************************************************************/ -/* @InProceedings{casanova01simgrid, */ -/* author = "H. Casanova", */ -/* booktitle = "Proceedings of the IEEE Symposium on Cluster Computing */ -/* and the Grid (CCGrid'01)", */ -/* publisher = "IEEE Computer Society", */ -/* title = "Simgrid: {A} Toolkit for the Simulation of Application */ -/* Scheduling", */ -/* year = "2001", */ -/* month = may, */ -/* note = "Available at */ -/* \url{http://grail.sdsc.edu/papers/simgrid_ccgrid01.ps.gz}." */ -/* } */ - -void surf_cpu_model_init_Cas01() -{ - char *optim = xbt_cfg_get_string(_sg_cfg_set, "cpu/optim"); - - if (surf_cpu_model) - return; - - if (!strcmp(optim, "TI")) { - surf_cpu_model_init_ti(); - return; - } - - surf_cpu_model_init_internal(); - cpu_define_callbacks(); - xbt_dynar_push(model_list, &surf_cpu_model); -} diff --git a/src/surf/cpu_ti.c b/src/surf/cpu_ti.c deleted file mode 100644 index b44fd4d035..0000000000 --- a/src/surf/cpu_ti.c +++ /dev/null @@ -1,1091 +0,0 @@ - -/* Copyright (c) 2009, 2010. The SimGrid Team. - * All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ - -/* - commit: e2d6799c4182f00443b3013aadb1c2412372460f - This commit retrieves the old implementation of CPU_TI with multi-levels. -*/ - -#include "surf_private.h" -#include "trace_mgr_private.h" -#include "cpu_ti_private.h" -#include "xbt/heap.h" -#include "surf/surf_resource.h" - -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_cpu_ti, surf, - "Logging specific to the SURF CPU TRACE INTEGRATION module"); - - -static xbt_swag_t - cpu_ti_running_action_set_that_does_not_need_being_checked = NULL; -static xbt_swag_t cpu_ti_modified_cpu = NULL; -static xbt_heap_t cpu_ti_action_heap; - -/* prototypes of new trace functions */ -static double surf_cpu_ti_integrate_trace(surf_cpu_ti_tgmr_t trace, - double a, double b); - - -static double surf_cpu_ti_solve_trace(surf_cpu_ti_tgmr_t trace, double a, - double amount); -static double surf_cpu_ti_solve_trace_somewhat_simple(surf_cpu_ti_tgmr_t - trace, double a, - double amount); - -static void surf_cpu_ti_free_tmgr(surf_cpu_ti_tgmr_t trace); - -static double surf_cpu_ti_integrate_trace_simple(surf_cpu_ti_trace_t trace, - double a, double b); -static double surf_cpu_ti_integrate_trace_simple_point(surf_cpu_ti_trace_t - trace, double a); -static double surf_cpu_ti_solve_trace_simple(surf_cpu_ti_trace_t trace, - double a, double amount); -static int surf_cpu_ti_binary_search(double *array, double a, int low, - int high); -/* end prototypes */ - -static void surf_cpu_ti_free_trace(surf_cpu_ti_trace_t trace) -{ - xbt_free(trace->time_points); - xbt_free(trace->integral); - xbt_free(trace); -} - -static void surf_cpu_ti_free_tmgr(surf_cpu_ti_tgmr_t trace) -{ - if (trace->trace) - surf_cpu_ti_free_trace(trace->trace); - xbt_free(trace); -} - -static surf_cpu_ti_trace_t surf_cpu_ti_trace_new(tmgr_trace_t power_trace) -{ - surf_cpu_ti_trace_t trace; - s_tmgr_event_t val; - unsigned int cpt; - double integral = 0; - double time = 0; - int i = 0; - trace = xbt_new0(s_surf_cpu_ti_trace_t, 1); - trace->time_points = - xbt_malloc0(sizeof(double) * - (xbt_dynar_length(power_trace->s_list.event_list) + 1)); - trace->integral = - xbt_malloc0(sizeof(double) * - (xbt_dynar_length(power_trace->s_list.event_list) + 1)); - trace->nb_points = xbt_dynar_length(power_trace->s_list.event_list); - xbt_dynar_foreach(power_trace->s_list.event_list, cpt, val) { - trace->time_points[i] = time; - trace->integral[i] = integral; - integral += val.delta * val.value; - time += val.delta; - i++; - } - trace->time_points[i] = time; - trace->integral[i] = integral; - return trace; -} - -/** -* \brief Creates a new integration trace from a tmgr_trace_t -* -* \param power_trace CPU availability trace -* \param value Percentage of CPU power available (useful to fixed tracing) -* \param spacing Initial spacing -* \return Integration trace structure -*/ -static surf_cpu_ti_tgmr_t cpu_ti_parse_trace(tmgr_trace_t power_trace, - double value) -{ - surf_cpu_ti_tgmr_t trace; - double total_time = 0.0; - s_tmgr_event_t val; - unsigned int cpt; - trace = xbt_new0(s_surf_cpu_ti_tgmr_t, 1); - -/* no availability file, fixed trace */ - if (!power_trace) { - trace->type = TRACE_FIXED; - trace->value = value; - XBT_DEBUG("No availabily trace. Constant value = %lf", value); - return trace; - } - - /* only one point available, fixed trace */ - if (xbt_dynar_length(power_trace->s_list.event_list) == 1) { - xbt_dynar_get_cpy(power_trace->s_list.event_list, 0, &val); - trace->type = TRACE_FIXED; - trace->value = val.value; - return trace; - } - - trace->type = TRACE_DYNAMIC; - trace->power_trace = power_trace; - - /* count the total time of trace file */ - xbt_dynar_foreach(power_trace->s_list.event_list, cpt, val) { - total_time += val.delta; - } - trace->trace = surf_cpu_ti_trace_new(power_trace); - trace->last_time = total_time; - trace->total = - surf_cpu_ti_integrate_trace_simple(trace->trace, 0, total_time); - - XBT_DEBUG("Total integral %lf, last_time %lf ", - trace->total, trace->last_time); - - return trace; -} - - -static void* cpu_ti_create_resource(const char *name, double power_peak, - double power_scale, - tmgr_trace_t power_trace, - int core, - e_surf_resource_state_t state_initial, - tmgr_trace_t state_trace, - xbt_dict_t cpu_properties) -{ - tmgr_trace_t empty_trace; - s_tmgr_event_t val; - 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_priv(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->power_peak = power_peak; - xbt_assert(cpu->power_peak > 0, "Power has to be >0"); - XBT_DEBUG("power scale %lf", power_scale); - cpu->power_scale = power_scale; - cpu->avail_trace = cpu_ti_parse_trace(power_trace, power_scale); - cpu->state_current = state_initial; - if (state_trace) - cpu->state_event = - tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu); - if (power_trace && xbt_dynar_length(power_trace->s_list.event_list) > 1) { - /* add a fake trace event if periodicity == 0 */ - xbt_dynar_get_cpy(power_trace->s_list.event_list, - xbt_dynar_length(power_trace->s_list.event_list) - 1, &val); - if (val.delta == 0) { - empty_trace = tmgr_empty_trace_new(); - cpu->power_event = - tmgr_history_add_trace(history, empty_trace, - cpu->avail_trace->last_time, 0, cpu); - } - } - xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, cpu); - - return xbt_lib_get_elm_or_null(host_lib, name); -} - - -static void parse_cpu_ti_init(sg_platf_host_cbarg_t host) -{ - cpu_ti_create_resource(host->id, - host->power_peak, - host->power_scale, - host->power_trace, - host->core_amount, - host->initial_state, - host->state_trace, - host->properties); - -} - -static void add_traces_cpu_ti(void) -{ - xbt_dict_cursor_t cursor = NULL; - char *trace_name, *elm; - - static int called = 0; - - if (called) - return; - called = 1; - -/* connect all traces relative to hosts */ - 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_ti_t cpu = surf_cpu_resource_priv(surf_cpu_resource_by_name(elm)); - - xbt_assert(cpu, "Host %s undefined", elm); - xbt_assert(trace, "Trace %s undefined", trace_name); - - if (cpu->state_event) { - XBT_DEBUG("Trace already configured for this CPU(%s), ignoring it", - elm); - continue; - } - XBT_DEBUG("Add state trace: %s to CPU(%s)", trace_name, elm); - cpu->state_event = tmgr_history_add_trace(history, trace, 0.0, 0, cpu); - } - - 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_ti_t cpu = surf_cpu_resource_priv(surf_cpu_resource_by_name(elm)); - - xbt_assert(cpu, "Host %s undefined", elm); - xbt_assert(trace, "Trace %s undefined", trace_name); - - XBT_DEBUG("Add power trace: %s to CPU(%s)", trace_name, elm); - if (cpu->avail_trace) - surf_cpu_ti_free_tmgr(cpu->avail_trace); - - cpu->avail_trace = cpu_ti_parse_trace(trace, cpu->power_scale); - - /* add a fake trace event if periodicity == 0 */ - if (trace && xbt_dynar_length(trace->s_list.event_list) > 1) { - s_tmgr_event_t val; - xbt_dynar_get_cpy(trace->s_list.event_list, - xbt_dynar_length(trace->s_list.event_list) - 1, &val); - if (val.delta == 0) { - tmgr_trace_t empty_trace; - empty_trace = tmgr_empty_trace_new(); - cpu->power_event = - tmgr_history_add_trace(history, empty_trace, - cpu->avail_trace->last_time, 0, cpu); - } - } - } -} - -static void cpu_ti_define_callbacks() -{ - sg_platf_host_add_cb(parse_cpu_ti_init); - sg_platf_postparse_add_cb(add_traces_cpu_ti); -} - -static int cpu_ti_resource_used(void *resource_id) -{ - cpu_ti_t cpu = resource_id; - return xbt_swag_size(cpu->action_set); -} - -static int cpu_ti_action_unref(surf_action_t action) -{ - action->refcount--; - if (!action->refcount) { - xbt_swag_remove(action, action->state_set); - /* remove from action_set */ - xbt_swag_remove(action, ((cpu_ti_t)surf_cpu_resource_priv(ACTION_GET_CPU(action)))->action_set); - /* remove from heap */ - xbt_heap_remove(cpu_ti_action_heap, - ((surf_action_cpu_ti_t) action)->index_heap); - xbt_swag_insert(((cpu_ti_t)surf_cpu_resource_priv(ACTION_GET_CPU(action))), cpu_ti_modified_cpu); - surf_action_free(&action); - return 1; - } - return 0; -} - -static void cpu_ti_action_cancel(surf_action_t action) -{ - surf_action_state_set(action, SURF_ACTION_FAILED); - xbt_heap_remove(cpu_ti_action_heap, - ((surf_action_cpu_ti_t) action)->index_heap); - xbt_swag_insert(surf_cpu_resource_priv(ACTION_GET_CPU(action)), cpu_ti_modified_cpu); - return; -} - -static void cpu_ti_action_state_set(surf_action_t action, - e_surf_action_state_t state) -{ - surf_action_state_set(action, state); - xbt_swag_insert(surf_cpu_resource_priv(ACTION_GET_CPU(action)), cpu_ti_modified_cpu); - return; -} - -/** -* \brief Update the remaining amount of actions -* -* \param cpu Cpu on which the actions are running -* \param now Current time -*/ -static void cpu_ti_update_remaining_amount(cpu_ti_t cpu, double now) -{ - double area_total; - surf_action_cpu_ti_t action; - -/* already updated */ - if (cpu->last_update >= now) - return; - -/* calcule the surface */ - area_total = - surf_cpu_ti_integrate_trace(cpu->avail_trace, cpu->last_update, - now) * cpu->power_peak; - XBT_DEBUG("Flops total: %lf, Last update %lf", area_total, - cpu->last_update); - - xbt_swag_foreach(action, cpu->action_set) { - surf_action_t generic = (surf_action_t)action; - /* action not running, skip it */ - if (generic->state_set != - surf_cpu_model->states.running_action_set) - continue; - - /* bogus priority, skip it */ - if (generic->priority <= 0) - continue; - - /* action suspended, skip it */ - if (action->suspended != 0) - continue; - - /* action don't need update */ - if (generic->start >= now) - continue; - - /* skip action that are finishing now */ - if (generic->finish >= 0 - && generic->finish <= now) - continue; - - /* update remaining */ - double_update(&(generic->remains), - area_total / (cpu->sum_priority * - generic->priority)); - XBT_DEBUG("Update remaining action(%p) remaining %lf", action, - generic->remains); - } - cpu->last_update = now; -#undef GENERIC_ACTION -} - -/** -* \brief Update the finish date of action if necessary -* -* \param cpu Cpu on which the actions are running -* \param now Current time -*/ -static void cpu_ti_update_action_finish_date(cpu_ti_t cpu, double now) -{ -#define GENERIC_ACTION(action) action->generic_action - surf_action_cpu_ti_t action; - double sum_priority = 0.0, total_area, min_finish = -1; - -/* update remaning amount of actions */ - cpu_ti_update_remaining_amount(cpu, now); - - xbt_swag_foreach(action, cpu->action_set) { - /* action not running, skip it */ - if (GENERIC_ACTION(action).state_set != - surf_cpu_model->states.running_action_set) - continue; - - /* bogus priority, skip it */ - if (GENERIC_ACTION(action).priority <= 0) - continue; - - /* action suspended, skip it */ - if (action->suspended != 0) - continue; - - sum_priority += 1.0 / GENERIC_ACTION(action).priority; - } - cpu->sum_priority = sum_priority; - - xbt_swag_foreach(action, cpu->action_set) { - min_finish = -1; - /* action not running, skip it */ - if (GENERIC_ACTION(action).state_set != - surf_cpu_model->states.running_action_set) - continue; - - /* verify if the action is really running on cpu */ - if (action->suspended == 0 && GENERIC_ACTION(action).priority > 0) { - /* total area needed to finish the action. Used in trace integration */ - total_area = - (GENERIC_ACTION(action).remains) * sum_priority * - GENERIC_ACTION(action).priority; - - total_area /= cpu->power_peak; - - GENERIC_ACTION(action).finish = - surf_cpu_ti_solve_trace(cpu->avail_trace, now, total_area); - /* verify which event will happen before (max_duration or finish time) */ - if ((GENERIC_ACTION(action).max_duration != NO_MAX_DURATION) && - (GENERIC_ACTION(action).start + - GENERIC_ACTION(action).max_duration < - GENERIC_ACTION(action).finish)) - min_finish = GENERIC_ACTION(action).start + - GENERIC_ACTION(action).max_duration; - else - min_finish = GENERIC_ACTION(action).finish; - } else { - /* put the max duration time on heap */ - if (GENERIC_ACTION(action).max_duration != NO_MAX_DURATION) - min_finish = - (GENERIC_ACTION(action).start + - GENERIC_ACTION(action).max_duration); - } - /* add in action heap */ - XBT_DEBUG("action(%p) index %d", action, action->index_heap); - if (action->index_heap >= 0) { - surf_action_cpu_ti_t heap_act = - xbt_heap_remove(cpu_ti_action_heap, action->index_heap); - if (heap_act != action) - DIE_IMPOSSIBLE; - } - if (min_finish != NO_MAX_DURATION) - xbt_heap_push(cpu_ti_action_heap, action, min_finish); - - XBT_DEBUG - ("Update finish time: Cpu(%s) Action: %p, Start Time: %lf Finish Time: %lf Max duration %lf", - cpu->generic_resource.name, action, GENERIC_ACTION(action).start, - GENERIC_ACTION(action).finish, - GENERIC_ACTION(action).max_duration); - } -/* remove from modified cpu */ - xbt_swag_remove(cpu, cpu_ti_modified_cpu); -#undef GENERIC_ACTION -} - -static double cpu_ti_share_resources(double now) -{ - cpu_ti_t cpu, cpu_next; - double min_action_duration = -1; - -/* iterates over modified cpus to update share resources */ - xbt_swag_foreach_safe(cpu, cpu_next, cpu_ti_modified_cpu) { - cpu_ti_update_action_finish_date(cpu, now); - } -/* get the min next event if heap not empty */ - if (xbt_heap_size(cpu_ti_action_heap) > 0) - min_action_duration = xbt_heap_maxkey(cpu_ti_action_heap) - now; - - XBT_DEBUG("Share resources, min next event date: %lf", min_action_duration); - - return min_action_duration; -} - -static void cpu_ti_update_actions_state(double now, double delta) -{ -#define GENERIC_ACTION(action) action->generic_action - surf_action_cpu_ti_t action; - while ((xbt_heap_size(cpu_ti_action_heap) > 0) - && (xbt_heap_maxkey(cpu_ti_action_heap) <= now)) { - action = xbt_heap_pop(cpu_ti_action_heap); - XBT_DEBUG("Action %p: finish", action); - GENERIC_ACTION(action).finish = surf_get_clock(); - /* set the remains to 0 due to precision problems when updating the remaining amount */ - GENERIC_ACTION(action).remains = 0; - cpu_ti_action_state_set((surf_action_t) action, SURF_ACTION_DONE); - /* update remaining amout of all actions */ - cpu_ti_update_remaining_amount(surf_cpu_resource_priv(action->cpu), surf_get_clock()); - } -#undef GENERIC_ACTION -} - -static void cpu_ti_update_resource_state(void *id, - tmgr_trace_event_t event_type, - double value, double date) -{ - cpu_ti_t cpu = id; - surf_action_cpu_ti_t action; - - surf_watched_hosts(); - - if (event_type == cpu->power_event) { - tmgr_trace_t power_trace; - surf_cpu_ti_tgmr_t trace; - s_tmgr_event_t val; - - XBT_DEBUG("Finish trace date: %lf value %lf date %lf", surf_get_clock(), - value, date); - /* update remaining of actions and put in modified cpu swag */ - cpu_ti_update_remaining_amount(cpu, date); - xbt_swag_insert(cpu, cpu_ti_modified_cpu); - - power_trace = cpu->avail_trace->power_trace; - xbt_dynar_get_cpy(power_trace->s_list.event_list, - xbt_dynar_length(power_trace->s_list.event_list) - 1, &val); - /* free old trace */ - surf_cpu_ti_free_tmgr(cpu->avail_trace); - cpu->power_scale = val.value; - - trace = xbt_new0(s_surf_cpu_ti_tgmr_t, 1); - trace->type = TRACE_FIXED; - trace->value = val.value; - XBT_DEBUG("value %lf", val.value); - - cpu->avail_trace = trace; - - if (tmgr_trace_event_free(event_type)) - cpu->power_event = NULL; - - } else if (event_type == cpu->state_event) { - if (value > 0) - cpu->state_current = SURF_RESOURCE_ON; - else { - cpu->state_current = SURF_RESOURCE_OFF; - - /* put all action running on cpu to failed */ - xbt_swag_foreach(action, cpu->action_set) { - if (surf_action_state_get((surf_action_t) action) == - SURF_ACTION_RUNNING - || surf_action_state_get((surf_action_t) action) == - SURF_ACTION_READY - || surf_action_state_get((surf_action_t) action) == - SURF_ACTION_NOT_IN_THE_SYSTEM) { - action->generic_action.finish = date; - cpu_ti_action_state_set((surf_action_t) action, - SURF_ACTION_FAILED); - if (action->index_heap >= 0) { - surf_action_cpu_ti_t heap_act = - xbt_heap_remove(cpu_ti_action_heap, action->index_heap); - if (heap_act != action) - DIE_IMPOSSIBLE; - } - } - } - } - if (tmgr_trace_event_free(event_type)) - cpu->state_event = NULL; - } else { - XBT_CRITICAL("Unknown event ! \n"); - xbt_abort(); - } - - return; -} - -static surf_action_t cpu_ti_execute(void *cpu, double size) -{ - surf_action_cpu_ti_t action = NULL; - cpu_ti_t CPU = surf_cpu_resource_priv(cpu); - - XBT_IN("(%s,%g)", surf_resource_name(CPU), size); - action = - surf_action_new(sizeof(s_surf_action_cpu_ti_t), size, surf_cpu_model, - CPU->state_current != SURF_RESOURCE_ON); - action->cpu = cpu; - action->index_heap = -1; - - xbt_swag_insert(CPU, cpu_ti_modified_cpu); - - xbt_swag_insert(action, CPU->action_set); - - action->suspended = 0; /* Should be useless because of the - calloc but it seems to help valgrind... */ - - XBT_OUT(); - return (surf_action_t) action; -} - -static void cpu_ti_action_update_index_heap(void *action, int i) -{ - ((surf_action_cpu_ti_t) action)->index_heap = i; -} - -static surf_action_t cpu_ti_action_sleep(void *cpu, double duration) -{ - surf_action_cpu_ti_t action = NULL; - - if (duration > 0) - duration = MAX(duration, MAXMIN_PRECISION); - - XBT_IN("(%s,%g)", surf_resource_name(surf_cpu_resource_priv(cpu)), duration); - action = (surf_action_cpu_ti_t) cpu_ti_execute(cpu, 1.0); - action->generic_action.max_duration = duration; - action->suspended = 2; - if (duration == NO_MAX_DURATION) { - /* Move to the *end* of the corresponding action set. This convention - is used to speed up update_resource_state */ - xbt_swag_remove(action, ((surf_action_t) action)->state_set); - ((surf_action_t) action)->state_set = - cpu_ti_running_action_set_that_does_not_need_being_checked; - xbt_swag_insert(action, ((surf_action_t) action)->state_set); - } - XBT_OUT(); - return (surf_action_t) action; -} - -static void cpu_ti_action_suspend(surf_action_t action) -{ - XBT_IN("(%p)", action); - if (((surf_action_cpu_ti_t) action)->suspended != 2) { - ((surf_action_cpu_ti_t) action)->suspended = 1; - xbt_heap_remove(cpu_ti_action_heap, - ((surf_action_cpu_ti_t) action)->index_heap); - xbt_swag_insert(surf_cpu_resource_priv(ACTION_GET_CPU(action)), cpu_ti_modified_cpu); - } - XBT_OUT(); -} - -static void cpu_ti_action_resume(surf_action_t action) -{ - XBT_IN("(%p)", action); - if (((surf_action_cpu_ti_t) action)->suspended != 2) { - ((surf_action_cpu_ti_t) action)->suspended = 0; - xbt_swag_insert(surf_cpu_resource_priv(ACTION_GET_CPU(action)), cpu_ti_modified_cpu); - } - XBT_OUT(); -} - -static int cpu_ti_action_is_suspended(surf_action_t action) -{ - return (((surf_action_cpu_ti_t) action)->suspended == 1); -} - -static void cpu_ti_action_set_max_duration(surf_action_t action, - double duration) -{ - surf_action_cpu_ti_t ACT = (surf_action_cpu_ti_t) action; - double min_finish; - - XBT_IN("(%p,%g)", action, duration); - - action->max_duration = duration; - - if (duration >= 0) - min_finish = - (action->start + action->max_duration) < - action->finish ? (action->start + - action->max_duration) : action->finish; - else - min_finish = action->finish; - -/* add in action heap */ - if (ACT->index_heap >= 0) { - surf_action_cpu_ti_t heap_act = - xbt_heap_remove(cpu_ti_action_heap, ACT->index_heap); - if (heap_act != ACT) - DIE_IMPOSSIBLE; - } - xbt_heap_push(cpu_ti_action_heap, ACT, min_finish); - - XBT_OUT(); -} - -static void cpu_ti_action_set_priority(surf_action_t action, - double priority) -{ - XBT_IN("(%p,%g)", action, priority); - action->priority = priority; - xbt_swag_insert(surf_cpu_resource_priv(ACTION_GET_CPU(action)), cpu_ti_modified_cpu); - XBT_OUT(); -} - -static double cpu_ti_action_get_remains(surf_action_t action) -{ - XBT_IN("(%p)", action); - cpu_ti_update_remaining_amount((cpu_ti_t) - ((surf_action_cpu_ti_t) action)->cpu, - surf_get_clock()); - XBT_OUT(); - return action->remains; -} - -static e_surf_resource_state_t cpu_ti_get_state(void *cpu) -{ - return ((cpu_ti_t)surf_cpu_resource_priv(cpu))->state_current; -} - -static double cpu_ti_get_speed(void *cpu, double load) -{ - return load * ((cpu_ti_t)surf_cpu_resource_priv(cpu))->power_peak; -} - -/** -* \brief Auxiliary function to update the CPU power scale. -* -* This function uses the trace structure to return the power scale at the determined time a. -* \param trace Trace structure to search the updated power scale -* \param a Time -* \return CPU power scale -*/ -static double surf_cpu_ti_get_power_scale(surf_cpu_ti_tgmr_t trace, - double a) -{ - double reduced_a; - int point; - s_tmgr_event_t val; - - reduced_a = a - floor(a / trace->last_time) * trace->last_time; - point = - surf_cpu_ti_binary_search(trace->trace->time_points, reduced_a, 0, - trace->trace->nb_points - 1); - xbt_dynar_get_cpy(trace->power_trace->s_list.event_list, point, &val); - return val.value; -} - -static double cpu_ti_get_available_speed(void *cpu) -{ - cpu_ti_t CPU = surf_cpu_resource_priv(cpu); - CPU->power_scale = - surf_cpu_ti_get_power_scale(CPU->avail_trace, surf_get_clock()); -/* number between 0 and 1 */ - return CPU->power_scale; -} - -static void cpu_ti_finalize(void) -{ - void **cpu; - xbt_lib_cursor_t cursor; - char *key; - - xbt_lib_foreach(host_lib, cursor, key, cpu){ - if(cpu[SURF_CPU_LEVEL]) - { - cpu_ti_t CPU = cpu[SURF_CPU_LEVEL]; - xbt_swag_free(CPU->action_set); - surf_cpu_ti_free_tmgr(CPU->avail_trace); - } - } - - surf_model_exit(surf_cpu_model); - surf_cpu_model = NULL; - - xbt_swag_free - (cpu_ti_running_action_set_that_does_not_need_being_checked); - xbt_swag_free(cpu_ti_modified_cpu); - cpu_ti_running_action_set_that_does_not_need_being_checked = NULL; - xbt_heap_free(cpu_ti_action_heap); -} - -static void surf_cpu_ti_model_init_internal(void) -{ - s_surf_action_t action; - s_cpu_ti_t cpu; - - surf_cpu_model = surf_model_init(); - - cpu_ti_running_action_set_that_does_not_need_being_checked = - xbt_swag_new(xbt_swag_offset(action, state_hookup)); - - cpu_ti_modified_cpu = - xbt_swag_new(xbt_swag_offset(cpu, modified_cpu_hookup)); - - surf_cpu_model->name = "cpu_ti"; - - surf_cpu_model->action_unref = cpu_ti_action_unref; - surf_cpu_model->action_cancel = cpu_ti_action_cancel; - surf_cpu_model->action_state_set = cpu_ti_action_state_set; - - surf_cpu_model->model_private->resource_used = cpu_ti_resource_used; - surf_cpu_model->model_private->share_resources = cpu_ti_share_resources; - surf_cpu_model->model_private->update_actions_state = - cpu_ti_update_actions_state; - surf_cpu_model->model_private->update_resource_state = - cpu_ti_update_resource_state; - surf_cpu_model->model_private->finalize = cpu_ti_finalize; - - surf_cpu_model->suspend = cpu_ti_action_suspend; - surf_cpu_model->resume = cpu_ti_action_resume; - surf_cpu_model->is_suspended = cpu_ti_action_is_suspended; - surf_cpu_model->set_max_duration = cpu_ti_action_set_max_duration; - surf_cpu_model->set_priority = cpu_ti_action_set_priority; - surf_cpu_model->get_remains = cpu_ti_action_get_remains; - - surf_cpu_model->extension.cpu.execute = cpu_ti_execute; - surf_cpu_model->extension.cpu.sleep = cpu_ti_action_sleep; - - surf_cpu_model->extension.cpu.get_state = cpu_ti_get_state; - surf_cpu_model->extension.cpu.get_speed = cpu_ti_get_speed; - surf_cpu_model->extension.cpu.get_available_speed = - cpu_ti_get_available_speed; - surf_cpu_model->extension.cpu.add_traces = add_traces_cpu_ti; - - cpu_ti_action_heap = xbt_heap_new(8, NULL); - xbt_heap_set_update_callback(cpu_ti_action_heap, - cpu_ti_action_update_index_heap); - -} - -void surf_cpu_model_init_ti() -{ - xbt_assert(!surf_cpu_model,"CPU model already initialized. This should not happen."); - surf_cpu_ti_model_init_internal(); - cpu_ti_define_callbacks(); - xbt_dynar_push(model_list, &surf_cpu_model); -} - - -/** -* \brief Integrate trace -* -* Wrapper around surf_cpu_integrate_trace_simple() to get -* the cyclic effect. -* -* \param trace Trace structure. -* \param a Begin of interval -* \param b End of interval -* \return the integrate value. -1 if an error occurs. -*/ -static double surf_cpu_ti_integrate_trace(surf_cpu_ti_tgmr_t trace, - double a, double b) -{ - double first_chunk; - double middle_chunk; - double last_chunk; - int a_index, b_index; - - if ((a < 0.0) || (a > b)) { - XBT_CRITICAL - ("Error, invalid integration interval [%.2f,%.2f]. You probably have a task executing with negative computation amount. Check your code.", - a, b); - xbt_abort(); - } - if (a == b) - return 0.0; - - if (trace->type == TRACE_FIXED) { - return ((b - a) * trace->value); - } - - if (ceil(a / trace->last_time) == a / trace->last_time) - a_index = 1 + (int) (ceil(a / trace->last_time)); - else - a_index = (int) (ceil(a / trace->last_time)); - - b_index = (int) (floor(b / trace->last_time)); - - if (a_index > b_index) { /* Same chunk */ - return surf_cpu_ti_integrate_trace_simple(trace->trace, - a - (a_index - - 1) * trace->last_time, - b - - (b_index) * - trace->last_time); - } - - first_chunk = surf_cpu_ti_integrate_trace_simple(trace->trace, - a - (a_index - - 1) * - trace->last_time, - trace->last_time); - middle_chunk = (b_index - a_index) * trace->total; - last_chunk = surf_cpu_ti_integrate_trace_simple(trace->trace, - 0.0, - b - - (b_index) * - trace->last_time); - - XBT_DEBUG("first_chunk=%.2f middle_chunk=%.2f last_chunk=%.2f\n", - first_chunk, middle_chunk, last_chunk); - - return (first_chunk + middle_chunk + last_chunk); -} - -/** - * \brief Auxiliary function to calculate the integral between a and b. - * It simply calculates the integral at point a and b and returns the difference - * between them. - * \param trace Trace structure - * \param a Initial point - * \param b Final point - * \return Integral -*/ -static double surf_cpu_ti_integrate_trace_simple(surf_cpu_ti_trace_t trace, - double a, double b) -{ - return surf_cpu_ti_integrate_trace_simple_point(trace, - b) - - surf_cpu_ti_integrate_trace_simple_point(trace, a); -} - -/** - * \brief Auxiliary function to calculate the integral at point a. - * \param trace Trace structure - * \param a point - * \return Integral -*/ -static double surf_cpu_ti_integrate_trace_simple_point(surf_cpu_ti_trace_t - trace, double a) -{ - double integral = 0; - int ind; - double a_aux = a; - ind = - surf_cpu_ti_binary_search(trace->time_points, a, 0, - trace->nb_points - 1); - integral += trace->integral[ind]; - XBT_DEBUG - ("a %lf ind %d integral %lf ind + 1 %lf ind %lf time +1 %lf time %lf", - a, ind, integral, trace->integral[ind + 1], trace->integral[ind], - trace->time_points[ind + 1], trace->time_points[ind]); - double_update(&a_aux, trace->time_points[ind]); - if (a_aux > 0) - integral += - ((trace->integral[ind + 1] - - trace->integral[ind]) / (trace->time_points[ind + 1] - - trace->time_points[ind])) * (a - - trace-> - time_points - [ind]); - XBT_DEBUG("Integral a %lf = %lf", a, integral); - - return integral; -} - -/** -* \brief Calculate the time needed to execute "amount" on cpu. -* -* Here, amount can span multiple trace periods -* -* \param trace CPU trace structure -* \param a Initial time -* \param amount Amount to be executed -* \return End time -*/ -static double surf_cpu_ti_solve_trace(surf_cpu_ti_tgmr_t trace, double a, - double amount) -{ - int quotient; - double reduced_b; - double reduced_amount; - double reduced_a; - double b; - -/* Fix very small negative numbers */ - if ((a < 0.0) && (a > -EPSILON)) { - a = 0.0; - } - if ((amount < 0.0) && (amount > -EPSILON)) { - amount = 0.0; - } - -/* Sanity checks */ - if ((a < 0.0) || (amount < 0.0)) { - XBT_CRITICAL - ("Error, invalid parameters [a = %.2f, amount = %.2f]. You probably have a task executing with negative computation amount. Check your code.", - a, amount); - xbt_abort(); - } - -/* At this point, a and amount are positive */ - - if (amount < EPSILON) - return a; - -/* Is the trace fixed ? */ - if (trace->type == TRACE_FIXED) { - return (a + (amount / trace->value)); - } - - XBT_DEBUG("amount %lf total %lf", amount, trace->total); -/* Reduce the problem to one where amount <= trace_total */ - quotient = (int) (floor(amount / trace->total)); - reduced_amount = (trace->total) * ((amount / trace->total) - - floor(amount / trace->total)); - reduced_a = a - (trace->last_time) * (int) (floor(a / trace->last_time)); - - XBT_DEBUG("Quotient: %d reduced_amount: %lf reduced_a: %lf", quotient, - reduced_amount, reduced_a); - -/* Now solve for new_amount which is <= trace_total */ -/* - fprintf(stderr,"reduced_a = %.2f\n",reduced_a); - fprintf(stderr,"reduced_amount = %.2f\n",reduced_amount); - */ - reduced_b = - surf_cpu_ti_solve_trace_somewhat_simple(trace, reduced_a, - reduced_amount); - -/* Re-map to the original b and amount */ - b = (trace->last_time) * (int) (floor(a / trace->last_time)) + - (quotient * trace->last_time) + reduced_b; - return b; -} - -/** -* \brief Auxiliary function to solve integral -* -* Here, amount is <= trace->total -* and a <=trace->last_time -* -*/ -static double surf_cpu_ti_solve_trace_somewhat_simple(surf_cpu_ti_tgmr_t - trace, double a, - double amount) -{ - double amount_till_end; - double b; - - XBT_DEBUG("Solve integral: [%.2f, amount=%.2f]", a, amount); - amount_till_end = - surf_cpu_ti_integrate_trace(trace, a, trace->last_time); -/* - fprintf(stderr,"amount_till_end=%.2f\n",amount_till_end); - */ - - if (amount_till_end > amount) { - b = surf_cpu_ti_solve_trace_simple(trace->trace, a, amount); - } else { - b = trace->last_time + - surf_cpu_ti_solve_trace_simple(trace->trace, 0.0, - amount - amount_till_end); - } - return b; -} - -/** - * \brief Auxiliary function to solve integral. - * It returns the date when the requested amount of flops is available - * \param trace Trace structure - * \param a Initial point - * \param amount Amount of flops - * \return The date when amount is available. -*/ -static double surf_cpu_ti_solve_trace_simple(surf_cpu_ti_trace_t trace, - double a, double amount) -{ - double integral_a; - int ind; - double time; - integral_a = surf_cpu_ti_integrate_trace_simple_point(trace, a); - ind = - surf_cpu_ti_binary_search(trace->integral, integral_a + amount, 0, - trace->nb_points - 1); - time = trace->time_points[ind]; - time += - (integral_a + amount - - trace->integral[ind]) / ((trace->integral[ind + 1] - - trace->integral[ind]) / - (trace->time_points[ind + 1] - - trace->time_points[ind])); - - return time; -} - -/** - * \brief Binary search in array. - * It returns the first point of the interval in which "a" is. - * \param array Array - * \param a Value to search - * \param low Low bound to search in array - * \param high Upper bound to search in array - * \return Index of point -*/ -static int surf_cpu_ti_binary_search(double *array, double a, int low, - int high) -{ - xbt_assert(low < high, "Wrong parameters: low (%d) should be smaller than" - " high (%d)", low, high); - - int mid; - do { - mid = low + (high - low) / 2; - XBT_DEBUG("a %lf low %d high %d mid %d value %lf", a, low, high, mid, - array[mid]); - - if (array[mid] > a) - high = mid; - else - low = mid; - } - while (low < high - 1); - - return low; -} diff --git a/src/surf/network.c b/src/surf/network.c deleted file mode 100644 index 04c576314d..0000000000 --- a/src/surf/network.c +++ /dev/null @@ -1,986 +0,0 @@ - -/* - * Network with improved management of tasks, IM (Improved Management). - * Uses a heap to store actions so that the share_resources is faster. - * This model automatically sets the selective update flag to 1 and is - * highly dependent on the maxmin lmm module. - */ - -/* Copyright (c) 2009, 2010, 2011. The SimGrid Team. - * All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ - -#include "network_private.h" -#include "xbt/log.h" -#include "xbt/str.h" - -#include "surf_private.h" -#include "xbt/dict.h" -#include "maxmin_private.h" -#include "surf/surfxml_parse_values.h" -#include "surf/surf_resource.h" -#include "surf/surf_resource_lmm.h" -#include "simgrid/sg_config.h" - -#undef GENERIC_LMM_ACTION -#undef GENERIC_ACTION -#define GENERIC_LMM_ACTION(action) (action)->generic_lmm_action -#define GENERIC_ACTION(action) GENERIC_LMM_ACTION(action).generic_action - - -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_network, surf, - "Logging specific to the SURF network module"); - -surf_model_t surf_network_model = NULL; -static void (*network_solve) (lmm_system_t) = NULL; - -xbt_dynar_t smpi_bw_factor = NULL; -xbt_dynar_t smpi_lat_factor = NULL; - -typedef struct s_smpi_factor *smpi_factor_t; -typedef struct s_smpi_factor { - long factor; - double value; -} s_smpi_factor_t; - - -double sg_sender_gap = 0.0; -double sg_latency_factor = 1.0; /* default value; can be set by model or from command line */ -double sg_bandwidth_factor = 1.0; /* default value; can be set by model or from command line */ -double sg_weight_S_parameter = 0.0; /* default value; can be set by model or from command line */ - -double sg_tcp_gamma = 0.0; -int sg_network_crosstraffic = 0; - -xbt_dict_t gap_lookup = NULL; - -/******************************************************************************/ -/* Factors callbacks */ -/******************************************************************************/ -static double constant_latency_factor(double size) -{ - return sg_latency_factor; -} - -static double constant_bandwidth_factor(double size) -{ - return sg_bandwidth_factor; -} - -static double constant_bandwidth_constraint(double rate, double bound, - double size) -{ - return rate; -} - -/**********************/ -/* SMPI callbacks */ -/**********************/ - -static int factor_cmp(const void *pa, const void *pb) -{ - return (((s_smpi_factor_t*)pa)->factor > ((s_smpi_factor_t*)pb)->factor); -} - - -static xbt_dynar_t parse_factor(const char *smpi_coef_string) -{ - char *value = NULL; - unsigned int iter = 0; - s_smpi_factor_t fact; - xbt_dynar_t smpi_factor, radical_elements, radical_elements2 = NULL; - - smpi_factor = xbt_dynar_new(sizeof(s_smpi_factor_t), NULL); - radical_elements = xbt_str_split(smpi_coef_string, ";"); - xbt_dynar_foreach(radical_elements, iter, value) { - - radical_elements2 = xbt_str_split(value, ":"); - if (xbt_dynar_length(radical_elements2) != 2) - xbt_die("Malformed radical for smpi factor!"); - fact.factor = atol(xbt_dynar_get_as(radical_elements2, 0, char *)); - fact.value = atof(xbt_dynar_get_as(radical_elements2, 1, char *)); - xbt_dynar_push_as(smpi_factor, s_smpi_factor_t, fact); - XBT_DEBUG("smpi_factor:\t%ld : %f", fact.factor, fact.value); - xbt_dynar_free(&radical_elements2); - } - xbt_dynar_free(&radical_elements); - iter=0; - xbt_dynar_sort(smpi_factor, &factor_cmp); - xbt_dynar_foreach(smpi_factor, iter, fact) { - XBT_DEBUG("ordered smpi_factor:\t%ld : %f", fact.factor, fact.value); - - } - return smpi_factor; -} - -static double smpi_bandwidth_factor(double size) -{ - if (!smpi_bw_factor) - smpi_bw_factor = - parse_factor(sg_cfg_get_string("smpi/bw_factor")); - - unsigned int iter = 0; - s_smpi_factor_t fact; - double current=1.0; - xbt_dynar_foreach(smpi_bw_factor, iter, fact) { - if (size <= fact.factor) { - XBT_DEBUG("%lf <= %ld return %f", size, fact.factor, current); - return current; - }else - current=fact.value; - } - XBT_DEBUG("%lf > %ld return %f", size, fact.factor, current); - - return current; -} - -static double smpi_latency_factor(double size) -{ - if (!smpi_lat_factor) - smpi_lat_factor = - parse_factor(sg_cfg_get_string("smpi/lat_factor")); - - unsigned int iter = 0; - s_smpi_factor_t fact; - double current=1.0; - xbt_dynar_foreach(smpi_lat_factor, iter, fact) { - if (size <= fact.factor) { - XBT_DEBUG("%lf <= %ld return %f", size, fact.factor, current); - return current; - }else - current=fact.value; - } - XBT_DEBUG("%lf > %ld return %f", size, fact.factor, current); - - return current; -} - -/**--------- -----------*/ - -static double smpi_bandwidth_constraint(double rate, double bound, - double size) -{ - return rate < 0 ? bound : min(bound, rate * smpi_bandwidth_factor(size)); -} - -static double (*latency_factor_callback) (double) = - &constant_latency_factor; -static double (*bandwidth_factor_callback) (double) = - &constant_bandwidth_factor; -static double (*bandwidth_constraint_callback) (double, double, double) = - &constant_bandwidth_constraint; - -static void (*gap_append) (double, const link_CM02_t, - surf_action_network_CM02_t) = NULL; - -static void *net_create_resource(const char *name, - double bw_initial, - tmgr_trace_t bw_trace, - double lat_initial, - tmgr_trace_t lat_trace, - e_surf_resource_state_t - state_initial, - tmgr_trace_t state_trace, - e_surf_link_sharing_policy_t - policy, xbt_dict_t properties) -{ - link_CM02_t nw_link = (link_CM02_t) - surf_resource_lmm_new(sizeof(s_link_CM02_t), - surf_network_model, name, properties, - surf_network_model->model_private->maxmin_system, - sg_bandwidth_factor * bw_initial, - history, - state_initial, state_trace, - bw_initial, bw_trace); - - xbt_assert(!xbt_lib_get_or_null(link_lib, name, SURF_LINK_LEVEL), - "Link '%s' declared several times in the platform file.", - name); - - 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); - - if (policy == SURF_LINK_FATPIPE) - lmm_constraint_shared(nw_link->lmm_resource.constraint); - - xbt_lib_set(link_lib, name, SURF_LINK_LEVEL, nw_link); - XBT_DEBUG("Create link '%s'",name); - - return nw_link; -} - -static void net_parse_link_init(sg_platf_link_cbarg_t link) -{ - if (link->policy == SURF_LINK_FULLDUPLEX) { - char *link_id; - link_id = bprintf("%s_UP", link->id); - net_create_resource(link_id, - link->bandwidth, - link->bandwidth_trace, - link->latency, - link->latency_trace, - link->state, - link->state_trace, link->policy, link->properties); - xbt_free(link_id); - link_id = bprintf("%s_DOWN", link->id); - net_create_resource(link_id, - link->bandwidth, - link->bandwidth_trace, - link->latency, - link->latency_trace, - link->state, - link->state_trace, link->policy, link->properties); - xbt_free(link_id); - } else { - net_create_resource(link->id, - link->bandwidth, - link->bandwidth_trace, - link->latency, - link->latency_trace, - link->state, - link->state_trace, link->policy, link->properties); - } -} - -static void net_add_traces(void) -{ - xbt_dict_cursor_t cursor = NULL; - char *trace_name, *elm; - - static int called = 0; - if (called) - return; - called = 1; - - /* connect all 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_CM02_t link = xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL); - - xbt_assert(link, "Cannot connect trace %s to link %s: link undefined", - trace_name, elm); - xbt_assert(trace, - "Cannot connect trace %s to link %s: trace undefined", - trace_name, elm); - - 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) { - tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name); - link_CM02_t link = xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL); - - xbt_assert(link, "Cannot connect trace %s to link %s: link undefined", - trace_name, elm); - xbt_assert(trace, - "Cannot connect trace %s to link %s: trace undefined", - trace_name, elm); - - 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) { - tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name); - link_CM02_t link = xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL); - - xbt_assert(link, "Cannot connect trace %s to link %s: link undefined", - trace_name, elm); - xbt_assert(trace, - "Cannot connect trace %s to link %s: trace undefined", - trace_name, elm); - - link->lat_event = tmgr_history_add_trace(history, trace, 0.0, 0, link); - } -} - -static void net_define_callbacks(void) -{ - /* Figuring out the network links */ - sg_platf_link_add_cb(net_parse_link_init); - sg_platf_postparse_add_cb(net_add_traces); -} - -static int net_resource_used(void *resource_id) -{ - return lmm_constraint_used(surf_network_model->model_private->maxmin_system, ((surf_resource_lmm_t) - resource_id)-> - constraint); -} - -void net_action_recycle(surf_action_t action) -{ - return; -} - -#ifdef HAVE_LATENCY_BOUND_TRACKING -int net_get_link_latency_limited(surf_action_t action) -{ - return action->latency_limited; -} -#endif - -static double net_share_resources_full(double now) -{ - s_surf_action_lmm_t s_action; - surf_action_network_CM02_t action = NULL; - xbt_swag_t running_actions = - surf_network_model->states.running_action_set; - double min; - - min = generic_maxmin_share_resources(running_actions, - xbt_swag_offset(s_action, - variable), - surf_network_model->model_private->maxmin_system, - network_solve); - -#define VARIABLE(action) (*((lmm_variable_t*)(((char *) (action)) + xbt_swag_offset(s_action, variable) ))) - - xbt_swag_foreach(action, running_actions) { -#ifdef HAVE_LATENCY_BOUND_TRACKING - if (lmm_is_variable_limited_by_latency(GENERIC_LMM_ACTION(action).variable)) { - action->latency_limited = 1; - } else { - action->latency_limited = 0; - } -#endif - if (action->latency > 0) { - min = (min < 0) ? action->latency : min(min, action->latency); - } - } - - XBT_DEBUG("Min of share resources %f", min); - - return min; -} - -static double net_share_resources_lazy(double now) -{ - return generic_share_resources_lazy(now, surf_network_model); -} - -static void net_update_actions_state_full(double now, double delta) -{ - generic_update_actions_state_full(now, delta, surf_network_model); -} - -static void net_update_actions_state_lazy(double now, double delta) -{ - generic_update_actions_state_lazy(now, delta, surf_network_model); -} - -static void net_update_resource_state(void *id, - tmgr_trace_event_t event_type, - double value, double date) -{ - link_CM02_t nw_link = id; - /* printf("[" "%lg" "] Asking to update network card \"%s\" with value " */ - /* "%lg" " for event %p\n", surf_get_clock(), nw_link->name, */ - /* value, event_type); */ - - if (event_type == nw_link->lmm_resource.power.event) { - double delta = - sg_weight_S_parameter / value - sg_weight_S_parameter / - (nw_link->lmm_resource.power.peak * - nw_link->lmm_resource.power.scale); - lmm_variable_t var = NULL; - lmm_element_t elem = NULL; - surf_action_network_CM02_t action = NULL; - - nw_link->lmm_resource.power.peak = value; - lmm_update_constraint_bound(surf_network_model->model_private->maxmin_system, - nw_link->lmm_resource.constraint, - sg_bandwidth_factor * - (nw_link->lmm_resource.power.peak * - nw_link->lmm_resource.power.scale)); -#ifdef HAVE_TRACING - TRACE_surf_link_set_bandwidth(date, - (char - *) (((nw_link->lmm_resource). - generic_resource).name), - sg_bandwidth_factor * - (nw_link->lmm_resource.power.peak * - nw_link->lmm_resource.power.scale)); -#endif - if (sg_weight_S_parameter > 0) { - while ((var = lmm_get_var_from_cnst - (surf_network_model->model_private->maxmin_system, nw_link->lmm_resource.constraint, - &elem))) { - action = lmm_variable_id(var); - action->weight += delta; - if (!(GENERIC_LMM_ACTION(action).suspended)) - lmm_update_variable_weight(surf_network_model->model_private->maxmin_system, - GENERIC_LMM_ACTION(action).variable, action->weight); - } - } - if (tmgr_trace_event_free(event_type)) - nw_link->lmm_resource.power.event = NULL; - } else if (event_type == nw_link->lat_event) { - double delta = value - nw_link->lat_current; - lmm_variable_t var = NULL; - lmm_element_t elem = NULL; - surf_action_network_CM02_t action = NULL; - - nw_link->lat_current = value; - while ((var = lmm_get_var_from_cnst - (surf_network_model->model_private->maxmin_system, nw_link->lmm_resource.constraint, - &elem))) { - action = lmm_variable_id(var); - action->lat_current += delta; - action->weight += delta; - if (action->rate < 0) - lmm_update_variable_bound(surf_network_model->model_private->maxmin_system, GENERIC_LMM_ACTION(action).variable, - sg_tcp_gamma / (2.0 * - action->lat_current)); - else { - lmm_update_variable_bound(surf_network_model->model_private->maxmin_system, GENERIC_LMM_ACTION(action).variable, - min(action->rate, - sg_tcp_gamma / (2.0 * - action-> - lat_current))); - - if (action->rate < sg_tcp_gamma / (2.0 * action->lat_current)) { - XBT_INFO("Flow is limited BYBANDWIDTH"); - } else { - XBT_INFO("Flow is limited BYLATENCY, latency of flow is %f", - action->lat_current); - } - } - if (!(GENERIC_LMM_ACTION(action).suspended)) - lmm_update_variable_weight(surf_network_model->model_private->maxmin_system, GENERIC_LMM_ACTION(action).variable, - action->weight); - - } - if (tmgr_trace_event_free(event_type)) - nw_link->lat_event = NULL; - } else if (event_type == nw_link->lmm_resource.state_event) { - if (value > 0) - nw_link->lmm_resource.state_current = SURF_RESOURCE_ON; - else { - lmm_constraint_t cnst = nw_link->lmm_resource.constraint; - lmm_variable_t var = NULL; - lmm_element_t elem = NULL; - - nw_link->lmm_resource.state_current = SURF_RESOURCE_OFF; - while ((var = lmm_get_var_from_cnst - (surf_network_model->model_private->maxmin_system, cnst, &elem))) { - surf_action_t action = lmm_variable_id(var); - - if (surf_action_state_get(action) == SURF_ACTION_RUNNING || - surf_action_state_get(action) == SURF_ACTION_READY) { - action->finish = date; - surf_network_model->action_state_set(action, SURF_ACTION_FAILED); - } - } - } - if (tmgr_trace_event_free(event_type)) - nw_link->lmm_resource.state_event = NULL; - } else { - XBT_CRITICAL("Unknown event ! \n"); - xbt_abort(); - } - - XBT_DEBUG - ("There were a resource state event, need to update actions related to the constraint (%p)", - nw_link->lmm_resource.constraint); - return; -} - - -static surf_action_t net_communicate(sg_routing_edge_t src, - sg_routing_edge_t dst, - double size, double rate) -{ - unsigned int i; - link_CM02_t link; - int failed = 0; - surf_action_network_CM02_t action = NULL; - double bandwidth_bound; - double latency = 0.0; - xbt_dynar_t back_route = NULL; - int constraints_per_variable = 0; - - xbt_dynar_t route = xbt_dynar_new(sizeof(sg_routing_link_t), NULL); - - XBT_IN("(%s,%s,%g,%g)", src->name, dst->name, size, rate); - - routing_get_route_and_latency(src, dst, &route, &latency); - xbt_assert(!xbt_dynar_is_empty(route) || latency, - "You're trying to send data from %s to %s but there is no connection at all between these two hosts.", - src->name, dst->name); - - xbt_dynar_foreach(route, i, link) { - if (link->lmm_resource.state_current == SURF_RESOURCE_OFF) { - failed = 1; - break; - } - } - if (sg_network_crosstraffic == 1) { - routing_get_route_and_latency(dst, src, &back_route, NULL); - xbt_dynar_foreach(back_route, i, link) { - if (link->lmm_resource.state_current == SURF_RESOURCE_OFF) { - failed = 1; - break; - } - } - } - - action = - surf_action_new(sizeof(s_surf_action_network_CM02_t), size, - surf_network_model, failed); -#ifdef HAVE_LATENCY_BOUND_TRACKING - action->latency_limited = 0; -#endif - action->weight = action->latency = latency; - - xbt_swag_insert(action, ((surf_action_t)action)->state_set); - action->rate = rate; - if (surf_network_model->model_private->update_mechanism == UM_LAZY) { - GENERIC_LMM_ACTION(action).index_heap = -1; - GENERIC_LMM_ACTION(action).last_update = surf_get_clock(); - } - - bandwidth_bound = -1.0; - if (sg_weight_S_parameter > 0) { - xbt_dynar_foreach(route, i, link) { - action->weight += - sg_weight_S_parameter / - (link->lmm_resource.power.peak * link->lmm_resource.power.scale); - } - } - xbt_dynar_foreach(route, i, link) { - double bb = bandwidth_factor_callback(size) * - (link->lmm_resource.power.peak * link->lmm_resource.power.scale); - bandwidth_bound = - (bandwidth_bound < 0.0) ? bb : min(bandwidth_bound, bb); - } - - action->lat_current = action->latency; - action->latency *= latency_factor_callback(size); - action->rate = - bandwidth_constraint_callback(action->rate, bandwidth_bound, size); - if (gap_append) { - xbt_assert(!xbt_dynar_is_empty(route), - "Using a model with a gap (e.g., SMPI) with a platform without links (e.g. vivaldi)!!!"); - - link = *(link_CM02_t *) xbt_dynar_get_ptr(route, 0); - gap_append(size, link, action); - XBT_DEBUG("Comm %p: %s -> %s gap=%f (lat=%f)", - action, src->name, dst->name, action->sender.gap, - action->latency); - } - - constraints_per_variable = xbt_dynar_length(route); - if (back_route != NULL) - constraints_per_variable += xbt_dynar_length(back_route); - - if (action->latency > 0) { - GENERIC_LMM_ACTION(action).variable = - lmm_variable_new(surf_network_model->model_private->maxmin_system, action, 0.0, -1.0, - constraints_per_variable); - if (surf_network_model->model_private->update_mechanism == UM_LAZY) { - // add to the heap the event when the latency is payed - XBT_DEBUG("Added action (%p) one latency event at date %f", action, - action->latency + GENERIC_LMM_ACTION(action).last_update); - surf_action_lmm_heap_insert(surf_network_model->model_private->action_heap,(surf_action_lmm_t)action, action->latency + GENERIC_LMM_ACTION(action).last_update, - xbt_dynar_is_empty(route) ? NORMAL : LATENCY); - } - } else - GENERIC_LMM_ACTION(action).variable = - lmm_variable_new(surf_network_model->model_private->maxmin_system, action, 1.0, -1.0, - constraints_per_variable); - - if (action->rate < 0) { - lmm_update_variable_bound(surf_network_model->model_private->maxmin_system, GENERIC_LMM_ACTION(action).variable, - (action->lat_current > 0) ? - sg_tcp_gamma / (2.0 * - action->lat_current) : -1.0); - } else { - lmm_update_variable_bound(surf_network_model->model_private->maxmin_system, GENERIC_LMM_ACTION(action).variable, - (action->lat_current > 0) ? - min(action->rate, - sg_tcp_gamma / (2.0 * - action->lat_current)) - : action->rate); - } - - xbt_dynar_foreach(route, i, link) { - lmm_expand(surf_network_model->model_private->maxmin_system, link->lmm_resource.constraint, - GENERIC_LMM_ACTION(action).variable, 1.0); - } - - if (sg_network_crosstraffic == 1) { - XBT_DEBUG("Fullduplex active adding backward flow using 5%%"); - xbt_dynar_foreach(back_route, i, link) { - lmm_expand(surf_network_model->model_private->maxmin_system, link->lmm_resource.constraint, - GENERIC_LMM_ACTION(action).variable, .05); - } - } - - xbt_dynar_free(&route); - XBT_OUT(); - - return (surf_action_t) action; -} - -static xbt_dynar_t net_get_route(void *src, void *dst) -{ - xbt_dynar_t route = NULL; - routing_get_route_and_latency(src, dst, &route, NULL); - return route; -} - -static double net_get_link_bandwidth(const void *link) -{ - surf_resource_lmm_t lmm = (surf_resource_lmm_t) link; - return lmm->power.peak * lmm->power.scale; -} - -static double net_get_link_latency(const void *link) -{ - return ((link_CM02_t) link)->lat_current; -} - -static int net_link_shared(const void *link) -{ - return - lmm_constraint_is_shared(((surf_resource_lmm_t) link)->constraint); -} - -static void net_finalize(void) -{ - lmm_system_free(surf_network_model->model_private->maxmin_system); - surf_network_model->model_private->maxmin_system = NULL; - - if (surf_network_model->model_private->update_mechanism == UM_LAZY) { - xbt_heap_free(surf_network_model->model_private->action_heap); - xbt_swag_free(surf_network_model->model_private->modified_set); - } - - surf_model_exit(surf_network_model); - surf_network_model = NULL; - - xbt_dict_free(&gap_lookup); - xbt_dynar_free(&smpi_bw_factor); - xbt_dynar_free(&smpi_lat_factor); -} - -static void smpi_gap_append(double size, const link_CM02_t link, - surf_action_network_CM02_t action) -{ - const char *src = link->lmm_resource.generic_resource.name; - xbt_fifo_t fifo; - //surf_action_network_CM02_t last_action; - //double bw; - - if (sg_sender_gap > 0.0) { - if (!gap_lookup) { - gap_lookup = xbt_dict_new(); - } - fifo = (xbt_fifo_t) xbt_dict_get_or_null(gap_lookup, src); - action->sender.gap = 0.0; - if (fifo && xbt_fifo_size(fifo) > 0) { - /* Compute gap from last send */ - /*last_action = - (surf_action_network_CM02_t) - xbt_fifo_get_item_content(xbt_fifo_get_last_item(fifo));*/ - // bw = net_get_link_bandwidth(link); - action->sender.gap = sg_sender_gap; - /* max(sg_sender_gap,last_action->sender.size / bw);*/ - action->latency += action->sender.gap; - } - /* Append action as last send */ - /*action->sender.link_name = link->lmm_resource.generic_resource.name; - fifo = - (xbt_fifo_t) xbt_dict_get_or_null(gap_lookup, - action->sender.link_name); - if (!fifo) { - fifo = xbt_fifo_new(); - xbt_dict_set(gap_lookup, action->sender.link_name, fifo, NULL); - } - action->sender.fifo_item = xbt_fifo_push(fifo, action);*/ - action->sender.size = size; - } -} - -static void smpi_gap_remove(surf_action_lmm_t lmm_action) -{ - xbt_fifo_t fifo; - size_t size; - surf_action_network_CM02_t action = (surf_action_network_CM02_t)(lmm_action); - - if (sg_sender_gap > 0.0 && action->sender.link_name - && action->sender.fifo_item) { - fifo = - (xbt_fifo_t) xbt_dict_get_or_null(gap_lookup, - action->sender.link_name); - xbt_fifo_remove_item(fifo, action->sender.fifo_item); - size = xbt_fifo_size(fifo); - if (size == 0) { - xbt_fifo_free(fifo); - xbt_dict_remove(gap_lookup, action->sender.link_name); - size = xbt_dict_length(gap_lookup); - if (size == 0) { - xbt_dict_free(&gap_lookup); - } - } - } -} - -static void set_update_mechanism(void) -{ - char *optim = xbt_cfg_get_string(_sg_cfg_set, "network/optim"); - int select = - xbt_cfg_get_boolean(_sg_cfg_set, "network/maxmin_selective_update"); - - if (!strcmp(optim, "Full")) { - surf_network_model->model_private->update_mechanism = UM_FULL; - surf_network_model->model_private->selective_update = select; - } else if (!strcmp(optim, "Lazy")) { - surf_network_model->model_private->update_mechanism = UM_LAZY; - surf_network_model->model_private->selective_update = 1; - xbt_assert((select == 1) - || - (xbt_cfg_is_default_value - (_sg_cfg_set, "network/maxmin_selective_update")), - "Disabling selective update while using the lazy update mechanism is dumb!"); - } else { - xbt_die("Unsupported optimization (%s) for this model", optim); - } -} - -static void surf_network_model_init_internal(void) -{ - s_surf_action_network_CM02_t comm; - surf_network_model = surf_model_init(); - - set_update_mechanism(); - - surf_network_model->name = "network"; - surf_network_model->action_unref = surf_action_unref; - surf_network_model->action_cancel = surf_action_cancel; - surf_network_model->action_recycle = net_action_recycle; - - surf_network_model->get_remains = surf_action_get_remains; - -#ifdef HAVE_LATENCY_BOUND_TRACKING - surf_network_model->get_latency_limited = net_get_link_latency_limited; -#endif -#ifdef HAVE_TRACING - surf_network_model->set_category = surf_action_set_category; -#endif - - surf_network_model->model_private->resource_used = net_resource_used; - if (surf_network_model->model_private->update_mechanism == UM_LAZY) { - surf_network_model->model_private->share_resources = - net_share_resources_lazy; - surf_network_model->model_private->update_actions_state = - net_update_actions_state_lazy; - } else if (surf_network_model->model_private->update_mechanism == UM_FULL) { - surf_network_model->model_private->share_resources = - net_share_resources_full; - surf_network_model->model_private->update_actions_state = - net_update_actions_state_full; - } - - surf_network_model->model_private->update_resource_state = - net_update_resource_state; - surf_network_model->model_private->finalize = net_finalize; - - surf_network_model->suspend = surf_action_suspend; - surf_network_model->resume = surf_action_resume; - surf_network_model->is_suspended = surf_action_is_suspended; - surf_cpu_model->set_max_duration = surf_action_set_max_duration; - - surf_network_model->extension.network.communicate = net_communicate; - surf_network_model->extension.network.get_route = net_get_route; - surf_network_model->extension.network.get_link_bandwidth = - net_get_link_bandwidth; - surf_network_model->extension.network.get_link_latency = - net_get_link_latency; - surf_network_model->extension.network.link_shared = net_link_shared; - surf_network_model->extension.network.add_traces = net_add_traces; - - if (!surf_network_model->model_private->maxmin_system) - surf_network_model->model_private->maxmin_system = lmm_system_new(surf_network_model->model_private->selective_update); - - routing_model_create(net_create_resource("__loopback__", - 498000000, NULL, 0.000015, NULL, - SURF_RESOURCE_ON, NULL, - SURF_LINK_FATPIPE, NULL)); - - if (surf_network_model->model_private->update_mechanism == UM_LAZY) { - surf_network_model->model_private->action_heap = xbt_heap_new(8, NULL); - xbt_heap_set_update_callback(surf_network_model->model_private->action_heap, - surf_action_lmm_update_index_heap); - surf_network_model->model_private->modified_set = - xbt_swag_new(xbt_swag_offset(comm, generic_lmm_action.action_list_hookup)); - surf_network_model->model_private->maxmin_system->keep_track = surf_network_model->model_private->modified_set; - } - - surf_network_model->gap_remove = NULL; -} - -/************************************************************************/ -/* New model based on LV08 and experimental results of MPI ping-pongs */ -/************************************************************************/ -/* @Inproceedings{smpi_ipdps, */ -/* author={Pierre-Nicolas Clauss and Mark Stillwell and Stéphane Genaud and Frédéric Suter and Henri Casanova and Martin Quinson}, */ -/* title={Single Node On-Line Simulation of {MPI} Applications with SMPI}, */ -/* booktitle={25th IEEE International Parallel and Distributed Processing Symposium (IPDPS'11)}, */ -/* address={Anchorage (Alaska) USA}, */ -/* month=may, */ -/* year={2011} */ -/* } */ -void surf_network_model_init_SMPI(void) -{ - - if (surf_network_model) - return; - - surf_network_model_init_internal(); - latency_factor_callback = &smpi_latency_factor; - bandwidth_factor_callback = &smpi_bandwidth_factor; - bandwidth_constraint_callback = &smpi_bandwidth_constraint; - gap_append = &smpi_gap_append; - surf_network_model->gap_remove = &smpi_gap_remove; - net_define_callbacks(); - xbt_dynar_push(model_list, &surf_network_model); - network_solve = lmm_solve; - - xbt_cfg_setdefault_double(_sg_cfg_set, "network/sender_gap", 10e-6); - xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S", 8775); -} - -/************************************************************************/ -/* New model based on optimizations discussed during Pedro Velho's thesis*/ -/************************************************************************/ -/* @techreport{VELHO:2011:HAL-00646896:1, */ -/* url = {http://hal.inria.fr/hal-00646896/en/}, */ -/* title = {{Flow-level network models: have we reached the limits?}}, */ -/* author = {Velho, Pedro and Schnorr, Lucas and Casanova, Henri and Legrand, Arnaud}, */ -/* type = {Rapport de recherche}, */ -/* institution = {INRIA}, */ -/* number = {RR-7821}, */ -/* year = {2011}, */ -/* month = Nov, */ -/* pdf = {http://hal.inria.fr/hal-00646896/PDF/rr-validity.pdf}, */ -/* } */ -void surf_network_model_init_LegrandVelho(void) -{ - if (surf_network_model) - return; - - surf_network_model_init_internal(); - net_define_callbacks(); - xbt_dynar_push(model_list, &surf_network_model); - network_solve = lmm_solve; - - xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor", - 13.01); - xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor", - 0.97); - xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S", 20537); -} - -/***************************************************************************/ -/* The nice TCP sharing model designed by Loris Marchal and Henri Casanova */ -/***************************************************************************/ -/* @TechReport{ rr-lip2002-40, */ -/* author = {Henri Casanova and Loris Marchal}, */ -/* institution = {LIP}, */ -/* title = {A Network Model for Simulation of Grid Application}, */ -/* number = {2002-40}, */ -/* month = {oct}, */ -/* year = {2002} */ -/* } */ -void surf_network_model_init_CM02(void) -{ - - if (surf_network_model) - return; - - surf_network_model_init_internal(); - net_define_callbacks(); - xbt_dynar_push(model_list, &surf_network_model); - network_solve = lmm_solve; - - xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor", 1.0); - xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor", - 1.0); - xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S", 0.0); -} - -/***************************************************************************/ -/* The models from Steven H. Low */ -/***************************************************************************/ -/* @article{Low03, */ -/* author={Steven H. Low}, */ -/* title={A Duality Model of {TCP} and Queue Management Algorithms}, */ -/* year={2003}, */ -/* journal={{IEEE/ACM} Transactions on Networking}, */ -/* volume={11}, number={4}, */ -/* } */ -void surf_network_model_init_Reno(void) -{ - if (surf_network_model) - return; - - surf_network_model_init_internal(); - net_define_callbacks(); - - xbt_dynar_push(model_list, &surf_network_model); - lmm_set_default_protocol_function(func_reno_f, func_reno_fp, - func_reno_fpi); - network_solve = lagrange_solve; - - xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor", 10.4); - xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor", - 0.92); - xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S", 8775); -} - - -void surf_network_model_init_Reno2(void) -{ - if (surf_network_model) - return; - - surf_network_model_init_internal(); - net_define_callbacks(); - - xbt_dynar_push(model_list, &surf_network_model); - lmm_set_default_protocol_function(func_reno2_f, func_reno2_fp, - func_reno2_fpi); - network_solve = lagrange_solve; - - xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor", 10.4); - xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor", - 0.92); - xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S_parameter", - 8775); -} - -void surf_network_model_init_Vegas(void) -{ - if (surf_network_model) - return; - - surf_network_model_init_internal(); - net_define_callbacks(); - - xbt_dynar_push(model_list, &surf_network_model); - lmm_set_default_protocol_function(func_vegas_f, func_vegas_fp, - func_vegas_fpi); - network_solve = lagrange_solve; - - xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor", 10.4); - xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor", - 0.92); - xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S", 8775); -} diff --git a/src/surf/network_constant.c b/src/surf/network_constant.c deleted file mode 100644 index 5dcff1b9f9..0000000000 --- a/src/surf/network_constant.c +++ /dev/null @@ -1,238 +0,0 @@ -/* Copyright (c) 2008, 2009, 2010. The SimGrid Team. - * All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ - -#include "surf_private.h" -#include "surf/random_mgr.h" -#include "xbt/dict.h" -#include "xbt/str.h" -#include "xbt/log.h" - -typedef struct surf_action_network_Constant { - s_surf_action_t generic_action; - double latency; - double lat_init; - int suspended; -} s_surf_action_network_Constant_t, *surf_action_network_Constant_t; - -XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_network); -static random_data_t random_latency = NULL; -static int host_number_int = 0; - -static void netcste_count_hosts(sg_platf_host_cbarg_t h) { - host_number_int++; -} - -static void netcste_define_callbacks(void) { - sg_platf_host_add_cb(netcste_count_hosts); -} - -static int netcste_resource_used(void *resource_id) -{ - return 0; -} - -static int netcste_action_unref(surf_action_t action) -{ - action->refcount--; - if (!action->refcount) { - xbt_swag_remove(action, action->state_set); - surf_action_free(&action); - return 1; - } - return 0; -} - -static void netcste_action_cancel(surf_action_t action) -{ - return; -} - -static double netcste_share_resources(double now) -{ - surf_action_network_Constant_t action = NULL; - xbt_swag_t running_actions = - surf_network_model->states.running_action_set; - double min = -1.0; - - xbt_swag_foreach(action, running_actions) { - if (action->latency > 0) { - if (min < 0) - min = action->latency; - else if (action->latency < min) - min = action->latency; - } - } - - return min; -} - -static void netcste_update_actions_state(double now, double delta) -{ - surf_action_network_Constant_t action = NULL; - surf_action_network_Constant_t next_action = NULL; - xbt_swag_t running_actions = - surf_network_model->states.running_action_set; - - xbt_swag_foreach_safe(action, next_action, running_actions) { - if (action->latency > 0) { - if (action->latency > delta) { - double_update(&(action->latency), delta); - } else { - action->latency = 0.0; - } - } - double_update(&(action->generic_action.remains), - action->generic_action.cost * delta / action->lat_init); - if (action->generic_action.max_duration != NO_MAX_DURATION) - double_update(&(action->generic_action.max_duration), delta); - - if (action->generic_action.remains <= 0) { - action->generic_action.finish = surf_get_clock(); - surf_network_model->action_state_set((surf_action_t) action, - SURF_ACTION_DONE); - } else if ((action->generic_action.max_duration != NO_MAX_DURATION) - && (action->generic_action.max_duration <= 0)) { - action->generic_action.finish = surf_get_clock(); - surf_network_model->action_state_set((surf_action_t) action, - SURF_ACTION_DONE); - } - } -} - -static void netcste_update_resource_state(void *id, - tmgr_trace_event_t event_type, - double value, double time) -{ - DIE_IMPOSSIBLE; -} - -static surf_action_t netcste_communicate(sg_routing_edge_t src, - sg_routing_edge_t dst, - double size, double rate) -{ - surf_action_network_Constant_t action = NULL; - - char *src_name = src->name; - char *dst_name = dst->name; - - XBT_IN("(%s,%s,%g,%g)", src_name, dst_name, size, rate); - - action = - surf_action_new(sizeof(s_surf_action_network_Constant_t), size, - surf_network_model, 0); - - action->suspended = 0; - - action->latency = sg_latency_factor; //random_generate(random_latency); - action->lat_init = action->latency; - - if (action->latency <= 0.0) { - action->generic_action.state_set = - surf_network_model->states.done_action_set; - xbt_swag_insert(action, action->generic_action.state_set); - } - - XBT_OUT(); - - return (surf_action_t) action; -} - -#ifdef HAVE_TRACING -static void netcste_action_set_category(surf_action_t action, const char *category) -{ - //ignore completely the categories in constant model, they are not traced -} -#endif - -static double netcste_get_link_bandwidth(const void *link) -{ - DIE_IMPOSSIBLE; - return -1.0; /* useless since DIE actually abort(), but eclipse prefer to have a useless and harmless return */ -} - -static double netcste_get_link_latency(const void *link) -{ - DIE_IMPOSSIBLE; - return -1.0; /* useless since DIE actually abort(), but eclipse prefer to have a useless and harmless return */ -} - -static int link_shared(const void *link) -{ - DIE_IMPOSSIBLE; - return -1; /* useless since DIE actually abort(), but eclipse prefer to have a useless and harmless return */ -} - -static void netcste_action_suspend(surf_action_t action) -{ - ((surf_action_network_Constant_t) action)->suspended = 1; -} - -static void netcste_action_resume(surf_action_t action) -{ - if (((surf_action_network_Constant_t) action)->suspended) - ((surf_action_network_Constant_t) action)->suspended = 0; -} - -static int netcste_action_is_suspended(surf_action_t action) -{ - return ((surf_action_network_Constant_t) action)->suspended; -} - -static void netcste_finalize(void) -{ - surf_model_exit(surf_network_model); - surf_network_model = NULL; -} - - - -void surf_network_model_init_Constant() -{ - xbt_assert(surf_network_model == NULL); - if (surf_network_model) - return; - surf_network_model = surf_model_init(); - - surf_network_model->name = "constant time network"; - surf_network_model->action_unref = netcste_action_unref; - surf_network_model->action_cancel = netcste_action_cancel; - surf_network_model->action_recycle = net_action_recycle; - surf_network_model->get_remains = surf_action_get_remains; -#ifdef HAVE_LATENCY_BOUND_TRACKING - surf_network_model->get_latency_limited = net_get_link_latency_limited; -#endif - - surf_network_model->model_private->resource_used = netcste_resource_used; - surf_network_model->model_private->share_resources = - netcste_share_resources; - surf_network_model->model_private->update_actions_state = - netcste_update_actions_state; - surf_network_model->model_private->update_resource_state = - netcste_update_resource_state; - surf_network_model->model_private->finalize = netcste_finalize; - - surf_network_model->suspend = netcste_action_suspend; - surf_network_model->resume = netcste_action_resume; - surf_network_model->is_suspended = netcste_action_is_suspended; - surf_cpu_model->set_max_duration = surf_action_set_max_duration; - - surf_network_model->extension.network.communicate = netcste_communicate; - surf_network_model->extension.network.get_link_bandwidth = - netcste_get_link_bandwidth; - surf_network_model->extension.network.get_link_latency = - netcste_get_link_latency; - surf_network_model->extension.network.link_shared = link_shared; -#ifdef HAVE_TRACING - surf_network_model->set_category = netcste_action_set_category; -#endif - - if (!random_latency) - random_latency = random_new(RAND, 100, 0.0, 1.0, .125, .034); - netcste_define_callbacks(); - xbt_dynar_push(model_list, &surf_network_model); - - routing_model_create(NULL); -} diff --git a/src/surf/network_gtnets.c b/src/surf/network_gtnets.c deleted file mode 100644 index 8207982393..0000000000 --- a/src/surf/network_gtnets.c +++ /dev/null @@ -1,468 +0,0 @@ -/* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team. - * All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ - -#include "network_gtnets_private.h" -#include "gtnets/gtnets_interface.h" -#include "xbt/str.h" -#include "surf/surfxml_parse_values.h" - -static double time_to_next_flow_completion = -1; - -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_network_gtnets, surf, - "Logging specific to the SURF network GTNetS module"); - -extern routing_platf_t routing_platf; - -double sg_gtnets_jitter = 0.0; -int sg_gtnets_jitter_seed = 10; - -static void link_new(const char *name, double bw, double lat, xbt_dict_t props) -{ - static int link_count = -1; - network_link_GTNETS_t gtnets_link; - - if (xbt_lib_get_or_null(link_lib, name, SURF_LINK_LEVEL)) { - return; - } - - XBT_DEBUG("Scanning link name %s", name); - - - gtnets_link = xbt_new0(s_network_link_GTNETS_t, 1); - gtnets_link->generic_resource.name = xbt_strdup(name); - gtnets_link->generic_resource.properties = props; - gtnets_link->bw_current = bw; - gtnets_link->lat_current = lat; - - link_count++; - - XBT_DEBUG("Adding new link, linkid %d, name %s, latency %g, bandwidth %g", - link_count, name, lat, bw); - - if (gtnets_add_link(link_count, bw, lat)) { - xbt_die("Cannot create GTNetS link"); - } - gtnets_link->id = link_count; - - xbt_lib_set(link_lib, name, SURF_LINK_LEVEL, gtnets_link); -} - -static void route_new(int src_id, int dst_id, xbt_dynar_t links, - int nb_link) -{ - network_link_GTNETS_t link; - unsigned int cursor; - int i = 0; - int *gtnets_links; - - XBT_IN("(src_id=%d, dst_id=%d, links=%p, nb_link=%d)", - src_id, dst_id, links, nb_link); - - /* Build the list of gtnets link IDs */ - gtnets_links = xbt_new0(int, nb_link); - i = 0; - xbt_dynar_foreach(links, cursor, link) { - gtnets_links[i++] = link->id; - } - - if (gtnets_add_route(src_id, dst_id, gtnets_links, nb_link)) { - xbt_die("Cannot create GTNetS route"); - } - XBT_OUT(); -} - -static void route_onehop_new(int src_id, int dst_id, - network_link_GTNETS_t link) -{ - if (gtnets_add_onehop_route(src_id, dst_id, link->id)) { - xbt_die("Cannot create GTNetS route"); - } -} - -/* Parse the XML for a network link */ -static void parse_link_init(sg_platf_link_cbarg_t link) -{ - XBT_DEBUG("link_gtnets"); - - if (link->bandwidth_trace) - XBT_INFO - ("The GTNetS network model doesn't support bandwidth state traces"); - if (link->latency_trace) - XBT_INFO("The GTNetS network model doesn't support latency state traces"); - if (link->state_trace) - XBT_INFO("The GTNetS network model doesn't support link state traces"); - - if (link->policy == SURF_LINK_FULLDUPLEX) - { - link_new(bprintf("%s_UP",link->id), link->bandwidth, link->latency, current_property_set); - link_new(bprintf("%s_DOWN",link->id), link->bandwidth, link->latency, current_property_set); - - } - else link_new(link->id, link->bandwidth, link->latency, current_property_set); - current_property_set = NULL; -} - -/* Create the gtnets topology based on routing strategy */ -static void create_gtnets_topology(void) -{ - XBT_DEBUG("Starting topology generation"); -// FIXME: We should take the list of hosts/routers (in the routing module), number the elements of this list, -// and then you can use the id to reimplement properly the following GTNets calls - - //get the onelinks from the parsed platform - xbt_dynar_t onelink_routes = routing_platf->get_onelink_routes(); - if (!onelink_routes) - return; - - //save them in trace file - onelink_t onelink; - unsigned int iter; - xbt_dynar_foreach(onelink_routes, iter, onelink) { - void *link = onelink->link_ptr; - - if(onelink->src->id != onelink->dst->id){ - XBT_DEBUG("Link (#%p), src (#%s), dst (#%s), src_id = %d, dst_id = %d", - link, - onelink->src->name, - onelink->dst->name, - onelink->src->id, - onelink->dst->id); - XBT_DEBUG("Calling one link route"); - if(onelink->src->rc_type == SURF_NETWORK_ELEMENT_ROUTER){ - gtnets_add_router(onelink->src->id); - } - if(onelink->dst->rc_type == SURF_NETWORK_ELEMENT_ROUTER){ - gtnets_add_router(onelink->dst->id); - } - route_onehop_new(onelink->src->id, onelink->dst->id, (network_link_GTNETS_t)(link)); - } - } - - if (XBT_LOG_ISENABLED(surf_network_gtnets, xbt_log_priority_debug)) { - gtnets_print_topology(); - } -} - -/* Main XML parsing */ -static void define_callbacks(void) -{ - /* Figuring out the network links */ - sg_platf_link_add_cb (&parse_link_init); - sg_platf_postparse_add_cb(&create_gtnets_topology); -} - -static int resource_used(void *resource_id) -{ - xbt_die("The resource_used feature is not implemented in GTNets model"); -} - -static int action_unref(surf_action_t action) -{ - action->refcount--; - if (!action->refcount) { - xbt_swag_remove(action, action->state_set); -#ifdef HAVE_TRACING - xbt_free(action->category); -#endif - surf_action_free(&action); - return 1; - } - return 0; -} - -static void action_cancel(surf_action_t action) -{ - xbt_die("Cannot cancel GTNetS flow"); - return; -} - -static void action_recycle(surf_action_t action) -{ - xbt_die("Cannot recycle GTNetS flow"); - return; -} - -static double action_get_remains(surf_action_t action) -{ - return action->remains; -} - -static void action_state_set(surf_action_t action, - e_surf_action_state_t state) -{ - surf_action_state_set(action, state); -} - -static double share_resources(double now) -{ - xbt_swag_t running_actions = - surf_network_model->states.running_action_set; - - //get the first relevant value from the running_actions list - if (!xbt_swag_size(running_actions)) - return -1.0; - - xbt_assert(time_to_next_flow_completion, - "Time to next flow completion not initialized!\n"); - - XBT_DEBUG("Calling gtnets_get_time_to_next_flow_completion"); - time_to_next_flow_completion = gtnets_get_time_to_next_flow_completion(); - XBT_DEBUG("gtnets_get_time_to_next_flow_completion received %lg", - time_to_next_flow_completion); - - return time_to_next_flow_completion; -} - -static void update_actions_state(double now, double delta) -{ - surf_action_network_GTNETS_t action = NULL; - xbt_swag_t running_actions = - surf_network_model->states.running_action_set; - - /* If there are no running flows, just return */ - if (time_to_next_flow_completion < 0.0) { - return; - } - - /* if delta == time_to_next_flow_completion, too. */ - if (time_to_next_flow_completion <= delta) { /* run until the first flow completes */ - void **metadata; - int i, num_flows; - - num_flows = 0; - - if (gtnets_run_until_next_flow_completion(&metadata, &num_flows)) { - xbt_die("Cannot run GTNetS simulation until next flow completion"); - } - if (num_flows < 1) { - xbt_die("GTNetS simulation couldn't find a flow that would complete"); - } - - xbt_swag_foreach(action, running_actions) { - XBT_DEBUG("Action (%p) remains old value: %f", action, - action->generic_action.remains); - double sent = gtnets_get_flow_rx(action); - - XBT_DEBUG("Sent value returned by GTNetS : %f", sent); - -#ifdef HAVE_TRACING - action->last_remains = action->generic_action.remains; -#endif - - //need to trust this remain value - if (sent == 0) { - action->generic_action.remains = 0; - } else { - action->generic_action.remains = - action->generic_action.cost - sent; - } - - // verify that this action is a finishing action. - int found=0; - for (i = 0; i < num_flows; i++) { - if(action == (surf_action_network_GTNETS_t) (metadata[i])){ - found = 1; - break; - } - } - - // indeed this action have not yet started - // because of that we need to fix the remaining to the - // original total cost - if(found != 1 && action->generic_action.remains == 0 ){ - action->generic_action.remains = action->generic_action.cost; - } - - XBT_DEBUG("Action (%p) remains new value: %f", action, - action->generic_action.remains); - -#ifdef HAVE_TRACING - if (TRACE_is_enabled()) { - double last_amount_sent = (action->generic_action.cost - action->last_remains); - double amount_sent = (action->generic_action.cost - action->generic_action.remains); - - // tracing resource utilization - xbt_dynar_t route = NULL; - - routing_get_route_and_latency (action->src, action->dst, &route, NULL); - - unsigned int i; - for (i = 0; i < xbt_dynar_length (route); i++){ - network_link_GTNETS_t *link = ((network_link_GTNETS_t*)xbt_dynar_get_ptr (route, i)); - TRACE_surf_link_set_utilization ((*link)->generic_resource.name, - ((surf_action_t) action)->category, - (amount_sent - last_amount_sent)/(delta), - now-delta, - delta); - } - } -#endif - - - } - - for (i = 0; i < num_flows; i++) { - action = (surf_action_network_GTNETS_t) (metadata[i]); - - - - action->generic_action.finish = now + time_to_next_flow_completion; - action_state_set((surf_action_t) action, SURF_ACTION_DONE); - XBT_DEBUG("----> Action (%p) just terminated", action); - - } - - - } else { /* run for a given number of seconds */ - if (gtnets_run(delta)) { - xbt_die("Cannot run GTNetS simulation"); - } - } - - return; -} - -static void update_resource_state(void *id, - tmgr_trace_event_t event_type, - double value, double date) -{ - xbt_die("Cannot update model state for GTNetS simulation"); -} - -/* Max durations are not supported */ -static surf_action_t communicate(sg_routing_edge_t src_card, - sg_routing_edge_t dst_card, - double size, double rate) -{ - surf_action_network_GTNETS_t action = NULL; - - int src = src_card->id; - int dst = dst_card->id; - char *src_name = src_card->name; - char *dst_name = dst_card->name; - - xbt_assert((src >= 0 - && dst >= 0), "Either src or dst have invalid id (id<0)"); - - XBT_DEBUG("Setting flow src %d \"%s\", dst %d \"%s\"", src, src_name, dst, - dst_name); - - xbt_dynar_t route = NULL; - - routing_get_route_and_latency(src_card, dst_card, &route, NULL); - - route_new(src, dst, route, xbt_dynar_length(route)); - - action = - surf_action_new(sizeof(s_surf_action_network_GTNETS_t), size, - surf_network_model, 0); - -#ifdef HAVE_TRACING - action->last_remains = 0; -#endif - - /* Add a flow to the GTNets Simulation, associated to this action */ - if (gtnets_create_flow(src, dst, size, (void *) action) < 0) { - xbt_die("Not route between host %s and host %s", src_name, dst_name); - } -#ifdef HAVE_TRACING - TRACE_surf_gtnets_communicate(action, src_card, dst_card); -#endif - - return (surf_action_t) action; -} - -/* Suspend a flow() */ -static void action_suspend(surf_action_t action) -{ - THROW_UNIMPLEMENTED; -} - -/* Resume a flow() */ -static void action_resume(surf_action_t action) -{ - THROW_UNIMPLEMENTED; -} - -/* Test whether a flow is suspended */ -static int action_is_suspended(surf_action_t action) -{ - return 0; -} - -#ifdef HAVE_TRACING -static void gtnets_action_set_category(surf_action_t action, const char *category) -{ - action->category = xbt_strdup (category); -} -#endif - -static void finalize(void) -{ - gtnets_finalize(); -} - -static void surf_network_model_init_internal(void) -{ - surf_network_model = surf_model_init(); - - surf_network_model->name = "network GTNetS"; - surf_network_model->action_unref = action_unref; - surf_network_model->action_cancel = action_cancel; - surf_network_model->action_recycle = action_recycle; - surf_network_model->action_state_set = action_state_set; - surf_network_model->get_remains = action_get_remains; - - surf_network_model->model_private->resource_used = resource_used; - surf_network_model->model_private->share_resources = share_resources; - surf_network_model->model_private->update_actions_state = - update_actions_state; - surf_network_model->model_private->update_resource_state = - update_resource_state; - surf_network_model->model_private->finalize = finalize; - - surf_network_model->suspend = action_suspend; - surf_network_model->resume = action_resume; - surf_network_model->is_suspended = action_is_suspended; -#ifdef HAVE_TRACING - surf_network_model->set_category = gtnets_action_set_category; -#endif - - surf_network_model->extension.network.communicate = communicate; - - /* Added the initialization for GTNetS interface */ - if (gtnets_initialize(sg_tcp_gamma)) { - xbt_die("Impossible to initialize GTNetS interface"); - } - - routing_model_create(NULL); -} - -#ifdef HAVE_LATENCY_BOUND_TRACKING -static int get_latency_limited(surf_action_t action) -{ - return 0; -} -#endif - -void surf_network_model_init_GTNETS(void) -{ - if (surf_network_model) - return; - - surf_network_model_init_internal(); - define_callbacks(); - xbt_dynar_push(model_list, &surf_network_model); - -#ifdef HAVE_LATENCY_BOUND_TRACKING - surf_network_model->get_latency_limited = get_latency_limited; -#endif - - if (sg_gtnets_jitter > 0.0) { - gtnets_set_jitter(sg_gtnets_jitter); - gtnets_set_jitter_seed(sg_gtnets_jitter_seed); - } -} diff --git a/src/surf/new_model.c b/src/surf/new_model.c deleted file mode 100644 index 3881a7458a..0000000000 --- a/src/surf/new_model.c +++ /dev/null @@ -1,189 +0,0 @@ -/* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012. The SimGrid Team. - * All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ - -/* ********************************************************************* */ -/* TUTORIAL: New model */ -/* ********************************************************************* */ - -#include "xbt/ex.h" -#include "xbt/dict.h" -#include "portable.h" -#include "surf_private.h" -#include "new_model_private.h" -#include "surf/surf_resource.h" - -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_new_model, surf, - "Logging specific to the SURF new model module"); - -surf_model_t surf_new_model = NULL; -lmm_system_t new_model_maxmin_system = NULL; -/*FIXME: -static int new_model_selective_update = 0; -static xbt_swag_t - new_model_running_action_set_that_does_not_need_being_checked = NULL; -*/ - -#define GENERIC_LMM_ACTION(action) action->generic_lmm_action -#define GENERIC_ACTION(action) GENERIC_LMM_ACTION(action).generic_action - -void surf_new_model_init_default(void){} - -//FIXME:UPDATE FOR SURF++ -#ifdef UPDATE_FOR_SURFPP -static void new_model_action_state_set(surf_action_t action, e_surf_action_state_t state); - -static surf_action_t new_model_action_execute () -{ - THROW_UNIMPLEMENTED; - return NULL; -} - -static surf_action_t new_model_action_fct() -{ - surf_action_t action = new_model_action_execute(); - return action; -} - -static void* new_model_create_resource(const char* id, const char* model,const char* type_id,const char* content_name) -{ - THROW_UNIMPLEMENTED; - return NULL; -} - -static void new_model_finalize(void) -{ - lmm_system_free(new_model_maxmin_system); - new_model_maxmin_system = NULL; - - surf_model_exit(surf_new_model); - surf_new_model = NULL; - - xbt_swag_free - (new_model_running_action_set_that_does_not_need_being_checked); - new_model_running_action_set_that_does_not_need_being_checked = NULL; -} - -static void new_model_update_actions_state(double now, double delta) -{ - return; -} - -static double new_model_share_resources(double NOW) -{ - return -1; -} - -static int new_model_resource_used(void *resource_id) -{ - THROW_UNIMPLEMENTED; - return 0; -} - -static void new_model_resources_state(void *id, tmgr_trace_event_t event_type, - double value, double time) -{ - THROW_UNIMPLEMENTED; -} - -static int new_model_action_unref(surf_action_t action) -{ - THROW_UNIMPLEMENTED; - return 0; -} - -static void new_model_action_cancel(surf_action_t action) -{ - surf_action_state_set(action, SURF_ACTION_FAILED); - return; -} - -static void new_model_action_state_set(surf_action_t action, e_surf_action_state_t state) -{ - surf_action_state_set(action, state); - return; -} - -static void new_model_action_suspend(surf_action_t action) -{ - XBT_IN("(%p)", action); - if (((surf_action_lmm_t) action)->suspended != 2) { - lmm_update_variable_weight(new_model_maxmin_system, - ((surf_action_lmm_t) action)->variable, - 0.0); - ((surf_action_lmm_t) action)->suspended = 1; - } - XBT_OUT(); -} - -static void new_model_action_resume(surf_action_t action) -{ - THROW_UNIMPLEMENTED; -} - -static int new_model_action_is_suspended(surf_action_t action) -{ - return (((surf_action_lmm_t) action)->suspended == 1); -} - -static void new_model_action_set_max_duration(surf_action_t action, double duration) -{ - THROW_UNIMPLEMENTED; -} - -static void new_model_action_set_priority(surf_action_t action, double priority) -{ - THROW_UNIMPLEMENTED; -} - -static void new_model_define_callbacks() -{ -} - -static void surf_new_model_init_internal(void) -{ - s_surf_action_t action; - - XBT_DEBUG("surf_new_model_model_init_internal"); - surf_new_model = surf_model_init(); - - new_model_running_action_set_that_does_not_need_being_checked = - xbt_swag_new(xbt_swag_offset(action, state_hookup)); - - surf_new_model->name = "New Model"; - surf_new_model->action_unref = new_model_action_unref; - surf_new_model->action_cancel = new_model_action_cancel; - surf_new_model->action_state_set = new_model_action_state_set; - - surf_new_model->model_private->finalize = new_model_finalize; - surf_new_model->model_private->update_actions_state = new_model_update_actions_state; - surf_new_model->model_private->share_resources = new_model_share_resources; - surf_new_model->model_private->resource_used = new_model_resource_used; - surf_new_model->model_private->update_resource_state = new_model_resources_state; - - surf_new_model->suspend = new_model_action_suspend; - surf_new_model->resume = new_model_action_resume; - surf_new_model->is_suspended = new_model_action_is_suspended; - surf_new_model->set_max_duration = new_model_action_set_max_duration; - surf_new_model->set_priority = new_model_action_set_priority; - - surf_new_model->extension.new_model.fct = new_model_action_fct; - surf_new_model->extension.new_model.create_resource = new_model_create_resource; - - if (!new_model_maxmin_system) { - new_model_maxmin_system = lmm_system_new(new_model_selective_update); - } - -} - -void surf_new_model_init_default(void) -{ - surf_new_model_init_internal(); - new_model_define_callbacks(); - - xbt_dynar_push(model_list, &surf_new_model); -} - -#endif diff --git a/src/surf/new_model_private.h b/src/surf/new_model_private.h deleted file mode 100644 index 3cdbeeb8b1..0000000000 --- a/src/surf/new_model_private.h +++ /dev/null @@ -1,14 +0,0 @@ -/* - * TUTORIAL: New model - * new_model_private.h - * - * Created on: 12 October 2012 - * Author: navarro - */ - -#ifndef NEW_MODEL_PRIVATE_H_ -#define NEW_MODEL_PRIVATE_H_ - - - -#endif /* NEW_MODEL_PRIVATE_H_ */ diff --git a/src/surf/storage.c b/src/surf/storage.c deleted file mode 100644 index 599210cb0d..0000000000 --- a/src/surf/storage.c +++ /dev/null @@ -1,662 +0,0 @@ -/* Copyright (c) 2004 - 2013. The SimGrid Team. - * All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ - -#include "xbt/ex.h" -#include "xbt/dict.h" -#include "portable.h" -#include "surf_private.h" -#include "storage_private.h" -#include "surf/surf_resource.h" - -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_storage, surf, - "Logging specific to the SURF storage module"); - -xbt_lib_t storage_lib; -int ROUTING_STORAGE_LEVEL; //Routing for storagelevel -int ROUTING_STORAGE_HOST_LEVEL; -int SURF_STORAGE_LEVEL; -xbt_lib_t storage_type_lib; -int ROUTING_STORAGE_TYPE_LEVEL; //Routing for storage_type level - -xbt_dynar_t mount_list = NULL; /* temporary store of current mount storage */ - -surf_model_t surf_storage_model = NULL; -lmm_system_t storage_maxmin_system = NULL; -static int storage_selective_update = 0; -static xbt_swag_t - storage_running_action_set_that_does_not_need_being_checked = NULL; - -static xbt_dynar_t storage_list; - -#define GENERIC_LMM_ACTION(action) action->generic_lmm_action -#define GENERIC_ACTION(action) GENERIC_LMM_ACTION(action).generic_action - -static xbt_dict_t parse_storage_content(char *filename, size_t *used_size); -static int storage_action_unref(surf_action_t action); -static void storage_action_state_set(surf_action_t action, e_surf_action_state_t state); -static surf_action_t storage_action_execute (void *storage, size_t size, e_surf_action_storage_type_t type); - -static surf_action_t storage_action_ls(void *storage, const char* path) -{ - surf_action_t action = storage_action_execute(storage,0, LS); - action->ls_dict = NULL; - xbt_dict_t ls_dict = xbt_dict_new(); - - char* key; - size_t size = 0; - xbt_dict_cursor_t cursor = NULL; - - xbt_dynar_t dyn = NULL; - char* file = NULL; - - // for each file in the storage content - xbt_dict_foreach(((storage_t)storage)->content,cursor,key,size){ - // Search if file start with the prefix 'path' - if(xbt_str_start_with(key,path)){ - file = &key[strlen(path)]; - - // Split file with '/' - dyn = xbt_str_split(file,"/"); - file = xbt_dynar_get_as(dyn,0,char*); - - // file - if(xbt_dynar_length(dyn) == 1){ - xbt_dict_set(ls_dict,file,&size,NULL); - } - // Directory - else - { - // if directory does not exist yet in the dictionary - if(!xbt_dict_get_or_null(ls_dict,file)) - xbt_dict_set(ls_dict,file,NULL,NULL); - } - xbt_dynar_free(&dyn); - } - } - - action->ls_dict = ls_dict; - return action; -} - -static surf_action_t storage_action_open(void *storage, const char* mount, - const char* path) -{ - XBT_DEBUG("\tOpen file '%s'",path); - xbt_dict_t content_dict = ((storage_t)storage)->content; - size_t size = (size_t) xbt_dict_get_or_null(content_dict,path); - // if file does not exist create an empty file - if(!size){ - xbt_dict_set(content_dict,path,&size,NULL); - XBT_DEBUG("File '%s' was not found, file created.",path); - } - surf_file_t file = xbt_new0(s_surf_file_t,1); - file->name = xbt_strdup(path); - file->size = size; - file->storage = xbt_strdup(mount); - - surf_action_t action = storage_action_execute(storage,0, OPEN); - action->file = (void *)file; - return action; -} - -static surf_action_t storage_action_close(void *storage, surf_file_t fd) -{ - char *filename = fd->name; - XBT_DEBUG("\tClose file '%s' size '%zu'",filename,fd->size); - // unref write actions from storage - surf_action_storage_t write_action; - unsigned int i; - xbt_dynar_foreach(((storage_t)storage)->write_actions,i,write_action) { - if ((write_action->generic_lmm_action.generic_action.file) == fd) { - xbt_dynar_cursor_rm(((storage_t)storage)->write_actions, &i); - storage_action_unref((surf_action_t) write_action); - } - } - - free(fd->name); - free(fd->storage); - xbt_free(fd); - surf_action_t action = storage_action_execute(storage,0, CLOSE); - return action; -} - -static surf_action_t storage_action_read(void *storage, void* ptr, - size_t size, surf_file_t fd) -{ - if(size > fd->size) - size = fd->size; - surf_action_t action = storage_action_execute(storage,size,READ); - return action; -} - -static surf_action_t storage_action_write(void *storage, const void* ptr, - size_t size, surf_file_t fd) -{ - char *filename = fd->name; - XBT_DEBUG("\tWrite file '%s' size '%zu/%zu'",filename,size,fd->size); - - surf_action_t action = storage_action_execute(storage,size,WRITE); - action->file = fd; - - // If the storage is full - if(((storage_t)storage)->used_size==((storage_t)storage)->size) { - storage_action_state_set((surf_action_t) action, SURF_ACTION_FAILED); - } - return action; -} - -static surf_action_t storage_action_execute (void *storage, size_t size, e_surf_action_storage_type_t type) -{ - surf_action_storage_t action = NULL; - storage_t STORAGE = storage; - - XBT_IN("(%s,%zu", surf_resource_name(STORAGE), size); - action = - surf_action_new(sizeof(s_surf_action_storage_t), size, surf_storage_model, - STORAGE->state_current != SURF_RESOURCE_ON); - - // Save the storage on action - action->storage = storage; - GENERIC_LMM_ACTION(action).suspended = 0; /* Should be useless because of the - calloc but it seems to help valgrind... */ - - /* TOREPAIR GENERIC_LMM_ACTION(action).variable = - lmm_variable_new(storage_maxmin_system, action, 1.0, -1.0 , 3);*/ - - // Must be less than the max bandwidth for all actions - lmm_expand(storage_maxmin_system, STORAGE->constraint, - GENERIC_LMM_ACTION(action).variable, 1.0); - - switch(type) { - case OPEN: - case CLOSE: - case STAT: - case LS: - break; - case READ: - lmm_expand(storage_maxmin_system, STORAGE->constraint_read, - GENERIC_LMM_ACTION(action).variable, 1.0); - break; - case WRITE: - lmm_expand(storage_maxmin_system, STORAGE->constraint_write, - GENERIC_LMM_ACTION(action).variable, 1.0); - xbt_dynar_push(((storage_t)storage)->write_actions,&action); - surf_action_ref((surf_action_t) action); - break; - } - action->type = type; - XBT_OUT(); - return (surf_action_t) action; -} - -static void* storage_create_resource(const char* id, const char* model,const char* type_id,const char* content_name) -{ - storage_t storage = NULL; - - xbt_assert(!surf_storage_resource_priv(surf_storage_resource_by_name(id)), - "Storage '%s' declared several times in the platform file", - id); - storage = (storage_t) surf_resource_new(sizeof(s_storage_t), - surf_storage_model, id,NULL); - - storage->state_current = SURF_RESOURCE_ON; - storage->used_size = 0; - storage->size = 0; - storage->write_actions = xbt_dynar_new(sizeof(char *),NULL); - - storage_type_t storage_type = xbt_lib_get_or_null(storage_type_lib, type_id,ROUTING_STORAGE_TYPE_LEVEL); - double Bread = atof(xbt_dict_get(storage_type->properties,"Bread")); - double Bwrite = atof(xbt_dict_get(storage_type->properties,"Bwrite")); - double Bconnection = atof(xbt_dict_get(storage_type->properties,"Bconnection")); - XBT_DEBUG("Create resource with Bconnection '%f' Bread '%f' Bwrite '%f' and Size '%lu'",Bconnection,Bread,Bwrite,(unsigned long)storage_type->size); - storage->constraint = lmm_constraint_new(storage_maxmin_system, storage, Bconnection); - /* TOREPAIR: storage->constraint = lmm_constraint_new(storage_maxmin_system, storage, Bconnection); - storage->constraint_read = lmm_constraint_new(storage_maxmin_system, storage, Bread); - storage->constraint_write = lmm_constraint_new(storage_maxmin_system, storage, Bwrite);*/ - storage->content = parse_storage_content((char*)content_name,&(storage->used_size)); - storage->size = storage_type->size; - - xbt_lib_set(storage_lib, id, SURF_STORAGE_LEVEL, storage); - - XBT_DEBUG("SURF storage create resource\n\t\tid '%s'\n\t\ttype '%s' \n\t\tmodel '%s' \n\t\tproperties '%p'\n\t\tBread '%f'\n", - id, - model, - type_id, - storage_type->properties, - Bread); - - if(!storage_list) storage_list=xbt_dynar_new(sizeof(char *),NULL); - xbt_dynar_push(storage_list,&storage); - - return storage; -} - -static void storage_finalize(void) -{ - lmm_system_free(storage_maxmin_system); - storage_maxmin_system = NULL; - - surf_model_exit(surf_storage_model); - surf_storage_model = NULL; - - xbt_dynar_free(&storage_list); - - xbt_swag_free - (storage_running_action_set_that_does_not_need_being_checked); - storage_running_action_set_that_does_not_need_being_checked = NULL; -} - -static void storage_update_actions_state(double now, double delta) -{ - surf_action_storage_t action = NULL; - surf_action_storage_t next_action = NULL; - xbt_swag_t running_actions = surf_storage_model->states.running_action_set; - - // Update the disk usage - // Update the file size - // For each action of type write - xbt_swag_foreach_safe(action, next_action, running_actions) { - if(action->type == WRITE) - { - double rate = lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable); - /* Hack to avoid rounding differences between x86 and x86_64 - * (note that the next sizes are of type size_t). */ - long incr = delta * rate + MAXMIN_PRECISION; - ((storage_t)(action->storage))->used_size += incr; // disk usage - ((surf_action_t)action)->file->size += incr; // file size - } - } - - xbt_swag_foreach_safe(action, next_action, running_actions) { - - double_update(&(GENERIC_ACTION(action).remains), - lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable) * delta); - - if (GENERIC_LMM_ACTION(action).generic_action.max_duration != NO_MAX_DURATION) - double_update(&(GENERIC_ACTION(action).max_duration), delta); - - if(GENERIC_ACTION(action).remains > 0 && - lmm_get_variable_weight(GENERIC_LMM_ACTION(action).variable) > 0 && - ((storage_t)action->storage)->used_size == ((storage_t)action->storage)->size) - { - GENERIC_ACTION(action).finish = surf_get_clock(); - storage_action_state_set((surf_action_t) action, SURF_ACTION_FAILED); - } else if ((GENERIC_ACTION(action).remains <= 0) && - (lmm_get_variable_weight(GENERIC_LMM_ACTION(action).variable) > 0)) - { - GENERIC_ACTION(action).finish = surf_get_clock(); - storage_action_state_set((surf_action_t) action, SURF_ACTION_DONE); - } else if ((GENERIC_ACTION(action).max_duration != NO_MAX_DURATION) && - (GENERIC_ACTION(action).max_duration <= 0)) - { - GENERIC_ACTION(action).finish = surf_get_clock(); - storage_action_state_set((surf_action_t) action, SURF_ACTION_DONE); - } - } - - return; -} - -static double storage_share_resources(double NOW) -{ - XBT_DEBUG("storage_share_resources %f",NOW); - s_surf_action_storage_t action; - unsigned int i,j; - storage_t storage; - surf_action_storage_t write_action; - - double min_completion = generic_maxmin_share_resources(surf_storage_model->states.running_action_set, - xbt_swag_offset(action, generic_lmm_action.variable), - storage_maxmin_system, lmm_solve); - - double rate; - // Foreach disk - xbt_dynar_foreach(storage_list,i,storage) - { - rate = 0; - // Foreach write action on disk - xbt_dynar_foreach(storage->write_actions,j,write_action) - { - rate += lmm_variable_getvalue(write_action->generic_lmm_action.variable); - } - if(rate > 0) - min_completion = MIN(min_completion, (storage->size-storage->used_size)/rate); - } - - return min_completion; -} - -static int storage_resource_used(void *resource_id) -{ - THROW_UNIMPLEMENTED; - return 0; -} - -static void storage_resources_state(void *id, tmgr_trace_event_t event_type, - double value, double time) -{ - THROW_UNIMPLEMENTED; -} - -static int storage_action_unref(surf_action_t action) -{ - action->refcount--; - if (!action->refcount) { - xbt_swag_remove(action, action->state_set); - if (((surf_action_lmm_t) action)->variable) - lmm_variable_free(storage_maxmin_system, - ((surf_action_lmm_t) action)->variable); -#ifdef HAVE_TRACING - xbt_free(action->category); -#endif - surf_action_free(&action); - return 1; - } - return 0; -} - -static void storage_action_cancel(surf_action_t action) -{ - surf_action_state_set(action, SURF_ACTION_FAILED); - return; -} - -static void storage_action_state_set(surf_action_t action, e_surf_action_state_t state) -{ - surf_action_state_set(action, state); - return; -} - -static void storage_action_suspend(surf_action_t action) -{ - XBT_IN("(%p)", action); - if (((surf_action_lmm_t) action)->suspended != 2) { - lmm_update_variable_weight(storage_maxmin_system, - ((surf_action_lmm_t) action)->variable, - 0.0); - ((surf_action_lmm_t) action)->suspended = 1; - } - XBT_OUT(); -} - -static void storage_action_resume(surf_action_t action) -{ - THROW_UNIMPLEMENTED; -} - -static int storage_action_is_suspended(surf_action_t action) -{ - return (((surf_action_lmm_t) action)->suspended == 1); -} - -static void storage_action_set_max_duration(surf_action_t action, double duration) -{ - THROW_UNIMPLEMENTED; -} - -static void storage_action_set_priority(surf_action_t action, double priority) -{ - THROW_UNIMPLEMENTED; -} - -static void parse_storage_init(sg_platf_storage_cbarg_t storage) -{ - void* stype = xbt_lib_get_or_null(storage_type_lib, - storage->type_id, - ROUTING_STORAGE_TYPE_LEVEL); - if(!stype) xbt_die("No storage type '%s'",storage->type_id); - - // if storage content is not specified use the content of storage_type if exist - if(!strcmp(storage->content,"") && strcmp(((storage_type_t) stype)->content,"")){ - storage->content = ((storage_type_t) stype)->content; - XBT_DEBUG("For disk '%s' content is empty, use the content of storage type '%s'",storage->id,((storage_type_t) stype)->type_id); - } - - XBT_DEBUG("SURF storage create resource\n\t\tid '%s'\n\t\ttype '%s' \n\t\tmodel '%s' \n\t\tcontent '%s'\n\t\tproperties '%p'\n", - storage->id, - ((storage_type_t) stype)->model, - ((storage_type_t) stype)->type_id, - storage->content, - ((storage_type_t) stype)->properties); - - storage_create_resource(storage->id, - ((storage_type_t) stype)->model, - ((storage_type_t) stype)->type_id, - storage->content); -} - -static void parse_mstorage_init(sg_platf_mstorage_cbarg_t mstorage) -{ - XBT_DEBUG("parse_mstorage_init"); -} - -static void parse_storage_type_init(sg_platf_storage_type_cbarg_t storagetype_) -{ - XBT_DEBUG("parse_storage_type_init"); -} - -static void parse_mount_init(sg_platf_mount_cbarg_t mount) -{ - XBT_DEBUG("parse_mount_init"); -} - -static void storage_define_callbacks() -{ - sg_platf_storage_add_cb(parse_storage_init); - sg_platf_storage_type_add_cb(parse_storage_type_init); - sg_platf_mstorage_add_cb(parse_mstorage_init); - sg_platf_mount_add_cb(parse_mount_init); -} - -static void surf_storage_model_init_internal(void) -{ - s_surf_action_t action; - - XBT_DEBUG("surf_storage_model_init_internal"); - surf_storage_model = surf_model_init(); - - storage_running_action_set_that_does_not_need_being_checked = - xbt_swag_new(xbt_swag_offset(action, state_hookup)); - - surf_storage_model->name = "Storage"; - surf_storage_model->action_unref = storage_action_unref; - surf_storage_model->action_cancel = storage_action_cancel; - surf_storage_model->action_state_set = storage_action_state_set; - - surf_storage_model->model_private->finalize = storage_finalize; - surf_storage_model->model_private->update_actions_state = storage_update_actions_state; - surf_storage_model->model_private->share_resources = storage_share_resources; - surf_storage_model->model_private->resource_used = storage_resource_used; - surf_storage_model->model_private->update_resource_state = storage_resources_state; - - surf_storage_model->suspend = storage_action_suspend; - surf_storage_model->resume = storage_action_resume; - surf_storage_model->is_suspended = storage_action_is_suspended; - surf_storage_model->set_max_duration = storage_action_set_max_duration; - surf_storage_model->set_priority = storage_action_set_priority; - - surf_storage_model->extension.storage.open = storage_action_open; - surf_storage_model->extension.storage.close = storage_action_close; - surf_storage_model->extension.storage.read = storage_action_read; - surf_storage_model->extension.storage.write = storage_action_write; - surf_storage_model->extension.storage.ls = storage_action_ls; - - if (!storage_maxmin_system) { - storage_maxmin_system = lmm_system_new(storage_selective_update); - } - -} - -void surf_storage_model_init_default(void) -{ - surf_storage_model_init_internal(); - storage_define_callbacks(); - - xbt_dynar_push(model_list, &surf_storage_model); -} - -static void storage_parse_storage(sg_platf_storage_cbarg_t storage) -{ - xbt_assert(!xbt_lib_get_or_null(storage_lib, storage->id,ROUTING_STORAGE_LEVEL), - "Reading a storage, processing unit \"%s\" already exists", storage->id); - - // Verification of an existing type_id -#ifndef NDEBUG - void* storage_type = xbt_lib_get_or_null(storage_type_lib, storage->type_id,ROUTING_STORAGE_TYPE_LEVEL); -#endif - xbt_assert(storage_type,"Reading a storage, type id \"%s\" does not exists", storage->type_id); - - XBT_DEBUG("ROUTING Create a storage name '%s' with type_id '%s' and content '%s'", - storage->id, - storage->type_id, - storage->content); - - xbt_lib_set(storage_lib, - storage->id, - ROUTING_STORAGE_LEVEL, - (void *) xbt_strdup(storage->type_id)); -} - -static xbt_dict_t parse_storage_content(char *filename, size_t *used_size) -{ - *used_size = 0; - if ((!filename) || (strcmp(filename, "") == 0)) - return NULL; - - xbt_dict_t parse_content = xbt_dict_new_homogeneous(NULL); - FILE *file = NULL; - - file = surf_fopen(filename, "r"); - xbt_assert(file != NULL, "Cannot open file '%s' (path=%s)", filename, - xbt_str_join(surf_path, ":")); - - char *line = NULL; - size_t len = 0; - ssize_t read; - char path[1024]; - size_t size; - - - while ((read = xbt_getline(&line, &len, file)) != -1) { - if (read){ - if(sscanf(line,"%s %zu",path, &size)==2) { - *used_size += size; - xbt_dict_set(parse_content,path,(void*) size,NULL); - } else { - xbt_die("Be sure of passing a good format for content file.\n"); - } - } - } - free(line); - fclose(file); - return parse_content; -} - -static void storage_parse_storage_type(sg_platf_storage_type_cbarg_t storage_type) -{ - xbt_assert(!xbt_lib_get_or_null(storage_type_lib, storage_type->id,ROUTING_STORAGE_TYPE_LEVEL), - "Reading a storage type, processing unit \"%s\" already exists", storage_type->id); - - storage_type_t stype = xbt_new0(s_storage_type_t, 1); - stype->model = xbt_strdup(storage_type->model); - stype->properties = storage_type->properties; - stype->content = xbt_strdup(storage_type->content); - stype->type_id = xbt_strdup(storage_type->id); - stype->size = storage_type->size * 1000000000; /* storage_type->size is in Gbytes and stype->sizeis in bytes */ - - XBT_DEBUG("ROUTING Create a storage type id '%s' with model '%s' content '%s'", - stype->type_id, - stype->model, - storage_type->content); - - xbt_lib_set(storage_type_lib, - stype->type_id, - ROUTING_STORAGE_TYPE_LEVEL, - (void *) stype); -} -static void storage_parse_mstorage(sg_platf_mstorage_cbarg_t mstorage) -{ - THROW_UNIMPLEMENTED; -// mount_t mnt = xbt_new0(s_mount_t, 1); -// mnt->id = xbt_strdup(mstorage->type_id); -// mnt->name = xbt_strdup(mstorage->name); -// -// if(!mount_list){ -// XBT_DEBUG("Creata a Mount list for %s",A_surfxml_host_id); -// mount_list = xbt_dynar_new(sizeof(char *), NULL); -// } -// xbt_dynar_push(mount_list,(void *) mnt); -// free(mnt->id); -// free(mnt->name); -// xbt_free(mnt); -// XBT_DEBUG("ROUTING Mount a storage name '%s' with type_id '%s'",mstorage->name, mstorage->id); -} - -static void mount_free(void *p) -{ - mount_t mnt = p; - xbt_free(mnt->name); -} - -static void storage_parse_mount(sg_platf_mount_cbarg_t mount) -{ - // Verification of an existing storage -#ifndef NDEBUG - void* storage = xbt_lib_get_or_null(storage_lib, mount->id,ROUTING_STORAGE_LEVEL); -#endif - xbt_assert(storage,"Disk id \"%s\" does not exists", mount->id); - - XBT_DEBUG("ROUTING Mount '%s' on '%s'",mount->id, mount->name); - - s_mount_t mnt; - mnt.id = surf_storage_resource_priv(surf_storage_resource_by_name(mount->id)); - mnt.name = xbt_strdup(mount->name); - - if(!mount_list){ - XBT_DEBUG("Create a Mount list for %s",A_surfxml_host_id); - mount_list = xbt_dynar_new(sizeof(s_mount_t), mount_free); - } - xbt_dynar_push(mount_list,&mnt); -} - -static XBT_INLINE void routing_storage_type_free(void *r) -{ - storage_type_t stype = r; - free(stype->model); - free(stype->type_id); - free(stype->content); - xbt_dict_free(&(stype->properties)); - free(stype); -} - -static XBT_INLINE void surf_storage_resource_free(void *r) -{ - // specific to storage - storage_t storage = r; - xbt_dict_free(&storage->content); - xbt_dynar_free(&storage->write_actions); - // generic resource - surf_resource_free(r); -} - -static XBT_INLINE void routing_storage_host_free(void *r) -{ - xbt_dynar_t dyn = r; - xbt_dynar_free(&dyn); -} - -void storage_register_callbacks() { - - ROUTING_STORAGE_LEVEL = xbt_lib_add_level(storage_lib,xbt_free); - ROUTING_STORAGE_HOST_LEVEL = xbt_lib_add_level(storage_lib,routing_storage_host_free); - ROUTING_STORAGE_TYPE_LEVEL = xbt_lib_add_level(storage_type_lib,routing_storage_type_free); - SURF_STORAGE_LEVEL = xbt_lib_add_level(storage_lib,surf_storage_resource_free); - - sg_platf_storage_add_cb(storage_parse_storage); - sg_platf_mstorage_add_cb(storage_parse_mstorage); - sg_platf_storage_type_add_cb(storage_parse_storage_type); - sg_platf_mount_add_cb(storage_parse_mount); -} diff --git a/src/surf/surf.c b/src/surf/surf.c deleted file mode 100644 index 3463fad79b..0000000000 --- a/src/surf/surf.c +++ /dev/null @@ -1,725 +0,0 @@ -/* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011. The SimGrid Team. - * All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ - -#include "surf_private.h" -#include "xbt/module.h" -#include "mc/mc.h" -#include "simix/smx_host_private.h" -#include "surf/surf_resource.h" -#include "xbt/xbt_os_thread.h" -#include "simgrid/sg_config.h" - -#include - -XBT_LOG_NEW_CATEGORY(surf, "All SURF categories"); -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_kernel, surf, - "Logging specific to SURF (kernel)"); - -/* Additional declarations for Windows portability. */ - -#ifndef MAX_DRIVE -#define MAX_DRIVE 26 -#endif - -#ifdef _XBT_WIN32 -#include -static const char *disk_drives_letter_table[MAX_DRIVE] = { - "A:\\", - "B:\\", - "C:\\", - "D:\\", - "E:\\", - "F:\\", - "G:\\", - "H:\\", - "I:\\", - "J:\\", - "K:\\", - "L:\\", - "M:\\", - "N:\\", - "O:\\", - "P:\\", - "Q:\\", - "R:\\", - "S:\\", - "T:\\", - "U:\\", - "V:\\", - "W:\\", - "X:\\", - "Y:\\", - "Z:\\" -}; -#endif /* #ifdef _XBT_WIN32 */ - -/* - * Returns the initial path. On Windows the initial path is - * the current directory for the current process in the other - * case the function returns "./" that represents the current - * directory on Unix/Linux platforms. - */ - -const char *__surf_get_initial_path(void) -{ - -#ifdef _XBT_WIN32 - unsigned i; - char current_directory[MAX_PATH + 1] = { 0 }; - unsigned int len = GetCurrentDirectory(MAX_PATH + 1, current_directory); - char root[4] = { 0 }; - - if (!len) - return NULL; - - strncpy(root, current_directory, 3); - - for (i = 0; i < MAX_DRIVE; i++) { - if (toupper(root[0]) == disk_drives_letter_table[i][0]) - return disk_drives_letter_table[i]; - } - - return NULL; -#else - return "./"; -#endif -} - -/* The __surf_is_absolute_file_path() returns 1 if - * file_path is a absolute file path, in the other - * case the function returns 0. - */ -int __surf_is_absolute_file_path(const char *file_path) -{ -#ifdef _XBT_WIN32 - WIN32_FIND_DATA wfd = { 0 }; - HANDLE hFile = FindFirstFile(file_path, &wfd); - - if (INVALID_HANDLE_VALUE == hFile) - return 0; - - FindClose(hFile); - return 1; -#else - return (file_path[0] == '/'); -#endif -} - -double NOW = 0; - -xbt_dynar_t model_list = NULL; -tmgr_history_t history = NULL; -lmm_system_t maxmin_system = NULL; -xbt_dynar_t surf_path = NULL; - -/* Don't forget to update the option description in smx_config when you change this */ -s_surf_model_description_t surf_network_model_description[] = { - {"LV08", - "Realistic network analytic model (slow-start modeled by multiplying latency by 10.4, bandwidth by .92; bottleneck sharing uses a payload of S=8775 for evaluating RTT). ", - surf_network_model_init_LegrandVelho}, - {"Constant", - "Simplistic network model where all communication take a constant time (one second). This model provides the lowest realism, but is (marginally) faster.", - surf_network_model_init_Constant}, - {"SMPI", - "Realistic network model specifically tailored for HPC settings (accurate modeling of slow start with correction factors on three intervals: < 1KiB, < 64 KiB, >= 64 KiB)", - surf_network_model_init_SMPI}, - {"CM02", - "Legacy network analytic model (Very similar to LV08, but without corrective factors. The timings of small messages are thus poorly modeled).", - surf_network_model_init_CM02}, -#ifdef HAVE_GTNETS - {"GTNets", - "Network pseudo-model using the GTNets simulator instead of an analytic model", - surf_network_model_init_GTNETS}, -#endif -#ifdef HAVE_NS3 - {"NS3", - "Network pseudo-model using the NS3 tcp model instead of an analytic model", - surf_network_model_init_NS3}, -#endif - {"Reno", - "Model from Steven H. Low using lagrange_solve instead of lmm_solve (experts only; check the code for more info).", - surf_network_model_init_Reno}, - {"Reno2", - "Model from Steven H. Low using lagrange_solve instead of lmm_solve (experts only; check the code for more info).", - surf_network_model_init_Reno2}, - {"Vegas", - "Model from Steven H. Low using lagrange_solve instead of lmm_solve (experts only; check the code for more info).", - surf_network_model_init_Vegas}, - {NULL, NULL, NULL} /* this array must be NULL terminated */ -}; - -s_surf_model_description_t surf_cpu_model_description[] = { - {"Cas01", - "Simplistic CPU model (time=size/power).", - surf_cpu_model_init_Cas01}, - {NULL, NULL, NULL} /* this array must be NULL terminated */ -}; - -s_surf_model_description_t surf_workstation_model_description[] = { - {"default", - "Default workstation model. Currently, CPU:Cas01 and network:LV08 (with cross traffic enabled)", - surf_workstation_model_init_current_default}, - {"compound", - "Workstation model that is automatically chosen if you change the network and CPU models", - surf_workstation_model_init_compound}, - {"ptask_L07", "Workstation model somehow similar to Cas01+CM02 but allowing parallel tasks", - surf_workstation_model_init_ptask_L07}, - {NULL, NULL, NULL} /* this array must be NULL terminated */ -}; - -s_surf_model_description_t surf_optimization_mode_description[] = { - {"Lazy", - "Lazy action management (partial invalidation in lmm + heap in action remaining).", - NULL}, - {"TI", - "Trace integration. Highly optimized mode when using availability traces (only available for the Cas01 CPU model for now).", - NULL}, - {"Full", - "Full update of remaining and variables. Slow but may be useful when debugging.", - NULL}, - {NULL, NULL, NULL} /* this array must be NULL terminated */ -}; - -s_surf_model_description_t surf_storage_model_description[] = { - {"default", - "Simplistic storage model.", - surf_storage_model_init_default}, - {NULL, NULL, NULL} /* this array must be NULL terminated */ -}; - -/* ********************************************************************* */ -/* TUTORIAL: New model */ -s_surf_model_description_t surf_new_model_description[] = { - {"default", - "Tutorial model.", - surf_new_model_init_default}, - {NULL, NULL, NULL} /* this array must be NULL terminated */ -}; -/* ********************************************************************* */ - -#ifdef CONTEXT_THREADS -static xbt_parmap_t surf_parmap = NULL; /* parallel map on models */ -#endif - -static double *surf_mins = NULL; /* return value of share_resources for each model */ -static int surf_min_index; /* current index in surf_mins */ -static double min; /* duration determined by surf_solve */ - -static void surf_share_resources(surf_model_t model); -static void surf_update_actions_state(surf_model_t model); - -/** Displays the long description of all registered models, and quit */ -void model_help(const char *category, s_surf_model_description_t * table) -{ - int i; - printf("Long description of the %s models accepted by this simulator:\n", - category); - for (i = 0; table[i].name; i++) - printf(" %s: %s\n", table[i].name, table[i].description); -} - -int find_model_description(s_surf_model_description_t * table, - const char *name) -{ - int i; - char *name_list = NULL; - - for (i = 0; table[i].name; i++) - if (!strcmp(name, table[i].name)) { - return i; - } - name_list = strdup(table[0].name); - for (i = 1; table[i].name; i++) { - name_list = - xbt_realloc(name_list, - strlen(name_list) + strlen(table[i].name) + 3); - strcat(name_list, ", "); - strcat(name_list, table[i].name); - } - xbt_die("Model '%s' is invalid! Valid models are: %s.", name, name_list); - return -1; -} - -double generic_maxmin_share_resources(xbt_swag_t running_actions, - size_t offset, - lmm_system_t sys, - void (*solve) (lmm_system_t)) -{ - surf_action_t action = NULL; - double min = -1; - double value = -1; -#define VARIABLE(action) (*((lmm_variable_t*)(((char *) (action)) + (offset)))) - - solve(sys); - - xbt_swag_foreach(action, running_actions) { - value = lmm_variable_getvalue(VARIABLE(action)); - if ((value > 0) || (action->max_duration >= 0)) - break; - } - - if (!action) - return -1.0; - - if (value > 0) { - if (action->remains > 0) - min = action->remains / value; - else - min = 0.0; - if ((action->max_duration >= 0) && (action->max_duration < min)) - min = action->max_duration; - } else - min = action->max_duration; - - - for (action = xbt_swag_getNext(action, running_actions->offset); - action; - action = xbt_swag_getNext(action, running_actions->offset)) { - value = lmm_variable_getvalue(VARIABLE(action)); - if (value > 0) { - if (action->remains > 0) - value = action->remains / value; - else - value = 0.0; - if (value < min) { - min = value; - XBT_DEBUG("Updating min (value) with %p: %f", action, min); - } - } - if ((action->max_duration >= 0) && (action->max_duration < min)) { - min = action->max_duration; - XBT_DEBUG("Updating min (duration) with %p: %f", action, min); - } - } - XBT_DEBUG("min value : %f", min); - -#undef VARIABLE - return min; -} - -double generic_share_resources_lazy(double now, surf_model_t model) -{ - surf_action_lmm_t action = NULL; - double min = -1; - double value; - - XBT_DEBUG - ("Before share resources, the size of modified actions set is %d", - xbt_swag_size(model->model_private->modified_set)); - - lmm_solve(model->model_private->maxmin_system); - - XBT_DEBUG - ("After share resources, The size of modified actions set is %d", - xbt_swag_size(model->model_private->modified_set)); - - while((action = xbt_swag_extract(model->model_private->modified_set))) { - int max_dur_flag = 0; - - if (action->generic_action.state_set != - model->states.running_action_set) - continue; - - /* bogus priority, skip it */ - if (action->generic_action.priority <= 0) - continue; - - generic_update_action_remaining_lazy(action,now); - - min = -1; - value = lmm_variable_getvalue(action->variable); - if (value > 0) { - if (action->generic_action.remains > 0) { - value = action->generic_action.remains / value; - min = now + value; - } else { - value = 0.0; - min = now; - } - } - - if ((action->generic_action.max_duration != NO_MAX_DURATION) - && (min == -1 - || action->generic_action.start + - action->generic_action.max_duration < min)) { - min = action->generic_action.start + - action->generic_action.max_duration; - max_dur_flag = 1; - } - - XBT_DEBUG("Action(%p) Start %lf Finish %lf Max_duration %lf", action, - action->generic_action.start, now + value, - action->generic_action.max_duration); - - if (min != -1) { - surf_action_lmm_heap_remove(model->model_private->action_heap,action); - surf_action_lmm_heap_insert(model->model_private->action_heap,action, min, max_dur_flag ? MAX_DURATION : NORMAL); - XBT_DEBUG("Insert at heap action(%p) min %lf now %lf", action, min, - now); - } else DIE_IMPOSSIBLE; - } - - //hereafter must have already the min value for this resource model - if (xbt_heap_size(model->model_private->action_heap) > 0) - min = xbt_heap_maxkey(model->model_private->action_heap) - now; - else - min = -1; - - XBT_DEBUG("The minimum with the HEAP %lf", min); - - return min; -} -static XBT_INLINE void routing_asr_host_free(void *p) -{ - sg_routing_edge_t elm = p; - free(elm->name); - xbt_free(elm); -} - -static XBT_INLINE void routing_asr_prop_free(void *p) -{ - xbt_dict_t elm = p; - xbt_dict_free(&elm); -} - -void sg_version(int *ver_major,int *ver_minor,int *ver_patch) { - *ver_major = SIMGRID_VERSION_MAJOR; - *ver_minor = SIMGRID_VERSION_MINOR; - *ver_patch = SIMGRID_VERSION_PATCH; -} - -void surf_init(int *argc, char **argv) -{ - XBT_DEBUG("Create all Libs"); - host_lib = xbt_lib_new(); - link_lib = xbt_lib_new(); - as_router_lib = xbt_lib_new(); - storage_lib = xbt_lib_new(); - storage_type_lib = xbt_lib_new(); - watched_hosts_lib = xbt_dict_new(); - - XBT_DEBUG("Add routing levels"); - ROUTING_HOST_LEVEL = xbt_lib_add_level(host_lib,routing_asr_host_free); - ROUTING_ASR_LEVEL = xbt_lib_add_level(as_router_lib,routing_asr_host_free); - ROUTING_PROP_ASR_LEVEL = xbt_lib_add_level(as_router_lib,routing_asr_prop_free); - - XBT_DEBUG("Add SURF levels"); - SURF_CPU_LEVEL = xbt_lib_add_level(host_lib,surf_resource_free); - SURF_WKS_LEVEL = xbt_lib_add_level(host_lib,surf_resource_free); - SURF_LINK_LEVEL = xbt_lib_add_level(link_lib,surf_resource_free); - - xbt_init(argc, argv); - if (!model_list) - model_list = xbt_dynar_new(sizeof(surf_model_private_t), NULL); - if (!history) - history = tmgr_history_new(); - -#ifdef HAVE_TRACING - TRACE_add_start_function(TRACE_surf_alloc); - TRACE_add_end_function(TRACE_surf_release); -#endif - - sg_config_init(argc, argv); - - surf_action_init(); - if (MC_is_active()) - MC_memory_init(); -} - -#ifdef _XBT_WIN32 -# define FILE_DELIM "\\" -#else -# define FILE_DELIM "/" /* FIXME: move to better location */ -#endif - -FILE *surf_fopen(const char *name, const char *mode) -{ - unsigned int cpt; - char *path_elm = NULL; - char *buff; - FILE *file = NULL; - - xbt_assert(name); - - if (__surf_is_absolute_file_path(name)) /* don't mess with absolute file names */ - return fopen(name, mode); - - /* search relative files in the path */ - xbt_dynar_foreach(surf_path, cpt, path_elm) { - buff = bprintf("%s" FILE_DELIM "%s", path_elm, name); - file = fopen(buff, mode); - free(buff); - - if (file) - return file; - } - return NULL; -} - -void surf_exit(void) -{ - unsigned int iter; - surf_model_t model = NULL; - - sg_config_finalize(); - - xbt_dynar_foreach(model_list, iter, model) - model->model_private->finalize(); - xbt_dynar_free(&model_list); - routing_exit(); - - if (maxmin_system) { - lmm_system_free(maxmin_system); - maxmin_system = NULL; - } - if (history) { - tmgr_history_free(history); - history = NULL; - } - surf_action_exit(); - -#ifdef CONTEXT_THREADS - xbt_parmap_destroy(surf_parmap); - xbt_free(surf_mins); - surf_mins = NULL; -#endif - - xbt_dynar_free(&surf_path); - - xbt_lib_free(&host_lib); - xbt_lib_free(&link_lib); - xbt_lib_free(&as_router_lib); - xbt_lib_free(&storage_lib); - xbt_lib_free(&storage_type_lib); - - xbt_dict_free(&watched_hosts_lib); - - tmgr_finalize(); - surf_parse_lex_destroy(); - surf_parse_free_callbacks(); - - NOW = 0; /* Just in case the user plans to restart the simulation afterward */ -} - -void surf_presolve(void) -{ - double next_event_date = -1.0; - tmgr_trace_event_t event = NULL; - double value = -1.0; - surf_resource_t resource = NULL; - surf_model_t model = NULL; - unsigned int iter; - - XBT_DEBUG - ("First Run! Let's \"purge\" events and put models in the right state"); - while ((next_event_date = tmgr_history_next_date(history)) != -1.0) { - if (next_event_date > NOW) - break; - while ((event = - tmgr_history_get_next_event_leq(history, next_event_date, - &value, - (void **) &resource))) { - if (value >= 0){ - resource->model->model_private->update_resource_state(resource, - event, value, - NOW); - } - } - } - xbt_dynar_foreach(model_list, iter, model) - model->model_private->update_actions_state(NOW, 0.0); -} - -double surf_solve(double max_date) -{ - min = -1.0; /* duration */ - double next_event_date = -1.0; - double model_next_action_end = -1.0; - double value = -1.0; - surf_resource_t resource = NULL; - surf_model_t model = NULL; - tmgr_trace_event_t event = NULL; - unsigned int iter; - - if (max_date != -1.0 && max_date != NOW) { - min = max_date - NOW; - } - - XBT_DEBUG("Looking for next action end for all models except NS3"); - - if (surf_mins == NULL) { - surf_mins = xbt_new(double, xbt_dynar_length(model_list)); - } - surf_min_index = 0; - - /* sequential version */ - xbt_dynar_foreach(model_list, iter, model) { - surf_share_resources(model); - } - - unsigned i; - for (i = 0; i < xbt_dynar_length(model_list); i++) { - if ((min < 0.0 || surf_mins[i] < min) - && surf_mins[i] >= 0.0) { - min = surf_mins[i]; - } - } - - XBT_DEBUG("Min for resources (remember that NS3 don't update that value) : %f", min); - - XBT_DEBUG("Looking for next trace event"); - - do { - XBT_DEBUG("Next TRACE event : %f", next_event_date); - - next_event_date = tmgr_history_next_date(history); - - if(surf_network_model->name && !strcmp(surf_network_model->name,"network NS3")){ - if(next_event_date!=-1.0 && min!=-1.0) { - min = MIN(next_event_date - NOW, min); - } else{ - min = MAX(next_event_date - NOW, min); - } - - XBT_DEBUG("Run for network at most %f", min); - // run until min or next flow - model_next_action_end = surf_network_model->model_private->share_resources(min); - - XBT_DEBUG("Min for network : %f", model_next_action_end); - if(model_next_action_end>=0.0) - min = model_next_action_end; - } - - if (next_event_date < 0.0) { - XBT_DEBUG("no next TRACE event. Stop searching for it"); - break; - } - - if ((min == -1.0) || (next_event_date > NOW + min)) break; - - XBT_DEBUG("Updating models (min = %g, NOW = %g, next_event_date = %g)",min, NOW, next_event_date); - while ((event = - tmgr_history_get_next_event_leq(history, next_event_date, - &value, - (void **) &resource))) { - if (resource->model->model_private->resource_used(resource)) { - min = next_event_date - NOW; - XBT_DEBUG - ("This event will modify model state. Next event set to %f", - min); - } - /* update state of model_obj according to new value. Does not touch lmm. - It will be modified if needed when updating actions */ - XBT_DEBUG("Calling update_resource_state for resource %s with min %lf", - resource->model->name, min); - resource->model->model_private->update_resource_state(resource, - event, value, - next_event_date); - } - } while (1); - - /* FIXME: Moved this test to here to avoid stopping simulation if there are actions running on cpus and all cpus are with availability = 0. - * This may cause an infinite loop if one cpu has a trace with periodicity = 0 and the other a trace with periodicity > 0. - * The options are: all traces with same periodicity(0 or >0) or we need to change the way how the events are managed */ - if (min == -1.0) { - XBT_DEBUG("No next event at all. Bail out now."); - return -1.0; - } - - XBT_DEBUG("Duration set to %f", min); - - NOW = NOW + min; - - /* sequential version */ - xbt_dynar_foreach(model_list, iter, model) { - surf_update_actions_state(model); - } - -#ifdef HAVE_TRACING - TRACE_paje_dump_buffer (0); -#endif - - return min; -} - -XBT_INLINE double surf_get_clock(void) -{ - return NOW; -} - -static void surf_share_resources(surf_model_t model) -{ - double next_action_end = -1.0; - int i = __sync_fetch_and_add(&surf_min_index, 1); - if (strcmp(model->name,"network NS3")) { - XBT_DEBUG("Running for Resource [%s]", model->name); - next_action_end = model->model_private->share_resources(NOW); - XBT_DEBUG("Resource [%s] : next action end = %f", - model->name, next_action_end); - } - surf_mins[i] = next_action_end; -} - -static void surf_update_actions_state(surf_model_t model) -{ - model->model_private->update_actions_state(NOW, min); -} - - -/* This function is a pimple that we ought to fix. But it won't be easy. - * - * The surf_solve() function does properly return the set of actions that changed. - * Instead, each model change a global data, and then the caller of surf_solve must - * pick into these sets of action_failed and action_done. - * - * This was not clean but ok as long as we didn't had to restart the processes when the resource comes back up. - * We worked by putting sentinel actions on every resources we are interested in, - * so that surf informs us if/when the corresponding resource fails. - * - * But this does not work to get Simix informed of when a resource comes back up, and this is where this pimple comes. - * We have a set of resources that are currently down and for which simix needs to know when it comes back up. - * And the current function is called *at every simulation step* to sweep over that set, searching for a resource - * that was turned back up in the meanwhile. This is UGLY and slow. - * - * The proper solution would be to not rely on globals for the action_failed and action_done swags. - * They must be passed as parameter by the caller (the handling of these actions in simix may let you - * think that these two sets can be merged, but their handling in SimDag induce the contrary unless this - * simdag code can check by itself whether the action is done of failed -- seems very doable, but yet more - * cleanup to do). - * - * Once surf_solve() is passed the set of actions that changed, you want to add a new set of resources back up - * as parameter to this function. You also want to add a boolean field "restart_watched" to each resource, and - * make sure that whenever a resource with this field enabled comes back up, it's added to that set so that Simix - * sees it and react accordingly. This would kill that need for surf to call simix. - * - */ - -static void remove_watched_host(void *key) -{ - xbt_dict_remove(watched_hosts_lib, *(char**)key); -} - -void surf_watched_hosts(void) -{ - char *key; - void *host; - xbt_dict_cursor_t cursor; - xbt_dynar_t hosts = xbt_dynar_new(sizeof(char*), NULL); - - XBT_DEBUG("Check for host SURF_RESOURCE_ON on watched_hosts_lib"); - xbt_dict_foreach(watched_hosts_lib,cursor,key,host) - { - if(SIMIX_host_get_state(host) == SURF_RESOURCE_ON){ - XBT_INFO("Restart processes on host: %s",SIMIX_host_get_name(host)); - SIMIX_host_autorestart(host); - xbt_dynar_push_as(hosts, char*, key); - } - else - XBT_DEBUG("See SURF_RESOURCE_OFF on host: %s",key); - } - xbt_dynar_map(hosts, remove_watched_host); - xbt_dynar_free(&hosts); -} diff --git a/src/surf/surf.cpp b/src/surf/surf.cpp index 179f64a57a..41545d889f 100644 --- a/src/surf/surf.cpp +++ b/src/surf/surf.cpp @@ -154,16 +154,6 @@ s_surf_model_description_t surf_storage_model_description[] = { {NULL, NULL, NULL} /* this array must be NULL terminated */ }; -/* ********************************************************************* */ -/* TUTORIAL: New model */ -s_surf_model_description_t surf_new_model_description[] = { - {"default", - "Tutorial model.", - surf_new_model_init_default}, - {NULL, NULL, NULL} /* this array must be NULL terminated */ -}; -/* ********************************************************************* */ - #ifdef CONTEXT_THREADS static xbt_parmap_t surf_parmap = NULL; /* parallel map on models */ #endif @@ -174,7 +164,7 @@ static double min; /* duration determined by surf_solve */ double NOW = 0; -XBT_INLINE double surf_get_clock(void) +double surf_get_clock(void) { return NOW; } diff --git a/src/surf/surf_action.c b/src/surf/surf_action.c deleted file mode 100644 index df348d156e..0000000000 --- a/src/surf/surf_action.c +++ /dev/null @@ -1,570 +0,0 @@ -/* Copyright (c) 2009, 2010. The SimGrid Team. - * All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ - -#include "surf_private.h" -#include "network_private.h" -#include "xbt/mallocator.h" - -XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_kernel); - -/* - * Generic action - */ - -const char *surf_action_state_names[6] = { - "SURF_ACTION_READY", - "SURF_ACTION_RUNNING", - "SURF_ACTION_FAILED", - "SURF_ACTION_DONE", - "SURF_ACTION_TO_FREE", - "SURF_ACTION_NOT_IN_THE_SYSTEM" -}; - -/* Surf actions mallocator */ -static xbt_mallocator_t action_mallocator = NULL; -static int action_mallocator_allocated_size = 0; -static void* surf_action_mallocator_new_f(void); -#define surf_action_mallocator_free_f xbt_free_f -static void surf_action_mallocator_reset_f(void* action); - -/** - * \brief Initializes the action module of Surf. - */ -void surf_action_init(void) { - - /* the action mallocator will always provide actions of the following size, - * so this size should be set to the maximum size of the surf action structures - */ - action_mallocator_allocated_size = sizeof(s_surf_action_network_CM02_t); - action_mallocator = xbt_mallocator_new(65536, surf_action_mallocator_new_f, - surf_action_mallocator_free_f, surf_action_mallocator_reset_f); -} - -/** - * \brief Uninitializes the action module of Surf. - */ -void surf_action_exit(void) { - - xbt_mallocator_free(action_mallocator); -} - -static void* surf_action_mallocator_new_f(void) { - return xbt_malloc(action_mallocator_allocated_size); -} - -static void surf_action_mallocator_reset_f(void* action) { - memset(action, 0, action_mallocator_allocated_size); -} - -void *surf_action_new(size_t size, double cost, surf_model_t model, - int failed) -{ - xbt_assert(size <= action_mallocator_allocated_size, - "Cannot create a surf action of size %zu: the mallocator only provides actions of size %d", - size, action_mallocator_allocated_size); - - surf_action_t action = xbt_mallocator_get(action_mallocator); - action->refcount = 1; - action->cost = cost; - action->remains = cost; - action->priority = 1.0; - action->max_duration = NO_MAX_DURATION; - action->start = surf_get_clock(); - action->finish = -1.0; - action->model_type = model; -#ifdef HAVE_TRACING - action->category = NULL; -#endif - - if (failed) - action->state_set = model->states.failed_action_set; - else - action->state_set = model->states.running_action_set; - - xbt_swag_insert(action, action->state_set); - - return action; -} - -e_surf_action_state_t surf_action_state_get(surf_action_t action) -{ - surf_action_state_t action_state = &(action->model_type->states); - - if (action->state_set == action_state->ready_action_set) - return SURF_ACTION_READY; - if (action->state_set == action_state->running_action_set) - return SURF_ACTION_RUNNING; - if (action->state_set == action_state->failed_action_set) - return SURF_ACTION_FAILED; - if (action->state_set == action_state->done_action_set) - return SURF_ACTION_DONE; - return SURF_ACTION_NOT_IN_THE_SYSTEM; -} - -/*FIXME:DELETEdouble surf_action_get_start_time(surf_action_t action) -{ - return action->start; -}*/ - -double surf_action_get_finish_time(surf_action_t action) -{ - /* keep the function behavior, some models (cpu_ti) change the finish time before the action end */ - return action->remains == 0 ? action->finish : -1; -} - -XBT_INLINE void surf_action_free(surf_action_t * action) -{ - xbt_mallocator_release(action_mallocator, *action); - *action = NULL; -} - -void surf_action_state_set(surf_action_t action, - e_surf_action_state_t state) -{ - surf_action_state_t action_state = &(action->model_type->states); - XBT_IN("(%p,%s)", action, surf_action_state_names[state]); - xbt_swag_remove(action, action->state_set); - - if (state == SURF_ACTION_READY) - action->state_set = action_state->ready_action_set; - else if (state == SURF_ACTION_RUNNING) - action->state_set = action_state->running_action_set; - else if (state == SURF_ACTION_FAILED) - action->state_set = action_state->failed_action_set; - else if (state == SURF_ACTION_DONE) - action->state_set = action_state->done_action_set; - else - action->state_set = NULL; - - if (action->state_set) - xbt_swag_insert(action, action->state_set); - XBT_OUT(); -} - -void surf_action_data_set(surf_action_t action, void *data) -{ - action->data = data; -} - -XBT_INLINE void surf_action_ref(surf_action_t action) -{ - action->refcount++; -} - -/* - * Maxmin action - */ - -/* added to manage the communication action's heap */ -void surf_action_lmm_update_index_heap(void *action, int i) { - surf_action_lmm_t a = action; - a->index_heap = i; -} -/* insert action on heap using a given key and a hat (heap_action_type) - * a hat can be of three types for communications: - * - * NORMAL = this is a normal heap entry stating the date to finish transmitting - * LATENCY = this is a heap entry to warn us when the latency is payed - * MAX_DURATION =this is a heap entry to warn us when the max_duration limit is reached - */ -void surf_action_lmm_heap_insert(xbt_heap_t heap, surf_action_lmm_t action, double key, - enum heap_action_type hat) -{ - action->hat = hat; - xbt_heap_push(heap, action, key); -} - -void surf_action_lmm_heap_remove(xbt_heap_t heap, surf_action_lmm_t action) -{ - action->hat = NOTSET; - if (action->index_heap >= 0) { - xbt_heap_remove(heap, action->index_heap); - } -} - -void surf_action_cancel(surf_action_t action) -{ - surf_model_t model = action->model_type; - surf_action_state_set(action, SURF_ACTION_FAILED); - if (model->model_private->update_mechanism == UM_LAZY) { - xbt_swag_remove(action, model->model_private->modified_set); - surf_action_lmm_heap_remove(model->model_private->action_heap,(surf_action_lmm_t)action); - } - return; -} - -int surf_action_unref(surf_action_t action) -{ - surf_model_t model = action->model_type; - action->refcount--; - if (!action->refcount) { - xbt_swag_remove(action, action->state_set); - if (((surf_action_lmm_t) action)->variable) - lmm_variable_free(model->model_private->maxmin_system, - ((surf_action_lmm_t) action)->variable); - if (model->model_private->update_mechanism == UM_LAZY) { - /* remove from heap */ - surf_action_lmm_heap_remove(model->model_private->action_heap,(surf_action_lmm_t)action); - xbt_swag_remove(action, model->model_private->modified_set); - } -#ifdef HAVE_TRACING - xbt_free(action->category); -#endif - surf_action_free(&action); - return 1; - } - return 0; -} - -void surf_action_suspend(surf_action_t action) -{ - surf_model_t model = action->model_type; - XBT_IN("(%p)", action); - if (((surf_action_lmm_t) action)->suspended != 2) { - lmm_update_variable_weight(model->model_private->maxmin_system, - ((surf_action_lmm_t) action)->variable, - 0.0); - ((surf_action_lmm_t) action)->suspended = 1; - if (model->model_private->update_mechanism == UM_LAZY) - surf_action_lmm_heap_remove(model->model_private->action_heap,(surf_action_lmm_t)action); - } - XBT_OUT(); -} - -void surf_action_resume(surf_action_t action) -{ - surf_model_t model = action->model_type; - XBT_IN("(%p)", action); - if (((surf_action_lmm_t) action)->suspended != 2) { - lmm_update_variable_weight(model->model_private->maxmin_system, - ((surf_action_lmm_t) action)->variable, - action->priority); - ((surf_action_lmm_t) action)->suspended = 0; - if (model->model_private->update_mechanism == UM_LAZY) - surf_action_lmm_heap_remove(model->model_private->action_heap,(surf_action_lmm_t)action); - } - XBT_OUT(); -} - -int surf_action_is_suspended(surf_action_t action) -{ - return (((surf_action_lmm_t) action)->suspended == 1); -} - -void surf_action_set_max_duration(surf_action_t action, double duration) -{ - surf_model_t model = action->model_type; - XBT_IN("(%p,%g)", action, duration); - action->max_duration = duration; - if (model->model_private->update_mechanism == UM_LAZY) // remove action from the heap - surf_action_lmm_heap_remove(model->model_private->action_heap,(surf_action_lmm_t)action); - XBT_OUT(); -} - -void surf_action_set_priority(surf_action_t action, double priority) -{ - surf_model_t model = action->model_type; - XBT_IN("(%p,%g)", action, priority); - action->priority = priority; - lmm_update_variable_weight(model->model_private->maxmin_system, - ((surf_action_lmm_t) action)->variable, - priority); - - if (model->model_private->update_mechanism == UM_LAZY) - surf_action_lmm_heap_remove(model->model_private->action_heap,(surf_action_lmm_t)action); - XBT_OUT(); -} - -#ifdef HAVE_TRACING -void surf_action_set_category(surf_action_t action, - const char *category) -{ - XBT_IN("(%p,%s)", action, category); - action->category = xbt_strdup(category); - XBT_OUT(); -} -#endif - -void generic_update_action_remaining_lazy( surf_action_lmm_t action, double now) -{ - double delta = 0.0; - surf_model_t model = action->generic_action.model_type; - - if(model == surf_network_model) - { - if (action->suspended != 0) - return; - } - else - { - xbt_assert(action->generic_action.state_set == model->states.running_action_set, - "You're updating an action that is not running."); - - /* bogus priority, skip it */ - xbt_assert(action->generic_action.priority > 0, - "You're updating an action that seems suspended."); - } - - delta = now - action->last_update; - - if (action->generic_action.remains > 0) { - XBT_DEBUG("Updating action(%p): remains was %lf, last_update was: %lf", action, action->generic_action.remains, action->last_update); - double_update(&(action->generic_action.remains), - action->last_value * delta); - -#ifdef HAVE_TRACING - if (model == surf_cpu_model && TRACE_is_enabled()) { - surf_resource_t cpu = - lmm_constraint_id(lmm_get_cnst_from_var - (model->model_private->maxmin_system, - action->variable, 0)); - TRACE_surf_host_set_utilization(cpu->name, - action->generic_action.category, - action->last_value, - action->last_update, - now - action->last_update); - } -#endif - XBT_DEBUG("Updating action(%p): remains is now %lf", action, - action->generic_action.remains); - } - - if(model == surf_network_model) - { - if (((surf_action_t)action)->max_duration != NO_MAX_DURATION) - double_update(&(((surf_action_t)action)->max_duration), delta); - - if ((((surf_action_t)action)->remains <= 0) && - (lmm_get_variable_weight(action->variable) > 0)) { - ((surf_action_t)action)->finish = surf_get_clock(); - model->action_state_set((surf_action_t) action, - SURF_ACTION_DONE); - - surf_action_lmm_heap_remove(model->model_private->action_heap,(surf_action_lmm_t)action); - } else if (((((surf_action_t)action)->max_duration != NO_MAX_DURATION) - && (((surf_action_t)action)->max_duration <= 0))) { - ((surf_action_t)action)->finish = surf_get_clock(); - model->action_state_set((surf_action_t) action, - SURF_ACTION_DONE); - surf_action_lmm_heap_remove(model->model_private->action_heap,(surf_action_lmm_t)action); - } - } - - action->last_update = now; - action->last_value = lmm_variable_getvalue(action->variable); -} - -double surf_action_get_remains(surf_action_t action) -{ - XBT_IN("(%p)", action); - surf_model_t model = action->model_type; - /* update remains before return it */ - if (model->model_private->update_mechanism == UM_LAZY) /* update remains before return it */ - generic_update_action_remaining_lazy((surf_action_lmm_t)action, surf_get_clock()); - XBT_OUT(); - return action->remains; -} - -void generic_update_actions_state_lazy(double now, double delta, surf_model_t model) -{ - surf_action_lmm_t action; - while ((xbt_heap_size(model->model_private->action_heap) > 0) - && (double_equals(xbt_heap_maxkey(model->model_private->action_heap), now))) { - action = xbt_heap_pop(model->model_private->action_heap); - XBT_DEBUG("Something happened to action %p", action); -#ifdef HAVE_TRACING - if (TRACE_is_enabled()) { - if(model == surf_cpu_model){ - surf_resource_t cpu = - lmm_constraint_id(lmm_get_cnst_from_var - (model->model_private->maxmin_system, - action->variable, 0)); - TRACE_surf_host_set_utilization(cpu->name, - ((surf_action_t)action)->category, - lmm_variable_getvalue(action->variable), - action->last_update, - now - action->last_update); - } - else{ - int n = lmm_get_number_of_cnst_from_var(model->model_private->maxmin_system, action->variable); - unsigned int i; - for (i = 0; i < n; i++){ - lmm_constraint_t constraint = lmm_get_cnst_from_var(model->model_private->maxmin_system, - action->variable, - i); - link_CM02_t link = lmm_constraint_id(constraint); - TRACE_surf_link_set_utilization(link->lmm_resource.generic_resource.name, - ((surf_action_t)action)->category, - (lmm_variable_getvalue(action->variable)* - lmm_get_cnst_weight_from_var(model->model_private->maxmin_system, - action->variable, - i)), - action->last_update, - now - action->last_update); - } - } - } -#endif - - if(model == surf_cpu_model){ - action->generic_action.finish = surf_get_clock(); - XBT_DEBUG("Action %p finished", action); - - /* set the remains to 0 due to precision problems when updating the remaining amount */ - action->generic_action.remains = 0; - surf_action_state_set((surf_action_t) action, SURF_ACTION_DONE); - surf_action_lmm_heap_remove(model->model_private->action_heap,action); //FIXME: strange call since action was already popped - } - else{ - // if I am wearing a latency hat - if (action->hat == LATENCY) { - XBT_DEBUG("Latency paid for action %p. Activating", action); - lmm_update_variable_weight(model->model_private->maxmin_system, action->variable, - ((surf_action_network_CM02_t)(action))->weight); - surf_action_lmm_heap_remove(model->model_private->action_heap,action); - action->last_update = surf_get_clock(); - - // if I am wearing a max_duration or normal hat - } else if (action->hat == MAX_DURATION || - action->hat == NORMAL) { - // no need to communicate anymore - // assume that flows that reached max_duration have remaining of 0 - action->generic_action.finish = surf_get_clock(); - XBT_DEBUG("Action %p finished", action); - action->generic_action.remains = 0; - ((surf_action_t)action)->finish = surf_get_clock(); - model->action_state_set((surf_action_t) action, - SURF_ACTION_DONE); - surf_action_lmm_heap_remove(model->model_private->action_heap,action); - - if (model->gap_remove && model == surf_network_model) - model->gap_remove(action); - } - } - } -#ifdef HAVE_TRACING - if (TRACE_is_enabled() && model == surf_cpu_model) { - //defining the last timestamp that we can safely dump to trace file - //without losing the event ascending order (considering all CPU's) - double smaller = -1; - xbt_swag_t running_actions = model->states.running_action_set; - xbt_swag_foreach(action, running_actions) { - if (smaller < 0) { - smaller = action->last_update; - continue; - } - if (action->last_update < smaller) { - smaller = action->last_update; - } - } - if (smaller > 0) { - TRACE_last_timestamp_to_dump = smaller; - } - } -#endif - return; -} - -void generic_update_actions_state_full(double now, double delta, surf_model_t model) -{ - surf_action_lmm_t action = NULL; - surf_action_lmm_t next_action = NULL; - xbt_swag_t running_actions = model->states.running_action_set; - - xbt_swag_foreach_safe(action, next_action, running_actions) { - - if(model == surf_network_model) - { - double deltap = 0.0; - deltap = delta; - if (((surf_action_network_CM02_t)action)->latency > 0) { - if (((surf_action_network_CM02_t)action)->latency > deltap) { - double_update(&(((surf_action_network_CM02_t)action)->latency), deltap); - deltap = 0.0; - } else { - double_update(&(deltap), ((surf_action_network_CM02_t)action)->latency); - ((surf_action_network_CM02_t)action)->latency = 0.0; - } - if ((((surf_action_network_CM02_t)action)->latency == 0.0) && !(action->suspended)) - lmm_update_variable_weight(model->model_private->maxmin_system, action->variable, - ((surf_action_network_CM02_t)action)->weight); - } - #ifdef HAVE_TRACING - if (TRACE_is_enabled()) { - int n = lmm_get_number_of_cnst_from_var(model->model_private->maxmin_system, action->variable); - unsigned int i; - for (i = 0; i < n; i++){ - lmm_constraint_t constraint = lmm_get_cnst_from_var(model->model_private->maxmin_system, - action->variable, - i); - link_CM02_t link = lmm_constraint_id(constraint); - TRACE_surf_link_set_utilization(link->lmm_resource.generic_resource.name, - ((surf_action_t)action)->category, - (lmm_variable_getvalue(action->variable)* - lmm_get_cnst_weight_from_var(model->model_private->maxmin_system, - action->variable, - i)), - now - delta, - delta); - } - } - #endif - if (!lmm_get_number_of_cnst_from_var - (model->model_private->maxmin_system, action->variable)) { - /* There is actually no link used, hence an infinite bandwidth. - * This happens often when using models like vivaldi. - * In such case, just make sure that the action completes immediately. - */ - double_update(&(action->generic_action.remains), - action->generic_action.remains); - } - } - else - { -#ifdef HAVE_TRACING - if (TRACE_is_enabled()) { - surf_resource_t x = - lmm_constraint_id(lmm_get_cnst_from_var - (model->model_private->maxmin_system, - action->variable, 0)); - - TRACE_surf_host_set_utilization(x->name, - ((surf_action_t)action)->category, - lmm_variable_getvalue(action->variable), - now - delta, - delta); - TRACE_last_timestamp_to_dump = now - delta; - } -#endif - } - - double_update(&(action->generic_action.remains), - lmm_variable_getvalue(action->variable) * delta); - - - if (action->generic_action.max_duration != NO_MAX_DURATION) - double_update(&(action->generic_action.max_duration), delta); - - - if ((action->generic_action.remains <= 0) && - (lmm_get_variable_weight(action->variable) > 0)) { - action->generic_action.finish = surf_get_clock(); - surf_action_state_set((surf_action_t) action, SURF_ACTION_DONE); - - if (model->gap_remove && model == surf_network_model) - model->gap_remove(action); - } else if ((action->generic_action.max_duration != NO_MAX_DURATION) && - (action->generic_action.max_duration <= 0)) { - action->generic_action.finish = surf_get_clock(); - surf_action_state_set((surf_action_t) action, SURF_ACTION_DONE); - - if (model->gap_remove && model == surf_network_model) - model->gap_remove(action); - } - } - - return; -} diff --git a/src/surf/surf_model.c b/src/surf/surf_model.c deleted file mode 100644 index da1bdd776e..0000000000 --- a/src/surf/surf_model.c +++ /dev/null @@ -1,66 +0,0 @@ - -/* Copyright (c) 2009, 2010. The SimGrid Team. - * All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ - -#include "surf_private.h" -#include "xbt/dict.h" - -static void void_die_impossible_paction(surf_action_t action) -{ - DIE_IMPOSSIBLE; -} - -static int int_die_impossible_paction(surf_action_t action) -{ - DIE_IMPOSSIBLE; - return -1; -} - -/** @brief initialize common datastructures to all models */ -surf_model_t surf_model_init(void) -{ - s_surf_action_t action; - surf_model_t model = xbt_new0(s_surf_model_t, 1); - - model->model_private = xbt_new0(s_surf_model_private_t, 1); - - model->states.ready_action_set = - xbt_swag_new(xbt_swag_offset(action, state_hookup)); - model->states.running_action_set = - xbt_swag_new(xbt_swag_offset(action, state_hookup)); - model->states.failed_action_set = - xbt_swag_new(xbt_swag_offset(action, state_hookup)); - model->states.done_action_set = - xbt_swag_new(xbt_swag_offset(action, state_hookup)); - - model->action_unref = int_die_impossible_paction; - model->action_cancel = void_die_impossible_paction; - model->action_recycle = void_die_impossible_paction; - - model->action_state_get = surf_action_state_get; - model->action_state_set = surf_action_state_set; - model->action_get_start_time = surf_action_get_start_time; - model->action_get_finish_time = surf_action_get_finish_time; - model->action_data_set = surf_action_data_set; - - model->model_private->modified_set = NULL; - model->model_private->action_heap = NULL; - model->model_private->update_mechanism = UM_UNDEFINED; - model->model_private->selective_update = 0; - - return model; -} - -/** @brief finalize common datastructures to all models */ -void surf_model_exit(surf_model_t model) -{ - xbt_swag_free(model->states.ready_action_set); - xbt_swag_free(model->states.running_action_set); - xbt_swag_free(model->states.failed_action_set); - xbt_swag_free(model->states.done_action_set); - free(model->model_private); - free(model); -} diff --git a/src/surf/surf_routing.c b/src/surf/surf_routing.c deleted file mode 100644 index 1efbed43fe..0000000000 --- a/src/surf/surf_routing.c +++ /dev/null @@ -1,1262 +0,0 @@ -/* Copyright (c) 2009, 2010, 2011. The SimGrid Team. - * All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ - -#include "simgrid/platf_interface.h" // platform creation API internal interface - -#include "surf_routing_private.h" -#include "surf/surf_routing.h" -#include "surf/surfxml_parse_values.h" - -/** - * @ingroup SURF_build_api - * @brief A library containing all known workstations - */ -xbt_lib_t host_lib; - -int ROUTING_HOST_LEVEL; //Routing level -int SURF_CPU_LEVEL; //Surf cpu level -int SURF_WKS_LEVEL; //Surf workstation level -int SIMIX_HOST_LEVEL; //Simix level -int MSG_HOST_LEVEL; //Msg level -int SD_HOST_LEVEL; //Simdag level -int COORD_HOST_LEVEL=0; //Coordinates level -int NS3_HOST_LEVEL; //host node for ns3 - -xbt_dict_t watched_hosts_lib; - -/** - * @ingroup SURF_build_api - * @brief A library containing all known links - */ -xbt_lib_t link_lib; -int SD_LINK_LEVEL; //Simdag level -int SURF_LINK_LEVEL; //Surf level -int NS3_LINK_LEVEL; //link for ns3 - -xbt_lib_t as_router_lib; -int ROUTING_ASR_LEVEL; //Routing level -int COORD_ASR_LEVEL; //Coordinates level -int NS3_ASR_LEVEL; //host node for ns3 -int ROUTING_PROP_ASR_LEVEL; //Where the properties are stored - -static xbt_dict_t random_value = NULL; - -/** @brief Retrieve a routing edge from its name - * - * Routing edges are either CPU/workstation and routers, whatever - */ -sg_routing_edge_t sg_routing_edge_by_name_or_null(const char *name) { - sg_routing_edge_t net_elm = xbt_lib_get_or_null(host_lib, name, ROUTING_HOST_LEVEL); - if(!net_elm) net_elm = xbt_lib_get_or_null(as_router_lib, name, ROUTING_ASR_LEVEL); - return net_elm; -} - -/* Global vars */ -routing_platf_t routing_platf = NULL; -AS_t current_routing = NULL; - -/* global parse functions */ -extern xbt_dynar_t mount_list; - -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route, surf, "Routing part of surf"); - -static void routing_parse_peer(sg_platf_peer_cbarg_t peer); /* peer bypass */ -static void routing_parse_Srandom(void); /* random bypass */ - -static void routing_parse_postparse(void); - -/* this lines are only for replace use like index in the model table */ -typedef enum { - SURF_MODEL_FULL = 0, - SURF_MODEL_FLOYD, - SURF_MODEL_DIJKSTRA, - SURF_MODEL_DIJKSTRACACHE, - SURF_MODEL_NONE, - SURF_MODEL_VIVALDI, - SURF_MODEL_CLUSTER -} e_routing_types; - -struct s_model_type routing_models[] = { - {"Full", - "Full routing data (fast, large memory requirements, fully expressive)", - model_full_create, model_full_end}, - {"Floyd", - "Floyd routing data (slow initialization, fast lookup, lesser memory requirements, shortest path routing only)", - model_floyd_create, model_floyd_end}, - {"Dijkstra", - "Dijkstra routing data (fast initialization, slow lookup, small memory requirements, shortest path routing only)", - model_dijkstra_create, model_dijkstra_both_end}, - {"DijkstraCache", - "Dijkstra routing data (fast initialization, fast lookup, small memory requirements, shortest path routing only)", - model_dijkstracache_create, model_dijkstra_both_end}, - {"none", "No routing (Unless you know what you are doing, avoid using this mode in combination with a non Constant network model).", - model_none_create, NULL}, - {"Vivaldi", "Vivaldi routing", - model_vivaldi_create, NULL}, - {"Cluster", "Cluster routing", - model_cluster_create, NULL}, - {NULL, NULL, NULL, NULL} -}; - -/** - * \brief Add a "host_link" to the network element list - */ -static void parse_S_host_link(sg_platf_host_link_cbarg_t host) -{ - sg_routing_edge_t info = NULL; - info = xbt_lib_get_or_null(host_lib, host->id, ROUTING_HOST_LEVEL); - xbt_assert(info, "Host '%s' not found!",host->id); - xbt_assert(current_routing->model_desc == &routing_models[SURF_MODEL_CLUSTER] || - current_routing->model_desc == &routing_models[SURF_MODEL_VIVALDI], - "You have to be in model Cluster to use tag host_link!"); - - s_surf_parsing_link_up_down_t link_up_down; - link_up_down.link_up = xbt_lib_get_or_null(link_lib, host->link_up, SURF_LINK_LEVEL); - link_up_down.link_down = xbt_lib_get_or_null(link_lib, host->link_down, SURF_LINK_LEVEL); - link_up_down.limiter_link = NULL; - link_up_down.loopback_link = NULL; - - xbt_assert(link_up_down.link_up, "Link '%s' not found!",host->link_up); - xbt_assert(link_up_down.link_down, "Link '%s' not found!",host->link_down); - - if(!current_routing->link_up_down_list) - current_routing->link_up_down_list = xbt_dynar_new(sizeof(s_surf_parsing_link_up_down_t),NULL); - - // If dynar is is greater than edge id and if the host_link is already defined - if(xbt_dynar_length(current_routing->link_up_down_list) > info->id && - xbt_dynar_get_as(current_routing->link_up_down_list,info->id,void*)) - xbt_die("Host_link for '%s' is already defined!",host->id); - - XBT_DEBUG("Push Host_link for host '%s' to position %d",info->name,info->id); - xbt_dynar_set_as(current_routing->link_up_down_list,info->id,s_surf_parsing_link_up_down_t,link_up_down); -} - -/** - * \brief Add a "host" to the network element list - */ -static void parse_S_host(sg_platf_host_cbarg_t host) -{ - sg_routing_edge_t info = NULL; - if (current_routing->hierarchy == SURF_ROUTING_NULL) - current_routing->hierarchy = SURF_ROUTING_BASE; - xbt_assert(!xbt_lib_get_or_null(host_lib, host->id, ROUTING_HOST_LEVEL), - "Reading a host, processing unit \"%s\" already exists", host->id); - - info = xbt_new0(s_routing_edge_t, 1); - info->rc_component = current_routing; - info->rc_type = SURF_NETWORK_ELEMENT_HOST; - info->name = xbt_strdup(host->id); - info->id = current_routing->parse_PU(current_routing, (void *) info); - xbt_lib_set(host_lib, host->id, ROUTING_HOST_LEVEL, (void *) info); - XBT_DEBUG("Having set name '%s' id '%d'",host->id,info->id); - - if(mount_list){ - xbt_lib_set(storage_lib, host->id, ROUTING_STORAGE_HOST_LEVEL, (void *) mount_list); - mount_list = NULL; - } - - if (host->coord && strcmp(host->coord, "")) { - unsigned int cursor; - char*str; - - if (!COORD_HOST_LEVEL) - xbt_die ("To use host coordinates, please add --cfg=network/coordinates:yes to your command line"); - /* Pre-parse the host coordinates -- FIXME factorize with routers by overloading the routing->parse_PU function*/ - xbt_dynar_t ctn_str = xbt_str_split_str(host->coord, " "); - xbt_dynar_t ctn = xbt_dynar_new(sizeof(double),NULL); - xbt_dynar_foreach(ctn_str,cursor, str) { - double val = atof(str); - xbt_dynar_push(ctn,&val); - } - xbt_dynar_shrink(ctn, 0); - xbt_dynar_free(&ctn_str); - xbt_lib_set(host_lib, host->id, COORD_HOST_LEVEL, (void *) ctn); - XBT_DEBUG("Having set host coordinates for '%s'",host->id); - } -} - -/** - * \brief Add a "router" to the network element list - */ -static void parse_S_router(sg_platf_router_cbarg_t router) -{ - sg_routing_edge_t info = NULL; - if (current_routing->hierarchy == SURF_ROUTING_NULL) - current_routing->hierarchy = SURF_ROUTING_BASE; - xbt_assert(!xbt_lib_get_or_null(as_router_lib, router->id, ROUTING_ASR_LEVEL), - "Reading a router, processing unit \"%s\" already exists", - router->id); - - info = xbt_new0(s_routing_edge_t, 1); - info->rc_component = current_routing; - info->rc_type = SURF_NETWORK_ELEMENT_ROUTER; - info->name = xbt_strdup(router->id); - info->id = current_routing->parse_PU(current_routing, (void *) info); - xbt_lib_set(as_router_lib, router->id, ROUTING_ASR_LEVEL, (void *) info); - XBT_DEBUG("Having set name '%s' id '%d'",router->id,info->id); - - if (router->coord && strcmp(router->coord, "")) { - unsigned int cursor; - char*str; - - if (!COORD_ASR_LEVEL) - xbt_die ("To use host coordinates, please add --cfg=network/coordinates:yes to your command line"); - /* Pre-parse the host coordinates */ - xbt_dynar_t ctn_str = xbt_str_split_str(router->coord, " "); - xbt_dynar_t ctn = xbt_dynar_new(sizeof(double),NULL); - xbt_dynar_foreach(ctn_str,cursor, str) { - double val = atof(str); - xbt_dynar_push(ctn,&val); - } - xbt_dynar_shrink(ctn, 0); - xbt_dynar_free(&ctn_str); - xbt_lib_set(as_router_lib, router->id, COORD_ASR_LEVEL, (void *) ctn); - XBT_DEBUG("Having set router coordinates for '%s'",router->id); - } -} - -/** - * \brief Store the route by calling the set_route function of the current routing component - */ -static void parse_E_route(sg_platf_route_cbarg_t route) -{ - xbt_assert(current_routing->parse_route, - "no defined method \"set_route\" in \"%s\"", - current_routing->name); - - current_routing->parse_route(current_routing, route); -} - -/** - * \brief Store the ASroute by calling the set_ASroute function of the current routing component - */ -static void parse_E_ASroute(sg_platf_route_cbarg_t ASroute) -{ - xbt_assert(current_routing->parse_ASroute, - "no defined method \"set_ASroute\" in \"%s\"", - current_routing->name); - current_routing->parse_ASroute(current_routing, ASroute); -} - -/** - * \brief Store the bypass route by calling the set_bypassroute function of the current routing component - */ -static void parse_E_bypassRoute(sg_platf_route_cbarg_t route) -{ - xbt_assert(current_routing->parse_bypassroute, - "Bypassing mechanism not implemented by routing '%s'", - current_routing->name); - - current_routing->parse_bypassroute(current_routing, route); -} - -/** - * \brief Store the bypass route by calling the set_bypassroute function of the current routing component - */ -static void parse_E_bypassASroute(sg_platf_route_cbarg_t ASroute) -{ - xbt_assert(current_routing->parse_bypassroute, - "Bypassing mechanism not implemented by routing '%s'", - current_routing->name); - current_routing->parse_bypassroute(current_routing, ASroute); -} - -static void routing_parse_trace(sg_platf_trace_cbarg_t trace) -{ - tmgr_trace_t tmgr_trace; - if (!trace->file || strcmp(trace->file, "") != 0) { - tmgr_trace = tmgr_trace_new_from_file(trace->file); - } else if (strcmp(trace->pc_data, "") == 0) { - tmgr_trace = NULL; - } else { - tmgr_trace = - tmgr_trace_new_from_string(trace->id, trace->pc_data, - trace->periodicity); - } - xbt_dict_set(traces_set_list, trace->id, (void *) tmgr_trace, NULL); -} - -static void routing_parse_trace_connect(sg_platf_trace_connect_cbarg_t trace_connect) -{ - xbt_assert(xbt_dict_get_or_null - (traces_set_list, trace_connect->trace), - "Cannot connect trace %s to %s: trace unknown", - trace_connect->trace, - trace_connect->element); - - switch (trace_connect->kind) { - case SURF_TRACE_CONNECT_KIND_HOST_AVAIL: - xbt_dict_set(trace_connect_list_host_avail, - trace_connect->trace, - xbt_strdup(trace_connect->element), NULL); - break; - case SURF_TRACE_CONNECT_KIND_POWER: - xbt_dict_set(trace_connect_list_power, trace_connect->trace, - xbt_strdup(trace_connect->element), NULL); - break; - case SURF_TRACE_CONNECT_KIND_LINK_AVAIL: - xbt_dict_set(trace_connect_list_link_avail, - trace_connect->trace, - xbt_strdup(trace_connect->element), NULL); - break; - case SURF_TRACE_CONNECT_KIND_BANDWIDTH: - xbt_dict_set(trace_connect_list_bandwidth, - trace_connect->trace, - xbt_strdup(trace_connect->element), NULL); - break; - case SURF_TRACE_CONNECT_KIND_LATENCY: - xbt_dict_set(trace_connect_list_latency, trace_connect->trace, - xbt_strdup(trace_connect->element), NULL); - break; - default: - xbt_die("Cannot connect trace %s to %s: kind of trace unknown", - trace_connect->trace, trace_connect->element); - break; - } -} - -extern int _sg_init_status; /* yay, this is an horrible hack */ - -/** - * \brief Make a new routing component to the platform - * - * Add a new autonomous system to the platform. Any elements (such as host, - * router or sub-AS) added after this call and before the corresponding call - * to sg_platf_new_AS_close() will be added to this AS. - * - * Once this function was called, the configuration concerning the used - * models cannot be changed anymore. - * - * @param AS_id name of this autonomous system. Must be unique in the platform - * @param wanted_routing_type one of Full, Floyd, Dijkstra or similar. Full list in the variable routing_models, in src/surf/surf_routing.c - */ -void routing_AS_begin(sg_platf_AS_cbarg_t AS) -{ - XBT_DEBUG("routing_AS_begin"); - AS_t new_as; - routing_model_description_t model = NULL; - - xbt_assert(!xbt_lib_get_or_null - (as_router_lib, AS->id, ROUTING_ASR_LEVEL), - "The AS \"%s\" already exists", AS->id); - - _sg_init_status = 2; /* horrible hack: direct access to the global controlling the level of configuration to prevent any further config */ - - /* search the routing model */ - switch(AS->routing){ - case A_surfxml_AS_routing_Cluster: model = &routing_models[SURF_MODEL_CLUSTER];break; - case A_surfxml_AS_routing_Dijkstra: model = &routing_models[SURF_MODEL_DIJKSTRA];break; - case A_surfxml_AS_routing_DijkstraCache: model = &routing_models[SURF_MODEL_DIJKSTRACACHE];break; - case A_surfxml_AS_routing_Floyd: model = &routing_models[SURF_MODEL_FLOYD];break; - case A_surfxml_AS_routing_Full: model = &routing_models[SURF_MODEL_FULL];break; - case A_surfxml_AS_routing_None: model = &routing_models[SURF_MODEL_NONE];break; - case A_surfxml_AS_routing_Vivaldi: model = &routing_models[SURF_MODEL_VIVALDI];break; - default: xbt_die("Not a valid model!!!"); - break; - } - - /* make a new routing component */ - new_as = (AS_t) model->create(); - new_as->model_desc = model; - new_as->hierarchy = SURF_ROUTING_NULL; - new_as->name = xbt_strdup(AS->id); - - sg_routing_edge_t info = NULL; - info = xbt_new0(s_routing_edge_t, 1); - - if (current_routing == NULL && routing_platf->root == NULL) { - - /* it is the first one */ - new_as->routing_father = NULL; - routing_platf->root = new_as; - info->id = -1; - } else if (current_routing != NULL && routing_platf->root != NULL) { - - xbt_assert(!xbt_dict_get_or_null - (current_routing->routing_sons, AS->id), - "The AS \"%s\" already exists", AS->id); - /* it is a part of the tree */ - new_as->routing_father = current_routing; - /* set the father behavior */ - if (current_routing->hierarchy == SURF_ROUTING_NULL) - current_routing->hierarchy = SURF_ROUTING_RECURSIVE; - /* add to the sons dictionary */ - xbt_dict_set(current_routing->routing_sons, AS->id, - (void *) new_as, NULL); - /* add to the father element list */ - info->id = current_routing->parse_AS(current_routing, (void *) info); - } else { - THROWF(arg_error, 0, "All defined components must be belong to a AS"); - } - - info->rc_component = new_as->routing_father; - info->rc_type = SURF_NETWORK_ELEMENT_AS; - info->name = new_as->name; - - xbt_lib_set(as_router_lib, info->name, ROUTING_ASR_LEVEL, - (void *) info); - XBT_DEBUG("Having set name '%s' id '%d'",new_as->name,info->id); - - /* set the new current component of the tree */ - current_routing = new_as; - current_routing->net_elem = info; - -} - -/** - * \brief Specify that the current description of AS is finished - * - * Once you've declared all the content of your AS, you have to close - * it with this call. Your AS is not usable until you call this function. - * - * @fixme: this call is not as robust as wanted: bad things WILL happen - * if you call it twice for the same AS, or if you forget calling it, or - * even if you add stuff to a closed AS - * - */ -void routing_AS_end(sg_platf_AS_cbarg_t AS) -{ - - if (current_routing == NULL) { - THROWF(arg_error, 0, "Close an AS, but none was under construction"); - } else { - if (current_routing->model_desc->end) - current_routing->model_desc->end(current_routing); - current_routing = current_routing->routing_father; - } -} - -/* Aux Business methods */ - -/** - * \brief Get the AS father and the first elements of the chain - * - * \param src the source host name - * \param dst the destination host name - * - * Get the common father of the to processing units, and the first different - * father in the chain - */ -static void elements_father(sg_routing_edge_t src, sg_routing_edge_t dst, - AS_t * res_father, - AS_t * res_src, - AS_t * res_dst) -{ - xbt_assert(src && dst, "bad parameters for \"elements_father\" method"); -#define ELEMENTS_FATHER_MAXDEPTH 16 /* increase if it is not enough */ - AS_t src_as, dst_as; - AS_t path_src[ELEMENTS_FATHER_MAXDEPTH]; - AS_t path_dst[ELEMENTS_FATHER_MAXDEPTH]; - int index_src = 0; - int index_dst = 0; - AS_t current; - AS_t current_src; - AS_t current_dst; - AS_t father; - - /* (1) find the as where the src and dst are located */ - sg_routing_edge_t src_data = src; - sg_routing_edge_t dst_data = dst; - src_as = src_data->rc_component; - dst_as = dst_data->rc_component; -#ifndef NDEBUG - char* src_name = src_data->name; - char* dst_name = dst_data->name; -#endif - - xbt_assert(src_as && dst_as, - "Ask for route \"from\"(%s) or \"to\"(%s) no found", src_name, dst_name); - - /* (2) find the path to the root routing component */ - for (current = src_as; current != NULL; current = current->routing_father) { - if (index_src >= ELEMENTS_FATHER_MAXDEPTH) - xbt_die("ELEMENTS_FATHER_MAXDEPTH should be increased for path_src"); - path_src[index_src++] = current; - } - for (current = dst_as; current != NULL; current = current->routing_father) { - if (index_dst >= ELEMENTS_FATHER_MAXDEPTH) - xbt_die("ELEMENTS_FATHER_MAXDEPTH should be increased for path_dst"); - path_dst[index_dst++] = current; - } - - /* (3) find the common father */ - do { - current_src = path_src[--index_src]; - current_dst = path_dst[--index_dst]; - } while (index_src > 0 && index_dst > 0 && current_src == current_dst); - - /* (4) they are not in the same routing component, make the path */ - if (current_src == current_dst) - father = current_src; - else - father = path_src[index_src + 1]; - - /* (5) result generation */ - *res_father = father; /* first the common father of src and dst */ - *res_src = current_src; /* second the first different father of src */ - *res_dst = current_dst; /* three the first different father of dst */ - -#undef ELEMENTS_FATHER_MAXDEPTH -} - -/* Global Business methods */ - -/** - * \brief Recursive function for get_route_latency - * - * \param src the source host name - * \param dst the destination host name - * \param *route the route where the links are stored. It is either NULL or a ready to use dynar - * \param *latency the latency, if needed - * - * This function is called by "get_route" and "get_latency". It allows to walk - * recursively through the ASes tree. - */ -static void _get_route_and_latency(sg_routing_edge_t src, sg_routing_edge_t dst, - xbt_dynar_t * links, double *latency) -{ - s_sg_platf_route_cbarg_t route; - memset(&route,0,sizeof(route)); - - xbt_assert(src && dst, "bad parameters for \"_get_route_latency\" method"); - XBT_DEBUG("Solve route/latency \"%s\" to \"%s\"", src->name, dst->name); - - /* Find how src and dst are interconnected */ - AS_t common_father, src_father, dst_father; - elements_father(src, dst, &common_father, &src_father, &dst_father); - XBT_DEBUG("elements_father: common father '%s' src_father '%s' dst_father '%s'", - common_father->name,src_father->name,dst_father->name); - - /* Check whether a direct bypass is defined */ - sg_platf_route_cbarg_t e_route_bypass = NULL; - if (common_father->get_bypass_route) - e_route_bypass = common_father->get_bypass_route(common_father, src, dst, latency); - - /* Common ancestor is kind enough to declare a bypass route from src to dst -- use it and bail out */ - if (e_route_bypass) { - xbt_dynar_merge(links, &e_route_bypass->link_list); - generic_free_route(e_route_bypass); - return; - } - - /* If src and dst are in the same AS, life is good */ - if (src_father == dst_father) { /* SURF_ROUTING_BASE */ - route.link_list = *links; - common_father->get_route_and_latency(common_father, src, dst, &route,latency); - // if vivaldi latency+=vivaldi(src,dst) - return; - } - - /* Not in the same AS, no bypass. We'll have to find our path between the ASes recursively*/ - - route.link_list = xbt_dynar_new(sizeof(sg_routing_link_t), NULL); - // Find the net_card corresponding to father - sg_routing_edge_t src_father_net_elm = src_father->net_elem; - sg_routing_edge_t dst_father_net_elm = dst_father->net_elem; - - common_father->get_route_and_latency(common_father, - src_father_net_elm, dst_father_net_elm, - &route, latency); - - xbt_assert((route.gw_src != NULL) && (route.gw_dst != NULL), - "bad gateways for route from \"%s\" to \"%s\"", src->name, dst->name); - - sg_routing_edge_t src_gateway_net_elm = route.gw_src; - sg_routing_edge_t dst_gateway_net_elm = route.gw_dst; - - /* If source gateway is not our source, we have to recursively find our way up to this point */ - if (src != src_gateway_net_elm) - _get_route_and_latency(src, src_gateway_net_elm, links, latency); - xbt_dynar_merge(links, &route.link_list); - - /* If dest gateway is not our destination, we have to recursively find our way from this point */ - if (dst_gateway_net_elm != dst) - _get_route_and_latency(dst_gateway_net_elm, dst, links, latency); - - // if vivaldi latency+=vivaldi(src_gateway,dst_gateway) -} - -/** - * \brief Find a route between hosts - * - * \param src the network_element_t for src host - * \param dst the network_element_t for dst host - * \param route where to store the list of links. - * If *route=NULL, create a short lived dynar. Else, fill the provided dynar - * \param latency where to store the latency experienced on the path (or NULL if not interested) - * It is the caller responsability to initialize latency to 0 (we add to provided route) - * \pre route!=NULL - * - * walk through the routing components tree and find a route between hosts - * by calling the differents "get_route" functions in each routing component. - */ -void routing_get_route_and_latency(sg_routing_edge_t src, - sg_routing_edge_t dst, - xbt_dynar_t * route, double *latency) -{ - XBT_DEBUG("routing_get_route_and_latency from %s to %s",src->name,dst->name); - if (!*route) { - xbt_dynar_reset(routing_platf->last_route); - *route = routing_platf->last_route; - } - - _get_route_and_latency(src, dst, route, latency); - - xbt_assert(!latency || *latency >= 0.0, - "negative latency on route between \"%s\" and \"%s\"", src->name, dst->name); -} - -static xbt_dynar_t recursive_get_onelink_routes(AS_t rc) -{ - xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free); - - //adding my one link routes - xbt_dynar_t onelink_mine = rc->get_onelink_routes(rc); - if (onelink_mine) - xbt_dynar_merge(&ret,&onelink_mine); - - //recursing - char *key; - xbt_dict_cursor_t cursor = NULL; - AS_t rc_child; - xbt_dict_foreach(rc->routing_sons, cursor, key, rc_child) { - xbt_dynar_t onelink_child = recursive_get_onelink_routes(rc_child); - if (onelink_child) - xbt_dynar_merge(&ret,&onelink_child); - } - return ret; -} - -static xbt_dynar_t get_onelink_routes(void) -{ - return recursive_get_onelink_routes(routing_platf->root); -} - -e_surf_network_element_type_t routing_get_network_element_type(const char *name) -{ - sg_routing_edge_t rc = sg_routing_edge_by_name_or_null(name); - if (rc) - return rc->rc_type; - - return SURF_NETWORK_ELEMENT_NULL; -} - -/** - * \brief Generic method: create the global routing schema - * - * Make a global routing structure and set all the parsing functions. - */ -void routing_model_create( void *loopback) -{ - /* config the uniq global routing */ - routing_platf = xbt_new0(s_routing_platf_t, 1); - routing_platf->root = NULL; - routing_platf->get_onelink_routes = get_onelink_routes; - routing_platf->loopback = loopback; - routing_platf->last_route = xbt_dynar_new(sizeof(sg_routing_link_t),NULL); - /* no current routing at moment */ - current_routing = NULL; -} - - -/* ************************************************** */ -/* ********** PATERN FOR NEW ROUTING **************** */ - -/* The minimal configuration of a new routing model need the next functions, - * also you need to set at the start of the file, the new model in the model - * list. Remember keep the null ending of the list. - */ -/*** Routing model structure ***/ -// typedef struct { -// s_routing_component_t generic_routing; -// /* things that your routing model need */ -// } s_routing_component_NEW_t,*routing_component_NEW_t; - -/*** Parse routing model functions ***/ -// static void model_NEW_set_processing_unit(routing_component_t rc, const char* name) {} -// static void model_NEW_set_autonomous_system(routing_component_t rc, const char* name) {} -// static void model_NEW_set_route(routing_component_t rc, const char* src, const char* dst, route_t route) {} -// static void model_NEW_set_ASroute(routing_component_t rc, const char* src, const char* dst, route_extended_t route) {} -// static void model_NEW_set_bypassroute(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route) {} - -/*** Business methods ***/ -// static route_extended_t NEW_get_route(routing_component_t rc, const char* src,const char* dst) {return NULL;} -// static route_extended_t NEW_get_bypass_route(routing_component_t rc, const char* src,const char* dst) {return NULL;} -// static void NEW_finalize(routing_component_t rc) { xbt_free(rc);} - -/*** Creation routing model functions ***/ -// static void* model_NEW_create(void) { -// routing_component_NEW_t new_component = xbt_new0(s_routing_component_NEW_t,1); -// new_component->generic_routing.set_processing_unit = model_NEW_set_processing_unit; -// new_component->generic_routing.set_autonomous_system = model_NEW_set_autonomous_system; -// new_component->generic_routing.set_route = model_NEW_set_route; -// new_component->generic_routing.set_ASroute = model_NEW_set_ASroute; -// new_component->generic_routing.set_bypassroute = model_NEW_set_bypassroute; -// new_component->generic_routing.get_route = NEW_get_route; -// new_component->generic_routing.get_bypass_route = NEW_get_bypass_route; -// new_component->generic_routing.finalize = NEW_finalize; -// /* initialization of internal structures */ -// return new_component; -// } /* mandatory */ -// static void model_NEW_load(void) {} /* mandatory */ -// static void model_NEW_unload(void) {} /* mandatory */ -// static void model_NEW_end(void) {} /* mandatory */ - -/* ************************************************************************** */ -/* ************************* GENERIC PARSE FUNCTIONS ************************ */ - -void routing_cluster_add_backbone(void* bb) { - xbt_assert(current_routing->model_desc == &routing_models[SURF_MODEL_CLUSTER], - "You have to be in model Cluster to use tag backbone!"); - xbt_assert(!((as_cluster_t)current_routing)->backbone,"The backbone link is already defined!"); - ((as_cluster_t)current_routing)->backbone = bb; - XBT_DEBUG("Add a backbone to AS '%s'",current_routing->name); -} - -static void routing_parse_cabinet(sg_platf_cabinet_cbarg_t cabinet) -{ - int start, end, i; - char *groups , *host_id , *link_id = NULL; - unsigned int iter; - xbt_dynar_t radical_elements; - xbt_dynar_t radical_ends; - - //Make all hosts - radical_elements = xbt_str_split(cabinet->radical, ","); - xbt_dynar_foreach(radical_elements, iter, groups) { - - radical_ends = xbt_str_split(groups, "-"); - start = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 0, char *)); - - switch (xbt_dynar_length(radical_ends)) { - case 1: - end = start; - break; - case 2: - end = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 1, char *)); - break; - default: - surf_parse_error("Malformed radical"); - break; - } - s_sg_platf_host_cbarg_t host; - memset(&host, 0, sizeof(host)); - host.initial_state = SURF_RESOURCE_ON; - host.power_peak = cabinet->power; - host.power_scale = 1.0; - host.core_amount = 1; - - s_sg_platf_link_cbarg_t link; - memset(&link, 0, sizeof(link)); - link.state = SURF_RESOURCE_ON; - link.policy = SURF_LINK_FULLDUPLEX; - link.latency = cabinet->lat; - link.bandwidth = cabinet->bw; - - s_sg_platf_host_link_cbarg_t host_link; - memset(&host_link, 0, sizeof(host_link)); - - for (i = start; i <= end; i++) { - host_id = bprintf("%s%d%s",cabinet->prefix,i,cabinet->suffix); - link_id = bprintf("link_%s%d%s",cabinet->prefix,i,cabinet->suffix); - host.id = host_id; - link.id = link_id; - sg_platf_new_host(&host); - sg_platf_new_link(&link); - - char* link_up = bprintf("%s_UP",link_id); - char* link_down = bprintf("%s_DOWN",link_id); - host_link.id = host_id; - host_link.link_up = link_up; - host_link.link_down= link_down; - sg_platf_new_host_link(&host_link); - - free(host_id); - free(link_id); - free(link_up); - free(link_down); - } - - xbt_dynar_free(&radical_ends); - } - xbt_dynar_free(&radical_elements); -} - -static void routing_parse_cluster(sg_platf_cluster_cbarg_t cluster) -{ - char *host_id, *groups, *link_id = NULL; - xbt_dict_t patterns = NULL; - - s_sg_platf_host_cbarg_t host; - s_sg_platf_link_cbarg_t link; - - unsigned int iter; - int start, end, i; - xbt_dynar_t radical_elements; - xbt_dynar_t radical_ends; - - if ((cluster->availability_trace && strcmp(cluster->availability_trace, "")) - || (cluster->state_trace && strcmp(cluster->state_trace, ""))) { - patterns = xbt_dict_new_homogeneous(xbt_free_f); - xbt_dict_set(patterns, "id", xbt_strdup(cluster->id), NULL); - xbt_dict_set(patterns, "prefix", xbt_strdup(cluster->prefix), NULL); - xbt_dict_set(patterns, "suffix", xbt_strdup(cluster->suffix), NULL); - } - - XBT_DEBUG("", cluster->id); - s_sg_platf_AS_cbarg_t AS = SG_PLATF_AS_INITIALIZER; - AS.id = cluster->id; - AS.routing = A_surfxml_AS_routing_Cluster; - sg_platf_new_AS_begin(&AS); - - current_routing->link_up_down_list - = xbt_dynar_new(sizeof(s_surf_parsing_link_up_down_t),NULL); - - //Make all hosts - radical_elements = xbt_str_split(cluster->radical, ","); - xbt_dynar_foreach(radical_elements, iter, groups) { - - radical_ends = xbt_str_split(groups, "-"); - start = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 0, char *)); - - switch (xbt_dynar_length(radical_ends)) { - case 1: - end = start; - break; - case 2: - end = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 1, char *)); - break; - default: - surf_parse_error("Malformed radical"); - break; - } - for (i = start; i <= end; i++) { - host_id = - bprintf("%s%d%s", cluster->prefix, i, cluster->suffix); - link_id = bprintf("%s_link_%d", cluster->id, i); - - XBT_DEBUG("", host_id, cluster->power); - - memset(&host, 0, sizeof(host)); - host.id = host_id; - if (cluster->availability_trace && strcmp(cluster->availability_trace, "")) { - xbt_dict_set(patterns, "radical", bprintf("%d", i), NULL); - char *avail_file = xbt_str_varsubst(cluster->availability_trace, patterns); - XBT_DEBUG("\tavailability_file=\"%s\"", avail_file); - host.power_trace = tmgr_trace_new_from_file(avail_file); - xbt_free(avail_file); - } else { - XBT_DEBUG("\tavailability_file=\"\""); - } - - if (cluster->state_trace && strcmp(cluster->state_trace, "")) { - char *avail_file = xbt_str_varsubst(cluster->state_trace, patterns); - XBT_DEBUG("\tstate_file=\"%s\"", avail_file); - host.state_trace = tmgr_trace_new_from_file(avail_file); - xbt_free(avail_file); - } else { - XBT_DEBUG("\tstate_file=\"\""); - } - - host.power_peak = cluster->power; - host.power_scale = 1.0; - host.core_amount = cluster->core_amount; - host.initial_state = SURF_RESOURCE_ON; - host.coord = ""; - sg_platf_new_host(&host); - XBT_DEBUG(""); - - XBT_DEBUG("", link_id, - cluster->bw, cluster->lat); - - memset(&link, 0, sizeof(link)); - link.id = link_id; - link.bandwidth = cluster->bw; - link.latency = cluster->lat; - link.state = SURF_RESOURCE_ON; - link.policy = cluster->sharing_policy; - sg_platf_new_link(&link); - - s_surf_parsing_link_up_down_t info; - - if (link.policy == SURF_LINK_FULLDUPLEX) { - char *tmp_link = bprintf("%s_UP", link_id); - info.link_up = - xbt_lib_get_or_null(link_lib, tmp_link, SURF_LINK_LEVEL); - free(tmp_link); - tmp_link = bprintf("%s_DOWN", link_id); - info.link_down = - xbt_lib_get_or_null(link_lib, tmp_link, SURF_LINK_LEVEL); - free(tmp_link); - } else { - info.link_up = xbt_lib_get_or_null(link_lib, link_id, SURF_LINK_LEVEL); - info.link_down = info.link_up; - } - - if(cluster->limiter_link!=0){ - char *tmp_link = bprintf("%s_limiter", link_id); - XBT_DEBUG("", tmp_link, - cluster->limiter_link); - - - memset(&link, 0, sizeof(link)); - link.id = tmp_link; - link.bandwidth = cluster->limiter_link; - link.latency = 0; - link.state = SURF_RESOURCE_ON; - link.policy = SURF_LINK_SHARED; - sg_platf_new_link(&link); - info.limiter_link = - xbt_lib_get_or_null(link_lib, tmp_link, SURF_LINK_LEVEL); - free(tmp_link); - }else{ - info.limiter_link =NULL; - } - - if(cluster->loopback_bw!=0 || cluster->loopback_lat!=0){ - char *tmp_link = bprintf("%s_loopback", link_id); - XBT_DEBUG("", tmp_link, - cluster->limiter_link); - - - memset(&link, 0, sizeof(link)); - link.id = tmp_link; - link.bandwidth = cluster->loopback_bw; - link.latency = cluster->loopback_lat; - link.state = SURF_RESOURCE_ON; - link.policy = SURF_LINK_FATPIPE; - sg_platf_new_link(&link); - info.loopback_link = - xbt_lib_get_or_null(link_lib, tmp_link, SURF_LINK_LEVEL); - free(tmp_link); - }else{ - info.loopback_link =NULL; - } - - xbt_dynar_push(current_routing->link_up_down_list,&info); - xbt_free(link_id); - xbt_free(host_id); - } - - xbt_dynar_free(&radical_ends); - } - xbt_dynar_free(&radical_elements); - - // Add a router. It is magically used thanks to the way in which surf_routing_cluster is written, - // and it's very useful to connect clusters together - XBT_DEBUG(" "); - XBT_DEBUG("", cluster->router_id); - char *newid = NULL; - s_sg_platf_router_cbarg_t router; - memset(&router, 0, sizeof(router)); - router.id = cluster->router_id; - router.coord = ""; - if (!router.id || !strcmp(router.id, "")) - router.id = newid = - bprintf("%s%s_router%s", cluster->prefix, cluster->id, - cluster->suffix); - sg_platf_new_router(&router); - ((as_cluster_t)current_routing)->router = xbt_lib_get_or_null(as_router_lib, router.id, ROUTING_ASR_LEVEL); - free(newid); - - //Make the backbone - if ((cluster->bb_bw != 0) || (cluster->bb_lat != 0)) { - char *link_backbone = bprintf("%s_backbone", cluster->id); - XBT_DEBUG("", link_backbone, - cluster->bb_bw, cluster->bb_lat); - - memset(&link, 0, sizeof(link)); - link.id = link_backbone; - link.bandwidth = cluster->bb_bw; - link.latency = cluster->bb_lat; - link.state = SURF_RESOURCE_ON; - link.policy = cluster->bb_sharing_policy; - - sg_platf_new_link(&link); - - routing_cluster_add_backbone(xbt_lib_get_or_null(link_lib, link_backbone, SURF_LINK_LEVEL)); - - free(link_backbone); - } - - XBT_DEBUG(""); - sg_platf_new_AS_end(); - XBT_DEBUG(" "); - xbt_dict_free(&patterns); // no op if it were never set -} - -static void routing_parse_postparse(void) { - xbt_dict_free(&random_value); -} - -static void routing_parse_peer(sg_platf_peer_cbarg_t peer) -{ - char *host_id = NULL; - char *link_id; - - XBT_DEBUG(" "); - host_id = HOST_PEER(peer->id); - link_id = LINK_PEER(peer->id); - - XBT_DEBUG("", host_id, peer->power); - s_sg_platf_host_cbarg_t host; - memset(&host, 0, sizeof(host)); - host.initial_state = SURF_RESOURCE_ON; - host.id = host_id; - host.power_peak = peer->power; - host.power_scale = 1.0; - host.power_trace = peer->availability_trace; - host.state_trace = peer->state_trace; - host.core_amount = 1; - host.coord = peer->coord; - sg_platf_new_host(&host); - - s_sg_platf_link_cbarg_t link; - memset(&link, 0, sizeof(link)); - link.state = SURF_RESOURCE_ON; - link.policy = SURF_LINK_SHARED; - link.latency = peer->lat; - - char* link_up = bprintf("%s_UP",link_id); - XBT_DEBUG("", link_up, - peer->bw_out, peer->lat); - link.id = link_up; - link.bandwidth = peer->bw_out; - sg_platf_new_link(&link); - - char* link_down = bprintf("%s_DOWN",link_id); - XBT_DEBUG("", link_down, - peer->bw_in, peer->lat); - link.id = link_down; - link.bandwidth = peer->bw_in; - sg_platf_new_link(&link); - - XBT_DEBUG("", host_id,link_up,link_down); - s_sg_platf_host_link_cbarg_t host_link; - memset(&host_link, 0, sizeof(host_link)); - host_link.id = host_id; - host_link.link_up = link_up; - host_link.link_down= link_down; - sg_platf_new_host_link(&host_link); - - XBT_DEBUG(" "); - - //xbt_dynar_free(&tab_elements_num); - free(host_id); - free(link_id); - free(link_up); - free(link_down); -} - -static void routing_parse_Srandom(void) -{ - double mean, std, min, max, seed; - char *random_id = A_surfxml_random_id; - char *random_radical = A_surfxml_random_radical; - char *rd_name = NULL; - char *rd_value; - mean = surf_parse_get_double(A_surfxml_random_mean); - std = surf_parse_get_double(A_surfxml_random_std___deviation); - min = surf_parse_get_double(A_surfxml_random_min); - max = surf_parse_get_double(A_surfxml_random_max); - seed = surf_parse_get_double(A_surfxml_random_seed); - - double res = 0; - int i = 0; - random_data_t random = xbt_new0(s_random_data_t, 1); - char *tmpbuf; - - xbt_dynar_t radical_elements; - unsigned int iter; - char *groups; - int start, end; - xbt_dynar_t radical_ends; - - switch (A_surfxml_random_generator) { - case AU_surfxml_random_generator: - case A_surfxml_random_generator_NONE: - random->generator = NONE; - break; - case A_surfxml_random_generator_DRAND48: - random->generator = DRAND48; - break; - case A_surfxml_random_generator_RAND: - random->generator = RAND; - break; - case A_surfxml_random_generator_RNGSTREAM: - random->generator = RNGSTREAM; - break; - default: - surf_parse_error("Invalid random generator"); - break; - } - random->seed = seed; - random->min = min; - random->max = max; - - /* Check user stupidities */ - if (max < min) - THROWF(arg_error, 0, "random->max < random->min (%f < %f)", max, min); - if (mean < min) - THROWF(arg_error, 0, "random->mean < random->min (%f < %f)", mean, min); - if (mean > max) - THROWF(arg_error, 0, "random->mean > random->max (%f > %f)", mean, max); - - /* normalize the mean and standard deviation before storing */ - random->mean = (mean - min) / (max - min); - random->std = std / (max - min); - - if (random->mean * (1 - random->mean) < random->std * random->std) - THROWF(arg_error, 0, "Invalid mean and standard deviation (%f and %f)", - random->mean, random->std); - - XBT_DEBUG - ("id = '%s' min = '%f' max = '%f' mean = '%f' std_deviatinon = '%f' generator = '%d' seed = '%ld' radical = '%s'", - random_id, random->min, random->max, random->mean, random->std, - (int)random->generator, random->seed, random_radical); - - if (!random_value) - random_value = xbt_dict_new_homogeneous(free); - - if (!strcmp(random_radical, "")) { - res = random_generate(random); - rd_value = bprintf("%f", res); - xbt_dict_set(random_value, random_id, rd_value, NULL); - } else { - radical_elements = xbt_str_split(random_radical, ","); - xbt_dynar_foreach(radical_elements, iter, groups) { - radical_ends = xbt_str_split(groups, "-"); - switch (xbt_dynar_length(radical_ends)) { - case 1: - xbt_assert(!xbt_dict_get_or_null(random_value, random_id), - "Custom Random '%s' already exists !", random_id); - res = random_generate(random); - tmpbuf = - bprintf("%s%d", random_id, - atoi(xbt_dynar_getfirst_as(radical_ends, char *))); - xbt_dict_set(random_value, tmpbuf, bprintf("%f", res), NULL); - xbt_free(tmpbuf); - break; - - case 2: - start = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 0, char *)); - end = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 1, char *)); - for (i = start; i <= end; i++) { - xbt_assert(!xbt_dict_get_or_null(random_value, random_id), - "Custom Random '%s' already exists !", bprintf("%s%d", - random_id, - i)); - res = random_generate(random); - tmpbuf = bprintf("%s%d", random_id, i); - xbt_dict_set(random_value, tmpbuf, bprintf("%f", res), NULL); - xbt_free(tmpbuf); - } - break; - default: - XBT_CRITICAL("Malformed radical"); - break; - } - res = random_generate(random); - rd_name = bprintf("%s_router", random_id); - rd_value = bprintf("%f", res); - xbt_dict_set(random_value, rd_name, rd_value, NULL); - - xbt_dynar_free(&radical_ends); - } - free(rd_name); - xbt_dynar_free(&radical_elements); - } -} - -void routing_register_callbacks() -{ - sg_platf_host_add_cb(parse_S_host); - sg_platf_router_add_cb(parse_S_router); - sg_platf_host_link_add_cb(parse_S_host_link); - sg_platf_route_add_cb(parse_E_route); - sg_platf_ASroute_add_cb(parse_E_ASroute); - sg_platf_bypassRoute_add_cb(parse_E_bypassRoute); - sg_platf_bypassASroute_add_cb(parse_E_bypassASroute); - - sg_platf_cluster_add_cb(routing_parse_cluster); - sg_platf_cabinet_add_cb(routing_parse_cabinet); - - sg_platf_peer_add_cb(routing_parse_peer); - sg_platf_postparse_add_cb(routing_parse_postparse); - - /* we care about the ASes while parsing the platf. Incredible, isnt it? */ - sg_platf_AS_end_add_cb(routing_AS_end); - sg_platf_AS_begin_add_cb(routing_AS_begin); - - sg_platf_trace_add_cb(routing_parse_trace); - sg_platf_trace_connect_add_cb(routing_parse_trace_connect); - -#ifdef HAVE_TRACING - instr_routing_define_callbacks(); -#endif -} - -/** - * \brief Recursive function for finalize - * - * \param rc the source host name - * - * This fuction is call by "finalize". It allow to finalize the - * AS or routing components. It delete all the structures. - */ -static void finalize_rec(AS_t as) { - xbt_dict_cursor_t cursor = NULL; - char *key; - AS_t elem; - - xbt_dict_foreach(as->routing_sons, cursor, key, elem) { - finalize_rec(elem); - } - - as->finalize(as); -} - -/** \brief Frees all memory allocated by the routing module */ -void routing_exit(void) { - if (!routing_platf) - return; - xbt_dynar_free(&routing_platf->last_route); - finalize_rec(routing_platf->root); - xbt_free(routing_platf); -} - -AS_t surf_AS_get_routing_root() { - return routing_platf->root; -} - -const char *surf_AS_get_name(AS_t as) { - return as->name; -} - -xbt_dict_t surf_AS_get_routing_sons(AS_t as) { - return as->routing_sons; -} - -const char *surf_AS_get_model(AS_t as) { - return as->model_desc->name; -} - -xbt_dynar_t surf_AS_get_hosts(AS_t as) { - xbt_dynar_t elms = as->index_network_elm; - sg_routing_edge_t relm; - xbt_dictelm_t delm; - int index; - int count = xbt_dynar_length(elms); - xbt_dynar_t res = xbt_dynar_new(sizeof(xbt_dictelm_t), NULL); - for (index = 0; index < count; index++) { - relm = xbt_dynar_get_as(elms, index, sg_routing_edge_t); - delm = xbt_lib_get_elm_or_null(host_lib, relm->name); - if (delm!=NULL) { - xbt_dynar_push(res, &delm); - } - } - return res; -} diff --git a/src/surf/surf_routing_cluster.c b/src/surf/surf_routing_cluster.c deleted file mode 100644 index fbd7b4211d..0000000000 --- a/src/surf/surf_routing_cluster.c +++ /dev/null @@ -1,174 +0,0 @@ -/* Copyright (c) 2009, 2010, 2011. The SimGrid Team. - * All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ -#include "surf_routing_private.h" -#include "xbt/graph.h" - -/* Global vars */ - -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_cluster, surf, "Routing part of surf"); - -/* This routing is specifically setup to represent clusters, aka homogeneous sets of machines - * Note that a router is created, easing the interconnexion with the rest of the world. - */ - -/* Business methods */ -static void cluster_get_route_and_latency(AS_t as, - sg_routing_edge_t src, - sg_routing_edge_t dst, - sg_platf_route_cbarg_t route, - double *lat) -{ - - s_surf_parsing_link_up_down_t info; - XBT_VERB("cluster_get_route_and_latency from '%s'[%d] to '%s'[%d]", - src->name, src->id, dst->name, dst->id); - - if (src->rc_type != SURF_NETWORK_ELEMENT_ROUTER) { // No specific link for router - info = - xbt_dynar_get_as(as->link_up_down_list, src->id, - s_surf_parsing_link_up_down_t); - - if((src->id == dst->id) && info.loopback_link ){ - xbt_dynar_push_as(route->link_list, void *, info.loopback_link); - if (lat) - *lat += - surf_network_model->extension.network.get_link_latency(info. - loopback_link); - return; - } - - - if (info.limiter_link) // limiter for sender - xbt_dynar_push_as(route->link_list, void *, info.limiter_link); - - if (info.link_up) { // link up - xbt_dynar_push_as(route->link_list, void *, info.link_up); - if (lat) - *lat += - surf_network_model->extension.network.get_link_latency(info. - link_up); - } - } - - if (((as_cluster_t) as)->backbone) { - xbt_dynar_push_as(route->link_list, void *, ((as_cluster_t) as)->backbone); - if (lat) - *lat += - surf_network_model->extension.network. - get_link_latency(((as_cluster_t) as)->backbone); - } - - if (dst->rc_type != SURF_NETWORK_ELEMENT_ROUTER) { // No specific link for router - info = - xbt_dynar_get_as(as->link_up_down_list, dst->id, - s_surf_parsing_link_up_down_t); - if (info.link_down) { // link down - xbt_dynar_push_as(route->link_list, void *, info.link_down); - if (lat) - *lat += - surf_network_model->extension.network.get_link_latency(info. - link_down); - } - - if (info.limiter_link) // limiter for receiver - xbt_dynar_push_as(route->link_list, void *, info.limiter_link); - - } -} - -static void cluster_get_graph(xbt_graph_t graph, xbt_dict_t nodes, - xbt_dict_t edges, AS_t rc) -{ - int isrc; - int table_size = xbt_dynar_length(rc->index_network_elm); - - sg_routing_edge_t src; - xbt_node_t current, previous, backboneNode = NULL, routerNode; - s_surf_parsing_link_up_down_t info; - - xbt_assert(((as_cluster_t) rc)->router,"Malformed cluster"); - - /* create the router */ - char *link_name = - ((sg_routing_edge_t) ((as_cluster_t) rc)->router)->name; - routerNode = new_xbt_graph_node(graph, link_name, nodes); - - if(((as_cluster_t) rc)->backbone) { - char *link_nameR = - ((surf_resource_t) ((as_cluster_t) rc)->backbone)->name; - backboneNode = new_xbt_graph_node(graph, link_nameR, nodes); - - new_xbt_graph_edge(graph, routerNode, backboneNode, edges); - } - - for (isrc = 0; isrc < table_size; isrc++) { - src = xbt_dynar_get_as(rc->index_network_elm, isrc, sg_routing_edge_t); - - if (src->rc_type != SURF_NETWORK_ELEMENT_ROUTER) { - previous = new_xbt_graph_node(graph, src->name, nodes); - - info = xbt_dynar_get_as(rc->link_up_down_list, src->id, - s_surf_parsing_link_up_down_t); - - if (info.link_up) { // link up - - char *link_name = ((surf_resource_t) info.link_up)->name; - current = new_xbt_graph_node(graph, link_name, nodes); - new_xbt_graph_edge(graph, previous, current, edges); - - if (((as_cluster_t) rc)->backbone) { - new_xbt_graph_edge(graph, current, backboneNode, edges); - } else { - new_xbt_graph_edge(graph, current, routerNode, edges); - } - - } - - if (info.link_down) { // link down - char *link_name = ((surf_resource_t) info.link_down)->name; - current = new_xbt_graph_node(graph, link_name, nodes); - new_xbt_graph_edge(graph, previous, current, edges); - - if (((as_cluster_t) rc)->backbone) { - new_xbt_graph_edge(graph, current, backboneNode, edges); - } else { - new_xbt_graph_edge(graph, current, routerNode, edges); - } - } - } - - } -} - -static void model_cluster_finalize(AS_t as) -{ - model_none_finalize(as); -} - -static int cluster_parse_PU(AS_t rc, sg_routing_edge_t elm) { - XBT_DEBUG("Load process unit \"%s\"", elm->name); - xbt_dynar_push_as(rc->index_network_elm,sg_routing_edge_t,elm); - return xbt_dynar_length(rc->index_network_elm)-1; -} - -static int cluster_parse_AS(AS_t rc, sg_routing_edge_t elm) { - XBT_DEBUG("Load Autonomous system \"%s\"", elm->name); - xbt_dynar_push_as(rc->index_network_elm,sg_routing_edge_t,elm); - return xbt_dynar_length(rc->index_network_elm)-1; -} - -/* Creation routing model functions */ -AS_t model_cluster_create(void) -{ - AS_t result = model_none_create_sized(sizeof(s_as_cluster_t)); - result->get_route_and_latency = cluster_get_route_and_latency; - result->finalize = model_cluster_finalize; - result->get_graph = cluster_get_graph; - result->parse_AS = cluster_parse_AS; - result->parse_PU = cluster_parse_PU; - - return (AS_t) result; -} diff --git a/src/surf/surf_routing_dijkstra.c b/src/surf/surf_routing_dijkstra.c deleted file mode 100644 index d225cd4621..0000000000 --- a/src/surf/surf_routing_dijkstra.c +++ /dev/null @@ -1,538 +0,0 @@ -/* Copyright (c) 2009, 2010, 2011. The SimGrid Team. - * All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ - -#include "surf_routing_private.h" - -/* Global vars */ -extern routing_platf_t routing_platf; - -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_dijkstra, surf, "Routing part of surf -- dijkstra routing logic"); - -typedef struct { - s_as_t generic_routing; - xbt_graph_t route_graph; /* xbt_graph */ - xbt_dict_t graph_node_map; /* map */ - xbt_dict_t route_cache; /* use in cache mode */ - int cached; -} s_as_dijkstra_t, *as_dijkstra_t; - - -typedef struct graph_node_data { - int id; - int graph_id; /* used for caching internal graph id's */ -} s_graph_node_data_t, *graph_node_data_t; - -typedef struct graph_node_map_element { - xbt_node_t node; -} s_graph_node_map_element_t, *graph_node_map_element_t; - -typedef struct route_cache_element { - int *pred_arr; - int size; -} s_route_cache_element_t, *route_cache_element_t; - -/* Free functions */ - -static void route_cache_elem_free(void *e) -{ - route_cache_element_t elm = (route_cache_element_t) e; - if (elm) { - xbt_free(elm->pred_arr); - xbt_free(elm); - } -} - -static void graph_node_map_elem_free(void *e) -{ - graph_node_map_element_t elm = (graph_node_map_element_t) e; - xbt_free(elm); -} - -static void graph_edge_data_free(void *e) // FIXME: useless code duplication -{ - sg_platf_route_cbarg_t e_route = (sg_platf_route_cbarg_t) e; - if (e_route) { - xbt_dynar_free(&(e_route->link_list)); - xbt_free(e_route); - } -} - -/* Utility functions */ - -static xbt_node_t route_graph_new_node(as_dijkstra_t as, - int id, int graph_id) -{ - xbt_node_t node = NULL; - graph_node_data_t data = NULL; - graph_node_map_element_t elm = NULL; - - data = xbt_new0(struct graph_node_data, 1); - data->id = id; - data->graph_id = graph_id; - node = xbt_graph_new_node(as->route_graph, data); - - elm = xbt_new0(struct graph_node_map_element, 1); - elm->node = node; - xbt_dict_set_ext(as->graph_node_map, (char *) (&id), sizeof(int), - (xbt_set_elm_t) elm, NULL); - - return node; -} - -static graph_node_map_element_t -graph_node_map_search(as_dijkstra_t as, int id) -{ - graph_node_map_element_t elm = (graph_node_map_element_t) - xbt_dict_get_or_null_ext(as->graph_node_map, - (char *) (&id), - sizeof(int)); - return elm; -} - -/* Parsing */ - -static void route_new_dijkstra(as_dijkstra_t as, int src_id, - int dst_id, sg_platf_route_cbarg_t e_route) -{ - XBT_DEBUG("Load Route from \"%d\" to \"%d\"", src_id, dst_id); - xbt_node_t src = NULL; - xbt_node_t dst = NULL; - - graph_node_map_element_t src_elm = (graph_node_map_element_t) - xbt_dict_get_or_null_ext(as->graph_node_map, - (char *) (&src_id), - sizeof(int)); - graph_node_map_element_t dst_elm = (graph_node_map_element_t) - xbt_dict_get_or_null_ext(as->graph_node_map, - (char *) (&dst_id), - sizeof(int)); - - - if (src_elm) - src = src_elm->node; - - if (dst_elm) - dst = dst_elm->node; - - /* add nodes if they don't exist in the graph */ - if (src_id == dst_id && src == NULL && dst == NULL) { - src = route_graph_new_node(as, src_id, -1); - dst = src; - } else { - if (src == NULL) { - src = route_graph_new_node(as, src_id, -1); - } - if (dst == NULL) { - dst = route_graph_new_node(as, dst_id, -1); - } - } - - /* add link as edge to graph */ - xbt_graph_new_edge(as->route_graph, src, dst, e_route); -} - -static void add_loopback_dijkstra(as_dijkstra_t as) { - xbt_dynar_t nodes = xbt_graph_get_nodes(as->route_graph); - - xbt_node_t node = NULL; - unsigned int cursor2; - xbt_dynar_foreach(nodes, cursor2, node) { - xbt_dynar_t out_edges = xbt_graph_node_get_outedges(node); - xbt_edge_t edge = NULL; - unsigned int cursor; - - int found = 0; - xbt_dynar_foreach(out_edges, cursor, edge) { - xbt_node_t other_node = xbt_graph_edge_get_target(edge); - if (other_node == node) { - found = 1; - break; - } - } - - if (!found) { - sg_platf_route_cbarg_t e_route = xbt_new0(s_sg_platf_route_cbarg_t, 1); - e_route->link_list = xbt_dynar_new(sizeof(sg_routing_link_t), NULL); - xbt_dynar_push(e_route->link_list, &routing_platf->loopback); - xbt_graph_new_edge(as->route_graph, node, node, e_route); - } - } -} - -static void dijkstra_get_route_and_latency(AS_t as_generic, - sg_routing_edge_t src, sg_routing_edge_t dst, sg_platf_route_cbarg_t route, double *lat); - -static xbt_dynar_t dijkstra_get_onelink_routes(AS_t as) -{ - xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free); - sg_platf_route_cbarg_t route = xbt_new0(s_sg_platf_route_cbarg_t,1); - route->link_list = xbt_dynar_new(sizeof(sg_routing_link_t),NULL); - - int src,dst; - sg_routing_edge_t src_elm, dst_elm; - size_t table_size = xbt_dynar_length(as->index_network_elm); - for(src=0; src < table_size; src++) { - for(dst=0; dst< table_size; dst++) { - xbt_dynar_reset(route->link_list); - src_elm = xbt_dynar_get_as(as->index_network_elm,src,sg_routing_edge_t); - dst_elm = xbt_dynar_get_as(as->index_network_elm,dst,sg_routing_edge_t); - dijkstra_get_route_and_latency(as, src_elm, dst_elm,route, NULL); - - if (xbt_dynar_length(route->link_list) == 1) { - void *link = *(void **) xbt_dynar_get_ptr(route->link_list, 0); - onelink_t onelink = xbt_new0(s_onelink_t, 1); - onelink->link_ptr = link; - if (as->hierarchy == SURF_ROUTING_BASE) { - onelink->src = src_elm; - onelink->dst = dst_elm; - } else if (as->hierarchy == SURF_ROUTING_RECURSIVE) { - onelink->src = route->gw_src; - onelink->dst = route->gw_dst; - } - xbt_dynar_push(ret, &onelink); - } - } - } - return ret; -} - -static void dijkstra_get_route_and_latency(AS_t asg, - sg_routing_edge_t src, sg_routing_edge_t dst, - sg_platf_route_cbarg_t route, double *lat) -{ - - /* set utils vars */ - as_dijkstra_t as = (as_dijkstra_t) asg; - - generic_src_dst_check(asg, src, dst); - int *src_id = &(src->id); - int *dst_id = &(dst->id); - - if (!src_id || !dst_id) - THROWF(arg_error,0,"No route from '%s' to '%s'",src->name,dst->name); - - int *pred_arr = NULL; - int src_node_id = 0; - int dst_node_id = 0; - int *nodeid = NULL; - int v; - sg_platf_route_cbarg_t e_route; - int size = 0; - unsigned int cpt; - void *link; - xbt_dynar_t links = NULL; - route_cache_element_t elm = NULL; - xbt_dynar_t nodes = xbt_graph_get_nodes(as->route_graph); - - /* Use the graph_node id mapping set to quickly find the nodes */ - graph_node_map_element_t src_elm = - graph_node_map_search(as, *src_id); - graph_node_map_element_t dst_elm = - graph_node_map_search(as, *dst_id); - - src_node_id = ((graph_node_data_t) - xbt_graph_node_get_data(src_elm->node))->graph_id; - dst_node_id = ((graph_node_data_t) - xbt_graph_node_get_data(dst_elm->node))->graph_id; - - /* if the src and dst are the same */ - if (src_node_id == dst_node_id) { - - xbt_node_t node_s_v = xbt_dynar_get_as(nodes, src_node_id, xbt_node_t); - xbt_node_t node_e_v = xbt_dynar_get_as(nodes, dst_node_id, xbt_node_t); - xbt_edge_t edge = - xbt_graph_get_edge(as->route_graph, node_s_v, node_e_v); - - if (edge == NULL) - THROWF(arg_error,0,"No route from '%s' to '%s'",src->name,dst->name); - - e_route = (sg_platf_route_cbarg_t) xbt_graph_edge_get_data(edge); - - links = e_route->link_list; - xbt_dynar_foreach(links, cpt, link) { - xbt_dynar_unshift(route->link_list, &link); - if (lat) - *lat += surf_network_model->extension.network.get_link_latency(link); - } - - } - - if (as->cached) { - /*check if there is a cached predecessor list avail */ - elm = (route_cache_element_t) - xbt_dict_get_or_null_ext(as->route_cache, (char *) (&src_id), - sizeof(int)); - } - - if (elm) { /* cached mode and cache hit */ - pred_arr = elm->pred_arr; - } else { /* not cached mode or cache miss */ - double *cost_arr = NULL; - xbt_heap_t pqueue = NULL; - int i = 0; - - int nr_nodes = xbt_dynar_length(nodes); - cost_arr = xbt_new0(double, nr_nodes); /* link cost from src to other hosts */ - pred_arr = xbt_new0(int, nr_nodes); /* predecessors in path from src */ - pqueue = xbt_heap_new(nr_nodes, xbt_free); - - /* initialize */ - cost_arr[src_node_id] = 0.0; - - for (i = 0; i < nr_nodes; i++) { - if (i != src_node_id) { - cost_arr[i] = DBL_MAX; - } - - pred_arr[i] = 0; - - /* initialize priority queue */ - nodeid = xbt_new0(int, 1); - *nodeid = i; - xbt_heap_push(pqueue, nodeid, cost_arr[i]); - - } - - /* apply dijkstra using the indexes from the graph's node array */ - while (xbt_heap_size(pqueue) > 0) { - int *v_id = xbt_heap_pop(pqueue); - xbt_node_t v_node = xbt_dynar_get_as(nodes, *v_id, xbt_node_t); - xbt_dynar_t out_edges = xbt_graph_node_get_outedges(v_node); - xbt_edge_t edge = NULL; - unsigned int cursor; - - xbt_dynar_foreach(out_edges, cursor, edge) { - xbt_node_t u_node = xbt_graph_edge_get_target(edge); - graph_node_data_t data = xbt_graph_node_get_data(u_node); - int u_id = data->graph_id; - sg_platf_route_cbarg_t tmp_e_route = (sg_platf_route_cbarg_t) xbt_graph_edge_get_data(edge); - int cost_v_u = (tmp_e_route->link_list)->used; /* count of links, old model assume 1 */ - - if (cost_v_u + cost_arr[*v_id] < cost_arr[u_id]) { - pred_arr[u_id] = *v_id; - cost_arr[u_id] = cost_v_u + cost_arr[*v_id]; - nodeid = xbt_new0(int, 1); - *nodeid = u_id; - xbt_heap_push(pqueue, nodeid, cost_arr[u_id]); - } - } - - /* free item popped from pqueue */ - xbt_free(v_id); - } - - xbt_free(cost_arr); - xbt_heap_free(pqueue); - } - - /* compose route path with links */ - sg_routing_edge_t gw_src = NULL, gw_dst, prev_gw_src, first_gw = NULL; - sg_routing_edge_t gw_dst_net_elm = NULL, prev_gw_src_net_elm = NULL; - - for (v = dst_node_id; v != src_node_id; v = pred_arr[v]) { - xbt_node_t node_pred_v = - xbt_dynar_get_as(nodes, pred_arr[v], xbt_node_t); - xbt_node_t node_v = xbt_dynar_get_as(nodes, v, xbt_node_t); - xbt_edge_t edge = - xbt_graph_get_edge(as->route_graph, node_pred_v, node_v); - - if (edge == NULL) - THROWF(arg_error,0,"No route from '%s' to '%s'",src->name,dst->name); - - prev_gw_src = gw_src; - - e_route = (sg_platf_route_cbarg_t) xbt_graph_edge_get_data(edge); - gw_src = e_route->gw_src; - gw_dst = e_route->gw_dst; - - if (v == dst_node_id) - first_gw = gw_dst; - - if (asg->hierarchy == SURF_ROUTING_RECURSIVE && v != dst_node_id - && strcmp(gw_dst->name, prev_gw_src->name)) { - xbt_dynar_t e_route_as_to_as=NULL; - routing_get_route_and_latency(gw_dst_net_elm, prev_gw_src_net_elm, &e_route_as_to_as, NULL); - if (edge == NULL) - THROWF(arg_error,0,"No route from '%s' to '%s'",src->name,dst->name); - links = e_route_as_to_as; - int pos = 0; - xbt_dynar_foreach(links, cpt, link) { - xbt_dynar_insert_at(route->link_list, pos, &link); - if (lat) - *lat += surf_network_model->extension.network.get_link_latency(link); - pos++; - } - } - - links = e_route->link_list; - xbt_dynar_foreach(links, cpt, link) { - xbt_dynar_unshift(route->link_list, &link); - if (lat) - *lat += surf_network_model->extension.network.get_link_latency(link); - } - size++; - } - - if (asg->hierarchy == SURF_ROUTING_RECURSIVE) { - route->gw_src = gw_src; - route->gw_dst = first_gw; - } - - if (as->cached && elm == NULL) { - /* add to predecessor list of the current src-host to cache */ - elm = xbt_new0(struct route_cache_element, 1); - elm->pred_arr = pred_arr; - elm->size = size; - xbt_dict_set_ext(as->route_cache, (char *) (&src_id), sizeof(int), - (xbt_set_elm_t) elm, NULL); - } - - if (!as->cached) - xbt_free(pred_arr); -} - -static void dijkstra_finalize(AS_t asg) -{ - as_dijkstra_t as = (as_dijkstra_t) asg; - - xbt_graph_free_graph(as->route_graph, &xbt_free, - &graph_edge_data_free, &xbt_free); - xbt_dict_free(&as->graph_node_map); - if (as->cached) - xbt_dict_free(&as->route_cache); - - model_generic_finalize(asg); -} - -/* Creation routing model functions */ - -AS_t model_dijkstra_both_create(int cached) -{ - as_dijkstra_t new_component = (as_dijkstra_t) - model_generic_create_sized(sizeof(s_as_dijkstra_t)); - - new_component->generic_routing.parse_route = model_dijkstra_both_parse_route; - new_component->generic_routing.parse_ASroute = model_dijkstra_both_parse_route; - new_component->generic_routing.get_route_and_latency = dijkstra_get_route_and_latency; - new_component->generic_routing.get_onelink_routes = - dijkstra_get_onelink_routes; - new_component->generic_routing.get_graph = generic_get_graph; - new_component->generic_routing.finalize = dijkstra_finalize; - new_component->cached = cached; - - return (AS_t)new_component; -} - -AS_t model_dijkstra_create(void) -{ - return model_dijkstra_both_create(0); -} - -AS_t model_dijkstracache_create(void) -{ - return model_dijkstra_both_create(1); -} - -void model_dijkstra_both_end(AS_t as) -{ - as_dijkstra_t THIS_AS = (as_dijkstra_t) as; - - xbt_node_t node = NULL; - unsigned int cursor2; - xbt_dynar_t nodes = NULL; - - /* Create the topology graph */ - if(!THIS_AS->route_graph) - THIS_AS->route_graph = xbt_graph_new_graph(1, NULL); - if(!THIS_AS->graph_node_map) - THIS_AS->graph_node_map = xbt_dict_new_homogeneous(&graph_node_map_elem_free); - - if (THIS_AS->cached && !THIS_AS->route_cache) - THIS_AS->route_cache = xbt_dict_new_homogeneous(&route_cache_elem_free); - - /* Add the loopback if needed */ - if (routing_platf->loopback && as->hierarchy == SURF_ROUTING_BASE) - add_loopback_dijkstra(THIS_AS); - - /* initialize graph indexes in nodes after graph has been built */ - nodes = xbt_graph_get_nodes(THIS_AS->route_graph); - - xbt_dynar_foreach(nodes, cursor2, node) { - graph_node_data_t data = xbt_graph_node_get_data(node); - data->graph_id = cursor2; - } - -} -void model_dijkstra_both_parse_route (AS_t asg, sg_platf_route_cbarg_t route) -{ - char *src = (char*)(route->src); - char *dst = (char*)(route->dst); - - int as_route = 0; - if(!route->gw_dst && !route->gw_src) - XBT_DEBUG("Load Route from \"%s\" to \"%s\"", src, dst); - else{ - XBT_DEBUG("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", src, - route->gw_src->name, dst, route->gw_dst->name); - as_route = 1; - if(route->gw_dst->rc_type == SURF_NETWORK_ELEMENT_NULL) - xbt_die("The gw_dst '%s' does not exist!",route->gw_dst->name); - if(route->gw_src->rc_type == SURF_NETWORK_ELEMENT_NULL) - xbt_die("The gw_src '%s' does not exist!",route->gw_src->name); - } - - as_dijkstra_t as = (as_dijkstra_t) asg; - sg_routing_edge_t src_net_elm, dst_net_elm; - - src_net_elm = sg_routing_edge_by_name_or_null(src); - dst_net_elm = sg_routing_edge_by_name_or_null(dst); - - xbt_assert(src_net_elm, "Network elements %s not found", src); - xbt_assert(dst_net_elm, "Network elements %s not found", dst); - - /* Create the topology graph */ - if(!as->route_graph) - as->route_graph = xbt_graph_new_graph(1, NULL); - if(!as->graph_node_map) - as->graph_node_map = xbt_dict_new_homogeneous(&graph_node_map_elem_free); - - if (as->cached && !as->route_cache) - as->route_cache = xbt_dict_new_homogeneous(&route_cache_elem_free); - - sg_platf_route_cbarg_t e_route = generic_new_extended_route(asg->hierarchy, route, 1); - route_new_dijkstra(as, src_net_elm->id, dst_net_elm->id, e_route); - - // Symmetrical YES - if ( (route->symmetrical == TRUE && as_route == 0) - || (route->symmetrical == TRUE && as_route == 1) - ) - { - if(!route->gw_dst && !route->gw_src) - XBT_DEBUG("Load Route from \"%s\" to \"%s\"", dst, src); - else - XBT_DEBUG("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", dst, - route->gw_dst->name, src, route->gw_src->name); - - xbt_dynar_t nodes = xbt_graph_get_nodes(as->route_graph); - xbt_node_t node_s_v = xbt_dynar_get_as(nodes, src_net_elm->id, xbt_node_t); - xbt_node_t node_e_v = xbt_dynar_get_as(nodes, dst_net_elm->id, xbt_node_t); - xbt_edge_t edge = - xbt_graph_get_edge(as->route_graph, node_e_v, node_s_v); - - if (edge) - THROWF(arg_error,0,"(AS)Route from '%s' to '%s' already exists",src,dst); - - if (route->gw_dst && route->gw_src) { - sg_routing_edge_t gw_tmp; - gw_tmp = route->gw_src; - route->gw_src = route->gw_dst; - route->gw_dst = gw_tmp; - } - sg_platf_route_cbarg_t link_route_back = generic_new_extended_route(asg->hierarchy, route, 0); - route_new_dijkstra(as, dst_net_elm->id, src_net_elm->id, link_route_back); - } - xbt_dynar_free(&route->link_list); -} diff --git a/src/surf/surf_routing_floyd.c b/src/surf/surf_routing_floyd.c deleted file mode 100644 index b7160b15d5..0000000000 --- a/src/surf/surf_routing_floyd.c +++ /dev/null @@ -1,345 +0,0 @@ -/* Copyright (c) 2009, 2010, 2011. The SimGrid Team. - * All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ - -#include "surf_routing_private.h" - -/* Global vars */ -extern routing_platf_t routing_platf; - -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_floyd, surf, "Routing part of surf"); - -#define TO_FLOYD_COST(i,j) (as->cost_table)[(i)+(j)*table_size] -#define TO_FLOYD_PRED(i,j) (as->predecessor_table)[(i)+(j)*table_size] -#define TO_FLOYD_LINK(i,j) (as->link_table)[(i)+(j)*table_size] - -/* Routing model structure */ - -typedef struct { - s_as_t generic_routing; - /* vars for calculate the floyd algorith. */ - int *predecessor_table; - double *cost_table; - sg_platf_route_cbarg_t *link_table; -} s_as_floyd_t, *as_floyd_t; - -static void floyd_get_route_and_latency(AS_t asg, sg_routing_edge_t src, sg_routing_edge_t dst, - sg_platf_route_cbarg_t res, double *lat); - -/* Business methods */ -static xbt_dynar_t floyd_get_onelink_routes(AS_t asg) -{ - xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free); - sg_platf_route_cbarg_t route = xbt_new0(s_sg_platf_route_cbarg_t, 1); - route->link_list = xbt_dynar_new(sizeof(sg_routing_link_t), NULL); - - int src,dst; - sg_routing_edge_t src_elm, dst_elm; - int table_size = xbt_dynar_length(asg->index_network_elm); - for(src=0; src < table_size; src++) { - for(dst=0; dst< table_size; dst++) { - xbt_dynar_reset(route->link_list); - src_elm = xbt_dynar_get_as(asg->index_network_elm,src,sg_routing_edge_t); - dst_elm = xbt_dynar_get_as(asg->index_network_elm,dst,sg_routing_edge_t); - floyd_get_route_and_latency(asg, src_elm, dst_elm, route, NULL); - - if (xbt_dynar_length(route->link_list) == 1) { - void *link = *(void **) xbt_dynar_get_ptr(route->link_list, 0); - onelink_t onelink = xbt_new0(s_onelink_t, 1); - onelink->link_ptr = link; - if (asg->hierarchy == SURF_ROUTING_BASE) { - onelink->src = src_elm; - onelink->dst = dst_elm; - } else if (asg->hierarchy == SURF_ROUTING_RECURSIVE) { - onelink->src = route->gw_src; - onelink->dst = route->gw_dst; - } - xbt_dynar_push(ret, &onelink); - } - } - } - - return ret; -} - -static void floyd_get_route_and_latency(AS_t asg, sg_routing_edge_t src, sg_routing_edge_t dst, - sg_platf_route_cbarg_t res, double *lat) -{ - - /* set utils vars */ - as_floyd_t as = (as_floyd_t)asg; - size_t table_size = xbt_dynar_length(asg->index_network_elm); - - generic_src_dst_check(asg, src, dst); - - /* create a result route */ - xbt_dynar_t route_stack = xbt_dynar_new(sizeof(sg_platf_route_cbarg_t), NULL); - int pred; - int cur = dst->id; - do { - pred = TO_FLOYD_PRED(src->id, cur); - if (pred == -1) - THROWF(arg_error, 0, "No route from '%s' to '%s'", src->name, dst->name); - xbt_dynar_push_as(route_stack, sg_platf_route_cbarg_t, TO_FLOYD_LINK(pred, cur)); - cur = pred; - } while (cur != src->id); - - if (asg->hierarchy == SURF_ROUTING_RECURSIVE) { - res->gw_src = xbt_dynar_getlast_as(route_stack, sg_platf_route_cbarg_t)->gw_src; - res->gw_dst = xbt_dynar_getfirst_as(route_stack, sg_platf_route_cbarg_t)->gw_dst; - } - - sg_routing_edge_t prev_dst_gw = NULL; - while (!xbt_dynar_is_empty(route_stack)) { - sg_platf_route_cbarg_t e_route = xbt_dynar_pop_as(route_stack, sg_platf_route_cbarg_t); - xbt_dynar_t links; - sg_routing_link_t link; - unsigned int cpt; - - if (asg->hierarchy == SURF_ROUTING_RECURSIVE && prev_dst_gw != NULL - && strcmp(prev_dst_gw->name, e_route->gw_src->name)) { - routing_get_route_and_latency(prev_dst_gw, e_route->gw_src, - &res->link_list, lat); - } - - links = e_route->link_list; - xbt_dynar_foreach(links, cpt, link) { - xbt_dynar_push_as(res->link_list, sg_routing_link_t, link); - if (lat) - *lat += surf_network_model->extension.network.get_link_latency(link); - } - - prev_dst_gw = e_route->gw_dst; - } - xbt_dynar_free(&route_stack); -} - -static void floyd_finalize(AS_t rc) -{ - as_floyd_t as = (as_floyd_t) rc; - int i, j; - size_t table_size; - if (as) { - table_size = xbt_dynar_length(as->generic_routing.index_network_elm); - /* Delete link_table */ - for (i = 0; i < table_size; i++) - for (j = 0; j < table_size; j++) - generic_free_route(TO_FLOYD_LINK(i, j)); - xbt_free(as->link_table); - /* Delete bypass dict */ - xbt_dict_free(&as->generic_routing.bypassRoutes); - /* Delete predecessor and cost table */ - xbt_free(as->predecessor_table); - xbt_free(as->cost_table); - - model_generic_finalize(rc); - } -} - -AS_t model_floyd_create(void) -{ - as_floyd_t new_component = (as_floyd_t)model_generic_create_sized(sizeof(s_as_floyd_t)); - new_component->generic_routing.parse_route = model_floyd_parse_route; - new_component->generic_routing.parse_ASroute = model_floyd_parse_route; - new_component->generic_routing.get_route_and_latency = floyd_get_route_and_latency; - new_component->generic_routing.get_onelink_routes = - floyd_get_onelink_routes; - new_component->generic_routing.get_graph = generic_get_graph; - new_component->generic_routing.finalize = floyd_finalize; - return (AS_t)new_component; -} - -void model_floyd_end(AS_t current_routing) -{ - - as_floyd_t as = - ((as_floyd_t) current_routing); - - unsigned int i, j, a, b, c; - - /* set the size of table routing */ - size_t table_size = xbt_dynar_length(as->generic_routing.index_network_elm); - - if(!as->link_table) - { - /* Create Cost, Predecessor and Link tables */ - as->cost_table = xbt_new0(double, table_size * table_size); /* link cost from host to host */ - as->predecessor_table = xbt_new0(int, table_size * table_size); /* predecessor host numbers */ - as->link_table = xbt_new0(sg_platf_route_cbarg_t, table_size * table_size); /* actual link between src and dst */ - - /* Initialize costs and predecessors */ - for (i = 0; i < table_size; i++) - for (j = 0; j < table_size; j++) { - TO_FLOYD_COST(i, j) = DBL_MAX; - TO_FLOYD_PRED(i, j) = -1; - TO_FLOYD_LINK(i, j) = NULL; /* fixed, missing in the previous version */ - } - } - - /* Add the loopback if needed */ - if (routing_platf->p_loopback && current_routing->p_hierarchy == SURF_ROUTING_BASE) { - for (i = 0; i < table_size; i++) { - sg_platf_route_cbarg_t e_route = TO_FLOYD_LINK(i, i); - if (!e_route) { - e_route = xbt_new0(s_sg_platf_route_cbarg_t, 1); - e_route->gw_src = NULL; - e_route->gw_dst = NULL; - e_route->link_list = xbt_dynar_new(sizeof(sg_routing_link_t), NULL); - xbt_dynar_push(e_route->link_list, &routing_platf->p_loopback); - TO_FLOYD_LINK(i, i) = e_route; - TO_FLOYD_PRED(i, i) = i; - TO_FLOYD_COST(i, i) = 1; - } - } - } - /* Calculate path costs */ - for (c = 0; c < table_size; c++) { - for (a = 0; a < table_size; a++) { - for (b = 0; b < table_size; b++) { - if (TO_FLOYD_COST(a, c) < DBL_MAX && TO_FLOYD_COST(c, b) < DBL_MAX) { - if (TO_FLOYD_COST(a, b) == DBL_MAX || - (TO_FLOYD_COST(a, c) + TO_FLOYD_COST(c, b) < - TO_FLOYD_COST(a, b))) { - TO_FLOYD_COST(a, b) = - TO_FLOYD_COST(a, c) + TO_FLOYD_COST(c, b); - TO_FLOYD_PRED(a, b) = TO_FLOYD_PRED(c, b); - } - } - } - } - } -} - -static int floyd_pointer_resource_cmp(const void *a, const void *b) { - return a != b; -} - -//FIXME: kill dupplicates in next function with full routing - -void model_floyd_parse_route(AS_t rc, sg_platf_route_cbarg_t route) -{ - char *src = (char*)(route->src); - char *dst = (char*)(route->dst); - - int as_route = 0; - as_floyd_t as = (as_floyd_t) rc; - - /* set the size of table routing */ - size_t table_size = xbt_dynar_length(rc->index_network_elm); - sg_routing_edge_t src_net_elm, dst_net_elm; - - src_net_elm = sg_routing_edge_by_name_or_null(src); - dst_net_elm = sg_routing_edge_by_name_or_null(dst); - - xbt_assert(src_net_elm, "Network elements %s not found", src); - xbt_assert(dst_net_elm, "Network elements %s not found", dst); - - if(!as->link_table) - { - int i,j; - /* Create Cost, Predecessor and Link tables */ - as->cost_table = xbt_new0(double, table_size * table_size); /* link cost from host to host */ - as->predecessor_table = xbt_new0(int, table_size * table_size); /* predecessor host numbers */ - as->link_table = xbt_new0(sg_platf_route_cbarg_t, table_size * table_size); /* actual link between src and dst */ - - /* Initialize costs and predecessors */ - for (i = 0; i < table_size; i++) - for (j = 0; j < table_size; j++) { - TO_FLOYD_COST(i, j) = DBL_MAX; - TO_FLOYD_PRED(i, j) = -1; - TO_FLOYD_LINK(i, j) = NULL; /* fixed, missing in the previous version */ - } - } - if(!route->gw_dst && !route->gw_src) - XBT_DEBUG("Load Route from \"%s\" to \"%s\"", src, dst); - else{ - as_route = 1; - XBT_DEBUG("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", src, - route->gw_src->name, dst, route->gw_dst->name); - if(route->gw_dst->rc_type == SURF_NETWORK_ELEMENT_NULL) - xbt_die("The dst_gateway '%s' does not exist!",route->gw_dst->name); - if(route->gw_src->rc_type == SURF_NETWORK_ELEMENT_NULL) - xbt_die("The src_gateway '%s' does not exist!",route->gw_src->name); - } - - if(TO_FLOYD_LINK(src_net_elm->id, dst_net_elm->id)) - { - - char * link_name; - unsigned int cpt; - xbt_dynar_t link_route_to_test = xbt_dynar_new(sizeof(sg_routing_link_t), NULL); - xbt_dynar_foreach(route->link_list,cpt,link_name) - { - void *link = xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL); - xbt_assert(link,"Link : '%s' doesn't exists.",link_name); - xbt_dynar_push(link_route_to_test,&link); - } - xbt_assert(!xbt_dynar_compare( - (void*)TO_FLOYD_LINK(src_net_elm->id, dst_net_elm->id)->link_list, - (void*)link_route_to_test, - (int_f_cpvoid_cpvoid_t) floyd_pointer_resource_cmp), - "The route between \"%s\" and \"%s\" already exists", src,dst); - } - else - { - TO_FLOYD_LINK(src_net_elm->id, dst_net_elm->id) = - generic_new_extended_route(rc->hierarchy, route, 1); - TO_FLOYD_PRED(src_net_elm->id, dst_net_elm->id) = src_net_elm->id; - TO_FLOYD_COST(src_net_elm->id, dst_net_elm->id) = - ((TO_FLOYD_LINK(src_net_elm->id, dst_net_elm->id))->link_list)->used; /* count of links, old model assume 1 */ - } - - if ( (route->symmetrical == TRUE && as_route == 0) - || (route->symmetrical == TRUE && as_route == 1) - ) - { - if(TO_FLOYD_LINK(dst_net_elm->id, src_net_elm->id)) - { - if(!route->gw_dst && !route->gw_src) - XBT_DEBUG("See Route from \"%s\" to \"%s\"", dst, src); - else - XBT_DEBUG("See ASroute from \"%s(%s)\" to \"%s(%s)\"", dst, - route->gw_src->name, src, route->gw_dst->name); - char * link_name; - unsigned int i; - xbt_dynar_t link_route_to_test = xbt_dynar_new(sizeof(sg_routing_link_t), NULL); - for(i=xbt_dynar_length(route->link_list) ;i>0 ;i--) - { - link_name = xbt_dynar_get_as(route->link_list,i-1,void *); - void *link = xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL); - xbt_assert(link,"Link : '%s' doesn't exists.",link_name); - xbt_dynar_push(link_route_to_test,&link); - } - xbt_assert(!xbt_dynar_compare( - (void*)TO_FLOYD_LINK(dst_net_elm->id, src_net_elm->id)->link_list, - (void*)link_route_to_test, - (int_f_cpvoid_cpvoid_t) floyd_pointer_resource_cmp), - "The route between \"%s\" and \"%s\" already exists", src,dst); - } - else - { - if(route->gw_dst && route->gw_src) - { - sg_routing_edge_t gw_src = route->gw_src; - sg_routing_edge_t gw_dst = route->gw_dst; - route->gw_src = gw_dst; - route->gw_dst = gw_src; - } - - if(!route->gw_src && !route->gw_dst) - XBT_DEBUG("Load Route from \"%s\" to \"%s\"", dst, src); - else - XBT_DEBUG("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", dst, - route->gw_src->name, src, route->gw_dst->name); - - TO_FLOYD_LINK(dst_net_elm->id, src_net_elm->id) = - generic_new_extended_route(rc->hierarchy, route, 0); - TO_FLOYD_PRED(dst_net_elm->id, src_net_elm->id) = dst_net_elm->id; - TO_FLOYD_COST(dst_net_elm->id, src_net_elm->id) = - ((TO_FLOYD_LINK(dst_net_elm->id, src_net_elm->id))->link_list)->used; /* count of links, old model assume 1 */ - } - } - xbt_dynar_free(&route->link_list); -} diff --git a/src/surf/surf_routing_full.c b/src/surf/surf_routing_full.c deleted file mode 100644 index 0fb34221c7..0000000000 --- a/src/surf/surf_routing_full.c +++ /dev/null @@ -1,284 +0,0 @@ -/* Copyright (c) 2009, 2010, 2011. The SimGrid Team. - * All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ - -#include "surf_routing_private.h" - -/* Global vars */ -extern routing_platf_t routing_platf; -extern int surf_parse_lineno; - -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_full, surf, "Routing part of surf"); - -#define TO_ROUTE_FULL(i,j) routing->routing_table[(i)+(j)*table_size] - -/* Routing model structure */ - -typedef struct s_routing_component_full { - s_as_t generic_routing; - sg_platf_route_cbarg_t *routing_table; -} s_routing_component_full_t, *routing_component_full_t; - -/* Business methods */ -static xbt_dynar_t full_get_onelink_routes(AS_t rc) -{ - xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free); - routing_component_full_t routing = (routing_component_full_t) rc; - - int src,dst; - int table_size = xbt_dynar_length(rc->index_network_elm); - - for(src=0; src < table_size; src++) { - for(dst=0; dst< table_size; dst++) { - sg_platf_route_cbarg_t route = TO_ROUTE_FULL(src, dst); - if (route) { - if (xbt_dynar_length(route->link_list) == 1) { - void *link = *(void **) xbt_dynar_get_ptr(route->link_list, 0); - onelink_t onelink = xbt_new0(s_onelink_t, 1); - onelink->link_ptr = link; - if (rc->hierarchy == SURF_ROUTING_BASE) { - onelink->src = xbt_dynar_get_as(rc->index_network_elm,src,sg_routing_edge_t); - onelink->src->id = src; - onelink->dst = xbt_dynar_get_as(rc->index_network_elm,dst,sg_routing_edge_t); - onelink->dst->id = dst; - } else if (rc->hierarchy == SURF_ROUTING_RECURSIVE) { - onelink->src = route->gw_src; - onelink->dst = route->gw_dst; - } - xbt_dynar_push(ret, &onelink); - XBT_DEBUG("Push route from '%d' to '%d'", - src, - dst); - } - } - } - } - return ret; -} - -static void full_get_route_and_latency(AS_t rc, - sg_routing_edge_t src, sg_routing_edge_t dst, - sg_platf_route_cbarg_t res, double *lat) -{ - XBT_DEBUG("full_get_route_and_latency from %s[%d] to %s[%d]", - src->name, - src->id, - dst->name, - dst->id ); - - /* set utils vars */ - routing_component_full_t routing = (routing_component_full_t) rc; - size_t table_size = xbt_dynar_length(routing->generic_routing.index_network_elm); - - sg_platf_route_cbarg_t e_route = NULL; - void *link; - unsigned int cpt = 0; - - e_route = TO_ROUTE_FULL(src->id, dst->id); - - if (e_route) { - res->gw_src = e_route->gw_src; - res->gw_dst = e_route->gw_dst; - xbt_dynar_foreach(e_route->link_list, cpt, link) { - xbt_dynar_push(res->link_list, &link); - if (lat) - *lat += surf_network_model->extension.network.get_link_latency(link); - } - } -} - -static void full_finalize(AS_t rc) -{ - routing_component_full_t routing = (routing_component_full_t) rc; - size_t table_size = xbt_dynar_length(routing->generic_routing.index_network_elm); - int i, j; - if (routing) { - /* Delete routing table */ - for (i = 0; i < table_size; i++) - for (j = 0; j < table_size; j++) - generic_free_route(TO_ROUTE_FULL(i, j)); - xbt_free(routing->routing_table); - model_generic_finalize(rc); - } -} - -/* Creation routing model functions */ - -AS_t model_full_create(void) -{ - routing_component_full_t new_component = (routing_component_full_t) - model_generic_create_sized(sizeof(s_routing_component_full_t)); - - new_component->generic_routing.parse_route = model_full_set_route; - new_component->generic_routing.parse_ASroute = model_full_set_route; - new_component->generic_routing.get_route_and_latency = - full_get_route_and_latency; - new_component->generic_routing.get_graph = generic_get_graph; - - new_component->generic_routing.get_onelink_routes = full_get_onelink_routes; - new_component->generic_routing.finalize = full_finalize; - - return (AS_t) new_component; -} - -void model_full_end(AS_t current_routing) -{ - unsigned int i; - sg_platf_route_cbarg_t e_route; - - /* set utils vars */ - routing_component_full_t routing = - ((routing_component_full_t) current_routing); - size_t table_size = xbt_dynar_length(routing->generic_routing.index_network_elm); - - /* Create table if necessary */ - if (!routing->routing_table) - routing->routing_table = xbt_new0(sg_platf_route_cbarg_t, table_size * table_size); - - /* Add the loopback if needed */ - if (routing_platf->loopback && current_routing->hierarchy == SURF_ROUTING_BASE) { - for (i = 0; i < table_size; i++) { - e_route = TO_ROUTE_FULL(i, i); - if (!e_route) { - e_route = xbt_new0(s_sg_platf_route_cbarg_t, 1); - e_route->gw_src = NULL; - e_route->gw_dst = NULL; - e_route->link_list = xbt_dynar_new(sizeof(sg_routing_link_t), NULL); - xbt_dynar_push(e_route->link_list, &routing_platf->loopback); - TO_ROUTE_FULL(i, i) = e_route; - } - } - } -} - -static int full_pointer_resource_cmp(const void *a, const void *b) -{ - return a != b; -} - -void model_full_set_route(AS_t rc, sg_platf_route_cbarg_t route) -{ - int as_route = 0; - char *src = (char*)(route->src); - char *dst = (char*)(route->dst); - sg_routing_edge_t src_net_elm, dst_net_elm; - src_net_elm = sg_routing_edge_by_name_or_null(src); - dst_net_elm = sg_routing_edge_by_name_or_null(dst); - - xbt_assert(src_net_elm, "Network elements %s not found", src); - xbt_assert(dst_net_elm, "Network elements %s not found", dst); - - routing_component_full_t routing = (routing_component_full_t) rc; - size_t table_size = xbt_dynar_length(routing->generic_routing.index_network_elm); - - xbt_assert(!xbt_dynar_is_empty(route->link_list), - "Invalid count of links, must be greater than zero (%s,%s)", - src, dst); - - if (!routing->routing_table) - routing->routing_table = xbt_new0(sg_platf_route_cbarg_t, table_size * table_size); - - if (TO_ROUTE_FULL(src_net_elm->id, dst_net_elm->id)) { - char *link_name; - unsigned int i; - xbt_dynar_t link_route_to_test = - xbt_dynar_new(sizeof(sg_routing_link_t), NULL); - xbt_dynar_foreach(route->link_list, i, link_name) { - void *link = xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL); - xbt_assert(link, "Link : '%s' doesn't exists.", link_name); - xbt_dynar_push(link_route_to_test, &link); - } - if (xbt_dynar_compare(TO_ROUTE_FULL(src_net_elm->id, dst_net_elm->id)->link_list, - link_route_to_test, full_pointer_resource_cmp)) { - surf_parse_error("A route between \"%s\" and \"%s\" already exists " - "with a different content. " - "If you are trying to define a reverse route, " - "you must set the symmetrical=no attribute to " - "your routes tags.", src, dst); - } else { - surf_parse_warn("Ignoring the identical redefinition of the route " - "between \"%s\" and \"%s\"", src, dst); - } - } else { - if (!route->gw_dst && !route->gw_dst) - XBT_DEBUG("Load Route from \"%s\" to \"%s\"", src, dst); - else { - // FIXME We can call a gw which is down the current AS (cf g5k.xml) but not upper. - // AS_t subas = xbt_dict_get_or_null(rc->routing_sons, src); - // if (subas == NULL) - // surf_parse_error("The source of an ASroute must be a sub-AS " - // "declared within the current AS, " - // "but '%s' is not an AS within '%s'", src, rc->name); - // if (subas->to_index - // && xbt_dict_get_or_null(subas->to_index, route->src_gateway) == NULL) - // surf_parse_error("In an ASroute, source gateway must be part of " - // "the source sub-AS (in particular, being in a " - // "sub-sub-AS is not allowed), " - // "but '%s' is not in '%s'.", - // route->src_gateway, subas->name); - // - // subas = xbt_dict_get_or_null(rc->routing_sons, dst); - // if (subas == NULL) - // surf_parse_error("The destination of an ASroute must be a sub-AS " - // "declared within the current AS, " - // "but '%s' is not an AS within '%s'", dst, rc->name); - // if (subas->to_index - // && xbt_dict_get_or_null(subas->to_index, route->dst_gateway) == NULL) - // surf_parse_error("In an ASroute, destination gateway must be " - // "part of the destination sub-AS (in particular, " - // "in a sub-sub-AS is not allowed), " - // "but '%s' is not in '%s'.", - // route->dst_gateway, subas->name); - as_route = 1; - XBT_DEBUG("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", - src, route->gw_src->name, dst, route->gw_dst->name); - if (route->gw_dst->rc_type == SURF_NETWORK_ELEMENT_NULL) - xbt_die("The dst_gateway '%s' does not exist!", route->gw_dst->name); - if (route->gw_src->rc_type == SURF_NETWORK_ELEMENT_NULL) - xbt_die("The src_gateway '%s' does not exist!", route->gw_src->name); - } - TO_ROUTE_FULL(src_net_elm->id, dst_net_elm->id) = - generic_new_extended_route(rc->hierarchy, route, 1); - xbt_dynar_shrink(TO_ROUTE_FULL(src_net_elm->id, dst_net_elm->id)->link_list, 0); - } - - if ( (route->symmetrical == TRUE && as_route == 0) - || (route->symmetrical == TRUE && as_route == 1) - ) { - if (route->gw_dst && route->gw_src) { - sg_routing_edge_t gw_tmp; - gw_tmp = route->gw_src; - route->gw_src = route->gw_dst; - route->gw_dst = gw_tmp; - } - if (TO_ROUTE_FULL(dst_net_elm->id, src_net_elm->id)) { - char *link_name; - unsigned int i; - xbt_dynar_t link_route_to_test = - xbt_dynar_new(sizeof(sg_routing_link_t), NULL); - for (i = xbt_dynar_length(route->link_list); i > 0; i--) { - link_name = xbt_dynar_get_as(route->link_list, i - 1, void *); - void *link = xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL); - xbt_assert(link, "Link : '%s' doesn't exists.", link_name); - xbt_dynar_push(link_route_to_test, &link); - } - xbt_assert(!xbt_dynar_compare(TO_ROUTE_FULL(dst_net_elm->id, src_net_elm->id)->link_list, - link_route_to_test, - full_pointer_resource_cmp), - "The route between \"%s\" and \"%s\" already exists", src, - dst); - } else { - if (!route->gw_dst && !route->gw_src) - XBT_DEBUG("Load Route from \"%s\" to \"%s\"", dst, src); - else - XBT_DEBUG("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", - dst, route->gw_src->name, src, route->gw_dst->name); - TO_ROUTE_FULL(dst_net_elm->id, src_net_elm->id) = - generic_new_extended_route(rc->hierarchy, route, 0); - xbt_dynar_shrink(TO_ROUTE_FULL(dst_net_elm->id, src_net_elm->id)->link_list, 0); - } - } - xbt_dynar_free(&route->link_list); -} diff --git a/src/surf/surf_routing_generic.c b/src/surf/surf_routing_generic.c deleted file mode 100644 index ea3726452b..0000000000 --- a/src/surf/surf_routing_generic.c +++ /dev/null @@ -1,477 +0,0 @@ -/* Copyright (c) 2009, 2010, 2011. The SimGrid Team. - * All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ - -#include "simgrid/platf_interface.h" // platform creation API internal interface - -#include "surf_routing_private.h" -#include "surf/surf_routing.h" -#include "surf/surfxml_parse_values.h" -#include "xbt/graph.h" - -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_routing_generic, surf_route, "Generic implementation of the surf routing"); - -static int no_bypassroute_declared = 1; - -AS_t model_generic_create_sized(size_t childsize) { - AS_t new_component = model_none_create_sized(childsize); - - new_component->parse_PU = generic_parse_PU; - new_component->parse_AS = generic_parse_AS; - new_component->parse_route = NULL; - new_component->parse_ASroute = NULL; - new_component->parse_bypassroute = generic_parse_bypassroute; - new_component->get_route_and_latency = NULL; - new_component->get_onelink_routes = NULL; - new_component->get_bypass_route = - generic_get_bypassroute; - new_component->finalize = model_generic_finalize; - new_component->bypassRoutes = xbt_dict_new_homogeneous((void (*)(void *)) generic_free_route); - - return new_component; -} -void model_generic_finalize(AS_t as) { - xbt_dict_free(&as->bypassRoutes); - model_none_finalize(as); -} - -int generic_parse_PU(AS_t as, sg_routing_edge_t elm) -{ - XBT_DEBUG("Load process unit \"%s\"", elm->name); - xbt_dynar_push_as(as->index_network_elm,sg_routing_edge_t,elm); - return xbt_dynar_length(as->index_network_elm)-1; -} - -int generic_parse_AS(AS_t as, sg_routing_edge_t elm) -{ - XBT_DEBUG("Load Autonomous system \"%s\"", elm->name); - xbt_dynar_push_as(as->index_network_elm,sg_routing_edge_t,elm); - return xbt_dynar_length(as->index_network_elm)-1; -} - -void generic_parse_bypassroute(AS_t rc, sg_platf_route_cbarg_t e_route) -{ - char *src = (char*)(e_route->src); - char *dst = (char*)(e_route->dst); - - if(e_route->gw_dst) - XBT_DEBUG("Load bypassASroute from \"%s\" to \"%s\"", src, dst); - else - XBT_DEBUG("Load bypassRoute from \"%s\" to \"%s\"", src, dst); - xbt_dict_t dict_bypassRoutes = rc->bypassRoutes; - char *route_name; - - route_name = bprintf("%s#%s", src, dst); - xbt_assert(!xbt_dynar_is_empty(e_route->link_list), - "Invalid count of links, must be greater than zero (%s,%s)", - src, dst); - xbt_assert(!xbt_dict_get_or_null(dict_bypassRoutes, route_name), - "The bypass route between \"%s\"(\"%s\") and \"%s\"(\"%s\") already exists", - src, e_route->gw_src->name, dst, e_route->gw_dst->name); - - sg_platf_route_cbarg_t new_e_route = NULL; - if(e_route->gw_dst) - new_e_route = generic_new_extended_route(SURF_ROUTING_RECURSIVE, e_route, 1); - else - new_e_route = generic_new_extended_route(SURF_ROUTING_BASE, e_route, 1); - - xbt_dynar_free(&(e_route->link_list)); - - xbt_dict_set(dict_bypassRoutes, route_name, new_e_route, NULL); - no_bypassroute_declared = 0; - xbt_free(route_name); -} - -/* ************************************************************************** */ -/* *********************** GENERIC BUSINESS METHODS ************************* */ - -xbt_dynar_t generic_get_onelink_routes(AS_t rc) { // FIXME: kill that stub - xbt_die("\"generic_get_onelink_routes\" not implemented yet"); - return NULL; -} - -static const char *instr_node_name(xbt_node_t node) -{ - void *data = xbt_graph_node_get_data(node); - char *str = (char *) data; - return str; -} - -xbt_node_t new_xbt_graph_node(xbt_graph_t graph, const char *name, - xbt_dict_t nodes) -{ - xbt_node_t ret = xbt_dict_get_or_null(nodes, name); - if (ret) - return ret; - - ret = xbt_graph_new_node(graph, xbt_strdup(name)); - xbt_dict_set(nodes, name, ret, NULL); - return ret; -} - -xbt_edge_t new_xbt_graph_edge(xbt_graph_t graph, xbt_node_t s, xbt_node_t d, - xbt_dict_t edges) -{ - xbt_edge_t ret; - - const char *sn = instr_node_name(s); - const char *dn = instr_node_name(d); - int len = strlen(sn) + strlen(dn) + 1; - char *name = (char *) xbt_malloc(len * sizeof(char)); - - - snprintf(name, len, "%s%s", sn, dn); - ret = xbt_dict_get_or_null(edges, name); - if (ret == NULL) { - snprintf(name, len, "%s%s", dn, sn); - ret = xbt_dict_get_or_null(edges, name); - } - - if (ret == NULL) { - ret = xbt_graph_new_edge(graph, s, d, NULL); - xbt_dict_set(edges, name, ret, NULL); - } - free(name); - return ret; -} - -void generic_get_graph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges, - AS_t rc) -{ - int src, dst; - int table_size = xbt_dynar_length(rc->index_network_elm); - - - for (src = 0; src < table_size; src++) { - sg_routing_edge_t my_src = - xbt_dynar_get_as(rc->index_network_elm, src, sg_routing_edge_t); - for (dst = 0; dst < table_size; dst++) { - if (src == dst) - continue; - sg_routing_edge_t my_dst = - xbt_dynar_get_as(rc->index_network_elm, dst, sg_routing_edge_t); - - sg_platf_route_cbarg_t route = xbt_new0(s_sg_platf_route_cbarg_t, 1); - route->link_list = xbt_dynar_new(sizeof(sg_routing_link_t), NULL); - - rc->get_route_and_latency(rc, my_src, my_dst, route, NULL); - - XBT_DEBUG ("get_route_and_latency %s -> %s", my_src->name, my_dst->name); - - unsigned int cpt; - void *link; - - xbt_node_t current, previous; - const char *previous_name, *current_name; - - if (route->gw_src) { - previous = new_xbt_graph_node(graph, route->gw_src->name, nodes); - previous_name = route->gw_src->name; - } else { - previous = new_xbt_graph_node(graph, my_src->name, nodes); - previous_name = my_src->name; - } - - xbt_dynar_foreach(route->link_list, cpt, link) { - char *link_name = ((surf_resource_t) link)->name; - current = new_xbt_graph_node(graph, link_name, nodes); - current_name = link_name; - new_xbt_graph_edge(graph, previous, current, edges); - XBT_DEBUG (" %s -> %s", previous_name, current_name); - previous = current; - previous_name = current_name; - } - - if (route->gw_dst) { - current = new_xbt_graph_node(graph, route->gw_dst->name, nodes); - current_name = route->gw_dst->name; - } else { - current = new_xbt_graph_node(graph, my_dst->name, nodes); - current_name = my_dst->name; - } - new_xbt_graph_edge(graph, previous, current, edges); - XBT_DEBUG (" %s -> %s", previous_name, current_name); - - xbt_dynar_free (&(route->link_list)); - xbt_free (route); - } - } -} - -sg_platf_route_cbarg_t generic_get_bypassroute(AS_t rc, sg_routing_edge_t src, - sg_routing_edge_t dst, - double *lat) -{ - // If never set a bypass route return NULL without any further computations - XBT_DEBUG("generic_get_bypassroute from %s to %s", src->name, dst->name); - if (no_bypassroute_declared) - return NULL; - - sg_platf_route_cbarg_t e_route_bypass = NULL; - xbt_dict_t dict_bypassRoutes = rc->bypassRoutes; - - if(dst->rc_component == rc && src->rc_component == rc ){ - char *route_name = bprintf("%s#%s", src->name, dst->name); - e_route_bypass = xbt_dict_get_or_null(dict_bypassRoutes, route_name); - if(e_route_bypass) - XBT_DEBUG("Find bypass route with %ld links",xbt_dynar_length(e_route_bypass->link_list)); - free(route_name); - } - else{ - AS_t src_as, dst_as; - int index_src, index_dst; - xbt_dynar_t path_src = NULL; - xbt_dynar_t path_dst = NULL; - AS_t current = NULL; - AS_t *current_src = NULL; - AS_t *current_dst = NULL; - - if (src == NULL || dst == NULL) - xbt_die("Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"", - src->name, dst->name, rc->name); - - src_as = src->rc_component; - dst_as = dst->rc_component; - - /* (2) find the path to the root routing component */ - path_src = xbt_dynar_new(sizeof(AS_t), NULL); - current = src_as; - while (current != NULL) { - xbt_dynar_push(path_src, ¤t); - current = current->routing_father; - } - path_dst = xbt_dynar_new(sizeof(AS_t), NULL); - current = dst_as; - while (current != NULL) { - xbt_dynar_push(path_dst, ¤t); - current = current->routing_father; - } - - /* (3) find the common father */ - index_src = path_src->used - 1; - index_dst = path_dst->used - 1; - current_src = xbt_dynar_get_ptr(path_src, index_src); - current_dst = xbt_dynar_get_ptr(path_dst, index_dst); - while (index_src >= 0 && index_dst >= 0 && *current_src == *current_dst) { - xbt_dynar_pop_ptr(path_src); - xbt_dynar_pop_ptr(path_dst); - index_src--; - index_dst--; - current_src = xbt_dynar_get_ptr(path_src, index_src); - current_dst = xbt_dynar_get_ptr(path_dst, index_dst); - } - - int max_index_src = path_src->used - 1; - int max_index_dst = path_dst->used - 1; - - int max_index = max(max_index_src, max_index_dst); - int i, max; - - for (max = 0; max <= max_index; max++) { - for (i = 0; i < max; i++) { - if (i <= max_index_src && max <= max_index_dst) { - char *route_name = bprintf("%s#%s", - (*(AS_t *) - (xbt_dynar_get_ptr(path_src, i)))->name, - (*(AS_t *) - (xbt_dynar_get_ptr(path_dst, max)))->name); - e_route_bypass = xbt_dict_get_or_null(dict_bypassRoutes, route_name); - xbt_free(route_name); - } - if (e_route_bypass) - break; - if (max <= max_index_src && i <= max_index_dst) { - char *route_name = bprintf("%s#%s", - (*(AS_t *) - (xbt_dynar_get_ptr(path_src, max)))->name, - (*(AS_t *) - (xbt_dynar_get_ptr(path_dst, i)))->name); - e_route_bypass = xbt_dict_get_or_null(dict_bypassRoutes, route_name); - xbt_free(route_name); - } - if (e_route_bypass) - break; - } - - if (e_route_bypass) - break; - - if (max <= max_index_src && max <= max_index_dst) { - char *route_name = bprintf("%s#%s", - (*(AS_t *) - (xbt_dynar_get_ptr(path_src, max)))->name, - (*(AS_t *) - (xbt_dynar_get_ptr(path_dst, max)))->name); - e_route_bypass = xbt_dict_get_or_null(dict_bypassRoutes, route_name); - xbt_free(route_name); - } - if (e_route_bypass) - break; - } - - xbt_dynar_free(&path_src); - xbt_dynar_free(&path_dst); - } - - sg_platf_route_cbarg_t new_e_route = NULL; - if (e_route_bypass) { - void *link; - unsigned int cpt = 0; - new_e_route = xbt_new0(s_sg_platf_route_cbarg_t, 1); - new_e_route->gw_src = e_route_bypass->gw_src; - new_e_route->gw_dst = e_route_bypass->gw_dst; - new_e_route->link_list = - xbt_dynar_new(sizeof(sg_routing_link_t), NULL); - xbt_dynar_foreach(e_route_bypass->link_list, cpt, link) { - xbt_dynar_push(new_e_route->link_list, &link); - if (lat) - *lat += surf_network_model->extension.network.get_link_latency(link); - } - } - - return new_e_route; -} - -/* ************************************************************************** */ -/* ************************* GENERIC AUX FUNCTIONS ************************** */ -/* change a route containing link names into a route containing link entities */ -sg_platf_route_cbarg_t -generic_new_extended_route(e_surf_routing_hierarchy_t hierarchy, - sg_platf_route_cbarg_t routearg, int change_order) { - - sg_platf_route_cbarg_t result; - char *link_name; - unsigned int cpt; - - result = xbt_new0(s_sg_platf_route_cbarg_t, 1); - result->link_list = xbt_dynar_new(sizeof(sg_routing_link_t), NULL); - - xbt_assert(hierarchy == SURF_ROUTING_BASE - || hierarchy == SURF_ROUTING_RECURSIVE, - "The hierarchy of this AS is neither BASIC nor RECURSIVE, I'm lost here."); - - if (hierarchy == SURF_ROUTING_RECURSIVE) { - - xbt_assert(routearg->gw_src && routearg->gw_dst, - "NULL is obviously a bad gateway"); - - /* remeber not erase the gateway names */ - result->gw_src = routearg->gw_src; - result->gw_dst = routearg->gw_dst; - } - - xbt_dynar_foreach(routearg->link_list, cpt, link_name) { - - void *link = xbt_lib_get_or_null(link_lib, link_name, SURF_LINK_LEVEL); - if (link) { - if (change_order) - xbt_dynar_push(result->link_list, &link); - else - xbt_dynar_unshift(result->link_list, &link); - } else - THROWF(mismatch_error, 0, "Link %s not found", link_name); - } - - return result; -} - -void generic_free_route(sg_platf_route_cbarg_t route) -{ - if (route) { - xbt_dynar_free(&route->link_list); - xbt_free(route); - } -} - -static AS_t generic_as_exist(AS_t find_from, - AS_t to_find) -{ - //return to_find; // FIXME: BYPASSERROR OF FOREACH WITH BREAK - xbt_dict_cursor_t cursor = NULL; - char *key; - int found = 0; - AS_t elem; - xbt_dict_foreach(find_from->routing_sons, cursor, key, elem) { - if (to_find == elem || generic_as_exist(elem, to_find)) { - found = 1; - break; - } - } - if (found) - return to_find; - return NULL; -} - -AS_t -generic_autonomous_system_exist(AS_t rc, char *element) -{ - //return rc; // FIXME: BYPASSERROR OF FOREACH WITH BREAK - AS_t element_as, result, elem; - xbt_dict_cursor_t cursor = NULL; - char *key; - element_as = ((sg_routing_edge_t) - xbt_lib_get_or_null(as_router_lib, element, - ROUTING_ASR_LEVEL))->rc_component; - result = ((AS_t) - 1); - if (element_as != rc) - result = generic_as_exist(rc, element_as); - - int found = 0; - if (result) { - xbt_dict_foreach(element_as->routing_sons, cursor, key, elem) { - found = !strcmp(elem->name, element); - if (found) - break; - } - if (found) - return element_as; - } - return NULL; -} - -AS_t -generic_processing_units_exist(AS_t rc, char *element) -{ - AS_t element_as; - element_as = ((sg_routing_edge_t) - xbt_lib_get_or_null(host_lib, - element, ROUTING_HOST_LEVEL))->rc_component; - if (element_as == rc) - return element_as; - return generic_as_exist(rc, element_as); -} - -void generic_src_dst_check(AS_t rc, sg_routing_edge_t src, - sg_routing_edge_t dst) -{ - - sg_routing_edge_t src_data = src; - sg_routing_edge_t dst_data = dst; - - if (src_data == NULL || dst_data == NULL) - xbt_die("Ask for route \"from\"(%s) or \"to\"(%s) no found at AS \"%s\"", - src->name, - dst->name, - rc->name); - - AS_t src_as = - (src_data)->rc_component; - AS_t dst_as = - (dst_data)->rc_component; - - if (src_as != dst_as) - xbt_die("The src(%s in %s) and dst(%s in %s) are in differents AS", - src->name, src_as->name, - dst->name, dst_as->name); - - if (rc != dst_as) - xbt_die - ("The routing component of src'%s' and dst'%s' is not the same as the network elements belong (%s?=%s?=%s)", - src->name, - dst->name, - src_as->name, - dst_as->name, - rc->name); -} diff --git a/src/surf/surf_routing_none.c b/src/surf/surf_routing_none.c deleted file mode 100644 index 1379bb7733..0000000000 --- a/src/surf/surf_routing_none.c +++ /dev/null @@ -1,76 +0,0 @@ -/* Copyright (c) 2009, 2010, 2011. The SimGrid Team. - * All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ - -#include "surf_routing_private.h" - -extern "C" { -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_none, surf, "Routing part of surf"); -} - -static xbt_dynar_t none_get_onelink_routes(AS_t rc) { - return NULL; -} - -static void none_get_route_and_latency(AS_t rc, sg_routing_edge_t src, sg_routing_edge_t dst, - sg_platf_route_cbarg_t res,double *lat) -{ - *lat = 0.0; -} - -static void none_get_graph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges, AS_t rc) -{ - XBT_INFO("No routing no graph"); -} - -static sg_platf_route_cbarg_t none_get_bypass_route(AS_t rc, - sg_routing_edge_t src, - sg_routing_edge_t dst, double *lat) { - return NULL; -} - -static int none_parse_PU(AS_t rc, sg_routing_edge_t elm) { - XBT_DEBUG("Load process unit \"%s\"", elm->name); - xbt_dynar_push_as(rc->index_network_elm,sg_routing_edge_t,elm); - /* don't care about PUs */ - return -1; -} - -static int none_parse_AS(AS_t rc, sg_routing_edge_t elm) { - XBT_DEBUG("Load Autonomous system \"%s\"", elm->name); - xbt_dynar_push_as(rc->index_network_elm,sg_routing_edge_t,elm); - /* even don't care about sub-ASes -- I'm as nihilist as an old punk*/ - return -1; -} - -/* Creation routing model functions */ -AS_t model_none_create() { - return model_none_create_sized(sizeof(s_as_t)); -} -AS_t model_none_create_sized(size_t childsize) { - AS_t new_component = xbt_malloc0(childsize); - new_component->parse_PU = none_parse_PU; - new_component->parse_AS = none_parse_AS; - new_component->parse_route = NULL; - new_component->parse_ASroute = NULL; - new_component->parse_bypassroute = NULL; - new_component->get_route_and_latency = none_get_route_and_latency; - new_component->get_onelink_routes = none_get_onelink_routes; - new_component->get_bypass_route = none_get_bypass_route; - new_component->finalize = model_none_finalize; - new_component->get_graph = none_get_graph; - new_component->routing_sons = xbt_dict_new_homogeneous(NULL); - new_component->index_network_elm = xbt_dynar_new(sizeof(char*),NULL); - - return new_component; -} - -void model_none_finalize(AS_t as) { - xbt_dict_free(&as->routing_sons); - xbt_dynar_free(&as->index_network_elm); - xbt_dynar_free(&as->link_up_down_list); - xbt_free(as); -} - diff --git a/src/surf/surf_routing_vivaldi.c b/src/surf/surf_routing_vivaldi.c deleted file mode 100644 index a7e0cce3e4..0000000000 --- a/src/surf/surf_routing_vivaldi.c +++ /dev/null @@ -1,111 +0,0 @@ -/* Copyright (c) 2009, 2010, 2011. The SimGrid Team. - * All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ -#include "surf_routing_private.h" - -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_vivaldi, surf, "Routing part of surf"); - -static XBT_INLINE double euclidean_dist_comp(int index, xbt_dynar_t src, xbt_dynar_t dst) { - double src_coord, dst_coord; - - src_coord = xbt_dynar_get_as(src, index, double); - dst_coord = xbt_dynar_get_as(dst, index, double); - - return (src_coord-dst_coord)*(src_coord-dst_coord); -} - -static void vivaldi_get_route_and_latency( - AS_t rc, sg_routing_edge_t src_p, sg_routing_edge_t dst_p, - sg_platf_route_cbarg_t route, double *lat) -{ - s_surf_parsing_link_up_down_t info; - - XBT_DEBUG("vivaldi_get_route_and_latency from '%s'[%d] '%s'[%d]",src_p->name,src_p->id,dst_p->name,dst_p->id); - char *src = (char*)src_p->name; - char *dst = (char*)dst_p->name; - - if(src_p->rc_type == SURF_NETWORK_ELEMENT_AS) { - route->gw_src = xbt_lib_get_or_null(as_router_lib,ROUTER_PEER(src),ROUTING_ASR_LEVEL); - route->gw_dst = xbt_lib_get_or_null(as_router_lib,ROUTER_PEER(dst),ROUTING_ASR_LEVEL); - } - - double euclidean_dist; - xbt_dynar_t src_ctn, dst_ctn; - char *tmp_src_name, *tmp_dst_name; - - if(src_p->rc_type == SURF_NETWORK_ELEMENT_HOST){ - tmp_src_name = HOST_PEER(src); - - if(rc->link_up_down_list){ - info = xbt_dynar_get_as(rc->link_up_down_list,src_p->id,s_surf_parsing_link_up_down_t); - if(info.link_up) { // link up - xbt_dynar_push_as(route->link_list,void*,info.link_up); - if (lat) - *lat += surf_network_model->extension.network.get_link_latency(info.link_up); - } - } - src_ctn = xbt_lib_get_or_null(host_lib, tmp_src_name, COORD_HOST_LEVEL); - if(!src_ctn ) src_ctn = xbt_lib_get_or_null(host_lib, src, COORD_HOST_LEVEL); - } - else if(src_p->rc_type == SURF_NETWORK_ELEMENT_ROUTER || src_p->rc_type == SURF_NETWORK_ELEMENT_AS){ - tmp_src_name = ROUTER_PEER(src); - src_ctn = xbt_lib_get_or_null(as_router_lib, tmp_src_name, COORD_ASR_LEVEL); - } - else{ - THROW_IMPOSSIBLE; - } - - if(dst_p->rc_type == SURF_NETWORK_ELEMENT_HOST){ - tmp_dst_name = HOST_PEER(dst); - - if(rc->link_up_down_list){ - info = xbt_dynar_get_as(rc->link_up_down_list,dst_p->id,s_surf_parsing_link_up_down_t); - if(info.link_down) { // link down - xbt_dynar_push_as(route->link_list,void*,info.link_down); - if (lat) - *lat += surf_network_model->extension.network.get_link_latency(info.link_down); - } - } - dst_ctn = xbt_lib_get_or_null(host_lib, tmp_dst_name, COORD_HOST_LEVEL); - if(!dst_ctn ) dst_ctn = xbt_lib_get_or_null(host_lib, dst, COORD_HOST_LEVEL); - } - else if(dst_p->rc_type == SURF_NETWORK_ELEMENT_ROUTER || dst_p->rc_type == SURF_NETWORK_ELEMENT_AS){ - tmp_dst_name = ROUTER_PEER(dst); - dst_ctn = xbt_lib_get_or_null(as_router_lib, tmp_dst_name, COORD_ASR_LEVEL); - } - else{ - THROW_IMPOSSIBLE; - } - - xbt_assert(src_ctn,"No coordinate found for element '%s'",tmp_src_name); - xbt_assert(dst_ctn,"No coordinate found for element '%s'",tmp_dst_name); - free(tmp_src_name); - free(tmp_dst_name); - - euclidean_dist = sqrt (euclidean_dist_comp(0,src_ctn,dst_ctn)+euclidean_dist_comp(1,src_ctn,dst_ctn)) - + fabs(xbt_dynar_get_as(src_ctn, 2, double))+fabs(xbt_dynar_get_as(dst_ctn, 2, double)); - - if (lat){ - XBT_DEBUG("Updating latency %f += %f",*lat,euclidean_dist); - *lat += euclidean_dist / 1000.0; //From .ms to .s - } -} - -static int vivaldi_parse_PU(AS_t rc, sg_routing_edge_t elm) { - XBT_DEBUG("Load process unit \"%s\"", elm->name); - xbt_dynar_push_as(rc->index_network_elm,sg_routing_edge_t,elm); - return xbt_dynar_length(rc->index_network_elm)-1; -} - -/* Creation routing model functions */ -AS_t model_vivaldi_create(void) -{ - AS_t new_component = model_generic_create_sized(sizeof *new_component); - - new_component->get_route_and_latency = vivaldi_get_route_and_latency; - new_component->parse_PU = vivaldi_parse_PU; - new_component->get_graph = generic_get_graph; - return new_component; -} diff --git a/src/surf/workstation.c b/src/surf/workstation.c deleted file mode 100644 index aec832a014..0000000000 --- a/src/surf/workstation.c +++ /dev/null @@ -1,496 +0,0 @@ -/* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team. - * All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ - -#include "xbt/ex.h" -#include "xbt/dict.h" -#include "portable.h" -#include "surf_private.h" -#include "storage_private.h" -#include "surf/surf_resource.h" -#include "simgrid/sg_config.h" - -typedef struct workstation_CLM03 { - s_surf_resource_t generic_resource; /* Must remain first to add this to a trace */ - void *net_elm; - xbt_dynar_t storage; -} s_workstation_CLM03_t, *workstation_CLM03_t; - -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_workstation, surf, - "Logging specific to the SURF workstation module"); - -surf_model_t surf_workstation_model = NULL; - -static void workstation_new(sg_platf_host_cbarg_t host) -{ - workstation_CLM03_t workstation = xbt_new0(s_workstation_CLM03_t, 1); - - workstation->generic_resource.model = surf_workstation_model; - workstation->generic_resource.name = xbt_strdup(host->id); - workstation->storage = xbt_lib_get_or_null(storage_lib,host->id,ROUTING_STORAGE_HOST_LEVEL); - workstation->net_elm = xbt_lib_get_or_null(host_lib,host->id,ROUTING_HOST_LEVEL); - XBT_DEBUG("Create workstation %s with %ld mounted disks",host->id,xbt_dynar_length(workstation->storage)); - xbt_lib_set(host_lib, host->id, SURF_WKS_LEVEL, workstation); -} - -static int ws_resource_used(void *resource_id) -{ - THROW_IMPOSSIBLE; /* This model does not implement parallel tasks */ - return -1; -} - -static void ws_parallel_action_cancel(surf_action_t action) -{ - THROW_UNIMPLEMENTED; /* This model does not implement parallel tasks */ -} - -static int ws_parallel_action_free(surf_action_t action) -{ - THROW_UNIMPLEMENTED; /* This model does not implement parallel tasks */ - return -1; -} - -static int ws_action_unref(surf_action_t action) -{ - if (action->model_type == surf_network_model) - return surf_network_model->action_unref(action); - else if (action->model_type == surf_cpu_model) - return surf_cpu_model->action_unref(action); - else if (action->model_type == surf_workstation_model) - return ws_parallel_action_free(action); - else - DIE_IMPOSSIBLE; - return 0; -} - -static void ws_action_cancel(surf_action_t action) -{ - if (action->model_type == surf_network_model) - surf_network_model->action_cancel(action); - else if (action->model_type == surf_cpu_model) - surf_cpu_model->action_cancel(action); - else if (action->model_type == surf_workstation_model) - ws_parallel_action_cancel(action); - else - DIE_IMPOSSIBLE; - return; -} - -static void ws_action_state_set(surf_action_t action, - e_surf_action_state_t state) -{ - if (action->model_type == surf_network_model) - surf_network_model->action_state_set(action, state); - else if (action->model_type == surf_cpu_model) - surf_cpu_model->action_state_set(action, state); - else if (action->model_type == surf_workstation_model) - surf_action_state_set(action, state); - else - DIE_IMPOSSIBLE; - return; -} - -static double ws_share_resources(double now) -{ - return -1.0; -} - -static void ws_update_actions_state(double now, double delta) -{ - return; -} - -static void ws_update_resource_state(void *id, - tmgr_trace_event_t event_type, - double value, double date) -{ - THROW_IMPOSSIBLE; /* This model does not implement parallel tasks */ -} - -static surf_action_t ws_execute(void *workstation, double size) -{ - surf_resource_t cpu = ((surf_resource_t) surf_cpu_resource_priv(workstation)); - return cpu->model->extension.cpu.execute(workstation, size); -} - -static surf_action_t ws_action_sleep(void *workstation, double duration) -{ - return surf_cpu_model->extension.cpu. - sleep(workstation, duration); -} - -static void ws_action_suspend(surf_action_t action) -{ - if (action->model_type == surf_network_model) - surf_network_model->suspend(action); - else if (action->model_type == surf_cpu_model) - surf_cpu_model->suspend(action); - else - DIE_IMPOSSIBLE; -} - -static void ws_action_resume(surf_action_t action) -{ - if (action->model_type == surf_network_model) - surf_network_model->resume(action); - else if (action->model_type == surf_cpu_model) - surf_cpu_model->resume(action); - else - DIE_IMPOSSIBLE; -} - -static int ws_action_is_suspended(surf_action_t action) -{ - if (action->model_type == surf_network_model) - return surf_network_model->is_suspended(action); - if (action->model_type == surf_cpu_model) - return surf_cpu_model->is_suspended(action); - DIE_IMPOSSIBLE; - return -1; -} - -static void ws_action_set_max_duration(surf_action_t action, - double duration) -{ - if (action->model_type == surf_network_model) - surf_network_model->set_max_duration(action, duration); - else if (action->model_type == surf_cpu_model) - surf_cpu_model->set_max_duration(action, duration); - else - DIE_IMPOSSIBLE; -} - -static void ws_action_set_priority(surf_action_t action, double priority) -{ - if (action->model_type == surf_network_model) - surf_network_model->set_priority(action, priority); - else if (action->model_type == surf_cpu_model) - surf_cpu_model->set_priority(action, priority); - else - DIE_IMPOSSIBLE; -} - -#ifdef HAVE_TRACING -static void ws_action_set_category(surf_action_t action, const char *category) -{ - if (action->model_type == surf_network_model) - surf_network_model->set_category(action, category); - else if (action->model_type == surf_cpu_model) - surf_cpu_model->set_category(action, category); - else - DIE_IMPOSSIBLE; -} -#endif - -#ifdef HAVE_LATENCY_BOUND_TRACKING -static int ws_get_latency_limited(surf_action_t action) -{ - if (action->model_type == surf_network_model) - return surf_network_model->get_latency_limited(action); - else - return 0; -} -#endif - -static double ws_action_get_remains(surf_action_t action) -{ - if (action->model_type == surf_network_model) - return surf_network_model->get_remains(action); - if (action->model_type == surf_cpu_model) - return surf_cpu_model->get_remains(action); - DIE_IMPOSSIBLE; - return -1.0; -} - -static surf_action_t ws_communicate(void *workstation_src, - void *workstation_dst, double size, - double rate) -{ - workstation_CLM03_t src = surf_workstation_resource_priv(workstation_src); - workstation_CLM03_t dst = surf_workstation_resource_priv(workstation_dst); - return surf_network_model->extension.network. - communicate(src->net_elm, - dst->net_elm, size, rate); -} - -static e_surf_resource_state_t ws_get_state(void *workstation) -{ - return surf_cpu_model->extension.cpu. - get_state(workstation); -} - -static double ws_get_speed(void *workstation, double load) -{ - return surf_cpu_model->extension.cpu. - get_speed(workstation, load); -} - -static int ws_get_core(void *workstation) -{ - return surf_cpu_model->extension.cpu. - get_core(workstation); -} - - - -static double ws_get_available_speed(void *workstation) -{ - return surf_cpu_model->extension.cpu. - get_available_speed(workstation); -} - -static surf_action_t ws_execute_parallel_task(int workstation_nb, - void **workstation_list, - double *computation_amount, - double *communication_amount, - double rate) -{ -#define cost_or_zero(array,pos) ((array)?(array)[pos]:0.0) - if ((workstation_nb == 1) - && (cost_or_zero(communication_amount, 0) == 0.0)) - return ws_execute(workstation_list[0], computation_amount[0]); - else if ((workstation_nb == 1) - && (cost_or_zero(computation_amount, 0) == 0.0)) - return ws_communicate(workstation_list[0], workstation_list[0],communication_amount[0], rate); - else if ((workstation_nb == 2) - && (cost_or_zero(computation_amount, 0) == 0.0) - && (cost_or_zero(computation_amount, 1) == 0.0)) { - int i,nb = 0; - double value = 0.0; - - for (i = 0; i < workstation_nb * workstation_nb; i++) { - if (cost_or_zero(communication_amount, i) > 0.0) { - nb++; - value = cost_or_zero(communication_amount, i); - } - } - if (nb == 1) - return ws_communicate(workstation_list[0], workstation_list[1],value, rate); - } -#undef cost_or_zero - - THROW_UNIMPLEMENTED; /* This model does not implement parallel tasks */ - return NULL; -} - - -/* returns an array of network_link_CM02_t */ -static xbt_dynar_t ws_get_route(void *workstation_src, void *workstation_dst) -{ - XBT_DEBUG("ws_get_route"); - workstation_CLM03_t src = surf_workstation_resource_priv(workstation_src); - workstation_CLM03_t dst = surf_workstation_resource_priv(workstation_dst); - return surf_network_model->extension. - network.get_route(src->net_elm, - dst->net_elm); -} - -static double ws_get_link_bandwidth(const void *link) -{ - return surf_network_model->extension.network.get_link_bandwidth(link); -} - -static double ws_get_link_latency(const void *link) -{ - return surf_network_model->extension.network.get_link_latency(link); -} - -static int ws_link_shared(const void *link) -{ - return surf_network_model->extension.network.link_shared(link); -} - -static void ws_finalize(void) -{ - surf_model_exit(surf_workstation_model); - surf_workstation_model = NULL; -} - -static xbt_dict_t ws_get_properties(const void *ws) -{ - return surf_resource_properties(surf_cpu_resource_priv(ws)); -} - -static storage_t find_storage_on_mount_list(void *workstation,const char* storage) -{ - storage_t st = NULL; - s_mount_t mnt; - unsigned int cursor; - workstation_CLM03_t ws = (workstation_CLM03_t) surf_workstation_resource_priv(workstation); - xbt_dynar_t storage_list = ws->storage; - - XBT_DEBUG("Search for storage name '%s' on '%s'",storage,ws->generic_resource.name); - xbt_dynar_foreach(storage_list,cursor,mnt) - { - XBT_DEBUG("See '%s'",mnt.name); - if(!strcmp(storage,mnt.name)){ - st = mnt.id; - break; - } - } - if(!st) xbt_die("Can't find mount '%s' for '%s'",storage,ws->generic_resource.name); - return st; -} - -static surf_action_t ws_action_open(void *workstation, const char* mount, - const char* path) -{ - storage_t st = find_storage_on_mount_list(workstation, mount); - XBT_DEBUG("OPEN on disk '%s'",st->generic_resource.name); - surf_model_t model = st->generic_resource.model; - return model->extension.storage.open(st, mount, path); -} - -static surf_action_t ws_action_close(void *workstation, surf_file_t fd) -{ - storage_t st = find_storage_on_mount_list(workstation, fd->storage); - XBT_DEBUG("CLOSE on disk '%s'",st->generic_resource.name); - surf_model_t model = st->generic_resource.model; - return model->extension.storage.close(st, fd); -} - -static surf_action_t ws_action_read(void *workstation, void* ptr, size_t size, - surf_file_t fd) -{ - storage_t st = find_storage_on_mount_list(workstation, fd->storage); - XBT_DEBUG("READ on disk '%s'",st->generic_resource.name); - surf_model_t model = st->generic_resource.model; - return model->extension.storage.read(st, ptr, size, fd); -} - -static surf_action_t ws_action_write(void *workstation, const void* ptr, - size_t size, surf_file_t fd) -{ - storage_t st = find_storage_on_mount_list(workstation, fd->storage); - XBT_DEBUG("WRITE on disk '%s'",st->generic_resource.name); - surf_model_t model = st->generic_resource.model; - return model->extension.storage.write(st, ptr, size, fd); -} - -static int ws_file_unlink(void *workstation, surf_file_t fd) -{ - if (!fd){ - XBT_WARN("No such file descriptor. Impossible to unlink"); - return 0; - } else { -// XBT_INFO("%s %zu", fd->storage, fd->size); - storage_t st = find_storage_on_mount_list(workstation, fd->storage); - xbt_dict_t content_dict = (st)->content; - /* Check if the file is on this storage */ - if (!xbt_dict_get_or_null(content_dict, fd->name)){ - XBT_WARN("File %s is not on disk %s. Impossible to unlink", fd->name, - st->generic_resource.name); - return 0; - } else { - XBT_DEBUG("UNLINK on disk '%s'",st->generic_resource.name); - st->used_size -= fd->size; - - // Remove the file from storage - xbt_dict_remove(content_dict,fd->name); - - free(fd->name); - free(fd->storage); - xbt_free(fd); - return 1; - } - } -} - -static surf_action_t ws_action_ls(void *workstation, const char* mount, - const char *path) -{ - XBT_DEBUG("LS on mount '%s' and file '%s'",mount, path); - storage_t st = find_storage_on_mount_list(workstation, mount); - surf_model_t model = st->generic_resource.model; - return model->extension.storage.ls(st, path); -} - -static size_t ws_file_get_size(void *workstation, surf_file_t fd) -{ - return fd->size; -} - -static void surf_workstation_model_init_internal(void) -{ - surf_workstation_model = surf_model_init(); - - surf_workstation_model->name = "Workstation"; - surf_workstation_model->action_unref = ws_action_unref; - surf_workstation_model->action_cancel = ws_action_cancel; - surf_workstation_model->action_state_set = ws_action_state_set; - - surf_workstation_model->model_private->resource_used = ws_resource_used; - surf_workstation_model->model_private->share_resources = - ws_share_resources; - surf_workstation_model->model_private->update_actions_state = - ws_update_actions_state; - surf_workstation_model->model_private->update_resource_state = - ws_update_resource_state; - surf_workstation_model->model_private->finalize = ws_finalize; - - surf_workstation_model->suspend = ws_action_suspend; - surf_workstation_model->resume = ws_action_resume; - surf_workstation_model->is_suspended = ws_action_is_suspended; - surf_workstation_model->set_max_duration = ws_action_set_max_duration; - surf_workstation_model->set_priority = ws_action_set_priority; -#ifdef HAVE_TRACING - surf_workstation_model->set_category = ws_action_set_category; -#endif - surf_workstation_model->get_remains = ws_action_get_remains; -#ifdef HAVE_LATENCY_BOUND_TRACKING - surf_workstation_model->get_latency_limited = ws_get_latency_limited; -#endif - - surf_workstation_model->extension.workstation.execute = ws_execute; - surf_workstation_model->extension.workstation.sleep = ws_action_sleep; - surf_workstation_model->extension.workstation.get_state = ws_get_state; - surf_workstation_model->extension.workstation.get_core = ws_get_core; - surf_workstation_model->extension.workstation.get_speed = ws_get_speed; - surf_workstation_model->extension.workstation.get_available_speed = - ws_get_available_speed; - - surf_workstation_model->extension.workstation.communicate = - ws_communicate; - surf_workstation_model->extension.workstation.get_route = ws_get_route; - surf_workstation_model->extension.workstation.execute_parallel_task = - ws_execute_parallel_task; - surf_workstation_model->extension.workstation.get_link_bandwidth = - ws_get_link_bandwidth; - surf_workstation_model->extension.workstation.get_link_latency = - ws_get_link_latency; - surf_workstation_model->extension.workstation.link_shared = - ws_link_shared; - surf_workstation_model->extension.workstation.get_properties = - ws_get_properties; - - surf_workstation_model->extension.workstation.open = ws_action_open; - surf_workstation_model->extension.workstation.close = ws_action_close; - surf_workstation_model->extension.workstation.read = ws_action_read; - surf_workstation_model->extension.workstation.write = ws_action_write; - surf_workstation_model->extension.workstation.unlink = ws_file_unlink; - surf_workstation_model->extension.workstation.ls = ws_action_ls; - surf_workstation_model->extension.workstation.get_size = ws_file_get_size; -} - -void surf_workstation_model_init_current_default(void) -{ - surf_workstation_model_init_internal(); - xbt_cfg_setdefault_boolean(_sg_cfg_set, "network/crosstraffic", xbt_strdup("yes")); - surf_cpu_model_init_Cas01(); - surf_network_model_init_LegrandVelho(); - - xbt_dynar_push(model_list, &surf_workstation_model); - sg_platf_host_add_cb(workstation_new); -} - -void surf_workstation_model_init_compound() -{ - - xbt_assert(surf_cpu_model, "No CPU model defined yet!"); - xbt_assert(surf_network_model, "No network model defined yet!"); - surf_workstation_model_init_internal(); - xbt_dynar_push(model_list, &surf_workstation_model); - sg_platf_host_add_cb(workstation_new); -} diff --git a/src/surf/workstation_ptask_L07.c b/src/surf/workstation_ptask_L07.c deleted file mode 100644 index 3a63505533..0000000000 --- a/src/surf/workstation_ptask_L07.c +++ /dev/null @@ -1,929 +0,0 @@ -/* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team. - * All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * 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" -#include "surf/surf_resource.h" -//#include "surf/surf_resource_lmm.h" - -typedef enum { - SURF_WORKSTATION_RESOURCE_CPU, - SURF_WORKSTATION_RESOURCE_LINK -} e_surf_workstation_model_type_t; - -/**************************************/ -/********* cpu object *****************/ -/**************************************/ -typedef struct cpu_L07 { - s_surf_resource_t generic_resource; /* Do not move this field: must match surf_resource_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; - double power_current; - tmgr_trace_event_t power_event; - tmgr_trace_event_t state_event; - e_surf_resource_state_t state_current; - sg_routing_edge_t info; -} s_cpu_L07_t, *cpu_L07_t; - -/**************************************/ -/*********** network object ***********/ -/**************************************/ - -typedef struct link_L07 { - s_surf_resource_t generic_resource; /* Do not move this field: must match surf_resource_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; - tmgr_trace_event_t lat_event; - double bw_current; - tmgr_trace_event_t bw_event; - e_surf_resource_state_t state_current; - tmgr_trace_event_t state_event; -} s_link_L07_t, *link_L07_t; - -/**************************************/ -/*************** actions **************/ -/**************************************/ -typedef struct surf_action_workstation_L07 { - s_surf_action_t generic_action; - lmm_variable_t variable; - int workstation_nb; - cpu_L07_t *workstation_list; - double *computation_amount; - double *communication_amount; - double latency; - double rate; - int suspended; -} s_surf_action_workstation_L07_t, *surf_action_workstation_L07_t; - - -XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_workstation); - -static int ptask_host_count = 0; -static xbt_dict_t ptask_parallel_task_link_set = NULL; -lmm_system_t ptask_maxmin_system = NULL; - -static surf_action_t die_impossible_communicate (sg_routing_edge_t src, - sg_routing_edge_t dst, - double size, double rate) -{ - DIE_IMPOSSIBLE; - return NULL; -} - -static xbt_dynar_t die_impossible_get_route(void *src, void *dst) -{ - DIE_IMPOSSIBLE; - return NULL; -} - -static void ptask_update_action_bound(surf_action_workstation_L07_t action) -{ - int workstation_nb = action->workstation_nb; - double lat_current = 0.0; - double lat_bound = -1.0; - int i, j; - - for (i = 0; i < workstation_nb; i++) { - for (j = 0; j < workstation_nb; j++) { - xbt_dynar_t route=NULL; - - if (action->communication_amount[i * workstation_nb + j] > 0) { - double lat = 0.0; - routing_get_route_and_latency(((cpu_L07_t)surf_workstation_resource_priv(action->workstation_list[i]))->info, - ((cpu_L07_t)surf_workstation_resource_priv(action->workstation_list[j]))->info, - &route, &lat); - lat_current = - MAX(lat_current, - lat * action->communication_amount[i * workstation_nb + j]); - } - } - } - lat_bound = sg_tcp_gamma / (2.0 * lat_current); - XBT_DEBUG("action (%p) : lat_bound = %g", action, lat_bound); - if ((action->latency == 0.0) && (action->suspended == 0)) { - if (action->rate < 0) - lmm_update_variable_bound(ptask_maxmin_system, action->variable, - lat_bound); - else - lmm_update_variable_bound(ptask_maxmin_system, action->variable, - min(action->rate, lat_bound)); - } -} - -/**************************************/ -/******* Resource Public **********/ -/**************************************/ - -static int ptask_action_unref(surf_action_t action) -{ - action->refcount--; - - if (!action->refcount) { - xbt_swag_remove(action, action->state_set); - if (((surf_action_workstation_L07_t) action)->variable) - lmm_variable_free(ptask_maxmin_system, - ((surf_action_workstation_L07_t) - action)->variable); - free(((surf_action_workstation_L07_t) action)->workstation_list); - free(((surf_action_workstation_L07_t) action)->communication_amount); - free(((surf_action_workstation_L07_t) action)->computation_amount); -#ifdef HAVE_TRACING - xbt_free(action->category); -#endif - surf_action_free(&action); - return 1; - } - return 0; -} - -static void ptask_action_cancel(surf_action_t action) -{ - surf_action_state_set(action, SURF_ACTION_FAILED); - return; -} - -/* action_change_state is inherited from the surf module */ -/* action_set_data is inherited from the surf module */ - -static void ptask_action_suspend(surf_action_t action) -{ - XBT_IN("(%p))", action); - if (((surf_action_workstation_L07_t) action)->suspended != 2) { - ((surf_action_workstation_L07_t) action)->suspended = 1; - lmm_update_variable_weight(ptask_maxmin_system, - ((surf_action_workstation_L07_t) - action)->variable, 0.0); - } - XBT_OUT(); -} - -static void ptask_action_resume(surf_action_t action) -{ - surf_action_workstation_L07_t act = - (surf_action_workstation_L07_t) action; - - XBT_IN("(%p)", act); - if (act->suspended != 2) { - lmm_update_variable_weight(ptask_maxmin_system, act->variable, 1.0); - act->suspended = 0; - } - XBT_OUT(); -} - -static int ptask_action_is_suspended(surf_action_t action) -{ - return (((surf_action_workstation_L07_t) action)->suspended == 1); -} - -static void ptask_action_set_max_duration(surf_action_t action, - double duration) -{ /* FIXME: should inherit */ - XBT_IN("(%p,%g)", action, duration); - action->max_duration = duration; - XBT_OUT(); -} - - -static void ptask_action_set_priority(surf_action_t action, - double priority) -{ /* FIXME: should inherit */ - XBT_IN("(%p,%g)", action, priority); - action->priority = priority; - XBT_OUT(); -} - -static double ptask_action_get_remains(surf_action_t action) -{ - XBT_IN("(%p)", action); - XBT_OUT(); - return action->remains; -} - -/**************************************/ -/******* Resource Private **********/ -/**************************************/ - -static int ptask_resource_used(void *resource_id) -{ - /* We can freely cast as a link_L07_t because it has - the same prefix as cpu_L07_t */ - return lmm_constraint_used(ptask_maxmin_system, - ((link_L07_t) resource_id)->constraint); - -} - -static double ptask_share_resources(double now) -{ - s_surf_action_workstation_L07_t s_action; - surf_action_workstation_L07_t action = NULL; - - xbt_swag_t running_actions = - surf_workstation_model->states.running_action_set; - double min = generic_maxmin_share_resources(running_actions, - xbt_swag_offset(s_action, - variable), - ptask_maxmin_system, - bottleneck_solve); - - xbt_swag_foreach(action, running_actions) { - if (action->latency > 0) { - if (min < 0) { - min = action->latency; - XBT_DEBUG("Updating min (value) with %p (start %f): %f", action, - action->generic_action.start, min); - } else if (action->latency < min) { - min = action->latency; - XBT_DEBUG("Updating min (latency) with %p (start %f): %f", action, - action->generic_action.start, min); - } - } - } - - XBT_DEBUG("min value : %f", min); - - return min; -} - -static void ptask_update_actions_state(double now, double delta) -{ - double deltap = 0.0; - surf_action_workstation_L07_t action = NULL; - surf_action_workstation_L07_t next_action = NULL; - xbt_swag_t running_actions = - surf_workstation_model->states.running_action_set; - - xbt_swag_foreach_safe(action, next_action, running_actions) { - deltap = delta; - if (action->latency > 0) { - if (action->latency > deltap) { - double_update(&(action->latency), deltap); - deltap = 0.0; - } else { - double_update(&(deltap), action->latency); - action->latency = 0.0; - } - if ((action->latency == 0.0) && (action->suspended == 0)) { - ptask_update_action_bound(action); - lmm_update_variable_weight(ptask_maxmin_system, action->variable, - 1.0); - } - } - XBT_DEBUG("Action (%p) : remains (%g) updated by %g.", - action, action->generic_action.remains, - lmm_variable_getvalue(action->variable) * delta); - double_update(&(action->generic_action.remains), - lmm_variable_getvalue(action->variable) * delta); - - if (action->generic_action.max_duration != NO_MAX_DURATION) - double_update(&(action->generic_action.max_duration), delta); - - XBT_DEBUG("Action (%p) : remains (%g).", - action, action->generic_action.remains); - if ((action->generic_action.remains <= 0) && - (lmm_get_variable_weight(action->variable) > 0)) { - action->generic_action.finish = surf_get_clock(); - surf_action_state_set((surf_action_t) action, SURF_ACTION_DONE); - } else if ((action->generic_action.max_duration != NO_MAX_DURATION) && - (action->generic_action.max_duration <= 0)) { - action->generic_action.finish = surf_get_clock(); - surf_action_state_set((surf_action_t) action, SURF_ACTION_DONE); - } else { - /* Need to check that none of the model has failed */ - lmm_constraint_t cnst = NULL; - int i = 0; - void *constraint_id = NULL; - - while ((cnst = - lmm_get_cnst_from_var(ptask_maxmin_system, action->variable, - i++))) { - constraint_id = lmm_constraint_id(cnst); - -/* if(((link_L07_t)constraint_id)->type== */ -/* SURF_WORKSTATION_RESOURCE_LINK) { */ -/* XBT_DEBUG("Checking for link %s (%p)", */ -/* ((link_L07_t)constraint_id)->name, */ -/* ((link_L07_t)constraint_id)); */ -/* } */ -/* if(((cpu_L07_t)constraint_id)->type== */ -/* SURF_WORKSTATION_RESOURCE_CPU) { */ -/* XBT_DEBUG("Checking for cpu %s (%p) : %s", */ -/* ((cpu_L07_t)constraint_id)->name, */ -/* ((cpu_L07_t)constraint_id), */ -/* ((cpu_L07_t)constraint_id)->state_current==SURF_CPU_OFF?"Off":"On"); */ -/* } */ - - if (((((link_L07_t) constraint_id)->type == - SURF_WORKSTATION_RESOURCE_LINK) && - (((link_L07_t) constraint_id)->state_current == - SURF_RESOURCE_OFF)) || - ((((cpu_L07_t) constraint_id)->type == - SURF_WORKSTATION_RESOURCE_CPU) && - (((cpu_L07_t) constraint_id)->state_current == - SURF_RESOURCE_OFF))) { - XBT_DEBUG("Action (%p) Failed!!", action); - action->generic_action.finish = surf_get_clock(); - surf_action_state_set((surf_action_t) action, - SURF_ACTION_FAILED); - break; - } - } - } - } - return; -} - -static void ptask_update_resource_state(void *id, - tmgr_trace_event_t event_type, - double value, double date) -{ - cpu_L07_t cpu = id; - link_L07_t nw_link = id; - - if (nw_link->type == SURF_WORKSTATION_RESOURCE_LINK) { - XBT_DEBUG("Updating link %s (%p) with value=%f for date=%g", - surf_resource_name(nw_link), nw_link, value, date); - if (event_type == nw_link->bw_event) { - nw_link->bw_current = value; - lmm_update_constraint_bound(ptask_maxmin_system, nw_link->constraint, - nw_link->bw_current); - if (tmgr_trace_event_free(event_type)) - nw_link->bw_event = NULL; - } 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 ((var = lmm_get_var_from_cnst - (ptask_maxmin_system, nw_link->constraint, &elem))) { - - - action = lmm_variable_id(var); - ptask_update_action_bound(action); - } - if (tmgr_trace_event_free(event_type)) - nw_link->lat_event = NULL; - - } else if (event_type == nw_link->state_event) { - if (value > 0) - nw_link->state_current = SURF_RESOURCE_ON; - else - nw_link->state_current = SURF_RESOURCE_OFF; - if (tmgr_trace_event_free(event_type)) - nw_link->state_event = NULL; - } else { - XBT_CRITICAL("Unknown event ! \n"); - xbt_abort(); - } - return; - } else if (cpu->type == SURF_WORKSTATION_RESOURCE_CPU) { - XBT_DEBUG("Updating cpu %s (%p) with value %g", surf_resource_name(cpu), - cpu, value); - if (event_type == cpu->power_event) { - cpu->power_current = value; - lmm_update_constraint_bound(ptask_maxmin_system, cpu->constraint, - cpu->power_current * cpu->power_scale); - if (tmgr_trace_event_free(event_type)) - cpu->power_event = NULL; - } else if (event_type == cpu->state_event) { - if (value > 0) - cpu->state_current = SURF_RESOURCE_ON; - else - cpu->state_current = SURF_RESOURCE_OFF; - if (tmgr_trace_event_free(event_type)) - cpu->state_event = NULL; - } else { - XBT_CRITICAL("Unknown event ! \n"); - xbt_abort(); - } - return; - } else { - DIE_IMPOSSIBLE; - } - return; -} - -static void ptask_finalize(void) -{ - xbt_dict_free(&ptask_parallel_task_link_set); - - surf_model_exit(surf_workstation_model); - surf_workstation_model = NULL; - surf_model_exit(surf_network_model); - surf_network_model = NULL; - - ptask_host_count = 0; - - if (ptask_maxmin_system) { - lmm_system_free(ptask_maxmin_system); - ptask_maxmin_system = NULL; - } -} - -/**************************************/ -/******* Resource Private **********/ -/**************************************/ - -static e_surf_resource_state_t ptask_resource_get_state(void *cpu) -{ - return ((cpu_L07_t)surf_workstation_resource_priv(cpu))->state_current; -} - -static double ptask_get_speed(void *cpu, double load) -{ - return load * ((cpu_L07_t)surf_workstation_resource_priv(cpu))->power_scale; -} - -static double ptask_get_available_speed(void *cpu) -{ - return ((cpu_L07_t)surf_workstation_resource_priv(cpu))->power_current; -} - -static surf_action_t ptask_execute_parallel_task(int workstation_nb, - void **workstation_list, - double - *computation_amount, double - *communication_amount, - double rate) -{ - surf_action_workstation_L07_t action = NULL; - int i, j; - unsigned int cpt; - int nb_link = 0; - int nb_host = 0; - double latency = 0.0; - - if (ptask_parallel_task_link_set == NULL) - ptask_parallel_task_link_set = xbt_dict_new_homogeneous(NULL); - - xbt_dict_reset(ptask_parallel_task_link_set); - - /* Compute the number of affected resources... */ - for (i = 0; i < workstation_nb; i++) { - for (j = 0; j < workstation_nb; j++) { - xbt_dynar_t route=NULL; - - if (communication_amount[i * workstation_nb + j] > 0) { - double lat=0.0; - unsigned int cpt; - link_L07_t link; - - routing_get_route_and_latency( - ((cpu_L07_t)surf_workstation_resource_priv(workstation_list[i]))->info, - ((cpu_L07_t)surf_workstation_resource_priv(workstation_list[j]))->info, - &route,&lat); - latency = MAX(latency, lat); - - xbt_dynar_foreach(route, cpt, link) { - xbt_dict_set(ptask_parallel_task_link_set,link->generic_resource.name,link,NULL); - } - } - } - } - - nb_link = xbt_dict_length(ptask_parallel_task_link_set); - xbt_dict_reset(ptask_parallel_task_link_set); - - for (i = 0; i < workstation_nb; i++) - if (computation_amount[i] > 0) - nb_host++; - - action = - surf_action_new(sizeof(s_surf_action_workstation_L07_t), 1, - surf_workstation_model, 0); - XBT_DEBUG("Creating a parallel task (%p) with %d cpus and %d links.", - action, workstation_nb, nb_link); - action->suspended = 0; /* Should be useless because of the - calloc but it seems to help valgrind... */ - action->workstation_nb = workstation_nb; - action->workstation_list = (cpu_L07_t *) workstation_list; - action->computation_amount = computation_amount; - action->communication_amount = communication_amount; - action->latency = latency; - action->rate = rate; - - 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); - - for (i = 0; i < workstation_nb; i++) - lmm_expand(ptask_maxmin_system, - ((cpu_L07_t)surf_workstation_resource_priv(workstation_list[i]))->constraint, - action->variable, computation_amount[i]); - - for (i = 0; i < workstation_nb; i++) { - for (j = 0; j < workstation_nb; j++) { - link_L07_t link; - xbt_dynar_t route=NULL; - if (communication_amount[i * workstation_nb + j] == 0.0) - continue; - - routing_get_route_and_latency( - ((cpu_L07_t)surf_workstation_resource_priv(workstation_list[i]))->info, - ((cpu_L07_t)surf_workstation_resource_priv(workstation_list[j]))->info, - &route,NULL); - - xbt_dynar_foreach(route, cpt, link) { - lmm_expand_add(ptask_maxmin_system, link->constraint, - action->variable, - communication_amount[i * workstation_nb + j]); - } - } - } - - if (nb_link + nb_host == 0) { - action->generic_action.cost = 1.0; - action->generic_action.remains = 0.0; - } - - return (surf_action_t) action; -} - -static surf_action_t ptask_execute(void *cpu, double size) -{ - void **workstation_list = xbt_new0(void *, 1); - double *computation_amount = xbt_new0(double, 1); - double *communication_amount = xbt_new0(double, 1); - - workstation_list[0] = cpu; - communication_amount[0] = 0.0; - computation_amount[0] = size; - - return ptask_execute_parallel_task(1, workstation_list, - computation_amount, - communication_amount, -1); -} - -static surf_action_t ptask_communicate(void *src, void *dst, double size, - double rate) -{ - void **workstation_list = xbt_new0(void *, 2); - double *computation_amount = xbt_new0(double, 2); - double *communication_amount = xbt_new0(double, 4); - surf_action_t res = NULL; - - workstation_list[0] = src; - workstation_list[1] = dst; - communication_amount[1] = size; - - res = ptask_execute_parallel_task(2, workstation_list, - computation_amount, - communication_amount, rate); - - return res; -} - -static surf_action_t ptask_action_sleep(void *cpu, double duration) -{ - surf_action_workstation_L07_t action = NULL; - - XBT_IN("(%s,%g)", surf_resource_name(cpu), duration); - - action = (surf_action_workstation_L07_t) ptask_execute(cpu, 1.0); - action->generic_action.max_duration = duration; - action->suspended = 2; - lmm_update_variable_weight(ptask_maxmin_system, action->variable, 0.0); - - XBT_OUT(); - return (surf_action_t) action; -} - -static xbt_dynar_t ptask_get_route(void *src, void *dst) // FIXME: kill that callback kind? -{ - xbt_dynar_t route=NULL; - routing_get_route_and_latency( - ((cpu_L07_t)surf_workstation_resource_priv(src))->info, ((cpu_L07_t)surf_workstation_resource_priv(dst))->info, - &route,NULL); - return route; -} - -static double ptask_get_link_bandwidth(const void *link) -{ - return ((link_L07_t) link)->bw_current; -} - -static double ptask_get_link_latency(const void *link) -{ - return ((link_L07_t) link)->lat_current; -} - -static int ptask_link_shared(const void *link) -{ - return lmm_constraint_is_shared(((link_L07_t) link)->constraint); -} - -/**************************************/ -/*** Resource Creation & Destruction **/ -/**************************************/ - -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 = NULL; - xbt_assert(!surf_workstation_resource_priv(surf_workstation_resource_by_name(name)), - "Host '%s' declared several times in the platform file.", - name); - - 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->info = xbt_lib_get_or_null(host_lib, name, ROUTING_HOST_LEVEL); - if(!(cpu->info)) xbt_die("Don't find ROUTING_HOST_LEVEL for '%s'",name); - - cpu->power_scale = power_scale; - xbt_assert(cpu->power_scale > 0, "Power has to be >0"); - - cpu->power_current = power_initial; - if (power_trace) - cpu->power_event = - tmgr_history_add_trace(history, power_trace, 0.0, 0, cpu); - - cpu->state_current = state_initial; - if (state_trace) - cpu->state_event = - tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu); - - cpu->constraint = - lmm_constraint_new(ptask_maxmin_system, cpu, - cpu->power_current * cpu->power_scale); - - xbt_lib_set(host_lib, name, SURF_WKS_LEVEL, cpu); - - return xbt_lib_get_elm_or_null(host_lib, name); -} - -static void ptask_parse_cpu_init(sg_platf_host_cbarg_t host) -{ - ptask_cpu_create_resource( - host->id, - host->power_peak, - host->power_scale, - host->power_trace, - host->initial_state, - host->state_trace, - host->properties); -} - -static void* ptask_link_create_resource(const char *name, - double bw_initial, - tmgr_trace_t bw_trace, - double lat_initial, - tmgr_trace_t lat_trace, - e_surf_resource_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_assert(!xbt_lib_get_or_null(link_lib, name, SURF_LINK_LEVEL), - "Link '%s' declared several times in the platform file.", - name); - - nw_link->generic_resource.model = surf_workstation_model; - nw_link->generic_resource.properties = properties; - nw_link->generic_resource.name = xbt_strdup(name); - nw_link->type = SURF_WORKSTATION_RESOURCE_LINK; - 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->state_current = state_initial; - 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); - 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(ptask_maxmin_system, nw_link, - nw_link->bw_current); - - if (policy == SURF_LINK_FATPIPE) - lmm_constraint_shared(nw_link->constraint); - - xbt_lib_set(link_lib, name, SURF_LINK_LEVEL, nw_link); - return nw_link; -} - -static void ptask_parse_link_init(sg_platf_link_cbarg_t link) -{ - if (link->policy == SURF_LINK_FULLDUPLEX) { - char *link_id; - link_id = bprintf("%s_UP", link->id); - ptask_link_create_resource(link_id, - link->bandwidth, - link->bandwidth_trace, - link->latency, - link->latency_trace, - link->state, - link->state_trace, - link->policy, - link->properties); - xbt_free(link_id); - link_id = bprintf("%s_DOWN", link->id); - ptask_link_create_resource(link_id, - link->bandwidth, - link->bandwidth_trace, - link->latency, - link->latency_trace, - link->state, - link->state_trace, - link->policy, - NULL); /* FIXME: We need to deep copy the - * properties or we won't be able to free - * it */ - xbt_free(link_id); - } else { - ptask_link_create_resource(link->id, - link->bandwidth, - link->bandwidth_trace, - link->latency, - link->latency_trace, - link->state, - link->state_trace, - link->policy, - link->properties); - } - - current_property_set = NULL; -} - -static void ptask_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 = surf_workstation_resource_priv(surf_workstation_resource_by_name(elm)); - - xbt_assert(host, "Host %s undefined", elm); - xbt_assert(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 = surf_workstation_resource_priv(surf_workstation_resource_by_name(elm)); - - xbt_assert(host, "Host %s undefined", elm); - xbt_assert(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_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL); - - xbt_assert(link, "Link %s undefined", elm); - xbt_assert(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_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL); - - xbt_assert(link, "Link %s undefined", elm); - xbt_assert(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_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL); - - xbt_assert(link, "Link %s undefined", elm); - xbt_assert(trace, "Trace %s undefined", trace_name); - - link->lat_event = tmgr_history_add_trace(history, trace, 0.0, 0, link); - } -} - -static void ptask_define_callbacks() -{ - sg_platf_host_add_cb(ptask_parse_cpu_init); - sg_platf_link_add_cb(ptask_parse_link_init); - sg_platf_postparse_add_cb(ptask_add_traces); -} - -/**************************************/ -/********* Module creation ***********/ -/**************************************/ - -static void ptask_model_init_internal(void) -{ - surf_workstation_model = surf_model_init(); - - surf_workstation_model->action_unref = ptask_action_unref; - surf_workstation_model->action_cancel = ptask_action_cancel; - surf_workstation_model->action_state_set = surf_action_state_set; - surf_workstation_model->suspend = ptask_action_suspend; - surf_workstation_model->resume = ptask_action_resume; - surf_workstation_model->is_suspended = ptask_action_is_suspended; - surf_workstation_model->set_max_duration = ptask_action_set_max_duration; - surf_workstation_model->set_priority = ptask_action_set_priority; - surf_workstation_model->get_remains = ptask_action_get_remains; - surf_workstation_model->name = "Workstation ptask_L07"; - - surf_workstation_model->model_private->resource_used = - ptask_resource_used; - surf_workstation_model->model_private->share_resources = - ptask_share_resources; - surf_workstation_model->model_private->update_actions_state = - ptask_update_actions_state; - surf_workstation_model->model_private->update_resource_state = - ptask_update_resource_state; - surf_workstation_model->model_private->finalize = ptask_finalize; - - - surf_workstation_model->extension.workstation.execute = ptask_execute; - surf_workstation_model->extension.workstation.sleep = ptask_action_sleep; - surf_workstation_model->extension.workstation.get_state = - ptask_resource_get_state; - surf_workstation_model->extension.workstation.get_speed = - ptask_get_speed; - surf_workstation_model->extension.workstation.get_available_speed = - ptask_get_available_speed; - surf_workstation_model->extension.workstation.communicate = - ptask_communicate; - surf_workstation_model->extension.workstation.get_route = - ptask_get_route; - surf_workstation_model->extension.workstation.execute_parallel_task = - ptask_execute_parallel_task; - surf_workstation_model->extension.workstation.get_link_bandwidth = - ptask_get_link_bandwidth; - surf_workstation_model->extension.workstation.get_link_latency = - ptask_get_link_latency; - surf_workstation_model->extension.workstation.link_shared = - ptask_link_shared; - surf_workstation_model->extension.workstation.get_properties = - surf_resource_properties; - surf_workstation_model->extension.workstation.add_traces = - ptask_add_traces; - - if (!ptask_maxmin_system) - ptask_maxmin_system = lmm_system_new(1); - - routing_model_create(ptask_link_create_resource("__loopback__", - 498000000, NULL, - 0.000015, NULL, - SURF_RESOURCE_ON, NULL, - SURF_LINK_FATPIPE, NULL)); - - surf_network_model = surf_model_init(); - - surf_network_model->extension.network.communicate = die_impossible_communicate; - surf_network_model->extension.network.get_route = die_impossible_get_route; - surf_network_model->extension.network.get_link_bandwidth = ptask_get_link_bandwidth; - surf_network_model->extension.network.get_link_latency = ptask_get_link_latency; - surf_network_model->extension.network.link_shared = ptask_link_shared; - surf_network_model->extension.network.add_traces = NULL; -} - -/**************************************/ -/*************** Generic **************/ -/**************************************/ -void surf_workstation_model_init_ptask_L07(void) -{ - XBT_INFO("surf_workstation_model_init_ptask_L07"); - xbt_assert(!surf_cpu_model, "CPU model type already defined"); - xbt_assert(!surf_network_model, "network model type already defined"); - ptask_define_callbacks(); - ptask_model_init_internal(); - xbt_dynar_push(model_list, &surf_workstation_model); -} diff --git a/src/xbt/log.c b/src/xbt/log.c index c560de6d9f..fd8d595696 100644 --- a/src/xbt/log.c +++ b/src/xbt/log.c @@ -681,7 +681,6 @@ static void xbt_log_connect_categories(void) XBT_LOG_CONNECT(surf_lagrange_dichotomy); XBT_LOG_CONNECT(surf_maxmin); XBT_LOG_CONNECT(surf_network); - XBT_LOG_CONNECT(surf_new_model); #ifdef HAVE_GTNETS XBT_LOG_CONNECT(surf_network_gtnets); XBT_LOG_CONNECT(surf_network_gtnets_interface);