PPT - Course Website Directory

Download Report

Transcript PPT - Course Website Directory

CS 423 – Operating Systems Design
Lecture 2 – Concepts
Review
Klara Nahrstedt
Fall 2011
CS 423 - Fall 2011
Overview
Administrative Issues
 System Concepts Review (cs231, cs232,
cs241)
 Read Tanenbaum textbook

 Chapter
Sections: 1.4-1.6
CS 423 - Fall 2011
Administrative Issues

MPs
 Find
MP partner (s) and submit form from compass
about the groups today 8/24
 MP1 will be posted on Monday 8/29 (not graded, but
very strongly recommended)

Proficiency Exam
 Student
will do MP4 and final exam
 Student needs to get VMware server account and
should contact TAs to arrange for the environment
ahead of MP4 posting time

Review cs231/232/241 concepts
CS 423 - Fall 2011
Typical Computer System
Memory
CPU
..
.
Programs and data
Operating System Software
CPU
OS
Apps
Data
Network
CS 423 - Fall 2011
OS Major Components

Resource management
 CPU

Process and Thread Management
 Memory

Memory Management
 Device

I/O Management (Disk, Network, Camera,
Microphone, Timers, Power)
File system
 Bootstrapping

CS 423 - Fall 2011
Processors
Each CPU has a specific set of instructions
 All CPUs contain

 General
registers inside to hold key variables and
temporary results
 Special registers visible to the programmer
Program counter contains the memory address of the
next instruction to be fetched
 Stack pointer points to the top of the current stack in
memory
 PSW (Program Status Word) contains the condition
code bits which are set by comparison instructions, the
CPU priority, the mode (user or kernel) and various
other control bits.

CS 423 - Fall 2011
How Processors Work

Execute instructions
 CPU
cycles
Fetch (from mem)  decode  execute
 Program counter (PC)



When is PC changed?
Pipeline: fetch n+2 while decode n+1 while
execute n
 Two
modes of CPU (why?)
User mode (a subset of instructions)
 Privileged mode (all instruction)

 Trap
(special instruction)
CS 423 - Fall 2011
Processor (CPU) Management

Goals
 Time
sharing
 Multiple CPU allocations

Issues
 Do
not waste CPU resources
 Synchronization and mutual
exclusion
 Fairness
 Deadlock free
CS 423 - Fall 2011
Analogy: Video Games
Memory Access

Memory read:
 Assert
address on address lines
 Wait till data appear on data line
 Much slower than CPU!

How many memory access for one instruction?
 Fetch
instruction
 Fetch operand (0, 1 or 2)
 Write results (0 or 1)

How to speed up instruction execution?
CS 423 - Fall 2011
CPU Cache

Cache hit:
 no

need to access memory
Cache miss:
 data
obtained from memory, possibly update
cache
CS 423 - Fall 2011
Registers
< 1KB capacity
1 nsec access time
Cache
4 MB capacity
2 nsec access time
Magnetic Disk
200-1000 GB
10 msec access time
Magnetic Tape
400-800 GB
100 sec access time
Source: http://en.wikipedia.org/wiki/Computer_data_storage#Primary_storage
Main Memory
512-2048 MB
10 nsec access time
Memory Management





How to protect programs from each other?
How to handle relocation ?
Base register
Limit register
Check and Mapping of Addresses
 Virtual Address - Physical Address
 Memory Management Unit (MMU –
located on CPU
chip or close to it

Performance effects on memory system
 Cache
 Context
switch
CS 423 - Fall 2011
Memory Management

Goals
 Support
programs to run
 Allocation and management
 Transfers from and to
secondary storage

Issues
 Efficiency
& convenience
 Fairness
Register
L2 10x
Memory 200x
Disk 10Mx
Tape 100Mx
 Protection
CS 423 - Fall 2011
I/O Device Management

Goals
User 1
...
User n
 Interactions
between
devices and applications
 Ability to plug in new
devices

Issues
 Efficiency
 Fairness
 Protection
and sharing
CS 423 - Fall 2011
Library support
Driver
Driver
I/O
device
I/O
device
...
I/O Devices

Controller
 Example: Disk Controller
 Controllers are complex converting
OS request into
device parameters
 Controllers often contain small embedded computers

Device
 Fairly simple interfaces and standardized
 IDE (Integrated Drive Electronics) – standard
type on Pentiums and other computers
CS 423 - Fall 2011
disk
I/O Devices

Device Driver
 Needed
since each type of controller may be
different.
 Software that talks to a controller, giving it
comments and accepting responses
 Each controller manufacturer supplies a driver
for each OS it supports (e.g., drivers for
Windows 7, UNIX)
CS 423 - Fall 2011
Methods for I/O

How device driver talks to controller
 Busy
wait
 Interrupt
 DMA
CS 423 - Fall 2011
File System Example
File system for a university department
CS 423 - Fall 2011
File System

A typical file system
User 1
...
User n
 Open
a file with
authentication
 Read/write data in files
 Close a file

Can the services be
moved to user level?
CS 423 - Fall 2011
File system services
File
...
File
Bootstrapping






Power up a computer
Processor reset
 Set to known state
 Jump to ROM code
Load in the boot loader
from stable storage
Jump to the boot loader
Load the rest of the
operating system
Initialize and run
Boot
loader
CS 423 - Fall 2011
Boot
loader
OS
sector 1
OS
sector 2
.
.
.
OS
sector n
From Lecture 1: What is OS

Code that:
 Sits
between programs & hardware
 Sits between different programs
 Sits betweens different users


hardware resources
Allocation, protection, reclamation,
virtualization
 Provide
services to app. How? -- System
Call

OS
Hardware
Job of OS:
 Manage
Application
Abstraction, simplification, standardization
CS 423 - Fall 2011
A peek into Unix/Linux
Application
Libraries
User space/level
Kernel space/level
Portable OS Layer
Machine-dependent layer
• User/kernel modes are
supported by hardware
•Some systems do not have
clear user-kernel boundary
CS 423 - Fall 2011
Unix: Application
Application
(E.g., emacs)
Libraries
Portable OS Layer
Machine-dependent layer
CS 423 - Fall 2011
Written by programmer
Compiled by programmer
Uses function calls
Unix: Libraries
Application
Libraries (e.g., stdio.h)
Portable OS Layer
Machine-dependent layer
CS 423 - Fall 2011
Provided pre-compiled
Defined in headers
Input to linker (compiler)
Invoked like functions
May be “resolved” when
program is loaded
Typical Unix OS Structure
Application
Libraries
Portable OS Layer
Machine-dependent layer
CS 423 - Fall 2011
system calls (read, open..)
All “high-level” code
Typical Unix OS Structure
Application
Libraries
Portable OS Layer
Machine-dependent layer
CS 423 - Fall 2011
Bootstrap
System initialization
Interrupt and exception
I/O device driver
Memory management
Kernel/user mode
switching
Processor management
Steps in Making a System Call
Example:
read (fd,
buffer,nbytes)
CS 423 - Fall 2011
System Calls (POSIX)


System calls for process management
Example of fork used in simplified shell program
#define TRUE 1
while(TRUE) {
type_prompt();
read_command(command, parameters);
if (fork()!=0) {
/* some code*/
waitpid(-1,&status, 0);}
else {
/* some code*/
execve(command, parameters,0);
}}
CS 423 - Fall 2011
System Calls (POSIX)

System calls for file/directory management
 fd=open(file,how,….)
 n=wride(fd,buffer,nbytes)
 s=rmdir(name)

Miscellaneous
 s=kill(pid,signal)
 s=chmod(name,mode)
CS 423 - Fall 2011
System Calls (Windows Win32 API)

Process Management
 CreateProcess-
new process (combined work of fork
and execve in UNIX)

In Windows – no process hierarchy, event concept
implemented
 WaitForSingleObject
– wait for an event (can wait for
process to exit)

File Management
 CreateFile,
CloseHandle, CreateDirectory, …
 Windows does not have signals, links to files, …, but
has a large number of system calls for managing GUI
CS 423 - Fall 2011
OS Service Examples

Services that need to be provided at kernel level
 System
calls: file open, close, read and write
 Control the CPU so that users won’t stuck by running
while ( 1 ) ;
 Protection:



Keep user programs from crashing OS
Keep user programs from crashing each other
Services that can be provided at user level
 Read
time of the day
CS 423 - Fall 2011
You Live in Interesting Times…




Processors speed used to double in 18 months
(Moore’s Law), but we are reaching the upper
bound (due to thermal problems) and need to go
towards multi-core processors, i.e., parallelism to
increase the processing power
Disk doubling every 12 months
Global bandwidth every 6 month
What will the future OS be?
CS 423 - Fall 2011