analysis of user level device driver usability in embedded

40
2006/4/11 CELF ELC 2006 Analysis of User Level Device Driver usability Analysis of User Level Device Driver usability in embedded application in embedded application - - Technique to achieve good real Technique to achieve good real - - time performance time performance - - Katsuya Matsubara Takanari Hayama Hitomi Takahashi Hisao Munakata IGEL Co., Ltd Renesas Solutions Corp.

Upload: others

Post on 03-Dec-2021

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Analysis of User Level Device Driver usability in embedded

2006/4/11 CELF ELC 2006

Analysis of User Level Device Driver usability Analysis of User Level Device Driver usability in embedded applicationin embedded application

--Technique to achieve good realTechnique to achieve good real--time performancetime performance--

Katsuya Matsubara Takanari HayamaHitomi Takahashi Hisao Munakata

IGEL Co., LtdRenesas Solutions Corp.

Page 2: Analysis of User Level Device Driver usability in embedded

2006/4/11 2CELF ELC 2006

BackgroundBackground

Device Driver Development in Embedded World is different in the following senses:

– Non-common New Devices• Due to newly developed devices, it is quite hard to re-use the device

driver from previous development.• Some of the device are common in embedded world, but not in the

Linux world, i.e. new in Linux.– Closed relationship with Applications

• Tends to be monolithic system architecture. Application requires to manage devices directly in fine-grain.

• Only one application dominantly uses the device.– Single-user, multi-task– IPR issue– Requires easiness of device driver development

• Short development cycle

Page 3: Analysis of User Level Device Driver usability in embedded

2006/4/11 3CELF ELC 2006

ObjectiveObjective

Design of a framework for User-Level Device DriverEvaluation on Implementation Methodology and its EnvironmentRelated Work– Peter Chubb, “Get more device drivers out of kernel,”

OLS2004.

Page 4: Analysis of User Level Device Driver usability in embedded

2006/4/11 4CELF ELC 2006

Required Features to Realize Required Features to Realize ULDDULDD

Memory Access– I/O Memory

• In many cases, devices are controlled over registers.• In some cases, access to device memory is required to perform I/O.

– RAM• Large contiguous memory is needed for DMA transfer etc.

Interrupt Handling– Communication between device and host CPU needs to be

interrupt driven.Latency Guarantee– How quick can a user task run after reception of interrupt, needed

to be guaranteed or presumable.Disabling Interrupt– Interrupt handler needs to be able to disable interrupts and run

dominantly.

Page 5: Analysis of User Level Device Driver usability in embedded

2006/4/11 5CELF ELC 2006

Design PrincipalDesign Principal

Memory Access– Access to I/O Memory

• Allow mmap(2) the I/O registers– Contiguous Memory Allocation

• Allow mmap(2) the contiguous memory allocated by the kernel.Interrupt Handling– Two Methodologies to Awake User Task

• Synchronous: Wake up task sleeping on I/O event• Asynchronous: Send UNIX signal

Latency Guarantee and Disabling Interrupt– RT Task– NPTL– O(1) Scheduler– Kernel Preemption etc.

Page 6: Analysis of User Level Device Driver usability in embedded

2006/4/11 CELF ELC 2006

Memory AccessMemory Access

Page 7: Analysis of User Level Device Driver usability in embedded

2006/4/11 7CELF ELC 2006

Kernel Memory Space

Memory AccessMemory Access

Access to I/O memory such as RAM and registers.– Make accessible by memory mapped I/O (mmap) from the

user task. User Task Memory Space

(1) Calls mmap

(2) Map the I/O region by calling io_remap_page_range()

(3) Access directly to H/W thru mmap’ed region

Page 8: Analysis of User Level Device Driver usability in embedded

2006/4/11 8CELF ELC 2006

Contiguous Memory AllocationContiguous Memory Allocation

Allocate contiguous memory in the kernel driver, and let user task to access through mmap(2).

KernelUser Task

(1) Request to allocate contiguous memory thru ioctl.

(5) Access directly to H/W thru mmap’ed region.

(3) Request to mmap the allocated region. (4) Map the memory region

allocated in the previous call.

(2) Allocate contiguous memory using __get_free_pages() and return address.

Page 9: Analysis of User Level Device Driver usability in embedded

2006/4/11 CELF ELC 2006

Interrupt HandlingInterrupt Handling

Page 10: Analysis of User Level Device Driver usability in embedded

2006/4/11 10CELF ELC 2006

Synchronous Interrupt HandlingSynchronous Interrupt Handling

Wake up the task from the kernel using synchronous file I/O.

Device

Linux kernel

IRQ hook driver

User Level DD

(2) Interrupt

(1) Wait for interrupt

synchronously

(3) Return from synchrounous I/O request

Page 11: Analysis of User Level Device Driver usability in embedded

2006/4/11 11CELF ELC 2006

API for Waiting Interrupt API for Waiting Interrupt SynchronouslySynchronously

Specify IRQ number to wait by [irqno]intr_fd = open(“/proc/irqhook/[irqno]”, O_RDWR);

Wait for Interruptread(intr_fd, &i, sizeof(int));

Page 12: Analysis of User Level Device Driver usability in embedded

2006/4/11 12CELF ELC 2006

Asynchronous Interrupt HandlingAsynchronous Interrupt Handling

Send UNIX signal to pre-registered task when interruption occures.

Device

Linux kernel

IRQ hook driver

User Level DD

(2) Interrupt

(1) Register Signal Handler

(3) Wakes up pre-registered Signal Handler

Page 13: Analysis of User Level Device Driver usability in embedded

2006/4/11 13CELF ELC 2006

API for Waiting Interrupt API for Waiting Interrupt AsynchronouslyAsynchronously

Registering Interrupt Handleract_sig.sa_handler = input_handler;sigaction(SIGIO, &act_sig, NULL);

Specify IRQ Number to wait by [irqno]intr_fd = open(“/proc/irqhook/[irqno]”, O_RDONLY);

Wait for Interruptoflags = fcntl(irqfd, F_GETFL);fcntl(irqfd, F_SETFL, oflags | FASYNC);read(intr_fd, &i, sizeof(int));

Page 14: Analysis of User Level Device Driver usability in embedded

2006/4/11 CELF ELC 2006

Latency Guarantee and Disabling Latency Guarantee and Disabling InterruptInterrupt

Page 15: Analysis of User Level Device Driver usability in embedded

2006/4/11 15CELF ELC 2006

Latency Guarantee and Disabling Latency Guarantee and Disabling InterruptInterrupt

To restrain context switch while device driver is processing interrupt, and to minimize the latency to wake up device driver, RT task shall be used.Linux 2.6 kernel that employs improved NPTL, O(1) Scheduler, Kernel Preemption etc should minimize the latency.

Evaluation to see how these work using real ULDD implementation!!

Page 16: Analysis of User Level Device Driver usability in embedded

2006/4/11 16CELF ELC 2006

Prototype ImplementationPrototype Implementation

SM501 UART Device– 8250 Compatible– Supports Byte I/O Mode and

FIFO Mode(For this experiment, we used byte I/O mode)

http://tree.celinuxforum.org/pubwiki/moin.cgi/RTS7751R2DHandlingManual

To Evaluate, Implemented SM501 UART Device Driver on RenesasRTS7751R2D Evaluation Board as ULDD

Page 17: Analysis of User Level Device Driver usability in embedded

2006/4/11 17CELF ELC 2006

I/O Memory in the KernelI/O Memory in the Kernel

int iommap_mmap(struct file *filp, struct vm_area_struct *vma) {

size_t size = vma->vm_end - vma->vm_start;unsigned long offset =

vma->vm_pgoff << PAGE_SHIFT;

...if (io_remap_page_range(vma, vma->vm_start,

offset, size, vma->vm_page_prot))

return -EAGAIN;return 0;

}

Page 18: Analysis of User Level Device Driver usability in embedded

2006/4/11 18CELF ELC 2006

I/O Memory Access in ULDDI/O Memory Access in ULDD

/* mmap the IO memory */

addr = mmap(0, IOMEM_SIZE, PROT_READ|PROT_WRITE,MAP_SHARED, iomap_fd, IOMEM_ADDR);

/* wait for an interrupt and then receive data */if (read(intr_fd, &i, sizeof(int)) == sizeof(int)) {

if ((st = *(u_char *)(addr + STATREG_OFFSET)& 0x01) {do {

/* get a byte from RX register */

dt = *(u_long *)(addr + RXREG_OFFSET);

Page 19: Analysis of User Level Device Driver usability in embedded

2006/4/11 19CELF ELC 2006

Interrupt Handling in the KernelInterrupt Handling in the Kernel

irqreturn_t irq_handler(int irq, void *vidp,struct pt_regs *regs) {

...if(idp->fasync){

/* Notify by UNIX signal (SIGIO) */

kill_fasync(&idp->fasync, SIGIO, POLL_IN);} else {

/* Wakeup task by usual notification */

wake_up(&idp->q);}return IRQ_HANDLED;

}

Page 20: Analysis of User Level Device Driver usability in embedded

2006/4/11 20CELF ELC 2006

Interrupt Handling in ULDDInterrupt Handling in ULDD(Synchronous)(Synchronous)

/* mmap the IO memory */addr = mmap(0, IOMEM_SIZE, PROT_READ|PROT_WRITE,

MAP_SHARED, iomap_fd, IOMEM_ADDR);

/* wait for an interrupt and then receive data */

if (read(intr_fd, &i, sizeof(int)) == sizeof(int)){

if ((st = *(u_char *)(addr + STATREG_OFFSET)) & 0x01) {do {

/* get a byte from RX register */dt = *(u_long *)(addr + RXREG_OFFSET);

Page 21: Analysis of User Level Device Driver usability in embedded

2006/4/11 21CELF ELC 2006

Interrupt Handling in ULDDInterrupt Handling in ULDD(Asynchronous)(Asynchronous)

oflags = fcntl(intr_fd, F_GETFL);

fcntl(intr_fd, F_SETFL, oflags | FASYNC);s.sa_handler = sigio_handler;sigaction(SIGIO, &s, NULL);read(intr_fd, &i, sizeof(int)); ...

}

void sigio_handler(void) {if((st = *(u_char *)(addr+STATREG_OFFSET)) & 0x01) {

do {

/* get a byte from RX register */st = *(u_long *)(addr+RXREG_OFFSET);

Page 22: Analysis of User Level Device Driver usability in embedded

2006/4/11 22CELF ELC 2006

Experiments and EvaluationExperiments and Evaluation

Performed experiments on RTS7751R2D’s SM501 UART ULDD device driver under the following condition:1. Evaluation on Interrupt Handling

a. File I/O (Synchronous) vs UNIX Signal (Asynchronous)2. Evaluation on Latency

a. RT Task vs non-RT Taskb. Kernel Level D/D vs User Level D/Dc. Linux 2.4 vs 2.6

Page 23: Analysis of User Level Device Driver usability in embedded

2006/4/11 23CELF ELC 2006

Environment for ExperimentsEnvironment for Experiments

H/W– Renesas RTS-7751R2D evaluation board

• Renesas SH7751R(SH-4) 240MHz• 64MB RAM, 100Mbps Ethernet

– NFS Server for rootfs• Intel Pentium4 2.8GHz• 512MB RAM, IDE HDD, 100Mbps Ethernet

– Serial Terminal• Intel Pentium4 laptop• Connected with 32kbps serial

S/W– Linux 2.6.13.4– glibc 2.3.3– Compile option: -O2 -g– Latency Measurement

• Kernel Space: current_kernel_timer()• User Space:

clock_gettime(CLOCK_REALTIME)Terminal

NFS Server

100Mbps Ethernet

Serial cross cable

Page 24: Analysis of User Level Device Driver usability in embedded

2006/4/11 24CELF ELC 2006

Linux KernelLinux Kernel

I/O Memory Map DriverI/O Memory Map Driver Interrupt Hook DriverInterrupt Hook Driver

Architecture: SM501 UART ULDD Architecture: SM501 UART ULDD and Terminal Applicationand Terminal Application

SM501 UART H/W

Pseudo Terminal

App

Output Data in

ASCII text

Shared Buffer

Serial TerminalBaud rate set to38400bps Xmit 1MB of Data

RT Thread which reads 1Byte per IRQ

RT Thread which reads 1Byte per IRQ

SM501 UART

ULDD

non-RT Thread

Page 25: Analysis of User Level Device Driver usability in embedded

2006/4/11 CELF ELC 2006

Evaluation on Interrupt HandlingEvaluation on Interrupt Handling

Page 26: Analysis of User Level Device Driver usability in embedded

2006/4/11 26CELF ELC 2006

Experiment 1Experiment 1--a: Comparison on a: Comparison on Interrupt Reception MethodologyInterrupt Reception Methodology

Measure the latency between the time interrupt hook driver receipt the interrupt and ULDD wakes up, i.e. either one of the followings– Synchronous (File I/O): Return from the read() call– Asynchronous (UNIX Signal): Signal handler wakes up

Linux Kernel

I/O Memory Map Driver Interrupt Hook Driver

SM501 UART

Terminal App

Serial Term

Byte Data Input

Measure the Latency

Notify Interrupt Synchronous or Asynchronously

SM501 UARTULDD

Page 27: Analysis of User Level Device Driver usability in embedded

2006/4/11 27CELF ELC 2006

Experiment 1Experiment 1--a : Result a : Result ((SychronousSychronous))

0.076Minimum (ms)50.1Maximum (ms)

18.06Average (ms)600Measurement

The worst case was 50ms.The worst case scenario is not the rare case.

0

10

20

30

40

50

60

70

<0 <9 <18

<27

<36

<45

<54

Latency (ms)

Tim

es

Page 28: Analysis of User Level Device Driver usability in embedded

2006/4/11 28CELF ELC 2006

Experiment 1Experiment 1--a : Result a : Result ((AsychronousAsychronous))

0

10

20

30

40

50

60

<0 <9 <18

<27

<36

<45

<54

Latency (ms)

Tim

es

0.019Minimum (ms)50.02Maximum (ms)18.15Average (ms)

600Measurement

The worst case was again 50ms.No big difference from synchronous one.

Page 29: Analysis of User Level Device Driver usability in embedded

2006/4/11 29CELF ELC 2006

Experiment 1Experiment 1--a: Observationsa: Observations

No obvious differences have been observed between synchronous and asynchronous interrupt handling.However, when transmission speed is increased, i.e. increase interruption frequency, asynchronous method using UNIX signal couldn’t catch up and, with “I/O possible” error in glibc, application has terminated.

Page 30: Analysis of User Level Device Driver usability in embedded

2006/4/11 CELF ELC 2006

Evaluation on LatencyEvaluation on Latency-- RT Task RT Task vsvs nonnon--RT Task RT Task --

Page 31: Analysis of User Level Device Driver usability in embedded

2006/4/11 31CELF ELC 2006

Linux Kernel

I/O Memory Map Driver Interrupt Hook Driver

By running CPU consuming disturbance in parallel, measure the impact on ULDD task running as either RT or Non-RT Task.

Experiment 2Experiment 2--a:a:Characteristic of RT TaskCharacteristic of RT Task

SM501 UART

Terminal App

SM501 UARTULDD

1MB Byte Input

Measure the throughput

Create task in RT or Non-RT

Serial Terminal

Disturbance Task

Change the number of disturbance tasks

Page 32: Analysis of User Level Device Driver usability in embedded

2006/4/11 32CELF ELC 2006

Experiment 2Experiment 2--a:a:Results and ObservationsResults and Observations

No difference between non-RT and RT when there is no disturbance tasks.In existence of disturbance tasks, proportional to number of disturbance task the non-RT task has been delayed.In the case of RT task, no influence of disturbance task has been observed. 0

5

10

15

20

25

30

35

0 1 2 3 4

Number of Disturbance Task

Bitra

te(k

bps)

RT

Non-RT

Page 33: Analysis of User Level Device Driver usability in embedded

2006/4/11 CELF ELC 2006

Evaluation on LatencyEvaluation on Latency-- Kernel Level D/D Kernel Level D/D vsvs User Level D/D User Level D/D --

Page 34: Analysis of User Level Device Driver usability in embedded

2006/4/11 34CELF ELC 2006

Linux Kernel

SM501 UART

KLDDLinux Kernel

I/O Memory Map

DriverInterrupt Hook Driver

Experiment 2Experiment 2--b:b:Overhead by Overhead by ImplmentingImplmenting ULDDULDD

Evaluate the influence of layers device driver is implemented in.

SM501 UART

Terminal App

Measure the Throughput

SM501 UARTULDD

SM501 UART

Terminal App

Compare between ULDD and KLDD

Page 35: Analysis of User Level Device Driver usability in embedded

2006/4/11 35CELF ELC 2006

Experiment 2Experiment 2--b:b:Result and ObservationResult and Observation

ULDD got stable result than that of KLDDThis is the result of unification of device driver and consumer application, i.e. resulting in lesser number context switch and memory copy.

26.50

27.00

27.50

28.00

28.50

29.00

29.50

30.00

30.50

31.00

Thro

ugh

put

(kbp

s)

MAX 30.04 30.15 30.69 28.08

MIN 29.71 29.08 30.68 28.08

AVG 29.95 29.69 30.68 28.08

ULDD (read) KLDD (read) ULDD (write) KLDD (write)

Page 36: Analysis of User Level Device Driver usability in embedded

2006/4/11 CELF ELC 2006

Evaluation on LatencyEvaluation on Latency-- Linux 2.4 Linux 2.4 vsvs 2.6 2.6 --

Page 37: Analysis of User Level Device Driver usability in embedded

2006/4/11 37CELF ELC 2006

Linux Kernel 2.4/2.6

I/O Memory Map Driver Interrupt Hook Driver

Experiment 2Experiment 2--c: Linux 2.6 c: Linux 2.6 vsvs 2.42.4

Evaluate how new features in 2.6 helps ULDD

SM501 UART

Terminal App

SM501 UARTULDD

Feed 1MB of Data

Measure Throughput

Used 2.4.20 / 2.6.13.4

Disturbance Task

Change # of disturbance tasks

Page 38: Analysis of User Level Device Driver usability in embedded

2006/4/11 38CELF ELC 2006

Experiment 2Experiment 2--c: Resultsc: Results

None major difference has been observed.This may due to:– Too few tasks– Frequency of interruption

is not high enough.

0

5

10

15

20

25

30

35

0 1 2 3 4

外乱プロセス数ビ

ット

レー

ト(k

bps)

RealTime(2.6.13) NonRealTime(2.6.13)

RealTime(2.4.20) NonRealTime(2.4.20)

Page 39: Analysis of User Level Device Driver usability in embedded

2006/4/11 39CELF ELC 2006

ConclusionConclusion

Implemented re-using existing File I/O, interrupt notification mechanism. No new system call is added.Implemented real ULDD device driver using the functionality above.Evaluated the usability of ULDD under embedded environment.

Page 40: Analysis of User Level Device Driver usability in embedded

2006/4/11 40CELF ELC 2006

Future WorkFuture Work

Evaluate the feature like RT_PREEMPT to see the impact to ULDD.Evaluate ULDD implementation on more various device to see its characteristic.Promote the use of ULDD ☺