From: navarro Date: Thu, 10 May 2012 10:29:31 +0000 (+0200) Subject: Merge cpu and network for action functions. X-Git-Tag: v3_7~22 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/71a716760bd828d8d9423f5b65cb430d016fde45 Merge cpu and network for action functions. --- diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index 2d4e5b4193..213270433b 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -34,6 +34,7 @@ XBT_PUBLIC(e_surf_network_element_type_t) /** @Brief Specify that we use that action */ XBT_PUBLIC(void) surf_action_ref(surf_action_t action); + /** @brief Creates a new action. * * @param size The size is the one of the subtype you want to create diff --git a/src/surf/cpu_cas01.c b/src/surf/cpu_cas01.c index 406c5315c8..60a7b7f6c0 100644 --- a/src/surf/cpu_cas01.c +++ b/src/surf/cpu_cas01.c @@ -139,51 +139,6 @@ static int cpu_resource_used(void *resource) ((cpu_Cas01_t) resource)->constraint); } -static int cpu_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(surf_cpu_model->model_private->maxmin_system, - ((surf_action_lmm_t) action)->variable); - if (surf_cpu_model->model_private->update_mechanism == UM_LAZY) { - /* remove from heap */ - surf_action_lmm_heap_remove(surf_cpu_model->model_private->action_heap,(surf_action_lmm_t)action); - xbt_swag_remove(action, surf_cpu_model->model_private->modified_set); - } -#ifdef HAVE_TRACING - xbt_free(action->category); -#endif - surf_action_free(&action); - return 1; - } - return 0; -} - -static void cpu_action_cancel(surf_action_t action) -{ - surf_action_state_set(action, SURF_ACTION_FAILED); - if (surf_cpu_model->model_private->update_mechanism == UM_LAZY) { - xbt_swag_remove(action, surf_cpu_model->model_private->modified_set); - surf_action_lmm_heap_remove(surf_cpu_model->model_private->action_heap,(surf_action_lmm_t)action); - } - return; -} - -static void cpu_action_state_set(surf_action_t action, - e_surf_action_state_t state) -{ -/* if((state==SURF_ACTION_DONE) || (state==SURF_ACTION_FAILED)) */ -/* if(((surf_action_lmm_t)action)->variable) { */ -/* lmm_variable_disable(surf_cpu_model->maxmin_system, ((surf_action_lmm_t)action)->variable); */ -/* ((surf_action_lmm_t)action)->variable = NULL; */ -/* } */ - - surf_action_state_set(action, state); - return; -} - static void cpu_update_action_remaining_lazy(surf_action_cpu_Cas01_t action, double now) { double delta = 0.0; @@ -330,7 +285,7 @@ static void cpu_update_actions_state_lazy(double now, double delta) #endif /* set the remains to 0 due to precision problems when updating the remaining amount */ GENERIC_ACTION(action).remains = 0; - cpu_action_state_set((surf_action_t) action, SURF_ACTION_DONE); + surf_action_state_set((surf_action_t) action, SURF_ACTION_DONE); surf_action_lmm_heap_remove(surf_cpu_model->model_private->action_heap,(surf_action_lmm_t)action); //FIXME: strange call since action was already popped } #ifdef HAVE_TRACING @@ -388,11 +343,11 @@ static void cpu_update_actions_state_full(double now, double delta) (lmm_get_variable_weight(GENERIC_LMM_ACTION(action).variable) > 0)) { GENERIC_ACTION(action).finish = surf_get_clock(); - cpu_action_state_set((surf_action_t) action, SURF_ACTION_DONE); + surf_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(); - cpu_action_state_set((surf_action_t) action, SURF_ACTION_DONE); + surf_action_state_set((surf_action_t) action, SURF_ACTION_DONE); } } @@ -442,7 +397,7 @@ static void cpu_update_resource_state(void *id, surf_action_state_get(action) == SURF_ACTION_NOT_IN_THE_SYSTEM) { action->finish = date; - cpu_action_state_set(action, SURF_ACTION_FAILED); + surf_action_state_set(action, SURF_ACTION_FAILED); } } } @@ -520,74 +475,6 @@ static surf_action_t cpu_action_sleep(void *cpu, double duration) return (surf_action_t) action; } -static void cpu_action_suspend(surf_action_t action) -{ - XBT_IN("(%p)", action); - if (((surf_action_lmm_t) action)->suspended != 2) { - lmm_update_variable_weight(surf_cpu_model->model_private->maxmin_system, - ((surf_action_lmm_t) action)->variable, - 0.0); - ((surf_action_lmm_t) action)->suspended = 1; - if (surf_cpu_model->model_private->update_mechanism == UM_LAZY) - surf_action_lmm_heap_remove(surf_cpu_model->model_private->action_heap,(surf_action_lmm_t)action); - } - XBT_OUT(); -} - -static void cpu_action_resume(surf_action_t action) -{ - - XBT_IN("(%p)", action); - if (((surf_action_lmm_t) action)->suspended != 2) { - lmm_update_variable_weight(surf_cpu_model->model_private->maxmin_system, - ((surf_action_lmm_t) action)->variable, - action->priority); - ((surf_action_lmm_t) action)->suspended = 0; - if (surf_cpu_model->model_private->update_mechanism == UM_LAZY) - surf_action_lmm_heap_remove(surf_cpu_model->model_private->action_heap,(surf_action_lmm_t)action); - } - XBT_OUT(); -} - -static int cpu_action_is_suspended(surf_action_t action) -{ - return (((surf_action_lmm_t) action)->suspended == 1); -} - -static void cpu_action_set_max_duration(surf_action_t action, - double duration) -{ - XBT_IN("(%p,%g)", action, duration); - - action->max_duration = duration; - if (surf_cpu_model->model_private->update_mechanism == UM_LAZY) - surf_action_lmm_heap_remove(surf_cpu_model->model_private->action_heap,(surf_action_lmm_t)action); - XBT_OUT(); -} - -static void cpu_action_set_priority(surf_action_t action, double priority) -{ - XBT_IN("(%p,%g)", action, priority); - action->priority = priority; - lmm_update_variable_weight(surf_cpu_model->model_private->maxmin_system, - ((surf_action_lmm_t) action)->variable, - priority); - - if (surf_cpu_model->model_private->update_mechanism == UM_LAZY) - surf_action_lmm_heap_remove(surf_cpu_model->model_private->action_heap,(surf_action_lmm_t)action); - XBT_OUT(); -} - -#ifdef HAVE_TRACING -static void cpu_action_set_category(surf_action_t action, - const char *category) -{ - XBT_IN("(%p,%s)", action, category); - action->category = xbt_strdup(category); - XBT_OUT(); -} -#endif - static double cpu_action_get_remains(surf_action_t action) { XBT_IN("(%p)", action); @@ -662,9 +549,9 @@ static void surf_cpu_model_init_internal() surf_cpu_model->name = "cpu"; - surf_cpu_model->action_unref = cpu_action_unref; - surf_cpu_model->action_cancel = cpu_action_cancel; - surf_cpu_model->action_state_set = cpu_action_state_set; + 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; @@ -685,13 +572,13 @@ static void surf_cpu_model_init_internal() cpu_update_resource_state; surf_cpu_model->model_private->finalize = cpu_finalize; - surf_cpu_model->suspend = cpu_action_suspend; - surf_cpu_model->resume = cpu_action_resume; - surf_cpu_model->is_suspended = cpu_action_is_suspended; - surf_cpu_model->set_max_duration = cpu_action_set_max_duration; - surf_cpu_model->set_priority = cpu_action_set_priority; + 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 = cpu_action_set_category; + surf_cpu_model->set_category = surf_action_set_category; #endif surf_cpu_model->get_remains = cpu_action_get_remains; diff --git a/src/surf/network.c b/src/surf/network.c index 9ba7180747..b37ff55d97 100644 --- a/src/surf/network.c +++ b/src/surf/network.c @@ -55,7 +55,6 @@ int sg_network_crosstraffic = 0; xbt_dict_t gap_lookup = NULL; -static int net_action_is_suspended(surf_action_t action); static void net_update_action_remaining_lazy(surf_action_network_CM02_t action, double now); /******************************************************************************/ @@ -297,40 +296,6 @@ static int net_resource_used(void *resource_id) constraint); } -static int net_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(surf_network_model->model_private->maxmin_system, - ((surf_action_lmm_t) action)->variable); - } - if (surf_network_model->model_private->update_mechanism == UM_LAZY) { // remove action from the heap - surf_action_lmm_heap_remove(surf_network_model->model_private->action_heap,(surf_action_lmm_t) action); - xbt_swag_remove(action, surf_network_model->model_private->modified_set); - } -#ifdef HAVE_TRACING - if (action->category) xbt_free (action->category); -#endif - surf_action_free(&action); - return 1; - } - return 0; -} - - - -static void net_action_cancel(surf_action_t action) -{ - XBT_DEBUG("cancel action %p", action); - surf_network_model->action_state_set(action, SURF_ACTION_FAILED); - if (surf_network_model->model_private->update_mechanism == UM_LAZY) { // remove action from the heap - xbt_swag_remove(action, surf_network_model->model_private->modified_set); - surf_action_lmm_heap_remove(surf_network_model->model_private->action_heap,(surf_action_lmm_t) action); - } -} - void net_action_recycle(surf_action_t action) { return; @@ -906,51 +871,6 @@ static int net_link_shared(const void *link) lmm_constraint_is_shared(((surf_resource_lmm_t) link)->constraint); } -static void net_action_suspend(surf_action_t action) -{ - ((surf_action_network_CM02_t) action)->generic_lmm_action.suspended = 1; - lmm_update_variable_weight(surf_network_model->model_private->maxmin_system, - ((surf_action_network_CM02_t) - action)->generic_lmm_action.variable, 0.0); - - if (surf_network_model->model_private->update_mechanism == UM_LAZY) // remove action from the heap - surf_action_lmm_heap_remove(surf_network_model->model_private->action_heap,(surf_action_lmm_t)action); -} - -static void net_action_resume(surf_action_t action) -{ - if (((surf_action_network_CM02_t) action)->generic_lmm_action.suspended) { - lmm_update_variable_weight(surf_network_model->model_private->maxmin_system, - ((surf_action_network_CM02_t) - action)->generic_lmm_action.variable, - ((surf_action_network_CM02_t) - action)->weight); - ((surf_action_network_CM02_t) action)->generic_lmm_action.suspended = 0; - if (surf_network_model->model_private->update_mechanism == UM_LAZY) // remove action from the heap - surf_action_lmm_heap_remove(surf_network_model->model_private->action_heap,(surf_action_lmm_t)action); - } -} - -static int net_action_is_suspended(surf_action_t action) -{ - return ((surf_action_network_CM02_t) action)->generic_lmm_action.suspended; -} - -void net_action_set_max_duration(surf_action_t action, double duration) -{ - action->max_duration = duration; - if (surf_network_model->model_private->update_mechanism == UM_LAZY) // remove action from the heap - surf_action_lmm_heap_remove(surf_network_model->model_private->action_heap,(surf_action_lmm_t)action); -} - -#ifdef HAVE_TRACING -static void net_action_set_category(surf_action_t action, - const char *category) -{ - action->category = xbt_strdup(category); -} -#endif - static void net_finalize(void) { lmm_system_free(surf_network_model->model_private->maxmin_system); @@ -1062,15 +982,17 @@ static void surf_network_model_init_internal(void) set_update_mechanism(); surf_network_model->name = "network"; - surf_network_model->action_unref = net_action_unref; - surf_network_model->action_cancel = net_action_cancel; + 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 = net_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 = net_action_set_category; + surf_network_model->set_category = surf_action_set_category; #endif surf_network_model->model_private->resource_used = net_resource_used; @@ -1090,10 +1012,10 @@ static void surf_network_model_init_internal(void) net_update_resource_state; surf_network_model->model_private->finalize = net_finalize; - surf_network_model->suspend = net_action_suspend; - surf_network_model->resume = net_action_resume; - surf_network_model->is_suspended = net_action_is_suspended; - surf_cpu_model->set_max_duration = net_action_set_max_duration; + 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; diff --git a/src/surf/network_constant.c b/src/surf/network_constant.c index 0a2251c829..57d8f55ee3 100644 --- a/src/surf/network_constant.c +++ b/src/surf/network_constant.c @@ -217,7 +217,7 @@ void surf_network_model_init_Constant() 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 = net_action_set_max_duration; + 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 = diff --git a/src/surf/surf.c b/src/surf/surf.c index b82cc834c9..f95c7b78b4 100644 --- a/src/surf/surf.c +++ b/src/surf/surf.c @@ -289,6 +289,11 @@ double generic_maxmin_share_resources(xbt_swag_t running_actions, return min; } +void generic_update_action_remaining_lazy( surf_action_t action, double now) +{ + // TODO merge for cpu and net +} + 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 0622378741..7b96125299 100644 --- a/src/surf/surf_action.c +++ b/src/surf/surf_action.c @@ -184,3 +184,117 @@ void surf_action_lmm_heap_remove(xbt_heap_t heap, surf_action_lmm_t action) 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 + +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()); + XBT_OUT(); + return action->remains; +} diff --git a/src/surf/surf_private.h b/src/surf/surf_private.h index e714b8d44d..6fb1dc79c1 100644 --- a/src/surf/surf_private.h +++ b/src/surf/surf_private.h @@ -62,6 +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); /* Generic functions common to all models */ void surf_action_init(void); @@ -79,6 +80,18 @@ 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); +int 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); FILE *surf_fopen(const char *name, const char *mode); @@ -94,7 +107,7 @@ double net_action_get_remains(surf_action_t action); #ifdef HAVE_LATENCY_BOUND_TRACKING int net_get_link_latency_limited(surf_action_t action); #endif -void net_action_set_max_duration(surf_action_t action, double duration); + /* * Returns the initial path. On Windows the initial path is * the current directory for the current process in the other