INTRODUCTION
TO
OPERATING SYSTEMS
Lecture 5: Input and Output
CHRIS STAFF
Dept. of Computer Science and Artificial Intelligence
University of Malta
Lecture Outline
Aims and Objectives
Terminology
Device Independence - Uniform Treatment of all Devices
Controlling Input and Output (From Lister & Eager)
Device Handlers
Buffering
File Devices
Spooling
Summary
Aims and Objectives
- To discuss I/O devices
- To discuss some issues of utilising I/O devices
- To introduce device independence
- To introduce Buffering
- And Spooling
Terminology
- Sequential Access - if it is necessary to read through all data on the device
until space or required data is found.
- Random Access - if free space and required data can be found without having
to look for it sequentially.
- I/O Management occurs at Layer 2 in the Hierarchical OS Model.
- I/O operations typically take place between Device and Primary Memory, or
Primary and Secondary memory.
- Asynchronous Operation of I/O devices and CPU.
Differences between devices
- Some devices are Input only, others Output only, and others are both.
- The Unit of Transfer can be characters, words, bytes, blocks or records.
- Data can be encoded in different representations (ASCII, EBCDIC).
- Some devices support operations that other devices do not (e.g., rewind, page
throw).
- There are different error conditions, and different ways of determining that
an error has occurred.
- Different devices operate at different speeds. Even devices of the same type
can differ wildly.
So
- It would make OS too large if it was to cater for every specific detail. Want
to try to abstract away from devices of same type, and also all devices of all
types.
Device Independence - Uniform Treatment of all Devices
- So users of Peripherals can use a standard way of interacting with different
devices.
- OS needs to smooth out all the differences between devices.
- This is achieved by the Virtual Device. Users interact with Virtual Devices
called streams. User creates a stream of a given type, and OS associates it
with a physical device the first time the device is required.
- Info about stream, and physical device, needs to be held in Process
Descriptor - PD points to a stream descriptor list.
- Stream is opened when OS associates stream with Phy. Device. Stream is closed
either explicitly by process or when process terminates
Advantages
- User can interact with devices using standard set of instructions.
- User does not need to know which specific Phy. Device will be used by a
process
- Easy to change device from, say, Tape to Disk, without having to rewrite
large chunks of code.
Device Handlers
- So far we've looked at ways in which users can use I/O devices in a standard
way.
- Need to look at ways in which OS can operate I/O devices in a uniform
manner.
- Device Handlers are software that interface between OS and I/O devices.
- When I/O instruction is received, Device Handler converts generic instruction
and internal character character code into format required by specific
device.
- To convert generic instructions in specific commands, device handler needs to
know the device's characteristics. These are held in the device's device
descriptor.
- The descriptor contains:
- the device identification
- the instructions which operate the device
- pointers to character translation table
- device's current status
- process id of process currently using device
- All device descriptors are linked to form a device structure pointed at from
Central Table.
Controlling Input and Output (From Lister & Eager)
I/O procedure of the following form can be used
DOIO(stream, mode, amount, destination, semaphore)
where: | |
DOIO | name of an I/O procedure |
stream | number of the stream I/O will occur |
mode | required operation |
amount | amount of data to be transferred |
destination | address into which data is to be input |
(source | address from which data is to be output) |
semaphore | address of semaphore request serviced which is to
be |
| signalled when I/O operation completes. |
Functions & Characteristics of the I/O procedure.
- It must be re-entrant
- It should locate the Phy. Device identified by the stream (from stream
descriptor list of calling process).
- It should validate the parameters
- Finally, it should initiate service of the request by assembling the
parameters into an IORB and adding it to the device's device request queue
(held in device descriptor)
- If the device is non-shareable, then the queue can contain IORBs from the one
process only, otherwise, the queue can contain IORBs from any process.
- When the request has been added to the queue, the procedure signals a
request pending.
- When I/O operation completes, device handler signals a request
serviced.
- procedure DOIO(stream, mode, amount, destination,
semaphore);
- begin lookup device in process descriptor;
- check parameters against device characteristics;
- if error then error exit;
- assemble IORB;
- add IORB to device request queue;
- signal(request pending)
end;
Device Handlers
- Each Device Class has its own handler.
- Device Handler waits for at least one request to be in the request queue.
- It picks the request at the top of the queue (unless entries are
prioritised), extracts details of the request, initiates the appropriate I/O
operation and waits on an `operation complete' semaphore.
- Just before entering ISR, device handler checks the status of the device.
- If request is for input, then the input data is translated before being
transferred to destination.
- If request is for output, then data is translated before I/O procedure is
called to output the data.
- If request is not for data transfer, then there is no data to translate or
transfer.
- At the end of the operation, device handler signals `request serviced'.
- The semaphore `operation complete' is signalled by the ISR initiated by the
Device Handler.
The interaction between the modules described above is summarised in the diagram below
Disadvantage of the operation described above
- Because the calling process is managing the synchronisation of semaphores,
the programmer must include the mechanism in his/her code.
- This gives programmers the freedom to have the process continue execution in
parallel with the service of the I/O request.
- However, there is room for error, because if the Wait is overlooked or put in
the wrong place, then the process could try to use data that isn't there, or
could continue after an error had occurred.
Restructuring the operation
- If the wait on `request serviced' is embedded in the I/O procedure, then
- Programmers don't have to cater for the synchronisation
- The process is automatically synchronised with the I/O operation
- The synchronisation is `localised' (embedded in the OS)
- The semaphore does not need to be a DOIO parameter
Buffering
- So far operation described implies that every time a process request I/O
operation, it is made unrunnable.
- Usually safe to assume that process will want to read/write more data while
the stream is open.
- So it is efficient to read in more data than is requested on the assumption
that the process will want to use other data that is logically close
(`Locality').
- Data can be read into an Input Buffer - area of primary memory. Perform
physical Input only when buffer is empty.
- Output - write data to output buffer, only writing it away to physical device
when buffer is full.
- Processes then do not have to wait for I/O operation, because (most)
reads/writes can be done in one operation.
Other Advantages
File Devices
- Not all devices can be identified by name alone. This is true of sequential
devices, where data can only be input or output sequentially, but it is not
true of Random Access Devices.
- On a random access device it is possible to read data from or write data to
logically separate areas in the same program. So a unique logical
identification of each area must be given as well as the device name.
- The logical area used to store or retrieve data is called a file, and is
identified by a file name.
- A device that supports files is called a file device, or file structured
device.
Spooling
- Buffering alone is not sufficient for non-shareable devices.
- E.g., all processes outputing to printer would be suspended while one process
controls printer. Print job could last for more than 30 minutes.
Unsatisfactory.
- Spooling (Simultaneous Peripheral Operations OnLine) is a more sophisticated
form of buffering.
- Output (input) is stored on disk until device is free.
- Spooler moves data between disk andthe device.
- Device can then operate at optimum speed.
- Jobs in spool queue can be prioritised.
- Buffering can be used to smooth the transfer between disk and the device.
Advantages and Disadvantages
+ can reduce, but not remove, risks of deadlock
+ can produce multiple copies of output without rerunning the job
- need large amounts of disk space
- increases disk traffic
- not practical for real-time environment, because results are produced at a
later time.
Summary
- Covered some I/O issues to derive concept of Virtual Device
- Looked at Device Handlers, to convert generic request to device specific
request
- Looked at `localised' communication between system processes to achieve
notion of apparent synchronisation between process execution and I/O
operation
- Buffering
- Spooling
Next Lecture...
Resource Allocation (1)