500 likes | 628 Views
Esterel and Other Projects. Prof. Stephen A. Edwards Columbia University, New York www.cs.columbia.edu/~sedwards. Outline. Part 1 The Esterel language My compiler for it (DAC 2000) Part 2 New Esterel Compiler Infrastructure Other projects. The Esterel Language. emit B;
E N D
Esterel and Other Projects Prof. Stephen A. Edwards Columbia University, New York www.cs.columbia.edu/~sedwards
Outline • Part 1 • The Esterel language • My compiler for it (DAC 2000) • Part 2 • New Esterel Compiler Infrastructure • Other projects
The Esterel Language emit B; if C emit D; Force signal B to be present in this cycle Emit D if signal C is present
The Esterel Language await A; emit B; if C emit D; pause Wait for next cycle with A present Wait for next cycle
The Esterel Language loop await A; emit B; if C emit D; pause end Infinite loop
The Esterel Language loop await A; emit B; if C emit D; pause end || loop if B emit C; pause end Run concurrently
The Esterel Language loop await A; emit B; if C emit D; pause end || loop if B emit C; pause end Same-cycle bidirectional communication
The Esterel Language every RESET do loop await A; emit B; if C emit D; pause end || loop if B emit C; pause end end Restart when RESET present
The Esterel Language every RESET do loop await A; emit B; if C emit D; pause end || loop if B emit C; pause end end Good for hierarchical FSMs
The Esterel Language every RESET do loop await A; emit B; if C emit D; pause end || loop if B emit C; pause end end Bad at manipulating data
The New Compiler Esterel every RESET do loop await A; emit B; if C emit D; pause end || loop if B emit C; pause end end Step 1: Translate Concurrent Control-Flow Graph
The New Compiler Step 2: Schedule Scheduled CCFG Esterel every RESET do loop await A; emit B; if C emit D; pause end || loop if B emit C; pause end end Step 1: Translate Concurrent Control-Flow Graph
The New Compiler Step 3: Sequentialize Sequential Control-Flow Graph Esterel every RESET do loop await A; emit B; if C emit D; pause end || loop if B emit C; pause end end Step 1: Translate Step 2: Schedule Concurrent Control-Flow Graph Scheduled CCFG
The New Compiler C Void foo() { switch (st) { 0: if (IN=3) st = 5; goto L5; 1: if (RES) st = 3; goto L8; } L5: switch } Step 4: Generate C Esterel every RESET do loop await A; emit B; if C emit D; pause end || loop if B emit C; pause end end Step 1: Translate Step 2: Schedule Step 3: Sequentialize Concurrent Control-Flow Graph Sequential Control-Flow Graph Scheduled CCFG
The New Compiler C Esterel Void foo() { switch (st) { 0: if (IN=3) st = 5; goto L5; 1: if (RES) st = 3; goto L8; } L5: switch } every RESET do loop await A; emit B; if C emit D; pause end || loop if B emit C; pause end end • Generated code is 2 to 100 faster • 1/2 to 1 the size
The New Compiler C Esterel Void foo() { switch (st) { 0: if (IN=3) st = 5; goto L5; 1: if (RES) st = 3; goto L8; } L5: switch } every RESET do loop await A; emit B; if C emit D; pause end || loop if B emit C; pause end end Flow similar to Lin [DAC ‘98]
Step 1: Build Concurrent CFG every RESET do loop await A; emit B; if C emit D; pause end || loop if B emit C; pause end end RESET
Add Threads every RESET do loop await A; emit B; if C emit D; pause end || loop if B emit C; pause end end RESET Fork Join
Split at Pauses every RESET do loop await A; emit B; if C emit D; pause end || loop if B emit C; pause end end RESET 1 1 s 2 2
Add Code Between Pauses every RESET do loop await A; emit B; if C emit D; pause end || loop if B emit C; pause end end RESET 1 s 2 A B C D s=2 s=1
Build Right Thread every RESET do loop await A; emit B; if C emit D; pause end || loop if B emit C; pause end end RESET 1 s 2 A B B C C D s=2 s=1
Step 2: Schedule Add arcs for communication RESET • Topological sort • Optimal scheduling: NP-Complete • “Bad” schedules OK 1 s 2 A B B C C D s=2 s=1
Step 3: Sequentialize • Hardest part: Removing concurrency • Simulate the Concurrent CFG • Main Loop: • For each node in scheduled order, • Insert context switch if from different thread • Copy node & connect predecessors
Context Switching Code Save state of suspending thread s=0 s=1 s=2 s=3 Restore state of resuming thread r 0 1 2
Run First Node RESET 1 s 2 A B B C C D s=2 s=1 RESET RESET
Run First Part of Left Thread RESET 1 s 2 A B B C C D s=2 s=1 RESET 1 s 2 B 1 s A 2 A B
Context switch: Save State RESET 1 s 2 A B B C C D s=2 s=1 RESET 1 s 2 B A t=0 t=1
Rejoin RESET 1 s 2 A B B C C D s=2 s=1 RESET 1 s 2 B A t=0 t=1
Run Right Thread RESET 1 s 2 A B B C C D s=2 s=1 RESET 1 s 2 B A t=0 t=1 B B C C
Context Switch: Restore State RESET 1 s 2 A B B C C D s=2 s=1 RESET 1 s 2 B A t=0 t=1 B C 0 1 t
Resume Left Thread RESET 1 s 2 A B B C C D s=2 s=1 RESET 1 s 2 B A t=0 t=1 B C C 0 1 t D C D s=2 s=1 s=2 s=1
Step 3: Finished RESET 1 s 2 A B B C C D s=2 s=1 RESET RESET 1 s 2 B 1 s A 2 A t=0 t=1 B B B C C C 0 1 t D C D s=2 s=1 s=2 s=1
Existing Esterel Compilers Automata V3 [Berry ‘87], Polis [DAC ‘95] switch (st) { case 0: st = 1; break; case 1: Capacity Simulation Speed
Existing Esterel Compilers Logic gates V4, V5 [Berry ‘92, ‘96] A = B && C; D = A && E; Capacity AutomataV3 [Berry ‘87], Polis [DAC ‘95] Simulation Speed
Existing Esterel Compilers Logic gates V4, V5 [Berry ‘92, ‘96] A = B && C; D = A && E; CNET [CASES 2k] Capacity AutomataV3 [Berry ‘87], Polis [DAC ‘95] Simulation Speed
Existing Esterel Compilers New Compiler Logic gates V4, V5 [Berry ‘92, ‘96] CNET [CASES 2k] Capacity Automata V3 [Berry ‘87], Polis [DAC ‘95] Simulation Speed
Speed of Generated Code Average cycle time (ms) Size (source lines)
Size of Generated Code Object code size (K) Size (source lines)
Part 2 Present and Future Work
New Projects • New Esterel compiler • Languages for Device Drivers • Languages for Communication Protocols
ESUIF • New, open Esterel compiler designed for research • Source distributed freely • Based on SUIF2 system (suif.stanford.edu) • Modular construction • Standard compiler approach • Front end builds AST • AST dismantled into intermediate form • Intermediate form translated into low-level code • C code ultimately produced
ESUIF Status • Front-end written, accepts large Esterel examples • Dismantlers partially complete: intermediate form defined • Linker (run statement expansion) to be implemented • Back-end to be implemented
Esterel Compilation Plans • Apply discrete-event simulation techniques • Similar to the CNET compiler • Apply Program Dependence Graph representation • Concurrent representation used in optimizing compilers • Apply “localized partial interpretation” to expand parts of the system into finite-state machines • Techniques will point the way for other synchronous, concurrent languages
Languages for Device Drivers • Device drivers are those pieces of software that you absolutely need that never seem to work • Tedious, difficult-to-write • Ever more important as systems incorporate customized hardware
Best To Date • Thibault, Marlet, and Consel • IEEE Transactions Software Engineering, 1999 • Developed the Graphics Adaptor Language for writing XFree86 video card drivers • Report GAL drivers are 1/9th the size of their C counterparts • No performance penalty
GAL S3 driver (fragment) chipsets S3_911, S3_924; What driver supports port svga index := 0x3d4; Write address, then data port misc := 0x3cc, 0x3c2; register ChipID := sva(0x30); Logical register serial begin Access sequence for register misc[3..2] <= (3,- , -, -, -) W; seq(0x12) <=> (-, PLL1, -, -, -) R/W; end; identification begin Rules for identifying card 1: ChipID[7..4] => (0x8 => step 2, 0x 9 => S3_928); 2: ChipID[1..0] => (0x1 => S3_911, 0x2 => S3_924);
Future Device Driver Work • Develop language for network card drivers under Linux • Study many existing implementations • Develop prototype language, compiler • Explore challenge of porting to other OSes • Apply lessons to other classes of drivers
Languages for Communication Protocols • Many optimizations for implementing protocol code • Fast-path optimization • Collapsing layers • Tedious to implement manually • Tend to obfuscate code • Too high-level to be applied to, say, C code • Domain-specific language would allow these optimizations to be automated
Summary • Esterel language • Esterel compiler based on control-flow graph • ESUIF: New Esterel compiler under development • Languages for Device Drivers • Languages for Communication Protocols