Kernel Interrupt: A Major Overhaul

Similar documents
EE458 - Embedded Systems Exceptions and Interrupts

CS 550 Operating Systems Spring Interrupt

Hardware OS & OS- Application interface

Today: Computer System Overview (Stallings, chapter ) Next: Operating System Overview (Stallings, chapter ,

Dan Noé University of New Hampshire / VeloBit

ELC4438: Embedded System Design ARM Cortex-M Architecture II

KVM/ARM. Marc Zyngier LPC 12

Xen VT status and TODO lists for Xen-summit. Arun Sharma, Asit Mallick, Jun Nakajima, Sunil Saxena

SMP bring up on ARM SoCs

AUTOBEST: A United AUTOSAR-OS And ARINC 653 Kernel. Alexander Züpke, Marc Bommert, Daniel Lohmann

INTERRUPTS in microprocessor systems

Interrupts Peter Rounce

2006/7/22. NTT Data Intellilink Corporation Fernando Luis Vázquez Cao. Copyright(C)2006 NTT Data Intellilink Corporation

Linux - Not real-time!

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 09, SPRING 2013

Part I Introduction Hardware and OS Review

Linux Kernel Hacking Free Course

Real Safe Times in the Jailhouse Hypervisor Unrestricted Siemens AG All rights reserved

Introduction to Operating. Chapter Chapter

Interrupts Peter Rounce - room 6.18

Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras

THE PROCESS ABSTRACTION. CS124 Operating Systems Winter , Lecture 7

Grundlagen Microcontroller Interrupts. Günther Gridling Bettina Weiss

Introduction to Operating Systems. Chapter Chapter

For more notes of DAE

CSC227: Operating Systems Fall Chapter 1 INTERRUPTS. Dr. Soha S. Zaghloul

Interconnecting Components

CS 326: Operating Systems. CPU Scheduling. Lecture 6

Concurrent programming: Introduction I

Boot Interrupt Quirks and (RealTime) Interrupt Handling on x86. Olaf Dabrunz, Stefan Assmann

SysGauge SYSTEM MONITOR. User Manual. Version 3.8. Oct Flexense Ltd.

The control of I/O devices is a major concern for OS designers

Homework / Exam. Return and Review Exam #1 Reading. Machine Projects. Labs. S&S Extracts , PIC Data Sheet. Start on mp3 (Due Class 19)

3. Process Management in xv6

ARM Interrupt Virtualization. Andre Przywara

Windows Interrupts

18-349: Introduction to Embedded Real-Time Systems

Programming Embedded Systems

Operating Systems Overview. Chapter 2

Lecture 4: Mechanism of process execution. Mythili Vutukuru IIT Bombay

Process Scheduling Queues

Operating Systems Course 2 nd semester 2016/2017 Chapter 1: Introduction

Interrupts and Time. Real-Time Systems, Lecture 5. Martina Maggio 28 January Lund University, Department of Automatic Control

MODERN OPERATING SYSTEMS. Chapter 3 Memory Management

Interrupt Swizzling Solution for Intel 5000 Chipset Series based Platforms

Interrupts and Time. Interrupts. Content. Real-Time Systems, Lecture 5. External Communication. Interrupts. Interrupts

Chapter 1 Computer System Overview

Frequently Asked Questions about Real-Time

Rebootless Kernel Updates

Lecture 3: Processes. CMPUT 379, Section A1, Winter 2014 January 13, 15 and 17

PROCESS SCHEDULING II. CS124 Operating Systems Fall , Lecture 13

Interrupt/Timer/DMA 1

CS370 Operating Systems

PCI Interrupts for x86 Machines under FreeBSD

Lecture 17: Threads and Scheduling. Thursday, 05 Nov 2009

19: I/O Devices: Clocks, Power Management

ARM Cortex-M and RTOSs Are Meant for Each Other

Computer Labs: I/O and Interrupts

OPERATING SYSTEMS & UTILITY PROGRAMS

Process Description and Control. Chapter 3

CSC 553 Operating Systems

Back To The Future: A Radical Insecure Design of KVM on ARM

Porting Linux to a new SoC

ECE 598 Advanced Operating Systems Lecture 8

Introduction to Operating Systems. Chapter Chapter

CSCE Operating Systems Interrupts, Exceptions, and Signals. Qiang Zeng, Ph.D. Fall 2018

Enhancing Linux Scheduler Scalability

AN316 Determining the stack usage of applications

Abstract. Testing Parameters. Introduction. Hardware Platform. Native System

W4118: interrupt and system call. Junfeng Yang

Virtual Memory. 1 Administrivia. Tom Kelliher, CS 240. May. 1, Announcements. Homework, toolboxes due Friday. Assignment.

Mobile Operating Systems Lesson 01 Operating System

s132_nrf52 release notes

Systems Programming and Computer Architecture ( ) Timothy Roscoe

Live Patching: The long road from Kernel to User Space. João Moreira Toolchain Engineer - SUSE Labs

LotOS Framework. Getting Started Guide for Banana Pi. Copyright (C) 2015 ilbers GmbH Revision 1.1,

[08] IO SUBSYSTEM 1. 1

Xen on ARM ARMv7 with virtualization extensions

By the end of Class. Outline. Homework 5. C8051F020 Block Diagram (pg 18) Pseudo-code for Lab 1-2 due as part of prelab

The K Project. Interrupt and Exception Handling. LSE Team. May 14, 2018 EPITA. The K Project. LSE Team. Introduction. Interrupt Descriptor Table

by I.-C. Lin, Dept. CS, NCTU. Textbook: Operating System Concepts 8ed CHAPTER 13: I/O SYSTEMS

Scheduling - Overview

8th Slide Set Operating Systems

ECE 598 Advanced Operating Systems Lecture 8

Lecture Topics. Announcements. Today: Uniprocessor Scheduling (Stallings, chapter ) Next: Advanced Scheduling (Stallings, chapter

Measuring the impacts of the Preempt-RT patch

COEN-4720 Embedded Systems Design Lecture 4 Interrupts (Part 1) Cristinel Ababei Dept. of Electrical and Computer Engineering Marquette University

CS370 Operating Systems

Announcement. Exercise #2 will be out today. Due date is next Monday

Types of Interrupts:

Achieve Low Latency NFV with Openstack*

PCI Bus & Interrupts

OS Structure. Hardware protection & privilege levels Control transfer to and from the operating system

Unit 1. Chapter 3 Top Level View of Computer Function and Interconnection

Operating Systems: Internals and Design Principles, 7/E William Stallings. Chapter 1 Computer System Overview

Operating Systems. Introduction & Overview. Outline for today s lecture. Administrivia. ITS 225: Operating Systems. Lecture 1

CS330: Operating System and Lab. (Spring 2006) I/O Systems

Barrelfish Project ETH Zurich. HPET Driver Report By: Rana Afifi. Supervised by: Lukas Humbel, Roni Hacki and Timothy Roscoe

Embedded Systems Design (630414) Lecture 1 Introduction to Embedded Systems Prof. Kasim M. Al-Aubidy Computer Eng. Dept.

NAME: KEY (FIRST NAME FIRST) TOTAL:

Transcription:

Kernel Interrupt: A Major Overhaul - APIC Initialization & - Vector Allocation Dou Liyang douly.fnst@cn.fujitsu.com June 20 2018 Copyright 2018 FUJITSU LIMITED

Outline Basics of an interrupt What's next? Overhaul of interrupt APIC Initialization Vector Allocation Future work 2 Copyright 2018 FUJITSU LIMITED

What is An Interrupt? A hardware signal Emitted from a peripheral to a CPU Indicating that a device-specific condition has been satisfied device CPU From Marc Zyngier <marc.zyngier@arm.com> 3 Copyright 2018 FUJITSU LIMITED

Multiplexing Interrupts Having a single interrupt for the CPU is usually not enough Most systems have tens, hundreds of them An interrupt controller allows them to be multiplexed Very often architecture or platform specific In old x86 machine, there was a PIC called 8259A a chip responsible for sequentially processing multiple interrupt requests from multiple devices Called PIC Mode device device PIC CPU 4 Copyright 2018 FUJITSU LIMITED

Multiplexing Interrupts in SMP System Only a CPU is usually not enough Most systems have tens, hundreds of CPUs An new interrupt controller should be used In x86 machine, there is an APIC Local APIC is located on each CPU core, handles the CPU-specific interrupt configuration I/O APIC distribute external interrupts from multiple devices to multiple CPU cores device Local APIC CPU Symmetric I/O Mode device I/O APIC Local APIC CPU 5 Copyright 2018 FUJITSU LIMITED

More than wired interrupts: MSIs Message Signaled Interrupts are as an alternative to line-based interrupts Trigger an interrupt by writing a value to a particular memory Allow the use of the same buses as the data device CPU device MSI Capabilities CPU device CPU 6 Copyright 2018 FUJITSU LIMITED

Handle an Interrupt Preempt current task 1 2 Pause execution of the current process. Execute interrupt handler Search for the handler of the interrupt and transfer control Resume the task 6 3 ~ 5 Return to execute the current process CPU 3 1 2 6 Current Task 5 Has an Interrupt 4 Interrupt Handler 7 Copyright 2018 FUJITSU LIMITED

How Does Handle an Interrupt Work? APIC and Vector mechanism make it work 1. Delivery the IRQ through the APIC 2. CPU search the handler in IDT through the vector 3. Get the irq_desc structure through the vector. 4. Use the irq_desc to get what the interrupt needs device info interrupt controller info IRQ action list info 5. Execute the interrupt service routine (ISR) 4 1 2 3 Interrupt APIC Vector Irq_desc Device Chip Domain Action 5 ISR 8 Copyright 2018 FUJITSU LIMITED

Why APIC and Vector Can Work? Do many initialization and setup works when Linux boots up For the interrupt delivery Initialize 8259A Switch interrupt delivery mode Initialize APIC Set Local APIC & I/O APIC For IDT table Initialize the mapping of Vector and Handler For each Interrupt Allocate an IRQ Allocate an irq_desc Assign a vector Device Interrupt Context Interrupt handler CPU Normal Context 9 Copyright 2018 FUJITSU LIMITED

Outline Basics of an interrupt What's next? Overhaul of interrupt APIC Initialization Vector Allocation Future work 10 Copyright 2018 FUJITSU LIMITED

Existing Problems Interrupt in x86 is a conglomerate of ancient bits and pieces Subject to 'modernization' and features over the years Kdump CPU Hotplug/System hibernation Multi-queue devices It looks like a penguin full of band-aids Can work, but can t see how it works easily. 11 Copyright 2018 FUJITSU LIMITED

Problems of APIC Initialization Horrible interrupt mode setup Setup the mode at random places Run the kernel with the potentially wrong mode Tangle the timer setup with interrupt initialization PIC Mode Virtual Wire Mode Timer Symmetric I/O Mode 12 Copyright 2018 FUJITSU LIMITED

Overhaul of APIC Initialization Kconfig CONFIG_X86_64 CONFIG_X86_LOCAL_APIC CONFIG_x86_IO_APIC CONFIG_SMP CPU Capability boot_cpu_has(x86_feature_apic) 1. Unify the APIC and interrupt mode setup Construct a selector for the interrupt delivery mode PIC Mode MP table smp_found_config ACPI table acpi_lapic acpi_ioapic nr_ioapic Command line options disable_apic skip_ioapic_setup nolapic/noapic/ apic= Selector Virtual Wire Mode Symmetric I/O Mode 13 Copyright 2018 FUJITSU LIMITED

Overhaul of APIC Initialization 1. Unify the APIC and interrupt mode setup Provide a single function init_bsp_apic( ) Finished at once native_smp_prepare_cpus( ) apic_intr_mode_init( ) smp_init( ) 14 Copyright 2018 FUJITSU LIMITED

Overhaul of APIC Initialization 2. Disentangle the timer setup from the APIC initialization Refactor the delay logic during APIC initialization process. Either use TSC or a simple delay loop to make a rough delay estimate mdelay(10) 400000000000/HZ TSC cycles 40940000000000/HZ TSC cycles Split local APIC timer setup from the APIC setup 15 Copyright 2018 FUJITSU LIMITED

Overhaul of APIC Initialization 3. Reorganize the interrupt initialization Set up the final interrupt delivery mode as soon as possible. 1) Set up the legacy timer(pit/hpet) x86_init.timers.timer_init( ) 2) Set up APIC/IOAPIC x86_init.irqs.intr_mode_init( ) 3) TSC calibration tsc_init( ) 4) Local APIC timer setup x86_init.timers.setup_percpu_clockev() 16 Copyright 2018 FUJITSU LIMITED

Overhaul of APIC Initialization 4. Some others Refactor some common APIC function Compatible with ACPI initialization Bypass the hypervisor, Such as KVM and Xen 5. Can check which mode the interrupt is by dmesg : 17 Copyright 2018 FUJITSU LIMITED

Outline Basics of an interrupt What's next? Overhaul of interrupt APIC Initialization Vector Allocation Future work 18 Copyright 2018 FUJITSU LIMITED

Problems of Vector Allocation Horrible worst vector management mechanism Abuse the interrupt allocation for different type interrupts Serve all different use cases in one go Based on nested loops to search Cause vector space exhaustion Allocate vectors at the wrong time and on the wrong place Some dubious properties, causes high complexity Multi CPU affinities for an IRQ Priority level spreading Lack of instrumentation Can work? All of this is a black box which allows no insight into the actual vector usage 19 Copyright 2018 FUJITSU LIMITED

Overhaul of Vector Allocation 1. Classify the types of vectors 2. Refactor the vector allocation mechanism 3. Switch to a reservation scheme Initilization An Vector ID 3. Reservation Scheme Request IRQ ny functions which request an vector activation IRQ enabled IRQ startup 1. Vector Classifier 2. Vector Allocator 20 Copyright 2018 FUJITSU LIMITED

Overhaul of Vector Allocation 1. Classify the types of vectors Each CPU has 256 vectors, But some are fixed 1. System Vector * Vectors 0... 31 Classifier * Vector 128 * Vectors INVALIDATE_TLB_VECTOR_START... 255 2. Legacy Vector * Vectors 0x30... 0x3f Others are allocated dynamically for normal and managed interrupts. 21 Copyright 2018 FUJITSU LIMITED

Overhaul of Vector Allocation 1. Classify the types of vectors For external interrupts Depend on Interrupt Affinity(the set of CPUs that can handle this interrupt) 3. Normal Vector 4. Managed Vector Normal Interrupt Managed Interrupt At setup time - Affinity may be NULL - A subset of the online CPUs - Affinity must have been setup - the possible CPUs may be included User space - Affinity can be modified - Affinity is fixed When migration - IRQ can be moved to any online CPUs - Affinity can be even reset - IRQ can move only in the affinity. - But, can be shutdown and restarted. - Affinity can t be reset 22 Copyright 2018 FUJITSU LIMITED

Overhaul of Vector Allocation 2. Refactor the vector allocation mechanism Create a new bitmap matrix allocator IRQ Matrix Allocator Global system Global Counters available allocated system bitmap 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 CPU 0 Percpu CPU 1 Percpu CPU n Percpu Percpu Local Counters available allocated managed allocated bitmap 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 managed bitmap 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 23 Copyright 2018 FUJITSU LIMITED

Overhaul of Vector Allocation 2. Refactor the vector allocation mechanism Use the matrix for System vector Global system Global Counters available allocated system bitmap 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 CPU 0 Percpu CPU 1 Percpu CPU n Percpu Percpu Local Counters available allocated managed allocated bitmap 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 managed bitmap 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 24 Copyright 2018 FUJITSU LIMITED

Overhaul of Vector Allocation 2. Refactor the vector allocation mechanism Use the matrix for Legacy vector Global system Global Counters available allocated system bitmap 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 CPU 0 Percpu CPU 1 Percpu CPU n Percpu Percpu Local Counters available allocated managed allocated bitmap 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 managed bitmap 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 25 Copyright 2018 FUJITSU LIMITED

Overhaul of Vector Allocation 2. Refactor the vector allocation mechanism Use the matrix for Normal vector Global system Global Counters available allocated system bitmap 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 CPU 0 Percpu CPU 1 Percpu Step 1 CPU n Percpu Percpu Local Counters available allocated managed allocated bitmap 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 Step 2 managed bitmap 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 26 Copyright 2018 FUJITSU LIMITED

Overhaul of Vector Allocation 2. Refactor the vector allocation mechanism Use the matrix for Managed vector Global system Global Counters available allocated system bitmap 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 CPU 0 Percpu CPU 1 Percpu Step 1 CPU n Percpu Percpu Local Counters available allocated managed allocated bitmap 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 Step 3 managed bitmap 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 1 1 1 0 0 0 Step 2 27 Copyright 2018 FUJITSU LIMITED

Overhaul of Vector Allocation 3. Switch to reservation scheme Reserve a new system vector, just in case Reservation 3.1 When the interrupt is allocated and initialized: Now Previously wasteful 1. Update the reservation request counter Assign a real vector for each interrupts 2. Assign the reserved vector for each interrupts 28 Copyright 2018 FUJITSU LIMITED

Overhaul of Vector Allocation 3. Switch to reservation scheme Separate activation and startup Assign the real vector 3.2 When the interrupt is requested: Startup Activate Fail? Can fail Vector Space Activate Saving Assign a real vector for normal interrupts Continue Startup Assign a real vector for managed interrupts Continue 29 Copyright 2018 FUJITSU LIMITED

Overhaul of Vector Allocation Some Others: Change from Multi CPU targets to single interrupt targets. Remove priority level spreading Simplify hotplug vector accounting Equip with trace points and detailed debugfs information Can see the Vector Allocation by: cat /sys/kernel/debug/irq/irqs/$n cat /sys/kernel/debug/irq/domains/$n 30 Copyright 2018 FUJITSU LIMITED

Outline Basics of an interrupt What's next? Overhaul of interrupt APIC Initialization Vector Allocation Future work 31 Copyright 2018 FUJITSU LIMITED

Future work Kernel's notion of possible CPU count should be realistic Once the kernel initialized: Make the possible CPU count realistic The vector allocation is a generic mechanism Can be used to other architectures 32 Copyright 2018 FUJITSU LIMITED

Thank you! 33 Copyright 2018 FUJITSU LIMITED