1 /**************************************************************************/
2 /* ---------------------------------------------------------------------- */
3 /* Copyright (C) 2006 - 2008 FRESCOR consortium partners: */
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 */
12 /* Thales Communication S.A. FRANCE */
13 /* Visual Tools S.A. SPAIN */
14 /* Rapita Systems Ltd UK */
17 /* See http://www.frescor.org for a link to partners' websites */
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. */
25 /* This file is part of FRSH (FRescor ScHeduler) */
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. */
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 /**************************************************************************/
48 * @file frsh_spare_capacity.c
49 * @author Dario Faggioli <faggioli@gandalf.sssup.it>
50 * @author Michal Sojka <sojkam1@fel.cvut.cz>
52 * @brief Implementation of FRSH contract API on top of FRES contracts.
56 #include <fres_contract.h>
57 #include <fres_contract_idl.h>
58 #include <frsh_core.h>
59 #include <frsh_error.h>
60 #include <fres_blocks.h>
63 #include "frsh_forb.h"
64 #include <fra_generic.h>
66 int frsh_contract_set_reclamation_params
67 (frsh_contract_t *contract,
68 const struct timespec *stability_time,
69 const struct timespec *budget_max,
70 const struct timespec *period_min,
71 frsh_granularity_t granularity,
72 const frsh_utilization_set_t *utilization_set,
76 fres_block_spare_capacity *s;
79 if (!contract || !*contract ||
80 !stability_time || !budget_max || !period_min)
81 return FRSH_ERR_BAD_ARGUMENT;
83 if (fosa_rel_time_is_null(*budget_max) ||
84 fosa_rel_time_is_null(*period_min) ||
85 fosa_rel_time_smaller(*period_min, *budget_max))
86 return FRSH_ERR_BAD_ARGUMENT;
88 if ((granularity == FRSH_GR_CONTINUOUS && utilization_set != NULL) ||
89 (granularity == FRSH_GR_DISCRETE && utilization_set == NULL))
90 return FRSH_ERR_BAD_ARGUMENT;
92 if (granularity != FRSH_GR_CONTINUOUS &&
93 granularity != FRSH_GR_DISCRETE)
94 return FRSH_ERR_NOT_IMPLEMENTED;
96 s = malloc(sizeof(*s));
97 if (!s) return ENOMEM;
98 memset(s, 0, sizeof(*s));
100 s->budget = *budget_max;
101 s->period = *period_min;
102 s->granularity = granularity;
104 if (utilization_set) {
106 if (!forb_sequence_alloc_buf(s->variants, utilization_set->size)) {
109 for (i=0; i<utilization_set->size; i++) {
110 struct fres_container *c = NULL;
111 fres_block_basic *b = NULL;
112 fres_block_timing_reqs *t = NULL;
113 c = fres_container_new();
116 b = malloc(sizeof(*b));
119 t = malloc(sizeof(*t));
123 b->budget = utilization_set->utilizations[i].budget;
124 b->period = utilization_set->utilizations[i].period;
125 /* FIXME: workload and contract type should be
126 * the same as in basic_params. The easyest
127 * solution would be to split basic block to
128 * two blocks - (budget, period) and
129 * (workload, contract_type).
130 * Note: frsh_contract_set_reclamation_params()
131 * should be defined differently. */
132 b->workload = FRSH_WT_BOUNDED;
133 b->contract_type = FRSH_CT_REGULAR;
134 ret = fres_container_add_basic(c, b);
136 t->d_equals_t = true; /* FIXME: the same as above */
137 t->deadline = utilization_set->utilizations[i].deadline;
139 ret = fres_container_add_timing_reqs(c, t);
141 forb_sequence_elem(s->variants, i) = c;
144 fres_container_destroy(c);
145 free(b); /* FIXME: Possible double free */
149 s->variants._length = utilization_set->size;
151 /* TODO: In case of CONTINUOUS granularity copy min and max
152 * requirements to the variants. */
153 s->importance = importance;
155 s->stability_time = *stability_time;
157 fres_contract_del_spare_capacity(*contract);
158 ret = fres_contract_add_spare_capacity(*contract, s);
163 return FRSH_NO_ERROR;
165 forb_sequence_free_buf(s->variants, forb_no_destructor);
170 int frsh_contract_get_reclamation_params
171 (const frsh_contract_t *contract,
172 struct timespec *stability_time,
173 struct timespec *budget_max,
174 struct timespec *period_min,
175 frsh_granularity_t *granularity,
176 frsh_utilization_set_t *utilization_set,
180 fres_block_spare_capacity *s;
182 if (!contract || !*contract)
183 return FRSH_ERR_BAD_ARGUMENT;
185 s = fres_contract_get_spare_capacity(*contract);
188 *budget_max = s->budget;
190 *period_min = s->period;
192 *granularity = s->granularity;
195 * support utilization-set for discrete spare
196 * capacity distribution.
199 *importance = s->importance;
203 *stability_time = s->stability_time;
205 return FRSH_NO_ERROR;
208 int frsh_vres_get_remaining_stability_time
209 (frsh_vres_id_t vres,
210 struct timespec *stability_time)
212 return FRSH_ERR_NOT_IMPLEMENTED;
215 int frsh_resource_get_capacity
216 (const frsh_resource_type_t resource_type,
217 const frsh_resource_id_t resource_id,
218 const int importance,
221 return FRSH_ERR_NOT_IMPLEMENTED;
224 int frsh_resource_get_total_weight
225 (const frsh_resource_type_t resource_type,
226 const frsh_resource_id_t resource_id,
227 const int importance,
228 uint32_t *total_weight)
230 return FRSH_ERR_NOT_IMPLEMENTED;
233 int frsh_vres_decrease_capacity
234 (frsh_vres_id_t vres_id,
235 struct timespec new_budget,
236 struct timespec new_period)
238 return FRSH_ERR_NOT_IMPLEMENTED;