*
* @brief FRESCAN bandwith reservation layer: sched analysis
*
- * This module contains the scheduling analysis data and functions for the
- * admission tests and spare capacity distribution of the negotiation layer.
- * It provides an easy API easy to understand and in the implementation part
- * it makes call to the general sched analysis module of FRSH which is shared
- * with the CPU contracts layer in FRSH.
+ * @version 0.02
*
- * EXAMPLE of utilization:
+ * @date 3-Jul-2008
*
- * INITIALIZATION
- * --------------
- * params.min_prio = 0;
- * params.max_prio = 16;
- * params.overhead = ...;
- * frescan_sa_init(&scenario, ¶ms);
- *
- * NEGOTIATE
- * ---------
- * fadt_freelist_alloc(&freelist_contracts, &id);
- * frescan_sa_add_contract(&scenario, &contracts[id], id);
- * frescan_sa_sched_test(&scenario, &success);
- *
- * if (!success) {
- * frescan_sa_remove_contract(&scenario, id);
- * } else {
- * frescan_sa_spare_capacity(&scenario);
- * vres_id = to_vres(resource_type, resource_id, id);
- * create vres runtime structures;
- *
- * for vres_id in active_vres_id {
- * frescan_sa_get_final_values(&scenario,
- * to_index(vres_id),
- * &final_values);
- * update vres runtime structures if necessary;
- * }
- * }
- *
- * RENEGOTIATE
- * -----------
- * copy old_contract
- * frescan_sa_update_contract(&scenario, to_index(vres_id), &contract);
- * frescan_sa_sched_test(&scenario, &success);
- *
- * if (!success) {
- * frescan_sa_update_contract(&sa_data,
- * to_index(vres_id),
- * &old_contract);
- * } else {
- * frescan_sa_spare_capacity(&scenario);
- * for vres_id in active_vres_id {
- * frescan_sa_get_final_values(&scenario,
- * to_index(vres_id),
- * &final_values);
- * update vres runtime structures if necessary;
- * }
- * }
- *
- * CANCEL
- * ------
- * frescan_sa_remove_contract(&scenario, to_index(vres_id));
- * frescan_sa_spare_capacity(&scenario);
+ * @author Daniel Sangorrin <daniel.sangorrin@unican.es>
*
- * @version 0.01
+ * @comments
*
- * @date 15-Apr-2008
+ * This module contains the scheduling analysis functions for the
+ * admission tests and spare capacity distribution of the bandwith
+ * reservation (bwres) layer.
*
- * @author Daniel Sangorrin <daniel.sangorrin@unican.es>
+ * The module "frescan_bwres_mode_change" must be used to apply finally this
+ * new parameters to the sporadic servers following an appropriate mode
+ * change protocol.
*
* @license
*
#include <math.h>
#include <misc/timespec_operations.h>
+#include <misc/linux_list.h>
+#include <misc/freelist.h>
#include "frescan_bwres_analysis.h"
-#undef ERROR
#include "frescan_debug.h"
/**
* frescan_sa_init() - init the scenario
*
- * @scenario: the scenario (in out)
- * @params: init params (in)
+ * Initialize the vres list and copy the initialization parameters
*/
int frescan_sa_init(frescan_sa_scenario_t *scenario,
const frescan_sa_init_params_t *params)
{
-// int ret;
-//
-// ret = frsh_sa_scenario_init(scenario, params);
-// return ret;
+ int ret;
+ frsh_sa_scenario_init_data_t fsa_scenario_init_data;
- INIT_LIST_HEAD(&scenario->contracts_head.list);
+ INIT_LIST_HEAD(&scenario->vres_head.list);
scenario->init_params = *params;
+
+ ret = freelist_init(&scenario->fsa_id_freelist,
+ FRESCAN_MX_NODES*FRESCAN_MX_IDS);
+ if (ret != 0) return ret;
+
+ fsa_scenario_init_data.min_priority = 1;
+ fsa_scenario_init_data.max_priority = 15;
+ fsa_scenario_init_data.ovhd_data.np =
+ frsh_rel_time_to_sa_time(frsh_usec_to_rel_time(0));
+
+ ret = frsh_sa_scenario_init(&scenario->fsa_scenario,
+ &fsa_scenario_init_data);
+ if (ret != 0) return -1;
+
return 0;
}
/**
* frescan_sa_add_contract() - add a contract to the scenario
*
- * @scenario: the scenario (in out)
- * @contract: the new contract (in)
- * @ss: the preallocated ss identificator (in)
- * @node: the node this contract belongs to (in)
+ * create the corresponding vres structure and set its values, and add the
+ * vres to the vres list
*/
-int frescan_sa_add_contract(frescan_sa_scenario_t *scenario,
- const frescan_contract_t *contract,
- frescan_ss_t ss,
- frescan_node_t node)
+int frescan_sa_add_contract(frescan_sa_scenario_t *scenario,
+ frescan_ss_t ss,
+ frescan_node_t node,
+ const frsh_contract_t *contract)
{
-// int ret;
-//
-// ret = frsh_sa_scenario_add_vres(scenario, contract, id);
-// return ret;
- frescan_sa_contract_t *sa_contract;
+ int ret;
+ frescan_sa_vres_t *sa_vres = &scenario->vres_pool[node][ss];
- sa_contract = &scenario->contracts[node][ss];
+ sa_vres->contract = *contract;
+ sa_vres->node = node;
+ sa_vres->ss = ss;
- sa_contract->contract = *contract;
- sa_contract->node = node;
- sa_contract->ss = ss;
+ ret = freelist_alloc(&scenario->fsa_id_freelist);
+ if (ret < 0) return -1;
- list_add_tail(&sa_contract->list,
- &scenario->contracts_head.list);
+ sa_vres->fsa_vres_global_id = (frsh_sa_vres_id_t)ret;
+
+ list_add_tail(&sa_vres->list,
+ &scenario->vres_head.list);
+
+ ret = frsh_sa_scenario_add_vres(&scenario->fsa_scenario,
+ &sa_vres->contract,
+ sa_vres->fsa_vres_global_id);
+ if (ret != 0) return -1;
return 0;
}
/**
* frescan_sa_update_contract() - update a contract in the scenario
- *
- * @scenario: the scenario (in out)
- * @ss: the ss identificator (in)
- * @node: the node this contract belongs to (in)
- * @contract: the values to update the contract (in)
- * @old_contract: the values of the previous contract. Can be NULL (out)
*/
-int frescan_sa_update_contract(frescan_sa_scenario_t *scenario,
- frescan_ss_t ss,
- frescan_node_t node,
- const frescan_contract_t *contract,
- frescan_contract_t *old_contract)
+int frescan_sa_update_contract(frescan_sa_scenario_t *scenario,
+ frescan_ss_t ss,
+ frescan_node_t node,
+ const frsh_contract_t *contract,
+ frsh_contract_t *old_contract)
{
-// int ret;
-//
-// ret = frsh_sa_scenario_modify_vres(scenario, id, *contract);
-// return ret;
- frescan_sa_contract_t *sa_contract;
-
- sa_contract = &scenario->contracts[node][ss];
+ int ret;
+ frescan_sa_vres_t *sa_vres = &scenario->vres_pool[node][ss];
if (old_contract != NULL) {
- *old_contract = sa_contract->contract;
+ *old_contract = sa_vres->contract;
}
- sa_contract->contract = *contract;
+ sa_vres->contract = *contract;
+
+ ret = frsh_sa_scenario_modify_vres(&scenario->fsa_scenario,
+ sa_vres->fsa_vres_global_id,
+ &sa_vres->contract);
+ if (ret != 0) return -1;
return 0;
}
/**
* frescan_sa_remove_contract() - remove a contract from the scenario
- *
- * @scenario: the scenario (in out)
- * @ss: the ss to remove (in)
- * @node: the node this contract belongs to (in)
*/
int frescan_sa_remove_contract(frescan_sa_scenario_t *scenario,
frescan_ss_t ss,
frescan_node_t node)
{
-// int ret;
-//
-// ret = frsh_sa_scenario_del_vres(scenario, id);
-// return ret;
- frescan_sa_contract_t *sa_contract;
+ int ret;
+ frescan_sa_vres_t *sa_vres = &scenario->vres_pool[node][ss];
+
+ ret = frsh_sa_scenario_del_vres(&scenario->fsa_scenario,
+ sa_vres->fsa_vres_global_id);
+ if (ret != 0) return -1;
+
+ ret = freelist_free(&scenario->fsa_id_freelist,
+ sa_vres->fsa_vres_global_id);
+ if (ret < 0) return -1;
- sa_contract = &scenario->contracts[node][ss];
- list_del(&sa_contract->list);
+ list_del(&sa_vres->list);
return 0;
}
/**
* frescan_sa_sched_test() - perform a scheduling test on the scenario
*
- * @scenario: the scenario (in out)
- * @success: if the scenario is schedulable or not (out)
*/
int frescan_sa_sched_test(frescan_sa_scenario_t *scenario,
- bool *success)
+ bool *is_schedulable)
{
-// int ret;
-//
-// ret = frsh_sa_scenario_reset_to_min(scenario, NULL, NULL);
-// if (ret != 0) goto error;
-//
-// ret = frsh_sa_assign_priorities(scenario, NULL, NULL, NULL, NULL);
-// if (ret != 0) goto error;
-//
-// ret = frsh_sa_ceilings_ok(scenario);
-// if (ret != 0) goto error;
-//
-// ret = frsh_sa_calculate_blockings(scenario);
-// if (ret != 0) goto error;
-//
-// ret = frsh_sa_sched_test(scenario, success);
-// if (ret != 0) goto error;
-//
-// return 0;
-//
-// error:
-// *success = false;
-// return ret;
-
- struct list_head *pos;
- frescan_sa_contract_t *sa_contract;
- int num_contracts;
- double utilization, max_utilization, budget, period;
-
- // WARNING("simplified ub test (no blocks, prio ordered)\n");
-
- utilization = 0.0;
- num_contracts = 0;
-
- list_for_each(pos, &scenario->contracts_head.list) {
- sa_contract = list_entry(pos, frescan_sa_contract_t, list);
- sa_contract->final_values.server_prio = sa_contract->contract.prio;
-
- budget = (double)sa_contract->contract.min_values.budget *
- (double)FRESCAN_FRAME_TX_TIME_US;
-
- period = timespec_to_double
- (&sa_contract->contract.min_values.period);
-
- utilization = utilization + (budget / period);
-
- num_contracts++;
-
- DEBUG(FRESCAN_SA_ENABLE_DEBUG,
- "sa_contract, node:%d ss:%d, c:%d t:(%d,%d) p:%d\n",
- sa_contract->node, sa_contract->ss,
- sa_contract->contract.min_values.budget,
- sa_contract->contract.min_values.period.tv_sec,
- sa_contract->contract.min_values.period.tv_nsec,
- sa_contract->contract.prio);
- }
+ int ret;
- max_utilization = num_contracts *
- (pow(2.0, 1.0/(double)num_contracts) - 1);
+ ret = frsh_sa_init_analysis(&scenario->fsa_scenario);
+ if (ret != 0) return -1;
- DEBUG(FRESCAN_SA_ENABLE_DEBUG, "u:%f n:%d u_max:%f %s\n",
- utilization, num_contracts, max_utilization,
- (utilization < max_utilization) ? "accepted" : "not accepted");
+ ret = frsh_sa_assign_priorities(&scenario->fsa_scenario);
+ if (ret != 0) return -1;
- if (utilization < max_utilization) {
- *success = true;
- } else {
- *success = false;
- }
+ ret = frsh_sa_sched_test(&scenario->fsa_scenario, is_schedulable);
+ if (ret != 0) return -1;
return 0;
}
/**
- * frescan_sa_spare_capacity() - distribute the remaining spare capacity
- *
- * @scenario: the scenario (in out)
+ * frescan_sa_spare_capacity() - distribute the spare capacity
*/
int frescan_sa_spare_capacity(frescan_sa_scenario_t *scenario)
{
-// int ret;
-//
-// ret = frsh_sa_distribute_spare(scenario,
-// NULL, NULL, NULL, NULL, NULL, NULL);
-// return ret;
- WARNING("not implemented, returning 0\n");
- return 0;
-}
-
-/**
- * frescan_sa_get_final_values() - get the final values
- *
- * @scenario: the scenario (in)
- * @ss: the ss from which we want the final values (in)
- * @node: the node this contract belongs to (in)
- * @final_values: the final values (out)
- */
-
-
-int frescan_sa_get_final_values(const frescan_sa_scenario_t *scenario,
- frescan_ss_t ss,
- frescan_node_t node,
- frescan_sa_final_values_t *final_values)
-{
-// final_values->budget = scenario->sa_vres_alloc[id].c;
-// final_values->period = scenario->sa_vres_alloc[id].t;
-// final_values->deadline = scenario->sa_vres_alloc[id].d;
-// final_values->priority = scenario->sa_vres_alloc[id].p;
-// return 0;
+ int ret;
- *final_values = scenario->contracts[node][ss].final_values;
+ ret = frsh_sa_distribute_spare(&scenario->fsa_scenario);
+ if (ret != 0) return -1;
return 0;
}