summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/examples/FaultTolerance/FLARe/DeCoRAM/src/Scheduler.h
blob: 66b82213b66e04404a3cee4f0c0a0c3d63426a51 (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
// -*- C++ -*-

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

#ifndef SCHEDULER_H_
#define SCHEDULER_H_

#include "Schedule.h"

/// this map groups all tasks that belong to one replica group
typedef std::pair <Processor, Task> TASK_POSITION;
typedef std::vector <TASK_POSITION> TASK_POSITIONS;
typedef std::map <Taskname, TASK_POSITIONS> REPLICA_GROUPS;
typedef std::list<PROCESSOR_SET> PROCESSOR_SETS;
typedef std::list<TASK_LIST> TASK_SCENARIOS;

class Scheduler : public std::unary_function <Task, 
                                              ScheduleResult>
{
public:
  /// default ctor
  Scheduler (const PROCESSOR_LIST & processors,
             unsigned int max_failures);

  /// destructor
  virtual ~Scheduler (void);

  // returns where the task has been placed and which WCRT it has.
  // If the WCRT response time is 0, it is not schedulable.
  ScheduleResult operator () (const Task & task);

  // this needs to be implemented by each scheduling algorithm
  virtual double schedule_task (const Task & task, 
                                const Processor & processor) = 0;

  // getter method for the schedule
  SCHEDULE schedule () const;

  virtual void update_schedule (const ScheduleResult & result);

protected:
  void update_replica_groups (const ScheduleResult & result);

protected:
  SCHEDULE schedule_;
  unsigned int max_failures_;
  REPLICA_GROUPS replica_groups_;
};

/*** Helper classes and operators ***/

/**
 * @class ProcessorNameComparison 
 *
 * @brief Can be used with the accumulate algorithm to find out if a
 *        processor name belongs to a list of task positions
 */
class ProcessorNameComparison : public std::binary_function <
  bool,
  TASK_POSITIONS::value_type,
  bool>
{
public:
  ProcessorNameComparison (const Processor & p);

  bool operator () (bool equal, const TASK_POSITIONS::value_type & pos);
private:
  Processor p_;
};

/**
 * @class ProcessorPicker
 * 
 * @brief can be used within transform to extract the 
 *        processor names from a TASK_POSITIONS structure.
 */
class ProcessorPicker : public std::unary_function<REPLICA_GROUPS::value_type,
                                                   Processor>
{
public:
  Processor operator () (const TASK_POSITIONS::value_type & entry);
};

/**
 * @class ReplicaFinder
 *
 * @brief Functor that uses the replica group to determine the
 *        processors that need to fail in order for a given backup
 *        task to become active
 */
class ReplicaFinder : public std::unary_function <Task,
                                                  PROCESSOR_SET>
{
public:
  ReplicaFinder (const REPLICA_GROUPS & rep_groups);

  virtual ~ReplicaFinder (void);

  virtual PROCESSOR_SET operator () (const Task & task) const;

private:
  const REPLICA_GROUPS & rep_groups_;
  ProcessorPicker processor_picker_;
};

// streaming operators for used data structures
std::ostream & operator<< (std::ostream & ostr, 
                           const TASK_POSITION & tp);

std::ostream & operator<< (std::ostream & ostr, 
                           const TASK_POSITIONS & tps);

std::ostream & operator<< (std::ostream & ostr, 
                           const REPLICA_GROUPS & rg);

std::ostream & operator<< (std::ostream & ostr, 
                           const PROCESSOR_SETS & ps);

std::ostream & operator<< (std::ostream & ostr, 
                           const TASK_SCENARIOS & ts);

#endif /* SCHEDULER_H_ */