06 Microprocessor Systems Lecture No 06 and 07 General Program Concept
06 Microprocessor Systems Lecture No 06 and 07 General Program Concept
Systems
Lecture No 06 and 07 General
Program Execution Concept
By Nasir Mahmood
Overview of Last Lecture
Assembly Language & Machine Language
How the translation is done
Compiler, Assembler, OS
Multistage Pipeline Concept
Concept of Stages and cycles execution
Make the execution fast by parallel pipelines
Superscalar Processor
Today’s Topics
Reading from Memory
Operating Systems
Multitasking
New Trends
Real Time Embedded Systems
Reading From Memory
Program throughput is often dependent on the speed of
memory access.
5
Operating System level
Operating System
An OS is a program that controls the execution of
application programs and acts as an interface b/w
the user and the computer hardware.
Like other programs, it provides instructions for
the processor. The key difference is the intent of
the program.
OS directs the µp in the use of system resources
and control timing of its execution of other
programs.
7
Operating System
But in order for the up to do anything, it must
cease executing the OS and execute other
programs.
Therefore, the OS relinquishes control for the
up to do some ‘useful’ work and then resumes
control long enough to prepare the processor to
do the next piece of work.
8
Multitasking
A Multitasking OS is capable of running multiple tasks at
the same time
Most modern OS simultaneously execute tasks that
communicate with hardware, display user interfaces,
perform file processing etc.
A CPU can really execute only one instruction at a time
A component of the OS – the scheduler- allocates a slice
of the CPU time to each task. During each time slice the
CPU executes a block of instructions, stopping when the
time slice has ended.
9
Multitasking (contd.)
10
Scheduling
The key to
multiprogram
ming or
multitasking is
scheduling.
11
Round Robin Scheduling
12
Process?
But first lets define a ‘Process’
A program in execution OR
The entity to which the processor is assigned
Process states
New: A new process is admitted but not executed. OS will
initialize the process, making it ready
Ready: process is ready & awaiting access to µp
Running: Process is being executed by µp
14
Process Control Block
contains:
Identifier
State
Priority
Program counter
Memory Pointers
Context Data
Accounting Info
15
Multitasking (contd.)
A Multitasking OS runs on a CPU that
supports task switching, the processor saves
the state of each task before switching to a new
one
A task’s state consists of the contents of the
processor registers, program counter, and status
flags, along with references to the task’s memory
segments.
Preemptive Multitasking assigns priorities to
tasks and a higher priority task can interrupt a
low priority task.
16
Memory Management
Effective memory management is vital in a
multiprogramming system.
If only a few processes are in memory, then for
much of the time all processes will be waiting
for I/O and processor will be idle.
Thus, memory needs to be allocated efficiently
to pack as many processes into memory as
possible.
17
Memory Management
(Swapping)
What to do?
Main memory could be expanded to
accommodate more processes but
Main memory is expensive
The appetite of programs for memory grows as fast
as the memory. Thus, larger memory results in
larger processes, not more processes.
18
Swapping
Swapping
Processes stored on disk are brought in one by one
as space becomes available.
Swapping however, is an I/O operation. Therefore,
there is the potential of making the problem worse.
However, swapping will generally enhance
performance.
A more, sophisticated scheme, involving virtual
memory improves performance over swapping.
19
Paging
Each process is broken down into smaller
chunks known as pages
Each page of the program could be assigned
available chunks of memory known as frames
Smaller processes require fewer pages, larger
processes require more.
When a process is brought in, its pages are
loaded into available frames and a page table is
set up by the OS.
20
Paging
The frames do
not have to be
contiguous as the
page table shows
the frame location
for each page of
the process.
21
Virtual Memory & Demand
Paging
As a process is executed only in main memory,
that memory is referred to real memory. But
the user sees a much larger memory – which is
allocated on disk.
This is referred to as the Virtual Memory
which is usually 3 times that of main memory
Virtual Memory allows for very effective
multiprogramming or multitasking and relieves
the user of the constraints of main memory.
22
Virtual Memory (Windows Task Mgr)
23
Virtual Memory & Demand
Paging
Demand Paging simply means that each page of a
process is brought in only when it is needed i.e. on
demand.
Therefore, it is not necessary to load an entire process
into main memory. Instead, with demand paging the
OS breaks the program into pieces that are loaded one
at a time.
When the process needs code which is not in
memory, a page fault is triggered which causes the
OS to bring in the desired page.
24
How Programs Run (Putting it
together)
Load & Execute Process
OS searches for the file in the current directory and
then in the Pre-Defined directories called Paths
If found the OS retrieves the basic info about the
file like the size and physical location
OS determines the next available location in
memory and loads the program file into memory
OS executes a branching instruction that begins
execution of the Program’s first machine
instruction, As soon as it starts running it is called
a Process
25
How Programs Run (contd.)
26
What is Real-time?
A system is classified as real-time if it is
required to complete the work on a timely
basis
It is of utmost importance that the correctness
of the timely behavior of real-time system
should be validated
Often real-time systems are also safety-critical, a
missing of a deadline an lead to disastrous
consequences
Hard and Soft deadlines
Summary
Reading from Memory
Bottleneck, Cache Memory
Operating Systems
It manages all the process running and do the
memory management
Multitasking
Tasks switching
New Trends
Real Time Embedded Systems
THE END