Académique Documents
Professionnel Documents
Culture Documents
What is an operating
system?
• A program that runs on the “raw” hardware and
supports
– Resource Abstraction
– Resource Sharing
• Abstracts and standardizes the interface to the
user across different types of hardware
– Virtual machine hides the messy details which must
be performed
• Manages the hardware resources
– Each program gets time with the resource
– Each program gets space on the resource
• May have potentially conflicting goals:
– Use hardware efficiently
– Give maximum performance to each user
What is the OS made of?
Hardware
Shell
Kernel and
system software
Users
Other Applications
OS cntd …..
• User – The system representation of the human
operator who requests for services.
• Application Software – Special software to
help the user do his task (E.g.. MS Word)
• Shell – The program that interprets the
commands or requests given by the user and
gets the job done by the kernel.
• Kernel – The core of the operating system. It
uses the hardware to do the jobs required by
the user or the system. It coordinates among
the hardware and interfaces it with the above
layers.
• System Software – Software that can access
the hardware directly and generally provides
various system services. (E.g.. The kernel
itself, device drivers etc.).
• Hardware – The set of electronic devices that
OPERATING SYSTEM T h e La ye rs O f
OVERVIEW A S yste m
H um ans
Pro g ra m
In te rfa ce
U se r Pro g ra m s
O . S . In te rfa ce
O .S .
H a rd w a re In te rfa ce /
Privile g e d
In stru ctio n s
D isk / Ta p e / M e m o r
y 1: Operating Systems Overview 5
The Goals of an OS
• Let users run programs:
– Correctness
• Memory boundaries, priorities, steady
state
•
– Convenience
• User should not handle the tiny details
(encapsulate/abstract), provide
synchronization primitives, system
calls, file system, tools
The Goals of an OS
• Let users run programs:
– Efficiency
• Resource Utilization, resource Sharing,
Multitasking
–
– Fairness (in resource allocation)
• Among: users, tasks, resources
• The tradeoff between efficiency and
fairness
Operating System Organization
• Modified microkernel architecture
– Not a pure microkernel
– Many system functions outside of the
microkernel run in kernel mode
• Any module can be removed,
upgraded, or replaced without
rewriting the entire system
8
Kernel-Mode Components
• Executive
– Contains base operating system
services
• Memory management
• Process and thread management
• Security
• I/O
• Interprocess communication
• Kernel
– Consists of the most used
components 9
Kernel-Mode Components
• Hardware abstraction layer (HAL)
– Isolates the operating system from
platform-specific hardware
differences
• Device drivers
– Translate user I/O function calls into
specific hardware device I/O
requests
• Windowing and graphics systems
– Implements the graphical user
interface (GUI) 10
Process Management
• A processis a program in execution. A
process needs certain resources,
including CPU time, memory, files,
and I/O devices, to accomplish its
task.
• The operating system is responsible for
the following activities in connection
with process management.
– Process creation and deletion.
– process suspension and resumption.
– Provision of mechanisms for:
• process synchronization
• process communication
Main-Memory
Management
• Memory is a large array of words or bytes,
each with its own address. It is a repository
of quickly accessible data shared by the
CPU and I/O devices.
• Main memory is a volatile storage device. It
loses its contents in the case of system
failure.
• The operating system is responsible for the
following activities in connections with
memory management:
– Keep track of which parts of memory are
currently being used and by whom.
– Decide which processes to load when
memory space becomes available.
– Allocate and deallocate memory space as
needed.
File Management
– command-line interpreter
– shell (in UNIX)
Service
routines
Utility
routines
Microkernels (client-server)
Application
OS
Hardware
Difference from Desktop OS
• An RTOS is closely linked to the
application with only the needed
functions present
• Desktop operating systems start at
power-up time and they start
applications. An RTOS is started by
an application
• In RTOSs, safety is sacrificed for
performance
Real time kernel
• It contains only the minimal set of
services required for running the user
applications/tasks
• Basic functions of real time kernel are
– Task/ process management
– Task/ process scheduling
– Task/ process synchronization
– Error/ exception handling
– Memory management
– Interrupt handling
– Time management
Process/Task Concept
• Process is a program in execution;
process execution must progress in
sequential fashion
• A process includes:
– program counter
– stack
– data section
Process/Task Concept
• Task States:
– Running: Instructions are being
executed
– Ready: The process is waiting to be
assigned to a process
– Blocked: The process is waiting for
some event to occur
– terminated: The process has finished
execution
– new: The process is being created
Task states
Whatever the task
needs, happens
blocked ready
This is Another
highest ready task
Task needs priority is higher
something ready task priority
to happen before
it can continue
running
Task State Transitions
Task / process management
• It deals with
– Sets up memory space for tasks
– Loads the tasks code into memory space
– Allocates system resources
– Sets up a TCB(task control block) for task
– Task/ process deletion
Task / process management
cntd….
• TCB contains the following set of information
– Task ID- task identification number
– Task state- current state of task( ready, waiting)
– Task type- hard real time or soft real time or
background task
– Task priority- is 1 for task with priority -1
– Task context pointer- pointer for context saving
– Task memory pointer - pointers to code memory, data
memory, stack memory
– Task system resource pointer- pointer to system
resources(mutex, semaphores)
– task pointers- pointers to other TCBs
– Other parameters- other relevant task parameters
Task / process management
cntd….
• TCBs are kernel dependent.
• Task management services utilizes TCB in
following way.
– Creates a TCB for a task on creating a task
– Delete / remove the TCB of a task when the task is
terminated or deleted
– Reads the TCB to get the state of the task
– U[date the TCB with updated parameters on need basis (on
context switching)
– Modify the TCB to change the priority of the task
dynamically
Task / process scheduling
• Deals with sharing the CPU among
various tasks / processes.
• Kernel application called “
Scheduler” handles task
scheduling.
• Scheduler is nothing but an algorithm
implementation,which performs
efficient and optimal scheduling of
the tasks to provide a deterministic
behaviour.
Task / process
synchronisation
• Deals with synchronising the
concurrent access of a resource,
which is shared across multiple
tasks and the communication
between various tasks.
Error / exception handling
• Deals with registering and handling the
errors occurred /exceptions raised
during the execution of the tasks.
• Errors/ exceptions can be insufficient
memory, timeouts, deadlocks,
deadline missing, bus error, divide by
zero etc.
• These can happen at kernel level
services( deadlocks) or task
level(timeouts) .
• OS kernel gives all the errors in the
form of system calls( API). Eg is
Memory management
• Deals with allocating memory.
• Predictable timing and deterministic behavior are achieved at the cost of
memory allocation in RTOS.
• RTOS uses block based memory allocation technique where as GPOS uses
dynamic memory allocation.
• Blocks are stored in “ free buffer queue”.
• RTOS kernels allow tasks to access the memory block without memory
protection.
• Few RTOS uses virtual memory concept for memory allocation.
• Block memory concept avoids the garbage collection overhead.
• Block based memory allocation achieves deterministic behavior with the
trade of limited choice of memory chunk size and suboptimal memory
usage.
•
Interrupt handling
• Deals with handling of various types of
interrupts.
• Interrupts provide real time behavior to the
systems.
• It informs the processor that external device
or task associated with it requires
attention of CPU.
• They can be either synchronous or
asynchronous.
• Synchronous- interrupts which occur in sync
with currently executing task. Eg – divide
by zero, memory segmentation error etc.
• Asynchronous –interrupts which occur at
point of execution of any task . Eg –
Time management
• Accurate time management is essential for
providing precise time reference for all
applications.
• Time reference to kernel is provided by a
high- resolution Real Time Clock(RTC)
hardware chip ( hardware timer).
• The hardware timer is programmed to
interrupt the processor/ controller at a
fixed rate. This is called “ timer tick”.
• Some RTOS provide options for selecting the
required kernel functions at the time of
building a kernel.
•
Real-Time Systems (Cont.)
• Hard real-time:
– Secondary storage limited or absent, data stored in
short term memory, or read-only memory (ROM)
– Conflicts with time-sharing systems, not supported by
general-purpose operating systems.
• Soft real-time
– Limited utility in industrial control of robotics
– Useful in applications (multimedia, virtual reality)
requiring advanced operating-system features.
Computing Elements
Applications
Programming paradigms
Threads
Threads
Interface
Interface
Microkernel
Microkernel Operating System
Multi - Processor Computing
P P P
System
P ..
P P Hardware
STACK STACK
Shared
Sharedmemory
memorysegments,
segments,pipes,
pipes,open
openfiles
filesor
ormmap’d
mmap’dfiles
files
DATA
DATA DATA
DATA
TEXT
TEXT TEXT
TEXT
Shared
Shared Memory
Memory
maintained
maintained by kernel
by kernel
processes
processes processes
processes
Processes
The Process Model
creation
1.System initialization
• Execution of a process creation
system
1.User request to create a new process
2.Initiation of a batch job
Process Termination
• Process executes last statement and
tells the OS
– Output status from child to parent
– Process’ resources are deallocated by
operating system.
• Parent may terminate execution of
children processes
– Child has exceeded allocated resources.
– Task assigned to child is no longer
required.
– Parent is exiting (options)
• Operating system does not allow child to
continue if its parent terminates.
• Cascading termination.
Process Termination
Conditions which terminate processes
SHARED
SHARED
MEMORY
MEMORY
THREAD
THREAD
DATA
DATA
Threads within a process THREAD
THREAD
TEXT
TEXT
●Independent executables
●All threads are parts of a process hence communication
easier and simpler.
Levels of Parallelism
Code-Granularity
Code-Granularity
Code
Code Item
Item
Task
Task ii-- Task
Task Large
ll Task
Task ii ii++11 Large grain
grain
((task level
task level))
Program
Program
func1
func1 func2
func2 func3
func3
Medium
Medium grain
grain
(( )) (( )) (( )) ((control
control level
level))
❍Task {{
....
{{
....
{{
....
Function
Function
❍Control ....
....
....
}}
....
....
....
}}
....
....
....
((thread
thread))
❍Data }}
main ( )
{
thread_t tid;
int exit_value;
- - - - - - - - - - -
thread_create (0, 0, func (), NULL, &tid);
- - - - - - - - - - -
thread_join (tid, 0, &exit_value);
- - - - - - - - - - -
}
Single and Multithreaded
Processes
Threads
The Thread Model (1)
67
The Thread Model (2)
73
Various Implementations
PThreads
• A POSIX standard (IEEE 1003.1c) API for thread creation and
synchronization
• API specifies behavior of the thread library, implementation is
up to development of the library
• Common in UNIX operating systems (Solaris, Linux, Mac OS X)
•
Windows Threads
Java Threads
• Examples
– Windows XP/2000
– Solaris
– Linux
– Tru64 UNIX
– Mac OS X
Implementing Threads in the
Kernel
Thread cancellation
Application
Application Application
Application
CPU
CPU
CPU CPU CPU CPU
Application
Application
P2
P2 CPU
P3
P3
time
time
Number
Numberof
ofSimulatneous
Simulatneousexecution
executionunits
units>>no
noof
ofCPUs
CPUs
Multithreading
Multithreading -- Multiprocessors
Multiprocessors
Concurrency
Concurrency Vs
Vs Parallelism
Parallelism
CPU
P1
P1
CPU
P2
P2
P3 CPU
P3
time
time
No
Noof
ofexecution
executionprocess
process==no
noof
ofCPUs
CPUs
Multi-tasking
• Types of multi-tasking
– Co-operative multi-tasking
– Pre-emptive multi-tasking
– Non – preemptive multi-tasking
Multitasking
Task Scheduling
• Tasks enter the blocked state voluntarily
• Some part of the RTOS is responsible for
determining when a task needs to be
moved from the blocked state to the
ready state (in response to some event)
• The scheduler is in charge of the running
state, it selects from the ready tasks, the
one with the highest priority and runs it
From Scheduler organization
other Remove the running process
states
Process
Ready process Descriptors
Ready List
Enqueuer
Process P2
…
yield (*, scheduler);
…
• Possible problems:
...
– If the processes are not voluntarily cooperate with the others
– One process could keep the process forever
Preemptive scheduler
In te rva lTim e r{ S e tIn te rva l(< p ro g ra m a b le V a lu e
In te rru p tC o u n t = >{
In te rrp tC o u n t - 1 ; K = p rg ra m m a b le V a lu e ;
if ( In te rru p tC o u n t < = 0 ){ In te rru p tC o u n t = K ;
In te rru p tR e q u e st = T R U E }
In te rru p tC o u n t = K ;
}
}
• Throughput
– no. of processes completed per time unit
• Turnaround time
– how long it takes to complete a process
• Waiting time
– the total time a process is in the ready queue
– the measure used in chapter 5
• Response time
– time a process takes to start responding
Scheduling – Metrics
• Simplicity – easy to implement
• Job latency – time from start to completion
• Interactive latency – time from action start
to expected system response
• Throughput – number of jobs completed
• Utilization – keep processor and/or subset
of I/O devices busy
• Determinism – insure that jobs get done
before some time or event
• Fairness – every job makes progress
Preemptive vs. Non-preemptive
scheduling
• Non-preemptive scheduling:
– The running process keeps the CPU
until it voluntarily gives up the CPU
• process exits Run 4 Termin
ated
• switches to blocked statening 1
3
• 1 and 4 only (no 3)
Rea Bloc
• Preemptive scheduling: dy ked
– The running process can be
interrupted and must release the
CPU (can be forced to give up CPU)
Preemptive vs. non-preemptive
scheduling
CPU scheduling decisions may take
state
Preemptive vs. non-preemptive
scheduling
• When scheduling takes place only under
circumstances 1 and 2, we say that the
scheduling scheme is non-preemptive;
otherwise, its called preemptive
•
• Under non-preemptive scheduling, once
the CPU has been allocated to a process,
the process keep the CPU until it release
the CPU either by terminating or by
switching to waiting state. (Windows 95
and earlier)
Preemptive vs. non-preemptive
scheduling
• Preemptive scheduling incurs a cost
associated with access to share data.
•
• Consider the case of two processes that
share a data. It is preemptive so that
while one process is updating the data,
the second process then tries to read the
data, which are in an inconsistent state.
(Ch6)
Task scheduling
classification
• Non – preemptive scheduling
– First-come-First Served( FCFS)/FIFO
scheduling
– Last-Come-First Served(LCFS)/LIFO
Scheduling
– Shortest Job First (SJF) Scheduling
– Priority based Scheduling
• Pre-emptive Scheduling
– Pre-emptive SJF/ Shortest Remaining
Time(SRT)
– Round Robin (RR) Scheduling
First Come First Served
• Non-preemptive algorithm
• This scheduling strategy assigns priority to
processes in the order in which they
request the processor
– The priority of a process is computed by the
enqueuer by time stamping all incoming
processes and then having the dispatcher to
select the process that has the oldest time
stamp
– Alternative implementation consists of having
the ready list organized as a FIFO data
structure (where each entry points to a
process descriptor); the enqueuer adds
processes to the tail of the queue and the
dispatcher removes processes from the head
of the queue
First Come First Served (FCFS)
FCFS example
1200TTRnd
i
0
τ(pi)
350
0 350 475 950 (p i)
1275
1 125
2 475
P0 P1 P2 P3 P4
3 250
4 75
• Convoy effect
– small processes can get stuck
behind a big process
FCFS drawbacks
Shortest Job First (Shortest
Process Next)
2 475
3 250 650 750 850 950 1050 1150 1250 1275
4 75 P0 P2 P3 P0 P2 P3 P0 P2 P0 P2 P2 P2 P2
11 P3 1
P4 7
Average
10 . 5
10
9.5
1 2 3 4 5 6 7
Time Quantum
RR Time Quantum