Hardware Support for Operating Systems Sunny Gleason Vivek Uppal COM S 414

Slides:



Advertisements
Similar presentations
Computer-System Structures Er.Harsimran Singh
Advertisements

Computer Architecture
Computer Architecture
1/1/ / faculty of Electrical Engineering eindhoven university of technology Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir.
I/O Unit.
Interrupts What is an interrupt? What does an interrupt do to the “flow of control” Interrupts used to overlap computation & I/O – Examples would be console.
Interrupts (contd..) Multiple I/O devices may be connected to the processor and the memory via a bus. Some or all of these devices may be capable of generating.
COMP3221: Microprocessors and Embedded Systems Lecture 15: Interrupts I Lecturer: Hui Wu Session 1, 2005.
Architectural Support for OS March 29, 2000 Instructor: Gary Kimura Slides courtesy of Hank Levy.
OS Fall ’ 02 Introduction Operating Systems Fall 2002.
Architectural Support for Operating Systems. Announcements Most office hours are finalized Assignments up every Wednesday, due next week CS 415 section.
OS Spring’03 Introduction Operating Systems Spring 2003.
Chapter 7 Interupts DMA Channels Context Switching.
Midterm Tuesday October 23 Covers Chapters 3 through 6 - Buses, Clocks, Timing, Edge Triggering, Level Triggering - Cache Memory Systems - Internal Memory.
Computer System Structures memory memory controller disk controller disk controller printer controller printer controller tape-drive controller tape-drive.
1 Last Class: Introduction Operating system = interface between user & architecture Importance of OS OS history: Change is only constant User-level Applications.
OS Spring’04 Introduction Operating Systems Spring 2004.
1 OS & Computer Architecture Modern OS Functionality (brief review) Architecture Basics Hardware Support for OS Features.
Chapter 2: Computer-System Structures
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
I/O Tanenbaum, ch. 5 p. 329 – 427 Silberschatz, ch. 13 p
Input/Output. Input/Output Problems Wide variety of peripherals —Delivering different amounts of data —At different speeds —In different formats All slower.
Chapter 7 Input/Output Luisa Botero Santiago Del Portillo Ivan Vega.
General System Architecture and I/O.  I/O devices and the CPU can execute concurrently.  Each device controller is in charge of a particular device.
Interrupts. 2 Definition: An electrical signal sent to the CPU (at any time) to alert it to the occurrence of some event that needs its attention Purpose:
1 CS503: Operating Systems Part 1: OS Interface Dongyan Xu Department of Computer Science Purdue University.
Introduction to Embedded Systems
System Calls 1.
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
OPERATING SYSTEM OVERVIEW. Contents Basic hardware elements.
MICROPROCESSOR INPUT/OUTPUT
Silberschatz, Galvin, and Gagne  Applied Operating System Concepts Module 2: Computer-System Structures Computer System Operation I/O Structure.
1 CSE Department MAITSandeep Tayal Computer-System Structures Computer System Operation I/O Structure Storage Structure Storage Hierarchy Hardware Protection.
2: Computer-System Structures
CHAPTER 3 TOP LEVEL VIEW OF COMPUTER FUNCTION AND INTERCONNECTION
Khaled A. Al-Utaibi  Interrupt-Driven I/O  Hardware Interrupts  Responding to Hardware Interrupts  INTR and NMI  Computing the.
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
Computer Architecture Lecture10: Input/output devices Piotr Bilski.
Chapter 2: Computer-System Structures 2.1 Computer System Operation 2.5 Hardware Protection 2.6 Network Structure.
1 Chapter 2: Computer-System Structures  Computer System Operation  I/O Structure  Storage Structure  Storage Hierarchy  Hardware Protection  General.
Operating System Structure A key concept of operating systems is multiprogramming. –Goal of multiprogramming is to efficiently utilize all of the computing.
We will focus on operating system concepts What does it do? How is it implemented? Apply to Windows, Linux, Unix, Solaris, Mac OS X. Will discuss differences.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Operating Systems 1 K. Salah Module 1.2: Fundamental Concepts Interrupts System Calls.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 2 Computer-System Structures Slide 1 Chapter 2 Computer-System Structures.
Silberschatz, Galvin and Gagne  Applied Operating System Concepts Chapter 2: Computer-System Structures Computer System Architecture and Operation.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Input/Output Problems Wide variety of peripherals —Delivering different amounts of data —At different speeds —In different formats All slower than CPU.
بسم الله الرحمن الرحيم MEMORY AND I/O.
1 Device Controller I/O units typically consist of A mechanical component: the device itself An electronic component: the device controller or adapter.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir. A.C. Verschueren Eindhoven University of Technology Section of Digital.
Chapter 2: Computer-System Structures
Interrupts and signals
Microprocessor Systems Design I
Chapter 8 Input/Output I/O basics Keyboard input Monitor output
Computer-System Architecture
Module 2: Computer-System Structures
CSE 451: Operating Systems Autumn 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 596 Allen Center 1.
Module 2: Computer-System Structures
CSE 451: Operating Systems Winter 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 412 Sieg Hall 1.
Module 2: Computer-System Structures
COMP3221: Microprocessors and Embedded Systems
Module 2: Computer-System Structures
Chapter 13: I/O Systems.
Presentation transcript:

Hardware Support for Operating Systems Sunny Gleason Vivek Uppal COM S 414

Multitasking In a multitasking uniprocessor OS, the OS tries to give each process the illusion that it is running on its own CPU. In reality, the OS: –runs process A for a while –gets interrupted by a timer, [the timer may need to be reset by the CPU] –saves the state of process A to memory –restores the state of another process, B (loading the PC, resumes execution of B) –runs process B for a while … [repeat] What’s the state of a process? Think!

Protection However, in a multitasking system, we can’t let the processes do everything that the CPU can do Examples: they shouldn’t be able to: –Halt the CPU –Read/Write to arbitrary devices, or locations in main memory (For example, the system timer, or the saved state of another process) We need methods of protection!

User Mode and Kernel Mode Modern CPUs support multiple modes of operation At the very least, we need user mode and kernel mode User mode is the mode under which normal applications run Kernel mode (also called Supervisor mode) is the mode under which the OS code runs How do you go between them? We’ll see – “interrupts and returning from interrupts”

User Mode and Kernel Mode Modes are implemented as integer privilege levels: user == 3, kernel == 0 In the x86 architecture, the current mode is stored using 2 bits of the MSW (machine status word) The mode is typically implemented by tagging a block of instructions in memory with the mode Jumping to new locations in memory causes the mode to change to the tagged mode

User Mode and Kernel Mode In the Intel Pentium architecture, examples of privileged instructions are: –LMSW, SMSW (load/store MSW) –MOV DBn, MOV CRn (move to debug/control registers) –LSL (load stack limit, adjusting one type of memory available to a process) –HLT (halt the CPU) A general protection exception is caused if these instructions are reached by the CPU while in user mode

User Mode and Kernel Mode How is memory protected? Typically, we check to make sure that an address is within a given range [s1, s2], that is, s1 <= a <= s2 To do this quickly, we will need additional hardware support …

Memory Protection In a shared environment, processes should not be able to write to arbitrary locations in the physical memory Processes need to have their own memory to work with, or logical address space The CPU must check each memory access to make sure that it is within the address space of the process

Memory Protection A simple scheme: –The program, as compiled, uses memory addresses from a start address A to end address B –When a program is loaded, the O/S allocates physical memory to the process from base address A’ to limit address B’ –While the process is running, A’ and B’ are loaded into special hardware registers –Special hardware translates a program address a to a physical address p using p = a – A + A’ –If p > B’, or p < A’, the hardware triggers an access out-of-bounds exception

Exceptions, faults, traps, interrupts… CPU ordinarily executes instructions in order After every intruction (clock cycle), checks the IRQ (interrupt request signal) Interrupts occur when: –a device sends a signal on the IRQ line going into the CPU (external interrupt) –an INT n instruction is executed (software interrupt) Exceptions occur due to the CPU instruction that was just executed: often these are categorized into faults and traps

Interrupts Each interrupt has a numerical priority The interrupt vector – array of function pointers to ISRs (interrupt service routines) When an interrupt occurs: –Push ret_addr = PC+4 onto the stack –Jump to [ivector_base + priority * 4] –[the CPU mode may switch] –Run the interrupt service routine code –Inform the interrupt controller that the interrupt has been handled –Pop ret_addr from the stack, jump to ret_add –[the CPU mode returns to the previous mode]

Interrupts Since interrupt service routines may access critical data structures (I/O buffers, PCB’s, etc.) we typically don’t want to be interrupted during their execution When interrupt i is being serviced, interrupts of priority j >= i are masked, or disabled Priority is not enough to save you! The kernel must be written so that higher-priority interrupts do not clobber the data structures used by lower- priority interrupts that they may have interrupted

System Calls System calls are just a special interrupt! –The process pushes system call arguments into registers, or onto the stack –Under the covers, the first argument to a system call is an integer system call identifier, call it id –[implementation note: Linux keeps an array of pointers to the actual system call routines, let’s call it sys_call[] ] –The process executes a software interrupt instruction (in Linux, INT 0x80) –The ISR for interrupt 0x80 jumps to address [sys_call[id]] –System call code places return value into return register –Returns from the interrupt using an IRET instruction

Returning from Exceptions For faults, execution returns to the original instruction (we’ll learn about this later – a page fault may trigger an ISR that loads the page from disk into memory) For traps, execution returns to the instruction following the original (have you ever wondered how debugging assembly code works?)

Peripherals Printer Key Board Mouse Speaker Storage Devices CPU communicates with the peripheral devices through a peripheral interface.

Peripheral Interface Abstract model of the interface. Top most layer of the interface High level commands (Like postscript commands) Device Model Detailed device behavior (printer/monitor)

Peripheral Interface Cont... Protocol layer Recognition of Data and command bytes Registers for giving commands to the device Register to transfer the data to the device. Lowest level Voltages, currents, Cables.

Device Organization Application Program Device Controller Device Abstract I/O machine External hardware Disks, Tapes, C D Roms

Controller Interface CommandStatus Data 0 Data 1 Data n-1 Logic... busy done Error code... busy done 0 0 idle 0 1 finished 1 0 working 1 1 undefined

Controller Interface A controller is at the protocol layer of the device. The controller could have registers dedicated for the commands and status or it could have some memory location reserved for it. In many cases the same controller may be driving many devices.

Direct Memory Access (DMA) What is the easiest I/O interface ? One I/P instruction. One O/P instruction. Each instruction selects a device, and transfers a byte of data. Disadvantages:

DMA cont… Better solution: CPU selects the device, memory address, and bytes of data to be transferred After this initial set up the data transfer is taken control of by the device controller and I/O and computation at the CPU take place in parallel. This is Direct memory Access(DMA). Cycle Stealing:

Interrupts A scenario when the I/O has finished. What should the device do to let the process know that I/O has finished ? 2 options Set flag in status. Wait for CPU to check it (Polling) Send a signal to CPU saying the I/O finished (Interrupts)

Priorities Scenario Few resources Many contenders So we need arbitration Leads to priorities

Interrupt Priorities Power event 30 Inter processor signal 29 Clock tick 28 Performance monitoring 27 General device interrupts 3-26 Scheduler operations 2

Daisy chained I/O buses Device 1 Highest priority Device 2 Bus Arbiter Device n Lowest Priority Grant Release Request

Daisy Chain Bus

Daisy Chain Disadvantages Unfair One device goes down the whole down stream is down The bus may have to be turned off when adding a new device to it

Review Several devices are on the same I/O bus Use some mechanism like daisy chain to determine who gets to use the bus I/O devices do DMA for bulk transfers Devices make interrupts when they are done with the I/O. Device controllers are visible in memory at some predefined address.