Lecture 26 I/O Systems

Download Report

Transcript Lecture 26 I/O Systems

Lecture 26
I/O Systems II
Fall 2000
M.B. Ibáñez
Application I/O Interface
• I/O system calls encapsulate device
behaviors in generic classes
• We discuss structuring techniques and
interfaces for the operating system that
enable I/O devices to be treated in a
standard, uniform way
• The approach involves abstraction,
encapsulation, and software layering
Fall 2000
M.B. Ibáñez
Block-device interface
• The block device interface captures all the aspects
necessary for accessing disk drivers and other blockoriented devices (disks, tapes)
• They store information in blocks that are usually fixed
size, and transfers are made a block at a time
• The device understands commands such as read and write
• If it is a random-access device, it has a seek command to
specify which block to transfer next
Fall 2000
M.B. Ibáñez
Character-stream interface
• The basic system calls in this interface enable an
application to get or put one character
• On top of this interface, libraries can be built that
offer line-at-a-time access, with buffering and
editing services
• Convenient for
– input devices such as keyboards, mice, and modems
– output devices such as printers or audio boards
Fall 2000
M.B. Ibáñez
Network Devices
• Network I/O differ significantly from disk I/O
• One interface that is available in many operating
systems is the network socket interface
• The system calls in the socket interface enable an
application to
–
–
–
–
Fall 2000
Create a socket
Connect a local socket to a remote address
Listen for any remote application to plug into the local socket
Send and receive packets over the connection
M.B. Ibáñez
Clocks and Timers
• Most computers have hardware clocks and
timers that provide three basic functions
– Give the current time
– Give the elapsed time
– Set a timer to trigger operation O at time T
Fall 2000
M.B. Ibáñez
Blocking System Call
• When an application issues a blocking system call,
the execution of the application is suspended
• The application is moved from the OS’s run queue
to a wait queue
• After the system call completes, the application is
moved back to the run queue, where it is eligible
to resume execution, at which time it will receive
the values returned by the system call
Fall 2000
M.B. Ibáñez
Non blocking (asynchronous) I/O
• Examples of non-blocking I/O
– User interface that receives keyboard and mouse input while
processing and displaying data on the screen
– A video application that reads frames from a file on disk while
simultaneously decompressing and displaying the output on the
display
• An asynchronous call returns immediately,
without waiting for the I/O to complete. The
application continues to execute its code, and the
completion of the I/O at some future time is
communicated to the application
Fall 2000
M.B. Ibáñez
I/O scheduling
• To schedule a set of I/O requests means to
determine a good order in which to execute
them
• Scheduling can improve overall system
performance, can share access fairly among
processes, and can reduce the average
waiting time for I/O to complete
Fall 2000
M.B. Ibáñez
Buffering
• A buffer is a memory area that stores data while
they are transferred
– between two devices
– or between a device and an application
• Buffering is done for three reasons
– To cope with a speech mismatch between the producer and the
consumer of a data stream
– To adapt between devices that have different data-transfer sizes
– To support copy semantics for application I/O
Fall 2000
M.B. Ibáñez
No Buffering
Operating System
I/O Device
User Process
In
No buffering
From Operating Systems. Internals and Design Principles. W. Stallings. Prentice Hall
Fall 2000
M.B. Ibáñez
Single Buffer
• Operating system assigns a buffer in main memory
for an I/O request
• Block-oriented
– input transfers made to buffer block moved to user
space when needed
– another block is moved into the buffer
• read ahead
Operating System
I/O Device
From Operating Systems. Internals and Design Principles. W. Stallings. Prentice Hall
Fall 2000
M.B. Ibáñez
In
Move
Single buffering
User Process
Single Buffer
• Block-oriented
– user process can process one block of data while next
block is read in
– swapping can occur since input is taking place in
system memory, not user memory
– operating system keeps track of assignment of system
buffers to user processes
– output is accomplished by the user process writing a
block to the buffer and later actually written out
From Operating Systems. Internals and Design Principles. W. Stallings. Prentice Hall
Fall 2000
M.B. Ibáñez
Single Buffer
• Stream-oriented
– used a line at time
– user input from a terminal is one line at a time
with carriage return signaling the end of the line
– output to the terminal is one line at a time
From Operating Systems. Internals and Design Principles. W. Stallings. Prentice Hall
Fall 2000
M.B. Ibáñez
Double Buffer
• Use two system buffers instead of one
• A process can transfer data to or from one
buffer while the operating system empties
or fills the other buffer
Operating System
I/O Device
User Process
Move
In
Double buffering
From Operating Systems. Internals and Design Principles. W. Stallings. Prentice Hall
Fall 2000
M.B. Ibáñez
Circular Buffer
• More than two buffers are used
• Each individual buffer is one unit in a circular
buffer
• Used when I/O operation must keep up with
process
Operating System
In
I/O Device
User Process
Move
.
.
Circular buffering
From Operating Systems. Internals and Design Principles. W. Stallings. Prentice Hall
Fall 2000
M.B. Ibáñez