]> rtime.felk.cvut.cz Git - frescor/fna.git/blobdiff - src_frescan/frescan_bwres_analysis.c
error in mapping function corrected using ceil... packets constant moved to config...
[frescor/fna.git] / src_frescan / frescan_bwres_analysis.c
index eda9c8c1ee94ca1ad977afa2a62c8a04cb2620f3..85a66bae3a7f2dd66f5ae4d2aca0f518f5835b16 100644 (file)
  *
  */
 
+#include <math.h>
+#include <misc/timespec_operations.h>
 #include "frescan_bwres_analysis.h"
 #undef ERROR
 #include "frescan_debug.h"
-// #include "frsh_sa_tools.h"
-
 
 /**
  * frescan_sa_init() - init the scenario
+ *
+ * @scenario: the scenario (in out)
+ * @params: init params (in)
  */
 
-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");
+
+        INIT_LIST_HEAD(&scenario->contracts_head.list);
+        scenario->init_params = *params;
         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)
  */
 
-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,
+                            const frescan_contract_t *contract,
+                            frescan_ss_t             ss,
+                            frescan_node_t           node)
 {
 //         int ret;
 //
 //         ret = frsh_sa_scenario_add_vres(scenario, contract, id);
 //         return ret;
-        WARNING("not implemented, returning 0\n");
+        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);
+
         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(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 frescan_contract_t *contract,
+                               frescan_contract_t       *old_contract)
 {
 //         int ret;
 //
 //         ret = frsh_sa_scenario_modify_vres(scenario, id, *contract);
 //         return ret;
-        WARNING("not implemented, returning 0\n");
+        frescan_sa_contract_t *sa_contract;
+
+        sa_contract = &scenario->contracts[node][ss];
+
+        if (old_contract != NULL) {
+                *old_contract = sa_contract->contract;
+        }
+
+        sa_contract->contract = *contract;
+
         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(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");
+        frescan_sa_contract_t *sa_contract;
+
+        sa_contract = &scenario->contracts[node][ss];
+        list_del(&sa_contract->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(frsh_sa_scenario_t *scenario,  // in out
-                          bool *success)                 // out
+int frescan_sa_sched_test(frescan_sa_scenario_t *scenario,
+                          bool *success)
 {
 //         int ret;
 //
@@ -169,15 +219,63 @@ int frescan_sa_sched_test(frsh_sa_scenario_t *scenario,  // in out
 // error:
 //         *success = false;
 //         return ret;
-        WARNING("not implemented, returning 0\n");
+
+        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);
+        }
+
+        max_utilization = num_contracts *
+                          (pow(2.0, 1.0/(double)num_contracts) - 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");
+
+        if (utilization < max_utilization) {
+                *success = true;
+        } else {
+                *success = false;
+        }
+
         return 0;
 }
 
 /**
  * frescan_sa_spare_capacity() - distribute the remaining spare capacity
+ *
+ * @scenario: the scenario (in out)
  */
 
-int frescan_sa_spare_capacity(frsh_sa_scenario_t *scenario) // in out
+int frescan_sa_spare_capacity(frescan_sa_scenario_t *scenario)
 {
 //         int ret;
 //
@@ -189,18 +287,27 @@ int frescan_sa_spare_capacity(frsh_sa_scenario_t *scenario) // in out
 }
 
 /**
- * sa_get_final_values() - get the final values
+ * 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 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_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;
-        WARNING("not implemented, returning 0\n");
+
+        *final_values = scenario->contracts[node][ss].final_values;
+
         return 0;
 }