if(enable_coverage)
find_program(GCOV_PATH gcov)
if(GCOV_PATH)
- SET(COVERAGE_COMMAND "${GCOV_PATH}" CACHE TYPE FILEPATH FORCE)
+ set(COVERAGE_COMMAND "${GCOV_PATH}" CACHE TYPE FILEPATH FORCE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DCOVERAGE")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
set(TESH_OPTION --enable-coverage)
+++ /dev/null
-/* Copyright (c) 2009-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 "surf_private.h"
-#include "surf/surf_resource.h"
-#include "maxmin_private.h"
-#include "simgrid/sg_config.h"
-#include "cpu_cas01_private.h"
-
-#include "string.h"
-#include "stdlib.h"
-
-surf_model_t surf_cpu_model = NULL;
-
-
-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;
-
-/* Additionnal callback function to cleanup some data, called from surf_resource_free */
-
-static void cpu_cas01_cleanup(void* r){
- cpu_Cas01_t cpu = (cpu_Cas01_t)r;
- unsigned int iter;
- xbt_dynar_t power_tuple = NULL;
- xbt_dynar_foreach(cpu->energy->power_range_watts_list, iter, power_tuple)
- xbt_dynar_free(&power_tuple);
- xbt_dynar_free(&cpu->energy->power_range_watts_list);
- xbt_dynar_free(&cpu->power_peak_list);
- xbt_free(cpu->energy);
- return;
-}
-
-/* This function is registered as a callback to sg_platf_new_host() and never called directly */
-static void *cpu_create_resource(const char *name, xbt_dynar_t power_peak,
- int pstate,
- 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_cas01_cleanup);
- cpu->power_peak = xbt_dynar_get_as(power_peak, pstate, double);
- cpu->power_peak_list = power_peak;
- cpu->pstate = pstate;
-
- cpu->energy = xbt_new(s_energy_cpu_cas01_t, 1);
- cpu->energy->total_energy = 0;
- cpu->energy->power_range_watts_list = cpu_get_watts_range_list(cpu);
- cpu->energy->last_updated = surf_get_clock();
-
- XBT_DEBUG("CPU create: peak=%f, pstate=%d",cpu->power_peak, cpu->pstate);
-
- 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, 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->pstate,
- 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);
-}
-
-xbt_dynar_t cpu_get_watts_range_list(cpu_Cas01_t cpu_model)
-{
- xbt_dynar_t power_range_list;
- xbt_dynar_t power_tuple;
- int i = 0, pstate_nb=0;
- xbt_dynar_t current_power_values;
- double min_power, max_power;
- xbt_dict_t props = cpu_model->generic_resource.properties;
-
- if (props == NULL)
- return NULL;
-
- char* all_power_values_str = xbt_dict_get_or_null(props, "power_per_state");
-
- if (all_power_values_str == NULL)
- return NULL;
-
-
- power_range_list = xbt_dynar_new(sizeof(xbt_dynar_t), NULL);
- xbt_dynar_t all_power_values = xbt_str_split(all_power_values_str, ",");
-
- pstate_nb = xbt_dynar_length(all_power_values);
- for (i=0; i< pstate_nb; i++)
- {
- /* retrieve the power values associated with the current pstate */
- current_power_values = xbt_str_split(xbt_dynar_get_as(all_power_values, i, char*), ":");
- xbt_assert(xbt_dynar_length(current_power_values) > 1,
- "Power properties incorrectly defined - could not retrieve min and max power values for host %s",
- cpu_model->generic_resource.name);
-
- /* min_power corresponds to the idle power (cpu load = 0) */
- /* max_power is the power consumed at 100% cpu load */
- min_power = atof(xbt_dynar_get_as(current_power_values, 0, char*));
- max_power = atof(xbt_dynar_get_as(current_power_values, 1, char*));
-
- power_tuple = xbt_dynar_new(sizeof(double), NULL);
- xbt_dynar_push_as(power_tuple, double, min_power);
- xbt_dynar_push_as(power_tuple, double, max_power);
-
- xbt_dynar_push_as(power_range_list, xbt_dynar_t, power_tuple);
- xbt_dynar_free(¤t_power_values);
- }
- xbt_dynar_free(&all_power_values);
- return power_range_list;
-
-}
-
-/**
- * Computes the power consumed by the host according to the current pstate and processor load
- *
- */
-static double cpu_get_current_watts_value(cpu_Cas01_t cpu_model, double cpu_load)
-{
- xbt_dynar_t power_range_list = cpu_model->energy->power_range_watts_list;
-
- if (power_range_list == NULL)
- {
- XBT_DEBUG("No power range properties specified for host %s", cpu_model->generic_resource.name);
- return 0;
- }
- xbt_assert(xbt_dynar_length(power_range_list) == xbt_dynar_length(cpu_model->power_peak_list),
- "The number of power ranges in the properties does not match the number of pstates for host %s",
- cpu_model->generic_resource.name);
-
- /* retrieve the power values associated with the current pstate */
- xbt_dynar_t current_power_values = xbt_dynar_get_as(power_range_list, cpu_model->pstate, xbt_dynar_t);
-
- /* min_power corresponds to the idle power (cpu load = 0) */
- /* max_power is the power consumed at 100% cpu load */
- double min_power = xbt_dynar_get_as(current_power_values, 0, double);
- double max_power = xbt_dynar_get_as(current_power_values, 1, double);
- double power_slope = max_power - min_power;
-
- double current_power = min_power + cpu_load * power_slope;
-
- XBT_DEBUG("[get_current_watts] min_power=%f, max_power=%f, slope=%f", min_power, max_power, power_slope);
- XBT_DEBUG("[get_current_watts] Current power (watts) = %f, load = %f", current_power, cpu_load);
-
- return current_power;
-
-}
-
-/**
- * Updates the total energy consumed as the sum of the current energy and
- * the energy consumed by the current action
- */
-void cpu_update_energy(cpu_Cas01_t cpu_model, double cpu_load)
-{
-
- double start_time = cpu_model->energy->last_updated;
- double finish_time = surf_get_clock();
-
- XBT_DEBUG("[cpu_update_energy] action time interval=(%f-%f), current power peak=%f, current pstate=%d",
- start_time, finish_time, cpu_model->power_peak, cpu_model->pstate);
- double current_energy = cpu_model->energy->total_energy;
- double action_energy = cpu_get_current_watts_value(cpu_model, cpu_load)*(finish_time-start_time);
-
- cpu_model->energy->total_energy = current_energy + action_energy;
- cpu_model->energy->last_updated = finish_time;
-
- XBT_DEBUG("[cpu_update_energy] old_energy_value=%f, action_energy_value=%f", current_energy, action_energy);
-
-}
-
-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;
-
- 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) {
- if(cpu->state_current == SURF_RESOURCE_OFF)
- xbt_dynar_push_as(host_that_restart, char*, (cpu->generic_resource.name));
- 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;
- //xbt_dict_cursor_t cursor = NULL;
- cpu_Cas01_t CPU = surf_cpu_resource_priv(cpu);
- //xbt_dict_t props = CPU->generic_resource.properties;
-
- 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 double cpu_get_current_power_peak(void *cpu)
-{
- return ((cpu_Cas01_t)surf_cpu_resource_priv(cpu))->power_peak;
-}
-
-static double cpu_get_power_peak_at(void *cpu, int pstate_index)
-{
- xbt_dynar_t plist = ((cpu_Cas01_t)surf_cpu_resource_priv(cpu))->power_peak_list;
- xbt_assert((pstate_index <= xbt_dynar_length(plist)), "Invalid parameters (pstate index out of bounds)");
-
- return xbt_dynar_get_as(plist, pstate_index, double);
-}
-
-static int cpu_get_nb_pstates(void *cpu)
-{
- return xbt_dynar_length(((cpu_Cas01_t)surf_cpu_resource_priv(cpu))->power_peak_list);
-}
-
-static void cpu_set_power_peak_at(void *cpu, int pstate_index)
-{
- cpu_Cas01_t cpu_implem = (cpu_Cas01_t)surf_cpu_resource_priv(cpu);
- xbt_dynar_t plist = cpu_implem->power_peak_list;
- xbt_assert((pstate_index <= xbt_dynar_length(plist)), "Invalid parameters (pstate index out of bounds)");
-
- double new_power_peak = xbt_dynar_get_as(plist, pstate_index, double);
- cpu_implem->pstate = pstate_index;
- cpu_implem->power_peak = new_power_peak;
-}
-
-static double cpu_get_consumed_energy(void *cpu)
-{
- return ((cpu_Cas01_t)surf_cpu_resource_priv(cpu))->energy->total_energy;
-}
-
-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.get_current_power_peak = cpu_get_current_power_peak;
- surf_cpu_model->extension.cpu.get_power_peak_at = cpu_get_power_peak_at;
- surf_cpu_model->extension.cpu.get_nb_pstates = cpu_get_nb_pstates;
- surf_cpu_model->extension.cpu.set_power_peak_at = cpu_set_power_peak_at;
- surf_cpu_model->extension.cpu.get_consumed_energy = cpu_get_consumed_energy;
-
- 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);
-}
+++ /dev/null
-
-/* Copyright (c) 2009-2010, 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. */
-
-#ifndef _SURF_CPU_CAS01_PRIVATE_H
-#define _SURF_CPU_CAS01_PRIVATE_H
-
-#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;
-
-
-/*
- * Energy-related properties for the cpu_cas01 model
- */
-typedef struct energy_cpu_cas01 {
- xbt_dynar_t power_range_watts_list; /*< List of (min_power,max_power) pairs corresponding to each cpu pstate */
- double total_energy; /*< Total energy consumed by the host */
- double last_updated; /*< Timestamp of the last energy update event*/
-} s_energy_cpu_cas01_t, *energy_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;
-
- xbt_dynar_t power_peak_list; /*< List of supported CPU capacities */
- int pstate; /*< Current pstate (index in the power_peak_list)*/
- energy_cpu_cas01_t energy; /*< Structure with energy-consumption data */
-
-} s_cpu_Cas01_t, *cpu_Cas01_t;
-
-xbt_dynar_t cpu_get_watts_range_list(cpu_Cas01_t cpu_model);
-void cpu_update_energy(cpu_Cas01_t cpu_model, double cpu_load);
-
-#endif /* _SURF_CPU_CAS01_PRIVATE_H */
+++ /dev/null
-
-/* Copyright (c) 2009-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. */
-
-/*
- 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 availability trace. Constant value = %f", 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 %f, last_time %f ",
- trace->total, trace->last_time);
-
- return trace;
-}
-
-
-static void* cpu_ti_create_resource(const char *name, xbt_dynar_t power_peak,
- int pstate,
- 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, NULL);
- cpu->action_set =
- xbt_swag_new(xbt_swag_offset(ti_action, cpu_list_hookup));
-
- xbt_dynar_get_cpy(power_peak, 0, &cpu->power_peak);
- xbt_dynar_free(&power_peak); /* kill memory leak */
- //cpu->power_peak = power_peak;
- cpu->pstate = pstate;
- XBT_DEBUG("CPU create: peak=%f, pstate=%d",cpu->power_peak, cpu->pstate);
-
- xbt_assert(cpu->power_peak > 0, "Power has to be >0");
- XBT_DEBUG("power scale %f", 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->pstate,
- 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: %f, Last update %f", 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 %f", 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: %f Finish Time: %f Max duration %f",
- 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: %f", 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 amount 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;
-
- 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: %f value %f date %f", 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 %f", 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) {
- if(cpu->state_current == SURF_RESOURCE_OFF)
- xbt_dynar_push_as(host_that_restart, char*, (cpu->generic_resource.name));
- 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 %f ind %d integral %f ind + 1 %f ind %f time +1 %f time %f",
- 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 %f = %f", 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 %f total %f", 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: %f reduced_a: %f", 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 %f low %d high %d mid %d value %f", a, low, high, mid,
- array[mid]);
-
- if (array[mid] > a)
- high = mid;
- else
- low = mid;
- }
- while (low < high - 1);
-
- return low;
-}
+++ /dev/null
-
-/* Copyright (c) 2009-2010, 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. */
-
-#ifndef _SURF_CPU_TI_PRIVATE_H
-#define _SURF_CPU_TI_PRIVATE_H
-
-typedef struct surf_cpu_ti_trace {
- double *time_points;
- double *integral;
- int nb_points;
-} s_surf_cpu_ti_trace_t, *surf_cpu_ti_trace_t;
-
-/* TRACE */
-typedef struct surf_cpu_ti_tgmr {
- enum trace_type {
- TRACE_FIXED, /*< Trace fixed, no availability file */
- TRACE_DYNAMIC /*< Dynamic, availability file disponible */
- } type;
-
- double value; /*< Percentage of cpu power disponible. Value fixed between 0 and 1 */
-
- /* Dynamic */
- double last_time; /*< Integral interval last point (discret time) */
- double total; /*< Integral total between 0 and last_pointn */
-
- surf_cpu_ti_trace_t trace;
- tmgr_trace_t power_trace;
-
-} s_surf_cpu_ti_tgmr_t, *surf_cpu_ti_tgmr_t;
-
-
-/* CPU with trace integration feature */
-typedef struct cpu_ti {
- s_surf_resource_t generic_resource; /*< Structure with generic data. Needed at begin to interate with SURF */
- double power_peak; /*< CPU power peak */
- int pstate;
- double power_scale; /*< Percentage of CPU disponible */
- surf_cpu_ti_tgmr_t avail_trace; /*< Structure with data needed to integrate trace file */
- e_surf_resource_state_t state_current; /*< CPU current state (ON or OFF) */
- tmgr_trace_event_t state_event; /*< trace file with states events (ON or OFF) */
- tmgr_trace_event_t power_event; /*< trace file with availability events */
- xbt_swag_t action_set; /*< set with all actions running on cpu */
- s_xbt_swag_hookup_t modified_cpu_hookup; /*< hookup to swag that indicacates whether share resources must be recalculated or not */
- double sum_priority; /*< the sum of actions' priority that are running on cpu */
- double last_update; /*< last update of actions' remaining amount done */
- double current_frequency;
-} s_cpu_ti_t, *cpu_ti_t;
-
-typedef struct surf_action_ti {
- s_surf_action_t generic_action;
- s_xbt_swag_hookup_t cpu_list_hookup;
- void *cpu;
- int suspended;
- int index_heap;
-} s_surf_action_cpu_ti_t, *surf_action_cpu_ti_t;
-
-/* Epsilon */
-#define EPSILON 0.000000001
-/* Usefull define to get the cpu where action is running on */
-#define ACTION_GET_CPU(action) ((cpu_ti_t)((surf_action_cpu_ti_t)action)->cpu)
-
-
-#endif /* _SURF_CPU_TI_PRIVATE_H */
+++ /dev/null
-
-/*
- * 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) 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 "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("%f <= %ld return %f", size, fact.factor, current);
- return current;
- }else
- current=fact.value;
- }
- XBT_DEBUG("%f > %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("%f <= %ld return %f", size, fact.factor, current);
- return current;
- }else
- current=fact.value;
- }
- XBT_DEBUG("%f > %ld return %f", size, fact.factor, current);
-
- return current;
-}
-
-/**--------- <copy/paste C code snippet in surf/network.c> -----------*/
-
-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("[" "%g" "] Asking to update network card \"%s\" with value " */
- /* "%g" " 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_homogeneous(NULL);
- }
- 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);
-}
+++ /dev/null
-/* Copyright (c) 2008-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 "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 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;
- 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
-
- netcste_define_callbacks();
- xbt_dynar_push(model_list, &surf_network_model);
-
- routing_model_create(NULL);
-}
+++ /dev/null
-/* Copyright (c) 2007-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 "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 %g",
- 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);
- }
-}
+++ /dev/null
-/* Copyright (c) 2004-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. */
-
-#ifndef _SURF_NETWORK_PRIVATE_H
-#define _SURF_NETWORK_PRIVATE_H
-
-#include "surf_private.h"
-#include "xbt/dict.h"
-#include "xbt/fifo.h"
-
-typedef struct network_link_CM02 {
- s_surf_resource_lmm_t lmm_resource; /* must remain first to be added to a trace */
-
- /* Using this object with the public part of
- model does not make sense */
- double lat_current;
- tmgr_trace_event_t lat_event;
-} s_link_CM02_t, *link_CM02_t;
-
-typedef struct surf_action_network_CM02 {
- s_surf_action_lmm_t generic_lmm_action;
- double latency;
- double lat_current;
- double weight;
- double rate;
- struct {
- const char* link_name;
- double gap;
- double size;
- xbt_fifo_item_t fifo_item;
- } sender;
-#ifdef HAVE_LATENCY_BOUND_TRACKING
- int latency_limited;
-#endif
-} s_surf_action_network_CM02_t, *surf_action_network_CM02_t;
-
-#endif /* _SURF_NETWORK_PRIVATE_H */
+++ /dev/null
-/* 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. */
-
-/* ********************************************************************* */
-/* 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;
-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
-
-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);
-}
+++ /dev/null
-#include "solver.hpp"
-
-#include "xbt/log.h"
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_maxmin, surf,
- "Logging specific to SURF (maxmin)");
-
-static int Global_debug_id = 1;
-static int Global_const_debug_id = 1;
-
-Solver::Solver(int selectiveUpdate)
-{
- VariablePtr var;
- ConstraintPtr cnst;
-
- m_modified = 0;
- m_selectiveUpdateActive = selectiveUpdate;
- m_visitedCounter = 1;
-
- XBT_DEBUG("Setting selective_update_active flag to %d\n",
- this->m_selectiveUpdateActive);
-
- /*xbt_swag_init(&(l->variable_set),
- xbt_swag_offset(var, variable_set_hookup));
- xbt_swag_init(&(l->constraint_set),
- xbt_swag_offset(cnst, constraint_set_hookup));
-
- xbt_swag_init(&(l->active_constraint_set),
- xbt_swag_offset(cnst, active_constraint_set_hookup));
-
- xbt_swag_init(&(l->modified_constraint_set),
- xbt_swag_offset(cnst, modified_constraint_set_hookup));
- xbt_swag_init(&(l->saturated_variable_set),
- xbt_swag_offset(var, saturated_variable_set_hookup));
- xbt_swag_init(&(l->saturated_constraint_set),
- xbt_swag_offset(cnst, saturated_constraint_set_hookup));
-
- l->variable_mallocator = xbt_mallocator_new(65536,
- lmm_variable_mallocator_new_f,
- lmm_variable_mallocator_free_f,
- lmm_variable_mallocator_reset_f);*/
-}
-
-ConstraintPtr Solver::createConstraint(void *id, double bound)
-{
- ConstraintPtr cnst = m_constraintAllocator.construct(id, bound);
- m_constraintSet.push_back(cnst);
- return cnst;
-}
-
-void Solver::destroyConstraint(Constraint* cnst)
-{
- m_constraintAllocator.destroy(cnst);
-}
-
-
-VariablePtr Solver::createVariable(void *id, double weight, double bound)
-{
- void *mem = m_variableAllocator.malloc();
- VariablePtr var = new (mem) Variable(id, weight, bound, m_visitedCounter - 1);
- var->m_visited = m_visitedCounter - 1;
- if (weight)
- m_variableSet.insert(m_variableSet.begin(), var);
- else
- m_variableSet.push_back(var);
- return var;
-}
-
-void Solver::destroyVariable(Variable* var)
-{
- m_variableAllocator.destroy(var);
-}
-
-void Solver::destroyElement(Element* elem)
-{
- m_elementAllocator.destroy(elem);
-}
-
-void Solver::expand(ConstraintPtr cnst, VariablePtr var, double value)
-{
- m_modified = 1;
-
- ElementPtr elem = m_elementAllocator.construct(cnst, var, value);
- var->m_cnsts.push_back(elem);
-
- if (var->m_weight)
- cnst->m_elementSet.insert(cnst->m_elementSet.begin(), elem);
- else
- cnst->m_elementSet.push_back(elem);
- if(!m_selectiveUpdateActive) {
- activateConstraint(cnst);
- } else if(value>0 || var->m_weight >0) {
- activateConstraint(cnst);
- updateModifiedSet(cnst);
- if (var->m_cnsts.size() > 1)
- updateModifiedSet(var->m_cnsts.front()->p_constraint);
- }
-}
-
-void Solver::expandAdd(ConstraintPtr cnst, VariablePtr var, double value)
-{
- m_modified = 1;
-
- std::vector<ElementPtr>::iterator it;
- for (it=var->m_cnsts.begin(); it!=var->m_cnsts.end(); ++it )
- if ((*it)->p_constraint == cnst)
- break;
-
- if (it != var->m_cnsts.end()) {
- if (cnst->isShared())
- (*it)->m_value += value;
- else
- (*it)->m_value = MAX((*it)->m_value, value);
- updateModifiedSet(cnst);
- } else
- expand(cnst, var, value);
-}
-
-void Solver::elementSetValue(ConstraintPtr cnst, VariablePtr var, double value)
-{
- std::vector<ElementPtr>::iterator it;
- for (it=var->m_cnsts.begin(); it!=var->m_cnsts.end(); ++it ) {
- ElementPtr elem = (*it);
- if (elem->p_constraint == cnst) {
- elem->m_value = value;
- m_modified = 1;
- updateModifiedSet(cnst);
- }
- }
- if (it==var->m_cnsts.end()) {
- DIE_IMPOSSIBLE;
- }
-}
-
-//XBT_INLINE
-ConstraintPtr Variable::getCnst(int num)
-{
- if (num < m_cnsts.size())
- return m_cnsts.at(num)->p_constraint;
- else {
- ConstraintPtr res;
- return res;
- }
-}
-
-//XBT_INLINE
-double Variable::getCnstWeight(int num)
-{
- if (num < m_cnsts.size())
- return (m_cnsts.at(num)->m_value);
- else
- return 0.0;
-}
-
-//XBT_INLINE
-int Variable::getNumberOfCnst()
-{
- return m_cnsts.size();
-}
-
-VariablePtr Constraint::getVar(ElementPtr elem)
-{
- vector<ElementPtr>::iterator it;
- if (!elem)
- elem = m_elementSet.front();
- else
- elem = *(++find(m_elementSet.begin(), m_elementSet.end(), elem));
- if (elem)
- return elem->p_variable;
- else {
- VariablePtr res;
- return res;
- }
-}
-
-//XBT_INLINE
-void* Constraint::id()
-{
- return p_id;
-}
-
-//XBT_INLINE
-void* Variable::id()
-{
- return p_id;
-}
-
-//static XBT_INLINE
-void Solver::saturatedConstraintSetUpdate(double usage,
- ConstraintLightPtr cnstLight,
- vector<ConstraintLightPtr> saturatedConstraintSet,
- double *minUsage)
-{
- xbt_assert(usage > 0,"Impossible");
-
- if (*minUsage < 0 || *minUsage > usage) {
- *minUsage = usage;
- saturatedConstraintSet.clear();
- saturatedConstraintSet.push_back(cnstLight);
- XBT_HERE(" min_usage=%f (cnst->remaining / cnst->usage =%f)", *minUsage, usage);
- } else if (*minUsage == usage) {
- saturatedConstraintSet.push_back(cnstLight);
- }
-}
-
-//static XBT_INLINE
-void Solver::saturatedVariableSetUpdate(vector<ConstraintLightPtr> cnstLightList,
- vector<ConstraintLightPtr> saturatedCnstSet)
-{
- ConstraintLight* cnst = NULL;
- Element* elem = NULL;
- vector<ElementPtr>* elem_list;
- std::vector<ConstraintLightPtr>::iterator it;
- std::vector<ElementPtr>::iterator elemIt;
- for (it=saturatedCnstSet.begin(); it!=saturatedCnstSet.end(); ++it) {
- cnst = (*it);
- elem_list = &(cnst->p_cnst->m_activeElementSet);
- for (elemIt=elem_list->begin(); elemIt!=elem_list->end(); ++elemIt) {
- elem = (*elemIt);
- if (elem->p_variable->m_weight <= 0)
- break;
- if (elem->m_value >0)
- m_saturatedVariableSet.push_back(elem->p_variable);
- }
- }
-}
-
-void Element::activate()
-{
- p_constraint->m_activeElementSet.push_back(this);
-}
-
-void Element::inactivate()
-{
- std::vector<ElementPtr>::iterator it;
- vector<ElementPtr> elemSet = p_constraint->m_activeElementSet;
- it = find(elemSet.begin(), elemSet.end(), this);
- if (it != elemSet.end())
- elemSet.erase(it);
-}
-
-void Solver::activateConstraint(ConstraintPtr cnst)
-{
- m_activeConstraintSet.push_back(cnst);
-}
-
-void Solver::inactivateConstraint(ConstraintPtr cnst)
-{
- std::vector<ConstraintPtr>::iterator it;
- it = find(m_activeConstraintSet.begin(), m_activeConstraintSet.end(), cnst);
- if (it != m_activeConstraintSet.end())
- m_activeConstraintSet.erase(it);
- m_modifiedConstraintSet.erase(std::find(m_modifiedConstraintSet.begin(), m_modifiedConstraintSet.end(), cnst));
-}
-
-template <class T>
-void vector_remove_first(vector<T> vec, T obj) {
- typename vector<T>::iterator it;
- for (it=vec.begin(); it != vec.end(); ++it) {
- if ((*it) == (obj)) {
- vec.erase(it);
- break;
- }
- }
-}
-
-void Solver::print()
-{
- //TODO
-}
-
-void Solver::solve()
-{
- Variable* var = NULL;
- Constraint* cnst = NULL;
- Element* elem = NULL;
- vector<ConstraintPtr>* cnstList = NULL;
- std::vector<ConstraintPtr>::iterator cnstIt;
- vector<VariablePtr>* varList = NULL;
- std::vector<VariablePtr>::iterator varIt;
- vector<ElementPtr>* elemList = NULL;
- std::vector<ElementPtr>::iterator elemIt;
- vector<ElementPtr>* elemListB = NULL;
- std::vector<ElementPtr>::iterator elemItB;
- double minUsage = -1;
- double minBound = -1;
-
- if (!m_modified)
- return;
-
- XBT_IN("(sys=%p)", this);
-
- /*
- * Compute Usage and store the variables that reach the maximum.
- */
- cnstList = m_selectiveUpdateActive ? &m_modifiedConstraintSet :
- &m_activeConstraintSet;
-
- XBT_DEBUG("Active constraintsSolver : %d", cnstList->size());
- /* Init: Only modified code portions */
-
- for (cnstIt=cnstList->begin(); cnstIt!=cnstList->end(); ++cnstIt) {
- elemList = &((*cnstIt)->m_elementSet);
- for (elemIt=elemList->begin(); elemIt!=elemList->end(); ++elemIt) {
- var = ((*elemIt)->p_variable);
- if (var->m_weight <= 0.0)
- break;
- var->m_value = 0.0;
- }
- }
-
- vector<ConstraintLightPtr> cnstLightList;
- std::vector<ConstraintLightPtr>::iterator cnstLightIt;
-
- vector<ConstraintLightPtr> saturatedConstraintSet;
- saturatedConstraintSet.reserve(5);
-
- for (cnstIt=cnstList->begin(); cnstIt!=cnstList->end(); ++cnstIt) {
- /* INIT */
- cnst = (*cnstIt);
- if (cnst->m_remaining == 0)
- continue;
- cnst->m_usage = 0;
- elemList = &(cnst->m_elementSet);
- for (elemIt=elemList->begin(); elemIt!=elemList->end(); ++elemIt) {
- /* 0-weighted elements (ie, sleep actions) are at the end of the swag and we don't want to consider them */
- elem = (*elemIt);
- if (elem->p_variable->m_weight <= 0)
- break;
- if ((elem->m_value > 0)) {
- if (cnst->m_shared)
- cnst->m_usage += elem->m_value / elem->p_variable->m_weight;
- else if (cnst->m_usage < elem->m_value / elem->p_variable->m_weight)
- cnst->m_usage = elem->m_value / elem->p_variable->m_weight;
-
- elem->activate();
- if (m_keepTrack.size()) //TODO: check good semantic
- m_keepTrack.push_back(elem->p_variable->p_id);
- }
- }
- XBT_DEBUG("Constraint Usage '%d' : %f", cnst->m_idInt, cnst->m_usage);
- /* Saturated constraints update */
- if(cnst->m_usage > 0) {
- ConstraintLightPtr cnstLight (new ConstraintLight((*cnstIt), cnst->m_remaining / cnst->m_usage));
- cnst->p_cnstLight = cnstLight;
- saturatedConstraintSetUpdate(cnstLight->m_remainingOverUsage, cnstLight, saturatedConstraintSet, &minUsage);
- cnstLightList.push_back(cnstLight);
- }
- }
-
- saturatedVariableSetUpdate(cnstLightList, saturatedConstraintSet);
-
- /* Saturated variables update */
- do {
- /* Fix the variables that have to be */
- varList = &m_saturatedVariableSet;
-
- for (varIt=varList->begin(); varIt!=varList->end(); ++varIt) {
- var = (*varIt);
- if (var->m_weight <= 0.0) {
- DIE_IMPOSSIBLE;
- }
- /* First check if some of these variables have reach their upper
- bound and update min_usage accordingly. */
- XBT_DEBUG
- ("var=%d, var->bound=%f, var->weight=%f, min_usage=%f, var->bound*var->weight=%f",
- var->m_idInt, var->m_bound, var->m_weight, minUsage,
- var->m_bound * var->m_weight);
-
- if ((var->m_bound > 0) && (var->m_bound * var->m_weight < minUsage)) {
- if (minBound < 0)
- minBound = var->m_bound;
- else
- minBound = MIN(minBound, var->m_bound);
- XBT_DEBUG("Updated min_bound=%f", minBound);
- }
- }
-
- while (varList->size()>0) {
- var = varList->front();
- int i;
-
- if (minBound < 0) {
- var->m_value = minUsage / var->m_weight;
- } else {
- if (minBound == var->m_bound)
- var->m_value = var->m_bound;
- else {
- vector_remove_first(*varList, varList->front());
- continue;
- }
- }
- XBT_DEBUG("Min usage: %f, Var(%d)->weight: %f, Var(%d)->value: %f ",
- minUsage, var->m_idInt, var->m_weight, var->m_idInt, var->m_value);
-
- /* Update usage */
-
- for (elemIt=var->m_cnsts.begin(); elemIt!=var->m_cnsts.end(); ++elemIt) {
- elem = (*elemIt);
- cnst = elem->p_constraint;
- if (cnst->m_shared) {
- double_update(&(cnst->m_remaining), elem->m_value * var->m_value);
- double_update(&(cnst->m_usage), elem->m_value / var->m_weight);
- if(cnst->m_usage<=0 || cnst->m_remaining<=0) {
- if (cnst->p_cnstLight) {
- // TODO: reformat message
- XBT_DEBUG("index: %d \t cnst_light_num: %d \t || \t cnst: %p \t cnst->cnst_light: %p \t cnst_light_tab: %p ",
- elemIt - var->m_cnsts.begin(), var->m_cnsts.size(), cnst, cnst->p_cnstLight, &cnstLightList);
- vector_remove_first(cnstLightList, cnst->p_cnstLight);
- cnst->p_cnstLight = ConstraintLightPtr();
- }
- } else {
- cnst->p_cnstLight->m_remainingOverUsage = cnst->m_remaining / cnst->m_usage;
- }
- elem->inactivate();
- } else {
- cnst->m_usage = 0.0;
- elem->inactivate();
- elemListB = &(cnst->m_elementSet);
- for (elemItB=elemListB->begin(); elemItB!=elemListB->end(); ++elemItB) {
- elem = (*elemItB);
- if (elem->p_variable->m_weight <= 0 || elem->p_variable->m_value > 0)
- break;
- if (elem->m_value > 0)
- cnst->m_usage = MAX(cnst->m_usage, elem->m_value / elem->p_variable->m_weight);
- }
- if (cnst->m_usage<=0 || cnst->m_remaining<=0) {
- if(cnst->p_cnstLight) {
- vector_remove_first(cnstLightList, cnst->p_cnstLight);
- // TODO: reformat message
- XBT_DEBUG("index: %d \t cnst_light_num: %d \t || \t cnst: %p \t cnst->cnst_light: %p \t cnst_light_tab: %p ",
- elemIt - var->m_cnsts.begin(), var->m_cnsts.size(), cnst, cnst->p_cnstLight, &cnstLightList);
- cnst->p_cnstLight = ConstraintLightPtr();
- }
- } else {
- cnst->p_cnstLight->m_remainingOverUsage = cnst->m_remaining / cnst->m_usage;
- }
- }
- }
- vector_remove_first(*varList, varList->front());
- }
-
- /* Find out which variables reach the maximum */
- minUsage = -1;
- minBound = -1;
- m_saturatedConstraintSet.clear();
-
- for (cnstLightIt=cnstLightList.begin(); cnstLightIt!=cnstLightList.end(); ++cnstLightIt)
- saturatedConstraintSetUpdate((*cnstLightIt)->m_remainingOverUsage,
- (*cnstLightIt),
- saturatedConstraintSet,
- &minUsage);
- saturatedVariableSetUpdate(cnstLightList, saturatedConstraintSet);
-
- } while (cnstLightList.size() > 0);
-
- m_modified = 0;
-
- if (m_selectiveUpdateActive)
- removeAllModifiedSet();
-
-
- if (m_selectiveUpdateActive)
- removeAllModifiedSet();
-
- if (XBT_LOG_ISENABLED(surf_maxmin, xbt_log_priority_debug)) {
- print();
- }
-
- /*TODO: xbt_free(saturated_constraint_set->data);
- xbt_free(saturated_constraint_set);
- xbt_free(cnst_light_tab);*/
- XBT_OUT();
-}
-
-/* Not a O(1) function */
-
-void Solver::update(ConstraintPtr cnst, VariablePtr var, double value)
-{
- std::vector<ElementPtr>::iterator it;
- for (it=var->m_cnsts.begin(); it!=var->m_cnsts.end(); ++it )
- if ((*it)->p_constraint == cnst) {
- (*it)->m_value = value;
- m_modified = true;
- updateModifiedSet(cnst);
- return;
- }
-}
-
-/** \brief Attribute the value bound to var->bound.
- *
- * \param sys the lmm_system_t
- * \param var the lmm_variable_t
- * \param bound the new bound to associate with var
- *
- * Makes var->bound equal to bound. Whenever this function is called
- * a change is signed in the system. To
- * avoid false system changing detection it is a good idea to test
- * (bound != 0) before calling it.
- *
- */
-void Solver::updateVariableBound(VariablePtr var, double bound)
-{
- m_modified = 1;
- var->m_bound = bound;
-
- if (var->m_cnsts.size() > 0)
- updateModifiedSet(var->m_cnsts.front()->p_constraint);
-}
-
-void Solver::updateVariableWeight(VariablePtr var, double weight)
-{
- int i;
-
- if (weight == var->m_weight)
- return;
- XBT_IN("(sys=%p, var=%p, weight=%f)", this, var, weight);
- m_modified = 1;
- var->m_weight = weight;
- vector_remove_first(m_variableSet, var);
- if (weight) // TODO: use swap instead
- m_variableSet.insert(m_variableSet.begin(), var);
- else
- m_variableSet.push_back(var);
-
- vector<ElementPtr> elemList;
- vector<ElementPtr>::iterator it;
- for (it=var->m_cnsts.begin(); it!=var->m_cnsts.end(); ++it ) {
- elemList = (*it)->p_constraint->m_elementSet;
- vector_remove_first(elemList, (*it));
- if (weight)
- elemList.insert(elemList.begin(), *it);
- else
- elemList.push_back(*it);
- if (it == var->m_cnsts.begin())
- updateModifiedSet((*it)->p_constraint);
- }
- if (!weight)
- var->m_value = 0.0;
-
- XBT_OUT();
-}
-
-double Variable::getWeight()
-{ return m_weight; }
-
-//XBT_INLINE
-void Solver::updateConstraintBound(ConstraintPtr cnst, double bound)
-{
- m_modified = 1;
- updateModifiedSet(cnst);
- cnst->m_bound = bound;
-}
-
-//XBT_INLINE
-bool Solver::constraintUsed(ConstraintPtr cnst)
-{
- return std::find(m_activeConstraintSet.begin(),
- m_activeConstraintSet.end(), cnst)!=m_activeConstraintSet.end();
-}
-
-//XBT_INLINE
-ConstraintPtr Solver::getFirstActiveConstraint()
-{
- return m_activeConstraintSet.front();
-}
-
-//XBT_INLINE
-ConstraintPtr Solver::getNextActiveConstraint(ConstraintPtr cnst)
-{
- return *(++std::find(m_activeConstraintSet.begin(), m_activeConstraintSet.end(), cnst));
-}
-
-#ifdef HAVE_LATENCY_BOUND_TRACKING
-//XBT_INLINE
-bool Variable::isLimitedByLatency()
-{
- return (double_equals(m_bound, m_value));
-}
-#endif
-
-/** \brief Update the constraint set propagating recursively to
- * other constraints so the system should not be entirely computed.
- *
- * \param sys the lmm_system_t
- * \param cnst the lmm_constraint_t affected by the change
- *
- * A recursive algorithm to optimize the system recalculation selecting only
- * constraints that have changed. Each constraint change is propagated
- * to the list of constraints for each variable.
- */
-//static
-void Solver::updateModifiedSetRec(ConstraintPtr cnst)
-{
- std::vector<ElementPtr>::iterator elemIt;
- for (elemIt=cnst->m_elementSet.begin(); elemIt!=cnst->m_elementSet.end(); ++elemIt) {
- VariablePtr var = (*elemIt)->p_variable;
- vector<ElementPtr> cnsts = var->m_cnsts;
- std::vector<ElementPtr>::iterator cnstIt;
- for (cnstIt=cnsts.begin(); var->m_visited != m_visitedCounter
- && cnstIt!=cnsts.end(); ++cnstIt){
- if ((*cnstIt)->p_constraint != cnst
- && std::find(m_modifiedConstraintSet.begin(),
- m_modifiedConstraintSet.end(), (*cnstIt)->p_constraint)
- == m_modifiedConstraintSet.end()) {
- m_modifiedConstraintSet.push_back((*cnstIt)->p_constraint);
- updateModifiedSetRec((*cnstIt)->p_constraint);
- }
- }
- var->m_visited = m_visitedCounter;
- }
-}
-
-//static
-void Solver::updateModifiedSet(ConstraintPtr cnst)
-{
- /* nothing to do if selective update isn't active */
- if (m_selectiveUpdateActive
- && std::find(m_modifiedConstraintSet.begin(),
- m_modifiedConstraintSet.end(), cnst)
- == m_modifiedConstraintSet.end()) {
- m_modifiedConstraintSet.push_back(cnst);
- updateModifiedSetRec(cnst);
- }
-}
-
-/** \brief Remove all constraints of the modified_constraint_set.
- *
- * \param sys the lmm_system_t
- */
-//static
-void Solver::removeAllModifiedSet()
-{
- if (++m_visitedCounter == 1) {
- /* the counter wrapped around, reset each variable->visited */
- std::vector<VariablePtr>::iterator it;
- for (it=m_variableSet.begin(); it!=m_variableSet.end(); ++it)
- (*it)->m_visited = 0;
- }
- m_modifiedConstraintSet.clear();
-}
-
-inline void Solver::disableVariable(VariablePtr var)
-{
- int i;
- bool m = false;
-
- ElementPtr elem;
-
- XBT_IN("(sys=%p, var=%p)", this, var);
- m_modified = 1;
-
- std::vector<ElementPtr>::iterator varIt, elemIt;
- for (varIt=var->m_cnsts.begin(); varIt!=var->m_cnsts.end(); ) {
- vector<ElementPtr> elemSet = (*varIt)->p_constraint->m_elementSet;
- elemSet.erase(std::find(elemSet.begin(), elemSet.end(), *varIt));
- vector<ElementPtr> activeElemSet = (*varIt)->p_constraint->m_activeElementSet;
- activeElemSet.erase(std::find(activeElemSet.begin(), activeElemSet.end(), *varIt));
- if (elemSet.empty()) {
- inactivateConstraint((*varIt)->p_constraint);
- var->m_cnsts.erase(varIt);
- } else {
- ++varIt;
- m = true;
- }
- }
- if (m)
- updateModifiedSet(var->m_cnsts.front()->p_constraint);
- var->m_cnsts.clear();
-
- XBT_OUT();
-}
-
-Constraint::Constraint(void *id, double bound):
- p_id(id), m_idInt(1), m_bound(bound), m_usage(0), m_shared(1),
- m_elementsZeroWeight(0)
-{
- m_idInt = Global_const_debug_id++;
-}
-
-void Constraint::addElement(ElementPtr elem)
-{
- m_elementSet.push_back(elem);
- if (elem->p_variable->m_weight<0)
- std::swap(m_elementSet[m_elementSet.size()-1], m_elementSet[m_elementsZeroWeight++]);
-}
-
-void Constraint::shared() {
- m_shared = 0;
-}
-
-bool Constraint::isShared() {
- return m_shared;
-}
-
-Variable::Variable(void *id, double weight, double bound, int visited)
-{
- int i;
-
- // TODO: reformat
- XBT_IN("(sys=%p, id=%p, weight=%f, bound=%f, num_cons =%d)",
- 0, id, weight, bound, 0);
-
- p_id = id;
- m_idInt = Global_debug_id++;
-
- // TODO: optimize cache
-
- m_weight = weight;
- m_bound = bound;
- m_value = 0.0;
- m_visited = visited;//sys->visited_counter - 1;
- m_mu = 0.0;
- m_newMu = 0.0;
- //m_func_f = func_f_def;
- //m_func_fp = func_fp_def;
- //m_func_fpi = func_fpi_def;
-
-
- XBT_OUT(" returns %p", this);
-}
-
-double Variable::value()
-{
- return m_value;
-}
-
-double Variable::bound()
-{
- return m_bound;
-}
-
-Element::Element(ConstraintPtr cnst, VariablePtr var, double value):
- p_constraint(cnst), p_variable(var), m_value(value)
-{}
-
+++ /dev/null
-#include <xbt.h>
-#include <math.h>
-
-#ifndef SURF_SOLVER_H_
-#define SURF_SOLVER_H_
-
-static double MAXMIN_PRECISION = 0.001;
-extern double sg_maxmin_precision;
-
-static XBT_INLINE int double_equals(double value1, double value2)
-{
- return (fabs(value1 - value2) < MAXMIN_PRECISION);
-}
-
-static XBT_INLINE void double_update(double *variable, double value)
-{
- *variable -= value;
- if (*variable < MAXMIN_PRECISION)
- *variable = 0.0;
-}
-
-#ifdef __cplusplus
-#include <vector>
-#include <boost/smart_ptr.hpp>
-#include <boost/pool/object_pool.hpp>
-#include <boost/bind.hpp>
-
-using namespace std;
-
-static XBT_INLINE int double_positive(double value)
-{
- return (value > MAXMIN_PRECISION);
-}
-
-class Solver;
-class Element;
-class Constraint;
-class ConstraintLight;
-class Variable;
-
-/*struct ElementPtrOps
-{
- bool operator()( const ElementPtr & a, const ElementPtr & b )
- { return true; } //a > b; }
-};*/
-
-#else
- typedef struct Solver Solver;
- typedef struct Element Element;
- typedef struct Constraint Constraint;
- typedef struct ConstraintLight ConstraintLight;
- typedef struct Variable Variable;
-
-#endif
-typedef Element *ElementPtr;
-typedef Variable *VariablePtr;
-typedef Constraint *ConstraintPtr;
-typedef ConstraintLight *ConstraintLightPtr;
-typedef Solver *SolverPtr;
-
-typedef ElementPtr lmm_element_t;
-typedef VariablePtr lmm_variable_t;
-typedef ConstraintPtr lmm_constraint_t;
-typedef ConstraintLightPtr lmm_constraint_light_t;
-typedef SolverPtr lmm_system_t;
-
-extern double (*func_f_def) (lmm_variable_t, double);
-extern double (*func_fp_def) (lmm_variable_t, double);
-extern double (*func_fpi_def) (lmm_variable_t, double);
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
- extern void _simgrid_log_category__surf_lagrange__constructor__(void);
- extern void _simgrid_log_category__surf_maxmin__constructor__(void);
- extern void _simgrid_log_category__surf_lagrange_dichotomy__constructor__(void);
-
- extern void lmm_set_default_protocol_function(double (*func_f)(lmm_variable_t var, double x),
- double (*func_fp) (lmm_variable_t var, double x),
- double (*func_fpi) (lmm_variable_t var, double x));
- extern double func_reno_f(lmm_variable_t var, double x);
- extern double func_reno_fp(lmm_variable_t var, double x);
- extern double func_reno_fpi(lmm_variable_t var, double x);
- extern double func_reno2_f(lmm_variable_t var, double x);
- extern double func_reno2_fp(lmm_variable_t var, double x);
- extern double func_reno2_fpi(lmm_variable_t var, double x);
- extern double func_vegas_f(lmm_variable_t var, double x);
- extern double func_vegas_fp(lmm_variable_t var, double x);
- extern double func_vegas_fpi(lmm_variable_t var, double x);
-
-
- //extern int double_equals(double value1, double value2);
- //extern void double_update(double *variable, double value);
-
- extern lmm_variable_t lmm_get_var_from_cnst(lmm_system_t sys, lmm_constraint_t cnst, lmm_element_t * elem);
- extern lmm_constraint_t lmm_get_cnst_from_var(lmm_system_t sys, lmm_variable_t var, int num);
- extern double lmm_get_cnst_weight_from_var(lmm_system_t sys, lmm_variable_t var, int num);
- extern int lmm_get_number_of_cnst_from_var(lmm_system_t sys, lmm_variable_t var);
-
- extern lmm_variable_t lmm_variable_new(lmm_system_t sys, void *id,
- double weight_value,
- double bound,
- int number_of_constraints);
- extern void *lmm_variable_id(lmm_variable_t var);
- extern double lmm_variable_getvalue(lmm_variable_t var);
- extern double lmm_get_variable_weight(lmm_variable_t var);
- extern void lmm_variable_free(lmm_system_t sys, lmm_variable_t var);
-
- extern lmm_constraint_t lmm_constraint_new(lmm_system_t sys, void *id,
- double bound_value);
- extern void *lmm_constraint_id(lmm_constraint_t cnst);
- extern void lmm_constraint_shared(lmm_constraint_t cnst);
- extern int lmm_constraint_is_shared(lmm_constraint_t cnst);
- extern int lmm_constraint_used(lmm_system_t sys, lmm_constraint_t cnst);
- extern void lmm_constraint_free(lmm_system_t sys, lmm_constraint_t cnst);
-
- extern lmm_system_t lmm_system_new(int selective_update);
- extern int lmm_system_modified(lmm_system_t solver);
- extern void lmm_expand(lmm_system_t sys, lmm_constraint_t cnst, lmm_variable_t var, double value);
- extern void lmm_expand_add(lmm_system_t sys, lmm_constraint_t cnst,
- lmm_variable_t var, double value);
- extern void lmm_update_variable_bound(lmm_system_t sys, lmm_variable_t var,
- double bound);
- extern void lmm_update_variable_weight(lmm_system_t sys,
- lmm_variable_t var,
- double weight);
- extern void lmm_update_constraint_bound(lmm_system_t sys,
- lmm_constraint_t cnst,
- double bound);
- extern void lmm_solve(lmm_system_t solver);
- extern void lagrange_solve(lmm_system_t solver);
- extern void bottleneck_solve(lmm_system_t solver);
- extern void lmm_system_free(lmm_system_t solver);
-
- extern void c_function(lmm_system_t); /* ANSI C prototypes */
- extern lmm_system_t cplusplus_callback_function(lmm_system_t);
- extern void lmm_print(lmm_system_t sys);
-
- /*********
- * FIXES *
- *********/
- extern int fix_constraint_is_active(lmm_system_t sys, lmm_constraint_t cnst);
-
-#ifdef __cplusplus
-}
-#endif
-
-
-
-
-
-#endif /* SURF_SOLVER_H_ */
+++ /dev/null
-#include <xbt.h>
-#include <vector>
-#include "solver.h"
-#include <boost/pool/object_pool.hpp>
-#include <boost/bind.hpp>
-
-#ifndef SURF_SOLVER_HPP_
-#define SURF_SOLVER_HPP_
-using namespace std;
-
-/*static void double_update(double *variable, double value)
-{
- *variable -= value;
- if (*variable < MAXMIN_PRECISION)
- *variable = 0.0;
-}*/
-
-class Solver;
-class Element;
-class Constraint;
-class ConstraintLight;
-class Variable;
-
-struct ElementOps
-{
- bool operator()( const Element & a, const Element & b )
- { return true; } //a > b; }
-};
-
-class Element {
-public:
- Element(ConstraintPtr cnst, VariablePtr var, double value);
- ConstraintPtr p_constraint;
- VariablePtr p_variable;
- double m_value;
-
- void activate();
- void inactivate();
-};
-
-class ConstraintLight {
-public:
- ConstraintLight(ConstraintPtr cnst, double remainingOverUsage):
- m_remainingOverUsage(remainingOverUsage), p_cnst(cnst) {};
- double m_remainingOverUsage;
- ConstraintPtr p_cnst;
-};
-
-class Constraint {
-public:
- Constraint(void *id, double bound);
- ~Constraint() {
- std::cout << "Del Const:" << m_bound << std::endl;
- };
-
- void shared();
- bool isShared();
- void* id();
- VariablePtr getVar(ElementPtr elem);
- void addElement(ElementPtr elem);
-
- vector<ElementPtr> m_elementSet; /* a list of lmm_element_t */
- int m_elementsZeroWeight;
- vector<ElementPtr> m_activeElementSet; /* a list of lmm_element_t */
- double m_remaining;
- double m_usage;
- double m_bound;
- int m_shared;
- void *p_id;
- int m_idInt;
- double m_lambda;
- double m_newLambda;
- ConstraintLightPtr p_cnstLight;
-};
-
-class Variable {
-public:
- Variable(void *id, double weight, double bound, int visited);
- ~Variable() {
- std::cout << "Del Variable" << std::endl;
- };
-
- double value();
- double bound();
- void* id();
- double getWeight();
- int getNumberOfCnst();
- ConstraintPtr getCnst(int num);
- double getCnstWeight(int num);
- double isLimitedByLatency();
-
- /* \begin{For Lagrange only} */
- double (*p_funcF) (VariablePtr var, double x); /* (f) */
- double (*p_funcFP) (VariablePtr var, double x); /* (f') */
- double (*p_funcFPI) (VariablePtr var, double x); /* (f')^{-1} */
- /* \end{For Lagrange only} */
- vector<ElementPtr> m_cnsts;
-
- unsigned m_visited; /* used by lmm_update_modified_set */
- double m_weight;
- double m_bound;
- double m_value;
- void *p_id;
- int m_idInt;
- double m_mu;
- double m_newMu;
-
-protected:
- /* \begin{For Lagrange only} */
- /* \end{For Lagrange only} */
-};
-
-class Solver {
-public:
- Solver(int selective_update);
- ~Solver() {
- std::cout << "Del Solver" << std::endl;
- }
-
- inline void disableVariable(VariablePtr var);
- ConstraintPtr createConstraint(void *id, double bound_value);
- VariablePtr createVariable(void *id, double weight, double bound);
- void expand(ConstraintPtr cnst, VariablePtr var, double value);
- void expandAdd(ConstraintPtr cnst, VariablePtr var, double value);
- void elementSetValue(ConstraintPtr cnst, VariablePtr var, double value);
- void saturatedConstraintSetUpdate(double usage, ConstraintLightPtr cnstLight,
- vector<ConstraintLightPtr> saturatedConstraintSet,
- double *minUsage);
- void saturatedVariableSetUpdate(vector<ConstraintLightPtr> cnstLightList,
- vector<ConstraintLightPtr> saturatedConstraintSet);
- void solve();
- void update(ConstraintPtr cnst, VariablePtr var, double value);
- void updateVariableBound(VariablePtr var, double bound);
- void updateVariableWeight(VariablePtr var, double weight);
- void updateConstraintBound(ConstraintPtr cnst, double bound);
- bool constraintUsed(ConstraintPtr cnst);
- ConstraintPtr getFirstActiveConstraint();
- ConstraintPtr getNextActiveConstraint(ConstraintPtr cnst);
- void updateModifiedSetRec(ConstraintPtr cnst);
- void updateModifiedSet(ConstraintPtr cnst);
- void removeAllModifiedSet();
- void activateConstraint(ConstraintPtr cnst);
- void inactivateConstraint(ConstraintPtr cnst);
- void print();
-
- vector<VariablePtr> m_variableSet; /* a list of lmm_variable_t */
- vector<VariablePtr> m_saturatedVariableSet; /* a list of lmm_variable_t */
- vector<ConstraintPtr> m_activeConstraintSet; /* a list of lmm_constraint_t */
- vector<ConstraintPtr> m_constraintSet; /* a list of lmm_constraint_t */
- vector<ConstraintPtr> m_modifiedConstraintSet; /* a list of modified lmm_constraint_t */
- vector<ConstraintPtr> m_saturatedConstraintSet; /* a list of lmm_constraint_t_t */
-
- bool m_modified;
-private:
-
-
-protected:
- bool m_selectiveUpdateActive; /* flag to update partially the system only selecting changed portions */
- unsigned m_visitedCounter; /* used by lmm_update_modified_set */
-
-
- boost::object_pool<Constraint> m_constraintAllocator;
- boost::object_pool<Variable> m_variableAllocator;
- boost::object_pool<Element> m_elementAllocator;
- void destroyConstraint(Constraint* cnst);
- void destroyVariable(Variable* var);
- void destroyElement(Element* elem);
-
- vector<void*> m_keepTrack;
-
- //xbt_mallocator_t variable_mallocator;
-};
-
-#endif /* SURF_SOLVER_H_ */
+++ /dev/null
-#include "solver.hpp"
-#include <boost/smart_ptr.hpp>
-#include <boost/pool/object_pool.hpp>
-#include <boost/bind.hpp>
-
-double sg_maxmin_precision = 0.00001;
-#define RENO_SCALING 1.0
-
-void lmm_solve(lmm_system_t solver)
-{
- solver->solve();
-}
-
-void lmm_print(lmm_system_t solver)
-{
- solver->print();
-}
-
-lmm_variable_t lmm_get_var_from_cnst(lmm_system_t sys, lmm_constraint_t cnst, lmm_element_t * elem)
-{
- cnst->getVar(*elem);
-}
-
-lmm_constraint_t lmm_get_cnst_from_var(lmm_system_t sys, lmm_variable_t var, int num)
-{
- var->getCnst(num);
-}
-
-double lmm_get_cnst_weight_from_var(lmm_system_t sys, lmm_variable_t var, int num)
-{
- var->getCnstWeight(num);
-}
-
-int lmm_get_number_of_cnst_from_var(lmm_system_t sys, lmm_variable_t var)
-{
- var->getNumberOfCnst();
-}
-
-lmm_variable_t lmm_variable_new(lmm_system_t sys, void *id,
- double weight_value,
- double bound,
- int number_of_constraints)
-{
- return sys->createVariable(id, weight_value, bound);
-}
-
-void *lmm_variable_id(lmm_variable_t var)
-{
- return var->id();
-}
-
-double lmm_variable_getvalue(lmm_variable_t var)
-{
- return var->m_value;
-}
-
-double lmm_get_variable_weight(lmm_variable_t var)
-{
- return var->m_weight;
-}
-
-void lmm_variable_free(lmm_system_t sys, lmm_variable_t var)
-{
- //TOREPAIR free
-}
-
-lmm_constraint_t lmm_constraint_new(lmm_system_t sys, void *id,
- double bound_value)
-{
- return sys->createConstraint(id, bound_value);
-}
-
-void *lmm_constraint_id(lmm_constraint_t cnst)
-{
- return cnst->id();
-}
-
-void lmm_constraint_shared(lmm_constraint_t cnst)
-{
- cnst->shared();
-}
-
-int lmm_constraint_is_shared(lmm_constraint_t cnst)
-{
- return cnst->isShared();
-}
-
-int lmm_constraint_used(lmm_system_t sys, lmm_constraint_t cnst)
-{
- return (int) sys->constraintUsed(cnst);
-}
-
-void lmm_constraint_free(lmm_system_t sys, lmm_constraint_t cnst)
-{
- //TOREPAIR free
-}
-
-lmm_system_t lmm_system_new(int selective_update) {
- return new Solver(selective_update);
-}
-
-void lmm_system_free(lmm_system_t sys) {
- //TOREPAIR free
-}
-
-int lmm_system_modified(lmm_system_t solver)
-{
- solver->m_modified;
-}
-void lmm_expand(lmm_system_t sys, lmm_constraint_t cnst, lmm_variable_t var, double value)
-{
- sys->expand(cnst, var, value);
-}
-
-void lmm_expand_add(lmm_system_t sys, lmm_constraint_t cnst,
- lmm_variable_t var, double value)
-{
- sys->expandAdd(cnst, var, value);
-}
-
-void lmm_update_variable_bound(lmm_system_t sys, lmm_variable_t var,
- double bound)
-{
- sys->updateVariableBound(var, bound);
-}
-
-void lmm_update_variable_weight(lmm_system_t sys,
- lmm_variable_t var,
- double weight)
-{
- sys->updateVariableWeight(var, weight);
-}
-
-void lmm_update_constraint_bound(lmm_system_t sys,
- lmm_constraint_t cnst,
- double bound)
-{
- sys->updateConstraintBound(cnst, bound);
-}
-
-
-/*********
- * FIXES *
- *********/
-int fix_constraint_is_active(lmm_system_t sys, lmm_constraint_t cnst)
-{
- int found = 0;
- std::vector<ConstraintPtr>::iterator cnstIt;
- lmm_constraint_t cnst_tmp;
- for (cnstIt=sys->m_activeConstraintSet.begin(); cnstIt!=sys->m_activeConstraintSet.end(); ++cnstIt) {
- cnst_tmp = *cnstIt;
- if (cnst_tmp == cnst) {
- found = 1;
- break;
- }
- }
- return found;
-}
-
+++ /dev/null
-/* 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"
-#include <inttypes.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, sg_storage_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, sg_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_homogeneous(xbt_free);
-
- char* key;
- sg_storage_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){
- sg_storage_size_t *psize = xbt_new(sg_storage_size_t,1);
- *psize=size;
- xbt_dict_set(ls_dict,file,psize,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;
- sg_storage_size_t size, *psize;
- psize = (sg_storage_size_t*) xbt_dict_get_or_null(content_dict, path);
- if (psize)
- size = *psize;
- else {
- // if file does not exist create an empty file
- psize = xbt_new(sg_storage_size_t,1);
- size = 0;
- *psize = size;
- xbt_dict_set(content_dict,path,psize,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->mount = 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 '%" PRIu64 "'", 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->mount);
- xbt_free(fd);
- surf_action_t action = storage_action_execute(storage,0, CLOSE);
- return action;
-}
-
-static surf_action_t storage_action_read(void *storage, surf_file_t fd, sg_storage_size_t size)
-{
- 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, surf_file_t fd, sg_storage_size_t size)
-{
- char *filename = fd->name;
- XBT_DEBUG("\tWrite file '%s' size '%" PRIu64 "/%" PRIu64 "'",
- 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, sg_storage_size_t size, e_surf_action_storage_type_t type)
-{
- surf_action_storage_t action = NULL;
- storage_t STORAGE = storage;
-
- XBT_IN("(%s,%" PRIu64, 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... */
-
- 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 xbt_dict_t storage_get_properties(const void *storage)
-{
- return surf_resource_properties(surf_storage_resource_priv(storage));
-}
-
-static xbt_dict_t storage_get_content(void *storage)
-{
- /* For the moment this action has no cost, but in the future we could take in account access latency of the disk */
- /*surf_action_t action = storage_action_execute(storage,0, LS);*/
-
- void *storage_resource = surf_storage_resource_priv(storage);
- xbt_dict_t content_dict = xbt_dict_new_homogeneous(NULL);
- xbt_dict_cursor_t cursor = NULL;
- char *file;
- sg_storage_size_t *psize;
-
- xbt_dict_foreach(((storage_t)storage_resource)->content, cursor, file, psize){
- xbt_dict_set(content_dict,file,psize,NULL);
- }
- return content_dict;
-}
-
-static sg_storage_size_t storage_get_size(void *storage){
- void *storage_resource = surf_storage_resource_priv(storage);
- return ((storage_t)storage_resource)->size;
-}
-
-static void* storage_create_resource(const char* id, const char* model,
- const char* type_id, const char* content_name, const char* content_type, xbt_dict_t properties){
- 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, properties, 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 =
- surf_parse_get_bandwidth(xbt_dict_get(storage_type->properties,"Bread"));
- double Bwrite =
- surf_parse_get_bandwidth(xbt_dict_get(storage_type->properties,"Bwrite"));
- double Bconnection =
- surf_parse_get_bandwidth(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);
- 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->content_type = xbt_strdup(content_type);
- storage->size = storage_type->size;
- storage->type_id = xbt_strdup(type_id);
-
- 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;
-
-
- xbt_swag_foreach_safe(action, next_action, running_actions) {
- if(action->type == WRITE)
- {
- // Update the disk usage
- // Update the file size
- // Update the storage content (with file size)
- 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 sg_storage_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
-
- sg_storage_size_t *psize = xbt_new(sg_storage_size_t,1);
- *psize = ((surf_action_t)action)->file->size;
-
- xbt_dict_t content_dict = ((storage_t)(action->storage))->content;
- xbt_dict_set(content_dict,((surf_action_t)action)->file->name,psize,NULL);
- }
-
- 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;
- storage->content_type = ((storage_type_t) stype)->content_type;
- XBT_DEBUG("For disk '%s' content is empty, inherit the content (of type %s) from storage type '%s' ",
- storage->id,((storage_type_t) stype)->content_type,
- ((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\tcontent_type '%s' "
- "\n\t\tproperties '%p'\n",
- storage->id,
- ((storage_type_t) stype)->model,
- ((storage_type_t) stype)->type_id,
- storage->content,
- storage->content_type,
- ((storage_type_t) stype)->properties);
-
- storage_create_resource(storage->id,
- ((storage_type_t) stype)->model,
- ((storage_type_t) stype)->type_id,
- storage->content,
- storage->content_type,
- storage->properties);
-}
-
-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;
- surf_storage_model->extension.storage.get_properties = storage_get_properties;
- surf_storage_model->extension.storage.get_content = storage_get_content;
- surf_storage_model->extension.storage.get_size = storage_get_size;
- 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, sg_storage_size_t *used_size)
-{
- *used_size = 0;
- if ((!filename) || (strcmp(filename, "") == 0))
- return NULL;
-
- xbt_dict_t parse_content = xbt_dict_new_homogeneous(xbt_free);
- 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];
- sg_storage_size_t size;
-
- while ((read = xbt_getline(&line, &len, file)) != -1) {
- if (read){
- if (sscanf(line,"%s %" SCNu64, path, &size) == 2) {
- *used_size += size;
- sg_storage_size_t *psize = xbt_new(sg_storage_size_t, 1);
- *psize = size;
- xbt_dict_set(parse_content,path,psize,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->content_type = xbt_strdup(storage_type->content_type);
- stype->type_id = xbt_strdup(storage_type->id);
- stype->size = storage_type->size;
-
- XBT_DEBUG("ROUTING Create a storage type id '%s' with model '%s', "
- "content '%s', and content_type '%s'",
- stype->type_id,
- stype->model,
- storage_type->content,
- storage_type->content_type);
-
- 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->storageId,ROUTING_STORAGE_LEVEL);
-#endif
- xbt_assert(storage,"Disk id \"%s\" does not exists", mount->storageId);
-
- XBT_DEBUG("ROUTING Mount '%s' on '%s'",mount->storageId, mount->name);
-
- s_mount_t mnt;
- mnt.storage =
- surf_storage_resource_priv(surf_storage_resource_by_name(mount->storageId));
- 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);
- free(stype->content_type);
- 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);
- free(storage->type_id);
- free(storage->content_type);
- // 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);
-}
-
+++ /dev/null
-/* Copyright (c) 2009, 2012-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. */
-
-#ifndef STORAGE_PRIVATE_H_
-#define STORAGE_PRIVATE_H_
-
-typedef struct s_storage_type {
- char *model;
- char *content;
- char *content_type;
- char *type_id;
- xbt_dict_t properties;
- sg_storage_size_t size;
-} s_storage_type_t, *storage_type_t;
-
-typedef struct s_mount {
- void *storage;
- char *name;
-} s_mount_t, *mount_t;
-
-typedef struct surf_file {
- char *name;
- char *mount;
- sg_storage_size_t size;
-} s_surf_file_t;
-
-<<<<<<< HEAD
-typedef struct storage {
- //FIXME:s_surf_resource_t generic_resource; /*< Structure with generic data. Needed at begin to interact with SURF */
-||||||| merged common ancestors
-typedef struct storage {
- s_surf_resource_t generic_resource; /*< Structure with generic data. Needed at begin to interact with SURF */
-=======
-typedef struct surf_storage {
- s_surf_resource_t generic_resource; /*< Structure with generic data. Needed at begin to interact with SURF */
->>>>>>> 045db1657e870c721be490b411868f4181a12ced
- e_surf_resource_state_t state_current; /*< STORAGE current state (ON or OFF) */
- lmm_constraint_t constraint; /* Constraint for maximum bandwidth from connection */
- lmm_constraint_t constraint_write; /* Constraint for maximum write bandwidth*/
- lmm_constraint_t constraint_read; /* Constraint for maximum write bandwidth*/
- xbt_dict_t content;
- char* content_type;
- sg_storage_size_t size;
- sg_storage_size_t used_size;
- char *type_id;
- xbt_dynar_t write_actions;
- xbt_dict_t properties;
-} s_storage_t, *storage_t;
-
-typedef enum {
- READ=0, WRITE, STAT, OPEN, CLOSE, LS
-} e_surf_action_storage_type_t;
-
-typedef struct surf_action_storage {
- //FIXME:s_surf_action_lmm_t generic_lmm_action;
- e_surf_action_storage_type_t type;
- void *storage;
-} s_surf_action_storage_t, *surf_action_storage_t;
-
-#endif /* STORAGE_PRIVATE_H_ */
+++ /dev/null
-/* 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 "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 <ctype.h>
-
-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 <windows.h>
-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;
-xbt_dynar_t host_that_restart = NULL;
-xbt_dict_t watched_hosts_lib;
-
-/* 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 %f Finish %f Max_duration %f", 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 %f now %f", 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 %f", 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_homogeneous(NULL);
-
- 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;
-
-#ifdef HAVE_TRACING
- TRACE_end(); /* Just in case it was not called by the upper
- * layer (or there is no upper layer) */
-#endif
-
- 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(&host_that_restart);
- 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(!host_that_restart)
- host_that_restart = xbt_dynar_new(sizeof(char*), NULL);
-
- 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) ||
- xbt_dict_get_or_null(watched_hosts_lib,resource->name)
- ) {
- 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 %f",
- resource->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);
-}
-
sg_config_init(argc, argv);
- surf_action_init();
if (MC_is_active())
MC_memory_init();
}
tmgr_history_free(history);
history = NULL;
}
- surf_action_exit();
#ifdef CONTEXT_THREADS
xbt_parmap_destroy(surf_parmap);
"SURF_ACTION_NOT_IN_THE_SYSTEM"
};
-/**
- * \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
- */
- /*FIXME: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) {
- //FIXME:xbt_mallocator_free(action_mallocator);
-}
-
Action::Action(){}
Action::Action(ModelPtr model, double cost, bool failed):
+++ /dev/null
-/* Copyright (c) 2009-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 "surf_private.h"
-#include "network_private.h"
-#include "maxmin_private.h"
-#include "surf/datatypes.h"
-#include "cpu_cas01_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;
-}
-
-double 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 %f, last_update was: %f", 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 %f", 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;
-}
-
-/**
- * Update the CPU total energy for a finished action
- *
- */
-void update_resource_energy(surf_model_t model, surf_action_lmm_t action)
-{
- if(model == surf_cpu_model){
- cpu_Cas01_t cpu_model = (cpu_Cas01_t)lmm_constraint_id(lmm_get_cnst_from_var
- (model->model_private->maxmin_system,
- action->variable, 0));
-
- if( cpu_model->energy->last_updated < surf_get_clock()) {
- double load = lmm_constraint_get_usage(cpu_model->constraint) / cpu_model->power_peak;
- cpu_update_energy(cpu_model, load);
- }
- }
-}
-
-
-
-
-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();
-
- update_resource_energy(model, 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);
- }
-
- update_resource_energy(model, action);
- }
-
- return;
-}
+++ /dev/null
-#include <xbt.h>
-
-#ifndef SURF_SOLVER_H_
-#define SURF_SOLVER_H_
-
-static double MAXMIN_PRECISION = 0.001;
-
-
-#ifdef __cplusplus
-#include <vector>
-#include <boost/smart_ptr.hpp>
-#include <boost/pool/object_pool.hpp>
-#include <boost/bind.hpp>
-
-static void double_update(double *variable, double value)
-{
- *variable -= value;
- if (*variable < MAXMIN_PRECISION)
- *variable = 0.0;
-}
-
-using namespace std;
-
-class Solver;
-typedef boost::shared_ptr<Solver> SolverPtr;
-
-class Element;
-typedef boost::shared_ptr<Element> ElementPtr;
-
-class Constraint;
-typedef boost::shared_ptr<Constraint> ConstraintPtr;
-
-class ConstraintLight;
-typedef boost::shared_ptr<ConstraintLight> ConstraintLightPtr;
-
-class Variable;
-typedef boost::shared_ptr<Variable> VariablePtr;
-
-struct ElementPtrOps
-{
- bool operator()( const ElementPtr & a, const ElementPtr & b )
- { return true; } //a > b; }
-};
-
-#else
- typedef struct Solver Solver;
- typedef struct Element Element;
- typedef struct Constraint Constraint;
- typedef struct ConstraintLight ConstraintLight;
- typedef struct Variable Variable;
-
-#endif
-
-typedef Element *lmm_element_t;
-typedef Variable *lmm_variable_t;
-typedef Constraint *lmm_constraint_t;
-typedef ConstraintLight *lmm_constraint_light_t;
-typedef Solver *lmm_system_t;
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#if defined(__STDC__) || defined(__cplusplus)
- extern lmm_system_t lmm_system_new(int selective_update);
-
- extern void c_function(Solver*); /* ANSI C prototypes */
- extern Solver* cplusplus_callback_function(Solver*);
-
-#else
- extern lmm_system_t lmm_system_new(int selective_update);
-
- extern void c_function(); /* K&R style */
- extern Solver* cplusplus_callback_function();
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-
-
-
-
-#endif /* SURF_SOLVER_H_ */
+++ /dev/null
-
-/* Copyright (c) 2009-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. */
-
-#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);
-}
UM_UNDEFINED
} e_UM_t;
-typedef struct surf_model_private {
- int (*resource_used) (void *resource_id);
- /* Share the resources to the actions and return in how much time
- the next action may terminate */
- double (*share_resources) (double now);
- /* Update the actions' state */
- void (*update_actions_state) (double now, double delta);
- void (*update_resource_state) (void *id, tmgr_trace_event_t event_type,
- double value, double time);
- void (*finalize) (void);
-
- lmm_system_t maxmin_system;
- e_UM_t update_mechanism;
- xbt_swag_t modified_set;
- xbt_heap_t action_heap;
- int selective_update;
-
-} s_surf_model_private_t;
-
-/*FIXME:REMOVEdouble generic_maxmin_share_resources(xbt_swag_t running_actions,
- size_t offset,
- lmm_system_t sys,
- void (*solve) (lmm_system_t));*/
-double generic_share_resources_lazy(double now, surf_model_t model);
-
/* Generic functions common to all models */
-void surf_action_init(void);
-void surf_action_exit(void);
-e_surf_action_state_t surf_action_state_get(surf_action_t action); /* cannot declare inline since we use a pointer to it */
-//FIXME:DELETEdouble surf_action_get_start_time(surf_action_t action); /* cannot declare inline since we use a pointer to it */
-double surf_action_get_finish_time(surf_action_t action); /* cannot declare inline since we use a pointer to it */
-void surf_action_free(surf_action_t * action);
-/*FIXME:void surf_action_state_set(surf_action_t action,
- e_surf_action_state_t state);*/
-//FIXME:void surf_action_data_set(surf_action_t action, void *data); /* cannot declare inline since we use a pointer to it */
-
-void surf_action_lmm_update_index_heap(void *action, int i); /* callback for heap management shared by cpu and net models */
-/*FIXME:void surf_action_lmm_heap_insert(xbt_heap_t heap, surf_action_lmm_t action,
- double key, enum heap_action_type hat);*/
-void surf_action_lmm_heap_remove(xbt_heap_t heap,surf_action_lmm_t action);
-
-void surf_action_cancel(surf_action_t action);
-//FIXME:removeint surf_action_unref(surf_action_t action);
-void surf_action_suspend(surf_action_t action);
-void surf_action_resume(surf_action_t action);
-int surf_action_is_suspended(surf_action_t action);
-void surf_action_set_max_duration(surf_action_t action, double duration);
-void surf_action_set_priority(surf_action_t action, double priority);
-#ifdef HAVE_TRACING
-void surf_action_set_category(surf_action_t action,
- const char *category);
-#endif
-double surf_action_get_remains(surf_action_t action);
-void update_resource_energy(surf_model_t model, surf_action_lmm_t action);
-void generic_update_action_remaining_lazy( surf_action_lmm_t action, double now);
-void generic_update_actions_state_lazy(double now, double delta, surf_model_t model);
-void generic_update_actions_state_full(double now, double delta, surf_model_t model);
FILE *surf_fopen(const char *name, const char *mode);
extern tmgr_history_t history;
-//void surf_config_init(int *argc, char **argv);
-//void surf_config_finalize(void);
-//void surf_config(const char *name, va_list pa);
-
-void net_action_recycle(surf_action_t action);
-#ifdef HAVE_LATENCY_BOUND_TRACKING
-int net_get_link_latency_limited(surf_action_t action);
-#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);
-typedef struct s_routing_edge {
- AS_t rc_component;
- e_surf_network_element_type_t rc_type;
- int id;
- char *name;
-} s_routing_edge_t;
-
-/*
- * Link of lenght 1, alongside with its source and destination. This is mainly usefull in the bindings to gtnets and ns3
- */
-typedef struct s_onelink {
- sg_routing_edge_t src;
- sg_routing_edge_t dst;
- void *link_ptr;
-} s_onelink_t, *onelink_t;
-
/**
* Routing logic
*/
SURF_ROUTING_RECURSIVE /**< Recursive case: also return gateway informations */
} e_surf_routing_hierarchy_t;
-typedef struct s_as {
- xbt_dynar_t index_network_elm;
- xbt_dict_t bypassRoutes; /* store bypass routes */
- routing_model_description_t model_desc;
- e_surf_routing_hierarchy_t hierarchy;
- char *name;
- struct s_as *routing_father;
- xbt_dict_t routing_sons;
- sg_routing_edge_t net_elem;
- xbt_dynar_t link_up_down_list;
-
- void (*get_route_and_latency) (AS_t as, sg_routing_edge_t src, sg_routing_edge_t dst, sg_platf_route_cbarg_t into, double *latency);
-
- xbt_dynar_t(*get_onelink_routes) (AS_t as);
- void (*get_graph) (xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges, AS_t rc);
- sg_platf_route_cbarg_t(*get_bypass_route) (AS_t as, sg_routing_edge_t src, sg_routing_edge_t dst, double *lat);
- void (*finalize) (AS_t as);
-
-
- /* The parser calls the following functions to inform the routing models
- * that a new element is added to the AS currently built.
- *
- * Of course, only the routing model of this AS is informed, not every ones */
- int (*parse_PU) (AS_t as, sg_routing_edge_t elm); /* A host or a router, whatever */
- int (*parse_AS) (AS_t as, sg_routing_edge_t elm);
- void (*parse_route) (AS_t as, sg_platf_route_cbarg_t route);
- void (*parse_ASroute) (AS_t as, sg_platf_route_cbarg_t route);
- void (*parse_bypassroute) (AS_t as, sg_platf_route_cbarg_t e_route);
-
-} s_as_t;
-
-struct s_routing_platf {
- AS_t root;
- void *loopback;
- xbt_dynar_t last_route;
- xbt_dynar_t(*get_onelink_routes) (void);
-};
-
XBT_PUBLIC(void) routing_model_create(void *loopback);
XBT_PUBLIC(void) routing_exit(void);
XBT_PUBLIC(void) storage_register_callbacks(void);
+
/* ***************************************** */
/* TUTORIAL: New TAG */
XBT_PUBLIC(void) gpu_register_callbacks(void);
+++ /dev/null
-
-#ifndef SURF_PRIVATE_HPP_
-#define SURF_PRIVATE_HPP_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-FILE *surf_fopen(const char *name, const char *mode);
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif /* SURF_PRIVATE_HPP_ */
#include "surf.hpp"
+#include <float.h>
#ifndef NETWORK_ROUTING_HPP_
#define NETWORK_ROUTING_HPP_
void routing_model_create( void *loopback);
+/* ************************************************************************** */
+/* ************************* GRAPH EXPORTING FUNCTIONS ********************** */
+xbt_node_t new_xbt_graph_node (xbt_graph_t graph, const char *name, xbt_dict_t nodes);
+xbt_edge_t new_xbt_graph_edge (xbt_graph_t graph, xbt_node_t s, xbt_node_t d, xbt_dict_t edges);
+
/***********
* Classes *
***********/
*/
class Onelink {
public:
+ Onelink(void *link, RoutingEdgePtr src, RoutingEdgePtr dst)
+ : p_link(link), p_src(src), p_dst(dst) {};
RoutingEdgePtr p_src;
RoutingEdgePtr p_dst;
- void *p_linkPtr;
+ void *p_link;
};
class RoutingPlatf {
+++ /dev/null
-/* Copyright (c) 2009-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 "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;
-}
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "surf_routing_cluster.hpp"
-#include "surf_routing_private.h"
extern "C" {
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_cluster, surf, "Routing part of surf");
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "surf_routing_dijkstra.hpp"
-#include "surf_routing_private.h"
#include "network.hpp"
/* Global vars */
if (xbt_dynar_length(route->link_list) == 1) {
void *link = *(void **) xbt_dynar_get_ptr(route->link_list, 0);
- OnelinkPtr onelink = new Onelink();
- onelink->p_linkPtr = link;
- if (p_hierarchy == SURF_ROUTING_BASE) {
- onelink->p_src = src_elm;
- onelink->p_dst = dst_elm;
- } else if (p_hierarchy == SURF_ROUTING_RECURSIVE) {
- onelink->p_src = route->gw_src;
- onelink->p_dst = route->gw_dst;
- }
+ OnelinkPtr onelink;
+ if (p_hierarchy == SURF_ROUTING_BASE)
+ onelink = new Onelink(link, src_elm, dst_elm);
+ else if (p_hierarchy == SURF_ROUTING_RECURSIVE)
+ onelink = new Onelink(link, route->gw_src, route->gw_dst);
+ else
+ onelink = new Onelink(link, NULL, NULL);
xbt_dynar_push(ret, &onelink);
}
}
/* 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 "surf_routing_floyd.hpp"
#include "network.hpp"
/* Business methods */
xbt_dynar_t AsFloyd::getOneLinkRoutes()
{
- xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
+ xbt_dynar_t ret = xbt_dynar_new(sizeof(OnelinkPtr), 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);
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 (p_hierarchy == SURF_ROUTING_BASE) {
- onelink->src = src_elm;
- onelink->dst = dst_elm;
- } else if (p_hierarchy == SURF_ROUTING_RECURSIVE) {
- onelink->src = route->gw_src;
- onelink->dst = route->gw_dst;
- }
+ OnelinkPtr onelink;
+ if (p_hierarchy == SURF_ROUTING_BASE)
+ onelink = new Onelink(link, src_elm, dst_elm);
+ else if (p_hierarchy == SURF_ROUTING_RECURSIVE)
+ onelink = new Onelink(link, route->gw_src, route->gw_dst);
+ else
+ onelink = new Onelink(link, NULL, NULL);
xbt_dynar_push(ret, &onelink);
}
}
/* 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 "surf_routing_full.hpp"
#include "network.hpp"
xbt_dynar_t AsFull::getOneLinkRoutes()
{
- xbt_dynar_t ret = xbt_dynar_new(sizeof(onelink_t), xbt_free);
+ xbt_dynar_t ret = xbt_dynar_new(sizeof(OnelinkPtr), xbt_free);
int src, dst;
int table_size = xbt_dynar_length(p_indexNetworkElm);
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;
+ OnelinkPtr onelink;
if (p_hierarchy == SURF_ROUTING_BASE) {
- onelink->src = xbt_dynar_get_as(p_indexNetworkElm, src, sg_routing_edge_t);
- onelink->src->m_id = src;
- onelink->dst = xbt_dynar_get_as(p_indexNetworkElm, dst, sg_routing_edge_t);
- onelink->dst->m_id = dst;
- } else if (p_hierarchy == SURF_ROUTING_RECURSIVE) {
- onelink->src = route->gw_src;
- onelink->dst = route->gw_dst;
- }
+ RoutingEdgePtr tmp_src = xbt_dynar_get_as(p_indexNetworkElm, src, sg_routing_edge_t);
+ tmp_src->m_id = src;
+ RoutingEdgePtr tmp_dst = xbt_dynar_get_as(p_indexNetworkElm, dst, sg_routing_edge_t);
+ tmp_dst->m_id = dst;
+ onelink = new Onelink(link, tmp_src, tmp_dst);
+ } else if (p_hierarchy == SURF_ROUTING_RECURSIVE)
+ onelink = new Onelink(link, route->gw_src, route->gw_dst);
+ else
+ onelink = new Onelink(link, NULL, NULL);
xbt_dynar_push(ret, &onelink);
XBT_DEBUG("Push route from '%d' to '%d'",
src,
+++ /dev/null
-/* Copyright (c) 2009-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 "surf_routing_private.h"
-
-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);
-}
-
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "surf_routing_none.hpp"
-#include "surf_routing_private.h"
extern "C" {
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_none, surf, "Routing part of surf");
+++ /dev/null
-/* Copyright (c) 2009-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. */
-
-#ifndef _SURF_SURF_ROUTING_PRIVATE_H
-#define _SURF_SURF_ROUTING_PRIVATE_H
-
-#include <float.h>
-#include "internal_config.h"
-
-//#include "surf_private.h"
-#include "xbt/dynar.h"
-#include "xbt/str.h"
-#include "xbt/config.h"
-#include "xbt/graph.h"
-#include "xbt/set.h"
-#include "surf/surfxml_parse.h"
-#include "surf_routing.hpp"
-
-/* ************************************************************************** */
-/* ******************************* NO ROUTING ******************************* */
-/* Only save the AS tree, and forward calls to child ASes */
-AsPtr model_none_create(void);
-AsPtr model_none_create_sized(size_t childsize);
-void model_none_finalize(AsPtr as);
-/* ************************************************************************** */
-/* ***************** GENERIC PARSE FUNCTIONS (declarations) ***************** */
-AsPtr model_generic_create_sized(size_t childsize);
-void model_generic_finalize(AsPtr as);
-
-int generic_parse_PU(AsPtr rc, RoutingEdgePtr elm);
-int generic_parse_AS(AsPtr rc, RoutingEdgePtr elm);
-void generic_parse_bypassroute(AsPtr rc, sg_platf_route_cbarg_t e_route);
-
-/* ************************************************************************** */
-/* *************** GENERIC BUSINESS METHODS (declarations) ****************** */
-
-xbt_dynar_t generic_get_onelink_routes(AsPtr rc);
-sg_platf_route_cbarg_t generic_get_bypassroute(AsPtr rc,
- RoutingEdgePtr src,
- RoutingEdgePtr dst,
- double *lat);
-
-/* ************************************************************************** */
-/* ****************** GENERIC AUX FUNCTIONS (declarations) ****************** */
-
-/* change a route containing link names into a route containing link entities.
- * If change_order is true, the links are put in reverse order in the
- * produced route */
-sg_platf_route_cbarg_t generic_new_extended_route(e_surf_routing_hierarchy_t hierarchy,
- sg_platf_route_cbarg_t data, int preserve_order);
-AsPtr
-generic_autonomous_system_exist(AsPtr rc, char *element);
-AsPtr
-generic_processing_units_exist(AsPtr rc, char *element);
-void generic_src_dst_check(AsPtr rc, RoutingEdgePtr src,
- RoutingEdgePtr dst);
-
-/* ************************************************************************** */
-/* *************************** FLOYD ROUTING ******************************** */
-AsPtr model_floyd_create(void); /* create structures for floyd routing model */
-void model_floyd_end(AsPtr as); /* finalize the creation of floyd routing model */
-void model_floyd_parse_route(AsPtr rc, sg_platf_route_cbarg_t route);
-
-AsPtr model_cluster_create(void); /* create structures for cluster routing model */
-
-/* ************************************************** */
-/* ************** Vivaldi ROUTING **************** */
-AsPtr model_vivaldi_create(void); /* create structures for vivaldi routing model */
-#define HOST_PEER(peername) bprintf("peer_%s", peername)
-#define ROUTER_PEER(peername) bprintf("router_%s", peername)
-#define LINK_PEER(peername) bprintf("link_%s", peername)
-
-/* ************************************************************************** */
-/* ********** Dijkstra & Dijkstra Cached ROUTING **************************** */
-AsPtr model_dijkstra_both_create(int cached); /* create by calling dijkstra or dijkstracache */
-AsPtr model_dijkstra_create(void); /* create structures for dijkstra routing model */
-AsPtr model_dijkstracache_create(void); /* create structures for dijkstracache routing model */
-void model_dijkstra_both_end(AsPtr as); /* finalize the creation of dijkstra routing model */
-void model_dijkstra_both_parse_route (AsPtr rc, sg_platf_route_cbarg_t route);
-
-/* ************************************************************************** */
-/* *************************** FULL ROUTING ********************************* */
-AsPtr model_full_create(void); /* create structures for full routing model */
-void model_full_end(AsPtr as); /* finalize the creation of full routing model */
-void model_full_set_route( /* Set the route and ASroute between src and dst */
- AsPtr rc, sg_platf_route_cbarg_t route);
-/* ************************************************************************** */
-/* ************************* GRAPH EXPORTING FUNCTIONS ********************** */
-xbt_node_t new_xbt_graph_node (xbt_graph_t graph, const char *name, xbt_dict_t nodes);
-xbt_edge_t new_xbt_graph_edge (xbt_graph_t graph, xbt_node_t s, xbt_node_t d, xbt_dict_t edges);
-
-
-#endif /* _SURF_SURF_ROUTING_PRIVATE_H */
+++ /dev/null
-/* Copyright (c) 2009-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 "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) {
- char *rp_src = ROUTER_PEER(src);
- char *rp_dst = ROUTER_PEER(dst);
- route->gw_src = xbt_lib_get_or_null(as_router_lib, rp_src,
- ROUTING_ASR_LEVEL);
- route->gw_dst = xbt_lib_get_or_null(as_router_lib, rp_dst,
- ROUTING_ASR_LEVEL);
- xbt_free(rp_src);
- xbt_free(rp_dst);
- }
-
- 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;
-}
-#include "surf_routing_private.h"
#include "surf_routing_vivaldi.hpp"
extern "C" {
#ifndef SURF_ROUTING_VIVALDI_HPP_
#define SURF_ROUTING_VIVALDI_HPP_
+/* ************************************************** */
+/* ************** Vivaldi ROUTING **************** */
+AS_t model_vivaldi_create(void); /* create structures for vivaldi routing model */
+#define HOST_PEER(peername) bprintf("peer_%s", peername)
+#define ROUTER_PEER(peername) bprintf("router_%s", peername)
+#define LINK_PEER(peername) bprintf("link_%s", peername)
+
/***********
* Classes *
***********/
+++ /dev/null
-/* 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"
-#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 double ws_get_current_power_peak(void *workstation)
-{
- return surf_cpu_model->extension.cpu.
- get_current_power_peak(workstation);
-}
-
-static double ws_get_power_peak_at(void *workstation, int pstate_index)
-{
- return surf_cpu_model->extension.cpu.
- get_power_peak_at(workstation, pstate_index);
-}
-
-static int ws_get_nb_pstates(void *workstation)
-{
- return surf_cpu_model->extension.cpu.
- get_nb_pstates(workstation);
-}
-
-static void ws_set_power_peak_at(void *workstation, int pstate_index)
-{
- surf_cpu_model->extension.cpu.
- set_power_peak_at(workstation, pstate_index);
-}
-
-static double ws_get_consumed_energy(void *workstation)
-{
- return surf_cpu_model->extension.cpu.
- get_consumed_energy(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* mount)
-{
- 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'",mount,ws->generic_resource.name);
- xbt_dynar_foreach(storage_list,cursor,mnt)
- {
- XBT_DEBUG("See '%s'",mnt.name);
- if(!strcmp(mount,mnt.name)){
- st = mnt.storage;
- break;
- }
- }
- if(!st) xbt_die("Can't find mount '%s' for '%s'",mount,ws->generic_resource.name);
- return st;
-}
-
-static xbt_dict_t ws_get_storage_list(void *workstation)
-{
- s_mount_t mnt;
- unsigned int i;
- xbt_dict_t storage_list = xbt_dict_new_homogeneous(NULL);
- char *storage_name = NULL;
-
- workstation_CLM03_t ws = (workstation_CLM03_t) surf_workstation_resource_priv(workstation);
- xbt_dynar_t storages = ws->storage;
-
- xbt_dynar_foreach(storages,i,mnt){
- storage_name = ((storage_t)mnt.storage)->generic_resource.name;
- xbt_dict_set(storage_list,mnt.name,storage_name,NULL);
- }
- return storage_list;
-}
-
-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->mount);
- 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, surf_file_t fd, sg_storage_size_t size)
-{
- storage_t st = find_storage_on_mount_list(workstation, fd->mount);
- XBT_DEBUG("READ on disk '%s'",st->generic_resource.name);
- surf_model_t model = st->generic_resource.model;
- return model->extension.storage.read(st, fd, size);
-}
-
-static surf_action_t ws_action_write(void *workstation, surf_file_t fd, sg_storage_size_t size)
-{
- storage_t st = find_storage_on_mount_list(workstation, fd->mount);
- XBT_DEBUG("WRITE on disk '%s'",st->generic_resource.name);
- surf_model_t model = st->generic_resource.model;
- return model->extension.storage.write(st, fd, size);
-}
-
-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->mount);
- 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->mount);
- 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 sg_storage_size_t ws_file_get_size(void *workstation, surf_file_t fd)
-{
- return fd->size;
-}
-
-static xbt_dynar_t ws_file_get_info(void *workstation, surf_file_t fd)
-{
- storage_t st = find_storage_on_mount_list(workstation, fd->mount);
- sg_storage_size_t *psize = xbt_new(sg_storage_size_t, 1);
- *psize = fd->size;
- xbt_dynar_t info = xbt_dynar_new(sizeof(void*), NULL);
- xbt_dynar_push_as(info, sg_storage_size_t *, psize);
- xbt_dynar_push_as(info, void *, fd->mount);
- xbt_dynar_push_as(info, void *, st->generic_resource.name);
- xbt_dynar_push_as(info, void *, st->type_id);
- xbt_dynar_push_as(info, void *, st->content_type);
-
- return info;
-}
-
-static sg_storage_size_t ws_storage_get_free_size(void *workstation,const char* name)
-{
- storage_t st = find_storage_on_mount_list(workstation, name);
- return st->size - st->used_size;
-}
-
-static sg_storage_size_t ws_storage_get_used_size(void *workstation,const char* name)
-{
- storage_t st = find_storage_on_mount_list(workstation, name);
- return st->used_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.get_current_power_peak = ws_get_current_power_peak;
- surf_workstation_model->extension.workstation.get_power_peak_at = ws_get_power_peak_at;
- surf_workstation_model->extension.workstation.get_nb_pstates = ws_get_nb_pstates;
- surf_workstation_model->extension.workstation.set_power_peak_at = ws_set_power_peak_at;
- surf_workstation_model->extension.workstation.get_consumed_energy = ws_get_consumed_energy;
-
- 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;
- surf_workstation_model->extension.workstation.get_info = ws_file_get_info;
- surf_workstation_model->extension.workstation.get_free_size = ws_storage_get_free_size;
- surf_workstation_model->extension.workstation.get_used_size = ws_storage_get_used_size;
- surf_workstation_model->extension.workstation.get_storage_list = ws_get_storage_list;
-}
-
-void surf_workstation_model_init_current_default(void)
-{
- surf_workstation_model_init_internal();
- xbt_cfg_setdefault_boolean(_sg_cfg_set, "network/crosstraffic", "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);
-}