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 * @contract: the values to update the contract (in)
139 * @node: the node this contract belongs to (in)
142 int frescan_sa_update_contract(frescan_sa_scenario_t *scenario,
144 const frescan_contract_t *contract,
149 // ret = frsh_sa_scenario_modify_vres(scenario, id, *contract);
151 frescan_sa_contract_t *sa_contract;
153 sa_contract = &scenario->contracts[node][ss];
155 sa_contract->contract = *contract;
156 sa_contract->node = node;
157 sa_contract->ss = ss;
163 * frescan_sa_remove_contract() - remove a contract from the scenario
165 * @scenario: the scenario (in out)
166 * @ss: the ss to remove (in)
167 * @node: the node this contract belongs to (in)
170 int frescan_sa_remove_contract(frescan_sa_scenario_t *scenario,
176 // ret = frsh_sa_scenario_del_vres(scenario, id);
178 frescan_sa_contract_t *sa_contract;
180 sa_contract = &scenario->contracts[node][ss];
181 list_del(&sa_contract->list);
187 * frescan_sa_sched_test() - perform a scheduling test on the scenario
189 * @scenario: the scenario (in out)
190 * @success: if the scenario is schedulable or not (out)
193 int frescan_sa_sched_test(frescan_sa_scenario_t *scenario,
198 // ret = frsh_sa_scenario_reset_to_min(scenario, NULL, NULL);
199 // if (ret != 0) goto error;
201 // ret = frsh_sa_assign_priorities(scenario, NULL, NULL, NULL, NULL);
202 // if (ret != 0) goto error;
204 // ret = frsh_sa_ceilings_ok(scenario);
205 // if (ret != 0) goto error;
207 // ret = frsh_sa_calculate_blockings(scenario);
208 // if (ret != 0) goto error;
210 // ret = frsh_sa_sched_test(scenario, success);
211 // if (ret != 0) goto error;
219 struct list_head *pos;
220 frescan_sa_contract_t *sa_contract;
222 double utilization, max_utilization, budget, period;
224 WARNING("simplified ub test (no blockings, prio ordered)\n");
229 list_for_each(pos, &scenario->contracts_head.list) {
230 sa_contract = list_entry(pos, frescan_sa_contract_t, list);
231 sa_contract->final_values.server_prio = sa_contract->contract.prio;
233 budget = (double)sa_contract->contract.min_values.budget *
234 (double)FRESCAN_FRAME_TX_TIME;
236 period = timespec_to_double
237 (&sa_contract->contract.min_values.period);
239 utilization = utilization + (budget / period);
243 DEBUG(FRESCAN_SA_ENABLE_DEBUG,
244 "sa_contract, node:%d ss:%d, c:%d t:(%d,%d) p:%d\n",
245 sa_contract->node, sa_contract->ss,
246 sa_contract->contract.min_values.budget,
247 sa_contract->contract.min_values.period.tv_sec,
248 sa_contract->contract.min_values.period.tv_nsec,
249 sa_contract->contract.prio);
252 max_utilization = num_contracts *
253 (pow(2.0, 1.0/(double)num_contracts) - 1);
255 DEBUG(FRESCAN_SA_ENABLE_DEBUG, "u:%f n:%d u_max:%f %s\n",
256 utilization, num_contracts, max_utilization,
257 (utilization < max_utilization) ? "accepted" : "not accepted");
259 if (utilization < max_utilization) {
269 * frescan_sa_spare_capacity() - distribute the remaining spare capacity
271 * @scenario: the scenario (in out)
274 int frescan_sa_spare_capacity(frescan_sa_scenario_t *scenario)
278 // ret = frsh_sa_distribute_spare(scenario,
279 // NULL, NULL, NULL, NULL, NULL, NULL);
281 WARNING("not implemented, returning 0\n");
286 * frescan_sa_get_final_values() - get the final values
288 * @scenario: the scenario (in)
289 * @ss: the ss from which we want the final values (in)
290 * @node: the node this contract belongs to (in)
291 * @final_values: the final values (out)
295 int frescan_sa_get_final_values(const frescan_sa_scenario_t *scenario,
298 frescan_sa_final_values_t *final_values)
300 // final_values->budget = scenario->sa_vres_alloc[id].c;
301 // final_values->period = scenario->sa_vres_alloc[id].t;
302 // final_values->deadline = scenario->sa_vres_alloc[id].d;
303 // final_values->priority = scenario->sa_vres_alloc[id].p;
306 *final_values = scenario->contracts[node][ss].final_values;