X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/0f5e8daaa6e9f74521068aa75837200bcd182ea6..0c539f5e2d25206246bb12e6dc036b108ea778e5:/src/surf/cpu_im.c diff --git a/src/surf/cpu_im.c b/src/surf/cpu_im.c index 3d1190667d..b5d2f8786c 100644 --- a/src/surf/cpu_im.c +++ b/src/surf/cpu_im.c @@ -26,6 +26,7 @@ typedef struct cpu_Cas01_im { 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; @@ -49,6 +50,7 @@ static xbt_swag_t static cpu_Cas01_im_t cpu_im_new(char *name, double power_peak, double power_scale, tmgr_trace_t power_trace, + int core, e_surf_resource_state_t state_initial, tmgr_trace_t state_trace, xbt_dict_t cpu_properties) @@ -57,10 +59,6 @@ static cpu_Cas01_im_t cpu_im_new(char *name, double power_peak, s_surf_action_cpu_Cas01_im_t action; cpu = xbt_new0(s_cpu_Cas01_im_t, 1); -#ifdef HAVE_TRACING - TRACE_surf_host_declaration(name, power_scale * power_peak); -#endif - xbt_assert1(!surf_model_resource_by_name(surf_cpu_model, name), "Host '%s' declared several times in the platform file", name); @@ -73,6 +71,8 @@ static cpu_Cas01_im_t cpu_im_new(char *name, double power_peak, if (power_trace) cpu->power_event = tmgr_history_add_trace(history, power_trace, 0.0, 0, cpu); + cpu->core = core; + xbt_assert1(core>0,"Invalid number of cores %d",core); cpu->state_current = state_initial; if (state_trace) @@ -81,7 +81,7 @@ static cpu_Cas01_im_t cpu_im_new(char *name, double power_peak, cpu->constraint = lmm_constraint_new(cpu_im_maxmin_system, cpu, - cpu->power_scale * cpu->power_peak); + cpu->core * cpu->power_scale * cpu->power_peak); xbt_dict_set(surf_model_resource_set(surf_cpu_model), name, cpu, surf_resource_free); @@ -95,6 +95,7 @@ static void parse_cpu_im_init(void) { double power_peak = 0.0; double power_scale = 0.0; + int core = 0; tmgr_trace_t power_trace = NULL; e_surf_resource_state_t state_initial = SURF_RESOURCE_OFF; tmgr_trace_t state_trace = NULL; @@ -102,6 +103,7 @@ static void parse_cpu_im_init(void) power_peak = get_cpu_power(A_surfxml_host_power); surf_parse_get_double(&power_scale, A_surfxml_host_availability); power_trace = tmgr_trace_new(A_surfxml_host_availability_file); + surf_parse_get_int(&core, A_surfxml_host_core); xbt_assert0((A_surfxml_host_state == A_surfxml_host_state_ON) || (A_surfxml_host_state == A_surfxml_host_state_OFF), @@ -114,7 +116,7 @@ static void parse_cpu_im_init(void) current_property_set = xbt_dict_new(); cpu_im_new(xbt_strdup(A_surfxml_host_id), power_peak, power_scale, - power_trace, state_initial, state_trace, + power_trace, core, state_initial, state_trace, current_property_set); } @@ -154,8 +156,6 @@ static void cpu_im_add_traces_cpu(void) static void cpu_im_define_callbacks(const char *file) { - - surf_parse_reset_parser(); surfxml_add_callback(STag_surfxml_host_cb_list, parse_cpu_im_init); surfxml_add_callback(ETag_surfxml_platform_cb_list, &cpu_im_add_traces_cpu); @@ -185,7 +185,7 @@ static int cpu_im_action_unref(surf_action_t action) if (action->category) xbt_free(action->category); #endif - free(action); + surf_action_free(&action); return 1; } return 0; @@ -277,13 +277,14 @@ static double cpu_im_share_resources(double now) min = -1; value = lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable); if (value > 0) { - if (GENERIC_ACTION(action).remains > 0) + if (GENERIC_ACTION(action).remains > 0) { value = GENERIC_ACTION(action).remains / value; - else + min = now + value; + } else { value = 0.0; + min = now; + } } - if (value > 0) - min = now + value; if ((GENERIC_ACTION(action).max_duration != NO_MAX_DURATION) && (min == -1 @@ -325,23 +326,42 @@ static void cpu_im_update_actions_state(double now, double delta) GENERIC_ACTION(action).finish = surf_get_clock(); /* set the remains to 0 due to precision problems when updating the remaining amount */ #ifdef HAVE_TRACING - TRACE_surf_host_set_utilization(((cpu_Cas01_im_t) - (action->cpu))->generic_resource.name, - action-> - generic_lmm_action.generic_action.data, - (surf_action_t) action, - lmm_variable_getvalue - (GENERIC_LMM_ACTION(action).variable), - ((cpu_Cas01_im_t) - (action->cpu))->last_update, - now - - ((cpu_Cas01_im_t) - (action->cpu))->last_update); + { + cpu_Cas01_im_t cpu = ((cpu_Cas01_im_t)(action->cpu)); + TRACE_surf_host_set_utilization(cpu->generic_resource.name, + action->generic_lmm_action.generic_action.data, + (surf_action_t) action, + lmm_variable_getvalue (GENERIC_LMM_ACTION(action).variable), + cpu->last_update, + now - cpu->last_update); + } #endif GENERIC_ACTION(action).remains = 0; cpu_im_cpu_action_state_set((surf_action_t) action, SURF_ACTION_DONE); cpu_im_update_remains(action->cpu, surf_get_clock()); } +#ifdef HAVE_TRACING + { + //defining the last timestamp that we can safely dump to trace file + //without losing the event ascending order (considering all CPU's) + cpu_Cas01_im_t cpu; + xbt_dict_cursor_t cursor; + char *key; + double smaller = -1; + xbt_dict_foreach(surf_model_resource_set(surf_cpu_model), cursor, key, cpu){ + if (smaller < 0){ + smaller = cpu->last_update; + continue; + } + if (cpu->last_update < smaller){ + smaller = cpu->last_update; + } + } + if (smaller > 0) { + TRACE_last_timestamp_to_dump = smaller; + } + } +#endif return; } @@ -350,14 +370,23 @@ static void cpu_im_update_resource_state(void *id, double value, double date) { cpu_Cas01_im_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(cpu_im_maxmin_system, cpu->constraint, - cpu->power_scale * cpu->power_peak); + cpu->core * cpu->power_scale * cpu->power_peak); #ifdef HAVE_TRACING TRACE_surf_host_set_power(date, cpu->generic_resource.name, - cpu->power_scale * cpu->power_peak); + cpu->core * cpu->power_scale * cpu->power_peak); #endif + while ((var = lmm_get_var_from_cnst + (cpu_im_maxmin_system, cpu->constraint, &elem))) { + surf_action_cpu_Cas01_im_t action = lmm_variable_id(var); + lmm_update_variable_bound(cpu_im_maxmin_system, action->generic_lmm_action.variable, + cpu->power_scale * cpu->power_peak); + } xbt_swag_insert(cpu, cpu_im_modified_cpu); if (tmgr_trace_event_free(event_type)) cpu->power_event = NULL; @@ -410,7 +439,7 @@ static surf_action_t cpu_im_execute(void *cpu, double size) GENERIC_LMM_ACTION(action).variable = lmm_variable_new(cpu_im_maxmin_system, action, - GENERIC_ACTION(action).priority, -1.0, 1); + GENERIC_ACTION(action).priority, CPU->power_scale * CPU->power_peak, 1); action->index_heap = -1; action->cpu = CPU; xbt_swag_insert(CPU, cpu_im_modified_cpu); @@ -506,6 +535,16 @@ static void cpu_im_action_set_priority(surf_action_t action, XBT_OUT; } +#ifdef HAVE_TRACING +static void cpu_im_action_set_category(surf_action_t action, + const char *category) +{ + XBT_IN2("(%p,%s)", action, category); + action->category = xbt_strdup (category); + XBT_OUT; +} +#endif + static double cpu_im_action_get_remains(surf_action_t action) { XBT_IN1("(%p)", action); @@ -539,11 +578,12 @@ static void cpu_im_action_update_index_heap(void *action, int i) static void cpu_im_create_resource(char *name, double power_peak, double power_scale, tmgr_trace_t power_trace, + int core, e_surf_resource_state_t state_initial, tmgr_trace_t state_trace, xbt_dict_t cpu_properties) { - cpu_im_new(name, power_peak, power_scale, power_trace, + cpu_im_new(name, power_peak, power_scale, power_trace, core, state_initial, state_trace, cpu_properties); } @@ -600,6 +640,9 @@ static void surf_cpu_im_model_init_internal(void) surf_cpu_model->is_suspended = cpu_im_action_is_suspended; surf_cpu_model->set_max_duration = cpu_im_action_set_max_duration; surf_cpu_model->set_priority = cpu_im_action_set_priority; +#ifdef HAVE_TRACING + surf_cpu_model->set_category = cpu_im_action_set_category; +#endif surf_cpu_model->get_remains = cpu_im_action_get_remains; surf_cpu_model->extension.cpu.execute = cpu_im_execute;