Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
No more xbt_maxmin_float_t not xbt_heap_float_t. I use double everywhere. In
[simgrid.git] / src / include / surf / surf.h
1 /*      $Id$     */
2
3 /* Copyright (c) 2004 Arnaud Legrand. All rights reserved.                  */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 #ifndef _SURF_SURF_H
9 #define _SURF_SURF_H
10
11 #include "xbt/swag.h"
12 #include "xbt/dynar.h"
13
14 /* Actions and resources are higly connected structures... */
15 typedef struct surf_action *surf_action_t;
16 typedef struct surf_resource *surf_resource_t;
17
18 /*****************/
19 /* Action object */
20 /*****************/
21 typedef enum {
22   SURF_ACTION_READY = 0,        /* Ready        */
23   SURF_ACTION_RUNNING,          /* Running      */
24   SURF_ACTION_FAILED,           /* Task Failure */
25   SURF_ACTION_DONE,             /* Completed    */
26   SURF_ACTION_NOT_IN_THE_SYSTEM /* Not in the system anymore. Why did you ask ? */
27 } e_surf_action_state_t;
28
29 typedef struct surf_action_state {
30   xbt_swag_t ready_action_set;
31   xbt_swag_t running_action_set;
32   xbt_swag_t failed_action_set;
33   xbt_swag_t done_action_set;
34 } s_surf_action_state_t, *surf_action_state_t;
35
36 /* Never create s_surf_action_t by yourself !!!! */
37 /* Use action_new from the corresponding resource */
38 typedef struct surf_action {
39   s_xbt_swag_hookup_t state_hookup;
40   xbt_swag_t state_set;
41   double cost;                  /* cost        */
42   double max_duration;          /* max_duration (may fluctuate until
43                                    the task is completed) */
44   double remains;               /* How much of that cost remains to
45                                  * be done in the currently running task */
46   double start;                 /* start time  */
47   double finish;                /* finish time : this is modified during the run
48                                  * and fluctuates until the task is completed */
49   void *callback;               /* for your convenience */
50   surf_resource_t resource_type;
51 } s_surf_action_t;
52
53 /***************************/
54 /* Generic resource object */
55 /***************************/
56
57 typedef struct surf_resource_private *surf_resource_private_t;
58 typedef struct surf_resource_public {
59   s_surf_action_state_t states; /* Any living action on this resource */
60   void *(*name_service) (const char *name);
61   const char *(*get_resource_name) (void *resource_id);
62
63    e_surf_action_state_t(*action_get_state) (surf_action_t action);
64   void (*action_free) (surf_action_t action);
65   void (*action_cancel) (surf_action_t action);
66   void (*action_recycle) (surf_action_t action);
67   void (*action_change_state) (surf_action_t action,
68                                e_surf_action_state_t state);
69   const char *name;
70 } s_surf_resource_public_t, *surf_resource_public_t;
71
72 typedef struct surf_resource {
73   surf_resource_private_t common_private;
74   surf_resource_public_t common_public;
75 } s_surf_resource_t;
76
77 typedef struct surf_resource_object {
78   surf_resource_t resource;
79 } s_surf_resource_object_t, *surf_resource_object_t;
80
81 /**************************************/
82 /* Implementations of resource object */
83 /**************************************/
84 /* Cpu resource */
85 typedef enum {
86   SURF_CPU_ON = 1,              /* Ready        */
87   SURF_CPU_OFF = 0              /* Running      */
88 } e_surf_cpu_state_t;
89
90 typedef struct surf_cpu_resource_extension_private
91 *surf_cpu_resource_extension_private_t;
92 typedef struct surf_cpu_resource_extension_public {
93   surf_action_t(*execute) (void *cpu, double size);
94   surf_action_t(*sleep) (void *cpu, double duration);
95   void (*suspend) (surf_action_t action);
96   void (*resume) (surf_action_t action);
97    e_surf_cpu_state_t(*get_state) (void *cpu);
98 } s_surf_cpu_resource_extension_public_t,
99     *surf_cpu_resource_extension_public_t;
100
101 typedef struct surf_cpu_resource {
102   surf_resource_private_t common_private;
103   surf_resource_public_t common_public;
104   surf_cpu_resource_extension_public_t extension_public;
105 } s_surf_cpu_resource_t, *surf_cpu_resource_t;
106 extern surf_cpu_resource_t surf_cpu_resource;
107 void surf_cpu_resource_init(const char *filename);
108
109 /* Network resource */
110 typedef struct surf_network_resource_extension_private
111 *surf_network_resource_extension_private_t;
112 typedef struct surf_network_resource_extension_public {
113   surf_action_t(*communicate) (void *src, void *dst, double size);
114 } s_surf_network_resource_extension_public_t,
115     *surf_network_resource_extension_public_t;
116
117 typedef struct surf_network_resource {
118   surf_resource_private_t common_private;
119   surf_resource_public_t common_public;
120   surf_network_resource_extension_public_t extension_public;
121 } s_surf_network_resource_t, *surf_network_resource_t;
122
123 extern surf_network_resource_t surf_network_resource;
124 void surf_network_resource_init(const char *filename);
125
126 /* Workstation resource */
127 typedef struct surf_workstation_resource_extension_private
128 *surf_workstation_resource_extension_private_t;
129 typedef struct surf_workstation_resource_extension_public {
130   surf_action_t(*execute) (void *workstation, double size);
131   surf_action_t(*sleep) (void *workstation, double duration);
132   void (*suspend) (surf_action_t action);
133   void (*resume) (surf_action_t action);
134    e_surf_cpu_state_t(*get_state) (void *workstation);
135    surf_action_t(*communicate) (void *workstation_src,
136                                 void *workstation_dst, double size);
137 } s_surf_workstation_resource_extension_public_t,
138     *surf_workstation_resource_extension_public_t;
139
140 typedef struct surf_workstation_resource {
141   surf_resource_private_t common_private;
142   surf_resource_public_t common_public;
143   surf_workstation_resource_extension_public_t extension_public;
144 } s_surf_workstation_resource_t, *surf_workstation_resource_t;
145
146 extern surf_workstation_resource_t surf_workstation_resource;
147 void surf_workstation_resource_init(const char *filename);
148
149 /*******************************************/
150 /*** SURF Globals **************************/
151 /*******************************************/
152
153 void surf_init(int *argc, char **argv); /* initialize common structures */
154
155 extern xbt_dynar_t resource_list;       /* list of initialized resources */
156
157 double surf_solve(void);        /*  update all states and returns
158                                    the time elapsed since last
159                                    event */
160 double surf_get_clock(void);
161 void surf_finalize(void);       /* clean everything */
162
163 #endif                          /* _SURF_SURF_H */