]> rtime.felk.cvut.cz Git - frescor/frsh.git/blob - fres/resmng/fres_sa_scenario.h
Generic allocator: unify terminology (scheduler/allocator)
[frescor/frsh.git] / fres / resmng / fres_sa_scenario.h
1 /**************************************************************************/
2 /* ---------------------------------------------------------------------- */
3 /* Copyright (C) 2006 - 2008 FRESCOR consortium partners:                 */
4 /*                                                                        */
5 /*   Universidad de Cantabria,              SPAIN                         */
6 /*   University of York,                    UK                            */
7 /*   Scuola Superiore Sant'Anna,            ITALY                         */
8 /*   Kaiserslautern University,             GERMANY                       */
9 /*   Univ. Politécnica  Valencia,           SPAIN                        */
10 /*   Czech Technical University in Prague,  CZECH REPUBLIC                */
11 /*   ENEA                                   SWEDEN                        */
12 /*   Thales Communication S.A.              FRANCE                        */
13 /*   Visual Tools S.A.                      SPAIN                         */
14 /*   Rapita Systems Ltd                     UK                            */
15 /*   Evidence                               ITALY                         */
16 /*                                                                        */
17 /*   See http://www.frescor.org for a link to partners' websites          */
18 /*                                                                        */
19 /*          FRESCOR project (FP6/2005/IST/5-034026) is funded             */
20 /*       in part by the European Union Sixth Framework Programme          */
21 /*       The European Union is not liable of any use that may be          */
22 /*       made of this code.                                               */
23 /*                                                                        */
24 /*                                                                        */
25 /*  This file is part of FRSH (FRescor ScHeduler)                         */
26 /*                                                                        */
27 /* FRSH is free software; you can redistribute it and/or modify it        */
28 /* under terms of the GNU General Public License as published by the      */
29 /* Free Software Foundation; either version 2, or (at your option) any    */
30 /* later version.  FRSH is distributed in the hope that it will be        */
31 /* useful, but WITHOUT ANY WARRANTY; without even the implied warranty    */
32 /* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU    */
33 /* General Public License for more details. You should have received a    */
34 /* copy of the GNU General Public License along with FRSH; see file       */
35 /* COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,  */
36 /* Cambridge, MA 02139, USA.                                              */
37 /*                                                                        */
38 /* As a special exception, including FRSH header files in a file,         */
39 /* instantiating FRSH generics or templates, or linking other files       */
40 /* with FRSH objects to produce an executable application, does not       */
41 /* by itself cause the resulting executable application to be covered     */
42 /* by the GNU General Public License. This exception does not             */
43 /* however invalidate any other reasons why the executable file might be  */
44 /* covered by the GNU Public License.                                     */
45 /**************************************************************************/
46
47 /**
48  * @file   fres_sa_scenario.h
49  * @author Michal Sojka <sojkam1@fel.cvut.cz>
50  * @date   Tue Nov 11 08:37:29 2008
51  * 
52  * @brief  Schedulability analysis data structures declarations.
53  * 
54  * 
55  */
56 #ifndef FRES_SA_SCENARIO_H
57 #define FRES_SA_SCENARIO_H
58
59 #include <fres_contract.h>
60 #include <ul_gavlcust.h>
61
62 /**
63  * Represenation of a contract in a scenario.
64  * 
65  */
66 struct fres_sa_contract {
67         fres_contract_id_t id; /**< ID of all contract versions stored here. */
68
69         /** If the contract was already committed, the committed version
70          * is stored here. The contract is moved here from @a reserved
71          * field in fres_resource_manager::commit_contracts(). */
72         struct fres_contract *committed;
73
74         /** The reserved (and not yet committed) version of the
75          * contract.  If a new contract is to be negotiated or an old
76          * one is to be changed, the new version is stored here after
77          * successful admission test. */
78         struct fres_contract *reserved;
79
80         /** If a new contract is to be negotiated it is stored
81          * here. After sucessfull admission test, the contract is
82          * moved to @a reserved field. If the contract is to be
83          * changed, the admission test can compare the committed and
84          * new version and analyze not only the target state but also
85          * the mode change. */
86         struct fres_contract *new;
87
88         /** Convenience pointer, which has the same value as one of @a
89          * new, @a reserved and @a committed. It is meant for simpler
90          * admission tests, which do not evaluate mode changes and
91          * therefore have no need for comparison of committed and new
92          * version of contact. */
93         struct fres_contract *contract;
94
95         
96         void *priv;             /**< Private data for use by admission test  */
97         gavl_node_t node;
98 };
99
100 /**
101  * Scenario for schedulability analysis.
102  *
103  * Basically it represents a set of contracts.
104  *
105  * @warning Do not manipulate the tree direcly through this macros,
106  * instead use fres_sa_scenario_add_contract(),
107  * fres_sa_scenario_del_contract() and
108  * fres_sa_scenario_find_contract().
109  */
110    
111 struct fres_sa_scenario {
112         gavl_cust_root_field_t contracts; /**< GAVL tree of contracts. */
113         unsigned num_contracts; /**< The number if contracts in scenario */
114         int utilization;        /**< Utilization (0-100) used by GUI */
115         void *priv;
116 };
117
118 GAVL_CUST_NODE_INT_DEC(fres_sa_scenario_contract /* cust_prefix */,
119                        struct fres_sa_scenario   /* cust_root_t */,
120                        struct fres_sa_contract   /* cust_item_t */,
121                        fres_contract_id_t        /* cust_key_t */,
122                        contracts                 /* cust_root_node */,
123                        node                      /* cust_item_node */,
124                        id                        /* cust_item_key */,
125                        fres_contract_id_cmp      /* cust_cmp_fnc */);
126
127
128 /**
129  * Expands to for-cycle for traversing all contracts in a
130  * scenario. The actual contract is stored in @a contract variable.
131  * 
132  */
133 #define fres_sa_scenario_for_each_contract(scenario, contract)  \
134         gavl_cust_for_each(fres_sa_scenario_contract, scenario, contract)
135
136
137 struct fres_sa_contract *
138 fres_sa_contract_new(void);
139
140 void
141 fres_sa_contract_destroy(struct fres_sa_contract *sa_contract);
142
143 struct fres_sa_contract *
144 fres_sa_contract_duplicate(const struct fres_sa_contract *sa_contract);
145
146 struct fres_sa_scenario *
147 fres_sa_scenario_new(void);
148
149 void fres_sa_scenario_destroy(struct fres_sa_scenario *scenario);
150
151 struct fres_sa_scenario *
152 fres_sa_scenario_duplicate(const struct fres_sa_scenario *scenario);
153
154 int fres_sa_scenario_add_contract(struct fres_sa_scenario *scenario,
155                                   struct fres_sa_contract *contract);
156
157 int fres_sa_scenario_del_contract(struct fres_sa_scenario *scenario,
158                                   struct fres_sa_contract *contract);
159                                   
160 struct fres_sa_contract *
161 fres_sa_scenario_find_contract(const struct fres_sa_scenario *scenario,
162                                fres_contract_id_t *id);
163
164 #endif