On using ‘tasklets’ An example of the Linux kernel’s ‘tasklet’ mechanism for deferring some interrupt-handling work.

Slides:



Advertisements
Similar presentations
System Integration and Performance
Advertisements

Device Drivers. Linux Device Drivers Linux supports three types of hardware device: character, block and network –character devices: R/W without buffering.
INPUT-OUTPUT ORGANIZATION
Lectures on File Management
Tutorial 3 - Linux Interrupt Handling -
Input and Output CS 215 Lecture #20.
The ATA/IDE Interface Can we write a character-mode device driver for the hard disk?
Another device-driver? Getting ready to program the network interface.
FIU Chapter 7: Input/Output Jerome Crooks Panyawat Chiamprasert
Chapter 6 Limited Direct Execution
Interrupts What is an interrupt? What does an interrupt do to the “flow of control” Interrupts used to overlap computation & I/O – Examples would be console.
A ‘ringbuffer’ application Introduction to process ‘blocking’ and the Linux kernel’s support for ‘sleeping’ and ‘waking’
Chapter 13-2 I/O Systems Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 13-2: I/O Systems Chapter 13-2 I/O Hardware (continued)
Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.
Handling a UART interrupt A look at some recent changes in the Linux kernel’s programming interface for device-interrupts.
Home: Phones OFF Please Unix Kernel Parminder Singh Kang Home:
The UART project Applying what we’ve learned about Linux device-drivers to the PC’s serial-port controller.
Computer Science 686 Spring 2007 Special Topic: Intel EM64T and VT Extensions.
1 Today I/O Systems Storage. 2 I/O Devices Many different kinds of I/O devices Software that controls them: device drivers.
1 The 9-Pin Connector Pin abbreviations (numbers in parentheses are the 25D pin numbers): 1. CD (8) 2. RD (Rx) (3) 3. TD (Tx) (2) 4. DTR (20) 5. SG (Ground)
Group 7 Jhonathan Briceño Reginal Etienne Christian Kruger Felix Martinez Dane Minott Immer S Rivera Ander Sahonero.
INTERRUPTS PROGRAMMING
1 Computer System Overview Chapter 1 Review of basic hardware concepts.
Copyright ©: Nahrstedt, Angrave, Abdelzaher
I/O Tanenbaum, ch. 5 p. 329 – 427 Silberschatz, ch. 13 p
INPUT-OUTPUT ORGANIZATION
University of Tehran 1 Interface Design Serial Communications Omid Fatemi.
1 CSC 2405: Computer Systems II Spring 2012 Dr. Tom Way.
Device Management. Serial Port Serial Device Serial Device Memory CPU Printer Terminal Modem Mouse etc.
Serial Port I/O Serial port sends and receives data one bit at a time. Serial communication devices are divided into: Data Communications Equipment (DCE),
OPERATING SYSTEM OVERVIEW. Contents Basic hardware elements.
1 Computer System Overview Chapter 1. 2 n An Operating System makes the computing power available to users by controlling the hardware n Let us review.
Input and Output Computer Organization and Assembly Language: Module 9.
Interrupts and DMA CSCI The Role of the Operating System in Performing I/O Two main jobs of a computer are: –Processing –Performing I/O manage and.
Universal Synchronous/Asynchronous Receiver/Transmitter (USART)
1-1 Embedded Network Interface (ENI) API Concepts Shared RAM vs. FIFO modes ENI API’s.
“Describe the overview of hardware interfacing and the serial communication interface. Describe the PIC18 connections to RS232. Explain the serial port.
Serial Communications
The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Tami Meredith, Ph.D. CSCI  Devices need CPU access  E.g., NIC has a full buffer it needs to empty  These device needs are often asynchronous.
I/O management is a major component of operating system design and operation Important aspect of computer operation I/O devices vary greatly Various methods.
Dhanshree Nimje Smita Khartad
 8251A is a USART (Universal Synchronous Asynchronous Receiver Transmitter) for serial data communication.  Programmable peripheral designed for synchronous.
13-Nov-15 (1) CSC Computer Organization Lecture 7: Input/Output Organization.
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.
Interfaces and Synchronization Martin Weiss. EIA 232D Interface Standard u Synonymous with ITU V.24 u Asynchronous interface u Up to 19.2kbps u 50 foot.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Chapter 13 – I/O Systems (Pgs ). Devices  Two conflicting properties A. Growing uniformity in interfaces (both h/w and s/w): e.g., USB, TWAIN.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
IT3002 Computer Architecture
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
Multithreading The objectives of this chapter are: To understand the purpose of multithreading To describe Java's multithreading mechanism.
1 Device Controller I/O units typically consist of A mechanical component: the device itself An electronic component: the device controller or adapter.
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.
Interrupts and Interrupt Handling David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO
Serial mode of data transfer
Linux Kernel Development - Robert Love
I/O SYSTEMS MANAGEMENT Krishna Kumar Ahirwar ( )
Lesson Objectives Aims Key Words Interrupt, Buffer, Priority, Stack
UNIT – Microcontroller.
Operating Systems (CS 340 D)
Computer Architecture
Serial Communication Interface: Using 8251
Computer System Overview
Serial Communication Interface
Processor Fundamentals
Top Half / Bottom Half Processing
CHAPTER SERIAL PORT PROGRAMMING. Basics of Serial Communication Computers transfer data in two ways: ◦ Parallel  Often 8 or more lines (wire.
Chapter 13: I/O Systems.
Presentation transcript:

On using ‘tasklets’ An example of the Linux kernel’s ‘tasklet’ mechanism for deferring some interrupt-handling work

Recall purpose of Project #2 Allow you to gain experience encountering the kinds of issues that commonly arise in crafting software to operate real hardware: Learning the hardware device’s capabilities Deciding which driver-methods to implement Accommodating your platform’s interfaces Exploiting the OS kernel’s support-functions Devising a strategy for testing and debugging

Driver enhancements Now that you’ve had an opportunity to get acquainted with the NS16550 serial UART (its documented capabilities and its quirks) we can build upon what you experienced to contemplate software enhancements that might not have made much sense if you lacked any actual confrontation with ‘real-world’ peripheral hardware on PCs

Urgent versus non-urgent When some peripheral device issues an interrupt request, it may need a prompt response to handle an urgent situation After the emergency has been dealt with, there may also be some further actions which are necessary, but which can be safely delayed without jeopardizing the integrity of proper system functioning

The serial UART As an example, when the UART receives characters via its serial-port, there is only a limited capability for preserving them in the device’s on-board ‘receive buffer’ These received characters need to be quickly moved out of the UART before they get overwritten by newer data -- or before they can cause other incoming characters to be ‘lost’ for lack of space

The ‘handshake’ lines A device-driver for the UART can use the handshaking signal-lines to regulate the quantity of data being transmitted to it It can de-assert the ‘Clear-To-Send’ signal being sampled by its equipment partner as a way to temporarily pause data-transfers Once the incoming data-stream is paused, there is less urgency to move data aside

9-wire null-modem cable CD CD RxD RxD TxD TxD GND GND DSR DSR DTR DTR RTS RTS CTS CTS RI RI Data Terminal Equipment Data Terminal Equipment the sender the receiver

Modem Control Register 7 6 5 4 3 2 1 0 LOOP BACK OUT2 OUT1 RTS DTR The receiver clears this bit Legend: DTR = Data Terminal Ready (1=yes, 0=no) RTS = Request To Send (1=yes, 0=no) OUT1 = not used (except in loopback mode) OUT2 = enables the UART to issue interrupts LOOPBACK-mode (1=enabled, 0=disabled)

Modem Status Register The sender checks this bit 7 6 5 4 3 2 1 0 DCD 7 6 5 4 3 2 1 0 DCD RI DSR CTS delta DCD delta RI delta DSR delta CTS set if the corresponding bit has changed since the last time this register was read Legend: [---- loopback-mode ----] CTS = Clear To Send (1=yes, 0=no) [bit 0 in Modem Control] DSR = Data Set Ready (1=yes, 0=no) [bit 1 in Modem Control] RI = Ring Indicator (1=yes,0=no) [bit 2 in Modem Control] DCD = Data Carrier Detected (1=yes,0=no) [bit 3 in Modem Control]

The sender’s algorithm Set RTS=1 in the Modem Control Register Read the Modem Status Register CTS==1? NO YES Read the Line Status Register THRE==1? NO YES Write byte to the Transmit Data Register DONE

The receiver’s actions When the receiver’s storage capacity has been reached, it takes urgent action to ‘pause’ any further transfers of data (i.e., it writes ‘0’ to the RTS-bit in its Modem Control register) Then it needs to remove its accumulation of received data out of its storage medium Being less urgent this can be postponed

Interrupt handling Often it’s beneficial to separate the actions a driver performs in responding to a device interrupt-request into two categories: the urgent ones are performed immediately, the less urgent ones temporarily delayed Accordingly programmers write separate functions, known as the “top half” and the “bottom half” for an interrupt handler

Application to the UART Top Half: Tell sender to ‘pause’ further data-transfers Bottom-Half: Move accumulated data out of the device’s on-board storage-area (e.g., its receive FIFO)

A tasklet for ‘bottom half’ work Your device-driver allocates and initializes a ‘struct tasklet_struct’ object, possessing a name, a function and a pointer to data Your driver’s ‘top-half’ interrupt-handler will schedule your tasklet for future execution name function ‘struct tasklet_struct’ object data-pointer

Linux syntax #include <linux/interrupt.h> struct tasklet_struct my_tasklet; struct mydata { … } my_tasklet_data; void my_function ( unsigned long ); tasklet_init( &my_tasklet, &my_function, (unsigned long)&my_tasklet_data ); tasklet_schedule( &my_tasklet ); tasklet_kill( &my_tasklet );

Tasklet semantics A few technical points to keep in mind if you decide to make use of ‘tasklets’: A ‘tasklet’ runs at ‘interrupt time’ (so it doesn’t own any user-space context, just kernel-space context) The kernel-space context is consistent across all tasks kernel space user space Some interrupted task’s context resides here (so it can’t be predicted) ‘virtual’ memory

More tasklet semantics… A tasklet runs in ‘atomic mode’ (so cannot sleep), although it can ‘wake up’ a task that is sleeping A tasklet executes on the CPU that scheduled it (and so doesn’t execute concurrently with itself) You can schedule your tasklet to run either at “normal” priority or at “high” priority – the latter ones all are run before any of the former ones

‘sleep’ versus ‘busy waiting’ Our ‘tasklet.c’ demo uses the ‘interruptible sleep’ mechanism in its device-driver ‘read()’ method Whenever the UART receives new data, it will interrupt whatever else the CPU is doing Quickly our ‘top half’ interrupt-handler pauses any more data-transfers, schedules our ‘bottom half’ for future execution, then resumes the interrupted task Later our ‘tasklet’ will move accumulated data from the FIFO to a ringbuffer, then will awaken any task was sleeping on our ‘read’ function’s wait-queue

The senario overview READ() sleeps until driver’s ringbuffer has some data moves data from to user’s buffer issues ‘Clear-To-Send’ if case the has been emptied reports count of bytes returned in user’s buffer Arrival of new data interrupts the CPU ISR stops the sending of additional data schedules the tasklet resumes the Interrupted task TASKLET transfers received bytes from UART to to ringbuffer wakes up sleeping readers

‘write()’ We did not employ efficiency-techniques in our device-driver’s ‘write()’ function: No wait-queues No interrupts No tasklets Thus there is still an opportunity for you to add improvements to our ‘tasklet.c’ demo!

In-class exercise Download our ‘tasklet.c’ module from the course website, compile it, and install it a pair of our machines which are connected to each other via a null-modem cable Try testing the ‘robustness’ of our driver: First launch the ‘cat’ command … … then redirect lots of screen-output! $ cat /dev/uart $ ls -l /usr/bin > /dev/uart