Logo AND Algorithmique Numérique Distribuée

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