From 41f6e93622ccf2e2c09dd0fd75ef6ad4f458e80b Mon Sep 17 00:00:00 2001 From: alegrand Date: Mon, 29 Nov 2004 00:39:25 +0000 Subject: [PATCH] OK, now clean structures are used for my objects. Forget about my uggly macros. Load variation handled for cpu. Next step, handling failures. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@525 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- src/include/surf/surf.h | 98 +++++++++++++++++++----------------- src/include/surf/trace_mgr.h | 15 +++--- src/surf/cpu.c | 95 +++++++++++++++++++++------------- src/surf/cpu_private.h | 17 +++++-- src/surf/maxmin.c | 8 +-- src/surf/maxmin_private.h | 4 +- src/surf/surf.c | 34 +++++++------ src/surf/surf_private.h | 12 +++++ src/surf/trace_mgr.c | 22 ++++---- src/surf/trace_mgr_private.h | 2 +- 10 files changed, 181 insertions(+), 126 deletions(-) diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index af93cc5020..c4fbe62309 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -8,8 +8,8 @@ #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 */ +#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; @@ -19,11 +19,11 @@ typedef struct surf_resource *surf_resource_t; /* Action object */ /*****************/ typedef enum { - SURF_ACTION_READY = 0, /* Ready */ - SURF_ACTION_RUNNING, /* Running */ - SURF_ACTION_FAILED, /* Task Failure */ - SURF_ACTION_DONE, /* Completed */ - SURF_ACTION_NOT_IN_THE_SYSTEM /* Not in the system anymore. Why did you ask ? */ + SURF_ACTION_READY = 0, /* Ready */ + SURF_ACTION_RUNNING, /* Running */ + SURF_ACTION_FAILED, /* Task Failure */ + SURF_ACTION_DONE, /* Completed */ + SURF_ACTION_NOT_IN_THE_SYSTEM /* Not in the system anymore. Why did you ask ? */ } e_surf_action_state_t; typedef struct surf_action_state { @@ -52,35 +52,30 @@ typedef struct surf_action { /* Generic resource object */ /***************************/ -typedef struct surf_resource { +typedef struct surf_resource_private *surf_resource_private_t; +typedef struct surf_resource_public { s_surf_action_state_t states; /* Any living action on this resource */ - - /* Moved to the initialization function */ - /* void (*parse_file)(const char *filename); */ - void *(*name_service)(const char *name); const char *(*get_resource_name)(void *resource_id); int (*resource_used)(void *resource_id); - /* surf_action_t (*action_new)(void *callback); */ - /* Not defined here. Actions have to be created by actually - performing it and prototype may therefore vary with the resource - implementationx */ - e_surf_action_state_t (*action_get_state)(surf_action_t action); - void (*action_free)(surf_action_t * action); /* Call it when you're done with this action */ - void (*action_cancel)(surf_action_t action); /* remove the variables from the linear system if needed */ - void (*action_recycle)(surf_action_t action); /* More efficient than free/new */ - void (*action_change_state)(surf_action_t action, e_surf_action_state_t state); - - xbt_heap_float_t (*share_resources)(xbt_heap_float_t now); /* Share the resources to the - actions and return in hom much time - the next action may terminate */ - void (*update_state)(xbt_heap_float_t now, - xbt_heap_float_t delta); /* Update the actions' state*/ + void (*action_free)(surf_action_t * action); + void (*action_cancel)(surf_action_t action); + void (*action_recycle)(surf_action_t action); + void (*action_change_state)(surf_action_t action, + e_surf_action_state_t state); +} s_surf_resource_public_t, *surf_resource_public_t; +typedef struct surf_resource { + surf_resource_private_t common_private; + surf_resource_public_t common_public; } s_surf_resource_t; +typedef struct surf_resource_object { + surf_resource_t resource; +} s_surf_resource_object_t, *surf_resource_object_t; + /**************************************/ /* Implementations of resource object */ /**************************************/ @@ -90,38 +85,47 @@ typedef enum { SURF_CPU_OFF = 0, /* Running */ } e_surf_cpu_state_t; +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); + e_surf_cpu_state_t(*get_state) (void *cpu); +} s_surf_cpu_resource_extension_public_t, *surf_cpu_resource_extension_public_t; + typedef struct surf_cpu_resource { - s_surf_resource_t resource; - surf_action_t (*execute)(void *cpu, xbt_maxmin_float_t size); - e_surf_cpu_state_t (*get_state)(void *cpu); + surf_resource_private_t common_private; + surf_resource_public_t common_public; +/* surf_cpu_resource_extension_private_t extension_private; */ + surf_cpu_resource_extension_public_t extension_public; } s_surf_cpu_resource_t, *surf_cpu_resource_t; extern surf_cpu_resource_t surf_cpu_resource; -void surf_cpu_resource_init(const char* filename); +void surf_cpu_resource_init(const char *filename); /* Network resource */ +typedef struct surf_network_resource_extension_private *surf_network_resource_extension_private_t; +typedef struct surf_network_resource_extension_public { + surf_action_t(*communicate) (void *src, void *dst, + xbt_maxmin_float_t size); +} s_surf_network_resource_extension_public_t, *surf_network_resource_extension_public_t; + typedef struct surf_network_resource { - s_surf_resource_t resource; - surf_action_t (*communicate)(void *src, void *dst, xbt_maxmin_float_t size); -} s_surf_network_resource_t, surf_network_resource_t; -extern surf_network_resource_t surf_network_resource; -void surf_network_resource_init(const char* filename); + surf_resource_private_t common_private; + surf_resource_public_t common_public; +/* surf_network_resource_extension_private_t extension_private; */ + surf_network_resource_extension_public_t extension_public; +} s_surf_network_resource_t, *surf_network_resource_t; -/* Timer resource */ -typedef struct surf_timer_resource { - s_surf_resource_t resource; - surf_action_t (*wait)(void *cpu, void *dst, xbt_maxmin_float_t size); -} s_surf_timer_resource_t, surf_timer_resource_t; -extern surf_timer_resource_t surf_timer_resource; -void surf_timer_resource_init(const char* filename); +extern surf_network_resource_t surf_network_resource; +void surf_network_resource_init(const char *filename); /*******************************************/ /*** SURF Globals **************************/ /*******************************************/ -void surf_init(void); /* initialize common structures */ -xbt_heap_float_t surf_solve(void); /* update all states and returns - the time elapsed since last - event */ +void surf_init(void); /* initialize common structures */ +xbt_heap_float_t surf_solve(void); /* update all states and returns + the time elapsed since last + event */ xbt_heap_float_t surf_get_clock(void); #endif /* _SURF_SURF_H */ diff --git a/src/include/surf/trace_mgr.h b/src/include/surf/trace_mgr.h index 91aa8d9d15..4a3be6b88e 100644 --- a/src/include/surf/trace_mgr.h +++ b/src/include/surf/trace_mgr.h @@ -12,6 +12,7 @@ typedef struct tmgr_history *tmgr_history_t; typedef struct tmgr_trace *tmgr_trace_t; +typedef struct tmgr_trace_event *tmgr_trace_event_t; /* Creation functions */ tmgr_history_t tmgr_history_new(void); @@ -20,15 +21,15 @@ void tmgr_history_free(tmgr_history_t history); tmgr_trace_t tmgr_trace_new(const char *filename); void tmgr_trace_free(tmgr_trace_t trace); -void tmgr_history_add_trace(tmgr_history_t history, tmgr_trace_t trace, - xbt_heap_float_t start_time, int offset, - void *resource); +tmgr_trace_event_t tmgr_history_add_trace(tmgr_history_t history, tmgr_trace_t trace, + xbt_heap_float_t start_time, int offset, + void *resource); /* Access functions */ xbt_heap_float_t tmgr_history_next_date(tmgr_history_t history); -int tmgr_history_get_next_event_leq(tmgr_history_t history, - xbt_heap_float_t date, - xbt_maxmin_float_t * value, - void **resource); +tmgr_trace_event_t tmgr_history_get_next_event_leq(tmgr_history_t history, + xbt_heap_float_t date, + xbt_maxmin_float_t * value, + void **resource); #endif /* _SURF_TMGR_H */ diff --git a/src/surf/cpu.c b/src/surf/cpu.c index 06b7eaa4d1..8b42a20b0c 100644 --- a/src/surf/cpu.c +++ b/src/surf/cpu.c @@ -7,6 +7,7 @@ #include "xbt/dict.h" surf_cpu_resource_t surf_cpu_resource = NULL; + static xbt_dict_t cpu_set = NULL; static lmm_system_t sys = NULL; @@ -23,15 +24,18 @@ static void *new_cpu(const char *name, xbt_maxmin_float_t power_scale, { cpu_t cpu = xbt_new0(s_cpu_t,1); + cpu->resource = (surf_resource_t) surf_cpu_resource; cpu->name = name; 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->power_trace = power_trace; */ + if(power_trace) + cpu->power_event = tmgr_history_add_trace(history, power_trace, 0.0, 0, cpu); cpu->current_state = initial_state; - cpu->state_trace = state_trace; - if(state_trace) tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu); +/* cpu->state_trace = state_trace; */ + if(state_trace) + cpu->state_event = tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu); cpu->constraint = lmm_constraint_new(sys, cpu, cpu->current_power * cpu->power_scale); @@ -46,7 +50,7 @@ static void parse_file(const char *file) 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); + new_cpu("Cpu B", 100.0, 1.0, trace_B, SURF_CPU_ON, NULL); } static void *name_service(const char *name) @@ -102,7 +106,7 @@ static void action_change_state(surf_action_t action, e_surf_action_state_t stat static xbt_heap_float_t share_resources() { surf_action_cpu_t action = NULL; - xbt_swag_t running_actions= surf_cpu_resource->resource.states.running_action_set; + 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(sys); @@ -121,12 +125,12 @@ static xbt_heap_float_t share_resources() return min; } -static void update_state(xbt_heap_float_t now, - xbt_heap_float_t delta) +static void update_actions_state(xbt_heap_float_t now, + xbt_heap_float_t delta) { surf_action_cpu_t action = NULL; surf_action_cpu_t next_action = NULL; - xbt_swag_t running_actions= surf_cpu_resource->resource.states.running_action_set; + xbt_swag_t running_actions= surf_cpu_resource->common_public->states.running_action_set; xbt_swag_foreach_safe(action, next_action, running_actions) { action->generic_action.remains -= @@ -140,6 +144,26 @@ static void update_state(xbt_heap_float_t now, return; } +static void update_resource_state(void *id, + tmgr_trace_event_t event_type, + xbt_maxmin_float_t value) +{ + cpu_t cpu = id; + + printf("Asking to update \"%s\" with value " XBT_MAXMIN_FLOAT_T " for event %p\n", + cpu->name, value, event_type); + + if(event_type==cpu->power_event) { + cpu->current_power = value; + lmm_update_constraint_bound(cpu->constraint,cpu->current_power * cpu->power_scale); + } else if (event_type==cpu->state_event) { + if(value>0) cpu->current_state = SURF_CPU_ON; + else cpu->current_state = SURF_CPU_OFF; + } else abort(); + + return; +} + static surf_action_t execute(void *cpu, xbt_maxmin_float_t size) { lmm_variable_t var; @@ -154,7 +178,7 @@ static surf_action_t execute(void *cpu, xbt_maxmin_float_t size) 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; + action->generic_action.state_set=surf_cpu_resource->common_public->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); @@ -168,48 +192,49 @@ static e_surf_cpu_state_t get_state(void *cpu) return SURF_CPU_OFF; } -static surf_cpu_resource_t surf_cpu_resource_init_internal(void) +static void 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->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); - surf_cpu_resource->resource.states.ready_action_set= + surf_cpu_resource->common_public->states.ready_action_set= xbt_swag_new(xbt_swag_offset(action,state_hookup)); - surf_cpu_resource->resource.states.running_action_set= + surf_cpu_resource->common_public->states.running_action_set= xbt_swag_new(xbt_swag_offset(action,state_hookup)); - surf_cpu_resource->resource.states.failed_action_set= + surf_cpu_resource->common_public->states.failed_action_set= xbt_swag_new(xbt_swag_offset(action,state_hookup)); - surf_cpu_resource->resource.states.done_action_set= + surf_cpu_resource->common_public->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.update_state = update_state; - - surf_cpu_resource->execute = execute; - surf_cpu_resource->get_state = get_state; + surf_cpu_resource->common_public->name_service = name_service; + surf_cpu_resource->common_public->get_resource_name = get_resource_name; + surf_cpu_resource->common_public->resource_used = resource_used; + surf_cpu_resource->common_public->action_get_state=surf_action_get_state; + surf_cpu_resource->common_public->action_free = action_free; + surf_cpu_resource->common_public->action_cancel = action_cancel; + surf_cpu_resource->common_public->action_recycle = action_recycle; + surf_cpu_resource->common_public->action_change_state = action_change_state; + surf_cpu_resource->common_private->share_resources = share_resources; + surf_cpu_resource->common_private->update_actions_state = update_actions_state; + surf_cpu_resource->common_private->update_resource_state = update_resource_state; + + surf_cpu_resource->extension_public->execute = execute; + surf_cpu_resource->extension_public->get_state = get_state; cpu_set = xbt_dict_new(); sys = lmm_system_new(); - - 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(); + surf_cpu_resource_init_internal(); parse_file(filename); - CPU = &(surf_cpu_resource->resource); /* to make short */ - xbt_dynar_push(resource_list, &CPU); + xbt_dynar_push(resource_list, &surf_cpu_resource); } diff --git a/src/surf/cpu_private.h b/src/surf/cpu_private.h index d10fea17d0..c5b2cde28b 100644 --- a/src/surf/cpu_private.h +++ b/src/surf/cpu_private.h @@ -14,14 +14,23 @@ typedef struct surf_action_cpu { } s_surf_action_cpu_t, *surf_action_cpu_t; typedef struct cpu { + surf_resource_t resource; /* Any such object, added in a trace + should start by this field!!! */ 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; +/* tmgr_trace_t power_trace; */ + tmgr_trace_event_t power_event; + e_surf_cpu_state_t current_state; +/* tmgr_trace_t state_trace; */ + tmgr_trace_event_t state_event; lmm_constraint_t constraint; } s_cpu_t, *cpu_t; +/* typedef struct surf_cpu_resource_extension_private { */ +/* } s_surf_cpu_resource_extension_private_t; */ -#endif /* _SURF_SURF_PRIVATE_H */ +void surf_cpu_resource_init(const char *filename); + + +#endif /* _SURF_CPU_PRIVATE_H */ diff --git a/src/surf/maxmin.c b/src/surf/maxmin.c index 3a1c4e2302..6cae691c2f 100644 --- a/src/surf/maxmin.c +++ b/src/surf/maxmin.c @@ -87,7 +87,7 @@ lmm_constraint_t lmm_constraint_new(lmm_system_t sys, void *id, s_lmm_element_t elem; cnst = xbt_new0(s_lmm_constraint_t, 1); -/* cnst->id = id; */ + cnst->id = id; xbt_swag_init(&(cnst->element_set), xbt_swag_offset(elem, element_set_hookup)); xbt_swag_init(&(cnst->active_element_set), @@ -97,8 +97,6 @@ lmm_constraint_t lmm_constraint_new(lmm_system_t sys, void *id, cnst->usage = 0; insert_constraint(sys, cnst); - cnst->id = id; - return cnst; } @@ -116,7 +114,7 @@ lmm_variable_t lmm_variable_new(lmm_system_t sys, void *id, lmm_variable_t var = NULL; var = xbt_new0(s_lmm_variable_t, 1); -/* var->id = id; */ + var->id = id; var->cnsts = xbt_new0(s_lmm_element_t, number_of_constraints); var->cnsts_size = number_of_constraints; /* var->cnsts_number = 0; *//* Useless because of the calloc */ @@ -125,8 +123,6 @@ lmm_variable_t lmm_variable_new(lmm_system_t sys, void *id, var->value = -1; insert_variable(sys, var); - var->id = id; - return var; } diff --git a/src/surf/maxmin_private.h b/src/surf/maxmin_private.h index 5a870d1f7d..99f1be6b39 100644 --- a/src/surf/maxmin_private.h +++ b/src/surf/maxmin_private.h @@ -33,7 +33,7 @@ typedef struct lmm_constraint { xbt_maxmin_float_t bound; xbt_maxmin_float_t remaining; xbt_maxmin_float_t usage; - char *id; + void *id; } s_lmm_constraint_t; typedef struct lmm_variable { @@ -47,7 +47,7 @@ typedef struct lmm_variable { xbt_maxmin_float_t weight; xbt_maxmin_float_t bound; xbt_maxmin_float_t value; - char *id; + void *id; } s_lmm_variable_t; typedef struct lmm_system { diff --git a/src/surf/surf.c b/src/surf/surf.c index eeff67479f..60cea9caa3 100644 --- a/src/surf/surf.c +++ b/src/surf/surf.c @@ -13,7 +13,7 @@ lmm_system_t maxmin_system = NULL; e_surf_action_state_t surf_action_get_state(surf_action_t action) { - surf_action_state_t action_state = &(action->resource_type->states); + surf_action_state_t action_state = &(action->resource_type->common_public->states); if(action->state_set == action_state->ready_action_set) return SURF_ACTION_READY; @@ -28,14 +28,14 @@ e_surf_action_state_t surf_action_get_state(surf_action_t action) void surf_action_free(surf_action_t * action) { - (*action)->resource_type->action_cancel(*action); + (*action)->resource_type->common_public->action_cancel(*action); xbt_free(*action); *action=NULL; } void surf_action_change_state(surf_action_t action, e_surf_action_state_t state) { - surf_action_state_t action_state = &(action->resource_type->states); + surf_action_state_t action_state = &(action->resource_type->common_public->states); xbt_swag_remove(action, action->state_set); @@ -54,7 +54,7 @@ void surf_action_change_state(surf_action_t action, e_surf_action_state_t state) void surf_init(void) { - if(!resource_list) resource_list = xbt_dynar_new(sizeof(surf_resource_t), NULL); + if(!resource_list) resource_list = xbt_dynar_new(sizeof(surf_resource_private_t), NULL); if(!history) history = tmgr_history_new(); if(!maxmin_system) maxmin_system = lmm_system_new(); } @@ -65,37 +65,43 @@ xbt_heap_float_t surf_solve(void) xbt_heap_float_t next_event_date = -1.0; xbt_heap_float_t resource_next_action_end = -1.0; xbt_maxmin_float_t value = -1.0; + surf_resource_object_t resource_obj = NULL; surf_resource_t resource = NULL; + tmgr_trace_event_t event = NULL; int i; while ((next_event_date = tmgr_history_next_date(history)) != -1.0) { if(next_event_date > NOW) break; - while (tmgr_history_get_next_event_leq(history, next_event_date, - &value, (void **) &resource)) { - if(surf_cpu_resource->resource.resource_used(resource)) { - min = next_event_date-NOW; - } + while ((event = tmgr_history_get_next_event_leq(history, next_event_date, + &value, (void **) &resource_obj))) { + resource_obj->resource->common_private->update_resource_state(resource_obj, + event, value); } } + min = -1.0; + xbt_dynar_foreach (resource_list,i,resource) { - resource_next_action_end = resource->share_resources(NOW); + resource_next_action_end = resource->common_private->share_resources(NOW); if((min<0) || (resource_next_action_end NOW+min) break; - while (tmgr_history_get_next_event_leq(history, next_event_date, - &value, (void **) &resource)) { - if(surf_cpu_resource->resource.resource_used(resource)) { + while ((event=tmgr_history_get_next_event_leq(history, next_event_date, + &value, (void **) &resource_obj))) { + if(resource_obj->resource->common_public->resource_used(resource_obj)) { min = next_event_date-NOW; +/* update_state of resource_obj according to new value */ } + resource_obj->resource->common_private->update_resource_state(resource_obj, + event, value); } } xbt_dynar_foreach (resource_list,i,resource) { - resource->update_state(NOW, min); + resource->common_private->update_actions_state(NOW, min); } NOW=NOW+min; diff --git a/src/surf/surf_private.h b/src/surf/surf_private.h index 47923e0e93..e808d3fb51 100644 --- a/src/surf/surf_private.h +++ b/src/surf/surf_private.h @@ -10,6 +10,18 @@ #include "surf/maxmin.h" #include "surf/trace_mgr.h" +typedef struct surf_resource_private { + /* Share the resources to the actions and return in hom much time + the next action may terminate */ + xbt_heap_float_t(*share_resources) (xbt_heap_float_t now); + /* Update the actions' state */ + void (*update_actions_state) (xbt_heap_float_t now, xbt_heap_float_t delta); + void (*update_resource_state) (void *id,tmgr_trace_event_t event_type, xbt_maxmin_float_t value); +} s_surf_resource_private_t; + +/* #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)))) */ + /* 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/src/surf/trace_mgr.c b/src/surf/trace_mgr.c index 071184935c..e16eccc854 100644 --- a/src/surf/trace_mgr.c +++ b/src/surf/trace_mgr.c @@ -129,9 +129,9 @@ void tmgr_trace_free(tmgr_trace_t trace) xbt_free(trace); } -void tmgr_history_add_trace(tmgr_history_t history, tmgr_trace_t trace, - xbt_heap_float_t start_time, int offset, - void *resource) +tmgr_trace_event_t tmgr_history_add_trace(tmgr_history_t history, tmgr_trace_t trace, + xbt_heap_float_t start_time, int offset, + void *resource) { tmgr_trace_event_t trace_event = NULL; @@ -145,6 +145,8 @@ void tmgr_history_add_trace(tmgr_history_t history, tmgr_trace_t trace, abort(); xbt_heap_push(history->heap, trace_event, start_time); + + return trace_event; } xbt_heap_float_t tmgr_history_next_date(tmgr_history_t history) @@ -155,10 +157,10 @@ xbt_heap_float_t tmgr_history_next_date(tmgr_history_t history) return -1.0; } -int tmgr_history_get_next_event_leq(tmgr_history_t history, - xbt_heap_float_t date, - xbt_maxmin_float_t * value, - void **resource) +tmgr_trace_event_t tmgr_history_get_next_event_leq(tmgr_history_t history, + xbt_heap_float_t date, + xbt_maxmin_float_t * value, + void **resource) { xbt_heap_float_t event_date = xbt_heap_maxkey(history->heap); tmgr_trace_event_t trace_event = NULL; @@ -166,10 +168,10 @@ int tmgr_history_get_next_event_leq(tmgr_history_t history, tmgr_trace_t trace = NULL; if (event_date > date) - return 0; + return NULL; if (!(trace_event = xbt_heap_pop(history->heap))) - return 0; + return NULL; trace = trace_event->trace; event = xbt_dynar_get_ptr(trace->event_list, trace_event->idx); @@ -188,5 +190,5 @@ int tmgr_history_get_next_event_leq(tmgr_history_t history, xbt_free(trace_event); } - return 1; + return trace_event; } diff --git a/src/surf/trace_mgr_private.h b/src/surf/trace_mgr_private.h index bcea7f354b..0b84cdb23e 100644 --- a/src/surf/trace_mgr_private.h +++ b/src/surf/trace_mgr_private.h @@ -23,7 +23,7 @@ typedef struct tmgr_trace_event { tmgr_trace_t trace; int idx; void *resource; -} s_tmgr_trace_event_t, *tmgr_trace_event_t; +} s_tmgr_trace_event_t; typedef struct tmgr_history { xbt_heap_t heap; -- 2.20.1