Kernel Synchronization and Interrupt Handling



Similar documents
A Survey of Parallel Processing in Linux

Mutual Exclusion using Monitors

REAL TIME OPERATING SYSTEMS. Lesson-10:

Real Time Programming: Concepts

Red Hat Linux Internals

Chapter 6, The Operating System Machine Level

SYSTEM ecos Embedded Configurable Operating System

Lecture 6: Interrupts. CSC 469H1F Fall 2006 Angela Demke Brown

Chapter 2: OS Overview

Linux Driver Devices. Why, When, Which, How?

Linux Scheduler. Linux Scheduler

Linux Kernel Networking. Raoul Rivas

Real-Time Systems Prof. Dr. Rajib Mall Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

An Implementation Of Multiprocessor Linux

Multiprocessor Scheduling and Scheduling in Linux Kernel 2.6

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

Operating System Manual. Realtime Communication System for netx. Kernel API Function Reference.

Chapter 13 Embedded Operating Systems

First-class User Level Threads

Why Computers Are Getting Slower (and what we can do about it) Rik van Riel Sr. Software Engineer, Red Hat

Exception and Interrupt Handling in ARM

Processes and Non-Preemptive Scheduling. Otto J. Anshus

Thomas Fahrig Senior Developer Hypervisor Team. Hypervisor Architecture Terminology Goals Basics Details

Embedded Systems. 6. Real-Time Operating Systems

Module 8. Industrial Embedded and Communication Systems. Version 2 EE IIT, Kharagpur 1

Resource Utilization of Middleware Components in Embedded Systems

Priority Based Implementation in Pintos

Real-Time Component Software. slide credits: H. Kopetz, P. Puschner

Have both hardware and software. Want to hide the details from the programmer (user).

Mouse Drivers. Alan Cox.

Keil C51 Cross Compiler

CS414 SP 2007 Assignment 1

Understanding Linux on z/vm Steal Time

Linux Process Scheduling Policy

Multi-core Programming System Overview

CPU performance monitoring using the Time-Stamp Counter register

Deciding which process to run. (Deciding which thread to run) Deciding how long the chosen process can run

Binary Device Driver Reuse. Bernhard Poess. Diplomarbeit

Kernel Optimizations for KVM. Rik van Riel Senior Software Engineer, Red Hat June

XMOS Programming Guide

Synchronization. Todd C. Mowry CS 740 November 24, Topics. Locks Barriers

ELEC 377. Operating Systems. Week 1 Class 3

Replication on Virtual Machines

Intel DPDK Boosts Server Appliance Performance White Paper

Performance Improvement In Java Application

Common clock framework: how to use it

Scaling Networking Applications to Multiple Cores

Introduction. What is an Operating System?

Readings for this topic: Silberschatz/Galvin/Gagne Chapter 5

Tasks Schedule Analysis in RTAI/Linux-GPL

POSIX. RTOSes Part I. POSIX Versions. POSIX Versions (2)

OS OBJECTIVE QUESTIONS

Programming real-time systems with C/C++ and POSIX

Interrupts in Linux. COMS W4118 Prof. Kaustubh R. Joshi hfp://

Real-Time Operating Systems.

W4118 Operating Systems. Instructor: Junfeng Yang

Enhancing the Monitoring of Real-Time Performance in Linux

System Software and TinyAUTOSAR

EE8205: Embedded Computer System Electrical and Computer Engineering, Ryerson University. Multitasking ARM-Applications with uvision and RTX

MQX Lite Real-Time Operating System User Guide

SSC - Concurrency and Multi-threading Java multithreading programming - Synchronisation (I)

Shared Address Space Computing: Programming

Performance Comparison of RTOS

The Real-Time Operating System ucos-ii

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

Getting maximum mileage out of tickless

Jorix kernel: real-time scheduling

Multi-Threading Performance on Commodity Multi-Core Processors

Threads Scheduling on Linux Operating Systems

Linux Load Balancing

REAL TIME OPERATING SYSTEM PROGRAMMING-II: II: Windows CE, OSEK and Real time Linux. Lesson-12: Real Time Linux

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Real-Time Scheduling 1 / 39

Zing Vision. Answering your toughest production Java performance questions

Outline. Review. Inter process communication Signals Fork Pipes FIFO. Spotlights

Department of Electrical Engineering and Computer Science MASSACHUSETTS INSTITUTE OF TECHNOLOGY Operating System Engineering: Fall 2005

Page 1 of 5. IS 335: Information Technology in Business Lecture Outline Operating Systems

1. Computer System Structure and Components

Java Virtual Machine Locks

Lecture 6: Semaphores and Monitors

Real-time KVM from the ground up

Concurrent Programming

White Paper. Real-time Capabilities for Linux SGI REACT Real-Time for Linux

Objectives. Chapter 2: Operating-System Structures. Operating System Services (Cont.) Operating System Services. Operating System Services (Cont.

Spring 2011 Prof. Hyesoon Kim

Xinying Wang, Cong Xu CS 423 Project

TivaWare Utilities Library

Transcription:

Kernel Synchronization and Interrupt Handling Oliver Sengpie, Jan van Esdonk Arbeitsbereich Wissenschaftliches Rechnen Fachbereich Informatik Fakultt fr Mathematik, Informatik und Naturwissenschaften Universitt Hamburg 2015-01-14 1 / 36

Table of Contents 1 Timers 2 Interrupts 3 Bottom Halves 4 Kernel synchronization 2 / 36

The timers Real time clock (RTC) Time stamp counter (TSC) Programmable interval timer (PIT) CPU Local timer (APIC) High precision timer (HPET) ACPI Power Management timer 3 / 36

Why do we need Interrupts? Getting information from hardware when it s needed (Hardware Interrupts) Processing data when it s needed (Software Interrupts) One solution would be polling Overhead through unnecessary checks Better solution: Interrupts Work is only done when needed 4 / 36

What is an Hardware Interrupt? Electrical signal, asynchronously emitted by a hardware device Each device is mapped to an Interrupt-Request-Line Processed by an Interrupt Controller Forces the CPU to handle the interrupt 5 / 36

Dealing with Hardware Interrupts Kernel gets interrupted by the CPU Each IRQ Line has Interrupt Handlers C function Implements a specific function prototype Executed in its own context (Interrupt Context) 6 / 36

Writing your own Interrupt Handler Function prototype: static irqreturn_t intr_handler(int irq, void *dev_id, struct pt_regs *regs) Registering the Handler at the IRQ: int request_irq(unsigned int irq, irqreturn_t (*handler)(int, void *, struct pt_regs *), unsigned long irqflags, const char *devname, void *dev_id) 7 / 36

Kinds of Interrupt Handlers SA_INTERRUPT Short execution time Not interruptable SA_SAMPLE_RANDOM Source for Kernel Entropy Pool SA_SHIRQ Multiple Handlers possible Handler detects which device emitted the interrupt Every registered handler is checked for the emitting device 8 / 36

Interrupt Context Not associated to any process Running process gets dumped to kernel memory No ability to sleep Its own stack (1 page) Simple rules: Be quick and short Only use the stack if absolutely necessary 9 / 36

Managing Interrupts Enabling/Disabling Interrupts local irq enable() / local irq disable() Disabling specific Interrupts disable irq(unsigned int irq) Status of Interrupts (Activation, Context) irqs disabled() in interrupt() / in irq() Interrupt statistics /proc/interrupts 10 / 36

Overview of Interrupt Handling Figure: Source: Robert Love: Linux Kernel Development 3rd Edition 11 / 36

Why do we need Bottom Halves Interrupt Handlers need to be finished fast All processes on the CPU are blocked by Interrupts Only used for time critical tasks and arrival confirmations Bottom Halves are used for data processing Interrupts are enabled while executing a BH 12 / 36

Types of Bottom Halves Deprecated types BH-Interface Task Queues softirq Tasklets Work-Queues 13 / 36

softirqs Statically allocated at compile time Maximum of 32 softirqs implemented as a structure Points to a function to run softirq handler gets a pointer to the structure void softirq_handler(struct softirq_action *) Needs to be marked for execution in a bitmask Gets executed by a looper over the softirq vec array 14 / 36

Usage of softirqs 1 Assigning a priority index 2 Registering the handler open_softirq() 3 Marking it for execution raise_softirq() Handler gets executed by the next do softirq() run 15 / 36

Tasklets based on softirqs implemented as tasklet struct State field manages its execution status Organized in a linked list Tasklet structures Gets executed in the do softirq() cycle 16 / 36

Writing your own Tasklet 1 Declare the Tasklet statically: DECLARE_TASKLET(name, func, data) dynamically: tasklet_init(t, tasklet_handler, dev) 2 Implement a Tasklet-Handler function prototype: void tasklet_handler(unsigned long data) 3 Schedule the Tasklet tasklet_schedule(&your_tasklet) 17 / 36

Work Queues Executed by their own kernel thread Executed in process context Organized in linked list of work queues structures 18 / 36

Usage of Work Queues 1 Declare Work Queue at runtime statically: DECLARE_WORK(name, void (*func)(void *), void *data) dynamically: INIT_WORK(struct work_struct *work, void (*func)(void *) void *data) 2 Implement Handler void work_handler(void *data) 3 Schedule the Work Queue schedule_work(&work) 19 / 36

Which BH should I choose? softirq High priority operations Short execution time Thread safe Tasklet Short execution time Doesn t need to be thread safe Work Queues Big operations (i/o) Doesn t need to be thread safe 20 / 36

What are synchronization mechanisms? Functions and structures provided by the kernel Prohibit race conditions in shared memory 21 / 36

Why are these mechanisms necessary? The kernel is not running serially Most kernels use preemption Multicore processor systems Kernel control paths are interleaving 22 / 36

Synchronization primitives There are a few elementary mechanisms to synchronize programs: Per-CPU variables Local interrupt disabling Local softirq disabling Optimization and memory barriers Atomic operations Spin locks Semaphores and completions Seqlocks Read-copy-update (RCU) 23 / 36

Where are them not needed Before we take a closer look at the mechanisms: There are cases in which no synchronization mechanisms are needed. 24 / 36

Where are them not needed Interrupts Interrupts disable their IRQ-lines, cannot be nested or be interleaved by deferrable functions and are nonblocking and nonpreemptable. Softirqs and tasklets They cannot be interleaved on their CPU and are nonblocking and nonpreemptable Unique structures in Tasklets They need no synchronization, because they can only be executed with one instance on all CPUs. 25 / 36

Single core 26 / 36

Per-CPU variables Simplest way to make sure no other CPU can corrupt the memory. With Interrupthandlers, Softirqs and Tasklets race condition secure. 27 / 36

Interrupt and softirq disabling Can be used to make interrupt handlers thread secure. 28 / 36

Optimization and memory barriers Instructions which affect the compiler. They avoid optimization and reorganization of the instructions in the compiler. Optimization barriers assure that the assambly instructions remain in the same order and memory barriers ensure that the instructions before the barrier are finished when the barrier is reached. 29 / 36

Multiple cores 30 / 36

Atomic operations Atomic operations appear to be instantanious to the hardware. 31 / 36

Spin locks Make sure that readers and writers don t get into conflicts accessing a ressource. There are different types of spin locks: simple spin locks (every action is equal) read write spin locks The waiting processes spin, i.e. they execute a tiny instruction loop to check whether the lock has yet been released. 32 / 36

Semaphores and completions Waiting processes are put to sleep and awakened, when they are at the first place of the wait queue and the lock is free. 33 / 36

Seqlocks Like Spinlock but with priviliges to the writers. The readers have to check after the reading if the data they read is valid. 34 / 36

RCU Use of pointer - and thus only available for data on the heap. 35 / 36

The Big Kernel Lock Forces the processor to allow only one process in kernel space. 36 / 36