Sie sind auf Seite 1von 50

I T

I
P

Computer Fundamentals

Layers of Computer Systems

O/S as a resource manager

What is Operating System?

In a top-down approach, the O/S


provides a virtual machine. A high
level abstraction of a computer
hardware.

In a bottom-up view, an O/S manages


the different hardware resources.

Services provided by O/S

Memory Management: Each users


seems to have the entire memory
Process Management: Many users can
simultaneously run their program
File Management: Store files and
directories. User A cannot access user
Bs program or files.
Network Access: Access servers,WWW..
Etc.

Kernel

Kernel

The portion of O/S that resides in main


memory.
Contains the most frequently used
functions.
Also called the nucleus.

System Calls

System Calls (2)

Programs communicate with the O/S


via system calls.
Example

Create a process - fork()


Access a file fopen()

Each O/S has its own system call


vocabulary which is usually large.

System Calls (3)

Programs want O/S to perform a


service

Program passes relevant information to the


O/S (through a system call).
O/S performs the service : (i) if it is able to
do so and (ii) program is authorized to avail
that service.

Another def. of System Calls


User Programs
The O/S provides a
set of programs or
extended instructions
to act as interface
between the user
programs and the O/S
called system calls.
These system calls
vary from O/S to O/S

Interface Programs

Operating System

Hardware

Evolution of O/S

First Generation O/S

User books a slot to use the computer


User operates the computer, write
programs, checks for errors and runs the
program
After the job of the user was completed,
next user executes his job

Problem: Only one job at a time, waste


resources while programming.

Batch Operating system

In batch O/S, instead of manually loading the


programs one by one, a number of jobs were
batched and kept ready.

Batch Operating system (2)

O/S sequentially loads program and


executes. CPU kept idle during I/O
operation .
Problem: Wastage of CPU time while
process doing I/O operation.

Uniprogramming

Processor must wait for I/O instruction


to complete before proceeding

Multiprogramming O/S

When one job needs to wait for I/O, the


processor can switch to the other job

Multiprogramming O/S (2)


Partitions memory
and simultaneously
store no. of programs
Overlaps the I/O of
one job with the
execution of another

Multiprogramming O/S (3)

Still one job active at a time, but better


CPU utilization
The O/S schedules the CPU to the
different programs
Main challenge is to protect the
programs from one another and
possible to stop programs in middle.

Multiprogramming O/S (4)

Although multiprogramming improved


the throughput the turnaround time was
still a problem.
Not interactive, users submit jobs and
gets results minutes/hours/days later.

Time Multiplexing

Processors time is shared among


multiple users.
Multiple users simultaneously access
the system through terminals.
Allows a large number of users to
interactively work with the computer by
time sharing the O/S between them.

Time Multiplexing example

tn

t1
t2

tn-1

Time Multiplexing (2)

The O/S allocates about 20 msecs to


each terminal in round-robin fashion. If
there are 50 terminals, each will get the
processors attention every 1 sec.

Time Multiplexing (3)

Different allocation schemes possible assign CPU to the first program and
when it has run for sufficiently long time
allocate CPU to the second program
and so on (time slotting).

Time Multiplexing (4)

When the O/S allocates the processor


to a second process, state of the first
process must be saved.
State of a process includes registers,
program counter, memory management
information.
Switch between process (context
switching) at each interrupt.

Space Multiplexing
Instead of a user getting the whole resource, allocate part of
a resource.
Divide main
memory space to
hold a number of
programs at a time.
Makes the system
more effective
Fig: Schematic memory
map of a microcomputer.

Process

A process is a program in execution


The entity that can be assigned to and
executed by a processor
A unit of activity characterized by a
single sequential thread of execution

Virtual Memory

Problem1: Several programs need to


use the same memory
Solution: Divide the memory.
Problem2: What will be the starting
address of the program?
Solution: O/S adjust re-locatable
addresses upon loading

Virtual Memory (2)

Problem3: A programs needs more


memory than the physical memory
available?
Solution: Overlay unused functions with
other functions.

Virtual Memory (3)

Better solution to all the three problems


Each program assumes it has access to
the entire memory called the virtual
address space
O/S allocates a small part of the
physical address space to each
process. Remaining virtual address
space kept somewhere in disk

Paging

A predominant method for implementing


virtual memory
Divide physical and virtual memory into
fixed size pages
A page table maps virtual page to
physical page
Maps virtual page # physical page #

Example of paging

UNIX

Hardware is surrounded by the


operating system software
Operating system is called the system
kernel
Comes with a number of user services
and interfaces

Shell
Components of the C compiler
32

UNIX Kernel

33

Modern UNIX Kernel

34

Central Processing Unit (CPU)


Processors

Central Processing Unit (CPU)


CPU is the place where data is
manipulated.
Consists of millions of tiny switches
called transistors.
Fundamental operation is to execute a
sequence of instructions (program).
Instructions set of a CPU are called opcodes (short for operation codes).

Central Processing Unit (CPU)


To execute an
instruction, it must be
moved from main
memory to the CPU
registers.
CPU consists of two
basic parts Control
Unit (CU) and
Arithmetic Logic Unit
(ALU).

CU and ALU
CU is responsible for moving data from
one storage to another. Instruction set
of CPU is built into the CU.
When CU encounters an arithmetic or
logical operation, it passes it on to the
ALU.
ALU consists of a no. of high speed
registers. The operands should be in
the ALU registers.

Machine Cycle
These series of steps to execute an
instruction is called a machine cycle.
Machine Cycle
Instruction Cycle

Execution Cycle

(performed by CU)

(performed by ALU)

Fetch

Decode

Execute

Store

Instruction Cycle
Fetch: Retrieve instruction from memory.
Decode: Interpret the instruction.

Main
Memory
(C=A+B)

System Bus Control Unit

Execution Cycle
Execute: Perform the desired operation
by converting the instruction into
microcode.
Writeback: Store the result to memory
but not always necessary.

Instruction
Typical Instruction : Add the operands
stored in address A and B; store the
result in C; Address of next instruction is
in N.
Add

Decrease size of Instruction


Store instructions sequentially, then N is
implied and can be omitted
Add

A special register Program Counter


stores the address of the next
instruction to be executed.

Size of Instructions
Size of instructions can vary
Some instructions need only one
address, example INC P (Increment the
operand stored in address P by 1).
Making size of all instructions uniform
will make the processor design simple.
Solution: Make size of instruction one
address

One Address Instructions


Make the size of all instruction one
address.
How to execute an operation like Add
which require at least two operands?
Store one operand in a special register
whose address need not be specified
explicitly (Accumulator) .

Sequence of single address


Instruction to Add two nos.
Abbreviated
Instruction

Address
of
Operand

Task Performed

CLA A

Clear Accumulator and


place operand A in it

Add operand B to the


contents of the
accumulator

Store the contents of


accumulator at
address location of C.

ADD B

STO C

RISC Processors
RISC processors use simple
instructions.
More lines of code, more memory and
compiler needs to perform more work.
Adv: Require less CPU registers. Since
all instructions execute in uniform time
pipelining is possible.

CISC Processors
Complex Instruction Set Computers
(CISC) goal is to complete a task with
as few lines of instruction as possible.
Example ADD A,B: Loads the two
values into two separate registers, adds
the value in the ALU and then stores the
sum in appropriate register.
Requires less memory and compiler
needs to do less work.

CISC Processors contd.


Disadvantage is require more cycles per
instruction and more CPU registers.
Since instruction set is complex, more
difficult to design and different
instructions take different amount of
cycles.
As memory prices become cheaper
RISC processors have become the
main stable.

Performance Equation

RISC tries to
reduce this
parameter

CISC tries to
reduce this
parameter

Das könnte Ihnen auch gefallen