Operating Systems - Computer-System Structures (Night Class)
Compiled
By Aurelie A. Peralta
Computer-System Structures
We need
to have a general knowledge of the structure of a computer system before we can
explore the details of system operation.
The operating
system must also ensure the correct operation of the computer system. To ensure
that user programs will not interfere with the proper operation of the system, the
hardware must provide appropriate mechanisms to ensure correct behavior.
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. 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.
For a computer
to start running – for instance, when it is powered up or rebooted it needs to have
an initial program to run. This initial program or bootstrap program is typically stored in read-only memory (ROM) such as firmware or EEPROM within the computer
hardware. It initializes all aspects of the system, from the CPU registers to device
controllers to memory contents. The bootstrap program must know how to load the
operating system and to start executing the system. To accomplish this goal, the
bootstrap program must locate and load into memory the operating-system kernel.
The operating system then starts executing the first process, such as “init”, and
waits for some event to occur.
The occurrence
of an event is usually signaled by an interrupt from either the hardware or the
software. Hardware may trigger an interrupt at any time by sending a signal to the
CPU, usually by way of the system bus. Software may trigger an interrupt by executing
a special operation called a system call or a monitor call.
Modern
operating systems are interrupt driven. A trap or an exception is a software-generated
interrupt caused either by an error or by a specific request from a user program
that an operating-system service be performed. An interrupt service routine is provided
that is responsible for dealing with the interrupt. When a CPU is interrupted, it
stops what it is doing and immediately transfers execution to a fixed location.
The fixed location usually contains the starting address where the service routine
for the interrupt is located.
Interrupts
are an important part of computer architecture. Each computer design has its own
interrupt mechanisms, but several functions are common. An array of addresses or
interrupt vector is a table of pointers to interrupt routines and is generally stored
in low memory.
I/O Structure
A general-purpose
computer system consists of a CPU and multiple device controllers that are connected
through a common bus. Each device controller is in charge of a specific type of
device. Depending on the controller, there may be more
than one attached device.
SCSI –
Small Computer-System Interface
A device
controller maintains some local buffer storage and a set of special-purpose registers.
The device controller is responsible for moving the data between the peripheral
devices that it controls and its local buffer storage.
I/O Interrupts
To start
an I/O operation, the CPU loads the appropriate registers within the device controller.
The device controller, in turn, examines the contents of these registers to determine
what action to take. Device controllers inform the CPU that a certain operation
is finished by triggering an interrupt.
Synchronous
I/O – waits for an operation to complete before returning the control to the user.
Asynchronous
I/O – returns control to the user program without waiting for the I/O to complete.
The main advantage of asynchronous I/O is increased system efficiency.
DMA Structure
Direct
Memory Access (DMA) is used for high-speed I/O devices. After setting up buffers,
pointers, and counters for the I/O device, the device controller transfers an entire
block of data directly to or from its own buffer storage to memory, with no intervention
by the CPU.
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. It is implemented in a semiconductor technology
called dynamic random-access memory (DRAM), which forms an array of memory words.
Ideally,
we want the programs and data to reside in main memory permanently. This arrangement
is not possible for the following two reasons:
- Main memory is usually too small to store all needed programs
and data permanently.
- Main memory is a volatile storage device that loses its contents
when power is turned off or otherwise lost.
Thus, most computer systems provide secondary storage as an extension of main memory. The main
requirement for secondary storage is that is be able to hold large quantities of
data permanently.
Secondary Storage
Magnetic
Disks – provide the bulk of secondary storage for modern computer systems. The storage
capacity of common disk drives is measured in gigabytes. Disk speed has two parts.
The transfer rate is the rate at which data flow between the drive and the computer.
The positioning time, sometimes called the random-access time, consists of the time
to move the disk arm to the desired cylinder, called the seek time, and the time
for the desired sector to rotate to the disk head, called the rotational latency.
A disk
drive is attached to a computer by a set of wires called an I/O bus. Several kinds
of buses are available, including enhanced integrated drive electronics (EIDE),
advanced technology attachment (ATA), and SCSI buses. A disk controller is built
into each disk drive.
Magnetic
Tapes – was 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 in main memory. Tapes are used mainly for backup, for storage of infrequently
used information, and as a medium for transferring information from one system to
another.
Storage Hierarchy
The wide variety of storage systems in a computer system can be organized in a hierarchy
according to speed and cost. The higher levels are expensive, but they are fast.
As we move down the hierarchy, the cost per bit generally decreases, whereas the
access time generally increases.
Registers
Cache
Main Memory
Electronic
disk
Magnetic
disk
Optical
disk
Magnetic
tapes
Caching
Caching
is an important principle of computer systems. Information is normally kept in some
storage system. As it is used, it is copied into a faster storage system – the cache
– on a temporary basis. Because caches have limited size, cache management is an
important design problem.
Coherency and Consistency
In a multiprocessor
environment various CPUs can all execute concurrently, we must make sure that an
update in one cache is immediately reflected in all other caches where a certain
value also resides. This situation is called cache coherency, and is usually a hardware
problem.
Hardware Protection
Early operating
systems were called resident monitors, and starting with the resident monitor, the
operating system began to perform many of the functions, especially I/O, for which
the programmer had previously been responsible.
In addition,
to improve system utilization, the operating system began to share system resources
among several programs simultaneously. With spooling, one program might have been
executing while I/O occurred for other processes; the disk simultaneously held data
for many processes. Multiprogramming put several programs in memory at the same
time.
This sharing
both improved utilization and increased problems. When the system was run without
sharing, an error in a program could cause problems for only the one program that
was running. With sharing, many processes could be adversely affected by a bug in
one program.
Without
protection against these sorts of errors, either the computer must execute only
one process at a time, or all output must be suspect. A properly designed operating
system must ensure that an incorrect program cannot cause other programs to execute
incorrectly.
Many programming
errors are detected by the hardware. These errors are normally handled by the operating
system. If a user program fails in some way then hardware will trap to the operating
system. The trap transfers control through the interrupt vector to the operating
system, just like an interrupt. Whenever a program error occurs, the operating system
must abnormally terminate the program. This situation is handled by the same code
as is a user-requested abnormal termination. An appropriate error message is given,
and the memory of the program may be dumped. The memory dump is usually written
to a file so that the user or programmer can examine it, and perhaps can correct
and restart the program.
Dual-Mode Operation
At the
very least, we need two separate modes of operation: user mode and monitor mode
(also called supervisor mode, system mode, or privileged mode). A bit, called the
mode bit, is added to the hardware of the computer to indicate the current mode:
monitor (0) and user (1). The dual mode of operation provides us with the means
for protecting the operating system from errant users, and errant users from one
another. We accomplish this protection by designating some of the machine instructions
that may cause harm as privileged instructions. The hardware allows privileged instructions
to be executed only in monitor mode. If an attempt is made to execute a privileged
instruction in user mode, the hardware does not execute the instruction, but rather
treats the instruction as illegal and traps it to the operating system.
I/O Protection
A user
program may disrupt the normal operation of the system by issuing illegal I/O instructions,
by accessing memory locations within the operating system itself, or by refusing
to relinquish the CPU. We can use various mechanisms to ensure that such disruptions
cannot take place in the system.
To prevent
users from performing illegal I/O, we define all I/O instructions to be privileged
instructions. Thus, users cannot issue I/O instructions directly; they must do it
through the operating system. For I/O protection to be complete, we must be sure
that a user program can never gain control of the computer in monitor mode. If it
could, I/O protection could be compromised.
Memory Protection
To ensure
correct operation, we must protect the interrupt vector from modification by a user
program. In addition, we must also protect the interrupt-service routines in the
operating system from modification.
We see
then that we must provide memory protection at least for the interrupt vector and
the interrupt-service routines of the operating system. To separate each program’s
memory space, we need the ability to determine the range of legal addresses that
the program may access, and to protect the memory outside that space. We can provide
this protection by using two registers, usually a base and a limit.
This protection
is accomplished by the CPU hardware comparing every address generated in user mode
with the registers. The base and limit registers can be loaded by only the operating
system, which uses a special privileged instruction.
CPU Protection
We must
prevent a user program from getting stuck in an infinite loop or not calling system
services, and never returning control to the operating system. To accomplish this
goal, we can use a timer. A timer can be set to interrupt the computer after a specified
period. The period may be fixed or variable. A variable timer is generally implemented
by a fixed-rate clock and a counter. The operating system sets the counter. 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 the operation of the timer
are privileged.
Thus, we
can use the timer to prevent a user program from running too long. A simple technique is to initialize a counter with the amount of time that a program is allowed to
run. A more common use of a timer is to implement time sharing. Another use of the
timer is to compute the current time.
Network Structure
There are
basically two types of networks: local-area networks (LAN) and wide-area networks
(WAN). The main difference between the two is the way in which they are geographically
distributed. The differences of these two type of networks imply
major variations
in the speed and reliability of the communications network, and they are reflected
in the distributed operating-system design.
Reference: Operating System Concepts by Silberschatz, Galvin, and Gagne, 2003