]> rtime.felk.cvut.cz Git - frescor/fna.git/blobdiff - src_frescan/frescan_bwres_analysis.c
changes to use the FRSH FSA module to do the analysis and spare capacity. TODO: finis...
[frescor/fna.git] / src_frescan / frescan_bwres_analysis.c
index eda9c8c1ee94ca1ad977afa2a62c8a04cb2620f3..e55b835691370d7beafaf3e0735217489528f0e7 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.
- *
- * EXAMPLE of utilization:
- *
- * INITIALIZATION
- * --------------
- * params.min_prio = 0;
- * params.max_prio = 16;
- * params.overhead = ...;
- * frescan_sa_init(&scenario, &params);
- *
- * 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);
- *
- * @version 0.01
- *
- * @date 15-Apr-2008
+ * @version 0.02
+ *
+ * @date 3-Jul-2008
  *
  * @author Daniel Sangorrin <daniel.sangorrin@unican.es>
  *
+ * @comments
+ *
+ * This module contains the scheduling analysis functions for the
+ * admission tests and spare capacity distribution of the bandwith
+ * reservation (bwres) layer.
+ *
+ * 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
+ *
+ * -----------------------------------------------------------------------
+ *  Copyright (C) 2006 - 2008 FRESCOR consortium partners:
+ *
+ *    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
+ *
+ *    See http://www.frescor.org for a link to partners' websites
+ *
+ *           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.
+ *
+ *  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"
-// #include "frsh_sa_tools.h"
-
 
 /**
  * frescan_sa_init() - init the scenario
+ *
+ * Initialize the vres list and copy the initialization parameters
  */
 
-int frescan_sa_init(frsh_sa_scenario_t *scenario,         // in out
-                    const frsh_sa_init_params_t *params)  // in
+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;
-        WARNING("not implemented, returning 0\n");
+        int ret;
+        frsh_sa_scenario_init_data_t fsa_scenario_init_data;
+
+        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
+ *
+ * create the corresponding vres structure and set its values, and add the
+ * vres to the vres list
  */
 
-int frescan_sa_add_contract(frsh_sa_scenario_t    *scenario, // in out
-                            const frsh_contract_t *contract, // in
-                            frsh_vres_index_t     id)        // in
+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;
-        WARNING("not implemented, returning 0\n");
+        int ret;
+        frescan_sa_vres_t *sa_vres = &scenario->vres_pool[node][ss];
+
+        sa_vres->contract = *contract;
+        sa_vres->node     = node;
+        sa_vres->ss       = ss;
+
+        ret = freelist_alloc(&scenario->fsa_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);
+
+        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;
 }
 
@@ -113,15 +148,26 @@ int frescan_sa_add_contract(frsh_sa_scenario_t    *scenario, // in out
  * frescan_sa_update_contract() - update a contract in the scenario
  */
 
-int frescan_sa_update_contract(frsh_sa_scenario_t    *scenario, // in out
-                               frsh_vres_index_t     id,        // in
-                               const frsh_contract_t *contract) // in
+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;
-        WARNING("not implemented, returning 0\n");
+        int ret;
+        frescan_sa_vres_t *sa_vres = &scenario->vres_pool[node][ss];
+
+        if (old_contract != NULL) {
+                *old_contract = sa_vres->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;
 }
 
@@ -129,78 +175,58 @@ int frescan_sa_update_contract(frsh_sa_scenario_t    *scenario, // in out
  * frescan_sa_remove_contract() - remove a contract from the scenario
  */
 
-int frescan_sa_remove_contract(frsh_sa_scenario_t *scenario,  // in out
-                               frsh_vres_index_t id)          // 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;
-        WARNING("not implemented, returning 0\n");
+        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;
+
+        list_del(&sa_vres->list);
+
         return 0;
 }
 
 /**
  * frescan_sa_sched_test() - perform a scheduling test on the scenario
+ *
  */
 
-int frescan_sa_sched_test(frsh_sa_scenario_t *scenario,  // in out
-                          bool *success)                 // out
+int frescan_sa_sched_test(frescan_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;
-        WARNING("not implemented, returning 0\n");
-        return 0;
-}
+        int ret;
 
-/**
- * frescan_sa_spare_capacity() - distribute the remaining spare capacity
- */
+        ret = frsh_sa_init_analysis(&scenario->fsa_scenario);
+        if (ret != 0) return -1;
+
+        ret = frsh_sa_assign_priorities(&scenario->fsa_scenario);
+        if (ret != 0) return -1;
+
+        ret = frsh_sa_sched_test(&scenario->fsa_scenario, is_schedulable);
+        if (ret != 0) return -1;
 
-int frescan_sa_spare_capacity(frsh_sa_scenario_t *scenario) // in out
-{
-//         int ret;
-//
-//         ret = frsh_sa_distribute_spare(scenario,
-//                                        NULL, NULL, NULL, NULL, NULL, NULL);
-//         return ret;
-        WARNING("not implemented, returning 0\n");
         return 0;
 }
 
 /**
- * sa_get_final_values() - get the final values
+ * frescan_sa_spare_capacity() - distribute the spare capacity
  */
 
-int sa_get_final_values(const frsh_sa_scenario_t *scenario,      // in
-                        frsh_vres_index_t id,                    // in
-                        frescan_sa_final_values_t *final_values) // out
+int frescan_sa_spare_capacity(frescan_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;
-        WARNING("not implemented, returning 0\n");
+        int ret;
+
+        ret = frsh_sa_distribute_spare(&scenario->fsa_scenario);
+        if (ret != 0) return -1;
+
         return 0;
 }