From: alegrand Date: Tue, 16 Nov 2004 17:33:49 +0000 (+0000) Subject: First attempt on SURF design. I'd like a 5'10" short board with a swallow X-Git-Tag: v3.3~4833 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/ee788f4511c85f6d6685fdd6692169453e244ce1 First attempt on SURF design. I'd like a 5'10" short board with a swallow tail. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@517 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h new file mode 100644 index 0000000000..c998d3e2b8 --- /dev/null +++ b/src/include/surf/surf.h @@ -0,0 +1,112 @@ +/* Authors: Arnaud Legrand */ + +/* This program is free software; you can redistribute it and/or modify it + under the terms of the license (GNU LGPL) which comes with this package. */ + + +#ifndef _SURF_SURF_H +#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; +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 ? */ +} e_surf_action_state_t; + +/* Never create s_surf_action_t by yourself !!!! */ +/* Use action_new from the corresponding resource */ +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 remains; /* How much of that cost remains to + * be done in the currently running task */ + xbt_heap_float_t start; /* start time */ + xbt_heap_float_t finish; /* finish time : this is modified during the run + * and fluctuates until the task is completed */ + void *callback; /* for your convenience */ + surf_resource_t resource_type; +} s_surf_action_t; + +/***************************/ +/* Generic resource object */ +/***************************/ +typedef struct surf_resource { + void (*parse_file)(const char *file); + void *(*name_service)(const char *name); + + surf_action_t (*action_new)(void *callback); + 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)(void); /* Share the resources to the + actions and return the potential + next action termination */ + void (*solve)(xbt_heap_float_t date); /* Advance time to "date" and update + the actions' state*/ +} s_surf_resource_t; + +/**************************************/ +/* Implementations of resource object */ +/**************************************/ +/* Host resource */ +typedef enum { + SURF_HOST_ON = 1, /* Ready */ + SURF_HOST_OFF = 0, /* Running */ +} e_surf_host_state_t; + +typedef struct surf_host_resource { + s_surf_resource_t resource; + void (*execute)(void *host, xbt_maxmin_float_t size, surf_action_t action); + e_surf_host_state_t (*get_state)(void *host); +} s_surf_host_resource_t, *surf_host_resource_t; +extern surf_host_resource_t surf_host_resource; + +/* Network resource */ +typedef struct surf_network_resource { + s_surf_resource_t resource; + surf_action_t (*communicate)(void *src, void *dst, xbt_maxmin_float_t size, + surf_action_t action); +} s_surf_network_resource_t, surf_network_resource_t; +extern surf_network_resource_t surf_network_resource; + +/* Timer resource */ +typedef struct surf_timer_resource { + s_surf_resource_t resource; + surf_action_t (*wait)(void *host, void *dst, xbt_maxmin_float_t size, + surf_action_t surf); +} s_surf_timer_resource_t, surf_timer_resource_t; +extern surf_timer_resource_t surf_timer_resource; + +/*******************************************/ +/*** SURF Globals **************************/ +/*******************************************/ +typedef struct surf_global { + xbt_swag_t ready_action_set; + xbt_swag_t running_action_set; + xbt_swag_t failed_action_set; + xbt_swag_t done_action_set; +} s_surf_global_t; +/* The main function */ +extern s_surf_global_t surf_global; + +void surf_init(void); /* initialize all resource objects */ +xbt_heap_float_t surf_solve(void); /* returns the next date */ + +#endif /* _SURF_SURF_H */ diff --git a/src/surf/cpu.c b/src/surf/cpu.c new file mode 100644 index 0000000000..9b63b8d676 --- /dev/null +++ b/src/surf/cpu.c @@ -0,0 +1,88 @@ +/* Authors: Arnaud Legrand */ + +/* This program is free software; you can redistribute it and/or modify it + under the terms of the license (GNU LGPL) which comes with this package. */ + +#include "host_private.h" + +surf_host_resource_t surf_host_resource = NULL; + +static void parse_file(const char *file) +{ +} + +static void *name_service(const char *name) +{ + return NULL; +} + +static surf_action_t action_new(void *callback) +{ + return NULL; +} + +static e_surf_action_state_t action_get_state(surf_action_t action) +{ + return SURF_ACTION_NOT_IN_THE_SYSTEM; +} + +static void action_free(surf_action_t * action) +{ + return; +} + +static void action_cancel(surf_action_t action) +{ + return; +} + +static void action_recycle(surf_action_t action) +{ + return; +} + +static void action_change_state(surf_action_t action, e_surf_action_state_t state) +{ + return; +} + +static xbt_heap_float_t share_resources(void) +{ + return -1.0; +} + +static void solve(xbt_heap_float_t date) +{ + return; +} + +static void execute(void *host, xbt_maxmin_float_t size, surf_action_t action) +{ +} + +static e_surf_host_state_t get_state(void *host) +{ + return SURF_HOST_OFF; +} + + +surf_host_resource_t surf_host_resource_init(void) +{ + surf_host_resource = xbt_new0(s_surf_host_resource_t,1); + + surf_host_resource->resource.parse_file = parse_file; + surf_host_resource->resource.name_service = name_service; + surf_host_resource->resource.action_new=action_new; + surf_host_resource->resource.action_get_state=surf_action_get_state; + surf_host_resource->resource.action_free = action_free; + surf_host_resource->resource.action_cancel = action_cancel; + surf_host_resource->resource.action_recycle = action_recycle; + surf_host_resource->resource.action_change_state = action_change_state; + surf_host_resource->resource.share_resources = share_resources; + surf_host_resource->resource.solve = solve; + + surf_host_resource->execute = execute; + surf_host_resource->get_state = get_state; + + return surf_host_resource; +} diff --git a/src/surf/cpu_private.h b/src/surf/cpu_private.h new file mode 100644 index 0000000000..f5ee3c304d --- /dev/null +++ b/src/surf/cpu_private.h @@ -0,0 +1,19 @@ +/* Authors: Arnaud Legrand */ + +/* This program is free software; you can redistribute it and/or modify it + under the terms of the license (GNU LGPL) which comes with this package. */ + +#ifndef _SURF_HOST_PRIVATE_H +#define _SURF_HOST_PRIVATE_H + +#include "surf/surf.h" +#include "surf/surf_private.h" + +typedef struct surf_action_host { + s_surf_action_t generic_action; + lmm_variable_t variable; +} s_surf_action_host_t, *surf_action_host_t; + +surf_host_resource_t surf_host_resource_init(void); + +#endif /* _SURF_SURF_PRIVATE_H */ diff --git a/src/surf/surf.c b/src/surf/surf.c new file mode 100644 index 0000000000..bc0667da7e --- /dev/null +++ b/src/surf/surf.c @@ -0,0 +1,55 @@ +/* Authors: Arnaud Legrand */ + +/* This program is free software; you can redistribute it and/or modify it + under the terms of the license (GNU LGPL) which comes with this package. */ + +#include "surf_private.h" +#include "host_private.h" + +s_surf_global_t surf_global; + +e_surf_action_state_t surf_action_get_state(surf_action_t action) +{ + if(action->state_set == surf_global.ready_action_set) + return SURF_ACTION_READY; + if(action->state_set == surf_global.running_action_set) + return SURF_ACTION_RUNNING; + if(action->state_set == surf_global.failed_action_set) + return SURF_ACTION_FAILED; + if(action->state_set == surf_global.done_action_set) + return SURF_ACTION_DONE; + return SURF_ACTION_NOT_IN_THE_SYSTEM; +} + +void surf_action_free(surf_action_t * action) +{ + (*action)->resource_type->action_cancel(*action); + xbt_free(*action); + *action=NULL; +} + +void surf_action_change_state(surf_action_t action, e_surf_action_state_t state) +{ + xbt_swag_extract(action, action->state_set); + if(state == SURF_ACTION_READY) + action->state_set = surf_global.ready_action_set; + else if(state == SURF_ACTION_RUNNING) + action->state_set = surf_global.running_action_set; + else if(state == SURF_ACTION_FAILED) + action->state_set = surf_global.failed_action_set; + else if(state == SURF_ACTION_DONE) + action->state_set = surf_global.done_action_set; + else action->state_set = NULL; + + if(action->state_set) xbt_swag_insert(action, action->state_set); +} + +void surf_init(void) +{ + surf_host_resource = surf_host_resource_init(); +} + +/* xbt_heap_float_t surf_solve(void) */ +/* { */ +/* } */ + diff --git a/src/surf/surf_private.h b/src/surf/surf_private.h new file mode 100644 index 0000000000..c22887c4f2 --- /dev/null +++ b/src/surf/surf_private.h @@ -0,0 +1,21 @@ +/* Authors: Arnaud Legrand */ + +/* This program is free software; you can redistribute it and/or modify it + under the terms of the license (GNU LGPL) which comes with this package. */ + +#ifndef _SURF_SURF_PRIVATE_H +#define _SURF_SURF_PRIVATE_H + +#include "surf/surf.h" +#include "surf/maxmin.h" +#include "surf/trace_mgr.h" +#include "host_private.h" + +/* 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); +void surf_action_change_state(surf_action_t action, e_surf_action_state_t state); + + + +#endif /* _SURF_SURF_PRIVATE_H */