ECEN 449 Microprocessor System Design. Hardware-Software Communication. Texas A&M University

Similar documents
Real Time and Embedded Systems. by Dr. Lesley Shannon Course Website:

Hardware OS & OS- Application interface

Linux Device Drivers Interrupt Requests

I/O Handling. ECE 650 Systems Programming & Engineering Duke University, Spring Based on Operating Systems Concepts, Silberschatz Chapter 13

CS 134. Operating Systems. April 8, 2013 Lecture 20. Input/Output. Instructor: Neil Rhodes. Monday, April 7, 14

PCI Bus & Interrupts

Spring 2017 :: CSE 506. Device Programming. Nima Honarmand

Anne Bracy CS 3410 Computer Science Cornell University

ECE331: Hardware Organization and Design

CS 104 Computer Organization and Design

Last 2 Classes: Introduction to Operating Systems & C++ tutorial. Today: OS and Computer Architecture

I/O. Kevin Walsh CS 3410, Spring 2010 Computer Science Cornell University. See: P&H Chapter 6.5-6

Scuola Superiore Sant Anna. I/O subsystem. Giuseppe Lipari

Device I/O Programming

CS 5460/6460 Operating Systems

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

Module 11: I/O Systems

Protection and System Calls. Otto J. Anshus

Operating System: Chap13 I/O Systems. National Tsing-Hua University 2016, Fall Semester

Anne Bracy CS 3410 Computer Science Cornell University

CSE 120 Principles of Operating Systems

CSE 153 Design of Operating Systems

Operating Systems 2010/2011

CPSC 213. Introduction to Computer Systems. I/O Devices, Interrupts and DMA. Unit 2a Oct 27, 29, 31. Winter Session 2014, Term 1

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

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

ECE 391 Exam 1 Review Session - Spring Brought to you by HKN

Chap.6 Limited Direct Execution. Dongkun Shin, SKKU

CSE 120. Overview. July 27, Day 8 Input/Output. Instructor: Neil Rhodes. Hardware. Hardware. Hardware

CSE 120 Principles of Operating Systems

INPUT/OUTPUT ORGANIZATION

Comp 204: Computer Systems and Their Implementation. Lecture 18: Devices

ECE 353 Lab 3. (A) To gain further practice in writing C programs, this time of a more advanced nature than seen before.

These three counters can be programmed for either binary or BCD count.

Interconnecting Components

I/O Devices. Nima Honarmand (Based on slides by Prof. Andrea Arpaci-Dusseau)

Topic 2. System calls. 1. Basic architecture 2. Input/Output routine mechanism 3. Resident routines 4. Accessing OS services: system calls

CS 537 Lecture 2 Computer Architecture and Operating Systems. OS Tasks

CSE 120 Principles of Operating Systems

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

Background: Operating Systems

Lecture 2: Architectural Support for OSes

IMPLEMENTATION OF SIGNAL HANDLING. CS124 Operating Systems Fall , Lecture 15

19: I/O. Mark Handley. Direct Memory Access (DMA)

ECE232: Hardware Organization and Design

OS: An Overview. ICS332 Operating Systems

ECE 650 Systems Programming & Engineering. Spring 2018

CSE 153 Design of Operating Systems Fall 18

OPERATING SYSTEMS CS136

Input/Output Problems. External Devices. Input/Output Module. I/O Steps. I/O Module Function Computer Architecture

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

Applying User-level Drivers on

Devices. Today. Comp 104: Operating Systems Concepts. Operating System An Abstract View 05/01/2017. Devices. Devices

Computer System Overview OPERATING SYSTEM TOP-LEVEL COMPONENTS. Simplified view: Operating Systems. Slide 1. Slide /S2. Slide 2.

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

we are here Page 1 Recall: How do we Hide I/O Latency? I/O & Storage Layers Recall: C Low level I/O

CS 550 Operating Systems Spring Interrupt

Interrupts and Low Power Features

Virtual Machines & the OS Kernel

Review: Hardware user/kernel boundary

Lecture 3: O/S Organization. plan: O/S organization processes isolation

Process Context & Interrupts. New process can mess up information in old process. (i.e. what if they both use the same register?)

Last class: Today: Course administration OS definition, some history. Background on Computer Architecture

EEL 4744C: Microprocessor Applications. Lecture 7. Part 1. Interrupt. Dr. Tao Li 1

Reading Assignment. Interrupt. Interrupt. Interrupt. EEL 4744C: Microprocessor Applications. Lecture 7. Part 1

CSCI-GA Operating Systems I/O. Hubertus Franke

Syscalls, exceptions, and interrupts, oh my!

W4118: interrupt and system call. Junfeng Yang

I/O Management Intro. Chapter 5

UC Santa Barbara. Operating Systems. Christopher Kruegel Department of Computer Science UC Santa Barbara

Chapter 5 - Input / Output

[08] IO SUBSYSTEM 1. 1

Hakim Weatherspoon CS 3410 Computer Science Cornell University

INPUT/OUTPUT ORGANIZATION

3L Diamond. Multiprocessor DSP RTOS

I/O. Fall Tore Larsen. Including slides from Pål Halvorsen, Tore Larsen, Kai Li, and Andrew S. Tanenbaum)

I/O. Fall Tore Larsen. Including slides from Pål Halvorsen, Tore Larsen, Kai Li, and Andrew S. Tanenbaum)

INTERRUPTS in microprocessor systems

8086 Interrupts and Interrupt Responses:

The Kernel Abstraction

CS162 Operating Systems and Systems Programming Lecture 17. Disk Management and File Systems

INPUT/OUTPUT ORGANIZATION

Computer Organization ECE514. Chapter 5 Input/Output (9hrs)

EECS 373 Design of Microprocessor-Based Systems

Page 1, 5/4/99 8:22 PM

e-pg Pathshala Subject: Computer Science Paper: Embedded System Module: Interrupt Programming in Embedded C Module No: CS/ES/20 Quadrant 1 e-text

CPS104 Computer Organization and Programming Lecture 17: Interrupts and Exceptions. Interrupts Exceptions and Traps. Visualizing an Interrupt

Newbie s Guide to AVR Interrupts

Using kgdb and the kgdb Internals

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

I/O Devices. I/O Management Intro. Sample Data Rates. I/O Device Handling. Categories of I/O Devices (by usage)

THE CPU SPENDS ALMOST ALL of its time fetching instructions from memory

Emulation 2. G. Lettieri. 15 Oct. 2014

Introduction to Operating Systems. Device Drivers. John Franco. Dept. of Electrical Engineering and Computing Systems University of Cincinnati

ECE 485/585 Microprocessor System Design

SYSTEM CALL IMPLEMENTATION. CS124 Operating Systems Fall , Lecture 14

Introduction. CS3026 Operating Systems Lecture 01

Interrupts and System Calls

CS162 Operating Systems and Systems Programming Lecture 16. I/O Systems. Page 1

EE108B Lecture 17 I/O Buses and Interfacing to CPU. Christos Kozyrakis Stanford University

Transcription:

ECEN 449 Microprocessor System Design Hardware-Software Communication 1

Objectives of this Lecture Unit Learn basics of Hardware-Software communication Memory Mapped I/O Polling/Interrupts 2

Motivation Many reasons why we want hardware devices to interact with software programs Input: keyboards, mice, scanners Output: CRT, printer Interact with real world: contact sensor, chemical analyzer, MEMS devices Performance: ASIC/System-on-chip designs Exploit 90-10 rule of software by implementing critical parts of application in HW, non-critical as SW Issue: embedded apps getting more complex, less likely to have one module that consumes most of the execution time. 3

Hardware-Software Interfaces What features do we want? 4

Hardware-Software Interfaces What features do we want? Some way to get data between HW and SW components Some way for HW to notify SW of asynchronous events Flexibility Don t want to have to have special HW in CPU for each device Only load SW into memory for devices that are present Bandwidth Demands may vary wildly: compare keyboard to Gb Ethernet Security: Multiple users/processes may need to share HW 5

Getting Data to/from CPU: Hardware Side I/O Device Naïve Direct connection I/O Device Processor I/O Device I/O Device I/O Device Processor CS CS I/O Device I/O Device I/O Bus 6

The Software Side: Memory-Mapped I/O Operating System Address Space mmap() call I/O Device Memory and Control Registers 7

Memory-Mapped I/O Basic Idea Make control registers and I/O device memory appear to be part of the system s main memory Reads and writes to that region of the memory are translated by OS/hardware into accesses of hardware device Makes it easy to support variable numbers/types of devices just map them onto different regions of memory Managing new devices is now like memory allocation Example: accessing memory on a PCMCIA card Once card memory mapped into address space, just hand out pointers like conventional memory Accessing I/O device registers and memory can be done by accessing data structures via the device pointers Most device drivers are now written in C. Memory mapped I/O makes it possible without special changes to the compiler 8

Memory-Mapped I/O Important abstraction A given processor may have multiple busses/connections to devices Ex: PPC in Virtex-II Pro has OCM bus to talk to BlockRAM, PLB bus to talk to other hardware, but they look the same once you call mmap() Can interact a bit oddly with caches References to memory-mapped addresses may not go to the right bus if the address is cached Solution: declare any data structures that are memory-mapped I/O regions as volatile Ex: volatile int *region; Tells system that it can t keep the address in the cache 9

Handling Asynchronous Events Issue: External devices operate on different time signals than processor Humans don t have clock rates Want: Way to let processor handle events on external hardware that it can t predict Processor to be able to do other things while it s waiting for an event Fast response to events Low overhead (few wasted CPU cycles when no event happens) 10

Alternative 1: Polling Every so often, processor checks each device to see if it has a request Takes CPU time even if no requests pending Tradeoff between overhead and average response time How does software know when to let the system poll? 11

Alternative 2: Interrupts Give each device a wire (interrupt line) that it can use to signal the processor When interrupt signaled, processor executes a routine called an interrupt handler to deal with the interrupt No overhead when no requests pending Device Processor Interrupt Controller Device Device Device 12

Polling vs. Interrupts Polling is like picking up the phone every few seconds to see if you have a call. Interrupts are like waiting for the phone to ring Interrupts are better if the processor has other work to do and the time to respond to events isn t absolutely critical Polling can be better if the processor has nothing better to do and has to respond to an event ASAP Performance of interrupt hardware is a critical factor on processors for embedded systems. 13

So, What Happens When an Interrupt Occurs? Acts a lot like a context switch. Interrupt controller signals processor that interrupt has occurred, passes interrupt number Processor uses interrupt number to determine which handler to start interrupt vector associates handlers with interrupts Processor halts current program Multi-cycle operations may be halted or squashed and restarted Current program state saved (like context switch) Processor jumps to interrupt handler When interrupt done, program state reloaded and program resumes Interrupts are assigned priorities to handle simultaneous interrupts 14

Example: Interrupts on 80386EX 80386 core has one interrupt line, one interrupt acknowledge line Interrupt sequence: Interrupt controller raises INT line 80386 core pulses INTA line low, allowing INT to go low 80386 core pulses INTA line low again, signaling controller to put interrupt number on data bus INT: INTA: Data bus: Interrupt # 15

Using Interrupts in Linux OS handles interaction with interrupt hardware Necessary to support multiple processor types You need to worry about three things 1. Writing the interrupt handler 2. Registering the interrupt handler with the OS Tells the OS that it should run the handler when the interrupt occurs 3. Interaction between the interrupt handler and user programs Handlers need to be run in very little time Handlers run as part of the operating system Linux doesn t allow them to access user data One general approach: User program does the work, interrupt handler just signals it when it s time to do something 16

Interrupts in Linux, Part II Documentation on interrupts, etc. in Linux: http://www.xml.com/ldd/chapter/book/index.html Entire Linux Device Drivers book by Rubini and Corbet is available via the web, free distribution license Key chapters for this stuff: Chapter 5 (Blocking I/O) and Chapter 9 (Interrupts) 17

Writing an Interrupt Handler An interrupt handler is just a C procedure void int_handler(int irq, void *dev_id, struct pt_regs *regs) Must match this declaration Limits what data you can pass in to the handler Can t return any value No calling procedure to return value to Interrupt handlers have significant limits on what they can do Can t directly read or write data in user space (not associated with a process) Can t do anything involving scheduling new threads or sleeping Need to terminate quickly to free up interrupt hardware 18

Interrupt Handlers Most interrupt handlers follow a similar format: 1. Read/write data to/from the device that signaled the interrupt Ex: get character typed on a keyboard 2. Signal any processes that are waiting for the device to complete its operation 3. Signal the device that the interrupt has been handled Often called clearing the interrupt 19

Communicating With User Programs Problem: interrupts can t directly read/write data in a user program s space PowerPC FPGA Frame Displayer Interrupt Handler Interrupt Frame Grabber Video Frame 20

Two Approaches 1. Interrupt handler copies data from interrupting device, places it into a buffer that is mapped onto a /dev/foo entry that user program can then read Illustrated in book Not the approach we recommend buffer size/overrun issues 2. User program handles actual reading/writing of data to/from device. User program sleeps after each data transfer All the interrupt handler does is wake the user program up whenever the device is ready In this approach, the user program, not the interrupt handler, should clear the interrupt bit on the device, to prevent the device from overwriting data before the user program has read it. 21

Example: Frame Grabber/Displayer Frame Display code on IPAQ: While(1) { interruptible_sleep_on(&queue); /* sleep until interrupted */ } (Do PCMCIA reads to grab frame of data from XUP) (Do PCMCIA write that tells XUP that interrupt has been processed) (Do frame data munging and display) 22

Interrupt handler void int_handler(int irq, void *dev_id, struct pt_regs *regs) { wake_up_interruptible(&queue); /* Just wake up anything waiting for the device */ } Arguments to int_handler: irq: the number of the interrupt that caused the handler to be run One handler could be associated with multiple interrupts Somewhat provided for backwards-compatibility (UNIX, etc.) dev_id: Pointer to device data structure Current best way for one interrupt handler to handle multiple devices regs: Snapshot of the processor s register state before the processor jumped to the interrupt handler Rarely used, mostly for debugging 23

Registering an Interrupt Handler Once you ve written your handler, you have to let the OS know that the handler should be associated with a specific interrupt int request_irq(unsigned int irq, void (*handler)(int, void *, struct pt_regs *), unsigned long flags, const char *dev_name, void *dev_id); Declared in <linux/sched.h> 24

Inputs to request_irq flags: bit vector that gives details about the interrupt handler s behavior You ll want to use SA_INTERRUPT, which indicates that the interrupt handler is fast, and can t be interrupted by another interrupt irq: number of the interrupt that the handler should be associated with Needs to match the interrupt that the device will signal (duh!) Bad things happen if two devices/handlers use the same irq and don t expect it Can share interrupts if the devices and handlers know about it 25

Security and the Operating System Need to control access to hardware devices Approach: Instructions that directly manipulate hardware resources are privileged, can only be run by the kernel User programs make kernel calls to request that the OS access hardware, allows OS to set policies Note: being logged in as root is not the same thing as running in kernel mode Being root just means that the OS will almost never say no to your request 26