# Why-We-Need-Operating-Systems

Document Sample

```					   Summary of the Last Lecture
• Evolution of Operating Systems

• Types of Operating System Services

• The Programmer’s View -- SVC’s

• The User View -- System and Application
Programs
Outline of the Lecture
1. Superlinear Speedup
2. Structure of OS
3. Notion of a Process
4. CPU Scheduling:
reasons,
methods,
algorithms
Example of Superlinear Speedup
Search in a tree with n-degree leaves.

At the first level, one leaf contains a hint which leaf in the one of sub-trees
contains a goal.
Only one leaf in the second level contains a goal.

Depth-first search does average work Ws=n*n/3+n/3...

The same algorithm on n processors does 1 step to find a hint and the second
step to find a goal. Assuming shared memory, the overhead of
communicating hint is also one step. Hence,
Wn=2, on=1 and Tn=3, so Sn=(n+1)*n/9
and En=(n+1)/9, clearly superlinear speedup for n>9.

Which sequential algorithm corresponds to parallel one and what
is its work ?
Depth-First Search with Hints
Analysis of Sequential Execution
1. Single-level tree
Consider a tree with a root and n leaves in which a
goal is randomly (with uniform probability) hidden
in one of the leaves. Inspection of each node takes
a unit of processing time. What is the average
processing time of the depth-first search?
Depth-First Search with Hints
Analysis (continued)
We always need to inspect a root, so this takes 1.
Depending on the position of the goal g, we have
that the average processing time is
n
g (n  1)n      n 1 n  3
1   1           1     
g 1 n    2n           2    2
because probability of a goal at a given node g is
equal to 1/n
Two-Level Tree with a Hint
Consider a tree from the previous section
with a hint placed randomly (with uniform
distribution) at one root of a subtree. A hint
contains g, an identity of the subtree with the goal.
Let h denote the position of the hint. If h ≥
g, the hint is useless and the processing is the
same as in the previous section. Otherwise, hint
speeds up processing by requiring processing h – 1
subtrees plus the root with the hint, followed by
the processing of the subtree with the goal. Hence,
the average processing time becomes:
Two-Level Tree Without a Hint
(continued)
Let g denote a root of the subtree which contains a goal.
We need to process (g – 1) trees without a goal, which
requires (g – 1)(n + 1) steps, plus the subtree g, which
requires (n + 3)/2 on average, to reach the goal. Hence,
the total time is:

1 n                   n3      n 1 n    n 1 n  n3
1   ( g  1)*(n  1)       1     1 g  n 11  2
n g 1                 2         n g        g

n  1 (n  1)* n n  1      (n  1)2 (n  1) n 2  n     n2
 1      *                 1                        
n       2        2           2        2       2        2
Two-Level Tree with a Hint (continued)
1 n  g 1                n3 n                       n  3 
1  2    (h  1)*(n  1)         ( g  1)*(n  1)        
n g 1  h1                2  h g                      2 
g 1

 (h  1) * (n  1)  (n  3) / 2  ( g  1) *[ gn  g  n  1] / 2
h 1

n

 [( g  1) *(n  1)  (n  3) / 2]  (n  g  1) *[ gn  g  n / 2  1/ 2]
h g

so after simplification, we need to compute the sum
n
1
1 2
2n
 [ g 2 (n  1)  g (2n 2  3n  1)  n 2  n]
g 1
which is equal to

(n  1) 2 (2n  1)           2n 2  3n  1 n 2  n n 2  n  6.5  0.5 / n n 2
1                     (n  1)                                            
12n                         4n         2n               3             3
Hence, having a hint saves about 33% of the execution time
Software Structure of a Computer
Basic Structure vs. Abstract View of OS
OS Basic Components and Functions

Components:           Function:
Process manager       Process control, execution,
scheduling…
Memory manager        Memory Management
Resource manager
File manager          File Manipulation
Device manager        Device Manipulation

Multi-component functions:
Communication between processes
Information Maintenance
Modern Operating Systems
Windows (Microsoft Corporation) these include a
family of systems: 98, Me, CE, 2000, XP, Vista,
and others
Linux (     (Linus Torvalds, OSF GNU)
OSF-1       (DEC, OSF)
Solaris     (Sun Microsystems) (
IRIX        (Silicon Graphics)
OS2         (IBM)
OS/390      (IBM)
VMS         (Dec/Compaq/HP)
MacOS       (Apple)
UNIX Structure
(the users)
shells and commands
compilers and interpreters
system libraries
system call interface to the kernel
signals           file system;     CPU scheduling;
terminal handling;      swapping;             page
character I/O   block I/O system;      replacement;
system;          disk and tape     demand paging;
terminal drivers         drivers        virtual memory
kernel interface to the hardware
terminal controllers;   device controllers;
terminals           disks and tapes         …
General Layered Structure

new                     layer M
operations

hidden     layer M - 1
operations

existing
operations
OS/2 Layered Structure

Application            Application               Application

Application Programming Interface API extension

subsystem        subsystem                     subsystem

(compare with Unix)
System
•memory management
•device management

device driver   device driver   device driver   device driver
Implementation View of Operating
System
Event Driven, consisting of Events:
SVC Call
I/O Device Interrupt
Trap (Fault)
Tables, Queues -- to remember what is
happening when processing the next event
Device Table
Process or Job Table
User Table
File Table ...
Definition of a Process
• Two important types of dynamic entities in a computer system are
• Dynamic entities only exist at execution time, and their behavior
exhibits state changes.
• A process is the fundamental computational unit that requests
various types of services in the computer system.
• Other descriptions:
–   Program in execution
–   Asynchronous activity
–   Animated spirit of a procedure
–   Locus of control of a procedure in execution
–   What is represented by process control block
–   Entity to which processors are assigned
–   OS Dispatchable unit
Operations on Processes
• Processes are executing, ready to execute, or waiting to
resume execution (several processes can be active at a time in
multiprogramming mode)
• Only one process is actually running at any instant of time
• Operations:
– Create/Destroy (when to destroy sub-processes?)
– Suspend/Resume
– Block/Wakeup
– Change Priority
– Dispatch
• Problem: What to do with processes blocked infinitely long
Process Creation
• On a typical operating system, a process is created
– In response to a new job arriving
– A new user who carries out a login
– A currently executing process that creates a new
process.
• A process is created if there is sufficient memory
available, and the process waits if other resources it
needs are not available.
CPU Scheduling
(1)   Why to schedule CPU?

(2)   How to switch CPU?

(3)   Scheduling algorithms

(4)   Evaluation and selection of algorithms
Switching the CPU from One Process
to Another

executing                                               Ratio of execution to switching overhead
interrupt or system call       defines efficiency

Save state into PCB0
idle

interrupt or         executing
idle                                        system call

Save state into PCB1
idle

process P0          operating system                process P1
Process States
 Created
 Running (executing)
 Blocked (suspended and waiting for I/O or other event)
 I/O processing
 Waiting for passive resources
 Interrupted by the OS
 Terminated
Diagram of Process States
Terminate                              Running
Has the CPU
Problem:
How to select
New            Dispatch                              Time_out,
Process                                              very small?
Time_out
large?
Block

Blocked
Waits for the                         Waits for I/O
CPU
Another View of the Diagram
States of a Process Extended
arrive
terminate
Blocked
Time_out
I/O or event
wait
Dispatch
Resume                                             Resume
Running
Suspend
Suspend

Suspend suspended
Suspended-         I/O or event completion          Suspended-