Title: Operating Systems
1Operating Systems
2OS Overview
- What is an OS
- all the code that you didn't write
- the code that manages physical (hardware)
resources - provides users with "logical" well-behaved
environment - OS defines a set of logical resources and a set
of well-defined operations on those objects
(interfaces) - provides mechanisms and policies for the control
of objets/resources - policies define what should be done
- mechanism implements how
- controls how different users and programs
interact - Resources managed by an OS
- CPU
- memory
- disk
- networks
- keyboard, mouse
- various IO devices printers, speakers, cameras.
...
3OS Taxonomy
- Multiprogramming OS
- keeps multiple runnable programs loaded in the
memory - overlaps IO processing of a job with computing of
another - benefits from asynchronous IO devices
- needs mechanism of interrupts and DMA
- tries to optimizes throughput, not response time
- Timesharing
- each user feels as if she has the entire machine
- timesharing tries to optimize response time, not
throughput - needs mechanism of time-slicing of CPU
- timer clock
- scheduler
- users are permitted to control the execution of
process
4OS Taxonomy
- Real Time OS
- for real time applications
- usually, it means small OS with real time
scheduler - there are issues with OS itself
- real time file system?
- real time memory management?
-
- Embedded OS
- OS for small devices
- usually RTOS
- usually, no disk but flash memory
- issues
- memory requirement
- file system
- execution style
5Computer Architecture and OS
- OS and Architecture
- the functionality of an OS is limited by
architecture features - the structure of an OS can be simplified by
architectural support - DOS is so primitive due to the lack of hardware
support when it was first designed - Most proprietary OS's were developed with the
architecture - Architectural features for modern OS
- timer operation
- atomic synchronization operations
- memory protection
- IO control and operations
- interrupts and exceptions
- OS protection (kernel/user mode)
- protected instructions
- system calls
- partial completion of an instruction
6Architectural Support for OS
- Exceptions
- remember MIPS exceptions
- interrupt vector . etc.
- hardware must detect special conditions
- page fault, write to read-only page, overflow,
... - must transfer control to OS immediately
- hardware must save state of the running process,
so that the faulting process can be restarted
afterwards - what if there is no hardware support
- OS should keep checking the condition at a very
high cost
7Architectural Support for OS (2)
- Synchronization
- interrupts cause potential problem because an
interrupt can occur at any time
non-deterministic race condition - concurrent processes may interfere with each
other - needs an atomic operation at various level
- primitive one (test and set) by hardware
- software can do this at a high cost
- some by programming languages
- you will spend at least a month in cs330 for this
topic. why? - OS contains lots of concurrency in itself
- synchronization sometimes involves process
management - OS must provide synch mechanisms
8Kernel Mode
- Protected Instructions
- users should not be allowed direct accesses to
- IO devices such as disks, printers, ...
- use privileged instructions or memory mapping
- memory management states
- page table updates,
- page table pointers
- TLB loads, flush, ...
- setting special mode bits
- halt instruction (why do we need this?)
- OS Protection
- how do we know if we can execute a protected
instruction? - architecture must support at least two modes of
operations kernel and user - mode is indicated by a status bit in a protected
processor register - user program executes in user mode the OS
executes in kernel mode - protected instructions can only be executed in
kernel mode.
9Kernel Mode (2)
- Crossing Protection Boundaries
- users have to ask OS to do something privileged
in behalf of them - how does a user program call a kernel mode
service? - system call
- system call instructions should be available to
users - required features of a system call
- stop what is going on exceptions
- specifies the kind of service asked interrupt
vector - specifies the exact contents of the action
parameter passing - saves the status of what is going on so it can be
restored when the service is done - there must be a way to return to user mode
10User-Kernel Interaction
user program
user mode
system call
kernel mode
trap to kernel mode
trap handler
system service routine
OS kernel
11IO Control (from device to OS)
device interrupts
CPU stops current operation, switches to kernel
mode, and saves current PC and other states on
kernel stack
CPU fetches proper vector from vector table and
branches to that address (to interrupt handler)
interrupt routine examines device database
and performs actions required by the interrupt
handler completes operation, restores saved
(interrupted) state and returns to user mode (or
calls scheduler to switch to another program)
12Process Management
- Process Management
- a process
- execution entity
- includes an execution context
- an instance of a program in execution (program is
only a file on the disk that is potentially
runnable) - many processes exists
- user programs
- batch jobs
- print spooler, name server, network listener
- OS schedules these processes
code stack PC registers
page tables resource counts .......
13Process
- Process states
- running has the CPU
- ready ready to be executed
- blocked waiting for some event to occur
create( )
ready
timer interrupt
IO completion
scheduler
running
blocked
exit( )
IO request
14Process Scheduling
- Choose a process to assign the CPU
- Activated by
- timer interrupt
- running process system calls
- other OS routines urgent event
- Scheduling queues
- ready queue
- IO queue (blocked)
- sleep queue
- ....
15Context Switching
- Timer
- how does OS prevent infinite loops?
- a timer is set to generates an interrupt in a
given time - before a user process begins, OS loads the timer
with a time to interrupt (more primitive hardware
generates interrupts periodically independent of
OS) - when the time arrives, the timer issues an
interrupt, and thus the user program stops and OS
regains control
16Context Switching (2)
- Context Switching
- Switching the CPU to another process
- save the state of the old process
- load the saved state of the new process
- System overhead
- 1 - 100 microseconds
- various hardware supports are available
- interrupt mechanism
- scheduling algorithm
- saving/restoring process states
- cache misses
- TLB misses
- overall overhead depends on the time slice
17Threads
- multiple execution entities within the same
address space - execution stack for each thread
- threads share data and code
- sharing is easy
- switching threads is cheaper
- synch betwn threads is easy
- two kinds of thread
- kernel level thread
- OS manages threads
- user level thread
- threads are transparent to OS
- a user level package manages threads
18Memory Management
- Memory Management
- primary memory is the space that is directly
accessible from CPU - program should be in memory to execute
- OS must
- allocate space for programs to run
- deallocates space when needed
- mapping virtual to real address (when virtual
memory is used) - decides how much space to allocate to a process,
and when a process should be removed from memory
19Virtual Memory
- Virtual Memory
- user program may be lager than the available
physical memory - with multiprogramming, there are many programs
that run concurrently - needs larger memory than the real memory
- methods
- overlay
- a program itself manages portions of allocated
memory - very difficult to develop a program
- paging
20Paging
21Address Translation
CPU
virtual address
VPN
offset
22Page Table
- Each entry is addressed by the VPN and the
contents is the RPN - Size may be large
- 32 bit address, 512 bytes/page, byte addressing
- offset field 9 bits, page field 23 bits
- total 223 8 Mega entries per process
- 6 bytes per entry, 32 processes 1536 MB
- Address translation must be fast
- needed for every memory access
- TLB is indispensable
- keep page tables in memory
23Address Space and Virtual Memory
- VM implements the concept of address space
- address space for a single process may be much
larger than physical memory(DRAM) - there may be many processes at a single time
- the addresses used in a program are restricted
within the address space - VM enforces the restriction through address
translation - if you want to access a part of another process,
ask OS for it - you cannot access any part of another address
space
24Disk Management
- Disk Management
- disk is the persistent memory, i.e., it endures
system failures (we hope) - OS does
- scheduling of disk requests
- disk arm movement
- error handling
- the line between this and the file system is
fuzzy
25Hard Disk
26Hard Disk Data Sheet
- model Baracuda ATA II cheetah 73
- capacity 30GB 73GB
- plates 3 12
- heads 6 24
- RPM 7200 10025
- sector size 512B same
- sector/track 63 463
- track/in 21368 18145
- seek time
- read 8.2 ms 5.85ms
- write 9.5ms 6.35ms
- track to track(r) 1.2ms 0.6ms
- track to track(w) 1.9ms 0.9ms
27All You Have to Know about HD
- all the sectors are numbered from 0 to N
- basic unit that can be accesses by software
- sequential access is much faster than random
access - sectors are scattered randomly
- seek(8ms) search(4ms) transfer(0.13
ms/sector) - almost 12.3 ms/sector gt 41 KB/s
- sectors are scattered in same cylinder
- search(4ms) transfer(0.13ms)
- roughly 4.13 ms/sector gt 124 KB/s
- sectors are contiguous on the track
- no seek, no search
- transfer 0.25 ms/sector gt 2MB/s
28File System
- File System
- raw disk is too crude to be used by user programs
- (even for OS)
- the file system provides logical objects and
logical operations on those objects - a file is the basic long-term storage entity a
file is a named collection of persistent
information that can be read or written - needs a way to locate information about a file
efficiently (humans forget too easily)
directories - a directory may be itself a file
- file system provides standard file operations
- the file system also provides general services,
e.g. - backup
- maintaining mapping information
- accounting and quotas
29Other Components of OS
- Protection System
- when many processes may run concurrently, all
resource objects need protection - memory
- processes
- files
- devices
- protection mechanism helps to detect errors as
well as to prevent malicious destruction - Command Interpreter
- interprets user command issued from a keyboard
- some systems have it as a standard part of OS
- other systems it is just a user program
(replaceable) - others do not have such thing they have iconic
interface - Accounting System
- keep track of resource usage
- used for enforce quotas, or to generate bills
30OS Architecture
- OS Structure
- So far, you have seen components of an OS
- the issues are
- how to organize all of them
- what are the entities and where are they
- how do these entities cooperate
- in reality,
- interaction between these components is very
complex - boundaries between them are very fuzzy
- but, we have to build an OS that is
- working
- efficient (performance)
- reliable
- extensible
31OS Architecture (contd)
- Traditional Structure
- everything in one process(program) monolithic
kernel - why monolithic?
- that's the way we have programmed so far
- fast interaction between components (procedure
call) - easy sharing no protection between OS components
- why not monolithic?
- hard to understand
- hard to modify
- unreliable a bug in anywhere causes an entire
system crash - hard to maintain
32OS Architecture (contd)
- Layered Structure
- it has been used in structuring many complex
systems - a layer is a virtual machine to the layer above
it - a layer should not be aware of a layer above it
- THE (Dijkstra)
- why layering?
- easy to focus on a small task
- easy to build a large system step by step
- why not layering?
- real systems are more complex than a simple
hierarchy - not flexible
- poor performance due to layer crossing
- In real world, systems are often modeled as
layered structures but not built that way
33OS Architecture
- Microkernel architecture
- a structure in vogue
- minimize that goes in the kernel
- implement the remaining things of OS as
user-level processes - what for?
- better reliability (focus on small part)
- ease of extension and customization
- any problem? poor performance
- interaction between OS components is not
procedure call anymore, it is inter-process
communication - Examples
- Hydra (CMU, 1970)
- MINIX (Tannenbaum)
- CMU March IBM Workplace, OSF/1. ...
- Chorus
- Microsoft Windows/NT (in a way)
34Windows/NT Structure