X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/152117af2fbcf4c99d0da5d10a6813aac7eee007..76fc8e47346d48064beed39e49693bf27561916d:/src/surf/cpu_cas01.c diff --git a/src/surf/cpu_cas01.c b/src/surf/cpu_cas01.c index 357f9e2837..15cf9981c3 100644 --- a/src/surf/cpu_cas01.c +++ b/src/surf/cpu_cas01.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2009-2011. The SimGrid Team. +/* Copyright (c) 2009-2013. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -22,6 +22,19 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_cpu, surf, 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, @@ -40,7 +53,7 @@ static void *cpu_create_resource(const char *name, xbt_dynar_t power_peak, name); cpu = (cpu_Cas01_t) surf_resource_new(sizeof(s_cpu_Cas01_t), surf_cpu_model, name, - cpu_properties); + 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; @@ -50,7 +63,7 @@ static void *cpu_create_resource(const char *name, xbt_dynar_t power_peak, cpu->energy->power_range_watts_list = cpu_get_watts_range_list(cpu); cpu->energy->last_updated = surf_get_clock(); - XBT_DEBUG("CPU create: peak=%lf, pstate=%d",cpu->power_peak, cpu->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"); cpu->power_scale = power_scale; @@ -161,7 +174,7 @@ static void cpu_update_actions_state_full(double now, double delta) xbt_dynar_t cpu_get_watts_range_list(cpu_Cas01_t cpu_model) { - xbt_dynar_t power_range_list = xbt_dynar_new(sizeof(xbt_dynar_t), NULL); + xbt_dynar_t power_range_list; xbt_dynar_t power_tuple; int i = 0, pstate_nb=0; xbt_dynar_t current_power_values; @@ -176,6 +189,8 @@ xbt_dynar_t cpu_get_watts_range_list(cpu_Cas01_t cpu_model) 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); @@ -197,12 +212,17 @@ xbt_dynar_t cpu_get_watts_range_list(cpu_Cas01_t cpu_model) 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; @@ -227,8 +247,8 @@ static double cpu_get_current_watts_value(cpu_Cas01_t cpu_model, double cpu_load double current_power = min_power + cpu_load * power_slope; - XBT_DEBUG("[get_current_watts] min_power=%lf, max_power=%lf, slope=%lf", min_power, max_power, power_slope); - XBT_DEBUG("[get_current_watts] Current power (watts) = %lf, load = %lf", current_power, cpu_load); + 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; @@ -244,7 +264,7 @@ 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=(%lf-%lf), current power peak=%lf, current pstate=%d", + 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); @@ -252,7 +272,7 @@ void cpu_update_energy(cpu_Cas01_t cpu_model, double cpu_load) cpu_model->energy->total_energy = current_energy + action_energy; cpu_model->energy->last_updated = finish_time; - XBT_DEBUG("[cpu_update_energy] old_energy_value=%lf, action_energy_value=%lf", current_energy, action_energy); + XBT_DEBUG("[cpu_update_energy] old_energy_value=%f, action_energy_value=%f", current_energy, action_energy); } @@ -264,8 +284,6 @@ static void cpu_update_resource_state(void *id, lmm_variable_t var = NULL; lmm_element_t elem = NULL; - surf_watched_hosts(); - if (event_type == cpu->power_event) { cpu->power_scale = value; lmm_update_constraint_bound(surf_cpu_model->model_private->maxmin_system, cpu->constraint, @@ -286,9 +304,11 @@ static void cpu_update_resource_state(void *id, if (tmgr_trace_event_free(event_type)) cpu->power_event = NULL; } else if (event_type == cpu->state_event) { - if (value > 0) + 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 { + } else { lmm_constraint_t cnst = cpu->constraint; cpu->state_current = SURF_RESOURCE_OFF; @@ -392,6 +412,12 @@ 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 */ @@ -516,6 +542,7 @@ static void surf_cpu_model_init_internal() 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;