2 * @file frescan_bwres_analysis.c
4 * @brief FRESCAN bandwith reservation layer: sched analysis
6 * This module contains the scheduling analysis data and functions for the
7 * admission tests and spare capacity distribution of the negotiation layer.
8 * It provides an easy API easy to understand and in the implementation part
9 * it makes call to the general sched analysis module of FRSH which is shared
10 * with the CPU contracts layer in FRSH.
12 * EXAMPLE of utilization:
16 * params.min_prio = 0;
17 * params.max_prio = 16;
18 * params.overhead = ...;
19 * frescan_sa_init(&scenario, ¶ms);
23 * fadt_freelist_alloc(&freelist_contracts, &id);
24 * frescan_sa_add_contract(&scenario, &contracts[id], id);
25 * frescan_sa_sched_test(&scenario, &success);
28 * frescan_sa_remove_contract(&scenario, id);
30 * frescan_sa_spare_capacity(&scenario);
31 * vres_id = to_vres(resource_type, resource_id, id);
32 * create vres runtime structures;
34 * for vres_id in active_vres_id {
35 * frescan_sa_get_final_values(&scenario,
38 * update vres runtime structures if necessary;
45 * frescan_sa_update_contract(&scenario, to_index(vres_id), &contract);
46 * frescan_sa_sched_test(&scenario, &success);
49 * frescan_sa_update_contract(&sa_data,
53 * frescan_sa_spare_capacity(&scenario);
54 * for vres_id in active_vres_id {
55 * frescan_sa_get_final_values(&scenario,
58 * update vres runtime structures if necessary;
64 * frescan_sa_remove_contract(&scenario, to_index(vres_id));
65 * frescan_sa_spare_capacity(&scenario);
71 * @author Daniel Sangorrin <daniel.sangorrin@unican.es>
75 * -----------------------------------------------------------------------
76 * Copyright (C) 2006 - 2008 FRESCOR consortium partners:
78 * Universidad de Cantabria, SPAIN
79 * University of York, UK
80 * Scuola Superiore Sant'Anna, ITALY
81 * Kaiserslautern University, GERMANY
82 * Univ. Politécnica Valencia, SPAIN
83 * Czech Technical University in Prague, CZECH REPUBLIC
85 * Thales Communication S.A. FRANCE
86 * Visual Tools S.A. SPAIN
87 * Rapita Systems Ltd UK
90 * See http://www.frescor.org for a link to partners' websites
92 * FRESCOR project (FP6/2005/IST/5-034026) is funded
93 * in part by the European Union Sixth Framework Programme
94 * The European Union is not liable of any use that may be
97 * This file is part of FRESCAN
99 * FRESCAN is free software; you can redistribute it and/or modify
100 * it under the terms of the GNU General Public License as published by
101 * the Free Software Foundation; either version 2, or (at your option)
104 * FRESCAN is distributed in the hope that it will be useful, but
105 * WITHOUT ANY WARRANTY; without even the implied warranty of
106 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
107 * General Public License for more details.
109 * You should have received a copy of the GNU General Public License
110 * distributed with FRESCAN; see file COPYING. If not, write to the
111 * Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
114 * As a special exception, including FRESCAN header files in a file,
115 * instantiating FRESCAN generics or templates, or linking other files
116 * with FRESCAN objects to produce an executable application, does not
117 * by itself cause the resulting executable application to be covered
118 * by the GNU General Public License. This exception does not
119 * however invalidate any other reasons why the executable file might be
120 * covered by the GNU Public License.
121 * -----------------------------------------------------------------------
126 #include <misc/timespec_operations.h>
127 #include "frescan_bwres_analysis.h"
129 #include "frescan_debug.h"
132 * frescan_sa_init() - init the scenario
134 * @scenario: the scenario (in out)
135 * @params: init params (in)
138 int frescan_sa_init(frescan_sa_scenario_t *scenario,
139 const frescan_sa_init_params_t *params)
143 // ret = frsh_sa_scenario_init(scenario, params);
146 INIT_LIST_HEAD(&scenario->contracts_head.list);
147 scenario->init_params = *params;
152 * frescan_sa_add_contract() - add a contract to the scenario
154 * @scenario: the scenario (in out)
155 * @contract: the new contract (in)
156 * @ss: the preallocated ss identificator (in)
157 * @node: the node this contract belongs to (in)
160 int frescan_sa_add_contract(frescan_sa_scenario_t *scenario,
161 const frescan_contract_t *contract,
167 // ret = frsh_sa_scenario_add_vres(scenario, contract, id);
169 frescan_sa_contract_t *sa_contract;
171 sa_contract = &scenario->contracts[node][ss];
173 sa_contract->contract = *contract;
174 sa_contract->node = node;
175 sa_contract->ss = ss;
177 list_add_tail(&sa_contract->list,
178 &scenario->contracts_head.list);
184 * frescan_sa_update_contract() - update a contract in the scenario
186 * @scenario: the scenario (in out)
187 * @ss: the ss identificator (in)
188 * @node: the node this contract belongs to (in)
189 * @contract: the values to update the contract (in)
190 * @old_contract: the values of the previous contract. Can be NULL (out)
193 int frescan_sa_update_contract(frescan_sa_scenario_t *scenario,
196 const frescan_contract_t *contract,
197 frescan_contract_t *old_contract)
201 // ret = frsh_sa_scenario_modify_vres(scenario, id, *contract);
203 frescan_sa_contract_t *sa_contract;
205 sa_contract = &scenario->contracts[node][ss];
207 if (old_contract != NULL) {
208 *old_contract = sa_contract->contract;
211 sa_contract->contract = *contract;
217 * frescan_sa_remove_contract() - remove a contract from the scenario
219 * @scenario: the scenario (in out)
220 * @ss: the ss to remove (in)
221 * @node: the node this contract belongs to (in)
224 int frescan_sa_remove_contract(frescan_sa_scenario_t *scenario,
230 // ret = frsh_sa_scenario_del_vres(scenario, id);
232 frescan_sa_contract_t *sa_contract;
234 sa_contract = &scenario->contracts[node][ss];
235 list_del(&sa_contract->list);
241 * frescan_sa_sched_test() - perform a scheduling test on the scenario
243 * @scenario: the scenario (in out)
244 * @success: if the scenario is schedulable or not (out)
247 int frescan_sa_sched_test(frescan_sa_scenario_t *scenario,
252 // ret = frsh_sa_scenario_reset_to_min(scenario, NULL, NULL);
253 // if (ret != 0) goto error;
255 // ret = frsh_sa_assign_priorities(scenario, NULL, NULL, NULL, NULL);
256 // if (ret != 0) goto error;
258 // ret = frsh_sa_ceilings_ok(scenario);
259 // if (ret != 0) goto error;
261 // ret = frsh_sa_calculate_blockings(scenario);
262 // if (ret != 0) goto error;
264 // ret = frsh_sa_sched_test(scenario, success);
265 // if (ret != 0) goto error;
273 struct list_head *pos;
274 frescan_sa_contract_t *sa_contract;
276 double utilization, max_utilization, budget, period;
278 // WARNING("simplified ub test (no blocks, prio ordered)\n");
283 list_for_each(pos, &scenario->contracts_head.list) {
284 sa_contract = list_entry(pos, frescan_sa_contract_t, list);
285 sa_contract->final_values.server_prio = sa_contract->contract.prio;
287 budget = (double)sa_contract->contract.min_values.budget *
288 (double)FRESCAN_FRAME_TX_TIME_US;
290 period = timespec_to_double
291 (&sa_contract->contract.min_values.period);
293 utilization = utilization + (budget / period);
297 DEBUG(FRESCAN_SA_ENABLE_DEBUG,
298 "sa_contract, node:%d ss:%d, c:%d t:(%d,%d) p:%d\n",
299 sa_contract->node, sa_contract->ss,
300 sa_contract->contract.min_values.budget,
301 sa_contract->contract.min_values.period.tv_sec,
302 sa_contract->contract.min_values.period.tv_nsec,
303 sa_contract->contract.prio);
306 max_utilization = num_contracts *
307 (pow(2.0, 1.0/(double)num_contracts) - 1);
309 DEBUG(FRESCAN_SA_ENABLE_DEBUG, "u:%f n:%d u_max:%f %s\n",
310 utilization, num_contracts, max_utilization,
311 (utilization < max_utilization) ? "accepted" : "not accepted");
313 if (utilization < max_utilization) {
323 * frescan_sa_spare_capacity() - distribute the remaining spare capacity
325 * @scenario: the scenario (in out)
328 int frescan_sa_spare_capacity(frescan_sa_scenario_t *scenario)
332 // ret = frsh_sa_distribute_spare(scenario,
333 // NULL, NULL, NULL, NULL, NULL, NULL);
335 WARNING("not implemented, returning 0\n");
340 * frescan_sa_get_final_values() - get the final values
342 * @scenario: the scenario (in)
343 * @ss: the ss from which we want the final values (in)
344 * @node: the node this contract belongs to (in)
345 * @final_values: the final values (out)
349 int frescan_sa_get_final_values(const frescan_sa_scenario_t *scenario,
352 frescan_sa_final_values_t *final_values)
354 // final_values->budget = scenario->sa_vres_alloc[id].c;
355 // final_values->period = scenario->sa_vres_alloc[id].t;
356 // final_values->deadline = scenario->sa_vres_alloc[id].d;
357 // final_values->priority = scenario->sa_vres_alloc[id].p;
360 *final_values = scenario->contracts[node][ss].final_values;