summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/examples/FaultTolerance/FLARe/DeCoRAM/src/CTT_Enhanced.cpp
blob: 41d8212439bcc01849c6db6411c4652105ab3a40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// -*- C++ -*-

//=============================================================================
/**
 *  @file    CTT_Enhanced.cpp
 *
 *  $Id$
 *
 *  @author  Friedhelm Wolf (fwolf@dre.vanderbilt.edu)
 */
//=============================================================================

#include <numeric>
#include <cmath>
#include "CTT_Enhanced.h"

CTT_Enhanced::~CTT_Enhanced ()
{
}

double
CTT_Enhanced::operator () (const TASK_LIST & tasks)
{
  // copy tasks for local modifications
  TASK_LIST scheduled_tasks = tasks;

  // take last element and use it for schedulability analysis.
  // It is assumed that all other tasks are schedulable

  if (scheduled_tasks.size () > 0)
    {
      Task t = scheduled_tasks [scheduled_tasks.size () - 1];
      scheduled_tasks.pop_back ();

      double wcrt = this->worst_case_response_time_check (t, scheduled_tasks);

      TRACE ("(" << tasks << ") = " << wcrt);

      // return the wcrt for this task
      return wcrt;
    }

  TRACE ("(" << tasks << ") = 0");
  return .0;
}

double
CTT_Enhanced::worst_case_response_time_check (
  const Task & task, 
  const TASK_LIST & higher_prio_tasks)
{
  // determine execution time based on type of application
  double exec_time = (task.role == PRIMARY ? 
                      task.execution_time : 
                      task.sync_time);

  // R0 = C1 + C2 + ... + Cn
  double R = std::accumulate (higher_prio_tasks.begin (),
			      higher_prio_tasks.end (),
			      exec_time,
			      AddExecutionTimes ());

  // R_k = C1 + sum_j (ceil (R_k-1 / T_j) * Cj)
  double R_copy = 0;
  double_equal equals;

  while (R <= task.period)
    {
      R_copy = R;
      R = std::accumulate (higher_prio_tasks.begin (),
                           higher_prio_tasks.end (),
                           exec_time,
                           WCET_Heuristic_Step (R));

      if (equals (R_copy, R))
        break;
    }

  if (R <= task.period)
    return R;
  else
    return .0;
}

double
CTT_Enhanced::AddExecutionTimes::operator () (double time, const Task & task)
{
  // determine execution time based on type of application
  double exec_time = (task.role == PRIMARY ? 
                      task.execution_time : 
                      task.sync_time);

  return time + exec_time;
}

CTT_Enhanced::WCET_Heuristic_Step::WCET_Heuristic_Step (double R)
  : R_ (R)
{
}

double
CTT_Enhanced::WCET_Heuristic_Step::operator () (double time, const Task & task)
{
  // determine execution time based on type of application
  double exec_time = (task.role == PRIMARY ? 
                      task.execution_time : 
                      task.sync_time);

  return time + 
    ceil (R_ / task.period) * 
    exec_time;
}