Microdrivers A New Architecture for Device Drivers Vinod

  • Slides: 33
Download presentation
Microdrivers A New Architecture for Device Drivers Vinod Ganapathy Arini Balakrishnan Michael Swift Somesh

Microdrivers A New Architecture for Device Drivers Vinod Ganapathy Arini Balakrishnan Michael Swift Somesh Jha Computer Sciences Department University of Wisconsin-Madison Hot. OS XI, 8 th May 2007 Hot. OS XI Microdrivers: A New Architecture for Device Drivers

Introduction § Device drivers account for a large fraction of kernel code • Over

Introduction § Device drivers account for a large fraction of kernel code • Over 70% in Linux [Chou et al. , 2001] § Buggy device drivers are a major source of reliability problems • Account for over 85% of Windows XP crashes [Orgovan and Tricker, 2003] Hot. OS XI Microdrivers: A New Architecture for Device Drivers 2

Challenging to write and debug Device drivers are hard to get right § Writing

Challenging to write and debug Device drivers are hard to get right § Writing a device driver • Must handle asynchronous events • Must obey kernel programming rules § Debugging a device driver • Non-reproducible failures • Fewer advanced development tools § Many drivers written by non-kernel experts Hot. OS XI Microdrivers: A New Architecture for Device Drivers 3

Macrokernels Poor fault isolation Applications Kernel Hot. OS XI Driver Device Microdrivers: A New

Macrokernels Poor fault isolation Applications Kernel Hot. OS XI Driver Device Microdrivers: A New Architecture for Device Drivers 4

User-space device drivers Applications Driver Kernel Device Runtime Device Hot. OS XI Microdrivers: A

User-space device drivers Applications Driver Kernel Device Runtime Device Hot. OS XI Microdrivers: A New Architecture for Device Drivers 5

But… Poor performance § Limited by existing kernel/driver interface [Van Maren, 1999] • Written

But… Poor performance § Limited by existing kernel/driver interface [Van Maren, 1999] • Written expecting local procedure calls Incompatible with commodity OS § New interfaces (e. g. , new system calls) § New device drivers [Chubb 2004, Leslie et al. , 2005] Hot. OS XI Microdrivers: A New Architecture for Device Drivers 6

Best of both worlds: Microdrivers Split device driver functionality Userdriver Applications Runtime Microdriver Startup,

Best of both worlds: Microdrivers Split device driver functionality Userdriver Applications Runtime Microdriver Startup, shutdown, device configuration Performance-critical functionality Kernel Runtime Kerndriver Device Common case Rare case Hot. OS XI Microdrivers: A New Architecture for Device Drivers 7

How to produce a microdriver? Use program analysis & transformation Userdriver Runtime Traditional device

How to produce a microdriver? Use program analysis & transformation Userdriver Runtime Traditional device driver Splitter and Code generator Runtime Kerndriver Hot. OS XI Microdrivers: A New Architecture for Device Drivers 8

How big is the kernel driver? § Studied 455 drivers from Linux-2. 6. 18

How big is the kernel driver? § Studied 455 drivers from Linux-2. 6. 18 § Identified critical functions • • Interrupt handlers Tasklets, bottom-halves Supply/receive data to/from the device Plus the functions that they transitively call § Analysis is automatic • Uses the call-graph of the device driver Hot. OS XI Microdrivers: A New Architecture for Device Drivers 9

e 100_xmit_frame e 100_exec_cmd Hot. OS XI Microdrivers: A New Architecture for Device Drivers

e 100_xmit_frame e 100_exec_cmd Hot. OS XI Microdrivers: A New Architecture for Device Drivers 10

e 100_xmit_frame e 100_exec_cmd Hot. OS XI Microdrivers: A New Architecture for Device Drivers

e 100_xmit_frame e 100_exec_cmd Hot. OS XI Microdrivers: A New Architecture for Device Drivers 11

e 100_xmit_frame e 100_exec_cmd Hot. OS XI Microdrivers: A New Architecture for Device Drivers

e 100_xmit_frame e 100_exec_cmd Hot. OS XI Microdrivers: A New Architecture for Device Drivers 12

In-kernel driver code is reduced Hot. OS XI Microdrivers: A New Architecture for Device

In-kernel driver code is reduced Hot. OS XI Microdrivers: A New Architecture for Device Drivers 13

Mechanics Hot. OS XI Microdrivers: A New Architecture for Device Drivers 14

Mechanics Hot. OS XI Microdrivers: A New Architecture for Device Drivers 14

Architecture of a microdriver Userdriver Applications Runtime Responsibilities • Communication • Object tracking •

Architecture of a microdriver Userdriver Applications Runtime Responsibilities • Communication • Object tracking • Recovery Kernel Runtime Kerndriver Hot. OS XI Microdrivers: A New Architecture for Device Drivers Device 15

Communication § Mechanisms for control and data transfer § Control transfer: • LRPC [Bershad

Communication § Mechanisms for control and data transfer § Control transfer: • LRPC [Bershad et al. , 1990], Nooks XPC [Swift et al. , 2003] • Stubs in kerndriver for userdriver functions • Upcall and downcall mechanism § Data transfer: • Copy function arguments • Copy shared data structures § Synchronization done by object tracker Hot. OS XI Microdrivers: A New Architecture for Device Drivers 16

Object tracking Synchronize shared data structures Kerndriver 0 x 128 0 x 196 0

Object tracking Synchronize shared data structures Kerndriver 0 x 128 0 x 196 0 x 128 0 x 512 0 x 196 0 x 248 0 x 202 0 x 296 0 x 202 Userdriver 0 x 512 0 x 248 0 x 296 Upcall Hot. OS XI Microdrivers: A New Architecture for Device Drivers 17

Object tracking: Key challenges Memory objects with special semantics § Challenging cases • Locks

Object tracking: Key challenges Memory objects with special semantics § Challenging cases • Locks • Device memory and registers • DMA memory § Solution • Userdriver must synchronize and update version seen by the kerndriver Hot. OS XI Microdrivers: A New Architecture for Device Drivers 18

Recovery § Detect and recover from failed userdriver • Ideally transparent to applications §

Recovery § Detect and recover from failed userdriver • Ideally transparent to applications § Detection done at interface • Parameter checks and timeouts § Recovery – compatible with prior work • Shadow driver mechanism [Swift et al. , 2004] • Safe. Drive recovery mechanism [Zhou et al. , 2006] Hot. OS XI Microdrivers: A New Architecture for Device Drivers 19

Benefits Hot. OS XI Microdrivers: A New Architecture for Device Drivers 20

Benefits Hot. OS XI Microdrivers: A New Architecture for Device Drivers 20

Improved fault isolation Fewer lines of in-kernel driver code Userdriver Applications Runtime Kernel Runtime

Improved fault isolation Fewer lines of in-kernel driver code Userdriver Applications Runtime Kernel Runtime Kerndriver Hot. OS XI Microdrivers: A New Architecture for Device Drivers Device 21

Good common-case performance User/kernel crosses are infrequent Userdriver Applications Runtime Performance-critical functionality Kernel Runtime

Good common-case performance User/kernel crosses are infrequent Userdriver Applications Runtime Performance-critical functionality Kernel Runtime Kerndriver Hot. OS XI Microdrivers: A New Architecture for Device Drivers Device 22

Compatibility with commodity OS Kernel/driver interface is unchanged Userdriver Applications Runtime Kernel Runtime Kerndriver

Compatibility with commodity OS Kernel/driver interface is unchanged Userdriver Applications Runtime Kernel Runtime Kerndriver Hot. OS XI Microdrivers: A New Architecture for Device Drivers Device 23

Compatibility with commodity OS Can coexist with traditional drivers Userdriver Applications Runtime Kernel Hot.

Compatibility with commodity OS Can coexist with traditional drivers Userdriver Applications Runtime Kernel Hot. OS XI Runtime Kerndriver Device Driver Device Microdrivers: A New Architecture for Device Drivers 24

Ease of driver development More tools available for driver development Userdriver Applications Runtime gdb,

Ease of driver development More tools available for driver development Userdriver Applications Runtime gdb, gprof, valgrind, … Kernel Runtime Kerndriver Hot. OS XI Microdrivers: A New Architecture for Device Drivers Device 25

Pragmatics Hot. OS XI Microdrivers: A New Architecture for Device Drivers 26

Pragmatics Hot. OS XI Microdrivers: A New Architecture for Device Drivers 26

Generating a microdriver Traditional device driver Splitter User Marshaling annotations Traditional device driver Code

Generating a microdriver Traditional device driver Splitter User Marshaling annotations Traditional device driver Code generator Userdriver Runtime Kerndriver Runtime Hot. OS XI Kern Microdrivers: A New Architecture for Device Drivers 27

Marshaling annotations Need to serialize complex data structures § char *nullterm string; § struct

Marshaling annotations Need to serialize complex data structures § char *nullterm string; § struct net_device *list next; § struct pcnet 32_rx_head *array(“rx_ringsize”) rx_ring; § Program analysis algorithms to infer need for annotations Hot. OS XI Microdrivers: A New Architecture for Device Drivers 28

Performance of a microdriver § e 1000 device driver from Linux-2. 6. 18 •

Performance of a microdriver § e 1000 device driver from Linux-2. 6. 18 • Intel PRO/1000 gigabit network adapter § Methodology • • Split into kerndriver and userdriver Ran both halves in the kernel Used delays to simulate user/kernel crosses Infrastructure is still in construction! § Testbed • Dual-core 3 Ghz Pentium-D machine. Hot. OS XI Microdrivers: A New Architecture for Device Drivers 29

Relative performance TCP-send performance 26% rise 6. 8% drop 60 million machine cycles Hot.

Relative performance TCP-send performance 26% rise 6. 8% drop 60 million machine cycles Hot. OS XI Delay to simulate cost of user/kernel crossing (in. Drivers microseconds) Microdrivers: A New Architecture for Device 30

Open questions § Will microdrivers improve system reliability in practice? • Where are most

Open questions § Will microdrivers improve system reliability in practice? • Where are most of the bugs – in the kerndriver or in the userdriver? § Will the transition to microdrivers expose otherwise latent bugs in device drivers? Hot. OS XI Microdrivers: A New Architecture for Device Drivers 31

Microdrivers … … reduce the amount of code in the kernel … improve fault

Microdrivers … … reduce the amount of code in the kernel … improve fault isolation … have good common-case performance … are compatible with commodity OSes … permit the use of user-mode tools for driver development … can be generated largely automatically from existing drivers Hot. OS XI Microdrivers: A New Architecture for Device Drivers 32

Microdrivers A New Architecture for Device Drivers Vinod Ganapathy Arini Balakrishnan Michael Swift Somesh

Microdrivers A New Architecture for Device Drivers Vinod Ganapathy Arini Balakrishnan Michael Swift Somesh Jha vg@cs. wisc. edu arinib@cs. wisc. edu swift@cs. wisc. edu jha@cs. wisc. edu Computer Sciences Department University of Wisconsin-Madison Hot. OS XI Microdrivers: A New Architecture for Device Drivers