07 Drivers
07 Drivers
COMP9242
2010/S2 Week 7
Lecture outline
User app
User app
User app
OS
driver
driver
driver
driver
Some statistics
OS archeology
The first (?) device drivers: I/O libraries for the IBM
709 batch processing system [1958]
OS archeology
The first (?) device drivers: I/O libraries for the IBM
709 batch processing system [1958]
OS archeology
IBM 7090 [1959] introduced I/O channels, which
allowed I/O and computation to overlap
OS archeology
IBM 7090 [1959] introduced I/O channels, which
allowed I/O and computation to overlap
OS archeology
IBM 7094 [1962] supported a wide range of
peripherals: tapes, disks, teletypes, flexowriters, etc.
OS archeology
IBM 7094 [1962] supported a wide range of
peripherals: tapes, disks, teletypes, flexowriters, etc.
Interface I:
character devices
Interface II:
block devices
OS archeology
GE-635 [1963] introduced the master CPU mode. Only
the hypervisor running in the master mode could
execute I/O instructions
Functions of a driver
Encapsulation
Hides low-level device protocol details from the client
Unification
Makes similar devices look the same
I/O bus
I/O device
bus interface
register file
internal logic
external medium
PCI
controller
RAM
PCI memory space
Dev1
Dev2
Dev3
PCI
controller
RAM
PCI memory space
Dev1
Dev2
Dev3
PCI
controller
IOMMU
RAM
PCI memory space
Dev1
Dev2
Dev3
DMA descriptors
Permanent DMA mappings
Streaming mappings
Driver
Driver
RAM
RAM
Device
Device
DMA descriptors
IRQ
controller
PCI
controller
RAM
PCI memory space
Dev1
Dev2
Dev3
I/O space
obsolete
Instantiation
Done by the OS when it finds a driver with a matching ID
Initialisation
Allocate PCI resources: memory regions, IRQ's
Enable bus mastering
Power management
Prepare the device for a transition into a low-power state
Restore device configuration during wake-up
DMA
Permanent mappings: disable caching
Streaming mappings: may require bounce buffers
Returns buffer address in the bus address space
Host-centric
Distributed-system-style architecture
Hot plug
Power management
Bus-powered and self-powered devices
USB 1.x
Up to 12Mb/s
USB 2.0
Up to 480Mb/s
USB 3.0
Up to 4.8Gb/s
Device 1
Device 2
Device 4
Hub
Root hub
DMA
Transfer descriptors
USB bus
controller
DMA
Completions
Driver stacking
Driver stacking
TCP/IP stack
hard_start_xmit(pkt)
AX88772
Ethernet
driver
Driver stacking
TCP/IP stack
hard_start_xmit(pkt)
AX88772
Ethernet
driver
usb_submit_urb(urb)
USB EHCI
controller
driver
Driver stacking
TCP/IP stack
hard_start_xmit(pkt)
AX88772
Ethernet
driver
usb_submit_urb(urb)
USB EHCI
controller
driver
mem loads/stores
PCI bus
driver
Driver stacking
TCP/IP stack
AX88772
Ethernet
driver
USB framework
USB EHCI
controller
driver
PCI framework
PCI bus
driver
Questions?
Some statistics
Driver
TCP/IP
Application
User land
DMA
Kernel
IPC
IPC
Driver
TCP/IP
Application
User land
IPC
IPC
Kernel
IRQ
IPC
Net filter
Application
Driver
TCP/IP
User land
IPC
Kernel
TCP/IP
Driver
Application
User land
IPC
Kernel
I/O throughput
Can the driver saturate the device?
I/O latency
How does the driver affect the latency of a single I/O request?
CPU utilisation
How much CPU overhead does the driver introduce?
Consumer
User land
Kernel
notifications
Issues:
Resource accounting
Safety
Asynchronous notifications
Rbufs
Proposed in the Nemesis microkernel-based multimedia OS
head pointer
tail pointer
rw
request descriptors
ro
data region
Producer
ro
response descriptors
head pointer
tail pointer
Consumer
rw
Early implementations
Michigan Terminal System [1970's]
OS for IBM System/360
Apparently, the first to support user-level drivers
Mach [1985-1994]
Distributed multi-personality -kernel-based multi-server OS
High IPC overhead
Eventually, moved drivers back into the kernel
L3 [1987-1993]
Persistent -kernel-based OS
High IPC overhead
Improved IPC design: 20-fold performance improvement
No data on driver performance available
DROPS [1998]
L4 Fiasco-based real-time OS
~100% CPU overhead due to user-level drivers
Fluke [1996]
~100% CPU overhead
Mungi [19932006]
Single-address-space distributed L4-based OS
Low-overhead user-level I/O demonstrated for a disk driver
Commercial
OKL4
QNX
GreenHills INTEGRITY
Driver
Application
User land
Linux Kernel
TCP/IP
Driver
read()
Application
User land
send()
Mem-mapped I/O
Linux Kernel
TCP/IP
Driver
Application
User land
read()
Linux Kernel
IRQ
recv()
TCP/IP
Driver
Application
User land
pci_map_xxx() syscall
Linux Kernel
Nooks
A complete device-driver reliability solution for Linux:
Fault isolation
Fault detection
Recovery
Linux kernel
(read-only for the driver)
Isolation
Isolation manager:
manager
XPC
Copying/replication
Checking
Driver
Heap
Stacks
Shadow driver
Nooks
A complete device-driver reliability solution for Linux:
Fault isolation
Fault detection
Recovery
Linux kernel
(read-only for the driver)
Isolation
Isolation manager:
manager
Shadow driver
XPC
Copying/replication
Checking
Driver
Heap
Stacks
Driver
Heap
Stacks
Nooks
A complete device-driver reliability solution for Linux:
Fault isolation
Fault detection
Recovery
Linux kernel
(read-only for the driver)
Isolation
Isolation manager:
manager
Shadow driver
XPC
Copying/replication
Checking
Driver
Heap
Stacks
Nooks
A complete device-driver reliability solution for Linux:
Fault isolation
Fault detection
Recovery
Problems
The driver interface in Linux is not well defined. Nooks must
simulate the behaviour of hundreds of kernel and driver entry
points.
Performance
10% throughput degradation
80% CPU overhead
VM1
VM2
Driver
Driver
Hypervisor
VMM
VM2
Driver
Stub
Hypervisor
Guest domain
I/O channels
netfront
free buf
TX
tx buf
rx packet
RX
rx buf
Driver
Xen hypervisor
Optimisations
Avoid mapping on the send path (the driver does not need to
see the packet content)
Replace mapping with copying on the receive path
Avoid unaligned copies
Optimised implementation of page mapping
CPU overhead down to 97% (worst-case receive path)
Questions?