From: alegrand Date: Thu, 9 Dec 2004 23:26:29 +0000 (+0000) Subject: Each action can now have a maximum duration. That is a convenient way to X-Git-Tag: v3.3~4767 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/93bfd522e431912cc88a28252eb9bc4074c991fb Each action can now have a maximum duration. That is a convenient way to model a sleep or a network saturation for a given period of time. Also add a suspend/resume to cpu. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@583 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index 0dcf20d5b8..e05156ade8 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -9,8 +9,6 @@ #define _SURF_SURF_H #include "xbt/swag.h" -#include "xbt/heap.h" /* for xbt_heap_float_t only */ -#include "surf/maxmin.h" /* for xbt_maxmin_float_t only */ /* Actions and resources are higly connected structures... */ typedef struct surf_action *surf_action_t; @@ -40,6 +38,8 @@ typedef struct surf_action { s_xbt_swag_hookup_t state_hookup; xbt_swag_t state_set; xbt_maxmin_float_t cost; /* cost */ + xbt_maxmin_float_t max_duration;/* max_duration (may fluctuate until + the task is completed) */ xbt_maxmin_float_t remains; /* How much of that cost remains to * be done in the currently running task */ xbt_heap_float_t start; /* start time */ @@ -89,7 +89,9 @@ typedef struct surf_cpu_resource_extension_private *surf_cpu_resource_extension_private_t; typedef struct surf_cpu_resource_extension_public { surf_action_t(*execute) (void *cpu, xbt_maxmin_float_t size); - surf_action_t(*wait) (void *cpu, xbt_maxmin_float_t size); + surf_action_t(*sleep) (void *cpu, xbt_maxmin_float_t duration); + void (*suspend) (surf_action_t action); + void (*resume) (surf_action_t action); e_surf_cpu_state_t(*get_state) (void *cpu); } s_surf_cpu_resource_extension_public_t, *surf_cpu_resource_extension_public_t; @@ -125,7 +127,7 @@ typedef struct surf_workstation_resource_extension_private *surf_workstation_resource_extension_private_t; typedef struct surf_workstation_resource_extension_public { surf_action_t(*execute) (void *workstation, xbt_maxmin_float_t size); - surf_action_t(*wait) (void *workstation, xbt_maxmin_float_t size); + surf_action_t(*sleep) (void *workstation, xbt_maxmin_float_t duration); e_surf_cpu_state_t(*get_state) (void *workstation); surf_action_t(*communicate) (void *workstation_src, void *workstation_dst, diff --git a/src/surf/cpu.c b/src/surf/cpu.c index 64649efb9c..3f40e53260 100644 --- a/src/surf/cpu.c +++ b/src/surf/cpu.c @@ -179,27 +179,9 @@ static void action_change_state(surf_action_t action, static xbt_heap_float_t share_resources(xbt_heap_float_t now) { - surf_action_cpu_t action = NULL; - xbt_swag_t running_actions = - surf_cpu_resource->common_public->states.running_action_set; - xbt_maxmin_float_t min = -1; - xbt_maxmin_float_t value = -1; - lmm_solve(maxmin_system); - - action = xbt_swag_getFirst(running_actions); - if (!action) - return -1.0; - value = lmm_variable_getvalue(action->variable); - min = action->generic_action.remains / value; - - xbt_swag_foreach(action, running_actions) { - value = action->generic_action.remains / - lmm_variable_getvalue(action->variable); - if (value < min) - min = value; - } - - return min; + s_surf_action_cpu_t action; + return generic_maxmin_share_resources(surf_cpu_resource->common_public->states.running_action_set, + xbt_swag_offset(action,variable)); } static void update_actions_state(xbt_heap_float_t now, @@ -215,9 +197,16 @@ static void update_actions_state(xbt_heap_float_t now, xbt_swag_foreach_safe(action, next_action, running_actions) { action->generic_action.remains -= lmm_variable_getvalue(action->variable) * delta; + if(action->generic_action.max_duration!=NO_MAX_DURATION) + action->generic_action.max_duration -= delta; /* if(action->generic_action.remains<.00001) action->generic_action.remains=0; */ if (action->generic_action.remains <= 0) { + action->generic_action.finish = surf_get_clock(); action_change_state((surf_action_t) action, SURF_ACTION_DONE); + } else if((action->generic_action.max_duration!=NO_MAX_DURATION) && + (action->generic_action.max_duration<=0)) { + action->generic_action.finish = surf_get_clock(); + action_change_state((surf_action_t) action, SURF_ACTION_DONE); } else { /* Need to check that none of the resource has failed */ lmm_constraint_t cnst = NULL; int i = 0; @@ -228,6 +217,7 @@ static void update_actions_state(xbt_heap_float_t now, i++))) { cpu = lmm_constraint_id(cnst); if (cpu->state_current == SURF_CPU_OFF) { + action->generic_action.finish = surf_get_clock(); action_change_state((surf_action_t) action, SURF_ACTION_FAILED); break; } @@ -278,7 +268,8 @@ static surf_action_t execute(void *cpu, xbt_maxmin_float_t size) action->generic_action.cost = size; action->generic_action.remains = size; - action->generic_action.start = -1.0; + action->generic_action.max_duration = NO_MAX_DURATION; + action->generic_action.start = surf_get_clock(); action->generic_action.finish = -1.0; /* action->generic_action.callback = cpu; */ action->generic_action.callback = NULL; @@ -300,6 +291,27 @@ static surf_action_t execute(void *cpu, xbt_maxmin_float_t size) return (surf_action_t) action; } +static surf_action_t action_sleep(void *cpu, xbt_maxmin_float_t duration) +{ + surf_action_cpu_t action = NULL; + + action = (surf_action_cpu_t) execute(cpu, 1.0); + action->generic_action.max_duration = duration; + lmm_update_variable_weight(maxmin_system, action->variable, 0.0); + + return (surf_action_t) action; +} + +static void action_suspend(surf_action_t action) +{ + lmm_update_variable_weight(maxmin_system, ((surf_action_cpu_t) action)->variable, 0.0); +} + +static void action_resume(surf_action_t action) +{ + lmm_update_variable_weight(maxmin_system, ((surf_action_cpu_t) action)->variable, 1.0); +} + static e_surf_cpu_state_t get_state(void *cpu) { return ((cpu_t) cpu)->state_current; @@ -331,7 +343,7 @@ static void surf_cpu_resource_init_internal(void) surf_cpu_resource->common_private = xbt_new0(s_surf_resource_private_t, 1); surf_cpu_resource->common_public = xbt_new0(s_surf_resource_public_t, 1); -/* surf_cpu_resource->extension_private = xbt_new0(s_surf_cpu_resource_extension_private_t,1); */ + surf_cpu_resource->extension_public = xbt_new0(s_surf_cpu_resource_extension_public_t, 1); @@ -363,6 +375,10 @@ static void surf_cpu_resource_init_internal(void) surf_cpu_resource->common_private->finalize = finalize; surf_cpu_resource->extension_public->execute = execute; + surf_cpu_resource->extension_public->sleep = action_sleep; + surf_cpu_resource->extension_public->suspend = action_suspend; + surf_cpu_resource->extension_public->resume = action_resume; + surf_cpu_resource->extension_public->get_state = get_state; cpu_set = xbt_dict_new(); diff --git a/src/surf/network.c b/src/surf/network.c index f8eacea1ec..e8d236d4b4 100644 --- a/src/surf/network.c +++ b/src/surf/network.c @@ -295,27 +295,9 @@ static void action_change_state(surf_action_t action, static xbt_heap_float_t share_resources(xbt_heap_float_t now) { - surf_action_network_t action = NULL; - xbt_swag_t running_actions = - surf_network_resource->common_public->states.running_action_set; - xbt_maxmin_float_t min = -1; - xbt_maxmin_float_t value = -1; - lmm_solve(maxmin_system); - - action = xbt_swag_getFirst(running_actions); - if (!action) - return -1.0; - value = lmm_variable_getvalue(action->variable); - min = action->generic_action.remains / value; - - xbt_swag_foreach(action, running_actions) { - value = action->latency + (action->generic_action.remains / - lmm_variable_getvalue(action->variable)); - if (value < min) - min = value; - } - - return min; + s_surf_action_network_t action; + return generic_maxmin_share_resources(surf_network_resource->common_public->states.running_action_set, + xbt_swag_offset(action,variable)); } @@ -343,11 +325,18 @@ static void update_actions_state(xbt_heap_float_t now, } action->generic_action.remains -= lmm_variable_getvalue(action->variable) * deltap; + if(action->generic_action.max_duration!=NO_MAX_DURATION) + action->generic_action.max_duration -= delta; /* if(action->generic_action.remains<.00001) action->generic_action.remains=0; */ if (action->generic_action.remains <= 0) { + action->generic_action.finish = surf_get_clock(); action_change_state((surf_action_t) action, SURF_ACTION_DONE); + } else if((action->generic_action.max_duration!=NO_MAX_DURATION) && + (action->generic_action.max_duration<=0)) { + action->generic_action.finish = surf_get_clock(); + action_change_state((surf_action_t) action, SURF_ACTION_DONE); } else { /* Need to check that none of the resource has failed */ lmm_constraint_t cnst = NULL; int i = 0; @@ -358,6 +347,7 @@ static void update_actions_state(xbt_heap_float_t now, i++))) { nw_link = lmm_constraint_id(cnst); if (nw_link->state_current == SURF_NETWORK_LINK_OFF) { + action->generic_action.finish = surf_get_clock(); action_change_state((surf_action_t) action, SURF_ACTION_FAILED); break; } @@ -425,6 +415,7 @@ static surf_action_t communicate(void *src, void *dst, action->generic_action.cost = size; action->generic_action.remains = size; + action->generic_action.max_duration = NO_MAX_DURATION; action->generic_action.start = -1.0; action->generic_action.finish = -1.0; action->generic_action.callback = NULL; diff --git a/src/surf/surf.c b/src/surf/surf.c index 1ae58ed587..a563608987 100644 --- a/src/surf/surf.c +++ b/src/surf/surf.c @@ -14,6 +14,48 @@ xbt_dynar_t resource_list = NULL; tmgr_history_t history = NULL; lmm_system_t maxmin_system = NULL; +xbt_heap_float_t generic_maxmin_share_resources(xbt_swag_t running_actions, + size_t offset) +{ + surf_action_t action = NULL; + xbt_maxmin_float_t min = -1; + xbt_maxmin_float_t value = -1; +#define VARIABLE(action) (*((lmm_variable_t*)(((char *) (action)) + (offset)))) + + lmm_solve(maxmin_system); + + xbt_swag_foreach(action, running_actions) { + value = lmm_variable_getvalue(VARIABLE(action)); + if((value>0) || (action->max_duration>=0)) break; + } + + if (!action) + return -1.0; + + if(value>0) { + min = value = action->remains / value; + if((action->max_duration>=0) && + (action->max_durationmax_duration; + } else min = action->max_duration; + + + for(action=xbt_swag_getNext(action,running_actions->offset); + action; + action=xbt_swag_getNext(action,running_actions->offset)) { + value = lmm_variable_getvalue(VARIABLE(action)); + if(value>0) { + value = action->remains / value; + if (value < min) min = value; + } + if((action->max_duration>=0) && + (action->max_durationmax_duration; + } +#undef VARIABLE + return min; +} + e_surf_action_state_t surf_action_get_state(surf_action_t action) { surf_action_state_t action_state = &(action->resource_type->common_public->states); diff --git a/src/surf/surf_private.h b/src/surf/surf_private.h index 0eef6aa01c..23ac7ca68d 100644 --- a/src/surf/surf_private.h +++ b/src/surf/surf_private.h @@ -14,6 +14,8 @@ #include "xbt/log.h" #include "surf/surf_parse.h" +#define NO_MAX_DURATION -1.0 + typedef struct surf_resource_private { int (*resource_used)(void *resource_id); /* Share the resources to the actions and return in hom much time @@ -28,6 +30,8 @@ typedef struct surf_resource_private { /* #define pub2priv(r) ((surf_resource_private_t) ((char *)(r) -(sizeof(struct surf_resource_private_part)))) */ /* #define priv2pub(r) ((void *) ((char *)(r) +(sizeof(struct surf_resource_private_part)))) */ +xbt_heap_float_t generic_maxmin_share_resources(xbt_swag_t running_actions, + size_t offset); /* Generic functions common to all ressources */ e_surf_action_state_t surf_action_get_state(surf_action_t action); void surf_action_free(surf_action_t * action); diff --git a/testsuite/surf/surf_usage.c b/testsuite/surf/surf_usage.c index e16a8a8aab..23136dd25c 100644 --- a/testsuite/surf/surf_usage.c +++ b/testsuite/surf/surf_usage.c @@ -39,9 +39,11 @@ void test(void) void *cardB = NULL; surf_action_t actionA = NULL; surf_action_t actionB = NULL; + surf_action_t actionC = NULL; surf_action_t commAB = NULL; e_surf_action_state_t stateActionA; e_surf_action_state_t stateActionB; + e_surf_action_state_t stateActionC; xbt_maxmin_float_t now = -1.0; surf_cpu_resource_init("platform.txt"); /* Now it is possible to use CPUs */ @@ -59,14 +61,17 @@ void test(void) /* Let's do something on it */ actionA = surf_cpu_resource->extension_public->execute(cpuA, 1000.0); actionB = surf_cpu_resource->extension_public->execute(cpuB, 1000.0); + actionC = surf_cpu_resource->extension_public->sleep(cpuB, 7.32); /* Use whatever calling style you want... */ stateActionA = surf_cpu_resource->common_public->action_get_state(actionA); /* When you know actionA resource type */ stateActionB = actionB->resource_type->common_public->action_get_state(actionB); /* If you're unsure about it's resource type */ + stateActionC = surf_cpu_resource->common_public->action_get_state(actionC); /* When you know actionA resource type */ - /* And just look at the stat of these tasks */ + /* And just look at the state of these tasks */ printf("actionA : %p (%s)\n", actionA, string_action(stateActionA)); printf("actionB : %p (%s)\n", actionB, string_action(stateActionB)); + printf("actionC : %p (%s)\n", actionB, string_action(stateActionC)); /*********************** Network *******************************/ printf("%p \n", surf_network_resource);