summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/examples/FaultTolerance/FLARe/DeCoRAM/src/Algorithms.h
blob: 242e4c69bf9fc2b7e81840133d7dcdde27752401 (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
// -*- C++ -*-

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

#ifndef FTRMFF_ALGORITHMS_H_
#define FTRMFF_ALGORITHMS_H_

#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <functional>

#ifdef DO_TRACE
#  define TRACE(X) std::cout << __PRETTY_FUNCTION__ << ": " << X << std::endl
#else
#  define TRACE(X)
#endif

#ifdef DO_DEBUG
#  define DBG_OUT(X) std::cout << X << std::endl
#else
#  define DBG_OUT(X)
#endif

// Algorithm 1 : Completion Time Test

// The following data structures and the CTT_Algorithm represent the
// external interface for a Completion Time Test. This algorithm
// determines whether a given set of tasks is schedulable on a
// processor, based on rate monotonic scheduling.

typedef std::string Taskname;

enum TaskRole
  {
    PRIMARY,
    BACKUP
  };

struct Task
{
  Taskname name;
  double execution_time;
  double period;
  double sync_time;
  TaskRole role;
  unsigned int rank;
};

typedef std::vector <Task> TASK_LIST;

class CTT_Algorithm : public std::unary_function <TASK_LIST, bool>
{
 public:
  virtual ~CTT_Algorithm ();

  virtual double operator () (const TASK_LIST & tasks) = 0;
};

// Algorithm 2 : Rate Monotonic First Fit Scheduling

// The following data structures and the FTRMFF_Algorithm class
// represent the external interface of a RMFF algorithm that creates a
// schedule (association of tasks to processors) based on a first fit
// placement. This algorithm uses CTT internally.

typedef std::string Processor;
typedef std::list <Processor> PROCESSOR_LIST;
typedef unsigned long Priority;

PROCESSOR_LIST create_processors (unsigned long count);

struct TaskPlacement
{
  Processor processor;
  Priority  priority;
};

typedef std::map <Taskname, TaskPlacement> SCHEDULING_MAP;

struct FTRMFF_Input
{
  TASK_LIST tasks;
  PROCESSOR_LIST processors;
  unsigned int backup_count;
};

struct ScheduleProgress
{
  Task task;
  unsigned int scheduled_replicas;
};

typedef std::list <ScheduleProgress> SCHEDULE_PROGRESS_LIST;

struct FTRMFF_Output
{
  // resulting schedule from algorithm
  SCHEDULING_MAP schedule;
  // this entry contains tasks that could not be scheduled
  SCHEDULE_PROGRESS_LIST unscheduled_tasks; 
};

class FTRMFF_Algorithm : public std::unary_function <FTRMFF_Input,
                                                     FTRMFF_Output>
{
 public:
  virtual ~FTRMFF_Algorithm ();

  virtual FTRMFF_Output operator () (const FTRMFF_Input & input) = 0;
};

// Helper functions for input and output for algorithm input and
// results, and for sorting and comparison of tasks.

std::ostream & operator<< (std::ostream & ostr, const Task & t);

std::ostream & operator<< (std::ostream & ostr, const TASK_LIST & t);

std::ostream & operator<< (std::ostream & ostr, const PROCESSOR_LIST & p);

std::ostream & operator<< (std::ostream & ostr, 
                           const SCHEDULE_PROGRESS_LIST & pl);

struct string_to_task : std::unary_function <std::string, Task>
{
  Task operator () (const std::string & s);
};

/**
 *  @struct TaskNamePredicate
 *
 *  @brief  Predicate functor for task name comparison
 */
struct TaskNamePredicate : public std::unary_function <Task,
                                                       bool>
{
public:
  TaskNamePredicate (const std::string & task_name);

  bool operator () (const Task & task);

private:
  std::string task_name_;
};

template <typename TASK>
struct PeriodComparison : public std::binary_function <TASK, 
                                                       TASK, 
                                                       bool>
{
  bool operator () (const TASK & t1, 
                    const TASK & t2)
  {
    return (t1.period < t2.period);
  }
};

struct double_equal : public std::binary_function <double, double, bool>
{
  bool operator () (double d1, double d2);
};

Taskname primary_name (const Task & task);


class PrimaryConversion : public std::unary_function<Task,
                                                     Task>
{
public:
  Task operator () (const Task & task);
};


#endif /* FTRMFF_ALGORITHMS_H_ */