Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
moving/hiding resource_object where it is needed.
[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 #include "xbt/dict.h"
14
15 /* Actions and resources are higly connected structures... */
16 typedef struct surf_action *surf_action_t;
17 typedef struct surf_resource *surf_resource_t;
18
19 /*****************/
20 /* Action object */
21 /*****************/
22 typedef enum {
23   SURF_ACTION_READY = 0,        /* Ready        */
24   SURF_ACTION_RUNNING,          /* Running      */
25   SURF_ACTION_FAILED,           /* Task Failure */
26   SURF_ACTION_DONE,             /* Completed    */
27   SURF_ACTION_NOT_IN_THE_SYSTEM /* Not in the system anymore. Why did you ask ? */
28 } e_surf_action_state_t;
29
30 typedef struct surf_action_state {
31   xbt_swag_t ready_action_set;
32   xbt_swag_t running_action_set;
33   xbt_swag_t failed_action_set;
34   xbt_swag_t done_action_set;
35 } s_surf_action_state_t, *surf_action_state_t;
36
37 /* Never create s_surf_action_t by yourself !!!! */
38 /* Use action_new from the corresponding resource */
39 typedef struct surf_action {
40   s_xbt_swag_hookup_t state_hookup;
41   xbt_swag_t state_set;
42   double cost;                  /* cost        */
43   double max_duration;          /* max_duration (may fluctuate until
44                                    the task is completed) */
45   double remains;               /* How much of that cost remains to
46                                  * be done in the currently running task */
47   double start;                 /* start time  */
48   double finish;                /* finish time : this is modified during the run
49                                  * and fluctuates until the task is completed */
50   void *data;                   /* for your convenience */
51   surf_resource_t resource_type;
52 } s_surf_action_t;
53
54 /***************************/
55 /* Generic resource object */
56 /***************************/
57
58 typedef struct surf_resource_private *surf_resource_private_t;
59 typedef struct surf_resource_public {
60   s_surf_action_state_t states; /* Any living action on this resource */
61   void *(*name_service) (const char *name);
62   const char *(*get_resource_name) (void *resource_id);
63
64    e_surf_action_state_t(*action_get_state) (surf_action_t action);
65   void (*action_free) (surf_action_t action);
66   void (*action_cancel) (surf_action_t action);
67   void (*action_recycle) (surf_action_t action);
68   void (*action_change_state) (surf_action_t action,
69                                e_surf_action_state_t state);
70   void (*action_set_data) (surf_action_t action, void *data);
71   void (*suspend) (surf_action_t action);
72   void (*resume) (surf_action_t action);
73   int (*is_suspended) (surf_action_t action);
74   const char *name;
75 } s_surf_resource_public_t, *surf_resource_public_t;
76
77 typedef struct surf_resource {
78   surf_resource_private_t common_private;
79   surf_resource_public_t common_public;
80 } s_surf_resource_t;
81
82 /**************************************/
83 /* Implementations of resource object */
84 /**************************************/
85 /* Cpu resource */
86 typedef enum {
87   SURF_CPU_ON = 1,              /* Ready        */
88   SURF_CPU_OFF = 0              /* Running      */
89 } e_surf_cpu_state_t;
90
91 typedef struct surf_cpu_resource_extension_private
92 *surf_cpu_resource_extension_private_t;
93 typedef struct surf_cpu_resource_extension_public {
94   surf_action_t(*execute) (void *cpu, double size);
95   surf_action_t(*sleep) (void *cpu, double duration);
96   e_surf_cpu_state_t(*get_state) (void *cpu);
97 } s_surf_cpu_resource_extension_public_t,
98     *surf_cpu_resource_extension_public_t;
99
100 typedef struct surf_cpu_resource {
101   surf_resource_private_t common_private;
102   surf_resource_public_t common_public;
103   surf_cpu_resource_extension_public_t extension_public;
104 } s_surf_cpu_resource_t, *surf_cpu_resource_t;
105 extern surf_cpu_resource_t surf_cpu_resource;
106 void surf_cpu_resource_init_Cas01(const char *filename);
107
108 /* Network resource */
109 typedef struct surf_network_resource_extension_private
110 *surf_network_resource_extension_private_t;
111 typedef struct surf_network_resource_extension_public {
112   surf_action_t(*communicate) (void *src, void *dst, double size,
113                                double max_rate);
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_CM02(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   e_surf_cpu_state_t(*get_state) (void *workstation);
133   surf_action_t(*communicate) (void *workstation_src,
134                                void *workstation_dst, double size,
135                                double max_rate);
136 } s_surf_workstation_resource_extension_public_t,
137     *surf_workstation_resource_extension_public_t;
138
139 typedef struct surf_workstation_resource {
140   surf_resource_private_t common_private;
141   surf_resource_public_t common_public;
142   surf_workstation_resource_extension_public_t extension_public;
143 } s_surf_workstation_resource_t, *surf_workstation_resource_t;
144
145 extern surf_workstation_resource_t surf_workstation_resource;
146 void surf_workstation_resource_init_CLM03(const char *filename);
147 void surf_workstation_resource_init_KCCFLN05(const char *filename);
148 extern xbt_dict_t workstation_set;
149
150 /*******************************************/
151 /*** SURF Globals **************************/
152 /*******************************************/
153
154 void surf_init(int *argc, char **argv); /* initialize common structures */
155
156 extern xbt_dynar_t resource_list;       /* list of initialized resources */
157
158 double surf_solve(void);        /*  update all states and returns
159                                    the time elapsed since last
160                                    event */
161 double surf_get_clock(void);
162 void surf_finalize(void);       /* clean everything */
163
164 #endif                          /* _SURF_SURF_H */