0% found this document useful (0 votes)
5 views44 pages

OS Chap 5 - Eng - Hust Theme

The document discusses I/O management in operating systems, focusing on general management principles, system I/O services, and disk I/O systems. It covers topics such as device types, interrupt handling, buffering techniques, and disk access scheduling algorithms. Various algorithms like FCFS, SSTF, SCAN, and C-SCAN are analyzed for their effectiveness in minimizing seek time during disk I/O operations.

Uploaded by

Anh Pham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views44 pages

OS Chap 5 - Eng - Hust Theme

The document discusses I/O management in operating systems, focusing on general management principles, system I/O services, and disk I/O systems. It covers topics such as device types, interrupt handling, buffering techniques, and disk access scheduling algorithms. Various algorithms like FCFS, SSTF, SCAN, and C-SCAN are analyzed for their effectiveness in minimizing seek time during disk I/O operations.

Uploaded by

Anh Pham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 44

Principles of Operating Systems

• Đỗ Quốc Huy
[email protected]
• Department of Computer Science
• School of Information and Communication Technology
Chapter 5 I/O Management

① General management principle


② System I/O service
③ Disk I/O system
Chapter 5: IO Management
1. General management principle

• Introduction

• Interrupt and Interrupt handle


Chapter 5 I/O management
1. General management principle
1.1 Introduction

IO device
• Diversity, many kinds, different types
• Engineering perspective: device with processor, motor, and other parts
• Programming perspective: Interface like software to receive, executive
command and return result
• Catergorize
• Block device (disk, magnetic tape)
• Information is stored with fixed size and private address
• Possible to read/write a block independent from other
• Operation to locate information exist (seek)
• Character device (printer, keyboard, mouse,..)
• Accept a stream of chracter, without block structure
• No information localization operation
• Other type: Clock
1. General management principle
1.1 Introduction

Controller device I

• Peripheral devices are diversity with many types


• CPU do not know them all ⇒ No individual signal for each device
• Processor do not control device directly
• Peripheral device is connected to the system via Device controller (DC)
Chapter 5: IO Management
1. General management principle
1.1 Introduction
Controller device I
I
• Electrical circuit attached to the mainboard’s slot
1. General management principle
1.1 Introduction

Controller device III

• Each DC can control 1,2,4,..


peripheral devices
• Depend on the number of
connector on the DC
• If the controller interface is
standard (ANSI, IEEE,
ISO,...) -> can connect to
different devices

• Each DC has its own register to work with CPU


• Use special address space for registers: IO port
Chapter 5: IO Management
1. General management principle
1.1 Introduction
Controller device III
• Controller and device interface: Low level interface
• Sector = 512bytes = 4096bits
• Disk controller must read/write bits and group them into sectors
• OS only work with controller
• Via device’s registers
• Commands and parameters are putted into controller’s
registers
• When a command is accepted by the controller, CPU let the
controller work itself and turn to other job
• When command is finished, controller notify CPU via
interrupt signal
• CPU take result and device status via controlling device’s
register
Chapter 5: IO Management
1. General management principle
1.1 Introduction
Device driver
• Code segment in system’s kernel allow interactive with hardware device
• Provide standard interface for different I/O devices
Chapter 5: IO Management
1. General management principle
1.1 Introduction
Device driver
• Categorized into 2 levels
• High level: Access via system calls
• Implement standard calls: open(), close(), read(), write()...
• Interface between kernel and driver
• High level thread wake up IO device then put control device
thread into temporary sleep

• Low level: Perform via interrupt procedure


• Read input data or bring out next data block
• Wake up the High level’s temporary sleep thread when IO finish
Chapter 5: IO Management
1. General management principle
1.1 Introduction
IO request cycle
Chapter 5: IO Management
1. General management principle
1.1 Introduction
Peripheral device – Operating system interact
• After sending request to device, OS need to acknowledge
• When device finish request
• If device has error
• 2 methods to acknowledge
• I/O interrupts
• Device generate an interrupt signal to let CPU know
• IRQ: physical path to interrupt manager
• Map IRQ signal to interrupt vector
• Call to interrupt handle routine
• Polling
• OS timely check device’s status register
• Waste checking period if the IO operation is not frequent
• Nowadays device can combine 2 methods (E.g. high bandwidth
network device)
• Send interrupt when first packet arrive
• Pooling next coming packet until the buffer is empty
Chapter 5: IO Management
1. General management principle

⚫Introduction

⚫Interrupt and Interrupt handle


1. General management principle
1.2 Interrupt and Interrupt handle

Interrupt definition

Mechanism to help device let the processor know its status

Phenomenon that a process is suddenly stopped, and the


system executive other process correspond to an event
1. General management principle
1.2 Interrupt and Interrupt handle

Classification

• Based on Source
• Internal interrupt
• External interrupt
• Based on device
• Hard
• Soft
• Based on handling ability
• maskable
• unmask able
• Based on interrupt moment
• Request
• Report
1. General management principle
1.2 Interrupt and Interrupt handle

Interrupt handle

① Write characteristic of event caused the interrupt into defined


memory area

② Save interrupted process 'state

③ Change address of interrupt handle routine to instruction


pointer register
⚫ Utilize interrupt vector table (IBM-PC)

④ Run interrupt handle routine

⑤ Restore interrupted process


⚫ Interrupt >< procedure !?
Chapter 5 I/O Management

①General management principle


②System I/O service
③Disk I/O system
2. System I/O service
2.1. Buffer

⚫Buffer
⚫SPOOL mechanism
2. System I/O service
2.1. Buffer

General conception

• Peripheral device’s characteristic: operate slow


• Active the device
• Wait for device to get to proper working status
• Wait for IO operation to be performed
• To Guarantee the system’s performance -> need to
• Reduce number of IO operations, work with block of data
• Perform IO operations parallelly with other operations
• Perform accessing operation in advance

Buffer: Intermediate memory area, utilized for storing


information during IO operation
2. System I/O service
2.1. Buffer

Buffer classification I

• Input buffer
• Can perform data access command
• Example: read data from disk

• Output buffer
• Information is putted into buffer, when buffer’s full, buffer
content is then written to device
2. System I/O service
2.1. Buffer

Buffer classification II
• Buffer attached to device
• Constructed when open device/file
• Serve device only, cleared when device is close
• Good when devices have different physical record’s structures
• Buffer attached to system
• Constructed when the system start, not attached to a specific
device
• Exist during system working process
• Open file/device ⇒ attach to already available buffer
• Close device/file ⇒ buffer returned to system
• Good for devices have same physical record’s structure
2. System I/O service
2.1. Buffer

Buffer organization

• Value buffer
• Input buffer
• Output buffer
• Processing buffer
• Circular buffer
• Input buffer
• Output buffer
• Processing buffer
2. System I/O service
2.1. Buffer

Buffer organization

• Value buffer
• Input buffer
• Output buffer read(f,a);
read(f,a);

Gi n
AM ị
át
biế
r
a
2. System I/O service
2.1. Buffer

Buffer organization

• Processing buffer

Đị ron ệm

AM
ac
ph
t read(f,a);
hỉ g
òn

biế

n
a
2. System I/O service
2.1. Buffer

Buffer organization

• Circular buffer
• Input buffer
• Output buffer
• Processing buffer Write
Read

Process
2. System I/O service
2.2 Spool

⚫Buffer
⚫SPOOL mechanism
2. System I/O service
2.2 Spool

SPOOL (Simultaneous Peripheral Operation On-line)

• From programming perspective, IO device is


• Station to receive request from program and perform
• Return status code to be analyzed by the system
• -> use software to simulate IO device
• IO device can be treated as process
• Synchronized like in process management
• Objective
• Simulate process of controlling and managing peripheral
device
• Check creating device working status
• Create parallel effect for sequential device
2. System I/O service
2.2 Spool

SPOOL: Virtual printer


2. System I/O service
2.2 Spool

SPOOL:IO example
Chapter 5 I/O Management

①General management principle


②System I/O service
③Disk I/O system
3. Disk I/O device

⚫Disk structure
⚫Disk accessing scheduling
3. Disk I/O device
3.1 Disk structure

Structure

• Modelled as array of logic blocks


• logic block is the smallest exchange unit
• Map continuous logic block to disk’s sector
• Block 0 is first sector header 0 outer most track/Cylinder
• Mapping follow an order: Sector → Header → Track/Cylinder
• Reading header do not need to move much when read sector next to
each other
3. Disk I/O device
3.1 Disk structure

Disk accessing problem


• OS is responded for effectively exploit the hardware
• For disk: Fast access time and high bandwidth
• Bandwidth is calculated based on
• Total bytes exchanged
• Time from the first service request until the request is
completed
• Access time consist of 2 parts
• Seek time : Time to move header to cylinders contain
required sector
• Rotational latency: Time to wait until disk rotate to required
sector
3. Disk I/O device
3.2 Disk accessing scheduling

⚫Disk structure
⚫Disk accessing scheduling
3. Disk I/O device
3.2 Disk accessing scheduling

Algorithm

• Objective: minimize seek time


• Seek time ≈ moving distance
• Algorithm for disk IO request scheduling
• FCFS:First Come First Served
• SSTF: Shortest Seek Time First
• SCAN
• C-SCAN: Circular SCAN
• LOOK/C-LOOK

• Assumption
• Accessing requests 98, 183, 37, 122, 14, 124, 65, 67
• Header current position at cylinder 53
3. Disk I/O device
3.2 Disk accessing scheduling

FCFS
Access follow the request order ⇒Not effective
Accessing requests 98, 183, 37, 122, 14, 124, 65, 67

45
85
146
85
108
Total: 630
110
59
2
3. Disk I/O device
3.2 Disk accessing scheduling

SSTF
Select access has smallest seek time from current position ⇒A
request may wait forever if new appearing requests closer to header (similar to SJF)
Accessing requests 98, 183, 37, 122, 14, 124, 65, 67

12
2
30

23
84
24 Total: 236
2
59
3. Disk I/O device
3.2 Disk accessing scheduling

SCAN
Header move from outer most cylinder to innermost cylinder and return. Serve
request met on the way

Accessing requests 98, 183, 37, 122, 14, 124, 65, 67

15
Header is moving to cylinder 0
23
14

65 2
31
24 Total: 235
2
59
3. Disk I/O device
3.2 Disk accessing scheduling

C-SCAN
Principle: Treat cylinders like a circular linked list: Outer most Cylinder connect
with innermost cylinder

• Header move from outermost cylinder to innermost cylinder


• Serve request met on the way
• When inner most Cylinder is reached, return to outermost Cylinder
• Do not serve request met on the way

• Remark: Retrieve more equal waiting time than SCAN


• When header reach to one side of disk (innermost/outermost
cylinders), density of requests appear at other side will be higher
than current place (reason: header just passing by). This request need
to wait longer ⇒ Return to other side immediately
3. Disk I/O device
3.2 Disk accessing scheduling

C-SCAN
Header move from outermost cylinder to innermost cylinder and return. Serve
request met on the way

Accessing requests 98, 183, 37, 122, 14, 124, 65, 67


3. Disk I/O device
3.2 Disk accessing scheduling

LOOK/ C-LOOK
SCAN/C-SCAN’s version: Header does not move to outermost/innermost cylinders,
only to farthest request at 2 sides and return

Accessing requests 98, 183, 37, 122, 14, 124, 65, 67


3. Disk I/O device
Chapter 5: IO Management
3.2 Disk accessing scheduling

Conclusion

• SSTF: More popular, more efficient than FCFS

• SCAN/C-SCAN works better for systems with lots of disk access


requests
• No starvation problem: “Queue too long“

• The efficiency of the algorithms depends on the number and type


of requests
3. Disk I/O device
Chapter 5: IO Management
3.2 Disk accessing scheduling

Conclusion

• Disk access requests are affected by disk allocation methods for files
• Continuous Allocation: making requests to access adjacent to each
other
• Link/index Allocation: can include widely split blocks on disk

• Disk access control algorithms can be written as separate modules of


the OS allowing them to be replaced by other algorithms as needed.

• Both SSTF and LOOK can be reasonable choices for the default algorithm

You might also like