X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/28b7f1f95510fe2efa30fc2fb4b4d27826da931e..25f6494903ca6f70ce4408574a7e57e7419d427a:/src/surf/cpu.c diff --git a/src/surf/cpu.c b/src/surf/cpu.c index 3f4c5100e4..06b7eaa4d1 100644 --- a/src/surf/cpu.c +++ b/src/surf/cpu.c @@ -10,16 +10,6 @@ surf_cpu_resource_t surf_cpu_resource = NULL; static xbt_dict_t cpu_set = NULL; static lmm_system_t sys = NULL; -typedef struct cpu { - const char *name; - xbt_maxmin_float_t power_scale; - xbt_maxmin_float_t current_power; - tmgr_trace_t power_trace; - e_surf_action_state_t current_state; - tmgr_trace_t state_trace; - lmm_constraint_t constraint; -} s_cpu_t, *cpu_t; - /* power_scale is the basic power of the cpu when the cpu is completely available. initial_power is therefore expected to be comprised between 0.0 and 1.0, just as the values of power_trace. @@ -37,9 +27,13 @@ static void *new_cpu(const char *name, xbt_maxmin_float_t power_scale, cpu->power_scale = power_scale; cpu->current_power = initial_power; cpu->power_trace = power_trace; + if(power_trace) tmgr_history_add_trace(history, power_trace, 0.0, 0, cpu); + cpu->current_state = initial_state; cpu->state_trace = state_trace; - cpu->constraint = lmm_constraint_new(sys, cpu, cpu->current_power); + if(state_trace) tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu); + + cpu->constraint = lmm_constraint_new(sys, cpu, cpu->current_power * cpu->power_scale); xbt_dict_set(cpu_set, name, cpu, NULL); @@ -48,8 +42,11 @@ static void *new_cpu(const char *name, xbt_maxmin_float_t power_scale, static void parse_file(const char *file) { - new_cpu("Cpu A", 200.0, 1.0, NULL, SURF_CPU_ON, NULL); - new_cpu("Cpu B", 100.0, 1.0, NULL, SURF_CPU_ON, NULL); + tmgr_trace_t trace_A = tmgr_trace_new("trace_A.txt"); + tmgr_trace_t trace_B = tmgr_trace_new("trace_B.txt"); + + new_cpu("Cpu A", 20.0, 1.0, trace_A, SURF_CPU_ON, NULL); + new_cpu("Cpu B", 120.0, 1.0, trace_B, SURF_CPU_ON, NULL); } static void *name_service(const char *name) @@ -66,6 +63,11 @@ static const char *get_resource_name(void *resource_id) return ((cpu_t) resource_id)->name; } +static int resource_used(void *resource_id) +{ + return lmm_constraint_used(sys, ((cpu_t)resource_id)->constraint); +} + static surf_action_t action_new(void *callback) { return NULL; @@ -97,19 +99,68 @@ static void action_change_state(surf_action_t action, e_surf_action_state_t stat return; } -static xbt_heap_float_t share_resources(void) +static xbt_heap_float_t share_resources() { - return -1.0; + surf_action_cpu_t action = NULL; + xbt_swag_t running_actions= surf_cpu_resource->resource.states.running_action_set; + xbt_maxmin_float_t min = -1; + xbt_maxmin_float_t value = -1; + lmm_solve(sys); + + action = xbt_swag_getFirst(running_actions); + if(!action) return 0.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(valueresource.states.running_action_set; + + xbt_swag_foreach_safe(action, next_action, running_actions) { + action->generic_action.remains -= + lmm_variable_getvalue(action->variable)*delta; +/* if(action->generic_action.remains<.00001) action->generic_action.remains=0; */ + if(action->generic_action.remains<=0) { + action_change_state((surf_action_t)action, SURF_ACTION_DONE); + } /* else if(host_failed..) */ + } + return; } static surf_action_t execute(void *cpu, xbt_maxmin_float_t size) { - return NULL; + lmm_variable_t var; + surf_action_cpu_t action = NULL; + + action=xbt_new0(s_surf_action_cpu_t,1); + + action->generic_action.cost=size; + action->generic_action.remains=size; + action->generic_action.start=-1.0; + action->generic_action.finish=-1.0; + action->generic_action.callback=cpu; + action->generic_action.resource_type=(surf_resource_t)surf_cpu_resource; + + action->generic_action.state_set=surf_cpu_resource->resource.states.running_action_set; + xbt_swag_insert(action,action->generic_action.state_set); + + action->variable = lmm_variable_new(sys, action, 1.0, -1.0, 1); + lmm_expand(sys, ((cpu_t)cpu)->constraint, action->variable, 1.0); + + return (surf_action_t) action; } static e_surf_cpu_state_t get_state(void *cpu) @@ -117,21 +168,31 @@ static e_surf_cpu_state_t get_state(void *cpu) return SURF_CPU_OFF; } - -surf_cpu_resource_t surf_cpu_resource_init(void) +static surf_cpu_resource_t surf_cpu_resource_init_internal(void) { + s_surf_action_t action; + surf_cpu_resource = xbt_new0(s_surf_cpu_resource_t,1); - surf_cpu_resource->resource.parse_file = parse_file; + surf_cpu_resource->resource.states.ready_action_set= + xbt_swag_new(xbt_swag_offset(action,state_hookup)); + surf_cpu_resource->resource.states.running_action_set= + xbt_swag_new(xbt_swag_offset(action,state_hookup)); + surf_cpu_resource->resource.states.failed_action_set= + xbt_swag_new(xbt_swag_offset(action,state_hookup)); + surf_cpu_resource->resource.states.done_action_set= + xbt_swag_new(xbt_swag_offset(action,state_hookup)); + surf_cpu_resource->resource.name_service = name_service; surf_cpu_resource->resource.get_resource_name = get_resource_name; + surf_cpu_resource->resource.resource_used = resource_used; surf_cpu_resource->resource.action_get_state=surf_action_get_state; surf_cpu_resource->resource.action_free = action_free; surf_cpu_resource->resource.action_cancel = action_cancel; surf_cpu_resource->resource.action_recycle = action_recycle; surf_cpu_resource->resource.action_change_state = action_change_state; surf_cpu_resource->resource.share_resources = share_resources; - surf_cpu_resource->resource.solve = solve; + surf_cpu_resource->resource.update_state = update_state; surf_cpu_resource->execute = execute; surf_cpu_resource->get_state = get_state; @@ -142,3 +203,13 @@ surf_cpu_resource_t surf_cpu_resource_init(void) return surf_cpu_resource; } + +void surf_cpu_resource_init(const char* filename) +{ + surf_resource_t CPU = NULL; + + surf_cpu_resource=surf_cpu_resource_init_internal(); + parse_file(filename); + CPU = &(surf_cpu_resource->resource); /* to make short */ + xbt_dynar_push(resource_list, &CPU); +}