]> 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 cda54eef1fc311dafffd8175a23c2bff784bc4e7..85a66bae3a7f2dd66f5ae4d2aca0f518f5835b16 100644 (file)
@@ -72,6 +72,8 @@
  *
  */
 
+#include <math.h>
+#include <misc/timespec_operations.h>
 #include "frescan_bwres_analysis.h"
 #undef ERROR
 #include "frescan_debug.h"
@@ -133,14 +135,16 @@ int frescan_sa_add_contract(frescan_sa_scenario_t    *scenario,
  *
  * @scenario: the scenario (in out)
  * @ss: the ss identificator (in)
- * @contract: the values to update the contract (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_node_t           node)
+                               frescan_contract_t       *old_contract)
 {
 //         int ret;
 //
@@ -150,9 +154,11 @@ int frescan_sa_update_contract(frescan_sa_scenario_t   *scenario,
 
         sa_contract = &scenario->contracts[node][ss];
 
+        if (old_contract != NULL) {
+                *old_contract = sa_contract->contract;
+        }
+
         sa_contract->contract = *contract;
-        sa_contract->node     = node;
-        sa_contract->ss       = ss;
 
         return 0;
 }
@@ -216,10 +222,28 @@ int frescan_sa_sched_test(frescan_sa_scenario_t *scenario,
 
         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,
@@ -229,8 +253,18 @@ int frescan_sa_sched_test(frescan_sa_scenario_t *scenario,
                       sa_contract->contract.prio);
         }
 
-        WARNING("test not implemented, returning 0 and success by default\n");
-        *success = true;
+        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;
 }