From fa42487c90223126c2e27ff12ca34ad4f22bb2a1 Mon Sep 17 00:00:00 2001 From: navarro Date: Tue, 22 May 2012 15:28:25 +0200 Subject: [PATCH] Merge cpu and network Remove *_update_action_remaining_lazy and *_share_resources_lazy from cpu.c and network.c Add functions generic_share_resources_lazy and generic_update_action_remaining_lazy --- src/surf/cpu_cas01.c | 122 +----------------------------------- src/surf/network.c | 117 +--------------------------------- src/surf/network_constant.c | 2 +- src/surf/surf.c | 73 ++++++++++++++++++++- src/surf/surf_action.c | 70 ++++++++++++++++++++- src/surf/surf_private.h | 3 +- 6 files changed, 146 insertions(+), 241 deletions(-) diff --git a/src/surf/cpu_cas01.c b/src/surf/cpu_cas01.c index 60a7b7f6c0..be08fc702b 100644 --- a/src/surf/cpu_cas01.c +++ b/src/surf/cpu_cas01.c @@ -139,116 +139,9 @@ static int cpu_resource_used(void *resource) ((cpu_Cas01_t) resource)->constraint); } -static void cpu_update_action_remaining_lazy(surf_action_cpu_Cas01_t action, double now) -{ - double delta = 0.0; - - xbt_assert(GENERIC_ACTION(action).state_set == surf_cpu_model->states.running_action_set, - "You're updating an action that is not running."); - - /* bogus priority, skip it */ - xbt_assert(GENERIC_ACTION(action).priority > 0, - "You're updating an action that seems suspended."); - - delta = now - GENERIC_LMM_ACTION(action).last_update; - if (GENERIC_ACTION(action).remains > 0) { - XBT_DEBUG("Updating action(%p): remains was %lf, last_update was: %lf", action, - GENERIC_ACTION(action).remains, - GENERIC_LMM_ACTION(action).last_update); - double_update(&(GENERIC_ACTION(action).remains), - GENERIC_LMM_ACTION(action).last_value * delta); - -#ifdef HAVE_TRACING - if (TRACE_is_enabled()) { - cpu_Cas01_t cpu = - lmm_constraint_id(lmm_get_cnst_from_var - (surf_cpu_model->model_private->maxmin_system, - GENERIC_LMM_ACTION(action).variable, 0)); - TRACE_surf_host_set_utilization(cpu->generic_resource.name, - ((surf_action_t)action)->category, - GENERIC_LMM_ACTION(action).last_value, - GENERIC_LMM_ACTION(action).last_update, - now - GENERIC_LMM_ACTION(action).last_update); - } -#endif - XBT_DEBUG("Updating action(%p): remains is now %lf", action, - GENERIC_ACTION(action).remains); - } - GENERIC_LMM_ACTION(action).last_update = now; - GENERIC_LMM_ACTION(action).last_value = lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable); -} - static double cpu_share_resources_lazy(double now) { - surf_action_cpu_Cas01_t action = NULL; - double min = -1; - double value; - - XBT_DEBUG - ("Before share resources, the size of modified actions set is %d", - xbt_swag_size(surf_cpu_model->model_private->modified_set)); - - lmm_solve(surf_cpu_model->model_private->maxmin_system); - - XBT_DEBUG - ("After share resources, The size of modified actions set is %d", - xbt_swag_size(surf_cpu_model->model_private->modified_set)); - - while((action = xbt_swag_extract(surf_cpu_model->model_private->modified_set))) { - int max_dur_flag = 0; - - 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; - - cpu_update_action_remaining_lazy(action,now); - - min = -1; - value = lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable); - if (value > 0) { - if (GENERIC_ACTION(action).remains > 0) { - value = GENERIC_ACTION(action).remains / value; - min = now + value; - } else { - value = 0.0; - min = now; - } - } - - if ((GENERIC_ACTION(action).max_duration != NO_MAX_DURATION) - && (min == -1 - || GENERIC_ACTION(action).start + - GENERIC_ACTION(action).max_duration < min)) { - min = GENERIC_ACTION(action).start + - GENERIC_ACTION(action).max_duration; - max_dur_flag = 1; - } - - XBT_DEBUG("Action(%p) Start %lf Finish %lf Max_duration %lf", action, - GENERIC_ACTION(action).start, now + value, - GENERIC_ACTION(action).max_duration); - - if (min != -1) { - surf_action_lmm_heap_remove(surf_cpu_model->model_private->action_heap,(surf_action_lmm_t)action); - surf_action_lmm_heap_insert(surf_cpu_model->model_private->action_heap,(surf_action_lmm_t)action, min, max_dur_flag ? MAX_DURATION : NORMAL); - XBT_DEBUG("Insert at heap action(%p) min %lf now %lf", action, min, - now); - } else DIE_IMPOSSIBLE; - } - - //hereafter must have already the min value for this resource model - if (xbt_heap_size(surf_cpu_model->model_private->action_heap) > 0) - min = xbt_heap_maxkey(surf_cpu_model->model_private->action_heap) - now; - else - min = -1; - - XBT_DEBUG("The minimum with the HEAP %lf", min); - - return min; + return generic_share_resources_lazy(now, surf_cpu_model); } static double cpu_share_resources_full(double now) @@ -475,17 +368,6 @@ static surf_action_t cpu_action_sleep(void *cpu, double duration) return (surf_action_t) action; } -static double cpu_action_get_remains(surf_action_t action) -{ - XBT_IN("(%p)", action); - /* update remains before return it */ - if (surf_cpu_model->model_private->update_mechanism == UM_LAZY) - cpu_update_action_remaining_lazy((surf_action_cpu_Cas01_t)action, - surf_get_clock()); - XBT_OUT(); - return action->remains; -} - static e_surf_resource_state_t cpu_get_state(void *cpu) { return ((cpu_Cas01_t) cpu)->state_current; @@ -580,7 +462,7 @@ static void surf_cpu_model_init_internal() #ifdef HAVE_TRACING surf_cpu_model->set_category = surf_action_set_category; #endif - surf_cpu_model->get_remains = cpu_action_get_remains; + 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; diff --git a/src/surf/network.c b/src/surf/network.c index b37ff55d97..5e94b3af0c 100644 --- a/src/surf/network.c +++ b/src/surf/network.c @@ -308,51 +308,6 @@ int net_get_link_latency_limited(surf_action_t action) } #endif -double net_action_get_remains(surf_action_t action) -{ - XBT_IN("(%p)", action); - /* update remains before return it */ - if (surf_network_model->model_private->update_mechanism == UM_LAZY) /* update remains before return it */ - net_update_action_remaining_lazy((surf_action_network_CM02_t)action, - surf_get_clock()); - XBT_OUT(); - return action->remains; -} - -static void net_update_action_remaining_lazy(surf_action_network_CM02_t action, double now) -{ - double delta = 0.0; - - if (GENERIC_LMM_ACTION(action).suspended != 0) - return; - - delta = now - GENERIC_LMM_ACTION(action).last_update; - - double_update(&(((surf_action_t)action)->remains), - GENERIC_LMM_ACTION(action).last_value * delta); - - 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(GENERIC_LMM_ACTION(action).variable) > 0)) { - ((surf_action_t)action)->finish = surf_get_clock(); - surf_network_model->action_state_set((surf_action_t) action, - SURF_ACTION_DONE); - - surf_action_lmm_heap_remove(surf_network_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(); - surf_network_model->action_state_set((surf_action_t) action, - SURF_ACTION_DONE); - surf_action_lmm_heap_remove(surf_network_model->model_private->action_heap,(surf_action_lmm_t)action); - } - - GENERIC_LMM_ACTION(action).last_update = now; - GENERIC_LMM_ACTION(action).last_value = lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable); -} - static double net_share_resources_full(double now) { s_surf_action_lmm_t s_action; @@ -389,75 +344,7 @@ static double net_share_resources_full(double now) static double net_share_resources_lazy(double now) { - surf_action_network_CM02_t action = NULL; - double min = -1; - double value; - - XBT_DEBUG - ("Before share resources, the size of modified actions set is %d", - xbt_swag_size(surf_network_model->model_private->modified_set)); - - lmm_solve(surf_network_model->model_private->maxmin_system); - - XBT_DEBUG - ("After share resources, The size of modified actions set is %d", - xbt_swag_size(surf_network_model->model_private->modified_set)); - - while((action = xbt_swag_extract(surf_network_model->model_private->modified_set))) { - int max_dur_flag = 0; - - if (GENERIC_ACTION(action).state_set != - surf_network_model->states.running_action_set) - continue; - - /* bogus priority, skip it */ - if (GENERIC_ACTION(action).priority <= 0) - continue; - - net_update_action_remaining_lazy(action,now); - - min = -1; - value = lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable); - if (value > 0) { - if (GENERIC_ACTION(action).remains > 0) { - value = GENERIC_ACTION(action).remains / value; - min = now + value; - } else { - value = 0.0; - min = now; - } - } - - if ((GENERIC_ACTION(action).max_duration != NO_MAX_DURATION) - && (min == -1 - || GENERIC_ACTION(action).start + - GENERIC_ACTION(action).max_duration < min)) { - min = GENERIC_ACTION(action).start + - GENERIC_ACTION(action).max_duration; - max_dur_flag = 1; - } - - XBT_DEBUG("Action(%p) Start %lf Finish %lf Max_duration %lf", action, - GENERIC_ACTION(action).start, now + value, - GENERIC_ACTION(action).max_duration); - - if (min != -1) { - surf_action_lmm_heap_remove(surf_network_model->model_private->action_heap,(surf_action_lmm_t)action); - surf_action_lmm_heap_insert(surf_network_model->model_private->action_heap,(surf_action_lmm_t)action, min, max_dur_flag ? MAX_DURATION : NORMAL); - XBT_DEBUG("Insert at heap action(%p) min %lf now %lf", action, min, - now); - } else DIE_IMPOSSIBLE; - } - - //hereafter must have already the min value for this resource model - if (xbt_heap_size(surf_network_model->model_private->action_heap) > 0) - min = xbt_heap_maxkey(surf_network_model->model_private->action_heap) - now; - else - min = -1; - - XBT_DEBUG("The minimum with the HEAP %lf", min); - - return min; + return generic_share_resources_lazy(now, surf_network_model); } static void net_update_actions_state_full(double now, double delta) @@ -986,7 +873,7 @@ static void surf_network_model_init_internal(void) surf_network_model->action_cancel = surf_action_cancel; surf_network_model->action_recycle = net_action_recycle; - surf_network_model->get_remains = net_action_get_remains; + 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; diff --git a/src/surf/network_constant.c b/src/surf/network_constant.c index 57d8f55ee3..e1be0fe41a 100644 --- a/src/surf/network_constant.c +++ b/src/surf/network_constant.c @@ -200,7 +200,7 @@ void surf_network_model_init_Constant() 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 = net_action_get_remains; + 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 diff --git a/src/surf/surf.c b/src/surf/surf.c index f95c7b78b4..36980e102f 100644 --- a/src/surf/surf.c +++ b/src/surf/surf.c @@ -289,11 +289,78 @@ double generic_maxmin_share_resources(xbt_swag_t running_actions, return min; } -void generic_update_action_remaining_lazy( surf_action_t action, double now) +double generic_share_resources_lazy(double now, surf_model_t model) { - // TODO merge for cpu and net -} + surf_action_lmm_t action = NULL; + double min = -1; + double value; + + XBT_DEBUG + ("Before share resources, the size of modified actions set is %d", + xbt_swag_size(model->model_private->modified_set)); + + lmm_solve(model->model_private->maxmin_system); + + XBT_DEBUG + ("After share resources, The size of modified actions set is %d", + xbt_swag_size(model->model_private->modified_set)); + while((action = xbt_swag_extract(model->model_private->modified_set))) { + int max_dur_flag = 0; + + if (action->generic_action.state_set != + model->states.running_action_set) + continue; + + /* bogus priority, skip it */ + if (action->generic_action.priority <= 0) + continue; + + generic_update_action_remaining_lazy(action,now); + + min = -1; + value = lmm_variable_getvalue(action->variable); + if (value > 0) { + if (action->generic_action.remains > 0) { + value = action->generic_action.remains / value; + min = now + value; + } else { + value = 0.0; + min = now; + } + } + + if ((action->generic_action.max_duration != NO_MAX_DURATION) + && (min == -1 + || action->generic_action.start + + action->generic_action.max_duration < min)) { + min = action->generic_action.start + + action->generic_action.max_duration; + max_dur_flag = 1; + } + + XBT_DEBUG("Action(%p) Start %lf Finish %lf Max_duration %lf", action, + action->generic_action.start, now + value, + action->generic_action.max_duration); + + if (min != -1) { + surf_action_lmm_heap_remove(model->model_private->action_heap,action); + surf_action_lmm_heap_insert(model->model_private->action_heap,action, min, max_dur_flag ? MAX_DURATION : NORMAL); + XBT_DEBUG("Insert at heap action(%p) min %lf now %lf", action, min, + now); + } else DIE_IMPOSSIBLE; + } + + //hereafter must have already the min value for this resource model + if (xbt_heap_size(model->model_private->action_heap) > 0) + min = xbt_heap_maxkey(model->model_private->action_heap) - now; + else + min = -1; + + XBT_DEBUG("The minimum with the HEAP %lf", min); + + return min; +} static XBT_INLINE void routing_asr_host_free(void *p) { sg_routing_edge_t elm = p; diff --git a/src/surf/surf_action.c b/src/surf/surf_action.c index 7b96125299..f90a48a0a9 100644 --- a/src/surf/surf_action.c +++ b/src/surf/surf_action.c @@ -288,13 +288,81 @@ void surf_action_set_category(surf_action_t action, } #endif +void generic_update_action_remaining_lazy( surf_action_lmm_t action, double now) +{ + double delta = 0.0; + + if(action->generic_action.model_type == surf_network_model) + { + if (action->suspended != 0) + return; + } + else + { + xbt_assert(action->generic_action.state_set == surf_cpu_model->states.running_action_set, + "You're updating an action that is not running."); + + /* bogus priority, skip it */ + xbt_assert(action->generic_action.priority > 0, + "You're updating an action that seems suspended."); + } + + delta = now - action->last_update; + + if (action->generic_action.remains > 0) { + XBT_DEBUG("Updating action(%p): remains was %lf, last_update was: %lf", action, action->generic_action.remains, action->last_update); + double_update(&(action->generic_action.remains), + action->last_value * delta); + +#ifdef HAVE_TRACING + if (action->generic_action.model_type == surf_cpu_model && TRACE_is_enabled()) { + surf_resource_t cpu = + lmm_constraint_id(lmm_get_cnst_from_var + (surf_cpu_model->model_private->maxmin_system, + action->variable, 0)); + TRACE_surf_host_set_utilization(cpu->name, + action->generic_action.category, + action->last_value, + action->last_update, + now - action->last_update); + } +#endif + XBT_DEBUG("Updating action(%p): remains is now %lf", action, + action->generic_action.remains); + } + + if(action->generic_action.model_type == 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(); + surf_network_model->action_state_set((surf_action_t) action, + SURF_ACTION_DONE); + + surf_action_lmm_heap_remove(surf_network_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(); + surf_network_model->action_state_set((surf_action_t) action, + SURF_ACTION_DONE); + surf_action_lmm_heap_remove(surf_network_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(action, surf_get_clock()); + generic_update_action_remaining_lazy((surf_action_lmm_t)action, surf_get_clock()); XBT_OUT(); return action->remains; } diff --git a/src/surf/surf_private.h b/src/surf/surf_private.h index 6fb1dc79c1..35ff6719cd 100644 --- a/src/surf/surf_private.h +++ b/src/surf/surf_private.h @@ -62,7 +62,7 @@ double generic_maxmin_share_resources(xbt_swag_t running_actions, size_t offset, lmm_system_t sys, void (*solve) (lmm_system_t)); -void generic_update_action_remaining_lazy( surf_action_t action, double now); +double generic_share_resources_lazy(double now, surf_model_t model); /* Generic functions common to all models */ void surf_action_init(void); @@ -92,6 +92,7 @@ void surf_action_set_category(surf_action_t action, const char *category); #endif double surf_action_get_remains(surf_action_t action); +void generic_update_action_remaining_lazy( surf_action_lmm_t action, double now); FILE *surf_fopen(const char *name, const char *mode); -- 2.20.1