• 沒有找到結果。

Operating System: Chap13 I/O Systems

N/A
N/A
Protected

Academic year: 2021

Share "Operating System: Chap13 I/O Systems"

Copied!
39
0
0

加載中.... (立即查看全文)

全文

(1)

Operating System:

Chap13 I/O Systems

National Tsing-Hua University

2016, Fall Semester

(2)

Outline

Overview

I/O Hardware

I/O Methods

Kernel I/O Subsystem

Performance

Application Interface

(3)

Chapter13 I/O Systems

Overview

The two main jobs of a computer

I/O

and

Computation

I/O devices : tape, HD, mouse, joystick, network card, screen, flash disks, etc

I/O subsystem : the methods to control all I/O devices

Two conflicting trends

Standardization of HW/SW interfaces

Board variety of I/O devices

Operating System Concepts – NTHU LSA Lab 3

(4)

Overview

Device drivers : a uniform device-access interface to the I/O subsystem

Similar to system calls between apps and OS

Device categories

Storage devices: disks, tapes

Transmission devices: network cards, modems

Human-interface devices: keyboard, screen, mouse

Specialized devices: joystick, touchpad

(5)

Chapter13 I/O Systems

I/O Hardware

Port : A connection point between I/O devices and the host

E.g.: USB ports

Bus : A set of wires and a well-defined protocol that specifies messages sent over the wires

E.g.: PCI bus

Controller : A collection of electronics that can operate a port, a bus, or a device

A controller could have its own processor, memory, etc. (E.g.: SCSI controller)

Operating System Concepts – NTHU LSA Lab 5

(6)

Typical PC Bus Structure

(7)

Chapter13 I/O Systems

Basic I/O Method (Port-mapped I/O)

Each I/O port (device) is identified by a unique port address

Each I/O port consists of four registers (1~4Bytes)

Data-in register: read by the host to get input

Data-out register: written by the host to send output

Status register: read by the host to check I/O status

Control register: written by the host to control the device

Program interact with an I/O port through

special I/O instructions

(different from mem. access)

X86: IN, OUT

Operating System Concepts – NTHU LSA Lab 7

(8)

Device I/O Port Locations on PCs (partial)

(9)

Chapter13 I/O Systems

I/O Methods Categorization

Depending on how to address a device:

Port-mapped I/O

Use different address space from memory

Access by special I/O instruction (e.g. IN, OUT)

Memory-mapped I/O

Reserve specific memory space for device

Access by standard data-transfer instruction (e.g. MOV)

More efficient for large memory I/O (e.g. graphic card)

Vulnerable to accidental modification, error

Operating System Concepts – NTHU LSA Lab 9

(10)

I/O Methods Categorization

Depending on how to interact with a device:

Poll (busy-waiting): processor periodically check status register of a device

Interrupt: device notify processor of its completion

Depending on who to control the transfer:

Programmed I/O: transfer controlled by CPU

Direct memory access (DMA) I/O: controlled by DMA controller (a special purpose controller)

Design for large data transfer

Commonly used with memory-mapped I/O and interrupt I/O method

(11)

Chapter13 I/O Systems

Six-Step Process to Perform DMA (Direct Memory Access)

Operating System Concepts – NTHU LSA Lab 11

(12)

Review Slides ( I )

Definition of I/O port? Bus? Controller?

I/O device and CPU communication?

Port-mapped vs. Memory-mapped

Poll vs. Interrupt

Programmed I/O vs. DMA

Steps to handle an interrupt I/O and DMA

request?

(13)

Chapter13 I/O Systems Operating System Concepts - NTHU EOS Lab 13

Kernel I/O Subsystem

(14)

I/O Subsystem

I/O Scheduling – improve system performance by ordering the jobs in I/O queue

e.g. disk I/O order scheduling

Buffering – store data in memory while transferring between I/O devices

Speed mismatch between devices

Devices with different data-transfer sizes

Support copy semantics

(15)

Chapter13 I/O Systems

I/O Subsystem

Caching – fast memory that holds copies of data

Always just a copy

Key to performance

Spooling – holds output for a device

e.g. printing (cannot accept interleaved files)

Error handling – when I/O error happens

e.g. SCSI devices returns error information

I/O protection

Privileged instructions

Operating System Concepts – NTHU LSA Lab 15

(16)

UNIX I/O Kernel Data Structure

Linux treats all I/O devices like a file

(17)

Chapter13 I/O Systems

Device-status Table

Operating System Concepts – NTHU LSA Lab 17

(18)

Blocking and Nonblocking I/O

Blocking - process suspended until I/O completed

Easy to use and understand

Insufficient for some needs

Use for synchronous communication & I/O

Nonblocking

Implemented via multi-threading

Returns quickly with count of bytes read or written

Use for asynchronous communication & I/O

(19)

Chapter13 I/O Systems

Life Cycle of An I/O Request

Operating System Concepts – NTHU LSA Lab 19

In buffer Physical I/O

Data transfer Check buffer

cache

Move process from run queue to wait queue

Allocate kernel buffer Schedule I/O

(20)

Performance

I/O is a major factor in system performance

It places heavy demands on the CPU to execute device driver code

The resulting context switches stress the CPU and its hardware caches

I/O loads down the memory bus during data copy between controllers and physical memory, …

Interrupt handling is a relatively expensive task

Busy-waiting could be more efficient than interrupt- driven if I/O time is small

(21)

Chapter13 I/O Systems

Improving Performance

Reduce number of context switches

Reduce data copying

Reduce interrupts by using large transfers, smart controllers, polling

Use DMA

Balance CPU, memory, bus, and I/O performance for highest throughput

Operating System Concepts – NTHU LSA Lab 21

(22)

Review Slides ( II )

What are the key I/O services

Scheduling

Cache

Buffering

Spooling

Error handling

I/ protection

How to improve system performance?

(23)

Chapter13 I/O Systems Operating System Concepts - NTHU EOS Lab 23

Application I/O Interface

(24)

A Kernel I/O Structure

Device drivers: a uniform device-access interface to the I/O subsystem; hide the differences among device

controllers from the I/O sub-system of OS

(25)

Chapter13 I/O Systems

Characteristics of I/O Devices

Operating System Concepts – NTHU LSA Lab 25

(26)

I/O Device Class

Device class is fairly standard across different OS

Block I/O

Char-stream I/O

Memory-mapped file access

Network sockets

Clock & timer interfaces

Back-door interfaces (e.g. ioctl() )

Enable an application to access any functionality

implemented by a device driver without the need to invent a new system call

(27)

Chapter13 I/O Systems

Block & Char Devices

Block devices: disk drives

system calls: read( ), write( ), seek( )

Memory-mapped file can be layered on top

Char-stream devices: mouse, keyboard, serial ports

system calls: get( ), put( )

Libraries layered on top allow line editing

Operating System Concepts – NTHU LSA Lab 27

(28)

Network Devices

Varying enough from block and character to have own interface

System call: send(), recv(), select()

select() returns which socket is waiting to send or receive, eliminates the need of busy waiting

Many other approaches

pipes, FIFOS, STREAMS, message queues

(29)

Chapter13 I/O Systems

Reading Material & HW

13.1 – 13.6

Problem Set

13.2

13.5

13.6

13.8

Operating System Concepts – NTHU LSA Lab 29

(30)

Interrupt Vector Table

Intel Pentium Processor:

(31)

Chapter13 I/O Systems

CPU and device Interrupt handshake

1. Device asserts interrupt request (IRQ)

2. CPU checks the interrupt request line at the beginning of each instruction cycle

3. Save the status and address of interrupted process

4. CPU acknowledges the interrupt and search the

interrupt vector table for interrupt handler routines

5. CPU fetches the next instruction from the interrupt handler routine

6. Restore interrupted process after executing interrupt handler routine

Operating System Concepts – NTHU LSA Lab 31

(32)

Interrupt Prioritization

Maskable interrupt: interrupt with

priority lower than current priority is not recognized until pending interrupt is

complete

Non-maskable interrupt (NMI): highest- priority, never masked

Often used for power-down, memory error

(33)

Chapter13 I/O Systems Operating System Concepts – NTHU LSA Lab 33

Interrupt-Driven I/O

CPU executing checks for interrupts between instructions

CPU Controller

initiates I/O 2

input ready, output complete, or error Generates interrupt signal

3 CPU receiving interrupt,

transfers control to Interrupt handler

4

interrupt handler processes data, returns from interrupt

5

CPU resumes processing of interrupted task

6 device driver

initiates I/O 1

7

(34)

Summary of Services in I/O Subsystem

The management of the name space for files and devices

Access control to files and devices

Operation control

File system space allocation

Disk allocation

Buffering, caching, and spooling

I/O scheduling

Device status monitoring, error handling, and failure recovery

Device driver configuration and initialization

(35)

Chapter13 I/O Systems

I/O Requests to Hardware Operations

Consider reading a file from disk for a process

Determine device holding file

Translate name to device representation

Physically read data from disk into buffer

Make data available to requesting process

Return control to process

Operating System Concepts – NTHU LSA Lab 35

(36)

Layered File System revisited

Logical File System Application Programs

File-Organization Module

Basic File System

I/O Control

Devices

Given a symbolic file name, use directory to provide values needed by FOM

Transform logical address to physical block address Numeric disk address

Driver: hardware instructions write(data_file, item)

file name

information of data_file

2144th block

driver 1, cylinder 73, surface 2, sector 10

(37)

Chapter13 I/O Systems

Intercomputer Communications

Network traffic could cause high context switch rate

Interrupt generated during keyboard & network I/O

Context switch occurs between prog. & kernel (drivers)

Operating System Concepts – NTHU LSA Lab 37

keyboard

e.g. telnet

e.g. telnet session

(38)

STREAMS

A full-duplex communication channel

between a user-level process and a device

STREAM provides a framework for a modular

and incremental approach to writing device

drivers and network protocols

(39)

Chapter13 I/O Systems

The STREAM Structure

A STREAM consists of

STREAM head interfaces with user process

Driver end interfaces with the device

zero or more STREAM modules between them

Each module contains a read and a write queue

Message passing is used to communicate between

queues

Operating System Concepts – NTHU LSA Lab 39

參考文獻

相關文件

This kind of algorithm has also been a powerful tool for solving many other optimization problems, including symmetric cone complementarity problems [15, 16, 20–22], symmetric

微算機基本原理與應用 第15章

She has to face all these life choices by herself, makes her own decisions and face the consequences...I was told the other day that I could not even make an appointment for

• Nearpod allows the teacher to create interactive lessons that are displayed on the student device while they are teaching2. • During the lesson students interact with the program

// VM command following the label c In the VM language, the program flow abstraction is delivered using three commands:.. VM

n Media Gateway Control Protocol Architecture and Requirements.

This algorithm has been incorporated into the FASTA program package, where it has decreased the amount of memory required to calculate local alignments from O(NW ) to O(N )

In this paper, by using Takagi and Sugeno (T-S) fuzzy dynamic model, the H 1 output feedback control design problems for nonlinear stochastic systems with state- dependent noise,