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
((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)
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;
#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;
}
#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;
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)
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;
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
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;
}
#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;
}
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);
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);