Upload
dorcas-wilcox
View
212
Download
0
Embed Size (px)
Citation preview
Distributed Object Computing LaboratoryWashington University
St. Louis, MO
Rate-Monotonic Analysisin the C++ Type System
Morgan Deters
Model-Driven Embedded Systems
27 May 2003
Research funded by DARPA under contract F33615-00-C-1697
Christopher GillRon Cytron
Washington University in St. LouisMDES 2003
Rate-Monotonic Analysis in the C++ Type SystemMorgan Deters
227 May 2003
Overview
• Context
• C++ template metaprograms
• Rate-Monotonic Analysis (RMA)
• RMA with Templates
• Extensions to the Core Approach
• Future Directions
• Concluding Remarks
Washington University in St. LouisMDES 2003
Rate-Monotonic Analysis in the C++ Type SystemMorgan Deters
327 May 2003
A Brief History
StructuredProgramming
Objects
Middleware
Components
Modeling
Separation of concerns
Reflection/MOP
Generative (configurational)
Domain-Specific Languages (DSLs)
GO TO
Washington University in St. LouisMDES 2003
Rate-Monotonic Analysis in the C++ Type SystemMorgan Deters
427 May 2003
C++ Templatestemplate <class T>class list_node { T data; list_node<T>* next;public: void add(T data); void remove(T data); /* ... */};
list_node<int> node1;list_node<string> node2;// ...
• C++ templates/generics reusable data structures
Washington University in St. LouisMDES 2003
Rate-Monotonic Analysis in the C++ Type SystemMorgan Deters
527 May 2003
C++ Templatestemplate <class synch>class list {public: void add(string data) { Guard<synch> lock; // perform the operation... }};
// in a single-threaded contextlist<no_synch> my_list;my_list.add("unsynchronized");// in a multithreaded contextlist<std_synch> other_list;other_list.add("synchronized");
• C++ templates/generics reusable data structures code specialization
• method inlining
Washington University in St. LouisMDES 2003
Rate-Monotonic Analysis in the C++ Type SystemMorgan Deters
627 May 2003
C++ Template Metaprogrammingtemplate <int i>struct fib { enum { a = fib<i-1>::value, b = fib<i-2>::value, value = a + b };};
template <>struct fib<0> { enum { value = 0 };};
template <>struct fib<1> { enum { value = 1 };};
• C++ templates/generics reusable data structures code specialization
• method inlining
metaprogramming• constant computation
• template instantiation
int i = fib<6>::value;cout << "The 6th Fibonacci " "number is " << i;
Washington University in St. LouisMDES 2003
Rate-Monotonic Analysis in the C++ Type SystemMorgan Deters
727 May 2003
Rate-Monotonic Analysis (RMA)
• Fixed-priority static scheduling Priorities inversely proportional to period
• Given a set of m independent tasks (Ci ,Ti )
The task set is feasible if
[Liu & Layland 1973]
Ci – cost for task iTi – period for task i
Ci – cost for task iTi – period for task i
Ci /Ti ≤ m(21/m – 1)Σi
Washington University in St. LouisMDES 2003
Rate-Monotonic Analysis in the C++ Type SystemMorgan Deters
827 May 2003
Improved Feasibility Test
• Given a set of m independent tasks (Ci ,Ti )
The task set is feasible if and only if
[Lehoczky, Sha, & Ding 1987]
Ci – cost for task iTi – period for task i
Ci – cost for task iTi – period for task i
A
i, 1 ≤ i ≤ m
where R = { (k,l) | 1 ≤ k ≤ i, 1 ≤ l ≤ Ti /Tk }
min Σ (Cj /(l Tk)) l Tk /Tj ≤ 1(k,l) ε R j = 1
i
Washington University in St. LouisMDES 2003
Rate-Monotonic Analysis in the C++ Type SystemMorgan Deters
927 May 2003
RMA Template Metaprogram
• Perform feasibility test during compilation
• Determine best task set for stated requirements Track and include dependencies
• Tasks become generic programming concepts
• Metaprogram is “reflective” on tasks
• Uses Alexandrescu’s typelists compile-time variable-length linked lists of types
Washington University in St. LouisMDES 2003
Rate-Monotonic Analysis in the C++ Type SystemMorgan Deters
1027 May 2003
Concept: Taskstruct my_task {
typedef TYPELIST_1(another_task) dependencies; typedef my_cheap_task cheaper_alternative;
static const int importance = 1000; static const bool droppable = false; static const int cost = 100; static const int period = 600;
static const int start = 50; static const int deadline = 500;
static void do_task(const context_object& context) { // perform the work of the task }
};
Washington University in St. LouisMDES 2003
Rate-Monotonic Analysis in the C++ Type SystemMorgan Deters
1127 May 2003
RMA Feasibility at Compile-Timestruct taskA { enum { cost = 5, period = 10, /* ... */ };};
struct taskB { enum { cost = 5, period = 15, /* ... */ };};
typedef TYPELIST_2(taskA,taskB) mytasks;
int main() { typedef Schedule<mytasks> my_schedule;
STATIC_CHECK(my_schedule::feasible, Schedule_Infeasible);
my_schedule::schedule();
/* ... */
return 0;}
No runtime cost
Specialized
Washington University in St. LouisMDES 2003
Rate-Monotonic Analysis in the C++ Type SystemMorgan Deters
1227 May 2003
RMA Computation Details
• Given a set of m independent tasks (Ci ,Ti )
The task set is feasible if and only if
A
i, 1 ≤ i ≤ m
where R = { (k,l) | 1 ≤ k ≤ i, 1 ≤ l ≤ Ti /Tk }
min Σ (Cj /(l Tk)) l Tk /Tj ≤ 1(k,l) ε R j = 1
i
Typelist
s.t. Σ Cj t /Tj ≤ tj = 1
it ε { (k,l) | 1 ≤ k ≤ i, 1 ≤ l ≤ Ti /Tk }
E
check_i support template
sum_j support template
get_t support template
Top-level Schedule template instantiation
Washington University in St. LouisMDES 2003
Rate-Monotonic Analysis in the C++ Type SystemMorgan Deters
1327 May 2003
Example: The check_i templatetemplate <class Head, class Tail,
int m, int i>
struct check_i<Typelist<Head,Tail>, m, i> {
enum { task_result =
task_feasible<Typelist<Head,Tail>,
i>::Result,
Result = task_result &&
check_i<Typelist<Head,Tail>,
m, i+1>::Result };
};
template <class Head, class Tail, int m>
struct check_i<Typelist<Head, Tail>, m, m> {
enum {
Result =
task_feasible<Typelist<Head,Tail>,
m>::Result };
};
Base of recursion
foreach i = 1..m
Washington University in St. LouisMDES 2003
Rate-Monotonic Analysis in the C++ Type SystemMorgan Deters
1427 May 2003
Using Tasks
• Also can specify dependencies & alternatives
• Could collect information for dynamic scheduling Adaptation transitions
typedef Schedule<TYPELIST_2(my_task, my_other_task)> sched;
sched::schedule();
Compile-time type errorif task set infeasibleProvides generic, no-overhead
interface to a threading API
Washington University in St. LouisMDES 2003
Rate-Monotonic Analysis in the C++ Type SystemMorgan Deters
1527 May 2003
Getting More from the Compiler
• Task dependenceτ1 requires { τ2 , τ3 }
• Task alternation{ τ1 , ... , τi , ... , τm } → { τ1 , ... , τi´ , ... , τm }
• Powerful combinations feasibility space search make this feasible!
Washington University in St. LouisMDES 2003
Rate-Monotonic Analysis in the C++ Type SystemMorgan Deters
1627 May 2003
Verification at Runtime
• Check that analysis results still hold on execution platform
• Distribution soundness
• Feedback loop
Application
cost estimates
profiling
production code
Washington University in St. LouisMDES 2003
Rate-Monotonic Analysis in the C++ Type SystemMorgan Deters
1727 May 2003
Adaptation at Runtime
typedef TYPELIST_3(user_task, idle_task, power_monitor_task) normalSet;
typedef TYPELIST_2(low_power_user_task, low_power_idle_task) lowPowerSet;
void power_monitor_task::do_task(const context_object&) { if(power() <= threshold) { taskSet = new Adaptation_Traits<power_monitor_task>::adapt_to; }};
template <>class Adaptation_Traits<power_monitor_task> { typedef lowPowerSet adapt_to;};
Washington University in St. LouisMDES 2003
Rate-Monotonic Analysis in the C++ Type SystemMorgan Deters
1827 May 2003
Remarks
• Bound to C++
• “Configuration negotiation” within C++ Program specialization Automatic program reconfiguration
• Related work
• And into the future... Assist dynamic schedulers Pre-compute adaptation transitions
Morgan [email protected]
Thanks !
www.cs.wustl.edu/~doc
Department of Computer ScienceWashington University Box #1045
St. Louis, MO 63130 USA
Christopher [email protected]