#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;
/* 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 {
/* 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 */
/**************************************/
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 */
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);
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 */
#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;
{
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);
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)
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);
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 -=
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;
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);
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);
}
} 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 */
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),
cnst->usage = 0;
insert_constraint(sys, cnst);
- cnst->id = id;
-
return cnst;
}
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 */
var->value = -1;
insert_variable(sys, var);
- var->id = id;
-
return var;
}
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 {
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 {
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;
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);
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();
}
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<min))
min = resource_next_action_end;
}
while ((next_event_date = tmgr_history_next_date(history)) != -1.0) {
if(next_event_date > 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;
#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);
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;
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)
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;
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);
xbt_free(trace_event);
}
- return 1;
+ return 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;