Architectural Support for Operating Systems Prof. Sirer CS 4410 Cornell University.

Slides:



Advertisements
Similar presentations
More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
Advertisements

1/1/ / faculty of Electrical Engineering eindhoven university of technology Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir.
The Kernel Abstraction
1/1/ / faculty of Electrical Engineering eindhoven university of technology Introduction Part 3: Input/output and co-processors dr.ir. A.C. Verschueren.
Avishai Wool lecture Introduction to Systems Programming Lecture 8 Input-Output.
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.
OS2-1 Chapter 2 Computer System Structures. OS2-2 Outlines Computer System Operation I/O Structure Storage Structure Storage Hierarchy Hardware Protection.
Architectural Support for OS March 29, 2000 Instructor: Gary Kimura Slides courtesy of Hank Levy.
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.
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
Computer System Organization S H Srinivasan
Hardware Support for Operating Systems Sunny Gleason Vivek Uppal COM S 414
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.
1 OS & Computer Architecture Modern OS Functionality (brief review) Architecture Basics Hardware Support for OS Features.
Chapter 2: Computer-System Structures
I/O Tanenbaum, ch. 5 p. 329 – 427 Silberschatz, ch. 13 p
CSE 451: Operating Systems Autumn 2013 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
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.
1 CS503: Operating Systems Part 1: OS Interface Dongyan Xu Department of Computer Science Purdue University.
System Calls 1.
3/11/2002CSE Input/Output Input/Output Control Datapath Memory Processor Input Output Memory Input Output Network Control Datapath Processor.
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
Protection and the Kernel: Mode, Space, and Context.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 8-1: I/O Management Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
Segmentation & O/S Input/Output Chapter 4 & 5 Tuesday, April 3, 2007.
2: Computer-System Structures
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.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto OS-Related Hardware.
1 Chapter 2: Computer-System Structures  Computer System Operation  I/O Structure  Storage Structure  Storage Hierarchy  Hardware Protection  General.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
I/O Computer Organization II 1 Interconnecting Components Need interconnections between – CPU, memory, I/O controllers Bus: shared communication channel.
Interrupt driven I/O. MIPS RISC Exception Mechanism The processor operates in The processor operates in user mode user mode kernel mode kernel mode Access.
1 CSE451 Architectural Supports for Operating Systems Autumn 2002 Gary Kimura Lecture #2 October 2, 2002.
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.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
1 Lecture 1: Computer System Structures We go over the aspects of computer architecture relevant to OS design  overview  input and output (I/O) organization.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
بسم الله الرحمن الرحيم MEMORY AND I/O.
Deniz ALTINBUKEN CS 3410, Spring 2015 Computer Science Cornell University P&H Chapter 4.9, pages 445–452, appendix A.7.
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.
Traps, Exceptions, System Calls, & Privileged Mode Hakim Weatherspoon CS 3410, Spring 2013 Computer Science Cornell University P&H Chapter 4.9, pages 509–515,
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
Processes. Main Points Process concept – A process is an OS abstraction for executing a program with limited privileges Dual-mode operation: user vs.
Of Privilege, Traps, Interrupts & Exceptions Prof. Sirer CS 316 Cornell University.
Computer System Structures Interrupts
System Calls, Interrupts and Exceptions
Introduction to Operating Systems
Introduction to Operating Systems
Microprocessor Systems Design I
Anton Burtsev February, 2017
Computer-System Architecture
Module 2: Computer-System Structures
Syscalls, exceptions, and interrupts, …oh my!
Exceptions Control Flow
Architectural Support for OS
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 Autumn 2001 Lecture 2 Architectural Support for Operating Systems Brian Bershad 310 Sieg Hall 1.
CSE 451: Operating Systems Winter 2007 Module 2 Architectural Support for Operating Systems Brian Bershad 562 Allen Center 1.
CSE 451: Operating Systems Winter 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 412 Sieg Hall 1.
Architectural Support for OS
Module 2: Computer-System Structures
Module 2: Computer-System Structures
Syscalls, exceptions, and interrupts, …oh my!
Chapter 13: I/O Systems.
Presentation transcript:

Architectural Support for Operating Systems Prof. Sirer CS 4410 Cornell University

Basic Computer Organization CPU Memory ?

Keyboard Let’s build a keyboard Lots of mechanical switches Need to convert to a compact form (binary) We’ll use a special mechanical switch that, when pressed, connects two wires simultaneously

Keyboard When a key is pressed, a 7-bit key identifier is computed + 3-bit encoder (4 to 3) 4-bit encoder (16 to 4) not all 16 wires are shown

Keyboard A latch can store the keystroke indefinitely + 3-bit encoder (4 to 3) 4-bit encoder (16 to 4) not all 16 wires are shown Latch

Keyboard The keyboard can then appear to the CPU as if it is a special memory address + 3-bit encoder (4 to 3) 4-bit encoder (16 to 4) not all 16 wires are shown Latch CPU

Device Interfacing Techniques Memory-mapped I/O Device communication goes over the memory bus Reads/Writes to special addresses are converted into I/O operations by dedicated device hardware Each device appears as if it is part of the memory address space Programmed I/O CPU has dedicated, special instructions CPU has additional input/output wires (I/O bus) Instruction specifies device and operation Memory-mapped I/O is the predominant device interfacing technique in use

Polling vs. Interrupts In our design, the CPU constantly needs to read the keyboard latch memory location to see if a key is pressed Called polling Inefficient An alternative is to add extra circuitry so the keyboard can alert the CPU when there is a keypress Called interrupt driven I/O Interrupt driven I/O enables the CPU and devices to perform tasks concurrently, increasing throughput Only needs a tiny bit of circuitry and a few extra wires to implement the “alert” operation

Interrupt Driven I/O CPU Memory An interrupt controller mediates between competing devices Raises an interrupt flag to get the CPU’s attention Identifies the interrupting device Can disable (aka mask) interrupts if the CPU so desires intr dev id Interrupt Controller

Interrupt Driven I/O CPU Memory An interrupt controller mediates between competing devices Raises an interrupt flag to get the CPU’s attention Identifies the interrupting device Can disable (aka mask) interrupts if the CPU so desires intr

Interrupt Management Interrupt controllers manage interrupts Maskable interrupts: can be turned off by the CPU for critical processing Nonmaskable interrupts: signifies serious errors (e.g. unrecoverable memory error, power out warning, etc) Interrupts contain a descriptor of the interrupting device A priority selector circuit examines all interrupting devices, reports highest level to the CPU Interrupt controller implements interrupt priorities Can optionally remap priority levels

Interrupt-driven I/O summary Normal interrupt-driven operation with memory-mapped I/O proceeds as follows CPU initiates a device operation (e.g. read from disk) by writing an operation descriptor to a device register CPU continues its regular computation The device asynchronously performs the operation When the operation is complete, interrupts the CPU This would incur high-overhead for moving bulk-data One interrupt per byte!

Direct Memory Access (DMA) Transfer data directly between device and memory No CPU intervention required for moving bits Device raises interrupts solely when the block transfer is complete Critical for high-performance devices

Recap We now have a basic computer system to which devices can be connected How do we execute applications on this system? Applications are not necessarily trusted!

Privilege Levels Some processor functionality cannot be made accessible to untrusted user applications e.g. HALT, change MMU settings, set clock, reset devices, manipulate device settings, … Need to have a designated mediator between untrusted/untrusting applications The operating system (OS) Need to delineate between untrusted applications and OS code Use a “privilege mode” bit in the processor 0 = Untrusted = user, 1 = Trusted = OS

Privilege Mode Privilege mode bit indicates if the current program can perform privileged operations On system startup, privilege mode is set to 1, and the processor jumps to a well-known address The operating system (OS) boot code resides at this address The OS sets up the devices, initializes the MMU, loads applications, and resets the privilege bit before invoking the application Applications must transfer control back to OS for privileged operations

Sample System Calls Print character to screen Needs to multiplex the shared screen resource between multiple applications Send a packet on the network Needs to manipulate the internals of a device whose hardware interface is unsafe Allocate a page Needs to update page tables & MMU

System Calls A system call is a controlled transfer of execution from unprivileged code to the OS A potential alternative is to make OS code read-only, and allow applications to just jump to the desired system call routine. Why is this a bad idea? A SYSCALL instruction transfers control to a system call handler at a fixed address

SYSCALL instruction SYSCALL instruction does an atomic jump to a controlled location Switches the sp to the kernel stack Saves the old (user) SP value Saves the old (user) PC value (= return address) Saves the old privilege mode Sets the new privilege mode to 1 Sets the new PC to the kernel syscall handler Kernel system call handler carries out the desired system call Saves callee-save registers Examines the syscall number Checks arguments for sanity Performs operation Stores result in v0 Restores callee-save registers Performs a “return from syscall” instruction, which restores the privilege mode, SP and PC

Libraries and Wrappers Compilers do not emit SYSCALL instructions They do not know the interface exposed by the OS Instead, applications are compiled with standard libraries, which provide “syscall wrappers” printf() -> write(); malloc() -> sbrk(); recv(); open(); close(); … Wrappers are: written in assembler, internally issue a SYSCALL instruction, pass arguments to kernel, pass result back to calling application

Typical Process Layout Libraries provide the glue between user processes and the OS libc linked in with all C programs Provides printf, malloc, and a whole slew of other routines necessary for programs OBJECT1 OBJECT2 Stack Heap Data Text HELLO WORLD GO BIG RED CS! printf(char * fmt, …) { create the string to be printed SYSCALL 80 } malloc() { … } strcmp() { … } main() { printf (“HELLO WORLD”); printf(“GO BIG RED CS”); ! Program Library Activation Records

Full System Layout The OS is omnipresent and steps in where necessary to aid application execution Typically resides in high memory When an application needs to perform a privileged operation, it needs to invoke the OS OBJECT1 OBJECT2 Stack Heap Data HELLO WORLD GO BIG RED CS! printf(char * fmt, …) { main() { … } Program Library Activation Records USER OBJECT1 OBJECT2 OS Stack OS Heap OS Data LINUX syscall_entry_point() { … } OS Text Kernel Activation Records

Exceptional Situations System calls are control transfers to the OS, performed under the control of the user application Sometimes, need to transfer control to the OS at a time when the user program least expects it Division by zero, Alert from the power supply that electricity is about to go out, Alert from the network device that a packet just arrived, Clock notifying the processor that the clock just ticked, Some of these causes for interruption of execution have nothing to do with the user application Need a (slightly) different mechanism, that allows resuming the user application

Interrupts & Exceptions On an interrupt or exception Switches the sp to the kernel stack Saves the old (user) SP value Saves the old (user) PC value Saves the old privilege mode Saves cause of the interrupt/exception Sets the new privilege mode to 1 Sets the new PC to the kernel interrupt/exception handler Kernel interrupt/exception handler handles the event Saves all registers Examines the cause Performs operation required Restores all registers Performs a “return from interrupt” instruction, which restores the privilege mode, SP and PC

Syscall vs. Interrupt The differences lie in how they are initiated, and how much state needs to be saved and restored Syscall requires much less state saving Caller-save registers are already saved by the application Interrupts typically require saving and restoring the full state of the processor Because the application got struck by a lightning bolt without anticipating the control transfer

Terminology Trap Any kind of a control transfer to the OS Syscall Synchronous, program-initiated control transfer from user to the OS to obtain service from the OS e.g. SYSCALL Exception Asynchronous, program-initiated control transfer from user to the OS in response to an exceptional event e.g. Divide by zero, segmentation fault Interrupt Asynchronous, device-initiated control transfer from user to the OS e.g. Clock tick, network packet

Memory Protection Some memory addresses need protection The OS text, data, heap and stack need to be protected from untrusted applications Some devices should be out of reach of applications Memory Management Unit (MMU) aids with memory management Provides a virtual to physical address translation Examines every load/store/jump and ensures that applications remain within bounds using protection (RWX) bits associated with every page of memory Modern architectures use a Translation Lookaside Buffer (TLB) for keeping track of virtual to physical mappings Software is invoked on a miss

TLB Operation TLB examines every virtual address uttered by the CPU, and if there is a match, and the permissions are appropriate, replaces the virtual page number with the physical page number CPU Memory TLB VaddrPaddrRWX

Atomic Instructions Hardware needs to provide special instructions to enable concurrent programs to operate correctly