Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
c4fbe623098b1f87f1a61fd5db4af96d9cd2441e
[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   int (*resource_used)(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 *surf_cpu_resource_extension_private_t;
89 typedef struct surf_cpu_resource_extension_public {
90   surf_action_t(*execute) (void *cpu, xbt_maxmin_float_t size);
91   surf_action_t(*wait) (void *cpu, xbt_maxmin_float_t size);
92   e_surf_cpu_state_t(*get_state) (void *cpu);
93 } s_surf_cpu_resource_extension_public_t, *surf_cpu_resource_extension_public_t;
94
95 typedef struct surf_cpu_resource {
96   surf_resource_private_t common_private;
97   surf_resource_public_t common_public;
98 /*   surf_cpu_resource_extension_private_t extension_private; */
99   surf_cpu_resource_extension_public_t extension_public;
100 } s_surf_cpu_resource_t, *surf_cpu_resource_t;
101 extern surf_cpu_resource_t surf_cpu_resource;
102 void surf_cpu_resource_init(const char *filename);
103
104 /* Network resource */
105 typedef struct surf_network_resource_extension_private *surf_network_resource_extension_private_t;
106 typedef struct surf_network_resource_extension_public {
107   surf_action_t(*communicate) (void *src, void *dst,
108                                xbt_maxmin_float_t size);
109 } s_surf_network_resource_extension_public_t, *surf_network_resource_extension_public_t;
110
111 typedef struct surf_network_resource {
112   surf_resource_private_t common_private;
113   surf_resource_public_t common_public;
114 /*   surf_network_resource_extension_private_t extension_private; */
115   surf_network_resource_extension_public_t extension_public;
116 } s_surf_network_resource_t, *surf_network_resource_t;
117
118 extern surf_network_resource_t surf_network_resource;
119 void surf_network_resource_init(const char *filename);
120
121 /*******************************************/
122 /*** SURF Globals **************************/
123 /*******************************************/
124
125 void surf_init(void);           /* initialize common structures */
126 xbt_heap_float_t surf_solve(void);      /*  update all states and returns
127                                            the time elapsed since last
128                                            event */
129 xbt_heap_float_t surf_get_clock(void);
130
131 #endif                          /* _SURF_SURF_H */