2006/1/201igel co.,ltd. / renesas solution corp. studies on user level device driver in embedded...
TRANSCRIPT
2006/1/20 1IGEL Co.,Ltd. / Renesas Solution Corp.
Studies on User Level Device DriverStudies on User Level Device Driverin Embedded Environmentin Embedded Environment
(( Progress ReportProgress Report ))
Katsuya Matsubara
IGEL Co.,Ltd.
2006/1/20 2IGEL Co.,Ltd. / Renesas Solution Corp.
Stories so farStories so far
Investigated behaviors of threads– RT Task vs Non-RT Task
WRITE → DD→ READ切り替え時間( タスク 仮想 タスク)
0
20
40
60
80
100
120
140
160
180
0 1 2 4 8 16 32負荷タスク数
応答
時間
(マイ
クロ
秒)
non-rt threadrt thread
DD→ READ起床時間(仮想 タスク)
0
20
40
60
80
100
120
140
160
180
0 1 2 4 8 16 32負荷タスク数
応答
時間
(マイ
クロ
秒)
non-RTスレッドRTスレッド
Number of Load TasksNumber of Load Tasks
Switching Time(WRITE Task->Vertual DD->Read Task) Wakeup Vertual DD->Read Task)
Res
pons
e T
ime(
mic
rose
c)
Res
pons
e T
ime(
mic
rose
c)
2006/1/20 3IGEL Co.,Ltd. / Renesas Solution Corp.
Background and ObjectivesBackground and Objectives
Want to implement device drivers in user level– Easy to devleop– Reduce system down due to driver bugs– ( Avoid GPL )
Some issues on implementing user level device drivers– Access to I/O memory, physical memory– Forwarding of Interupttion Requests ( IRQ )– Response performance to interuption– ‥‥
New features in Kernel 2.6– NPTL(Native POSIX Thread Library)– Sceduler improvement ( O(1) scheduler etc. )– Kernel preemption– ….
2006/1/20 4IGEL Co.,Ltd. / Renesas Solution Corp.
Facts in Development of EmbeddeFacts in Development of Embedded Softwared Software
More development of drivers for new devices Applications directly control devices
– To minimize latency– More intimate relation between devices and applications, tha
nt desktop PC applications
Hiding hardware specification
2006/1/20 5IGEL Co.,Ltd. / Renesas Solution Corp.
User Level Device DriversUser Level Device Drivers
Implementing Device Drivers in User Space Expected effects
– Use of abundant tools/libraries (e.g. files)– Ease of development and debugging– Less system hang ups– Less distance to applications– ….
Related research– Peter Chubb, “Get more device drivers out of kernel,” OLS20
04.
2006/1/20 6IGEL Co.,Ltd. / Renesas Solution Corp.
Features RequiredFeatures Requiredfor Device Driversfor Device Drivers
Access to I/O Memory– Device control through register I/O, data I/O
Interrupt Receipt and Handling Physical Memory Allocation and Access
– Necessary for devices which access directly to memory using DMA, etc.
– In case of DMA, allocation of consecutive memory may be required
Lock of CPU , Realtime Interface to Applications
2006/1/20 7IGEL Co.,Ltd. / Renesas Solution Corp.
Interrupt Receipt and HandlingInterrupt Receipt and Handlingin User Level Device Driversin User Level Device Drivers
Interrupt Reciept by File I/O– Prepare device files for each interrupt number– read() the device file and block until interrupt occurs
2006/1/20 8IGEL Co.,Ltd. / Renesas Solution Corp.
Memory AccessMemory Accessin User Level Device Driversin User Level Device Drivers
Direct Access to I/O Memory with Memory Map(mmap)– open(), mmap() the /dev/mem or specific device file– Once mmap’ed, then accessible as usual
For Physical Memory, Allocate, then mmap
2006/1/20 9IGEL Co.,Ltd. / Renesas Solution Corp.
Interface to ApplicationsInterface to Applicationsin User Level Device Driversin User Level Device Drivers
As User Level Device Driver can Exist in the Same User Space as Applications, Such Interfaces as Interprocess Communications, Shared Memory, etc. can Implementable
Easy to Integrate with Applications
2006/1/20 10IGEL Co.,Ltd. / Renesas Solution Corp.
CPU Lock, RealtimeCPU Lock, Realtimein User Level Device Driversin User Level Device Drivers
With RT Threads, to Some Extent… To be discussed
2006/1/20 11IGEL Co.,Ltd. / Renesas Solution Corp.
ImplementationImplementation (( Serial DriveSerial Driverr ))
Implementation Environment– RTS7751R2D
• Renesas SH4• SM501 companion chip em
bedding UART– 8250 compatible
– 2 modes: 1 byte I/O and FIFO buffer I/O
– Linux 2.6.13.4• CONFIG_PREEMPT=y• Glibc 2.3.3
2006/1/20 12IGEL Co.,Ltd. / Renesas Solution Corp.
ProcessingProcessing
Interrupt Handling– Receiving Data– Emptying Send Buffer[?]
I/O Memory Access– SM501 Register I/O
2006/1/20 13IGEL Co.,Ltd. / Renesas Solution Corp.
Linux Kernel
Software ArchitectureSoftware Architecture
I/O Memory Map Driver Interrupt Hook Driver
SM501 UART
Terminal
App
User Level
UART D.Driver
Data I/O
Buffer
2006/1/20 14IGEL Co.,Ltd. / Renesas Solution Corp.
Interrupt Hook DriverInterrupt Hook Driver
static int irqhook_proc_open(struct inode *inop, struct file *filp) {
...request_irq(ipp->irq, irqhook_proc_irq_handler, SA_INTERRUPT, ipp->devname, ipp);...}
static ssize_t irqhook_proc_read(struct file *filp, char __user *bufp, size_t len, loff_t *ppos) {
.... prepare_to_wait(&ipp->q, &wait, TASK_INTERRUPTIBLE); pending = atomic_read(&ipp->count);
if (pending == 0) schedule(); .....}
2006/1/20 15IGEL Co.,Ltd. / Renesas Solution Corp.
I/O Memory Map DriverI/O Memory Map Driver
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;
vma->vm_flags |= VM_RESERVED; vma->vm_flags |= VM_IO; vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
/* Map each page to users' virtual memory space */ if (io_remap_page_range(vma, vma->vm_start, offset, size, vma->vm_page_prot)) return -EAGAIN;
return 0;}
2006/1/20 16IGEL Co.,Ltd. / Renesas Solution Corp.
UART DriverUART Driver
while (1) { .... if (read(fd, &n_pending, sizeof(int) > 0) { if ((status = SM501_UART0_LINESTAT(&iomem)) & 0x01) { do { buffer[count]= SM501_UART0_RXBUFF(&iomem); status = SM501_UART0_LINESTAT(&iomem); count++; if(count >= BUFFER_SIZE){ loop++; count = 0; if(loop >= LOOP_COUNT) goto end; } while((status & 0x01)&&(max_count-- > 0)); } ....}
2006/1/20 17IGEL Co.,Ltd. / Renesas Solution Corp.
ExperimentExperiment
Just started experimenting… Serial I/O
– Measured throughput with 1MB READ/WRITE for serial device
– Used SM501 byte I/O mode– Kernel drivers are those included in 2.6.13.4– User level device driver was executed as RT task– User level device driver was integrated with serial I/O proces
s– Connected R2D board and note PC(TeraTerm) with serial cr
oss cable
2006/1/20 18IGEL Co.,Ltd. / Renesas Solution Corp.
Experiment ResultsExperiment Results
38.4kbps 300bps
Read Write Read Write
User Level DD 29.95kbps 30.68kbps 210.70bps 213.34bps
Kernel Level DD
29.69kbps 28.08kbps 232.82bps 232.70bps
Data Size : 1MB Buffer Size : 1KB Baud Rate : 300 or 38400 bps Mesured values : Average of the 10 trial res
ults of the same experiment
2006/1/20 19IGEL Co.,Ltd. / Renesas Solution Corp.
ImpressionsImpressions
Negligible Overhead At least in Low Load Environment (where no one intervenes)?– ULDD is rather faster for 38.4kbps– Deserves analysis – My action item
System Stability, Ease of Coding and Debugging, and Abundance of User Land Features are Attractive
2006/1/20 20IGEL Co.,Ltd. / Renesas Solution Corp.
IssuesIssues
Behavior in Heavy Load Environment– RT tasks / Non-RT tasks
Comparison with PC Environment Evaluation with Other Devices Summary of Characteristics of Kernel Level Device D
rivers and User Level Device Drivers Seeking for Novelty…
2006/1/20 21IGEL Co.,Ltd. / Renesas Solution Corp.
DiscussionDiscussion