]> rtime.felk.cvut.cz Git - frescor/fna.git/blobdiff - src_frescan/frescan_bwres_analysis.c
add debugging message
[frescor/fna.git] / src_frescan / frescan_bwres_analysis.c
index 85a66bae3a7f2dd66f5ae4d2aca0f518f5835b16..b2a6196752ca42dc0331be91091093736f816e84 100644 (file)
  *
  * @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, &params);
+ * @author Daniel Sangorrin <daniel.sangorrin@unican.es>
  *
- * NEGOTIATE
- * ---------
- * fadt_freelist_alloc(&freelist_contracts, &id);
- * frescan_sa_add_contract(&scenario, &contracts[id], id);
- * frescan_sa_sched_test(&scenario, &success);
+ * @comments
  *
- * 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;
+ * This module contains the scheduling analysis functions for the
+ * admission tests and spare capacity distribution of the bandwith
+ * reservation (bwres) layer.
  *
- *      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;
- *      }
- * }
+ * 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.
  *
- * RENEGOTIATE
- * -----------
- * copy old_contract
- * frescan_sa_update_contract(&scenario, to_index(vres_id), &contract);
- * frescan_sa_sched_test(&scenario, &success);
+ * @license
  *
- * 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;
- *      }
- * }
+ * -----------------------------------------------------------------------
+ *  Copyright (C) 2006 - 2008 FRESCOR consortium partners:
  *
- * CANCEL
- * ------
- * frescan_sa_remove_contract(&scenario, to_index(vres_id));
- * frescan_sa_spare_capacity(&scenario);
+ *    Universidad de Cantabria,              SPAIN
+ *    University of York,                    UK
+ *    Scuola Superiore Sant'Anna,            ITALY
+ *    Kaiserslautern University,             GERMANY
+ *    Univ. Politécnica  Valencia,           SPAIN
+ *    Czech Technical University in Prague,  CZECH REPUBLIC
+ *    ENEA                                   SWEDEN
+ *    Thales Communication S.A.              FRANCE
+ *    Visual Tools S.A.                      SPAIN
+ *    Rapita Systems Ltd                     UK
+ *    Evidence                               ITALY
  *
- * @version 0.01
+ *    See http://www.frescor.org for a link to partners' websites
  *
- * @date 15-Apr-2008
+ *           FRESCOR project (FP6/2005/IST/5-034026) is funded
+ *        in part by the European Union Sixth Framework Programme
+ *        The European Union is not liable of any use that may be
+ *        made of this code.
  *
- * @author Daniel Sangorrin <daniel.sangorrin@unican.es>
+ *  This file is part of FRESCAN
+ *
+ *  FRESCAN is free software; you can  redistribute it and/or  modify
+ *  it under the terms of  the GNU General Public License as published by
+ *  the Free Software Foundation;  either  version 2, or (at  your option)
+ *  any later version.
+ *
+ *  FRESCAN  is distributed  in  the hope  that  it  will  be useful,  but
+ *  WITHOUT  ANY  WARRANTY;     without  even the   implied   warranty  of
+ *  MERCHANTABILITY  or  FITNESS FOR  A  PARTICULAR PURPOSE. See  the  GNU
+ *  General Public License for more details.
+ *
+ *  You should have  received a  copy of  the  GNU  General Public License
+ *  distributed  with  FRESCAN;  see file COPYING.   If not,  write to the
+ *  Free Software  Foundation,  59 Temple Place  -  Suite 330,  Boston, MA
+ *  02111-1307, USA.
+ *
+ * As a special exception, including FRESCAN header files in a file,
+ * instantiating FRESCAN generics or templates, or linking other files
+ * with FRESCAN objects to produce an executable application, does not
+ * by itself cause the resulting executable application to be covered
+ * by the GNU General Public License. This exception does not
+ * however invalidate any other reasons why the executable file might be
+ * covered by the GNU Public 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
+ * frescan_bwres_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 frescan_bwres_sa_init(frescan_bwres_sa_scenario_t          *scenario,
+                          const frescan_bwres_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_vres_global_id_freelist,
+                            FRESCAN_MX_NODES*FRESCAN_MX_IDS);
+        if (ret != 0) return ret;
+
+        fsa_scenario_init_data.min_priority = params->min_prio;
+        fsa_scenario_init_data.max_priority = params->max_prio;
+        fsa_scenario_init_data.ovhd_data.np =
+                        frsh_rel_time_to_sa_time(frsh_usec_to_rel_time(0));
+
+        DEBUG(FRESCAN_BWRES_SA_ENABLE_DEBUG,
+              "init the scenario min_prio:%d max_prio:%d\n",
+              params->min_prio, params->max_prio);
+
+        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
+ * frescan_bwres_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_bwres_sa_add_contract(frescan_bwres_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;
-
-        sa_contract = &scenario->contracts[node][ss];
-
-        sa_contract->contract = *contract;
-        sa_contract->node     = node;
-        sa_contract->ss       = ss;
-
-        list_add_tail(&sa_contract->list,
-                      &scenario->contracts_head.list);
+        int ret;
+        frescan_bwres_vres_t *sa_vres = &scenario->vres_pool[node][ss];
+
+        sa_vres->contract = *contract;
+        sa_vres->node     = node;
+        sa_vres->ss       = ss;
+        sa_vres->old_c    = 0;
+        sa_vres->old_t    = 0;
+        sa_vres->old_p    = 0;
+
+        ret = freelist_alloc(&scenario->fsa_vres_global_id_freelist);
+        if (ret < 0) return -1;
+
+        sa_vres->fsa_vres_global_id = (frsh_sa_vres_id_t)ret;
+
+        list_add_tail(&sa_vres->list,
+                      &scenario->vres_head.list);
+
+        DEBUG(FRESCAN_BWRES_SA_ENABLE_DEBUG,
+              "add contract, node:%d ss:%d globalid:%d\n",
+              node, ss, sa_vres->fsa_vres_global_id);
+
+        DEBUG(FRESCAN_BWRES_SA_ENABLE_DEBUG,
+              "contract bmin=(%u,%u) tmax=(%u,%u) bmax=(%u,%u) tmin=(%u,%u) prio=%u\n",
+              contract->budget_min.tv_sec,
+              contract->budget_min.tv_nsec,
+              contract->period_max.tv_sec,
+              contract->period_max.tv_nsec,
+              contract->budget_max.tv_sec,
+              contract->budget_max.tv_nsec,
+              contract->period_min.tv_sec,
+              contract->period_min.tv_nsec,
+              contract->preemption_level);
+
+        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)
+ * frescan_bwres_sa_update_contract() - update a contract in the scenario
  */
 
-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_bwres_sa_update_contract(frescan_bwres_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_bwres_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;
+
+        DEBUG(FRESCAN_BWRES_SA_ENABLE_DEBUG,
+              "update contract node:%d ss:%d globalid:%d\n",
+              node, ss, sa_vres->fsa_vres_global_id);
+
+        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)
+ * frescan_bwres_sa_remove_contract() - remove a contract from the scenario
  */
 
-int frescan_sa_remove_contract(frescan_sa_scenario_t *scenario,
-                               frescan_ss_t          ss,
-                               frescan_node_t        node)
+int frescan_bwres_sa_remove_contract(frescan_bwres_sa_scenario_t *scenario,
+                                     frescan_ss_t                ss,
+                                     frescan_node_t              node,
+                                     frsh_contract_t             *contract)
 {
-//         int ret;
-//
-//         ret = frsh_sa_scenario_del_vres(scenario, id);
-//         return ret;
-        frescan_sa_contract_t *sa_contract;
+        int ret;
+        frescan_bwres_vres_t *sa_vres = &scenario->vres_pool[node][ss];
+
+        if (contract != NULL) {
+                *contract = sa_vres->contract;
+        }
+
+        DEBUG(FRESCAN_BWRES_SA_ENABLE_DEBUG,
+              "remove contract, node:%d ss:%d globalid:%d\n",
+              node, ss, sa_vres->fsa_vres_global_id);
+
+        ret = frsh_sa_scenario_del_vres(&scenario->fsa_scenario,
+                                        sa_vres->fsa_vres_global_id);
+        if (ret != 0) return -1;
 
-        sa_contract = &scenario->contracts[node][ss];
-        list_del(&sa_contract->list);
+        ret = freelist_free(&scenario->fsa_vres_global_id_freelist,
+                            sa_vres->fsa_vres_global_id);
+        if (ret < 0) return -1;
+
+        list_del(&sa_vres->list);
 
         return 0;
 }
 
 /**
- * frescan_sa_sched_test() - perform a scheduling test on the scenario
+ * frescan_bwres_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)
+int frescan_bwres_sa_sched_test(frescan_bwres_sa_scenario_t *scenario,
+                                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;
-
-                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);
+        DEBUG(FRESCAN_BWRES_SA_ENABLE_DEBUG, "init the fsa scenario\n");
 
-        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_init_analysis(&scenario->fsa_scenario);
+        if (ret != 0) return -1;
 
-        if (utilization < max_utilization) {
-                *success = true;
-        } else {
-                *success = false;
-        }
+        ret = frsh_sa_assign_priorities(&scenario->fsa_scenario);
+        if (ret != 0) return -1;
 
-        return 0;
-}
+        DEBUG(FRESCAN_BWRES_SA_ENABLE_DEBUG, "do scheduling test\n");
 
-/**
- * frescan_sa_spare_capacity() - distribute the remaining spare capacity
- *
- * @scenario: the scenario (in out)
- */
+        ret = frsh_sa_sched_test(&scenario->fsa_scenario, is_schedulable);
+        if (ret != 0) return -1;
+
+        DEBUG(FRESCAN_BWRES_SA_ENABLE_DEBUG, "%s\n",
+              (*is_schedulable) ? "OK" : "FAILED");
 
-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)
+ * frescan_bwres_sa_spare_capacity() - distribute the spare capacity
  */
 
-
-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)
+int frescan_bwres_sa_spare_capacity(frescan_bwres_sa_scenario_t *scenario)
 {
-//         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;
+
+        DEBUG(FRESCAN_BWRES_SA_ENABLE_DEBUG, "distribute sc\n");
 
-        *final_values = scenario->contracts[node][ss].final_values;
+        ret = frsh_sa_distribute_spare(&scenario->fsa_scenario);
+        if (ret != 0) return -1;
 
         return 0;
 }