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 /**************************************************************************/
49 * @author Michal Sojka <sojkam1@fel.cvut.cz>
50 * @date Wed Feb 18 16:06:34 2009
52 * @brief Dummy resource allocator implementation
59 #include <ul_logreg.h>
60 #include <fra_generic.h>
61 #include "res_dummy.h"
63 #include "dummy_config.h"
66 UL_LOG_CUST(ulogd_frs_dummy);
67 ul_log_domain_t ulogd_fra_dummy = {UL_LOGL_MSG, "fra_dummy"};
68 UL_LOGREG_SINGLE_DOMAIN_INIT_FUNCTION(fra_dummy_logreg_domains, ulogd_fra_dummy);
70 struct dummy_vres_priv {
74 static int create_vres(fres_vres_t *vres, void *priv)
77 struct dummy_vres_priv *vres_priv;
78 fres_block_basic *basic;
79 fres_block_dummy_sched *dummy_sched;
84 fres_contract_id_to_string(id, &vres->id, sizeof(id));
85 basic = fres_contract_get_basic(vres->new);
86 dummy_sched = fres_contract_get_dummy_sched(vres->new);
87 vres_priv = malloc(sizeof(vres_priv));
88 vres_priv->num = *my_data;
89 vres->priv = vres_priv;
90 #ifdef CONFIG_RESOURCE_DUMMY_VERBOSE
91 printf("Creating VRes #%d (id=%s, period=%ld ms, budget=%ld ms, priority=%d)\n",
93 fosa_rel_time_to_msec(basic->period),
94 fosa_rel_time_to_msec(basic->budget),
95 dummy_sched ? dummy_sched->priority : -1);
100 static int cancel_vres(fres_vres_t *vres, void *priv)
103 fres_block_basic *basic;
104 fres_block_dummy_sched *dummy_sched;
107 fres_contract_id_to_string(id, &vres->id, sizeof(id));
108 basic = fres_contract_get_basic(vres->allocated);
109 dummy_sched = fres_contract_get_dummy_sched(vres->allocated);
110 #ifdef CONFIG_RESOURCE_DUMMY_VERBOSE
111 struct dummy_vres_priv *vres_priv = vres->priv;
112 printf("Canceling VRes #%d (id=%s, period=%ld ms, budget=%ld ms, priority=%d)\n",
114 fosa_rel_time_to_msec(basic->period),
115 fosa_rel_time_to_msec(basic->budget),
116 dummy_sched ? dummy_sched->priority : 999);
122 static int change_vres(fres_vres_t *vres, void *priv)
124 fres_block_basic *basic[2];
125 fres_block_dummy_sched *dummy_sched[2];
128 fres_contract_id_to_string(id, &vres->id, sizeof(id));
129 basic[0] = fres_contract_get_basic(vres->allocated);
130 basic[1] = fres_contract_get_basic(vres->new);
131 dummy_sched[0] = fres_contract_get_dummy_sched(vres->allocated);
132 dummy_sched[1] = fres_contract_get_dummy_sched(vres->new);
134 #ifdef CONFIG_RESOURCE_DUMMY_VERBOSE
135 struct dummy_vres_priv *vres_priv = vres->priv;
136 printf("Changing VRes #%d (id=%s, period: %ld -> %ld ms, budget: %ld -> %ld ms, priority: %d -> %d)\n",
138 fosa_rel_time_to_msec(basic[0]->period),
139 fosa_rel_time_to_msec(basic[1]->period),
140 fosa_rel_time_to_msec(basic[0]->budget),
141 fosa_rel_time_to_msec(basic[1]->budget),
142 dummy_sched[0] ? dummy_sched[0]->priority : 999,
143 dummy_sched[1] ? dummy_sched[1]->priority : 999);
146 vres->perceived = vres->new;
155 static struct fres_allocator dummy_allocator = {
156 .res_type = DUMMY_RESOURCE_TYPE,
157 .res_id = DUMMY_RESOURCE_ID,
158 /* Here we are using the "simple interface" */
159 .create_vres = create_vres,
160 .cancel_vres = cancel_vres,
161 .change_vres = change_vres,
165 int fra_dummy_init(void)
167 fres_block_register_dummy();
168 return fra_register(&dummy_allocator);
172 * Initializes addition dummy resource allocator.
174 * This is intended for the use in automatic tests which need to work
175 * with multiple resources. The test can initialize several dummy
176 * resources, not just the default one with id 255.
180 * @return Zero on success, non-zero error code on error.
182 int fra_dummy_init_and_activate_id(frsh_resource_id_t res_id)
184 struct fres_allocator *fra;
186 fres_block_register_dummy();
187 fra = malloc(sizeof(*fra));
190 *fra = dummy_allocator;
191 fra->res_id = res_id;
192 fra->priv = malloc(sizeof(int));
193 ret = fra_register(fra);
196 ret = fra_activate(fra->res_type, fra->res_id);