Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Initializing logs once and only once.
[simgrid.git] / src / include / surf / surf.h
1 /* Authors: Arnaud Legrand                                                  */
2
3 /* This program is free software; you can redistribute it and/or modify it
4    under the terms of the license (GNU LGPL) which comes with this package. */
5
6
7 #ifndef _SURF_SURF_H
8 #define _SURF_SURF_H
9
10 #include "xbt/swag.h"
11 #include "xbt/heap.h"           /* for xbt_heap_float_t only */
12 #include "surf/maxmin.h"        /* for xbt_maxmin_float_t only  */
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   xbt_maxmin_float_t cost;      /* cost        */
42   xbt_maxmin_float_t remains;   /* How much of that cost remains to
43                                  * be done in the currently running task */
44   xbt_heap_float_t start;       /* start time  */
45   xbt_heap_float_t finish;      /* finish time : this is modified during the run
46                                  * and fluctuates until the task is completed */
47   void *callback;               /* for your convenience */
48   surf_resource_t resource_type;
49 } s_surf_action_t;
50
51 /***************************/
52 /* Generic resource object */
53 /***************************/
54
55 typedef struct surf_resource_private *surf_resource_private_t;
56 typedef struct surf_resource_public {
57   s_surf_action_state_t states; /* Any living action on this resource */
58   void *(*name_service)(const char *name);
59   const char *(*get_resource_name)(void *resource_id);
60
61   e_surf_action_state_t (*action_get_state)(surf_action_t action);
62   void (*action_free)(surf_action_t action);
63   void (*action_cancel)(surf_action_t action);
64   void (*action_recycle)(surf_action_t action); 
65   void (*action_change_state)(surf_action_t action,
66                               e_surf_action_state_t state);
67 } s_surf_resource_public_t, *surf_resource_public_t;
68
69 typedef struct surf_resource {
70   surf_resource_private_t common_private;
71   surf_resource_public_t common_public;
72 } s_surf_resource_t;
73
74 typedef struct surf_resource_object {
75   surf_resource_t resource;
76 } s_surf_resource_object_t, *surf_resource_object_t;
77
78 /**************************************/
79 /* Implementations of resource object */
80 /**************************************/
81 /* Cpu resource */
82 typedef enum {
83   SURF_CPU_ON = 1,              /* Ready        */
84   SURF_CPU_OFF = 0              /* Running      */
85 } e_surf_cpu_state_t;
86
87 typedef struct surf_cpu_resource_extension_private *surf_cpu_resource_extension_private_t;
88 typedef struct surf_cpu_resource_extension_public {
89   surf_action_t(*execute) (void *cpu, xbt_maxmin_float_t size);
90   surf_action_t(*wait) (void *cpu, xbt_maxmin_float_t size);
91   e_surf_cpu_state_t(*get_state) (void *cpu);
92 } s_surf_cpu_resource_extension_public_t, *surf_cpu_resource_extension_public_t;
93
94 typedef struct surf_cpu_resource {
95   surf_resource_private_t common_private;
96   surf_resource_public_t common_public;
97 /*   surf_cpu_resource_extension_private_t extension_private; */
98   surf_cpu_resource_extension_public_t extension_public;
99 } s_surf_cpu_resource_t, *surf_cpu_resource_t;
100 extern surf_cpu_resource_t surf_cpu_resource;
101 void surf_cpu_resource_init(const char *filename);
102
103 /* Network resource */
104 typedef struct surf_network_resource_extension_private *surf_network_resource_extension_private_t;
105 typedef struct surf_network_resource_extension_public {
106   surf_action_t(*communicate) (void *src, void *dst,
107                                xbt_maxmin_float_t size);
108 } s_surf_network_resource_extension_public_t, *surf_network_resource_extension_public_t;
109
110 typedef struct surf_network_resource {
111   surf_resource_private_t common_private;
112   surf_resource_public_t common_public;
113 /*   surf_network_resource_extension_private_t extension_private; */
114   surf_network_resource_extension_public_t extension_public;
115 } s_surf_network_resource_t, *surf_network_resource_t;
116
117 extern surf_network_resource_t surf_network_resource;
118 void surf_network_resource_init(const char *filename);
119
120 /*******************************************/
121 /*** SURF Globals **************************/
122 /*******************************************/
123
124 void surf_init(void);           /* initialize common structures */
125 xbt_heap_float_t surf_solve(void);      /*  update all states and returns
126                                            the time elapsed since last
127                                            event */
128 xbt_heap_float_t surf_get_clock(void);
129 void surf_finalize(void);               /* clean everything */
130
131 #endif                          /* _SURF_SURF_H */