01 - Operating System-1
01 - Operating System-1
Content:
1.1 Introduction
1.2 History Of Operating Systems
1.3 Computer Hardware Review
1.4 What Is An Operating System?
1.5 What Operating Systems Do?
1.2 Computer System Organization
1.4 Computer System Operations
1.3 Computer System Architecture
1.5 Operating System Structure
1.6 Operating-System Operahons
c...ca ~e.9cf "(, ~
1
Introduction
User
1
operating system
cOmp_uter hardware
2
HISTORY OF OPERATING SYSTEMS
Operating systems have been evolving through the years.
- The First Generation (1945-55): Vacuum Tubes.
- The Second Generation (1955-65): Transistors and Batch Systems.
- The Third Generation (1965-1980): ICs and Multiprogramming.
- The Fourth Generation (1980-Present): Personal Computers.
- The Fifth Generation (1990-Present): Mobile Computers.
3
Along with the Kemal, there are two other type of programs: System
Programs, which are associated with the Operating System but are not
necessarily part of the Kemal, and application programs, which include
all programs not associated with the Operating System.
- Today's OSes for general purpose and mobile computing also include
middleware - a set of software frameworks that provide additional
services to application developers such as databases, multimedia,
graphics.
4
Embedded systems such as computers 111 home devices and
automobiles.
• System View
-a-a 6 11
CPU
system bus
memory
5
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, tends to be simple. Typically, it is stored within the
computer hardware in read-only memory (ROM) or electrically erasable
programmable read-only memory (EEPROM), !mown by the general term
firmware. It initializes all aspects of the system, from CPU registers to
device controllers to memory contents. The bootstrap program must know
how to load the operating system and how to start executing that system. To
accomplish this goal, the bootstrap program must locate the operating-
system kernel and load it into memory.
Once the kernel is loaded and executing, it can start providing services to
the system and its users. Some services are provided outside of the kernel,
by system programs that are loaded into memory at boot time to become
system processes, or system daemons that run the entire time the kernel is
running. Once this phase is complete, the system is fully booted, and the
system waits for some event to occur.
6
• Interrupt Handling and Interrupt Timeline
In digital computers, an interrupt (sometimes referred to as a trap) is a
request for the processor to interrupt currently executing code. If the request
is accepted, the processor will suspend its current activities, save its state, and
execute a function called an interrupt handler (or an interrupt service routine,
ISR) to deal with the event. This interruption is often temporary, allowing the
software to resume normal activities after the interrupt handler finishes.
In computer systems programming, an interrupt handler, also known as
an interrupt service routine or ISR, is a special block of code associated
with a specific interrupt condition.
The occurrence of an event is usually signaled by an interrupt from either
the hardware or the software. Hardware may trigger an intem1pt 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
(also called a monitor call).
When the CPU is intem1pted, it stops what it 1s doing and immediately
transfers execution to a fixed location.
An intem1pt is a signal to the processor emitted by hardware or software
indicating an event that needs immediate attention. Whenever an intem1pt
occurs, the controller completes the execution of the current instruction and
starts the execution of an Interrupt Service Routine (ISR) or Interrupt
Handler. ISR tells the processor or controller what to do when the interrupt
occurs.
7
Program Execution wlthout Interrupts
Time
;J,1ain
Hardware Interrupt
Software Interrupt
8
CPU 110 controller
interrupt handler ,
proces_ses data,
returns from, Interrupt
CPU resumes
processing of
interrupted task
tr,an~farrln9
9
Storage Structure
The CPU can load instructions only from memory, so any programs to run must
be stored there. General-purpose computers run most of their programs from
rewritable memory, called main memory (also called ram.lom-access memory,
or RA.VI). Main memory commonly is implemented in a semiconductor
technology called dynamic random-access memory (DRAY]).
Computers use other fo1ms of memory as well. We have already mentioned
read-only memory, ROM) and electrically erasable programmable read-only
memory, EEPROM). Because ROM cannot be changed, only static programs,
such as the bootstrap program described earlier, are stored there.
All fo1ms of memory provide an an-ay of bytes. Each byte has its own address.
Interaction is achieved through a sequence of load or store instructions to
specific memory addresses. The load instruction moves a byte or word from
main memory to an internal register within the CPU, whereas the store
instruction moves the content of a register to main memory. The CPU
automatically loads instructions from main memory for execution.
Most computer systems provide secondary storage as an extension of main
memory. The main requirement for secondary storage is that it be able to hold
large quantities of data permanently.
The most common secondary-storage device 1s a magnetic disk, which
provides storage for both programs and data. Most programs (system and
application) are stored on a disk tmtil they are loaded into memory.
The wide variety of storage systems can be organized in a hierarchy (Figure
below) 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.
The top four levels of memory in Figure below may be constructed usmg
semiconductor memory. In addition to differing in speed and cost, the various
10
storage systems are either volatile or nonvolatile. As mentioned earlier, volatile
storage loses its contents when the power to the device is removed.
In the hierarchy shown in Figure below, the storage systems above the solid-
state disk are volatile, whereas those including the solid-state disk and below
are nonvolatile. Solid-state disks have several variants but in general are faster
than magnetic disks and are nonvolatile.
volat!le
storage
:J?r~,
main memory J)
primary
storage
~
~
..£5!
nonvolatile
storage nonvolatile ~emory
~-~--,,-
fsecond<1ry
storage
hard-disk drives
optical disk
tertiary
•storage
~•
'iii
magnetic tapes
I/O Structure
A large portion of operating system code is dedicated to managing I/O, both
because of its importance to the reliability and performance of a system and
because of the varying nature of the devices. A general-purpose computer
system consists of CPUs and multiple device controllers that are connected
through a common bus. Each device controller is in charge of a specific type of
device. 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.
11
,,,,,=g•Oo•M,.,
""''""""'"''"
A device controller is a system that handles the incoming and outgoing signals
of the CPU by acting as a bridge between CPU and the I/O devices. A device is
connected to the computer via a plug and socket, and the socket is connected to
a device controller. Device controllers use binary and digital codes. An IO
device contains mechanical and electrical parts. A device controller is the
electrical part of the IO device.
- instruction execution
~
cycle
instructions
thread of execution ;:; .. and
data movement - <lata
CPU ('N)
c§
~
il i•.. v~.
5·
~
DMA
~~\~-
'- .("M)
The Device Controller receives the data from a connected device and stores it
temporarily in some special purpose registers (i.e. local buffer) inside the
controller. Then it communicates the data with a Device Driver. For each device
controller there is an equivalent device driver which is the standard interface
through which the device controller communicates with the Operating Systems
12
through Interrupts. Device controller is a hardware whereas device driver is a
software. A device driver is a program that lets the operating system
communicate with specific computer hardware.
13
common and does not turn a single-processor system into a multiprocessor. If
there is only one general-purpose CPU, then the system is a single-processor
system.
Multiprocessor Systems
:\lultiprocessor systems (also known as parallel systems or multi.core
systems) have two or more processors in close communication, sharing the
computer bus and sometimes the clock, memory, and peripheral devices.
Multiprocessor systems first appeared prominently appeared in servers and have
since migrated to desktop and laptop systems. Recently, multiple processors
have appeared on mobile devices such as smartphones and tablet computers.
Multiprocessor systems have three main advantages:
l. Increased throughput. By increasing the number of processors, we expect to
get more work done in less time. The speed-up ratio with N processors is not N,
however; rather, it is less than N. When multiple processors cooperate on a task,
a certain amount of overhead is incurred in keeping all the parts working
correctly. This overhead, plus contention for shared resources, lowers the
expected gain from additional processors. Similarly, N programmers working
closely together do not produce N times the amount of work a single
programmer would produce.
2, Economy of scale. Multiprocessor systems can cost less than equivalent
multiple single-processor systems, because they can share peripherals, mass
storage, and power supplies. If several programs operate on the same set of data,
it is cheaper to store those data on one disk and to have all the processors share
them than to have many computers with local disks and many copies of the
data.
3. Increased reliability. If functions can be distributed properly among several
processors, then the failure of one processor will not halt the system, only slow
it down. If we have ten processors and one fails, then each of the remaining nine
14
processors can pick up a share of the work of the failed processor. Thus, the
entire system runs only 10 percent slower, rather than failing altogether.
The multiple-processor systems in use today are of two types. Some systems
use asymmetric multiprocessing, in which each processor is assigned a
specific task. A boss processor controls the system; the other processors either
look to the boss for instruction or have predefined tasks. This scheme defines a
boss-worker relationship. The boss processor schedules and allocates work to
processors.
memory
15
• Clustered Systems
A clustered system, which gathers together multiple CPUs. Clustered systems
differ from the multiprocessor systems described in Section 1.3.2 in that they
are composed of two or more individual systems-or nodes-joined together.
Such systems are considered loosely coupled. Each node may be a single
processor system or a multicore system. The generally accepted definition is
that clustered computers share storage and are closely linked via a local-area
network LAN or a faster interconnect,
interconnect interconnect
~oinputer computer computer
storage area
network
2. Layered Structure
16
3. Micro-Kernel Structure
4. Exo-Kernel Structure
5. Virtual Machines
17
resident system program
/the users)
"iii
signals terminal file system CPU scheduling
E handling swapping block l/0 page replacement
"'
-"' character 1/0 system
terminal drivers
system
disk and tape drivers
tjemand !)aging
virtual memory
kernel]ntertace tqtheh~rclware
terminal controllers device controllers memory controlklrs
terminals disks<lnd tapes physical memory
18
2. Layered Structure
layer N
user interface
A system can be made modular in many ways. One method is the layered
approach, in which the operating system is broken into a number of layers
19
(levels). The bottom layer (layer 0) is the hardware; the highest (layer N) is the
user interface.
Layer Function
5 The operator
4 User programs
3 Input/output management
2 Operator·process communication
1 Memory and drum management
0 Processor allocation and multiprogramming
Layer 1 did the memory management. It allocated space for processes in main
mem01y.
Layer 2 handled communication between each process and the operator console
(that is, the user).
Layer 3 took care of managing the I/0 devices and buffering the information
streams to and from them.
Layer 4 was where the user programs were found. They did not have to worry
about process, memory, console, or I/0 management. The system operator
process was located in layer 5.
These layers are so designed that each layer uses the functions of the lower-
level layers. This simplifies the debugging process, if lower-level layers are
debugged and an error occurs during debugging, then the error must be on that
layer only, as the lower-level layers have already been debugged.
The main disadvantage of this strncture is that at each layer, the data needs to be
modified and passed on which adds overhead to the system. Moreover, careful
planning of the layers is necessary, as a layer can use only lower-level layers.
UNIX is an example of this strncture.
20
The main advantage of the layered approach is simplicity of construction and
debugging. The layers are selected so that each uses functions (operations) and
services of only lower-level layers. This approach simplifies debugging and
system verification. The first layer can be debugged without any concern for the
rest of the system, because, by definition, it uses only the basic hardware (which
is assumed correct) to implement its functions. Once the first layer is debugged,
its correct functioning can be assumed while the second layer is debugged, and
so on. If an error is fmmd during the debugging of a particular layer, the error
must be on that layer, because the layers below it are already debugged. Thus,
the design and implementation of the system are simplified.
Each layer is implemented only with operations provided by lower-level layers.
A layer does not need to know how these operations are implemented; it needs
to know only what these operations do. Hence, each layer hides the existence of
certain data structures, operations, and hardware from higher-level layers. The
major difficulty with the layered approach involves appropriately defining the
various layers. Because a layer can use only lower-level layers, careful planning
1s necessary.
3. Microkernels Structure
We have already seen that as UNIX expanded, the kernel became large and
difficult to manage. In the mid-1980s, researchers at Carnegie Mellon
University developed an operating system called 1Vfach that modularized the
kernel using the microkerne.l approach. This method structures the operating
system by removing all nonessential components from the kernel and
implementing them as system and user-level programs. The result is a smaller
kernel. There is little consensus regarding which services should remain in the
kernel and which should be implemented in user space. Typically, however,
microkemels provide minimal process and memory management, in addition to
a communication facility.
21
The main function of the microkernel is to provide c01m1rnnication between the
client program and the various services that are also running in user space.
Communication is provided through message passing. For example, if the
client program wishes to access a file, it must interact with the file server. The
client program and service never interact directly. Rather, they communicate
indirectly by exchanging messages with the
micro kernel.
One benefit of the microkernel approach is that it makes extending the operating
system easier. All new services are added to user space and consequently do not
require modification of the kernel. When the kernel does have to be modified,
the changes tend to be fewer, because the microkemel is a smaller kernel. The
resulting operating system is easier to port from one hardware design to another.
The microkernel also provides more secmity and reliability, since most services
are running as user-rather than kernel processes. If a service fails, the rest of
the operating system remains untouched.
Some contemporary operating systems have used the microkemel
I~
r
/\pplroation File user
Program system mode
,,. ]
kernel
mode
mia-okeme!
hardware
22
low compared with that of Windows 95. Windows NT 4.0 partially corrected
the performance problem by moving layers from user space to kernel space and
integrating them more closely. By the time Windows XP was designed,
Windows architecture had become more monolithic than microkernel.
4. Microkernels Structure
23
5. Modules Structure
(>cheduling
device and classes
file systems •
bus drivers
miscellaneous loadable
modules system calls
Operating-System Debugging
We have mentioned debugging frequently in this chapter. Here, we take a closer
look. Broadly, debugging is the activity of finding and fixing eITors in a system,
both in hardware and in software. Performance problems are considered bugs,
so debugging can also include performance tuning, which seeks to improve
perfmmance by removing processing bottlenecks.
24
Operating Systems Categories
1. Mainframe Operating Systems
At the high end are the operating systems for mainframes, those room-sized
computers still found in major corporate data centers. These computers differ
from personal computers in terms of their I/O capacity. A mainframe with 1000
disks and millions of gigabytes of data.
high-end Web servers, servers for large-scale electronic commerce sites, and
servers for business-to-business transactions.
The operating systems for mainframes are heavily oriented toward processing
many jobs at once, most of which need huge amounts of I/O. They typically
offer three kinds of services: batch, transaction processing, and timesharing. A
batch system is one that processes routine jobs without any interactive user
present.
Claims processing in an insurance company or sales reporting for a chain of
stores is typically done in batch mode. Transaction-processing systems handle
large numbers of small requests, for example, check processing at a bank or
airline reservations.
Each unit of work is small, but the system must handle hundreds or thousands
per second. Timesharing systems allow multiple remote users to run jobs on the
computer at once, such as querying a big database. However, mainframe
operating systems are gradually being replaced by UNIX variants such as
Linux.
26
periodically based on an internal clock. The operating system has to be small
and simple because the nodes have little RAM and battety lifetime is a major
issue. Also, as with embedded systems, all the programs are loaded in advance.
27
Computer Startup
28