Linux Kernel Development - Robert Love

Slides:



Advertisements
Similar presentations
Device Drivers. Linux Device Drivers Linux supports three types of hardware device: character, block and network –character devices: R/W without buffering.
Advertisements

CSNB324 Advanced Operating Systems 6: Device Management
Chapter 3 Basic Input/Output
Tutorial 3 - Linux Interrupt Handling -
Kernel Synchronization
Interrupts (Hardware). Interrupt Descriptor Table Slide #2 IDT specified as a segment using the IDTR register.
CSCI 4717/5717 Computer Architecture
Figure 2.8 Compiler phases Compiling. Figure 2.9 Object module Linking.
Home: Phones OFF Please Unix Kernel Parminder Singh Kang Home:
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
CS533 - Concepts of Operating Systems 1 CS533 Concepts of Operating Systems Class 8 Synchronization on Multiprocessors.
Mehmet Can Vuran, Instructor University of Nebraska-Lincoln Acknowledgement: Overheads adapted from those provided by the authors of the textbook.
Computer System Laboratory
Device Drivers In Linux © Gregory Kesden Fall 2000.
Interrupt Handling Sarah Diesburg COP Interrupt Handling One big responsibility of an operating system is to handle hardware connected to the machine.
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
CSC 660: Advanced Operating SystemsSlide #1 CSC 660: Advanced OS Interrupts.
CS591 (Spring 2001) The Linux Kernel: Debugging. CS591 (Spring 2001) Accessing the “Black Box” n Kernel code: n Not always executed in context of a process.
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.
Windows 2000 System Mechanisms Computing Department, Lancaster University, UK.
Fall 2013 SILICON VALLEY UNIVERSITY CONFIDENTIAL 1 Introduction to Embedded Systems Dr. Jerry Shiao, Silicon Valley University.
Lab 13 Department of Computer Science and Information Engineering National Taiwan University Lab13 – Interrupt + Timer 2014/12/23 1 /16.
Sogang University Advanced Operating Systems (Enhanced Device Driver Operations) Advanced Operating Systems (Enhanced Device Driver Operations) Sang Gue.
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.
RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals.
Preemptive Context Switching
Ch 7. Interrupts and Interrupt Handlers. Overview (1) A primary responsibility of the kernel is managing the hardware connected to the machine  The kernel.
CSNB334 Advanced Operating Systems 6. Device Management Lecturer: Asma Shakil.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
Interrupt Handling Ted Baker  Andy Wang CIS 4930 / COP 5641.
CSC 660: Advanced Operating SystemsSlide #1 CSC 660: Advanced OS Synchronization.
Ch 6. Interrupts and Interrupt Handlers. Overview (1) A primary responsibility of the kernel is managing the hardware connected to the machine  The kernel.
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.
Where Testing Fails …. Problem Areas Stack Overflow Race Conditions Deadlock Timing Reentrancy.
Interrupts and Interrupt Handling David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO
Ch6. Flow of Time Ch7. Getting Hold of Memory 홍원의.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
Lecture 7 Interrupt ,Trap and System Call
Interrupts and Exceptions 國立中正大學 資訊工程研究所 羅習五 老師. Interrupt & Exceptions Interrupts – maskable & nonmaskable interrupt Exceptions – Processor-detected.
Timers and Time Management Ok-Kyun Ha
Chapter 10 Interrupts. Basic Concepts in Interrupts  An interrupt is a communication process set up in a microprocessor or microcontroller in which:
REAL-TIME OPERATING SYSTEMS
Interrupts and Interrupts Handling
Processes and threads.
Process concept.
Interrupts and signals
Microprocessor and Assembly Language
Interfacing with Hardware
Microprocessor Systems Design I
CS 6560: Operating Systems Design
Lesson Objectives Aims Key Words Interrupt, Buffer, Priority, Stack
Anton Burtsev February, 2017
Mechanism: Limited Direct Execution
Interrupts In 8085 and 8086.
Day 08 Processes.
Day 09 Processes.
Process Synchronization and Communication
Interrupts and Interrupt Handling
Structure of Processes
Computer System Overview
Processor Fundamentals
Top Half / Bottom Half Processing
Linux Kernel Programming CIS 4930/COP 5641
Interrupt handling Explain how interrupts are used to obtain processor time and how processing of interrupted jobs may later be resumed, (typical.
Unix Process Control B.Ramamurthy 4/11/2019 B.Ramamurthy.
COMP3221: Microprocessors and Embedded Systems
Interrupts and Interrupt Handling
Presentation transcript:

Linux Kernel Development - Robert Love 설지훈

Contents Interrupts and interrupt handlers Bottom halves and deferring work

Introduction Interrupts Interrupts are special electrical signals sent from hardware devices to the processor The operating system can service each interrupt with a unique handler These interrupt values are often called interrupt request (IRQ) lines Example, zero is timer, one is keyboard.

Interrupts and interrupt handlers The function the kernel runs in response to a specific interrupt is called an interrupt handler or interrupt service routine (ISR) The interrupt handler for a device is part of the devices’s driver The interrupt handler execute in as short a period as possible

Registering an interrupt handler Parameters irq Specifies the interrupt number to allocate handler A pointer to the actual interrupt handler that services this interrupt irqflags SA_INTERRUPT, SA_SAMPLE_RANDOM, SA_SHIRQ devname An ASCII text representation of the device associated with the interrupt dev_id Used primarily for shared interrupt lines Note request_irq() might sleep and, therefore, cannot be called from interrupt context or other situations where code cannot block int request_irq (unsigned int irq, irqreturn_t (*handler)(int, void *, struct pt_regs *), unsigned long irqflags, const char * devname, void *dev_id)

Freeing an interrupt handler If the interrupt line is shared, the handler identified via dev_id is removed A call to free_irq() must be made from process context void free_irq (unsigned int irq, void *dev_id)

Writing an interrupt handler static irqreturn_t intr_handler (int irq, void *dev_id, struct pt_regs *regs) Parameter regs Holds a pointer to a structure containing the processor registers and state prior to servicing the interrupt. They are rarely used, except for debugging Return value of an interrupt handler IRQ_NONE Detects an interrupt for which its device was not the originator IRQ_HANDLED Correctly invoked, and its device did cause the interrupt

Shared handlers A shared handler is registered and executed much like a non-shared handler. Three main differences are The SA_SHIRQ flag must be set in the flags argument to request_irq() The dev_id argument must be unique to each registered handler. The interrupt handler must be capable of distinguishing whether its device actually generated an interrupt

Interrupt context When executing an interrupt handler or bottom half, the kernel is in interrupt context Interrupt context is not associated with a process Interrupt context cannot sleep Interrupt context is time critical Interrupt handler does not receive its own stack Instead, it shares the kernel stack of the process or idle task’s stack

Implementation of interrupt handling int handle_IRQ_event(unsigned int irq, struct pt_regs *regs, struct irqaction *action) { int status = 1; if (!(action->flags & SA_INTERRUPT)) local_irq_enable(); do { status |= action->flags; action ->handler(irq, action->dev_id, regs); action = action->next; } while (action); if (status & SA_SAMPLE_RANDOM) add_interrupt_randomness(irq); local_irq_disable(); return status; }

/proc/interrupts

Interrupt control Reasons to control the interrupt system generally boil down to needing to provide synchronization Kernel code more generally needs to obtain some sort of lock to prevent access to shared data simultaneously from another processor These locks are often obtained in conjunction with disabling local interrupts

Disabling and Enabling interrupts To disable interrupts locally for the current processor (and only the current processor) and later enable them: local_irq_disable(); /* interrupts are disabled */ local_irq_enabled();

Bottom Halves and Deferring Work Interrupt limitations include They need to run as quickly as possible Interrupt handlers are often very timing-critical because they deal with hardware Interrupt handlers do not run in process context, therefore, they cannot block Managing interrupts is divided two parts Interrupt handlers (top halves) Interrupt-related work not performed by the interrupt handler (bottom halves)

Bottom halves Why bottom halves? A world of bottom halves Interrupt handlers run with the current interrupt line disabled or all local interrupt disabled The bottom half runs later with all interrupts enabled Later is often simply not now A world of bottom halves BH (bottom halves) Removed in 2.5 Task queues Softirq Available since 2.3 Tasklet Work queues Available since 2.5

Softirqs Implementation of Softirqs Statically allocated at compile-time There can be a possible 32 softirqs (fixed)