Fast Interrupts. Krste Asanovic, UC Berkeley / SiFive Inc. (Chair) Kevin Chen, Andes (Vice-Chair)

Similar documents
COMP 303 Computer Architecture Lecture 3. Comp 303 Computer Architecture

Subroutines. int main() { int i, j; i = 5; j = celtokel(i); i = j; return 0;}

Lecture 5: Procedure Calls

ECE232: Hardware Organization and Design

LECTURE 19. Subroutines and Parameter Passing

SPIM Procedure Calls

Operating Systems: Virtual Machines & Exceptions

SiFive U54 Core Complex Manual v1p1. SiFive, Inc.

SiFive E24 Core Complex Manual v1p0. SiFive, Inc.

Chapter 2. Computer Abstractions and Technology. Lesson 4: MIPS (cont )

CS64 Week 5 Lecture 1. Kyle Dewey

Lecture 5: Procedure Calls

SiFive E31 Core Complex Manual v2p0. SiFive, Inc.

Control Instructions. Computer Organization Architectures for Embedded Computing. Thursday, 26 September Summary

Threads and Concurrency

Branch Addressing. Jump Addressing. Target Addressing Example. The University of Adelaide, School of Computer Science 28 September 2015

Operating Systems and Interrupts/Exceptions

Control Instructions

Instruction Set Architectures (4)

CSCI 402: Computer Architectures. Instructions: Language of the Computer (3) Fengguang Song Department of Computer & Information Science IUPUI.

Threads and Concurrency

MIPS Programming. A basic rule is: try to be mechanical (that is, don't be "tricky") when you translate high-level code into assembler code.

CSE Lecture In Class Example Handout

Lecture 5. Announcements: Today: Finish up functions in MIPS

ECE331: Hardware Organization and Design

Examples of IO, Interrupts, and Exceptions

Functions in MIPS. Functions in MIPS 1

SiFive E31 Core Complex Manual v1p2. c SiFive, Inc.

ECE260: Fundamentals of Computer Engineering

Lectures 5. Announcements: Today: Oops in Strings/pointers (example from last time) Functions in MIPS

Chapter 2. Instructions: Language of the Computer. Adapted by Paulo Lopes

comp 180 Lecture 10 Outline of Lecture Procedure calls Saving and restoring registers Summary of MIPS instructions

EN164: Design of Computing Systems Lecture 11: Processor / ISA 4

Course Administration

Procedures and Stacks

Compiling Code, Procedures and Stacks

Memory Usage 0x7fffffff. stack. dynamic data. static data 0x Code Reserved 0x x A software convention

Review: Program Execution. Memory program code program data program stack containing procedure activation records

CENG3420 Computer Organization and Design Lab 1-2: System calls and recursions

MIPS Functions and Instruction Formats

Today. Putting it all together

CA Compiler Construction

Review of Activation Frames. FP of caller Y X Return value A B C

EE 361 University of Hawaii Fall

Review: Program Execution. Memory program code program data program stack containing procedure activation records

Thomas Polzer Institut für Technische Informatik

RISC-V Core IP Products

CS 61c: Great Ideas in Computer Architecture

Common Problems on Homework

Procedure Calling. Procedure Calling. Register Usage. 25 September CSE2021 Computer Organization

ECE260: Fundamentals of Computer Engineering. Supporting Procedures in Computer Hardware

MIPS R-format Instructions. Representing Instructions. Hexadecimal. R-format Example. MIPS I-format Example. MIPS I-format Instructions

Lectures 3-4: MIPS instructions

Implementing Procedure Calls

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

Machine Instructions - II. Hwansoo Han

CS61C : Machine Structures

Procedure Calls Main Procedure. MIPS Calling Convention. MIPS-specific info. Procedure Calls. MIPS-specific info who cares? Chapter 2.7 Appendix A.

Functions and Procedures

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

EE 109 Unit 15 Subroutines and Stacks

Code Generation. The Main Idea of Today s Lecture. We can emit stack-machine-style code for expressions via recursion. Lecture Outline.

Do-While Example. In C++ In assembly language. do { z--; while (a == b); z = b; loop: addi $s2, $s2, -1 beq $s0, $s1, loop or $s2, $s1, $zero

Assembly labs start this week. Don t forget to submit your code at the end of your lab section. Download MARS4_5.jar to your lab PC or laptop.

We can emit stack-machine-style code for expressions via recursion

Review: Program Execution. Memory program code program data program stack containing procedure activation records

CSC258: Computer Organization. Microarchitecture

Review: Program Execution. Memory program code program data program stack containing procedure activation records

Review: Program Execution. Memory program code program data program stack containing procedure activiation records

ECE 30 Introduction to Computer Engineering

ELEC / Computer Architecture and Design Fall 2013 Instruction Set Architecture (Chapter 2)

Procedure Call and Return Procedure call

Contents. Slide Set 2. Outline of Slide Set 2. More about Pseudoinstructions. Avoid using pseudoinstructions in ENCM 369 labs

MIPS ISA and MIPS Assembly. CS301 Prof. Szajda

Overview. Introduction to the MIPS ISA. MIPS ISA Overview. Overview (2)

MIPS Functions and the Runtime Stack

CS3350B Computer Architecture MIPS Procedures and Compilation

Storage in Programs. largest. address. address

Function Calls. 1 Administrivia. Tom Kelliher, CS 240. Feb. 13, Announcements. Collect homework. Assignment. Read

Lecture 11: Interrupt and Exception. James C. Hoe Department of ECE Carnegie Mellon University

CS 316: Procedure Calls/Pipelining

ECE 30 Introduction to Computer Engineering

Calling Conventions. Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University. See P&H 2.8 and 2.12

Computer Architecture. Chapter 2-2. Instructions: Language of the Computer

CS 61C: Great Ideas in Computer Architecture Strings and Func.ons. Anything can be represented as a number, i.e., data or instruc\ons

MIPS Assembly (Functions)

COE608: Computer Organization and Architecture

Lecture 6: Assembly Programs

2/16/2018. Procedures, the basic idea. MIPS Procedure convention. Example: compute multiplication. Re-write it as a MIPS procedure

Quiz for Chapter 2 Instructions: Language of the Computer3.10

MIPS Assembly (FuncDons)

Prof. Kavita Bala and Prof. Hakim Weatherspoon CS 3410, Spring 2014 Computer Science Cornell University. See P&H 2.8 and 2.12, and A.

Chapter 2A Instructions: Language of the Computer

Function Calls. Tom Kelliher, CS 220. Oct. 24, SPIM programs due Wednesday. Refer to homework handout for what to turn in, and how.

CS 61c: Great Ideas in Computer Architecture

Computer Organization MIPS Architecture. Department of Computer Science Missouri University of Science & Technology

5/17/2012. Recap from Last Time. CSE 2021: Computer Organization. The RISC Philosophy. Levels of Programming. Stored Program Computers

Architecture II. Computer Systems Laboratory Sungkyunkwan University

Recap from Last Time. CSE 2021: Computer Organization. Levels of Programming. The RISC Philosophy 5/19/2011

MIPS Instruction Set

Transcription:

Fast Interrupts Krste Asanovic, UC Berkeley / SiFive Inc. (Chair) Kevin Chen, Andes (Vice-Chair) 8 th RISC-V Workshop Barcelona Supercomputer Center, Barcelona, Spain May 9, 2018

RISC-V for Embedded Embedded is one of major uses for RISC-V Many different kinds of embedded system: - single microcontroller with 1KiB SRAM and simple I/O - 32 cores of dual-issue superscalar with L1/L2 caches, PCIe - 1024 cores with scratchpads, local I/O per core Desire for faster interrupt handling with support for nested preempted interrupts Task Group started XXXX Early days, only a few meetings so far please join!

Summary of Current RISC-V Interrupts Local Interrupts - Directly connected to one hart - No arbitration between harts to service - Determine source directly through xcause CSR - Only two standard local interrupts (software, timer) Global (External) Interrupts - Routed via Platform-Level Interrupt Controller (PLIC) - PLIC arbitrates between multiple harts claiming interrupt - Read of memory-mapped register returns source 3

External Interrupt 1 Current RISC-V Interrupt Overview External Interrupt 2 PLIC Global Interrupts External Hart 0 U S H M Hart 1 U S H M Local Interrupts Timer Software Timer Software Timer Software Timer Software Timer Software Timer Software Timer Software Timer Software 4

Machine Interrupt Pending (mip) CSR (Add custom local interrupts here, bits 16 and up) External from PLIC Local Timer Local Software mip reflects pending status of interrupts for hart Separate interrupts for each supported privilege level (M/S/U) User-level interrupt handling ( N ) optional feature when U-mode present (discussed later) 5

Machine Interrupt Enable (mie) CSR External from PLIC Local Timer Local Software mie mirrors layout of mip provides per-interrupt enables 6

Interrupts in mstatus Privilege stack Enable stack Per-privilege global interrupt enables Only take a pending interrupt for privilege mode x if xie=1 and running in mode x or greater Interrupts always disabled for privileges less than current level 7

Interrupt reported in mcause CSR High bit of mcause is 1 Exception code gives interrupt cause Might have to interrogate PLIC also, if external interrupt 8

Machine trap-vector base (mtvec) CSR Two modes: Direct- all exceptions and interrupts jump to base Vectored exceptions to base, interrupts vectored 9

Vectored Interrupts (mtvec mode=1) Exceptions jump to: BASE Interrupts jump to: BASE+ExcCode*4 12-15 reserved 16+ for custom local interrupts Interrupts disabled at entry to handler, i.e., mstatus.mie=0 10

Saving/Restoring Interrupted Context mepc holds PC of interrupted instruction mstatus.mpp[1:0] in mstatus holds privilege mode of interrupted instruction mstatus.mpie holds interrupt enable of interrupted instruction Restored at end of handler by an mret 11

Problems with Current Interrupts Only hardware preemption is via privileged modes - Each privilege mode has independent hardware xepc and xpp/xie to save interrupted context Fixed priority for local interrupts, but fast vectoring Vector table holds jump instructions, can only jump +/- 1MiB. - Need free register to jump further, more instructions/vector entry PLIC has variable priority, but no vectoring PLIC need two memory accesses to claim/complete Unix ABI requires many registers to be saved/restored 12

Input from Multiple Proposals Andes enhanced PLIC - adds stacked preemptive servicing and vectoring to PLIC Syntacore - Restructure existing *IP/*IDELEG to provide faster interrupts on one core reusing existing local interrupt vectoring scheme, preemption via privilege mode Seagate - Add PLIC-based vectoring Liviu Ionescu - Multiple interrupt levels, vector table holds C-function addresses, hardware stacking with new embedded ABI SiFive - Multiple nested levels/priv mode, plus accelerated software save/restore 13

Interrupt Handler Interfaces Regular C function: - Interrupt hardware or software trampoline has to save/restore all caller-save registers Inline handler: - Use gcc interrupt attribute to convert function to always callee-save every register (save as you go). Opinion: Both are needed. C provides convenient interface, but even with hardware support adds unnecessary overhead for short handlers. 14

Inline interrupt Example void attribute ((interrupt)) foo2 (void) { extern volatile int INTERRUPT_FLAG; INTERRUPT_FLAG = 0; extern volatile int COUNTER; #ifdef riscv_atomic atomic_fetch_add (&COUNTER, 1, ATOMIC_RELAXED); #else COUNTER++; #endif } foo2: addi sp, sp, -FRAMESIZE # Create a frame on stack. sw s0, offset(sp) # Save working register. sw x0, INTERRUPT_FLAG, s0 # Clear interrupt flag. sw s1, offset(sp) # Save working register. la s0, COUNTER # Get counter address. li s1, 1 amoadd.w x0, (s0), s1 # Increment counter in memory lw s1, offset(sp) # Restore registers. lw s0, offset(sp) addi sp, sp, FRAMESIZE # Free stack frame. mret 15

Unix C ABI has high context switch cost The current RISC-V ABI requires (ignoring floating-point registers): addi sp, sp, -FRAMESIZE sw ra, x(sp) # 1 return address sw t0-t6, x(sp) # 7 temporaries sw a0-a7, x(sp) # 8 arguments jal c_handler lw a0-a7, x(sp) # 8 arguments lw t0-t6, x(sp) # 7 temporaries lw ra, x(sp) # 1 return address addi sp, sp, FRAMESIZE mret or 36 instructions for each interrupt vector. Not including floating-point. Putting save/restore in hardware won t help much, need new ABI. 16

Vectoring Options Current PC jump constrains range Put function pointers in table (Seagate,Andes,Liviu) - Hardware has to fetch pointer and jump to it Add new +/- 2GiB offset instruction only visible in new interrupt ISA mode (SiFive) - Looks like single regular instruction to pipeline - Entry contains xxxxxxxxxxxx011, 32-bit instruction with new PC relative addressing mode Want vectoring for hardware save/restore or inline ISRs, but no vectoring for software trampoline 17

Interrupt Mode, Level, Priority Each interrupt is configured with: - Privilege mode: M/S/U where supported - Interrupt level: 1-N, N is number of preemption levels - Priority: is priority within a single preemption level (doesn t preempt but serviced in priority order) Various schemes to allow fixed number of bits to be allocated dynamically among these fields Single max reduction in interrupt controller picks highest privilege/level/priority to service next 18

Managing Preempted Context state Push/pop mepc/mpp/mil/mie to memory stack using hardware or software - Now need to remember previous interrupt level, mil, also Add additional mepc/mpp/mil/mie registers in hardware registers Pack mpp/mil/mie into mcause to simplify save/restore and reduce number of CSRs 19

Other issues Handling multiple privilege levels, security and stacks Quickly servicing remaining interrupts - Go from exit of one handler to entrance of another without restore/save again Supporting large numbers of MSI interrupts - Interaction with virtualization 20

Foundation Fast Int TG Work Meeting Thursday 3:30-4:30pm, Track 1 21