/
Input and Output Professor Hugh C. Lauer Input and Output Professor Hugh C. Lauer

Input and Output Professor Hugh C. Lauer - PowerPoint Presentation

triclin
triclin . @triclin
Follow
343 views
Uploaded On 2020-08-07

Input and Output Professor Hugh C. Lauer - PPT Presentation

CS3013 Operating Systems Slides include copyright materials Modern Operating Systems 3 rd ed by Andrew Tanenbaum and from Operating System Concepts 7 th and 8 th ed by ID: 801295

term 3013 input device 3013 term device input output 2014 interrupt outputcs register devices control memory physical amp data

Share:

Link:

Embed:

Download Presentation from below link

Download The PPT/PDF document "Input and Output Professor Hugh C. Lauer" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Slide1

Input and Output

Professor Hugh C. LauerCS-3013, Operating Systems(Slides include copyright materials Modern Operating Systems, 3rd ed., by Andrew Tanenbaum and from Operating System Concepts, 7th and 8th ed., by Silbershatz, Galvin, & Gagne)

Input and Output

CS-3013, C-Term 2014

1

Slide2

While a typical Linux or Windows distribution includes support for > 50 file systems …

Input and OutputCS-3013, C-Term 20142…

these systems are called

upon to support 1000’s of I/O devices and subsystems

Slide3

The I/O subsystem

The largest, most complex subsystem in OSMost lines of codeHighest rate of code changesWhere OS engineers most likely to workDifficult to test thoroughlyMake-or-break issue for any systemBig impact on performance and perceptionBigger impact on acceptability in market

Input and Output

CS-3013, C-Term 2014

3

Slide4

Overview

What is I/O?Principles of I/O hardwarePrinciples of I/O softwareMethods of implementing input-output activitiesOrganization of device driversSpecific kinds of devices(Tanenbaum, Chapter 5)Input and OutputCS-3013, C-Term 2014

4

Slide5

Hardware organization

(simple, naïve)Input and OutputCS-3013, C-Term 20145

Device

CPU

Memory

memory bus

Device

Slide6

Hardware organization

(recent PC)Input and OutputCS-3013, C-Term 20146

Level 2 cache

ISA bridge

IDE disk

Main Memory

Processor

Bridge

Moni

-

tor

Graphics card

USB

Key-

board

Mouse

Ether-

net

SCSI

Modem

Sound

card

Printer

PCI bus

ISA bus

Processor

w/ caches

PCI Express

Slide7

Kinds of I/O devices

Character (and sub-character) devicesMouse, character terminal, joy stick, some keyboardsBlock transferDisk, tape, CD, DVDNetworkClocksInternal, externalGraphicsGUI, gamesMultimediaAudio, videoOther

Sensors, cameras, controllers, touch screens, etc.

Input and OutputCS-3013, C-Term 2014

7

Slide8

Controlling an I/O device

A function of host CPU architectureTwo approaches:– Special instructions vs. memory-mappedSpecial I/O instructionsOpcode to stop, start, query, etc.Separate I/O address spaceKernel mode onlyMemory-mapped I/O control registersEach register has a physical memory addressWriting to data register is output

Reading from data register is inputWriting to control register causes actionCan be mapped to kernel or user-level virtual memory

Input and Output

CS-3013, C-Term 2014

8

Slide9

Character device

(example)Data register:Register or address where data is read from or written toVery limited capacity (at most a few bytes)Action register:When writing to register, causes a physical actionReading from register yields zeroStatus register:Reading from register provides informationWriting to register is no-opInput and Output

CS-3013, C-Term 2014

9

Slide10

Block transfer device

(example)Buffer address register:Points to area in physical memory to read or write data orAddressable buffer for dataE.g., network cards, modern hard drives

Action register:When writing to register, initiates a physical action or data transferReading from register yields zero

Status register:Reading from register provides informationWriting to register is no-op

Input and Output

CS-3013, C-Term 2014

10

Keyboard/mouse

Slide11

DMA (

Direct Memory Access)Block devices to autonomously read from and/or write to main memory(Usually) physical addressesCompete with processor(s) for access to bus, memoryTransfer addressPoints to location in physical memoryAction register:Initiates a reading of control block chain to start actions

Status register:Reading from register provides information

Input and OutputCS-3013, C-Term 2014

11

Slide12

Input and Output

CS-3013, C-Term 201412

controls

disk

operation

address

Count

control info

next

operation

address

Count

control info

next

operation

address

Count

control info

next

physical

memory

DMA

controller

First

control block

Slide13

Intelligent DMA Controller

(continued)DMA control register points to first control block in chainEach DMA control block hasAction & control info for a single transfer of one or more blocksData addresses in physical memory(optional) link to next block in chain(optional) interrupt upon completionEach control block removed from chain upon completionI/O subsystem may add control blocks to chain while transfers are in progressResult:– uninterrupted sequence of transfers with no CPU intervention

Input and Output

CS-3013, C-Term 201413

Slide14

Questions?

CS-3013, C-Term 2014Input and Output14

Slide15

Overview

What is I/O?Principles of I/O hardwarePrinciples of I/O softwareMethods of implementing input-output activitiesOrganization of device driversSpecific kinds of devices(Tanenbaum, Chapter 5)Input and Output

CS-3013, C-Term 2014

15

Slide16

Requirements of I/O software

Efficiency – Do not allow I/O operations to become system bottleneckEspecially slow devicesDevice independence – isolate OS and application programs from device specific details and peculiaritiesUniform naming – support a way of naming devices that is scalable and consistentError handling – isolate the impact of device errors, retry where possible, provide uniform error codesErrors are abundant in I/O…

Input and OutputCS-3013, C-Term 2014

16

Slide17

Principles of I/O software

(continued)…Buffering – provide uniform methods for storing and copying data between physical memory and the devicesUniform data transfer modes – synchronous and asynchronous, read, write, ..Controlled device access – sharing and transfer modesUniform driver support – specify interfaces and protocols that drivers must adhere toInput and Output

CS-3013, C-Term 2014

17

Slide18

I/O software “stack”

Input and OutputCS-3013, C-Term 201418

User Level Software

Device Independent

Software

Device Drivers

Interrupt Handlers

Hardware

I/O API & libraries

Device

Dependent –

schedulable

Device Dependent – as

quick as possible

(Rest of

the OS

)

Slide19

Three common ways of I/O

Programmed I/OInterrupt-Driven I/OI/O using DMAInput and OutputCS-3013, C-Term 201419

Slide20

Programmed I/O

(polling)Used when device and controller are relatively quick to process an I/O operationDevice driverGains access to deviceInitiates I/O operationLoops testing for completion of I/O operation (busy wait)If there are more I/O operations, repeatUsed in following kinds of cases

Service interrupt time > Device response timeDevice has no interrupt capabilityEmbedded systems where CPU has nothing else to do

Input and Output

CS-3013, C-Term 2014

20

Slide21

Programmed I/O example —

bitmapped keyboard & mouseKeyboard & mouse buttons implemented as 128-bit read-only registerOne bit for each key and mouse button0 = “up”; 1 = “down”Mouse position implemented as pair of countersOne increment per unit of motion in each of x and

y directionsPeriodic clock interrupt (e.g., every 10

msec)Reads keyboard register, compares to previous copyDetermines key & button transitions up or down

Decodes transition stream to form character and button sequence

Reads and compares mouse counters to form motion sequence

Input and Output

CS-3013, C-Term 2014

21

Advantage:– key positions

& mouse behavior

are

programmed entirely

in software

Slide22

Other programmed I/O examples

Check status of deviceRead from disk or boot device at boot timeNo OS present, hence no interrupt handlersNeeded for bootstrap loading of the inner portions of kernelExternal sensors or controllersReal-time control systemsInput and OutputCS-3013, C-Term 201422

Slide23

Questions about programmed I/O?

CS-3013, C-Term 2014Input and Output23

Slide24

Interrupt-driven I/O

Interrupts occur on I/O events operation completion Error or change of statusData transferred by interrupt handlerReading or writing device registersInput and OutputCS-3013, C-Term 2014

24

Processor participates in

every

byte or word transferred

!

Slide25

Interrupts

Input and OutputCS-3013, C-Term 201425

Slide26

Interrupt request lines (IRQs)

Every device is assigned an IRQUsed when raising an interruptInterrupt handler can identify the interrupting deviceAssigning IRQsIn older and simpler hardware, physical wires and contacts on device or busIn most modern PCs, etc., assigned dynamically at boot timeInput and OutputCS-3013, C-Term 2014

26

Slide27

Handling interrupts

(Linux style)TerminologyInterrupt context – kernel operating not on behalf of any processProcess context – kernel operating on behalf of a particular processUser context – process executing in user-space virtual memoryInterrupt Service Routine (ISR), also called Interrupt Handler

The function that is invoked when an interrupt is raisedIdentified by IRQOperates on Interrupt stack

(as of Linux kernel 2.6)One interrupt stack per processor or coreApprox

4-8

kbytes

All handlers share same stack on processor!

Input and Output

CS-3013, C-Term 2014

27

Slide28

Handling interrupts

(Linux style – continued)…Top half – does minimal, time-critical work necessaryAcknowledge interrupt, reset device, copy buffer or registers, etc.Interrupts (usually) disabled on current processorBottom half – the part of the ISR that can be deferred to more convenient timeCompletes I/O processing; does most of the work

Interrupts enabled (usually)Communicates with processesPossibly in a kernel thread (or even a user thread!)

Input and Output

CS-3013, C-Term 2014

28

Definitions!

Slide29

Interrupt-driven I/O example — software time-of-day clock

Interrupt occurs at fixed intervals50 or 60 Hz1 kHz in more modern processorsService routine (top half):–Adds one tick to clock counterService routine (bottom half):–Checks list of soft timersNotifies tasks of any expired timers

Input and Output

CS-3013, C-Term 2014

29

Note that this looks a lot like programmed I/O

Except for bottom-half processing

Slide30

Other interrupt-driven I/O examples

Very “slow” character-at-a-time terminalsMechanical printers (15 characters/second)Some keyboards (one character/keystroke)Command-line completion in many Unix systemsGame consolesSerial modemsMany I/O devices in “old” computersPaper tape, punched cards, etc.Input and OutputCS-3013, C-Term 2014

30

Slide31

Programmed I/O

vs. interrupt-driven I/OProgrammed I/OA process or thread pro-actively works the device, gets or puts the data, does everything else.Interrupt-driven I/ODevice operates autonomously, let’s processor know when it is done or readyBothCPU participates in transfer of every byte or word.Input and OutputCS-3013, C-Term 2014

31

Slide32

I/O using DMA

Input and OutputCS-3013, C-Term 201432

Located inside bridge

chip

in

many computers

Slide33

DMA interrupt handler

Service Routine – top half (interrupts disabled)Does as little work as possible and returns(Mostly) notices completion of one transfer, starts another(Occasionally) checks for statusSetup for more processing in bottom halfService Routine – bottom half (interrupts enabled)

Compiles control blocks from I/O requestsManages & pins buffers, translates virtual to physical addressesPosts completion of transfers to requesting applications

Unpin and/or release buffersPossibly in a kernel thread

Input and Output

CS-3013, C-Term 2014

33

Device transfers

data itself

Slide34

DMA examples

Disks, CD-ROM readers, DVD readersEthernet & wireless “modems”Tape and bulk storage devicesCommon themes:–Device controller has space to buffer a (big) block of dataController has intelligence to update physical addresses and transfer dataController (often) has intelligence to interpret a sequence of control blocks without CPU helpCPU does not touch data during transfer!Input and OutputCS-3013, C-Term 2014

34

Not GUIs

Slide35

Buffering

DMA devices need memory to read from, write toMust be contiguous pages(Usually) physical addressesDouble bufferingOne being filled (or emptied) by deviceOther being emptied (or filled) by applicationSpecial case of producer-consumer with n = 2Input and Output

CS-3013, C-Term 2014

35

Slide36

DMA example — streaming tape

RequirementMove data to/from tape device fast enough to avoid stopping tape motionProducer-consumer model between application and bottom-half service routineMultiple actions queued up before previous action is completedNotifies application of completed actionsTop half service routine Records completion of each actionStarts next action before tape moves too farResult:–Ability to read or write 100’s or 1000’s of megabytes without stopping tape motion

Input and Output

CS-3013, C-Term 2014

36

Slide37

Digression:– error detection and correction

Most data storage and network devices have hardware error detection and correctionRedundancy code added during writingParity: detects 1-bit errors, not 2-bit errorsHamming codesCorrects 1-bit errors, detects 2-bit errorsCyclic redundancy check (CRC)Detects errors in string of 16- or 32-bitsReduces probability of undetected errors to very, very lowCheck during reading

Report error to device driver Error recovery:– one of principal responsibilities of a device driver!

Input and OutputCS-3013, C-Term 2014

37

Slide38

Questions?

Input and OutputCS-3013, C-Term 201438

Slide39

Overview

What is I/O?Principles of I/O hardwarePrinciples of I/O softwareMethods of implementing input-output activitiesOrganization of device driversSpecific kinds of devices(Tanenbaum, Chapter 5)Input and Output

CS-3013, C-Term 2014

39

Slide40

Device Drivers

OrganizationUniform interfaces to OSUniform buffering strategiesHide device idiosyncrasiesInput and OutputCS-3013, C-Term 201440

Slide41

Device Drivers

Device Drivers are dependent on both the OS & deviceOS dependenceMeet the interface specs of the device independent layerUse the facilities supplied by the OS – buffers, error codes, etc.Accept and execute OS commands – e.g. read, open, etc.Device Dependent Actions during Interrupt Service routineTranslate OS commands into device operations

E.g read block n becomes a series of setting and clearing and interpreting device registers or interfaces

Note that some device drivers have layersStrategy or policy part to optimize arm movement or do retries; plus a mechanism part the executes the operations

Input and Output

CS-3013, C-Term 2014

41

Slide42

OS Responsibility to Device Driver

Uniform APIOpen, Close, Read, Write, Seek functionsioctl function as escape mechanismBufferingKernel functions for allocating, freeing, mapping, pinning buffersUniform naming

/dev/(type)(unit)

type defines driver; unit says which deviceOtherAssign interrupt level (IRQ)

Protection (accessibility by application, user-space routines)

Error reporting mechanism

Input and Output

CS-3013, C-Term 2014

42

Slide43

Abstract Overview

Think of I/O subsystem as a C++ or Java-style abstract classUniform interface in form of specific operations (methods) and servicesUniform state informationEach I/O driver implements a subclassOwn methods for uniform interfaceAdditional state info & methods for specific needsHowever, no Java or C++ support in kernelMust implement everything in long-hand in CJust like with file systems!Input and Output

CS-3013, C-Term 2014

43

Slide44

Operating System Organization

Input and OutputCS-3013, C-Term 201444

Kernel

System Libraries (user space)

Utilities, tools, Window packages, program management, other stuff

Drivers & modules

File Systems

Dynamically

loaded

at

run time!

Dynamically

loaded

at

run time!

Slide45

Uniform API and Buffering Example

Memory-mapped Keyboard/dev/kbDevice interrupt routine detects key transitionsDriver converts sequence of transitions into characters in user’s written languageCharacters placed sequentially in bufferAccessible by read()Application calls getchar() or get()Library routines implemented with read

()Provides uniform input stream semanticsInput and Output

CS-3013, C-Term 2014

45

Slide46

Installing Device Drivers

Classic UnixCreate and compile driver to .o fileEdit and re-compile device table to add new deviceRe-link with .o files for OS kernel  new boot fileClassic MacintoshSubmit to Apple for verification, approval, and inclusionMS-DOS and WindowsDynamic driver loading and installation

Special driver-level debuggers available; open device environmentCertification program for trademarking

LinuxDynamic driver loading and installationOpen device environment

Input and Output

CS-3013, C-Term 2014

46

Reason why Windows won

battle of the desktop

Slide47

Dynamic Device Configuration

At boot time:–Probe hardware for inventory of devices & addressesMap devices to drivers (using table previously created)Load necessary drivers into kernel space, register in interrupt vector (.sys files in Windows)Run time:–Detect interrupt from newly added deviceSearch for driver, or ask user; add to table

Load into kernel space, register in interrupt vectorInput and Output

CS-3013, C-Term 2014

47

Slide48

Probing for devices

(Most) bridge and bus standards include registration protocol[vendor, device ID]OS (recursively) tests every addressable connectionIf device is present, it responds with own IDPerformed both atBoot time: to associate drivers with addressesInstallation time: to build up association tableInput and Output

CS-3013, C-Term 201448

Slide49

Alternative: Self-registration

In systems where every module or class initializes itselfAt start-up time, each driver module is invokedChecks for presence if deviceIf present, registers with OS itsNameInterrupt handlerShutdown actionHibernate actionSleep action…Input and OutputCS-3013, C-Term 2014

49

Slide50

Allocating and Releasing Devices

Some devices can only be used by one application at a timeCD-ROM recordersGUI interfaceAllocated at Open() timeFreed at Close() timeInput and OutputCS-3013, C-Term 2014

50

Slide51

User Space I/O Software

(Daemons and Spoolers)Device registers mapped into virtual address space of daemon processControlled directly by daemonTop-half service routineHandles interruptsSignals via semaphores or monitorsBottom-half service routineThe daemon itself!Waits for signals or monitorsManages device and requests from outside kernel

Input and Output

CS-3013, C-Term 201451

Slide52

User Space I/O example

Print Spooler/dev/lpt is a “virtual” device available to every process & userDriver causes “Printing” to spool fileControl info to spooler daemonPrinter selection, options, and parametersSpooler selects one print “job” at a timePrints from spool file to physical deviceTypes of printing

Simple character strings separated by \n charactersStream of PCL or inkjet commandsPostscript files

…Input and Output

52

CS-3013, C-Term 2014

Slide53

Overview

What is I/O?Principles of I/O hardwarePrinciples of I/O softwareMethods of implementing input-output activitiesOrganization of device driversSpecific kinds of devices(Tanenbaum, Chapter 5)Input and Output

CS-3013, C-Term 2014

53

Slide54

Character Terminal

Really two devicesKeyboard inputCharacter display output/dev/tty (Unix) or COM (Windows)The classic input-output terminalRS-232 standardModesrawcooked (aka canonical) – with backspace correction, tab expansion, etc.

Printed output vs. CRT display

Input and Output

54

CS-3013, C-Term 2014

Slide55

A special kind of device —graphical user interface

aka, the bitmapped displayIn IBM language:– “all points addressable”300K pixels to 2M pixelsEach pixel may be separated writtenCollectively, they createWindowsGraphics

ImagesVideosGames

Input and Output

CS-3013, C-Term 2014

55

Slide56

GUI Device — early days

Bitmap in main memoryAll output via library routines to bitmapEntirely (or mostly) in user spaceController, an automaton to do:–D-A conversion (digital to analog video)60+ Hz refresh rate“clock” interrupt at top of each frameInput and Output

CS-3013, C-Term 2014

56

Main Memory

CPU

Bitmap

Digital to

Analog

Video

Slide57

GUI Device — Displaying Text

Font: an array of bitmaps, one per characterDesigned to be pleasing to eyebitblt: (Bit-oriented Block Transfer)An operation to copy a rectangular array of pixels from one bitmap to anotherInput and OutputCS-3013, C-Term 2014

57

A

B

C

D

E

F

Bitmap

bitblt

Dog

Slide58

GUI Device – Color

Monochrome: one bit per pixelforeground vs. backgroundColor: 2-32 bits per pixelDirect vs. Color paletteDirect: (usually) 8 bits each per Red, Green, BluePalette: a table of length 2p, for p-bit pixels Each entry (usually) 8 bits each for RGBInput and Output

CS-3013, C-Term 2014

58

Slide59

GUI Device – Cursor

A small bitmap to overlay main bitmapHardware supportSubstitute cursor bits during each frameSoftware implementationBitblt area under cursor to temporary bitmapBitblt cursor bitmap to main bitmapRestore area under cursor from temporary bitmapVery, very tricky!Timing is critical for smooth appearanceBest with double-buffered main bitmap

Input and Output

CS-3013, C-Term 2014

59

Slide60

GUI Device – Window

A virtual bitmapsize, position, clipping boundariesfont, foreground and background colorsA list of operations needed to redraw contentsOperations to window itself:–write(), refresh()Input and Output

CS-3013, C-Term 201460

Called by application to add/change information

Called by window manager to redraw current contents

Slide61

GUI Device — Text Window

Character terminal emulated in a windowRS-232 character set and controls/dev/ttyOperates like a character terminal with visible, partially obscured, or completely coveredInput and OutputCS-3013, C-Term 201461

Slide62

Modern GUI devices

Input and OutputCS-3013, C-Term 201462

ISA bridge

IDE disk

Main Memory

Processor

Level 2 cache

Bridge

Moni

-

tor

Graphics card

USB

Key-

board

Mouse

Ether-

net

SCSI

Modem

Sound

card

Printer

PCI bus

ISA bus

PCI Express

Slide63

Modern GUI Devices (continued)

Double-buffered bitmap in Graphics cardGraphics and information written/drawn in back bufferMonitor refreshes from main buffer (60+ Hz)Refresh interrupt at start of every frameBitblt to substitute cursorCPU writes text, etc.Graphics processor (GPU) draws images, vectors, polygonsWindow manager orders redraw when necessaryInput and Output

CS-3013, C-Term 2014

63

CPU

Bridge

Moni

-

tor

Graphics card

Slide64

Questions?

Reading Assignment Tanenbaum, Chapter 5CS-3013, C-Term 2014Input and Output64