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>
76 #include <misc/timespec_operations.h>
77 #include "frescan_bwres_analysis.h"
79 #include "frescan_debug.h"
82 * frescan_sa_init() - init the scenario
84 * @scenario: the scenario (in out)
85 * @params: init params (in)
88 int frescan_sa_init(frescan_sa_scenario_t *scenario,
89 const frescan_sa_init_params_t *params)
93 // ret = frsh_sa_scenario_init(scenario, params);
96 INIT_LIST_HEAD(&scenario->contracts_head.list);
97 scenario->init_params = *params;
102 * frescan_sa_add_contract() - add a contract to the scenario
104 * @scenario: the scenario (in out)
105 * @contract: the new contract (in)
106 * @ss: the preallocated ss identificator (in)
107 * @node: the node this contract belongs to (in)
110 int frescan_sa_add_contract(frescan_sa_scenario_t *scenario,
111 const frescan_contract_t *contract,
117 // ret = frsh_sa_scenario_add_vres(scenario, contract, id);
119 frescan_sa_contract_t *sa_contract;
121 sa_contract = &scenario->contracts[node][ss];
123 sa_contract->contract = *contract;
124 sa_contract->node = node;
125 sa_contract->ss = ss;
127 list_add_tail(&sa_contract->list,
128 &scenario->contracts_head.list);
134 * frescan_sa_update_contract() - update a contract in the scenario
136 * @scenario: the scenario (in out)
137 * @ss: the ss identificator (in)
138 * @node: the node this contract belongs to (in)
139 * @contract: the values to update the contract (in)
140 * @old_contract: the values of the previous contract. Can be NULL (out)
143 int frescan_sa_update_contract(frescan_sa_scenario_t *scenario,
146 const frescan_contract_t *contract,
147 frescan_contract_t *old_contract)
151 // ret = frsh_sa_scenario_modify_vres(scenario, id, *contract);
153 frescan_sa_contract_t *sa_contract;
155 sa_contract = &scenario->contracts[node][ss];
157 if (old_contract != NULL) {
158 *old_contract = sa_contract->contract;
161 sa_contract->contract = *contract;
167 * frescan_sa_remove_contract() - remove a contract from the scenario
169 * @scenario: the scenario (in out)
170 * @ss: the ss to remove (in)
171 * @node: the node this contract belongs to (in)
174 int frescan_sa_remove_contract(frescan_sa_scenario_t *scenario,
180 // ret = frsh_sa_scenario_del_vres(scenario, id);
182 frescan_sa_contract_t *sa_contract;
184 sa_contract = &scenario->contracts[node][ss];
185 list_del(&sa_contract->list);
191 * frescan_sa_sched_test() - perform a scheduling test on the scenario
193 * @scenario: the scenario (in out)
194 * @success: if the scenario is schedulable or not (out)
197 int frescan_sa_sched_test(frescan_sa_scenario_t *scenario,
202 // ret = frsh_sa_scenario_reset_to_min(scenario, NULL, NULL);
203 // if (ret != 0) goto error;
205 // ret = frsh_sa_assign_priorities(scenario, NULL, NULL, NULL, NULL);
206 // if (ret != 0) goto error;
208 // ret = frsh_sa_ceilings_ok(scenario);
209 // if (ret != 0) goto error;
211 // ret = frsh_sa_calculate_blockings(scenario);
212 // if (ret != 0) goto error;
214 // ret = frsh_sa_sched_test(scenario, success);
215 // if (ret != 0) goto error;
223 struct list_head *pos;
224 frescan_sa_contract_t *sa_contract;
226 double utilization, max_utilization, budget, period;
228 WARNING("simplified ub test (no blocks, prio ordered)\n");
233 list_for_each(pos, &scenario->contracts_head.list) {
234 sa_contract = list_entry(pos, frescan_sa_contract_t, list);
235 sa_contract->final_values.server_prio = sa_contract->contract.prio;
237 budget = (double)sa_contract->contract.min_values.budget *
238 (double)FRESCAN_FRAME_TX_TIME;
240 period = timespec_to_double
241 (&sa_contract->contract.min_values.period);
243 utilization = utilization + (budget / period);
247 DEBUG(FRESCAN_SA_ENABLE_DEBUG,
248 "sa_contract, node:%d ss:%d, c:%d t:(%d,%d) p:%d\n",
249 sa_contract->node, sa_contract->ss,
250 sa_contract->contract.min_values.budget,
251 sa_contract->contract.min_values.period.tv_sec,
252 sa_contract->contract.min_values.period.tv_nsec,
253 sa_contract->contract.prio);
256 max_utilization = num_contracts *
257 (pow(2.0, 1.0/(double)num_contracts) - 1);
259 DEBUG(FRESCAN_SA_ENABLE_DEBUG, "u:%f n:%d u_max:%f %s\n",
260 utilization, num_contracts, max_utilization,
261 (utilization < max_utilization) ? "accepted" : "not accepted");
263 if (utilization < max_utilization) {
273 * frescan_sa_spare_capacity() - distribute the remaining spare capacity
275 * @scenario: the scenario (in out)
278 int frescan_sa_spare_capacity(frescan_sa_scenario_t *scenario)
282 // ret = frsh_sa_distribute_spare(scenario,
283 // NULL, NULL, NULL, NULL, NULL, NULL);
285 WARNING("not implemented, returning 0\n");
290 * frescan_sa_get_final_values() - get the final values
292 * @scenario: the scenario (in)
293 * @ss: the ss from which we want the final values (in)
294 * @node: the node this contract belongs to (in)
295 * @final_values: the final values (out)
299 int frescan_sa_get_final_values(const frescan_sa_scenario_t *scenario,
302 frescan_sa_final_values_t *final_values)
304 // final_values->budget = scenario->sa_vres_alloc[id].c;
305 // final_values->period = scenario->sa_vres_alloc[id].t;
306 // final_values->deadline = scenario->sa_vres_alloc[id].d;
307 // final_values->priority = scenario->sa_vres_alloc[id].p;
310 *final_values = scenario->contracts[node][ss].final_values;