Unit IV
Unit IV
stick, digitizer
Printer (Hard Copy Device) : Dot matrix (impact), thermal,
Control
Keyboard
and Printer Magnetic
display disk
terminal
www.ustudy.in
Asynchronous Data Transfer
This Scheme is used when speed of I/O devices do not match with
microprocessor, and timing characteristics of I/O devices is not predictable.
In this method, process initiates the device and check its status. As a
result, CPU has to wait till I/O device is ready to transfer data. When device
is ready CPU issues instruction for I/O transfer. In this method two types of
techniques are used based on signals before data transfer.
i. Strobe Control
ii. Handshaking
Strobe Signal
Data Bus
Source Destination
Strobe Unit
Unit
Data
Valid data
Strobe
The timing diagram fig. (b) the source unit first places the data on the
data bus. The information on the data bus and strobe signal remain in the active
state to allow the destination unit to receive the data.
Data Transfer Initiated by Destination Unit
Data Bus
Source Destination
Strobe Unit
Unit
Data
Valid data
Strobe
The data must be valid and remain in the bus long enough
for the destination unit to accept it. When accepted the destination
unit then disables the strobe and the source unit removes the data
from the bus.
Disadvantage of Strobe Signal
The disadvantage of the strobe method is that, the source unit
initiates the transfer has no way of knowing whether the
destination unit has actually received the data item that was
places in the bus. Similarly, a destination unit that initiates the
transfer has no way of knowing whether the source unit has
actually placed the data on bus. The Handshaking method
solves this problem.
Handshaking
One control line is in the same direction as the data flows in the bus
from the source to destination. It is used by source unit to inform the
destination unit whether there a valid data in the bus. The other
control line is in the other direction from the destination to the
source. It is used by the destination unit to inform the source whether
it can accept the data. The sequence of control during the transfer
depends on the unit that initiates the transfer.
Source Initiated Transfer using Handshaking
The sequence of events shows four possible states that the
system can be at any given time. The source unit initiates
the transfer by placing the data on the bus and enabling
its data valid signal. The data accepted signal is activated
by the destination unit after it accepts the data from the
bus. The source unit then disables its data accepted
signal and the system goes into its initial state.
Handshaking
Data Bus
Destination Unit
Source unit
Ready to accept data.
Place the data on bus. Enable ready for data.
Enable data Valid.
i. Start bit
ii. Stop Bit- Last bit, called stop bit is always one and used to
indicate end of characters. Stop bit is always in the 1- state and
frame the end of the characters to signify the idle or wait state.
iii. Character Bit- Bits in between the start bit and the stop bit
are known as character bits. The character bits always follow
the start bit.
Asynchronous Serial Transmission
0 1 1 0 0 0 1 0 1
Start Stop
bit Character bits bits
The transmitter register accepts a data byte from CPU through the
data bus and transferred to a shift register for serial transmission.
i. Programmed I/O
Anticipated transfer
Interrupt-driven I/O
Interrupts are used to initiate and/or terminate data transfers
Powerful technique
Status Error
Busy
Ready
CPU reads word from I/O module & writes it to memory or
CPU reads word from memory & writes it to I/O module
Is
transfer
NO complete
yes
Drawback of the Programmed I/O
The CPU has to monitor the units all the times when the
program is executing.
Thus the CPU stays in a program loop until the I/O unit
indicates that it is ready for data transfer.
A time consuming process and the CPU time is wasted a lot
in keeping an eye to the execution of program.
To remove this problem an Interrupt facility and
special commands are used.
Programmed Input/Output
Several ways of mapping I/O
Memory-mapped I/O
Same address space
Reading and writing similar to memory read/write
Isolated I/O
Separate I/O address space
Removing the CPU from the path and letting the peripheral device
manage the memory buses directly would improve the speed of transfer.
This transfer technique is called Direct Memory Access (DMA).
Computer System with DMA
Direct Memory Access (DMA)
Bus Grant BG
WR Write
i. DMA Burst
i. Address Register
Disadvantages of DMA
In case of Burst Mode data transfer, the CPU is rendered
inactive for relatively long periods of time.
Privileged and non privileged
instructions
Non-privileged
Processor-memory
Data Processing
Arithmetic
Shift Operations
Flow control
Branch
Subroutine linkage
Privileged
Processor-I/O
Control
Interrupts
Interrupts
In program-controlled I/O, when the processor continuously
monitors the status of the device, it does not perform any useful
tasks.
An alternate approach would be for the I/O device to alert the
processor when it becomes ready.
Do so by sending a hardware signal called an interrupt to the
processor.
At least one of the bus control lines, called an interrupt-request
line is dedicated for this purpose.
Processor can perform other useful tasks while it is waiting for the
device to be ready.
Interrupts (contd..)
Program 1 Interrupt Service routine
1
2
Interrupt
occurs i
here
i +1
M
Processor is executing the instruction located
at address i when an interrupt occurs.
Routine executed in response to an interrupt
request is called the interrupt-service routine.
When an interrupt occurs, control must be
transferred to the interrupt service routine.
But before transferring control, the current
contents of the PC (i+1), must be saved in a
known location.
This will enable the return-from-interrupt
instruction to resume execution at i+1.
Return address, or the contents of the PC
are usually stored on the processor stack.
Interrupts (contd..)
Treatment of an interrupt-service routine is
very similar to that of a subroutine.
However there are significant differences:
A subroutine performs a task that is required by the calling program.
Interrupt-service routine may not have anything in common with the program it
interrupts.
Interrupt-service routine and the program that it interrupts may belong to
different users.
As a result, before branching to the interrupt-service routine, not only the PC,
but other information such as condition code flags, and processor registers used
by both the interrupted program and the interrupt service routine must be
stored.
This will enable the interrupted program to resume execution upon return from
interrupt service routine.
Interrupts (contd..)
Saving and restoring information can be done automatically by the processor
or explicitly by program instructions.
Saving and restoring registers involves memory transfers:
Increases the total execution time.
Increases the delay between the time an interrupt request is received, and
the start of execution of the interrupt-service routine. This delay is called
interrupt latency.
In order to reduce the interrupt latency, most processors save only the minimal
amount of information:
This minimal amount of information includes Program Counter and
processor status registers.
Any additional information that must be saved, must be saved explicitly by the
program instructions at the beginning of the interrupt service routine.
Interrupts (contd..)
When a processor receives an interrupt-
request, it must branch to the interrupt service
routine.
It must also inform the device that it has
recognized the interrupt request.
This can be accomplished in two ways:
Some processors have an explicit interrupt-acknowledge control signal for this
purpose.
In other cases, the data transfer that takes place between the device and the
processor can be used to inform the device.
Interrupts (contd..)
Interrupt-requests interrupt the
execution of a program, and may alter the
intended sequence of events:
Sometimes such alterations may be undesirable, and must not be
allowed.
For example, the processor may not want to be interrupted by the
same device while executing its interrupt-service routine.
Processors generally provide the ability to enable and disable such
interruptions as desired.
One simple way is to provide machine instructions such as Interrupt-
enable and Interrupt-disable for this purpose.
To avoid interruption by the same device during the execution of an
interrupt service routine:
First instruction of an interrupt service routine can be Interrupt-
disable.
Last instruction of an interrupt service routine can be Interrupt-
enable.
Interrupts (contd..)
Multiple I/O devices may be connected to
the processor and the memory via a bus.
Some or all of these devices may be
capable of generating interrupt requests.
Each device operates independently, and hence no definite
order can be imposed on how the devices generate interrupt
requests?
How does the processor know which device has generated an
interrupt?
How does the processor know which interrupt service routine needs to
be executed?
When the processor is executing an interrupt service routine for one
device, can other device interrupt the processor?
If two interrupt-requests are received simultaneously, then how to
break the tie?
Interrupts (contd..)
Consider a simple arrangement where all devices send their
interrupt-requests over a single control line in the bus.
When the processor receives an interrupt request over this
control line, how does it know which device is requesting an
interrupt?
This information is available in the status register of the device
requesting an interrupt:
The status register of each device has an IRQ bit which it sets to 1 when it requests an interrupt.
Interrupt service routine can poll the I/O devices connected to
the bus. The first device with IRQ equal to 1 is the one that is
serviced.
Polling mechanism is easy, but time consuming to query the
status bits of all the I/O devices connected to the bus.
Interrupts (contd..)
The device requesting an interrupt may
identify itself directly to the processor.
Device can do so by sending a special code (4 to 8 bits) the processor over the
bus.
Code supplied by the device may represent a part of the starting address of the
interrupt-service routine.
The remainder of the starting address is obtained by the processor based on
other information such as the range of memory addresses where interrupt
service routines are located.
Usually the location pointed to by the
interrupting device is used to store the starting
address of the interrupt-service routine.
Interrupts (contd..)
Previously, before the processor started executing
the interrupt service routine for a device, it disabled
the interrupts from the device.
In general, same arrangement is used when multiple
devices can send interrupt requests to the processor.
During the execution of an interrupt service routine of device, the processor does not
accept interrupt requests from any other device.
Since the interrupt service routines are usually short, the delay that this causes is generally
acceptable.
However, for certain devices this delay may not be
acceptable.
Which devices can be allowed to interrupt a processor when it is executing an interrupt
service routine of another device?
Interrupts (contd..)
I/O devices are organized in a priority
structure:
An interrupt request from a high-priority device is accepted while the processor
is executing the interrupt service routine of a low priority device.
A priority level is assigned to a processor that
can be changed under program control.
Priority level of a processor is the priority of the program that is currently being
executed.
When the processor starts executing the interrupt service routine of a device, its
priority is raised to that of the device.
If the device sending an interrupt request has a higher priority than the
processor, the processor accepts the interrupt request.
Interrupts (contd..)
Processor’s priority is encoded in a few bits of
the processor status register.
Priority can be changed by instructions that write into the processor status
register.
Usually, these are privileged instructions, or instructions that can be executed
only in the supervisor mode.
Privileged instructions cannot be executed in the user mode.
Prevents a user program from accidentally or intentionally changing the priority
of the processor.
If there is an attempt to execute a privileged
instruction in the user mode, it causes a special
type of interrupt called as privilege exception.
Interrupts (contd..)
IN T R 1 INTR p
Processor
INTA1 INTA p
Priority arbitration
Device Device
INTA1
Processor
INTR p
Device Device
INTAp
Priority arbitration
circuit
•Devices are organized into groups.
•Each group is assigned a different priority level.
•All the devices within a single group share an interrupt-request line, an
connected to form a daisy chain.
Interrupts (contd..)
Only those devices that are being used in a program should be
allowed to generate interrupt requests.
To control which devices are allowed to generate interrupt
requests, the interface circuit of each I/O device has an interrupt-
enable bit.
If the interrupt-enable bit in the device interface is set to 1, then the device is allowed to generate an
interrupt-request.
Interrupt-enable bit in the device’s interface circuit determines
whether the device is allowed to generate an interrupt request.
Interrupt-enable bit in the processor status register or the
priority structure of the interrupts determines whether a given
interrupt will be accepted.
Exceptions
Interrupts caused by interrupt-requests sent by I/O devices.
Interrupts could be used in many other situations where the
execution of one program needs to be suspended and execution
of another program needs to be started.
In general, the term exception is used to refer to any event that
causes an interruption.
Interrupt-requests from I/O devices is one type of an exception.
Other types of exceptions are:
Recovery from errors
Debugging
Privilege exception
Exceptions (contd..)
Many sources of errors in a processor. For
example:
Error in the data stored.
Error during the execution of an instruction.
When such errors are detected, exception
processing is initiated.
Processor takes the same steps as in the case of I/O interrupt-request.
It suspends the execution of the current program, and starts executing an exception-
service routine.
Difference between handling I/O interrupt-
request and handling exceptions due to errors:
In case of I/O interrupt-request, the processor usually completes the execution of an
instruction in progress before branching to the interrupt-service routine.
In case of exception processing however, the execution of an instruction in progress
usually cannot be completed.
Exceptions (contd..)
Debugger uses exceptions to provide
important features:
Trace,
Breakpoints.
Trace mode:
Exception occurs after the execution of every instruction.
Debugging program is used as the exception-service routine.
Breakpoints:
Exception occurs only at specific points selected by the user.
Debugging program is used as the exception-service routine.
Exceptions (contd..)
Certain instructions can be executed only when
the processor is in the supervisor mode. These
are called privileged instructions.
If an attempt is made to execute a privileged
instruction in the user mode, a privilege
exception occurs.
Privilege exception causes:
Processor to switch to the supervisor mode,
Execution of an appropriate exception-servicing routine.
Processes: The Process Model
Time-out
Event Event
Occurs Wait
Blocked
Time-out
Event Wait
Event
Occurs
Blocked Queue
Time-out
Admit Suspend
Admit
Activate Dispatch
Ready, Ready Running Exit
suspend
Suspend Time out
Event Event
Event
Occurs Wait
Occurs
Activate
Blocked, Blocked
suspend
Suspend Operating Systems, 2013, Meni Adler, Michael Elhadad & 125
Amnon Meisels
Process Management Operations
Process creation and termination
Process scheduling and dispatching
Process switching
Process synchronization and support for inter-
process communication
Operating Systems, 2013, Meni Adler, Michael Elhadad & Amnon Meisels
127
Process Control Information
Additional information needed by the operating system to
control and coordinate the various active processes
o Execution state: see next slide…
o Scheduling-related information - state; priority; scheduling
info
o inter-process communication - signals; pipes
o Time of next alarm
o memory management - pointers to text/data/stack
segments
o resource ownership and utilization - open files
o Process relationships: Parent, process group…
o Environment variables
Runnin
g
Ready
Blocked