summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Runtime_Scheduler.cpp
blob: d977034c1af39c8510961a1828a193ce70f2f813 (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
// ============================================================================
//
// $Id$
//
// ============================================================================

#include "orbsvcs/Time_Utilities.h"
#include "orbsvcs/Runtime_Scheduler.h"

#if defined (__ACE_INLINE__)
#include "orbsvcs/Runtime_Scheduler.i"
#endif /* __ACE_INLINE__ */

ACE_Runtime_Scheduler::
ACE_Runtime_Scheduler (int entry_count,
                       RtecScheduler::RT_Info* rt_info[])
:  entry_count_ (entry_count),
   rt_info_ (rt_info)
{
}

RtecScheduler::handle_t
ACE_Runtime_Scheduler::create (const char * entry_point,
                               CORBA::Environment &_env)
     TAO_THROW_SPEC ((CORBA::SystemException,
                      RtecScheduler::DUPLICATE_NAME))
{
  // Just make sure its there and returns its handle (position).
  int i;
  for (i = 0; i < entry_count_; ++i)
    {
      if (strcmp (entry_point, rt_info_[i]->entry_point) == 0)
        {
          return i;
        }
    }
  // TODO: throw an exception or print an error.
  return -1;
}

RtecScheduler::handle_t
ACE_Runtime_Scheduler::lookup (const char * entry_point,
                               CORBA::Environment &_env)
    TAO_THROW_SPEC ((CORBA::SystemException))
{
  return create (entry_point, _env);
}

RtecScheduler::RT_Info*
ACE_Runtime_Scheduler::get (RtecScheduler::handle_t handle,
                            CORBA::Environment &_env)
     TAO_THROW_SPEC((CORBA::SystemException,
                     RtecScheduler::UNKNOWN_TASK))
{
  if (handle < 0 || handle > entry_count_)
    {
      TAO_THROW_RETURN (RtecScheduler::UNKNOWN_TASK(), 0);
    }
  return rt_info_[handle];
}

void ACE_Runtime_Scheduler::set (RtecScheduler::handle_t handle,
                                 RtecScheduler::Criticality criticality,
                                 const RtecScheduler::Time &time,
                                 const RtecScheduler::Time &typical_time,
                                 const RtecScheduler::Time &cached_time,
                                 RtecScheduler::Period period,
                                 RtecScheduler::Importance importance,
                                 const RtecScheduler::Quantum &quantum,
                                 CORBA::Long threads,
                                 RtecScheduler::Info_Type info_type,
                                 CORBA::Environment &_env)
     TAO_THROW_SPEC ((CORBA::SystemException,
                      RtecScheduler::UNKNOWN_TASK))
{
  // We compare the values with the ones stored and print a message on
  // any differences.
  if (handle < 0 || handle > entry_count_)
    {
      TAO_THROW (RtecScheduler::UNKNOWN_TASK);
      ACE_NOTREACHED (return);
    }
  if (rt_info_[handle]->criticality != criticality
      || rt_info_[handle]->worst_case_execution_time != time
      || rt_info_[handle]->typical_execution_time != typical_time
      || rt_info_[handle]->cached_execution_time != cached_time
      || rt_info_[handle]->period != period
      || rt_info_[handle]->importance != importance
      || rt_info_[handle]->quantum != quantum
      || rt_info_[handle]->info_type != info_type
      || rt_info_[handle]->threads != threads)
    {
      ACE_ERROR ((LM_ERROR, "invalid data for RT_Info: %s\n",
                  (const char*)rt_info_[handle]->entry_point));
      // TODO: throw something here.
    }
}


void ACE_Runtime_Scheduler::priority (RtecScheduler::handle_t handle,
                                      RtecScheduler::OS_Priority& priority,
                                      RtecScheduler::Sub_Priority& subpriority,
                                      RtecScheduler::Preemption_Priority& p_priority,
                                      CORBA::Environment &_env)
     TAO_THROW_SPEC ((CORBA::SystemException,
                      RtecScheduler::UNKNOWN_TASK,
                      RtecScheduler::NOT_SCHEDULED))
{
  if (handle < 0 || handle > entry_count_)
    {
      TAO_THROW (RtecScheduler::UNKNOWN_TASK());
      ACE_NOTREACHED (return);
    }
  priority = rt_info_[handle]->priority;
  subpriority = rt_info_[handle]->static_subpriority;
  p_priority = rt_info_[handle]->preemption_priority;
}

void ACE_Runtime_Scheduler::entry_point_priority (const char * entry_point,
                                                  RtecScheduler::OS_Priority& priority,
                                                  RtecScheduler::Sub_Priority& subpriority,
                                                  RtecScheduler::Preemption_Priority& p_priority,
                                                  CORBA::Environment &_env)
     TAO_THROW_SPEC((CORBA::SystemException,
                     RtecScheduler::UNKNOWN_TASK,
                     RtecScheduler::NOT_SCHEDULED))
{
  RtecScheduler::handle_t handle = lookup (entry_point, _env);
  if (handle < -1)
    {
      // The exception was thrown or is in _env already.
      return;
    }
  this->priority (handle, priority, subpriority, p_priority, _env);
}

void ACE_Runtime_Scheduler::add_dependency (RtecScheduler::handle_t handle,
                                            RtecScheduler::handle_t dependency,
                                            CORBA::Long number_of_calls,
                                            RtecScheduler::Dependency_Type
                                              dependency_type,
                                            CORBA::Environment &_env)
     TAO_THROW_SPEC ((CORBA::SystemException,
                      RtecScheduler::UNKNOWN_TASK))
{
  if (handle < 0 || handle > entry_count_)
    {
      TAO_THROW (RtecScheduler::UNKNOWN_TASK);
      ACE_NOTREACHED (return);
    }
  // Just check that the information is consistent.
  RtecScheduler::Dependency_Set& deps = rt_info_[handle]->dependencies;
  for (CORBA::ULong i = 0; i < deps.length (); ++i)
    {
      if (deps[i].rt_info == dependency
          && deps[i].number_of_calls == number_of_calls
          && deps[i].dependency_type == dependency_type)
        {
          return;
        }
    }
  ACE_ERROR ((LM_ERROR, "unmatched dependency on %s\n",
              (const char*)rt_info_[handle]->entry_point));
}

void ACE_Runtime_Scheduler::compute_scheduling (CORBA::Long minimum_priority,
                                                CORBA::Long maximum_priority,
                                                RtecScheduler::RT_Info_Set_out infos,
                                                CORBA::Environment &_env)
     TAO_THROW_SPEC ((CORBA::SystemException,
                      RtecScheduler::UTILIZATION_BOUND_EXCEEDED,
                      RtecScheduler::INSUFFICIENT_THREAD_PRIORITY_LEVELS,
                      RtecScheduler::TASK_COUNT_MISMATCH))
{
  // TODO: Right now just do nothing, later we could validate the
  // priorities (without recomputing).
  // TODO: fill up the infos.
  return;
}