I/O Multiplexing The role of the ‘poll()’ method in Linux device-driver operations.

Slides:



Advertisements
Similar presentations
Linux device-driver issues
Advertisements

RT_FIFO, Device driver.
Tutorial 3 - Linux Interrupt Handling -
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Another device-driver? Getting ready to program the network interface.
I/O Multiplexing Road Map: 1. Motivation 2. Description of I/O multiplexing 3. Scenarios to use I/O multiplexing 4. I/O Models  Blocking I/O  Non-blocking.
Daemon Processes Long lived utility processes Often started at system boot and ended when system shuts down Run in the background with no controlling terminal.
Today’s topic Issues about sending structures with TCP. Server design alternatives: concurrent server and multiplexed server. I/O multiplexing.
I/o multiplexing On adding a ‘poll()’ method to our character-mode device-driver for an 82573L network controller.
Day 10 Threads. Threads and Processes  Process is seen as two entities Unit of resource allocation (process or task) Unit of dispatch or scheduling (thread.
What’s in a device driver?. Role of the OS Protect data and resources (file permissions, etc.) Provide isolation (virtual memory, etc.) Abstract away.
CS 342 – Operating Systems Spring 2003 © Ibrahim Korpeoglu Bilkent University1 Threads CS 342 – Operating Systems Ibrahim Korpeoglu Bilkent University.
A ‘ringbuffer’ application Introduction to process ‘blocking’ and the Linux kernel’s support for ‘sleeping’ and ‘waking’
Standard C Library Application Programming Interface to System-Calls.
Applying kernel timers Could we prevent a device-driver from consuming an excessive amount of processor time?
Home: Phones OFF Please Unix Kernel Parminder Singh Kang Home:
How to Debug VB .NET Code.
The ‘ioctl’ driver-function On implementing a way to query and modify our UART’s baudrate via the ‘device-file’ abstraction.
Kernel timing issues An introduction to the use of kernel timers and work queues.
Access to High Memory Introduction to the kernel functions ‘kmap()’ and ‘kunmap()
Multiplexing i/o A look at some alternatives under Linux for dealing concurrently with multiple sources of device-input.
1 Today I/O Systems Storage. 2 I/O Devices Many different kinds of I/O devices Software that controls them: device drivers.
IP Multiplexing Ying Zhang EECS 489 W07.
Chapter 18 I/O in C. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Standard C Library I/O commands.
Memory Mapped Files Using the Linux mechanism for direct access to device data.
I/O Systems ◦ Operating Systems ◦ CS550. Note:  Based on Operating Systems Concepts by Silberschatz, Galvin, and Gagne  Strongly recommended to read.
CSE 451: Operating Systems Autumn 2013 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Operating System Program 5 I/O System DMA Device Driver.
General System Architecture and I/O.  I/O devices and the CPU can execute concurrently.  Each device controller is in charge of a particular device.
System Calls 1.
Nachos Phase 1 Code -Hints and Comments
FINAL MPX DELIVERABLE Due when you schedule your interview and presentation.
CHAPTER 2: COMPUTER-SYSTEM STRUCTURES Computer system operation Computer system operation I/O structure I/O structure Storage structure Storage structure.
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Principles of I/0 hardware.
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
I/O Interfacing A lot of handshaking is required between the CPU and most I/O devices. All I/O devices operate asynchronously with respect to the CPU.
Multiprogramming. Readings r Silberschatz, Galvin, Gagne, “Operating System Concepts”, 8 th edition: Chapter 3.1, 3.2.
OS2014 PROJECT 2 Supplemental Information. Outline Sequence Diagram of Project 2 Kernel Modules Kernel Sockets Work Queues Synchronization.
1 I/O Multiplexing We often need to be able to monitor multiple descriptors:We often need to be able to monitor multiple descriptors: –a generic TCP client.
CSCE 515: Computer Network Programming Select Wenyuan Xu Department of Computer Science and Engineering.
Interrupt driven I/O. MIPS RISC Exception Mechanism The processor operates in The processor operates in user mode user mode kernel mode kernel mode Access.
Operating System Structure A key concept of operating systems is multiprogramming. –Goal of multiprogramming is to efficiently utilize all of the computing.
Implementing ‘noecho’ Programming details regarding the Linux implementation for ‘struct termios’ objects.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Processes and Threads.
Weather-Sensing Fabulous Weather-Sensing Data-logger! Introducing the… 100% designed and manufactured at the Vigyan Ashram FabLab!
Named Pipes. Kinds of IPC u Mutexes/Conditional Variables/Semaphores u Pipes u Named pipes u Signals u Shared memory u Messages u Sockets.
CS 342 – Operating Systems Spring 2003 © Ibrahim Korpeoglu Bilkent University1 Input/Output – 2 I/O Software CS 342 – Operating Systems Ibrahim Korpeoglu.
Data Types and Conversions, Input from the Keyboard CS303E: Elements of Computers and Programming.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
TANNENBAUM: 5, BIC & SHAW, SILBERSCHATZ: 12 INPUT/OUTPUT DEVICE DRIVERS.
10. Epilogue ENGI 3655 Lab Sessions.  We took control of the computer as early as possible, right after the end of the BIOS  Our multi-stage bootloader.
I/O Software CS 537 – Introduction to Operating Systems.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
Ch6. Flow of Time Ch7. Getting Hold of Memory 홍원의.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
Input/Output Device Drivers
Chapter 2: Computer-System Structures(Hardware)
Chapter 2: Computer-System Structures
CS 6560: Operating Systems Design
Mechanism: Limited Direct Execution
Threads and Locks.
The slides must be understood in Lecture 5
Computer System Laboratory
January 15, 2004 Adrienne Noble
Chapter 2: Computer-System Structures
Chapter 2: Computer-System Structures
I/O Multiplexing We often need to be able to monitor multiple descriptors: a generic TCP client (like telnet) need to be able to handle unexpected situations,
Chapter 13: I/O Systems “The two main jobs of a computer are I/O and [CPU] processing. In many cases, the main job is I/O, and the [CPU] processing is.
Presentation transcript:

I/O Multiplexing The role of the ‘poll()’ method in Linux device-driver operations

struct file_operations fops; read: write: open: close: llseek: … poll://  what is this function for?

Recall ‘watchtsc.cpp’ demo After some initializations, this application entered an endless loop, rereading from the ‘/dev/tsc’ device special file. But it also checked for user input from the keyboard, so a user could break out of the endless loop in order to quit the program.

Illustrates I/O Multiplexing Read from /dev/tsc Read from keyboard redraw display maybe quit More than just one source for input

Remember ‘read()’ semantics If device-driver’s ‘read()’ function is called before the device has any data available, then the calling task is expected to ‘sleep’ on a wait-queue until the device has at least one byte of data ready to return. The keyboard’s device-driver behaves in exactly that expected way: it ‘blocks’ if we try to read when there are no keystrokes.

Blocking versus Multiplexing If we want to read from multiple devices, we are not able to do it properly with the read() system-call If one device has no data, our task will be blocked, and so can’t read data that may become available from some other device

Idea: use ‘nonblocking’ i/o When we ‘open()’ a device-file, we could specify the ‘O_NONBLOCK’ i/o mode For the keyboard: two problems with this: –The ‘stdin’ device is already open by default –If a task tries to do multiplexing with devices that have been opened in non-blocking mode, it will likely consume way too much cpu time!

Better idea: use ‘select()’ The ‘select()’ system-call was designed to allow applications to efficiently perform i/o multiplexing With ‘select()’ the application informs the kernel as to which system devices it is interested in The kernel then ‘polls’ those devices, to see if any of them is ready to do i/o without blocking If not, it puts the process to sleep until at least one device is ready to do i/o without blocking

Calling ‘select()’ Application needs an ‘fd_set’ structure For reading, for writing, and for errors And maybe also a ‘timeout’ structure In our ‘watchtsc.cpp’ demo: –We only were interested in reading –Not interested in writing or in errors –And not concerned about ‘timeouts’ Full details on the ‘man’ page for ‘select()’

Driver needs ‘poll()’ method To support the ‘select()’ system-call, our ‘tsc.c’ driver needs to implement ‘poll()’ Our textbook tells what we need to do Just two things: –Need to call the kernel ‘poll_wait()’ function –Return a bitmap indicating device readiness

prototype for ‘poll()’ method #include // for ‘poll_table’ static int ready;// kernel-timer’s flag DECLARE_WAIT_QUEUE_HEAD( wq ); static unsigned long my_poll( struct file *file, poll_table *wait );

Actions in our ‘poll()’ function static unsigned long my_poll( sruct file *file, poll_table *wait ) { unsigned longmask = 0; poll_wait( file, &wq, wait ); if ( ready ) // our kernel-timer’s flag mask |= ( POLLIN | POLLRDNORM ); returnmask; }

An experiment with ‘poll()’ Modify the ‘tsc.c’ device-driver code Include ‘poll()’ in ‘file_operations’ struct Use a kernel software timer in ‘read()’ Use 5-second delay between ‘reads’ Run ‘watchtsc’ with polling implemented And run ‘watchtsc’ with polling ommitted Note responsiveness to keyboard input!

Does ‘ram.c’ need ‘poll()’? The system memory is ‘volatile’ Contents of memory continually changing For example, the ‘jiffies’ variable And lots of other examples as well Our ‘fileview.cpp’ tool doesn’t show this It ‘blocks’ until the user presses a key Would be much better to use ‘select()’