Devil: an IDL for Hardware Programming Fabrice Mérillon, Laurent Réveillère, Charles Consel, Renaud Marlet, Gilles Muller Compose Group http://www.irisa.fr/compose Irisa/Labri, Rennes/Bordeaux (France) 1
Interfacing Devices ... The Devil is in t he det ails Compose group Page 2 Compose group Page 2
Looking into the "Details" (busmouse.h) (busmouse.h) #define MSE_DATA_PORT 0x23c #define MSE_SIGNATURE_PORT 0x23d #define MSE_CONTROL_PORT 0x23e ... #define MSE_READ_X_LOW 0x80 #define MSE_READ_X_HIGH 0xa0 (busmouse.c) (busmouse.c) outb(MSE_READ_Y_LOW, MSE_CONTROL_PORT ); dy = (inb(MSE_DATA_PORT) & 0xf); outb(MSE_READ_Y_HIGH, MSE_CONTROL_PORT); buttons = inb(MSE_DATA_PORT); dy |= (buttons & 0xf) << 4; buttons = ((buttons >> 5) & 0x07); Compose group Page 3 Compose group Page 3
Assessment of Existing (Linux) Drivers N Assembly-level programming style N Macros – unreadable code factorized, not suppressed – no single programming style – no typing / consistency checking The hardware interface code is: ¯ hard to read and maintain ¯ tedious and error prone Compose group Page 4 Compose group Page 4
Lack of Support for the Driver Programmer N Paper documentation » natural language » manufacturer-specific terminology » inconsistencies, ambiguities, omissions, typos N Mixed levels of abstractions » communication mechanisms, data layout, semantics N Inherent complexity of devices ¯ Laborious testing until expected functionality is obtained Compose group Page 5 Compose group Page 5
Devil: a DEVice Interface Language Application DevI L API Existing device interface code System outb(MSE_READ_Y_LOW, API MSE_CONTROL_PORT ); C Devil dy = (inb(MSE_DATA_PORT) & 0xf); Driver outb(MSE_READ_Y_HIGH, Generated MSE_CONTROL_PORT); buttons = inb(MSE_DATA_PORT); Stubs DI dy |= (buttons & 0xf) << 4; Device Compose group Page 6 Compose group Page 6
Our Vision Hardware vendor, Public repository, • High-level description Device expert of device interface L L I I v v Device e e • Easy to write D D Specification • Strongly typed Driver programmer Driver Verifier • Consistency checking • Code generation Compiler C Devil • Functional interface C stubs • Easy to use (run-time checks) • Debug/production mode Compose group Page 7 Compose group Page 7
Devil: Key Concepts N Ports – communication point, address range N Registers – repository of data, granule of exchange N Variables: programmer interface – collection of register fragments – semantic values: » bounded integers » enumerated types Compose group Page 8 Compose group Page 8
Programmer Support: Verifying Critical Properties N Consistency of Devil specifications – no omission – no double definition – no overlapping – type/size of variables N C Devil interface usage in debug mode – compile-time (type checking) – run-time (assertion checking) Compose group Page 9 Compose group Page 9
The Logitech Busmouse: functional interface N dx (delta X) – relative horizontal movement N dy (delta Y) – relative vertical movement N buttons – button state Read only variables ! Compose group Page 10 Compose group Page 10
Device Interface Code: C Devil vs. existing drivers dx = get_dx(); C Devil dy = get_dy(); buttons = get_buttons(); outb(MSE_READ_X_LOW, MSE_CONTROL_PORT); dx = (inb(MSE_DATA_PORT) & 0xf); Existing outb(MSE_READ_X_HIGH, MSE_CONTROL_PORT); code dx |= (inb(MSE_DATA_PORT) & 0xf) << 4; outb(MSE_READ_Y_LOW, MSE_CONTROL_PORT ); dy = (inb(MSE_DATA_PORT) & 0xf); outb(MSE_READ_Y_HIGH, MSE_CONTROL_PORT); buttons = inb(MSE_DATA_PORT); dy |= (buttons & 0xf) << 4; buttons = ((buttons >> 5) & 0x07); Compose group Page 11 Compose group Page 11
The Logitech Busmouse: detailed description base + 2 base + 0 dx 0 0 1 . . 0 0 0 0 0 Direct register * * * * . . . . 1 1 * * * * . . . . Register array index 2 2 * * * * . . . . 3 3 . . . * . . . . buttons dy Compose group Page 12 Compose group Page 12
Direct registers base + 2 base + 0 dx → index_reg 0 0 1 . . 0 0 0 0 0 * * * * . . . . 1 1 * * * * . . . . Register array index 2 2 * * * * . . . . 3 3 . . . * . . . . buttons dy ... register index_reg = write base@2, mask ’1..00000’: bit[8]; Compose group Page 13 Compose group Page 13
Private device variables base + 2 base + 0 dx → index_reg 0 0 1 . . 0 0 0 0 0 * * * * . . . . 1 1 * * * * . . . . Register array index 2 2 * * * * . . . . 3 3 . . . * . . . . buttons dy ... register index_reg = write base@2, mask ’1..00000’ : bit[8]; private variable index = index_reg[6..5] : int(2); Compose group Page 14 Compose group Page 14
Indexed registers base + 2 base + 0 dx → index_reg 0 0 → x_low 1 . . 0 0 0 0 0 * * * * . . . . 1 1 → x_high * * * * . . . . index 2 2 → y_low * * * * . . . . 3 3 → y_high . . . * . . . . buttons dy ... register index_reg = write base@2, mask ’1..00000’ : bit[8]; private variable index = index_reg[6..5] : int(2); ... register x_low = read base@0, pre {index = 0}, mask ’****....’ : bit[8]; register x_high = read base@0, pre {index = 1}, mask ’****....’ : bit[8]; ... Compose group Page 15 Compose group Page 15
Interface variables base + 2 base + 0 dx → index_reg 0 0 → x_low 1 . . 0 0 0 0 0 * * * * . . . . 1 1 → x_high * * * * . . . . index 2 2 → y_low * * * * . . . . 3 3 → y_high . . . * . . . . buttons dy ... register index_reg = write base@2, mask ’1..00000’ : bit[8]; private variable index = index_reg[6..5] : int(2); ... register x_low = read base@0, pre {index = 0}, mask ’****....’ : bit[8]; register x_high = read base@0, pre {index = 1}, mask ’****....’ : bit[8]; ... variable dx = x_high[3..0] # x_low[3..0], volatile : signed int(8); variable dy = y_high[3..0] # y_low[3..0], volatile : signed int(8); Compose group Page 16 Compose group Page 16
What About Performance ? N Sharing registers between variables may induce performance penalty – additional I/O w.r.t. hand-crafted drivers – command parameters N Re-engineering of performance critical drivers – IDE disk driver – Permedia2 X11 driver Compose group Page 17 Compose group Page 17
IDE Linux Driver (intel 82371SB) N Characteristics: – many initializations – DMA/PIO-loop for transfer N DMA mode C: 14 I/Os Devil: 20 I/Os 14.25 Mb/s N PIO-32bits mode, 16 sectors/interrupt C (rep loop): 8.17 Mb/s Devil (C loop): 7.36 Mb/s (90% of C) Devil (rep loop): 8.17 Mb/s Compose group Page 18 Compose group Page 18
Permedia2 X11 driver N Characteristics: –registers mapped in memory –buffered write (on-chip FIFO) –same number of I/Os N Screen copy operations (24 bpp) – 100% performance of C N Rectangle operations (24 bpp) – 97%-100% performance of C – difference due to stub code for small size operation Compose group Page 19 Compose group Page 19
Benefits of Devil N Expressivity » advanced Devil constructs (see paper and manual) » DMA, sound, interrupt, Ethernet controllers N Guaranteed safety » Mutation-based experiment (typo simulation) » 5 times less prone to errors than C code N Negligible performance overhead N Improved productivity » reuse of specifications » tools and verifications Compose group Page 20 Compose group Page 20
Our Vision (On-going work) Hardware vendor Device specification Verifier Compiler Driver programmer Device interface Device interface Device driver documentation implementation specification DSL type-checker DSL compiler DSL optimizer Generated Device driver device driver documentation Compose group Page 21 Compose group Page 21
Conclusion N Step toward the development of robust drivers N Compiler/checker available N No performance penalty N Expressive enough to allow the specification of various devices Instance of our vision: “DSL for Operating System Design” Compose group Page 22 Compose group Page 22
The details are in Devil Compose group Page 23 Compose group Page 23
Questions ? N Specifications/compiler/manual available : www.irisa.fr/compose/devil N Public CVS repository of specs Please contribute … Compose group Page 24 Compose group Page 24
Recommend
More recommend