2 * @file frescan_bwres_analysis.c
4 * @brief FRESCAN bandwith reservation layer: sched analysis
10 * @author Daniel Sangorrin <daniel.sangorrin@unican.es>
14 * This module contains the scheduling analysis functions for the
15 * admission tests and spare capacity distribution of the bandwith
16 * reservation (bwres) layer.
18 * The module "frescan_bwres_mode_change" must be used to apply finally this
19 * new parameters to the sporadic servers following an appropriate mode
24 * -----------------------------------------------------------------------
25 * Copyright (C) 2006 - 2008 FRESCOR consortium partners:
27 * Universidad de Cantabria, SPAIN
28 * University of York, UK
29 * Scuola Superiore Sant'Anna, ITALY
30 * Kaiserslautern University, GERMANY
31 * Univ. Politécnica Valencia, SPAIN
32 * Czech Technical University in Prague, CZECH REPUBLIC
34 * Thales Communication S.A. FRANCE
35 * Visual Tools S.A. SPAIN
36 * Rapita Systems Ltd UK
39 * See http://www.frescor.org for a link to partners' websites
41 * FRESCOR project (FP6/2005/IST/5-034026) is funded
42 * in part by the European Union Sixth Framework Programme
43 * The European Union is not liable of any use that may be
46 * This file is part of FRESCAN
48 * FRESCAN is free software; you can redistribute it and/or modify
49 * it under the terms of the GNU General Public License as published by
50 * the Free Software Foundation; either version 2, or (at your option)
53 * FRESCAN is distributed in the hope that it will be useful, but
54 * WITHOUT ANY WARRANTY; without even the implied warranty of
55 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
56 * General Public License for more details.
58 * You should have received a copy of the GNU General Public License
59 * distributed with FRESCAN; see file COPYING. If not, write to the
60 * Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
63 * As a special exception, including FRESCAN header files in a file,
64 * instantiating FRESCAN generics or templates, or linking other files
65 * with FRESCAN objects to produce an executable application, does not
66 * by itself cause the resulting executable application to be covered
67 * by the GNU General Public License. This exception does not
68 * however invalidate any other reasons why the executable file might be
69 * covered by the GNU Public License.
70 * -----------------------------------------------------------------------
75 #include <misc/timespec_operations.h>
76 #include <misc/linux_list.h>
77 #include <misc/freelist.h>
78 #include "frescan_bwres_analysis.h"
79 #include "frescan_debug.h"
82 * frescan_sa_init() - init the scenario
84 * Initialize the vres list and copy the initialization parameters
87 int frescan_sa_init(frescan_sa_scenario_t *scenario,
88 const frescan_sa_init_params_t *params)
91 frsh_sa_scenario_init_data_t fsa_scenario_init_data;
93 INIT_LIST_HEAD(&scenario->vres_head.list);
94 scenario->init_params = *params;
96 ret = freelist_init(&scenario->fsa_id_freelist,
97 FRESCAN_MX_NODES*FRESCAN_MX_IDS);
98 if (ret != 0) return ret;
100 fsa_scenario_init_data.min_priority = 1;
101 fsa_scenario_init_data.max_priority = 15;
102 fsa_scenario_init_data.ovhd_data.np =
103 frsh_rel_time_to_sa_time(frsh_usec_to_rel_time(0));
105 ret = frsh_sa_scenario_init(&scenario->fsa_scenario,
106 &fsa_scenario_init_data);
107 if (ret != 0) return -1;
113 * frescan_sa_add_contract() - add a contract to the scenario
115 * create the corresponding vres structure and set its values, and add the
116 * vres to the vres list
119 int frescan_sa_add_contract(frescan_sa_scenario_t *scenario,
122 const frsh_contract_t *contract)
125 frescan_sa_vres_t *sa_vres = &scenario->vres_pool[node][ss];
127 sa_vres->contract = *contract;
128 sa_vres->node = node;
131 ret = freelist_alloc(&scenario->fsa_id_freelist);
132 if (ret < 0) return -1;
134 sa_vres->fsa_vres_global_id = (frsh_sa_vres_id_t)ret;
136 list_add_tail(&sa_vres->list,
137 &scenario->vres_head.list);
139 ret = frsh_sa_scenario_add_vres(&scenario->fsa_scenario,
141 sa_vres->fsa_vres_global_id);
142 if (ret != 0) return -1;
148 * frescan_sa_update_contract() - update a contract in the scenario
151 int frescan_sa_update_contract(frescan_sa_scenario_t *scenario,
154 const frsh_contract_t *contract,
155 frsh_contract_t *old_contract)
158 frescan_sa_vres_t *sa_vres = &scenario->vres_pool[node][ss];
160 if (old_contract != NULL) {
161 *old_contract = sa_vres->contract;
164 sa_vres->contract = *contract;
166 ret = frsh_sa_scenario_modify_vres(&scenario->fsa_scenario,
167 sa_vres->fsa_vres_global_id,
169 if (ret != 0) return -1;
175 * frescan_sa_remove_contract() - remove a contract from the scenario
178 int frescan_sa_remove_contract(frescan_sa_scenario_t *scenario,
183 frescan_sa_vres_t *sa_vres = &scenario->vres_pool[node][ss];
185 ret = frsh_sa_scenario_del_vres(&scenario->fsa_scenario,
186 sa_vres->fsa_vres_global_id);
187 if (ret != 0) return -1;
189 ret = freelist_free(&scenario->fsa_id_freelist,
190 sa_vres->fsa_vres_global_id);
191 if (ret < 0) return -1;
193 list_del(&sa_vres->list);
199 * frescan_sa_sched_test() - perform a scheduling test on the scenario
203 int frescan_sa_sched_test(frescan_sa_scenario_t *scenario,
204 bool *is_schedulable)
208 ret = frsh_sa_init_analysis(&scenario->fsa_scenario);
209 if (ret != 0) return -1;
211 ret = frsh_sa_assign_priorities(&scenario->fsa_scenario);
212 if (ret != 0) return -1;
214 ret = frsh_sa_sched_test(&scenario->fsa_scenario, is_schedulable);
215 if (ret != 0) return -1;
221 * frescan_sa_spare_capacity() - distribute the spare capacity
224 int frescan_sa_spare_capacity(frescan_sa_scenario_t *scenario)
228 ret = frsh_sa_distribute_spare(&scenario->fsa_scenario);
229 if (ret != 0) return -1;