Computer System Architecture

Download Report

Transcript Computer System Architecture

IOS103/IOS102
OPERATING SYSTEM
Computer System Architecture
Objectives
At the end of the course, the student should be
able to:
•Explain how the computer and its controller
connected;
•Discuss the booting of the computer system ;
•Define Input/Output interrupt and direct memory
access;
•Discuss the structure of the computer storage;
•Give the importance of protecting the hardware,
Input/Output, memory and CPU of the computer
system.
Computer System Architecture
Computer System Operation
• A modern, general-purpose computer system
consists of a CPU and a number of device
controllers that are connected through a
common bus that provides access to shared
memory.
Computer System Architecture
Computer System Operation
Printer
Tape Drive
Printer
Controller
Tape Drive
Controller
Disk
CPU
Disk
Controller
System
Bus
Memory
Controller
Memory
Computer System Architecture
Computer System Operation
• Each device controller is in charge of a
specific type of device.
• The CPU and the device controllers can
execute concurrently, competing for memory
cycles. To ensure orderly access to the
shared memory, a memory controller is
provided whose function is to synchronize
access to the memory.
Computer System Architecture
Computer System Operation
• When a computer is powered up or rebooted,
the bootstrap program is first loaded. This
program initializes all aspects of the system,
from CPU registers to device controllers to
memory contents. It then locates and loads
the operating system kernel.
Computer System Architecture
Computer System Operation
• Modern operating systems are interrupt
driven. If there are no processes (programs)
to execute, no I/O devices to service, and no
users to whom to respond, an operating
system will sit quietly, waiting for something to
happen. If a process, device, or user needs
service from the operating system, it sends an
interrupt signal.
Computer System Architecture
Computer System Operation
• Events are almost always signalled by the
occurrence of an interrupt or a trap. A trap
(or an exception) is a software-generated
interrupt caused either by an error (for
example, division by zero or invalid memory
access) or by a specific request from a user
program that an operating-system service be
performed.
Computer System Architecture
Computer System Operation
• The interrupt-driven nature of an operating
system defines that system’s general
structure. For each type of interrupt, separate
segments of code, called interrupt-service
routines, in the operating system determine
what action should be taken.
Computer System Architecture
I/O Interrupts
• A general-purpose computer system consists
of a CPU and multiple device controllers.
• Each device controller is in charge of a
specific type of device. Depending on the
type of controller, there may be more than
one attached device.
Computer System Architecture
I/O Interrupts
• Once an I/O operation is started, two courses
of action are possible. In the simplest case,
the I/O is started; then, at I/O completion,
control is returned to the user process. This
case is known as synchronous I/O.
• The other possibility, called asynchronous
I/O, returns control to the user program
without waiting for the I/O to complete. The
I/O then can continue while other system
operations occur.
Computer System Architecture
I/O Interrupts
•
•
If the CPU waits for I/O completion, at most one
I/O request is outstanding at a time. So this
approach excludes concurrent I/O operations to
several devices, and also excludes the possibility
of overlapping useful computation with I/O.
A better alternative is to start the I/O and then
continue processing other operating-system or
user program code. Once the I/O process has
completed or if it needs additional service, it will
send an interrupt signal. In this manner, several
I/O requests can be entertained at any one time.
Computer System Architecture
I/O Interrupts
•
The operating system must keep track of many
I/O requests occurring at any instant. For this
purpose, it uses a table containing an entry for
each I/O device: the device-status table.
device: keyboard
status : idle
device: printer
status : busy
request for printer
address : 38546
length : 1372
device: disk 1
status : idle
device: disk 2
status : busy
.
.
.
request for disk 2
request for disk 2
file
operation
address
length
file
operation
address
length
: xxx
: read
: 43046
: 20000
: yyy
: write
: 03458
: 500
Computer System Architecture
I/O Interrupts
• Each table entry indicates the device type and
state (not functioning, idle, or busy). If the
device is busy with a request, the type of
request and other parameters will be stored in
the table entry for that device.
• Since it is possible for other processes to
issue requests to the same device, the
operating system will also maintain a wait
queue – a list of waiting requests – for each
I/O device.
Computer System Architecture
I/O Interrupts
•
•
An I/O device interrupts when it needs service.
When an interrupt occurs, the operating system
first determines which I/O device caused the
interrupt. It then indexes into the I/O device table
to determine the status of that device and
modifies the table entry to reflect the occurrence
of the interrupt.
For most devices, an interrupt signals completion
of an I/O request. If there are additional requests
waiting in the queue for this device, the operating
system starts processing the next request.
Computer System Architecture
I/O Interrupts
• Finally, control is returned from the I/O
interrupt. If a process was waiting for this
request to complete (as recorded in the
device-status table), the system can now
return control to it. Otherwise, the system will
return to whatever it was doing before the I/O
interrupt.
In a time-sharing system, the
operating system could switch to another
ready-to-run process.
Computer System Architecture
I/O Interrupts
• The main advantage of asynchronous I/O is
increased system efficiency. While I/O is
taking place, the system CPU can be used for
processing or starting I/Os to other devices.
Because I/O can be slow compared to
processor speed, the system makes efficient
use of its facilities.
Computer System Architecture
DMA Structure
Consider the following scenario:
1.A computer terminal transmitting data to a
computer (via a terminal controller) at a speed of
9,600 bps. This translates to 960 characters per
second assuming 10 bits per character. In effect,
the terminal takes 1,000 µs (0.001 sec.) to transmit a
character.
2.Each character received by the terminal controller
generates an interrupt to the CPU. This causes an
interrupt-service routine to execute that will transfer
the character from the controller to the CPU.
Computer System Architecture
DMA Structure
3.Assume that it takes 2 µs (0.000002 sec.) for the
interrupt service routine to execute.
4.This leaves 998 µs (0.000998 sec.) for every 1,000
µs for CPU computation (and for servicing of other
interrupts).
Given this disparity, asynchronous I/O (such as a
terminal) is usually assigned a low interrupt priority,
allowing other, more important interrupts to be
processed first.
Computer System Architecture
DMA Structure
• However, a high-speed device such as a disk
or a communications network may be able to
transmit information close to memory speeds;
if the CPU needs 2 ms to respond to each
interrupt and interrupts occur every 4 ms, for
example, that does not leave much time for
process execution.
Computer System Architecture
DMA Structure
•
•
•
To solve this problem, direct memory access
(DMA) is used for high-speed I/O devices. DMA
allows devices to transfer blocks of data directly
to or from the memory, with no intervention by the
CPU.
In this way, only one interrupt is generated per
block, rather than one interrupt per byte (or word)
generated by low-speed devices.
While the DMA controller is performing the data
transfer, the CPU is free to perform other tasks.
Computer System Architecture
Storage Structure
• Computer programs must be in main memory
(also called random-access memory or
RAM) to be executed.
• Main memory is the only large storage area
(millions to billions of bytes) that the
processor can access directly.
Computer System Architecture
Storage Structure
• Main memory is composed of an array of
memory words. Each word has its own
address. Interaction is achieved through a
sequence of load or store instructions to
specific memory addresses.
The load
instruction moves a word from main memory
to an internal register within the CPU,
whereas the store instruction moves the
contents of a register to main memory.
Computer System Architecture
Storage Structure
• Ideally, programs and data should reside in
main memory permanently. However, this
arrangement is not possible for the following
two reasons:
1. Main memory is usually too small to store all
needed programs and data permanently.
2. Main memory is a volatile storage device that
loses its contents when power is turned off or
otherwise lost.
Computer System Architecture
Storage Structure
•
•
Thus most computer systems provide secondary
storage as an extension of main memory. The
main requirement for secondary storage is that it
is able to hold large quantities of data
permanently.
The most common secondary storage device is
the magnetic disk. Most programs are stored on
a disk until they are loaded into memory. Any
instructions in execution, and any data being
used by the instructions, must be in main
memory.
Computer System Architecture
A magnetic disk system
has several disk platters.
Each disk platter has a
flat circular shape, like a
CD.
A magnetic
material, similar to that
of a magnetic tape or
floppy diskette, covers
its
two
surfaces.
Information is recorded
on the surfaces.
READ/WRITE HEAD
DISK
ROTATING SHAFT
Computer System Architecture
The disk surface is
logically divided into
circular tracks, which
are subdivided into
sectors. The system
stores information by
recording
it
magnetically on the
sector under the readwrite head.
Computer System Architecture
Storage Structure
• The set of tracks that are at one arm position
forms a cylinder.
• There may be hundreds of concentric
cylinders on a disk surface, containing
thousands of sectors. The platter itself may
be between 1.8 inches and 5.25 inches wide.
The storage capacity of common disk drives
is measured in gigabytes.
Computer System Architecture
Storage Structure
• When the disk is in use, a drive motor spins it
at a high speed (for example, 60 to 200
revolutions per second). There is a read-write
head positioned just above the surface of the
platter.
• The time it takes to access a sector depends
on three parameters, the seek time,
rotational latency, and transfer time.
Computer System Architecture
Storage Structure
•
•
•
Seek time (also called positioning time) is the
time it takes to move the read-write head to the
correct cylinder while the rotational latency is the
time it takes for the desired sector to rotate under
the head.
Transfer time is the time it takes to actually
transfer data between disk and main memory.
The head does not actually touch the surface of a
disk. Instead, it floats or flies only microns from
the disk surface, supported by a cushion of air.
Computer System Architecture
Storage Structure
•
•
Head crashes can be problem. If the head
contacts the disk surface (due to power failure,
for example), the head will scrape the recording
medium off the disk, destroying data that had
been there.
Usually, the head touching the surface causes
the removed medium to become airborne and to
come between the other heads and their platters,
causing more crashes.
Under normal
circumstances, a head crash results in the entire
disk failing and needing to be replaced.
Computer System Architecture
Storage Structure
•
•
Floppy disks take a different approach. The disks
are coated with a hard surface, so the read-write
head scans it directly on the disk surface without
destroying the data. The coating (and the readwrite head) will wear with use, however, and need
to be replaced over time.
Magnetic tapes were used as an early secondarystorage medium. Although it is relatively
permanent and can hold large quantities of data,
its access time is slow in comparison to that of
main memory and magnetic disks.
Computer System Architecture
Storage Structure
• Tapes are used mainly for backup, for storage of
infrequently used information, and as medium
for transferring information from one system to
another.
• Magnetic tapes were used as an early
secondary-storage medium. Although it is
relatively permanent and can hold large
quantities of data, its access time is slow in
comparison to that of main memory and
magnetic disks.
Computer System Architecture
Hardware Protection
• Recall
that
multiprogramming
allows the operating
system and two or
more user programs
to reside in the main
memory at the same
time.
Operating
System
Job 1
Job 2
Job 3
Job 4
Computer System Architecture
Hardware Protection
• One potential problem in this is that on
erroneous program might modify the
program or data of another program or even
the operating system itself.
• A properly designed operating system must
ensure that an incorrect (or malicious)
program cannot cause other programs to
execute incorrectly.
Computer System Architecture
Hardware Protection
• To ensure proper operation, there must be
hardware support that allows various modes
of execution:
1.User Mode. The CPU enters this mode if it
is executing a user program.
2.Monitor Mode. The CPU is in this mode if it
is executing a task on behalf of the
operating system.
Also called the
supervisor mode, system mode, or
privileged mode.
Computer System Architecture
Hardware Protection
• Machine instructions that may cause harm
to other programs are designated as
privileged instructions. The hardware
allows privileged instructions to be executed
only in monitor mode. If an attempt is made
to execute a privileged in user mode, the
hardware does not execute the instruction.
Computer System Architecture
Hardware Protection
• Through this, there is a means for the user
to interact with the operating system by
asking the system to perform some
designated tasks that only the operating
system should do. Such a request is known
as a system call (also called a monitor
call or an operating system function call).
Computer System Architecture
Hardware Protection
• The lack of a hardware-supported dual
mode can cause serious shortcomings in an
operating system.
• For instance, MS-DOS was written for the
Intel 8088 architecture, which does not have
dual mode of execution. A user program
running awry can wipe out the operating
system by writing over it with data, and
multiple programs are able to write to a
device at the same time.
Computer System Architecture
Hardware Protection
• More recent and advanced versions of the
Intel CPU, such as the Pentium, do provide
dual-mode operation. As a result, more
recent operating systems take advantage of
this feature and provide greater protection
for the operating system.
Computer System Architecture
I/O Protection
• A user program may disrupt the normal
operation of the system by issuing illegal I/O
instructions.
• To prevent users from performing illegal I/O,
all I/O instructions are defined to be
privileged instructions. The users cannot
issue I/O instructions directly, they must do
it through the operating system.
Computer System Architecture
I/O Protection
•
•
To make I/O protection complete, it must be
ensured that a user program can never gain
control of the computer in monitor mode.
To do I/O, a user program executes a system
call to request that the operating system
perform I/O on its behalf.
The operating
system, executing in monitor mode, checks that
the request is valid, and (if the request is valid)
does the I/O requested. The operating system
then returns to the user.
Computer System Architecture
Memory Protection
•
•
In general, it is necessary to protect the
operating system from access by user
programs, and in addition, to protect user
programs from one another. This protection
must be provided by hardware.
To separate each program’s memory space,
there is a need for the ability to determine the
range of legal addresses that the program may
access, and to protect the memory outside that
space.
Computer System Architecture
Memory Protection
• In general, it is necessary to protect the
operating system from access by user
programs, and in addition, to protect user
programs from one another. This protection
must be provided by hardware.
This
protection can be provided by using two
registers, usually a base register and a limit
register.
Computer System Architecture
Memory Protection
0
Operating
System
256000
300040
Job 1
Job 2
base register
300040
limit register
120900
420940
Job 3
880000
1024000
Job 4
• The base register holds the smallest legal
physical memory address; the limit register
contains the size of the range.
Computer System Architecture
Memory Protection
• This protection is accomplished by the CPU
hardware
comparing
every
address
generated in user mode with the registers.
Any attempt by a program executing in user
mode to access operating system memory
or other users’ memory results in a trap to
the operating system, which treats the
attempt as a fatal error.
Computer System Architecture
Memory Protection
base
>=
CPU
base + limit
yes
yes
<
to MM
address
no
trap to operating system
monitor -addressing error
no
trap to operating system
monitor -addressing error
Computer System Architecture
Memory Protection
• This prevents the user program from
(accidentally or deliberately) modifying the
code or data structures of either the
operating system or other users.
• The base and limit registers can be loaded
by only the operating system which uses a
special privileged instruction.
Computer System Architecture
CPU Protection
• In addition to protecting I/O and memory, it
must be ensured that the operating system
maintains control. User programs must be
prevented from getting stuck in an infinite
loop and never returning control to the
operating system.
• To accomplish this goal, a timer is used. A
timer can set to interrupt the computer after
a specified period.
Computer System Architecture
CPU Protection
• Before turning over control to the user, the
operating system ensures that the timer is
set to interrupt. If the timer interrupts,
control transfers automatically to the
operating system, which may treat the
interrupt as a fatal error or may give the
program more time.
• Clearly, instructions that modify
operation of the timer are privileged.
the
Computer System Architecture
CPU Protection
• A more common use of a timer is to
implement time sharing.
In the most
straightforward case, the timer could be set
to interrupt every N milliseconds, where N is
the time slice that each user is allowed to
execute before the user gets control of the
CPU.