1 input/output the messiest part of o.s. chap11. 2 speed difference of i/o hardware

81
1 Input/Output The messiest part of O.S. Chap11

Post on 21-Dec-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

1

Input/OutputThe messiest part of O.S.

Chap11

Page 2: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

2

Speed difference of I/O Hardware

Page 3: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

3

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

Page 4: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

4

Memory-Mapped I/O (1)

• Separate I/O and memory space• Memory-mapped I/O• Hybrid

Page 5: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

5

Memory-Mapped I/O (2)

(a) A single-bus architecture(b) A dual-bus memory architecture

Page 6: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

6

I/O Architecture

• Several types of bus,such as ISA, EISA,PCI and MCA, are currently in use.

• data bus – the pentium has 64 bit wide data bus• Address bus – • Control bus – a group of lines that transmit control

information to the connected circuits. The Pentium uses control lines to specify, for example, whether the bus is used to allow data transfers between a processor and the RAM, or alternatively, between a processor and an I/O device.

Page 7: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

7

CPUCPU

I/O busI/O bus

I/O PortI/O Port I/O PortI/O Port

I/O InterfaceI/O Interface

I/O ControllerI/O Controller

PC’s I/O architecturePC’s I/O architecture

Page 8: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

8

PC’s I/O architecture

• When a bus connects to the CPU to an I/O device, it is called an I/O bus.

• 80x86 use 16 out of the 32 address lines to address I/O devices and 8,16, or 32 out of the 64 data lines to transfer data

Page 9: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

9

I/O ports

• Each device connected to the I/O bus has its own I/O address, which are usually called I/O ports

• PC provides up to 65536 8-bits I/O ports. Two consecutive 8-bit ports may be regarded as a single 16-bit port.

• Four assembly instructions in,ins,out,outs allow CPU to read and write into an I/O port

Page 10: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

10

Memory mapped I/O ports in PC

• PC’s device I/O ports may also be mapped into address of physical address space.

• O.S. can use mov instruction that operate directly on memory.

• Modern hardware devices are more suited to mapped I/O, since it is faster and can be combined with DMA

Page 11: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

11

I/O and registers

• The I/O ports of each device are actually structured into a set of specialized registers

• CPU write commands to control registers• CPU reads a value that represents the internal

state of the device from status register• CPU fetch data from a device by reading input

register• CPU push data to device by writing bytes into

output registers

Page 12: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

12

CPUCPU

Control registerControl register

Status registerStatus register

input registerinput register

Output registerOutput register

Device’sDevice’sI/O InterfaceI/O Interface

Specialized I/O ports

Page 13: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

13

• To lower costs, the same I/O port is often used for different purposes. e.g., some bits describe the device state and others are used to specifycommands.e.g., the same I/O ports may be used as an input register or an output register

Page 14: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

14

What is an I/O interface?

• An I/O interface is a hardware circuit inserted between a group of I/O ports and the corresponding device controller.

• It acts as an interpreter that translates the values in the I/O ports into commands and data for the device.

Page 15: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

15

Types of I/O interfaces

• Custom I/O interfaces– devoted to one specific hardware device– usually, the device controller is on the

same card of I/O interfaces.

• General-purpose I/O interface– used to connect several different

hardware devices

Page 16: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

16

Custom I/O interfaces

• Keyboard interface• Graphic interface • Disk interface• Network interface

Page 17: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

17

General –purpose I/O interface

• Parallel port– traditionally connected to printers, but can also be

connected to removable disks, scanners

• Serial port– one bit at a time– use UART chip (Universal Asynchronous Receiver and

Transmitter) to string out the bytes into a sequence of bits.

• Universal serial bus (USB)• PCMCIA interface• SCSI (Small Computer System Interface) Interface

Page 18: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

18

Device Controller

• It interprets the high-level commands received from the I/O interface and force the device to execute specific actions by sending proper sequence of electrical signals

• It converts and properly interprets the electrical signals received from the device and modifies (through the I/O interface) the value of the status register

Page 19: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

19

I/O shared memory

• Several hardware device sometimes include their own memory, which is often called I/O shared memory. E.g. graphic cards.

Page 20: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

20

PC’s mapping addressesof I/O shared memory

• For device connected to ISA bus– mapped into physical address from

0xa0000 to 0xfffff: a hole between 640K-1MB. These are reserved page frames

• For some old devices using VESA Local bus– 0xe00000 to 0xffffff : 14MB-16MB– going out of production

• For device connected to PCI bus– is mapped into very large physical address, well above the end

of RAM’s physical address. Much simpler to handle• AGP (Accelerated Graphics Port)

– use a special hardware circuit GART (Graphics Address Remapping Table)

– GART enables AGP to sustain much higher data transfer rate.

Page 21: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

21

Direct Memory Access (DMA)

Operation of a DMA transfer

Page 22: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

22

Interrupts Revisited

How interrupts happens. Connections between devices and interrupt controller actually use interrupt lines on the bus rather than dedicated wires

Page 23: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

23

Principles of I/O SoftwareGoals of I/O Software (1)

• Device independence– programs can access any I/O device – without specifying device in advance

· (floppy, hard drive, or CD-ROM)

• Uniform naming– name of a file or device a string or an

integer– not depending on which machine

• Error handling– handle as close to the hardware as possible

Page 24: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

24

Goals of I/O Software (2)

• 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

Page 25: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

25

Programmed I/O (1)

Steps in printing a string

Page 26: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

26

Programmed I/O (2)

Writing a string to the printer using programmed I/O

Page 27: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

27

Interrupt-Driven I/O

• Writing a string to the printer using interrupt-driven I/O– Code executed when print system call is made– Interrupt service procedure

Page 28: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

28

I/O Using DMA

• Printing a string using DMA– code executed when the print system call is made– interrupt service procedure

Page 29: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

29

I/O Software Layers

Layers of the I/O Software System

Page 30: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

30

Interrupt Handlers (1)

• Interrupt handlers are best hidden– have driver starting an I/O operation block until

interrupt notifies of completion

• Interrupt procedure does its task– then unblocks driver that started it

• Steps must be performed in software after interrupt completed

1. Save regs not already saved by interrupt hardware

2. Set up context for interrupt service procedure

Page 31: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

31

Interrupt Handlers (2)

3. Set up stack for interrupt service procedure4. Ack interrupt controller, reenable interrupts5. Copy registers from where saved6. Run service procedure 7. Set up MMU context for process to run next8. Load new process' registers9. Start running the new process

Page 32: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

32

Device Drivers

• Logical position of device drivers is shown here• Communications between drivers and device controllers goes

over the bus

Page 33: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

33

Device-Independent I/O Software (1)

Functions of the device-independent I/O software

Uniform interfacing for device drivers

Buffering

Error reporting

Allocating and releasing dedicate devices

Providing a device-independent block size

Page 34: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

34

Device-Independent I/O Software (2)

(a) Without a standard driver interface(b) With a standard driver interface

Page 35: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

35

Device-Independent I/O Software (3)

(a) Unbuffered input(b) Buffering in user space(c) Buffering in the kernel followed by copying to user

space(d) Double buffering in the kernel

Page 36: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

36

Device-Independent I/O Software (4)

Networking may involve many copies

Page 37: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

37

User-Space I/O Software

Layers of the I/O system and the main functions of each layer

Page 38: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

38

UNIX I/O (1)/Device Driver

Some of the fields of a typical cdevsw table

Page 39: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

39

UNIX I/O (2)

The UNIX I/O system in BSD

Page 40: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

40

Streams

An example of streams in System V

Page 41: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

41

Disk Hardware (1)

Disk parameters for the original IBM PC floppy disk and a Western Digital WD 18300 hard disk

Page 42: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

42

Disk Hardware (2)

• Physical geometry of a disk with two zones• A possible virtual geometry for this disk

Page 43: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

43

Disk Hardware (3)

• Raid levels 0 through 2 • Backup and parity drives are shaded

Page 44: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

44

Disk Hardware (4)

• Raid levels 3 through 5• Backup and parity drives are shaded

Page 45: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

45

Disk Hardware (5)

Recording structure of a CD or CD-ROM

Page 46: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

46

Disk Hardware (6)

Logical data layout on a CD-ROM

Page 47: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

47

Disk Hardware (7)

• Cross section of a CD-R disk and laser– not to scale

• Silver CD-ROM has similar structure– without dye layer– with pitted aluminum layer instead of gold

Page 48: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

48

Disk Hardware (8)

A double sided, dual layer DVD disk

Page 49: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

49

Disk Formatting (1)

A disk sector

Page 50: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

50

Disk Formatting (2)

An illustration of cylinder skew

Page 51: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

51

Disk Formatting (3)

• No interleaving• Single interleaving• Double interleaving

Page 52: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

52

Disk Arm Scheduling Algorithms (1)

• Time required to read or write a disk block determined by 3 factors

1. Seek time2. Rotational delay3. Actual transfer time

• Seek time dominates• Error checking is done by controllers

Page 53: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

53

Disk Arm Scheduling Algorithms (2)

Shortest Seek First (SSF) disk scheduling algorithm

Initialposition

Pendingrequests

Page 54: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

54

Disk Arm Scheduling Algorithms (3)

The elevator algorithm for scheduling disk requests

Page 55: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

55

Error Handling

• A disk track with a bad sector• Substituting a spare for the bad sector• Shifting all the sectors to bypass the bad

one

Page 56: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

56

Stable Storage

Analysis of the influence of crashes on stable writes

Page 57: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

57

ClocksClock Hardware

A programmable clock

Page 58: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

58

Clock Software (1)

Three ways to maintain the time of day

Page 59: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

59

Clock Software (2)

Simulating multiple timers with a single clock

Page 60: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

60

Soft Timers

• A second clock available for timer interrupts– specified by applications– no problems if interrupt frequency is low

• Soft timers avoid interrupts– kernel checks for soft timer expiration before

it exits to user mode– how well this works depends on rate of

kernel entries

Page 61: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

61

Character Oriented TerminalsRS-232 Terminal Hardware

• An RS-232 terminal communicates with computer 1 bit at a time• Called a serial line – bits go out in series, 1 bit at a time• Windows uses COM1 and COM2 ports, first to serial lines• Computer and terminal are completely independent

Page 62: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

62

• Central buffer pool• Dedicated buffer for each terminal

Input Software (1)

Page 63: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

63

Input Software (2)

Characters handled specially in canonical mode

Page 64: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

64

Output Software

The ANSI escape sequences• accepted by terminal driver on output• ESC is ASCII character (0x1B)• n,m, and s are optional numeric parameters

Page 65: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

65

Display Hardware (1)

Memory-mapped displays• driver writes directly into display's video RAM

Parallel port

Page 66: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

66

Display Hardware (2)

• A video RAM image – simple monochrome display– character mode

• Corresponding screen– the xs are attribute bytes

Page 67: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

67

Input Software

• Keyboard driver delivers a number– driver converts to characters– uses a ASCII table

• Exceptions, adaptations needed for other languages– many OS provide for loadable keymaps or

code pages

Page 68: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

68

Output Software for Windows (1)

Sample window located at (200,100) on XGA display

Page 69: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

69

Output Software for Windows (2)

Skeleton of a Windows main program (part 1)

Page 70: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

70

Output Software for Windows (3)

Skeleton of a Windows main program (part 2)

Page 71: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

71

Output Software for Windows (4)

An example rectangle drawn using Rectangle

Page 72: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

72

Output Software for Windows (5)

• Copying bitmaps using BitBlt.– before– after

Page 73: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

73

Output Software for Windows (6)

Examples of character outlines at different point sizes

Page 74: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

74

Network TerminalsX Windows (1)

Clients and servers in the M.I.T. X Window System

Page 75: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

75

X Windows (2)

Skeleton of an X Windows application program

Page 76: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

76

The SLIM Network Terminal (1)

The architecture of the SLIM terminal system

Page 77: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

77

The SLIM Network Terminal (2)

Messages used in the SLIM protocol from the server to the terminals

Page 78: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

78

Power Management (1)

Power consumption of various parts of a laptop computer

Page 79: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

79

Power management (2)

The use of zones for backlighting the display

Page 80: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

80

Power Management (3)

• Running at full clock speed

• Cutting voltage by two – cuts clock speed by two, – cuts power by four

Page 81: 1 Input/Output The messiest part of O.S. Chap11. 2 Speed difference of I/O Hardware

81

Power Management (4)

• Telling the programs to use less energy– may mean poorer user experience

• Examples– change from color output to black and

white– speech recognition reduces vocabulary– less resolution or detail in an image