190 likes | 208 Views
Research funded by DARPA under contract F33615-00-C-1697. Rate-Monotonic Analysis in the C++ Type System. Morgan Deters. Christopher Gill. Ron Cytron. Model-Driven Embedded Systems 27 May 2003. Overview. Context C++ template metaprograms Rate-Monotonic Analysis (RMA) RMA with Templates
E N D
Research funded by DARPA under contract F33615-00-C-1697 Rate-Monotonic Analysisin the C++ Type System Morgan Deters Christopher Gill Ron Cytron Model-Driven Embedded Systems 27 May 2003
Overview • Context • C++ template metaprograms • Rate-Monotonic Analysis (RMA) • RMA with Templates • Extensions to the Core Approach • Future Directions • Concluding Remarks
A Brief History GO TO Middleware Structured Programming Components Reflection/MOP Objects Separation of concerns Modeling Generative (configurational) Domain-Specific Languages (DSLs)
template <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 C++ Templates
template <class synch> class list { public: void add(string data) { Guard<synch> lock; // perform the operation... } }; // in a single-threaded context list<no_synch> my_list; my_list.add("unsynchronized"); // in a multithreaded context list<std_synch> other_list; other_list.add("synchronized"); C++ templates/generics reusable data structures code specialization method inlining C++ Templates
template <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 C++ Template Metaprogramming int i = fib<6>::value; cout << "The 6th Fibonacci " "number is " << i;
Σ Ci /Ti ≤ m(21/m – 1) i 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 i Ti – period for task i
A i, 1 ≤ i≤m i min Σ (Cj /(lTk)) l Tk /Tj≤ 1 (k,l) εR j = 1 where R = { (k,l) | 1 ≤k≤i, 1 ≤l≤Ti /Tk} 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 i Ti – period for task i
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
Concept: Task struct 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 } };
struct 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; } RMA Feasibility at Compile-Time No runtime cost Specialized
A i, 1 ≤ i≤m i min Σ (Cj /(lTk)) l Tk /Tj≤ 1 i (k,l) εR j = 1 s.t.ΣCj t/Tj≤ t tε{ (k,l) | 1 ≤k≤i, 1 ≤l≤Ti /Tk} where R = { (k,l) | 1 ≤k≤i, 1 ≤l≤Ti /Tk} E j = 1 RMA Computation Details Typelist • Given a set of m independent tasks (Ci ,Ti ) The task set is feasible if and only if check_i support template Top-level Schedule template instantiation get_t support template sum_j support template
template <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 }; }; foreach i = 1..m Example: The check_i template Base of recursion
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 error if task set infeasible Provides generic, no-overhead interface to a threading API
Getting More from the Compiler • Task dependence τ1requires{ τ2 , τ3 } • Task alternation { τ1 , ... , τi , ... , τm}→ { τ1 , ... , τi´ , ... , τm} • Powerful combinations • feasibility space search • make this feasible!
cost estimates Application production code profiling Verification at Runtime • Check that analysis results still hold on execution platform • Distribution soundness • Feedback loop
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; };
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
Thanks ! Morgan Deters mdeters@cs.wustl.edu Ron Cytron cytron@cs.wustl.edu Christopher Gill cdgill@cs.wustl.edu www.cs.wustl.edu/~doc Department of Computer Science Washington University Box #1045 St. Louis, MO 63130 USA