Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add a convenient function
[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   int (*is_suspended) (surf_action_t action);
98    e_surf_cpu_state_t(*get_state) (void *cpu);
99 } s_surf_cpu_resource_extension_public_t,
100     *surf_cpu_resource_extension_public_t;
101
102 typedef struct surf_cpu_resource {
103   surf_resource_private_t common_private;
104   surf_resource_public_t common_public;
105   surf_cpu_resource_extension_public_t extension_public;
106 } s_surf_cpu_resource_t, *surf_cpu_resource_t;
107 extern surf_cpu_resource_t surf_cpu_resource;
108 void surf_cpu_resource_init(const char *filename);
109
110 /* Network resource */
111 typedef struct surf_network_resource_extension_private
112 *surf_network_resource_extension_private_t;
113 typedef struct surf_network_resource_extension_public {
114   surf_action_t(*communicate) (void *src, void *dst, double size);
115 } s_surf_network_resource_extension_public_t,
116     *surf_network_resource_extension_public_t;
117
118 typedef struct surf_network_resource {
119   surf_resource_private_t common_private;
120   surf_resource_public_t common_public;
121   surf_network_resource_extension_public_t extension_public;
122 } s_surf_network_resource_t, *surf_network_resource_t;
123
124 extern surf_network_resource_t surf_network_resource;
125 void surf_network_resource_init(const char *filename);
126
127 /* Workstation resource */
128 typedef struct surf_workstation_resource_extension_private
129 *surf_workstation_resource_extension_private_t;
130 typedef struct surf_workstation_resource_extension_public {
131   surf_action_t(*execute) (void *workstation, double size);
132   surf_action_t(*sleep) (void *workstation, double duration);
133   void (*suspend) (surf_action_t action);
134   void (*resume) (surf_action_t action);
135   int (*is_suspended) (surf_action_t action);
136    e_surf_cpu_state_t(*get_state) (void *workstation);
137    surf_action_t(*communicate) (void *workstation_src,
138                                 void *workstation_dst, double size);
139 } s_surf_workstation_resource_extension_public_t,
140     *surf_workstation_resource_extension_public_t;
141
142 typedef struct surf_workstation_resource {
143   surf_resource_private_t common_private;
144   surf_resource_public_t common_public;
145   surf_workstation_resource_extension_public_t extension_public;
146 } s_surf_workstation_resource_t, *surf_workstation_resource_t;
147
148 extern surf_workstation_resource_t surf_workstation_resource;
149 void surf_workstation_resource_init(const char *filename);
150
151 /*******************************************/
152 /*** SURF Globals **************************/
153 /*******************************************/
154
155 void surf_init(int *argc, char **argv); /* initialize common structures */
156
157 extern xbt_dynar_t resource_list;       /* list of initialized resources */
158
159 double surf_solve(void);        /*  update all states and returns
160                                    the time elapsed since last
161                                    event */
162 double surf_get_clock(void);
163 void surf_finalize(void);       /* clean everything */
164
165 #endif                          /* _SURF_SURF_H */