COSC 4P13 - Brock University

Download Report

Transcript COSC 4P13 - Brock University

COSC 4P13
Operating Systems : Design and
Implementation
Course Description(1)
 The
Goals for this course
 Understand
UNIX
 Understand Operating Systems
 Prerequisites:
 COSC
2P13 : Introduction to Operating Systems
 COSC 2P91 : Procedural Programming
 COSC 1P12 : Computer Organization and
Assembly Language
Course Description(2)

An intensive study of computer operating
system design
 Multiprogramming
 Time-sharing
 Real-time
processing
 Job and task control
 Synchronization of concurrent processes and
processors
 Resource scheduling
 Protection
 Management of hierarchical storage.
How to study this course
 Read
and remember
 Read
the book, remember the concepts
and commands
 Think
 Think
operating systems as natural
administrative agents
 Practice
 Coding
with UNIX, use and understand of
UNIX commands and get the results
The Textbook Used
 Uresh
Vahalia, UNIX Internals: The
New Frontiers, Prentice Hall, 1996
 Why we use this book?
 UNIX
is one of the popular operating
systems of the world.
 If you understand UNIX, you can
understand other operating systems.
References
William Stallings, Operating Systems,4th
Ed., Prentice Hall,2000
 A. Tanenbaum, Modern Operating Systems,
2nd ed. Prentice Hall 2001
 Kay A. Robbins and Steven Robbins,
Practical UNIX Programming, Prentice
Hall,1996
 W. R. Stevens, Advanced Programming in
the UNIX Environment, Addison Wesley,
1992

Operating System Overview



Computer System
Computer Hardware
 Components
 Registers
 Instruction execution
 Interrupt
 Memory Hierarchy and I/O
Operating System
 Services of OS
 Major Achievements
 Characteristics of Modern OS
Computer System
End
User
Programmer
Application
Programs
Utilities
Operating-System
Computer Hardware
OperatingSystem
Designer
Computer Hardware




Processor
Main Memory
 referred to as real memory or primary memory
 volatile
I/O modules
 secondary memory devices
 communications equipment
 terminals
System interconnection
 communication among processors, memory, and
I/O modules
Computer Components:
top-level view
Memory
..
.
CPU
PC
MAR
IR
MBR
I/O AR
I/O BR
I/O Module
Instruction
Instruction
Instruction
.
.
Buffers
- Memory Address Register
address
MBR
for next read or write
- Memory Buffer Register
data
to be written into memory
receives
data read from memory
Data
Data
Data
Data
..
.
..
MAR
I/OAR
- I/O Address
specifies
I/OBR
a particular I/O device
- I/O Buffer
exchange
of data between an I/O
module and the processor
I/O Module Structure




Data to/from system bus are buffered in data
register(s)
Status/Control register(s)
I/O logic interact with CPU via control bus
Contains logic specific to the interface of each device
Processor Registers

User-visible registers
 Data
Registers
 Address Registers
index register
 segment pointer
 stack pointer

 Condition
Codes or Flags
 Control and Status Registers
Program Counter (PC)
 Instruction Register (IR)
 Program Status Word (PSW)

Instruction Execution
 Processor
executes instructions in a
program
 Instructions are fetched from memory
one at a time
Fetch Cycle
START
Fetch Next
Instruction
Execute Cycle
Execute
Instruction
HALT
Instruction Fetch and
Execute
 The
processor fetches the instruction
from memory
 Program counter (PC) holds address of
the instruction to be fetched next
 Program counter is incremented after
each fetch
Instruction Register
Fetched instruction is placed here
 Types of instructions

 Processor-memory

transfer data between processor and memory
 Processor-I/O

data transferred to or from a peripheral device
 Data

processing
arithmetic or logic operation on data
 Control

alter sequence of execution
Interrupts
An interruption of the normal processing of
processor
 Improves processing efficiency
 Allows the processor to execute other
instructions while an I/O operation is in
progress
 A suspension of a process caused by an
event external to that process and performed
in such a way that the process can be
resumed

Classes of Interrupts
 Program
 arithmetic
overflow
 division by zero
 execute illegal instruction
 reference outside user’s memory space
 Timer
 I/O
 Hardware
failure
Instruction Cycle with
Interrupts
Fetch Cycle
Execute Cycle
Interrupt Cycle
Interrupts
Disabled
START
Fetch Next
Instruction
Execute
Instruction
HALT
Check for
Interrupt:
Interrupts
Process Interrupt
Enabled
Interrupt Handler
 A program
that determines nature of
the interrupt and performs whatever
actions are needed
 Control is transferred to this program
 Generally part of the operating system
Interrupt Cycle
 Processor
checks for interrupts
 If no interrupts fetch the next instruction
for the current program
 If an interrupt is pending, suspend
execution of the current program, and
execute the interrupt handler
Simple Interrupt Processing
Device controller or
other system hardware
issues an interrupt
Processor finishes
execution of current
instruction
Processor signals
acknowledgment
of interrupt
Save remainder of
process state
information
Process interrupt
Processor pushes PSW
and PC onto control
stack
Restore process state
information
Processor loads new
PC value based on
interrupt
Restore old PSW
and PC
Interrupts improve CPU usage





I/O pgm prepares the I/O module
and issues the I/O command (eg:
to printer)
I/O pgm branches to user pgm
User code gets executed during
I/O operation (eg: printing): no
waiting
User pgm gets interrupted (x)
when I/O operation is done and
branches to interrupt handler to
examine status of I/O module
Execution of user code resumes
Multiple interrupts:
sequential order



Disable interrupts during an interrupt
Interrupts remain pending until the processor enables
interrupts
After interrupt handler routine completes, the
processor checks for additional interrupts
Multiple Interrupts: priorities



Higher priority interrupts cause lower-priority interrupts to wait
Causes a lower-priority interrupt handler to be interrupted
Example: when input arrives from communication line, it needs to be
absorbed quickly to make room for more input
Cache/Main-Memory Structure
Memory
Address
0
1
2
3
Block
(k words)
Slot
Number Tag
0
1
2
Block
C -1
Block Length
(k words)
(b) Cache
Block
2n - 1
Word
Length
(a) Main Memory
Cache Design
 Cache
size
 Block size
 Mapping function
 Replacement algorithm
I/O Techniques
 Programmed
I/O
 Interrupt-Driven I/O
 Direct Memory Access
Programmed I/O
Insert Read
command to CPU I/O
I/O Module
Read Status
of I/O
Module
Not
Ready
Check
Status
I/O CPU
Error
Condition
Ready
Read word
from I/O
Module
I/O CPU
Write word
CPU Memory
into memory
No
Done?
Yes
Next Instruction
I/O
module performs
the action, not the
processor
Sets
appropriate bits
in the I/O status register
No
interrupts occur
Processor
is kept busy
checking status
Interrupt-Driven I/O
Insert Read
command to CPU I/O
Do something
I/O Module
else
Read Status
of I/O
Module
Interrupt
I/O CPU
Error
Condition
Check
Status
Ready
Read word
from I/O
Module
is interrupted
when I/O module ready to
exchange data
Processor
is free to do other
work
I/O CPU
Write word
CPU Memory
into memory
No
Processor
Done?
Yes
Next Instruction
No
needless waiting
Consumes
a lot of processor
time because every word read
or written passes through the
processor
Direct Memory Access
Issue Read
block command
to I/O module
Read status
of DMA
module
CPU DMA
Do something
else
Transfers
a block of data
directly to or from memory
Interrupt
DMA CPU
An
interrupt is sent when
the task is complete
Next Instruction
The
processor is only
involved at the beginning
and end of the transfer
Operating System
 Making
computing power available to
users by controlling the hardware
 a program that controls execution of
application programs
 an interface between the user and
hardware
 Directs
the processor in the use of system
resources
 Directs the processor when executing
other programs
Services Provided by the OS
 Facilities
 editors,
 Program
 loading
 Access
 deals
 System
for Program creation
compilers, linkers, and debuggers
execution
in memory, I/O and file initialization
to I/O and files
with the specifics of I/O and file formats
access
 Protection
of access to resources and data
 Resolves conflicts for resource contention
Services Provided by the OS

Error Detection
 internal
and external
hardware errors
memory error
 device failure

 software
errors
arithmetic overflow
 access forbidden
memory locations

 Inability
of OS to
grant request of
application
 Error
Response
 simply
report error to
the application
 Retry the operation
 Abort the application
Services Provided by the OS
 Accounting
 collect
statistics on resource usage
 monitor performance (eg: response time)
 used for system parameter tuning to
improve performance
 useful for anticipating future
enhancements
 used for billing users (on multiuser
systems)
Operating System as a
Resource Manager
Computer System
Memory
I/O Controller
Operating
System
Software
I/O Controller
.
.
.
Programs
and Data
I/O Controller
Processor
. ..
Processor
OS
Programs
Data
Ability to Evolve
 Must
be able to adapt to hardware
upgrades and new types of hardware.
Examples:
 Character
vs graphic terminals
 Introduction of paging hardware
 Must
be able to offer new services,
eg: internet support
Major Achievements
 Processes
 Memory
Management
 Information protection and security
 Scheduling and resource
management
 System structure
Memory Management
 Process
isolation
 Automatic allocation and management
 Support for modular programming
 Protection and access control
 Long-term storage
Virtual Memory
 Allows
programmers to address
memory from a logical point of view
 While program is running portions of
the program and data are kept in blocks
on disk
File System
 Implements
long-term store
 Information stored in named objects
called files
Categories of Security and Protection
 Access
control
 regulate
user access to the system
 Information
flow control
 regulate
flow of data within the system and
its delivery to users
 Certification
 proving
that access and flow control
perform according to specifications
Scheduling and
Resource Management
 Fairness
 give
equal and fair access to all processes
 Differential
responsiveness
 discriminate
between different classes of
jobs
 Efficiency
 maximize
throughput, minimize response
time, and accommodate as many uses as
possible
Characteristics of Modern
Operating Systems
 Microkernel
architecture
 assigns
only a few essential functions to
the kernel
 address
space
 interprocess communication (IPC)
 basic scheduling
Characteristics of Modern
Operating Systems
 Multithreading
 process
 is
divided into threads that can run
simultaneously
 Process is a collection of one or more threads
 Thread
 dispatchable
unit of work
 executes sequentially and is interruptable
Characteristics of Modern
Operating Systems
 Symmetric
 there
multiprocessing
are multiple processors
 these processors share the same main
memory and I/O facilities
 All processors can perform the same
functions
Characteristics of Modern
Operating Systems
 Distributed
 provides
operating systems
the illusion of a single main
memory
 used for distributed file system
Characteristics of Modern
Operating Systems
 Object-oriented
 used
design
for adding modular extensions to a
small kernel
 enables programmers to customize an
operating system without disrupting
system integrity