600 likes | 913 Views
Operating Systems. Mehdi Naghavi naghavi@iust.ac.ir naghavi@aut.ac.ir Spring 1386. Class outline. Introduction and Overview Operating system structures Processes Scheduling Deadlocks Memory management Input/Output File Systems Security. Operating Systems. Input/Output Systems.
E N D
Operating Systems Mehdi Naghavi naghavi@iust.ac.ir naghavi@aut.ac.ir Spring 1386
Class outline • Introduction and Overview • Operating system structures • Processes • Scheduling • Deadlocks • Memory management • Input/Output • File Systems • Security
Operating Systems Input/Output Systems Mehdi Naghavi naghavi@aut.ac.ir naghavi_mehdi@yahoo.com Spring 1386
Input/Output Systems Mehdi Naghavi naghavi@aut.ac.ir Spring 1386
Overview • Principles of I/O hardware • Principles of I/O software • I/O software layers • Disks • Clocks • Character-oriented terminals • Graphical user interfaces • Network terminals • Power management
I/O Hardware Outsideworld Videocontroller Hard drivecontroller USBcontroller Networkcontroller CPU Computer internals(inside the “box”) Memory
Device controllers • I/O devices have components • Mechanical component • Electronic component • The electronic component is the device controller • May be able to handle multiple devices • Controller's tasks • Convert serial bit stream to block of bytes • Perform error correction as necessary • Make available to main memory
Memory-Mapped I/O Memory 0xFFF… I/O ports 0 SeparateI/O & memoryspace Memory-mapped I/O Hybrid: bothmemory-mapped &separate spaces
How is memory-mapped I/O done? • Single-bus • All memory accesses go over a shared bus • I/O and RAM accesses compete for bandwidth • Dual-bus • RAM access over high-speed bus • I/O access over lower-speed bus • Less competition • More hardware (more expensive…) CPU Memory I/O CPU Memory I/O This port allows I/O devicesaccess into memory
Intercommunication between I/O devices & CPU • Pooling • Interrupt
Polling • Determines state of device • command-ready • busy • Error • Busy-wait cycle to wait for I/O from device
Interrupts • CPU Interrupt-request line triggered by I/O device • Interrupt handler receives interrupts • Maskable to ignore or delay some interrupts • Interrupt vector to dispatch interrupt to correct handler • Based on priority • Some nonmaskable • Interrupt mechanism also used for exceptions
Hardware’s view of interrupts Bus How interrupts happens. Connections between devices and interrupt controller actually use interrupt lines on the bus rather than dedicated wires
Direct Memory Access • Used to avoid programmed I/O for large data movement • Requires DMA controller • Bypasses CPU to transfer data directly between I/O device and memory
Input/Output Systems Principles of I/O Software
I/O software: goals • Device independence • Programs can access any I/O device • No need to specify device in advance (floppy, hard drive, or CD-ROM) • Uniform naming • Name of a file or device is a string or an integer • Doesn’t depend on the machine (underlying hardware) • Error handling • Done as close to the hardware as possible • Isolate higher-level software • Synchronous vs. asynchronous transfers • Blocked transfers vs. interrupt-driven • Buffering • Data coming off a device cannot be stored in final destination • Sharable vs. dedicated devices • disks are sharable • tape drives would not be
Programmed I/O: printing a page Steps in printing a string
Code for programmed I/O Writing a string to the printer using programmed I/O
Interrupt-driven I/O copy_from_user (buffer, p, count); j = 0; enable_interrupts(); while (*printer_status_reg != READY) ; *printer_data_reg = p[0]; scheduler(); // and block user Code run by system call if (count == 0) { unblock_user(); } else { *printer_data_reg = p[j]; count--; j++; } acknowledge_interrupt(); return_from_interrupt(); Code run at interrupt time • Writing a string to the printer using interrupt-driven I/O • Code executed when print system call is made • Interrupt service procedure
I/O using DMA copy_from_user (buffer, p, count); set_up_DMA_controller(); scheduler(); // and block user Code run by system call acknowledge_interrupt(); unblock_user(); return_from_interrupt(); Code run at interrupt time • Printing a string using DMA • code executed when the print system call is made • interrupt service procedure
I/O Interface • I/O system calls encapsulatedevice behaviors in generic classes • Device-driver layer hides differences among I/O controllers from kernel • Devices vary in many dimensions • Character-stream or block • Sequential or random-access • Sharable or dedicated • Speed of operation • read-write, read only, or write only
Layers of I/O software User-level I/O software & libraries User Device-independent OS software Operatingsystem(kernel) Device drivers Interrupt handlers Hardware
Interrupt handlers • Interrupt handlers are best hidden • Driver starts an I/O operation and blocks • Interrupt notifies of completion • Interrupt procedure does its task • Then unblocksdriver that started it • Perform minimalactions at interrupt time • Some of the functionality can be done by the driver after it is unblocked • Interrupt handler must • Saveregs not already saved by interrupt hardware
Device drivers Userspace • Device drivers go between device controllers and rest of OS • Drivers standardize interface to widely varied devices • Device drivers communicate with controllers over bus • Controllers communicate with devices themselves Userprogram Kernelspace Rest of the OS Software Keyboarddriver Diskdriver Keyboardcontroller Diskcontroller Hardware Devices
Device-independent I/O software • Device-independent I/O software provides common “library” routines for I/O software • Helps drivers maintain a standard appearance to the rest of the OS • Uniform interface for many device drivers for • Buffering • Error reporting • Allocating and releasing dedicated devices • Suspending and resuming processes • Common resource pool • Device-independent block size (keep track of blocks)
Non-standard driver interfaces Why a standard driver interface? Standard driver interfaces
Buffering device input Userspace Userspace Userspace Userspace Kernelspace Kernelspace Kernelspace Kernelspace 2 2 1 1 3 Unbufferedinput Buffering inuser space Buffer in kernelCopy to user space Double bufferin kernel
Anatomy of an I/O request Layers of the I/O system and the main functions of each layer
Disk drive structure head • Data stored on surfaces • Up to two surfaces per platter • One or more platters per disk • Data in concentric tracks • Tracks broken into sectors • 256B-1KB per sector • Cylinder: corresponding tracks on all surfaces • Data read and written by heads • Actuator moves heads • Heads move in unison sector platter track cylinder surfaces spindle actuator
Disk “zones” • Outside tracks are longer than inside tracks • Two options • Bits are “bigger” • More bits (transfer faster) • Modern hard drives use second option • More data on outer tracks • Disk divided into “zones” • Constant sectors per track in each zone • 8–20 (or more) zones on a disk
Disk “addressing” • Millions of sectors on the disk must be labeled • Two possibilities • Cylinder/track/sector • Sequential numbering • Modern drives use sequential numbers • Disks mapsequential numbers into specific location • Mapping may be modified by the disk • Remap bad sectors • Optimize performance • Hide the exact geometry, making life simpler for the OS
Disk Structure • Disk drives are addressed as large 1-dimensional arrays of logical blocks, where the logical block is the smallest unit of transfer. • The 1-dimensional array of logical blocks is mapped into the sectors of the disk sequentially. • Sector 0 is the first sector of the first track on the outermost cylinder. • Mapping proceeds in order through that track, then the rest of the tracks in that cylinder, and then through the rest of the cylinders from outermost to innermost.
Building a better “disk” • Problem: CPU performance has been increasing exponentially, but disk performance hasn’t • Disks are limited by mechanics • Problem: disks aren’t all that reliable • Solution: distribute data across disks, and use some of the space to improve reliability • Data transferred in parallel • Data storedacross drives (striping) • Parity on an “extra” drive for reliability
RAID Structure Stripe stripe stripe RAID 0 (Redundant Array of Inexpensive Disks RAID 1 (Mirrored copies) RAID 4 (Striped with parity: any disk failure can be masked, but bottleneck for parity disk) RAID 5 (Parity rotates through disks: how do you update blocks?)
RAID Recovery • X4(i)=X3(i)(+) X2(i)(+) X1(i)(+) X0(i) • (+) :exclusive or • X1(i)= X4(i)(+) X3(i)(+) X2(i)(+) X0(i)
CD-ROM recording • CD-ROM has data in a spiral • Hard drives have concentric circles of data • One continuous track: just like vinyl records! • Pits & lands “simulated” with heat-sensitive material on CD-Rs and CD-RWs
Network-Attached Storage • Network-attached storage (NAS) is storage made available over a network rather than over a local connection (such as a bus) • NFS (Network File System, Sun) and CIFS (Common Internet Files Systems, MS Protocol) are common protocols • Implemented via remote procedure calls between host and storage • New iSCSI protocol uses IP network to carry the SCSI protocol
Storage Area Network • Common in large storage environments (and becoming more common) • Multiple hosts attached to multiple storage arrays flexible
Structure of a disk sector Preamble Data ECC • Preamble contains information about the sector • Sector number & location information • Data is usually 256, 512, or 1024 bytes • ECC (Error Correcting Code) is used to detect & correct minor errors in the data