Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Renamed resource initialization functions. Now they are postfixed by a alpha-style...
[simgrid.git] / src / include / surf / surf.h
index c998d3e..2dbbc5d 100644 (file)
@@ -1,15 +1,16 @@
-/* Authors: Arnaud Legrand                                                  */
+/*     $Id$     */
 
-/* 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. */
+/* Copyright (c) 2004 Arnaud Legrand. All rights reserved.                  */
 
+/* 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  */
+#include "xbt/dynar.h"
+#include "xbt/dict.h"
 
 /* Actions and resources are higly connected structures... */
 typedef struct surf_action *surf_action_t;
@@ -19,94 +20,151 @@ 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 {
+  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_action_state_t, *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
+  double cost;                 /* cost        */
+  double max_duration;         /* max_duration (may fluctuate until
+                                  the task is completed) */
+  double 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
+  double start;                        /* start time  */
+  double finish;               /* finish time : this is modified during the run
                                 * and fluctuates until the task is completed */
-  void *callback;              /* for your convenience */
+  void *data;                  /* for your convenience */
   surf_resource_t resource_type;
 } s_surf_action_t;
 
 /***************************/
 /* Generic resource object */
 /***************************/
+
+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 */
+  void *(*name_service) (const char *name);
+  const char *(*get_resource_name) (void *resource_id);
+
+   e_surf_action_state_t(*action_get_state) (surf_action_t action);
+  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);
+  void (*action_set_data) (surf_action_t action,
+                          void *data);
+  const char *name;
+} s_surf_resource_public_t, *surf_resource_public_t;
+
 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*/
+  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 */
 /**************************************/
-/* Host resource */
+/* Cpu 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;
+  SURF_CPU_ON = 1,             /* Ready        */
+  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, double size);
+  surf_action_t(*sleep) (void *cpu, double duration);
+  void (*suspend) (surf_action_t action);
+  void (*resume) (surf_action_t action);
+  int (*is_suspended) (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;
+
+typedef struct surf_cpu_resource {
+  surf_resource_private_t common_private;
+  surf_resource_public_t common_public;
+  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_Cas01(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, double 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,
-                              surf_action_t action);
-} s_surf_network_resource_t, surf_network_resource_t;
-extern surf_network_resource_t surf_network_resource;
+  surf_resource_private_t common_private;
+  surf_resource_public_t common_public;
+  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 *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;
+extern surf_network_resource_t surf_network_resource;
+void surf_network_resource_init_CM02(const char *filename);
+
+/* Workstation resource */
+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, double size);
+  surf_action_t(*sleep) (void *workstation, double duration);
+  void (*suspend) (surf_action_t action);
+  void (*resume) (surf_action_t action);
+  int (*is_suspended) (surf_action_t action);
+   e_surf_cpu_state_t(*get_state) (void *workstation);
+   surf_action_t(*communicate) (void *workstation_src,
+                               void *workstation_dst, double size);
+} s_surf_workstation_resource_extension_public_t,
+    *surf_workstation_resource_extension_public_t;
+
+typedef struct surf_workstation_resource {
+  surf_resource_private_t common_private;
+  surf_resource_public_t common_public;
+  surf_workstation_resource_extension_public_t extension_public;
+} s_surf_workstation_resource_t, *surf_workstation_resource_t;
+
+extern surf_workstation_resource_t surf_workstation_resource;
+void surf_workstation_resource_init_CLM03(const char *filename);
+void surf_workstation_resource_init_resource_init_KCCFLN05(const char *filename);
+extern xbt_dict_t workstation_set;
 
 /*******************************************/
 /*** 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 */
+void surf_init(int *argc, char **argv);        /* initialize common structures */
+
+extern xbt_dynar_t resource_list;      /* list of initialized resources */
+
+double surf_solve(void);       /*  update all states and returns
+                                  the time elapsed since last
+                                  event */
+double surf_get_clock(void);
+void surf_finalize(void);      /* clean everything */
 
 #endif                         /* _SURF_SURF_H */