OperatingSystemLectures

Download Report

Transcript OperatingSystemLectures

Operating Systems
Lecture 1
Crucial hardware concepts review
M. Naghibzadeh
Reference: M. Naghibzadeh, Operating System Concepts and Techniques, iUniverse publisher, 2005.
To order: www.iUniverse.com, www.barnesandnoble.com, or www.amazon.com
Introduction
A computer is a device which runs programs.
A program is a set of instructions that is
prepared to do a specific job.
The operating system is an special program
which sits on top of the computer hardware. It
acts as an interface between the running
programs and the computer hardware to:



Provide basic software modules to be used by programs
Facilitate efficient use of computer resources
Prevent running programs interference
2
Computer Hardware Organization
Within every computer there are many
hardware devices.
Control unit,
 Arithmetic-logic unit,
 Cache memory,
 And main memory are the basic devices.
 Other devices are usually Input/Output
devices.
Figure 1 shows essential logical interconnctions
of the devices

3
Essential logical interconnctions of a computer’s
devices
CPU
Control Unit
Arithmetic-Logic
Unit
Input
Unit
Main
Memory
Output Unit
Figure 1: Computer organization model
4
Physical interconnctions of a computer’s devices
To reduce internal interconnection wiring, buses are used to
connect devices.
A bus is similar to a highway via which different parts of a city
are connected.
There are at least three busses, address bus, data bus and
control bus, in every computer.
Some computer devices are not directly connected to the
computer’s internal bus.
In a 32-bit computer, for example, the address bus and data bus
are each 32 bits wide.
There are mechanisms for possessing the address and data
buses, otherwise data and addresses from different devices
could become mixed up.
A model of the bus-based computer organization is shown in
Figure 2.
5
Essential Physical interconnctions of a computer’s
devices
Central
Processing Unit
(CPU)
Main
Memory
(MM)
Monitor
Mouse
Control bus
Address bus
Data bus
Hard Disk
(HD)
Internet
Connection
...
Figure 2: A bus-based Computer organization model
6
The Fetch-Execute Cycle
The computer reads an instruction from the
main memory (RAM) and moves it to a
temporary place called the Instruction
Register (IR) in the Central Processing
Unit (CPU).
It then finds out what has to be done with
respect to this instruction and performs the
actions.
It repeats this cycle of moving an instruction
from the main memory to the CPU and
executing it over and over again.
This is called Fetch-Execute Cycle
7
The Details of Fetch-Execute Cycle
Fetch cycle
Read the instruction pointed out
by the Program Counter (PC)
register from main memory and
move it to the CPU
Find out what this instruction is
Execute cycle
Move the data upon which the
instruction has to be executed from
main memory to the CPU.
Execute the instruction, i.e.,
perform what is requested by the
instruction. Perhaps this may
readjust the PC.
Adjust PC for the next instruction
Figure 3: A simplified functional model of a computer
8
Program Counter (PC) update
It is important to understand how the PC is filled.
The PC is automatically filled with an initial value when the
computer is started or restarted.
When a new program is to be executed, the operating system
will fill the PC with the first executable instruction of the
program.
Otherwise, it is updated as shown in the figure 3.
When an instruction is executed, the next instruction to be
fetched is most likely the one immediately following this
instruction. However, this is not always the case. Look at the
piece of program below that is written in a pseudo code
format.
1. If A > B
2. then print A
3. else print B
4. endif
Most of the time, the PC update during the fetch cycle suffices.
9
Interrupt
Interrupt is a signal that is sent to the CPU to
capture its attention. It may be issued by
different sources, like




By a fault detecting hardware that is trying to
informs the CPU of a circuitry malfunction
By a monitoring circuit within the ALU that controls
the acceptability of the data size for the operation
being performed and, consequently, the operation
result size
By a user that may press a special key like “break”
at any time
By an slave processor that wants to inform the
CPU of the completion of the assigned task …
10
Interrupt masking
Some interrupts are maskable by user
programs.
Masked interrupts are ignored by the CPU.
This is analogous to ignoring a door knock.
Some interrupts are not user-maskable. It is
not reasonable to let the computer continue in
the presence of a hardware failure.
However, all interrupts are maskable within
the kernel of an operating system.
11
Interrupt Categorization
Interrupts are categorized into few classes.
Different classes of interrupts require. different
handling consideration.
Each category of interrupts is represented by a
bit in interrupt vector within the CPU.
Interrupt categories have priorities.
When handling a higher priority interrupt
handling any lower priority interrupt is
postponed.
12
Program execution suspension
A non-masked interrupt causes the suspension of the
currently executing program.
It is usually possible to resume the execution of the
program after the interrupt is handled.
Interrupt signals reach the CPU and are stored in the
interrupt vector. The interrupt(s) is ignored until the
currently executing machine instruction is completed.
There are very few exceptions. One example might be the
“move” instruction in some computers that is suppose to
move a big chunk, say 256 bytes, of data from one
location of main memory to another.
The CPU always looks for interrupt signals just before
fetching a new instruction to execute. If there are any
interrupt signals, the system handles them in the order of
priorities and urgencies.
13
Fetch-Execute Cycle with interrupt
Fetch cycle
Handle all non-masked interrupts
Read the instruction pointed out
by the Program Counter (PC)
register from main memory and
move it to the CPU
Find out what this instruction is
Execute cycle
Move the data upon which the
instruction has to be executed from
main memory to the CPU.
Execute the instruction, i.e.,
perform what is requested by the
instruction. Perhaps this may
readjust the PC.
Adjust PC for the next instruction
Figure 4: A simplified functional model of a computer with interrupt
14
Privileged instructions
Privileged instructions are those which are not
usable by assembly application programmers.
Privileged instructions are executable only
within the operating system kernel
Other parts of the OS and application
programmers
may
execute
privileged
instruction by special means that are provided
by the operating system
Disable interrupt which disables all interrupts
is a sample privileged instruction.
15
CPU speed
CPU speed is usually measured by its clock
cycle which is around Giga hertz for PCs.
A clock cycle is usually the time that takes to
move one data (instruction, or address) from
one internal register to another.
A machine instruction execution takes around
10 clock cycles.
There are other units of measuring a CPU
speed, like Million instruction per second
(MIPS) and Million Floating point instructions
per second (MFLOPS).
16
Summary
The following subjects were discussed:
Computer, Program, and operating system
Logical Computer organization model
Physical Computer organization model
Functional Computer organization model and
the Fetch-Execute Cycle
Interrupt, Interrupt masking, Interrupt
categorization, and interrupt handling.
CPU speed.
17
Find out
Your computer’s instruction categories based on
their length.
The benefits of adjusting the PC register during the
fetch cycle even though we have to readjust it
during the execute cycle for some instructions?
You have just bought a new personal computer. No
operating system is installed, what software does it
have and for what purposes?
If your computer is a 32-bit one, what is the
maximum memory size that the CPU can directly
address (without using a base register)?
Your computer’s speed in terms of MIPS.
Your computer’s interrupt classes
Your computer’s interruptable instructions
Your computer’s privileged instructions
18
Thank you!
19