Top Half / Bottom Half Processing

Slides:



Advertisements
Similar presentations
Tutorial 3 - Linux Interrupt Handling -
Advertisements

ECE 526 – Network Processing Systems Design Software-based Protocol Processing Chapter 7: D. E. Comer.
Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented by: Jeremy Schiff.
Home: Phones OFF Please Unix Kernel Parminder Singh Kang Home:
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,
CE Operating Systems Lecture 11 Windows – Object manager and process management.
Fall 2013 SILICON VALLEY UNIVERSITY CONFIDENTIAL 1 Introduction to Embedded Systems Dr. Jerry Shiao, Silicon Valley University.
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.
Preemptive Context Switching
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 2: The Linux System Part 3.
How & When The Kernel Runs David Ferry, Chris Gill Department of Computer Science and Engineering Washington University, St. Louis MO
Kernel Structure and Infrastructure David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO
Interrupts and Interrupt Handling David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
Kernel Synchronization David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO
Chapter 4: Threads Modified by Dr. Neerja Mhaskar for CS 3SH3.
Kernel Design & Implementation
Non Contiguous Memory Allocation
Chapter 13: I/O Systems Modified by Dr. Neerja Mhaskar for CS 3SH3.
Chapter 4: Threads.
Linux Kernel Development - Robert Love
Processes and threads.
Linux Details: Device Drivers
Scheduling of Non-Real-Time Tasks in Linux (SCHED_NORMAL/SCHED_OTHER)
Interfacing with Hardware
CS 6560: Operating Systems Design
Midterm Review Chris Gill CSE 422S - Operating Systems Organization
Time Sources and Timing
Midterm Review David Ferry, Chris Gill
Processes David Ferry, Chris Gill
Intro to Processes CSSE 332 Operating Systems
Architecture Background
Semester Review Chris Gill CSE 422S - Operating Systems Organization
Interrupts and Interrupt Handling
Computer System Overview
Kernel Synchronization II
Processor Fundamentals
Chapter 2: The Linux System Part 3
Outline Module 1 and 2 dealt with processes, scheduling and synchronization Next two modules will deal with memory and storage Processes require data to.
Kernel Structure and Infrastructure
TinyOS CSE466 Final Project Presentation
Linux Details: Device Drivers
Multithreaded Programming
Kernel Synchronization I
CSE 451: Operating Systems Autumn 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 596 Allen Center 1.
CSE 451: Operating Systems Autumn 2001 Lecture 2 Architectural Support for Operating Systems Brian Bershad 310 Sieg Hall 1.
Midterm Review Brian Kocoloski
How & When The Kernel Runs
Semester Review Brian Kocoloski
Kernel Synchronization II
Chapter 4: Threads.
Scheduling of Regular Tasks in Linux
Userspace Synchronization
CSE 451: Operating Systems Winter 2007 Module 2 Architectural Support for Operating Systems Brian Bershad 562 Allen Center 1.
Processes in Unix, Linux, and Windows
CSE 451: Operating Systems Autumn 2003 Lecture 7 Synchronization
Linux Block I/O Layer Chris Gill, Brian Kocoloski
CSE 451: Operating Systems Autumn 2005 Lecture 7 Synchronization
CSE 451: Operating Systems Winter 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 412 Sieg Hall 1.
CS333 Intro to Operating Systems
Scheduling Classes and Real-Time Scheduling in Linux
CSE 451 Section 1/27/2000.
Interrupts and Interrupt Handling
Processes David Ferry, Chris Gill, Brian Kocoloski
Page Cache and Page Writeback
In Today’s Class.. General Kernel Responsibilities Kernel Organization
Scheduling of Regular Tasks in Linux
Presentation transcript:

Top Half / Bottom Half Processing David Ferry, Chris Gill, Brian Kocoloski CSE 422S - Operating Systems Organization Washington University in St. Louis St. Louis, MO 63130

Bottom Halves Defer Work Modern interrupt handlers are split into top half (fast) and bottom half (slow) components Top half: Does minimum work to service hardware Sets up future execution of bottom half Clears interrupt line Bottom half: Performs deferred processing Example: Network card – top half clears card buffer while bottom half processes and routes packets CSE 422S – Operating Systems Organization

Advantages of Bottom Halves 1. Allow the kernel to run time-sensitive work before your bottom half 2. Allow your deferred work to itself be pre-emptible, because it runs with interrupts enabled Some interrupt handles run with all interrupts disabled (IRQF_DISABLED) Others only disable the current interrupt line, which could still be problematic All other devices that use that interrupt line are blocked e.g., devices on PCI buses can share interrupt lines CSE 422S – Operating Systems Organization

CSE 422S – Operating Systems Organization Interrupt context Note: there is a key distinction between interrupt context and execution with interrupts disabled Top halves run in interrupt context and with interrupts disabled Bottom halves can run in interrupt context, but run with interrupts enabled Why is this distinction important? Disabling interrupts prevents the kernel from running higher priority work – i.e., it creates non-determinism from the kernel’s perspective CSE 422S – Operating Systems Organization

When does bottom half work run? At some point in the future Bottom halves gives the kernel the opportunity to decide whether or not now is a good time to do this work That means: The kernel could decide to run your bottom half immediately The kernel could decide it is higher priority work to do You thus have no guarantee on when deferred work will finish CSE 422S – Operating Systems Organization

Bottom Half Mechanisms Softirqs (interrupt context) Statically defined Same softirq handler can execute concurrently on different processors, so may be more difficult to program correctly Offer most concurrency at the expense of being harder to program - locking must be done by driver Tasklets (interrupt context) Should be your default choice over softirqs Tasklet handlers of same type do not execute concurrently Work Queues (process context) Defers work to generic kernel threads (kworker) It’s ok for the work function to sleep, block, etc. Replaces having to make your own deferred kernel thread CSE 422S – Operating Systems Organization

CSE 422S – Operating Systems Organization Softirqs Most complex bottom half mechanism Only used in a small set of situations When the work to do is substantial and can benefit from concurrency i.e., when you want to run your bottom half work concurrently on multiple cores Rarely used directly by programmers Defined at compile time, code can’t register dynamically Need to watch out for data races (can execute concurrently) Stored in a fixed-sized array of pointers to “functors” (struct with action handler function pointer as a member CSE 422S – Operating Systems Organization

CSE 422S – Operating Systems Organization When do softirqs run? Consider the example of a network interrupt handler Some packets come in, the top-half copies them to DRAM, lowers the interrupt, and then schedules the bottom-half softirq to run (NET_RX_SOFTIRQ) Q: When will the bottom half run? A: it depends Return from hardware interrupt code path (i.e., immediately) In the ksoftirqd kernel thread (i.e, once the kernel schedules a kernel thread to execute it) In any code that explicitly checks for the existence of softirq work CSE 422S – Operating Systems Organization

CSE 422S – Operating Systems Organization Tasklets Tasklets may be easier to use than (non-tasklet) softirqs Can be registered dynamically (by code) or at compile time Tasklets are (implemented atop) softirqs Can register as HI_SOFTIRQ (run at high priority) or as TASKLET_SOFTIRQ (run at normal priority) Tasklet handlers of same type can’t run concurrently Can share data (across processors) w/out locking (still can’t block) But, don’t need to worry about data races within a handler type CSE 422S – Operating Systems Organization

Review: when do Softirqs (and therefore, tasklets) run? 3 ways the kernel checks for pending softirqs (LKD pp. 138): In the return from hardware interrupt code path In the ksoftirqd kernel thread In any code that explicitly checks for and executes softirqs, such as the networking subsystem CSE 422S – Operating Systems Organization

CSE 422S – Operating Systems Organization Work Queues Work is deferred to run in kernel threads Execute in process context (not in interrupt context) So, can sleep, lock, block, etc. Thus, any work that must sleep/block/etc. should run there Data structure for work queues One is defined for each type of worker thread Per CPU: work items, a thread task structure, and a spin lock Work structure packages up data and processing Work is implemented as pointer to function that is run While work list isn’t empty, thread calls each entry’s function When work list is empty, thread goes to sleep This approach is suitable for many deferred work situations CSE 422S – Operating Systems Organization

Which bottom half should you use? Does your work absolutely need to do operations that may block? E.g., large memory allocations If so, use work queues Is your work very time sensitive, or does it need concurrency? If so, use softirqs You need to modify the kernel source to use this operation – i.e., no kernel modules Otherwise, use tasklets CSE 422S – Operating Systems Organization