Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Renamed host to cpu. That was really confusing.
[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 /* Never create s_surf_action_t by yourself !!!! */
30 /* Use action_new from the corresponding resource */
31 typedef struct surf_action {
32   s_xbt_swag_hookup_t state_hookup;
33   xbt_swag_t state_set;
34   xbt_maxmin_float_t cost;      /* cost        */
35   xbt_maxmin_float_t remains;   /* How much of that cost remains to
36                                  * be done in the currently running task */
37   xbt_heap_float_t start;       /* start time  */
38   xbt_heap_float_t finish;      /* finish time : this is modified during the run
39                                  * and fluctuates until the task is completed */
40   void *callback;               /* for your convenience */
41   surf_resource_t resource_type;
42 } s_surf_action_t;
43
44 /***************************/
45 /* Generic resource object */
46 /***************************/
47 typedef struct surf_resource {
48   void (*parse_file)(const char *file);
49   void *(*name_service)(const char *name);
50   const char *(*get_resource_name)(void *resource_id);
51
52   /*   surf_action_t (*action_new)(void *callback);  */
53   /* Not defined here. Actions have to be created by actually
54      performing it and prototype may therefore vary with the resource
55      implementation */
56
57   e_surf_action_state_t (*action_get_state)(surf_action_t action);
58   void (*action_free)(surf_action_t * action);  /* Call it when you're done with this action */
59   void (*action_cancel)(surf_action_t action); /* remove the variables from the linear system if needed */
60   void (*action_recycle)(surf_action_t action); /* More efficient than free/new */
61   void (*action_change_state)(surf_action_t action, e_surf_action_state_t state);
62
63   xbt_heap_float_t (*share_resources)(void); /* Share the resources to the 
64                                                 actions and return the potential 
65                                                 next action termination */
66   void (*solve)(xbt_heap_float_t date); /* Advance time to "date" and update
67                                            the actions' state*/
68 } s_surf_resource_t;
69
70 /**************************************/
71 /* Implementations of resource object */
72 /**************************************/
73 /* Cpu resource */
74 typedef enum {
75   SURF_CPU_ON = 1,              /* Ready        */
76   SURF_CPU_OFF = 0,             /* Running      */
77 } e_surf_cpu_state_t;
78
79 typedef struct surf_cpu_resource {
80   s_surf_resource_t resource;
81   surf_action_t (*execute)(void *cpu, xbt_maxmin_float_t size);
82   e_surf_cpu_state_t (*get_state)(void *cpu);
83 } s_surf_cpu_resource_t, *surf_cpu_resource_t;
84 extern surf_cpu_resource_t surf_cpu_resource;
85
86 /* Network resource */
87 typedef struct surf_network_resource {
88   s_surf_resource_t resource;
89   surf_action_t (*communicate)(void *src, void *dst, xbt_maxmin_float_t size);
90 } s_surf_network_resource_t, surf_network_resource_t;
91 extern surf_network_resource_t surf_network_resource;
92
93 /* Timer resource */
94 typedef struct surf_timer_resource {
95   s_surf_resource_t resource;
96   surf_action_t (*wait)(void *cpu, void *dst, xbt_maxmin_float_t size);
97 } s_surf_timer_resource_t, surf_timer_resource_t;
98 extern surf_timer_resource_t surf_timer_resource;
99
100 /*******************************************/
101 /*** SURF Globals **************************/
102 /*******************************************/
103 typedef struct surf_global {
104   xbt_swag_t ready_action_set;
105   xbt_swag_t running_action_set;
106   xbt_swag_t failed_action_set;
107   xbt_swag_t done_action_set;
108 } s_surf_global_t;
109 /* The main function */
110 extern s_surf_global_t surf_global;
111
112 void surf_init(void); /* initialize all resource objects */
113 xbt_heap_float_t surf_solve(void); /* returns the next date */
114
115 #endif                          /* _SURF_SURF_H */