Introduction to Operating SystemsLecture 1: Operating system overview
MING GAO
SE@ecnu(for course related communications)
Mar. 2, 2015
Outline
1 What is an Operating Systems?
2 Co-evolution of computer systems and operating systemsCS overviewOS historyOS structures
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 2 / 56
what
What’s an OS?
A conceptual framework of a computer system
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 3 / 56
what
Two point-of-views
Machine interface: resource manager
How do programs run on CPUs simultaneously?
Whatif the memory is used off?
How is a file stored and accessed?
Whatif two uses send printing job to the same printer at the sametime?
...
Human (programmer) interface: virtual machine
cont’d in the next slide
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 4 / 56
what
Two point-of-views
Machine interface: resource manager
Human (programmer) interface: virtual machine
You (a process) have all CPU time and memory
You are the single owner of all devices
Different devices have same interfaces
Device interfaces are more powerful than raw hardware
...
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 5 / 56
what
Definitions of OS
“An OS is similar to the government”
“Everything a vendor ships when you order an operating system”
“An operating system implements a virtual machine that is (hopefully)easier and safer to program and use than the raw hardware”
“The one program running at all times on the computer” is thekernel.
Everything else is either a system program (ships with the operatingsystem) or an application program
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 7 / 56
what
Why do SEI students study OS?
As a programmer
You should know:
What does it meanSegmentation faulthere?
Why does it happen?
How to solve it?
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 8 / 56
what
Why do SEI students study OS?
As a programmer
And:
Why there is noSegmentation faultnow?
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 9 / 56
what
Why do SEI students study OS?
As a programmer/QA
How many methods are there to allocate memory/storage?
What are their differences?
Which one is appropriate when you need 1KB, 100KB, 1MB, 100MB,or 1GB storage in a machine with 128MB, 512MB, 1GB, or 4GBmain memory? Why?
This is only a tiny technical issue in coding, and maybe you know theanswer intuitively.
But you need to know OS well to make sure that all your decisionsare reasonable.
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 10 / 56
what
Why do SEI students study OS?
As a software designer
Given a computer, to determine appropriate functions that can runsmoothly
To design the process/thread structure, memory usage, fileorganization, etc.
Many issues related to performance, availability, robustness etc shouldbe considered based on deep understanding to OS
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 11 / 56
what
Why do SEI students study OS?
As a system administrator
Hundreds or even thousands of parameters to be setup or tuned
What do “circular logging” mean?
What to do when a system runs overloaded? (graceful degradation)
Buy new hardware?Tune parameters?Limit users’ activities?
It’s not that simple! An inappropriate action may overload the systemfurther.
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 12 / 56
what
Why do SEI students study OS?
As a manager (tech.-related)
You need solid knowledge and be rational before decision making
You need to be a qualified user and technical worker before being agood manager
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 13 / 56
CS-OS co-evolution CS overview
An overview of OS
Before that, we need to look close at the computer system.
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 14 / 56
CS-OS co-evolution CS overview
An overview of a computer system
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 15 / 56
CS-OS co-evolution CS overview
CS overview: Issues
CPU(s) and I/O devices may execute simultaneously
CPU is expensive
There may be conflicts in memory access and bus
There is speed mismatch
Device start-up or warm-up is usually slow
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 16 / 56
CS-OS co-evolution CS overview
CPU: A simplified, ideal architecture
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 17 / 56
CS-OS co-evolution CS overview
CPU issues
One or some CPUs, many programs running simultaneously
Browser (with several windows), MSN/QQ, MS Word, MS OutlookExpress,
Anti Virus, Printer Manager, ... There are conflicts and needcoordination!
When you are writing a program (so you are a programmer now), youdon’t know what other programs will be running with yours
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 18 / 56
CS-OS co-evolution CS overview
I/O
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 19 / 56
CS-OS co-evolution CS overview
I/O issues
CPU-I/O, memory-I/O speed mismatch
Various devices: you need a/limited unified interfaces
Mode: character/block, sync/async, buffering...SpeedController/driver details
Limited capabilities: you need some more advanced interfaces
Try to write a program that uses serial port to communicate
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 20 / 56
CS-OS co-evolution CS overview
Storage hierarchy
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 21 / 56
CS-OS co-evolution CS overview
Storage issues
Size mismatch
You cannot put all things in to main memory
Even your program (and its data) can, the sum of all programs can’t!
Speed mismatch
You should try to put your data (including programs) as close to theCPU as you can (as high as possible)
Allocation, addressing, and organization
Who will do this for you?
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 22 / 56
CS-OS co-evolution OS history
Moore’s Law
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 23 / 56
CS-OS co-evolution OS history
My own experience
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 24 / 56
CS-OS co-evolution OS history
CS-OS co-evolution
1948 - 1970 hardware expensive, human cheap
1970 - 1985 hardware cheaper, human expensive
1985 - hardware very cheap, human very expensive
1989 - distributed systems
1995 - mobile systems
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 25 / 56
CS-OS co-evolution OS history
1948 - 1970:Hardware expensive (M$), human cheap
Aim: Optimize for more efficient use of the hardware
OS Batch monitor
Load program, run, printNo protection
Users Wait when the program is running
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 26 / 56
CS-OS co-evolution OS history
Interrupts
Obervations
The behavior of programs: “compute, I/O, compute, ...”
CPU is much faster than I/O
Must CPU wait when I/O is processing?
CPU time is expensive!
Ideas
I/O can be completed asynchronously
Trap: Software-generated interrupt caused either by an error or a userrequest.
An OS is interrupt-driven
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 27 / 56
CS-OS co-evolution OS history
Interrupts
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 28 / 56
CS-OS co-evolution OS history
Interrupts
Interrupt handling
Interrupt transfers control to the interrupt service routine, throughthe interrupt vector, which contains the addresses of all the serviceroutines.
Interrupt architecture must save the address of the interruptedinstruction.
The OS preserves the state of the CPU by storing registers and theprogram counter.
Incoming interrupts are disabled while another interrupt is beingprocessed to prevent a lost interrupt.
Interrupts may be nested (based on priorities)
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 29 / 56
CS-OS co-evolution OS history
Multi-programming
Observations
The behaviors of programs: “compute, I/O, compute, ...”
When one program is waiting I/O, should other ones wait too?
CPU time is expensive!
How?
Idea Several programs run simultaneously
Issue Need memory protection between programs and/or OS
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 30 / 56
CS-OS co-evolution OS history
Complexity of OS
Multics: announced in 1963, ran in 1969
1777 people “contributed to Multics” (30-40 core dev)
Turing award lecture from Fernando Corbato (key researcher): “Onbuilding systems that will fail”
OS 360: released with 1000 known bugs (APARs)
“Anomalous Program Activity Report”
OS finally becomes an important science
How to deal with complexity?
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 31 / 56
CS-OS co-evolution OS history
1970 - 1985:HW cheaper (104$), human expensive
Observations
Users need to debug, edit, and use email online, simultaneouslyResponse time is important for user experience
Idea Time-sharing
Use cheap terminals (K$) to let multiple users interactwith the system at the same timeSacrifice CPU time to get better response time
Issue Thrashing
Performance varies non-linearly w.r.t. loadCaused by many factors including swapping andqueueing
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 32 / 56
CS-OS co-evolution OS history
1985 - :HW very cheap (K$), human very expensive
Observations
Requirements and possibilities of personal computing
Limited hardware resource initially
PCs become powerful eventually (Moore’s Law)
Ideas
OS as a subroutine library (DOS, CP/M) for limited HW
Less protection for PC?
OS regains all the complexity of a big OS
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 33 / 56
CS-OS co-evolution OS history
1989 - : Distributed systems
Observations
Networking (Local Area Networking, LAN)
Ideas: Distributed OS vs. Network OS
Resource (computing, file storage, devices, services) sharing
Client-Server (C/S) model
Web Server, file server, printer server, database server, . . .
Peer-to-Peer (P2P) computing
Web-based computing
Considering Google Apps. (Gmail, Gtalk, G-Office suite, G-notebook,G-pages, G-reader, G-calendar, G-groups, ...) that emulates afull-featured desktop
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 34 / 56
CS-OS co-evolution OS history
1995 - : Mobile systems
Observations
Ubiquitous mobile devices with limited capabilities: Laptops, PDAs, mobilephones, . . .Wireless/Wide-area networking
Ideas
Resource (computing, file storage, devices, services) sharing
Handheld systems and OS
P2P computing
Web-based computing
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 35 / 56
CS-OS co-evolution OS history
More on CS/OS co-evolution
Real-time embedded systems : Real-time OS, Embedded OS
Multimedia systems
Multiprocessor systems :
For high throughput, scalability and reliabilityMulti-core CPUsParallel computing
Clustered systems :
For high availabilityGoogle File System/Map-Reduce
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 36 / 56
CS-OS co-evolution OS structures
OS components
Process management
Main memory management
I/O system management
File management
Networking
User interfaces
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 37 / 56
CS-OS co-evolution OS structures
OS services
Helpful to users
User interfaces
Program execution
I/O operations
File-system manipulation
Communications
Error detection
Helpful to the system itself
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 38 / 56
CS-OS co-evolution OS structures
OS services
Helpful to users
Helpful to the system itself
Error detection & recovery
Resource allocation
Accounting
Protection and security
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 39 / 56
CS-OS co-evolution OS structures
User/OS interfaces
CLI (Command Line Interface)
Sometimes in kernel, sometimes provided by system program (shells)
For built-in features (in kernel) or external programs
GUI (Graphical User Interface)
User-friendly desktop metaphor interface
With help of mouse, keyboard, and monitor
Invented at Xerox PARC
System calls
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 40 / 56
CS-OS co-evolution OS structures
System calls
Programming interface to the services provided by the OS
Typically written in a high-level language (C or C++)
Mostly accessed by programs via a high-level Application ProgramInterface (API) rather than direct system call use
Typically, a number associated with each system call
System-call interface maintains a table indexed according to thesenumbersWith parameter-passing (via register, block/table, or stack)
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 41 / 56
CS-OS co-evolution OS structures
System calls
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 42 / 56
CS-OS co-evolution OS structures
Dual-mode operation
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 43 / 56
CS-OS co-evolution OS structures
OS structures
Simple Only one or two levels of code
Layered Lower levels independent of upper levels
Microkernel OS built from many user-level processes
Modular Core kernel with dynamically loadable modules
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 44 / 56
CS-OS co-evolution OS structures
MS DOS: Simple structure
MS DOS
Written to provide the most function-ality in the least space
Not divided into modules
Interfaces and levels offunctionality not well separated
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 45 / 56
CS-OS co-evolution OS structures
UNIX: Also simple structure
UNIX - limited by hardware functionality
Original UNIX operating system consists of two separable parts:
Systems programs
The kernel :
Consists of everything below the system-call interfaceand above the physical hardware;Provides the file system, CPU scheduling, memorymanagement, and other operating-system functions;Many interacting functions for one level
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 46 / 56
CS-OS co-evolution OS structures
Layered structure
The operating system is divided into a number of layers (levels),
Each built on top of lower layers.
The bottom layer (layer 0), is the hardware;
The highest (layer N) is the user interface.
With modularity, layers are selected such that each uses functions(operations) and services of only lower-level layers
Not always possible
There are machine dependant layers and independent layers
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 47 / 56
CS-OS co-evolution OS structures
Layered structure
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 48 / 56
CS-OS co-evolution OS structures
Micro-kernel structure
Ideas
Moves as much from thekernel into “user” space
Small core OS running atkernel level
OS services built frommany independentuser-level processes
Communication betweenmodules with message passing
Benefits
1 Easier to extend amicro-kernel
2 Easier to port OS to newarchitectures
3 More reliable (less code isrunning in kernel mode)
4 Fault Isolation (parts ofkernel protected from otherparts)
5 More secure
Detriments
Performance overhead severe for naive implementation
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 49 / 56
CS-OS co-evolution OS structures
Module-based structure
Most modern operating systems implement kernel modules
Uses object-oriented approach
Each core component is separate
Each talks to the others over known interfaces
Each is loadable as needed within the kernel
Overall, similar to layers but with more flexible
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 50 / 56
CS-OS co-evolution OS structures
Virtual machines
What? It takes the layered approach to its logical conclusion. Ittreats hardware and the operating system kernel as thoughthey were all hardware
How? The OS creates the illusion of multiple processes, eachexecuting on its own processor with its own (virtual) memory
Why? Benefits:
Programming simplicityFault isolationProtection and portability
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 51 / 56
CS-OS co-evolution OS structures
Virtual machines
VMWare
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 52 / 56
CS-OS co-evolution OS structures
OS implementation issues
Policy vs. Mechanism: Should be separated, since both change
Policy: What do you want to do?Mechanism: How are you going to do it?
Algorithms used
Linear, Tree-based, Log Structured, etc . . .
Event models used
threads vs. event loops
Backward compatibility issues
System generation/configuration
How to make generic OS fit on specific hardware
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 53 / 56
Take-home msg.
Terms and their Chinese translations
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 54 / 56
Take-home msg.
Take-aways
Two point-of-views
CS-OS co-evolutionOS design: Application-driven
Dual-mode operation
Some important concepts
Everything exist with a reason!
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 55 / 56
Take-home msg.
Acknowledgement
Many slides are copied or adapted from:
Slides provided by authors of the textbook(http://codex.cs.yale.edu/avi/os-book/os7/)
Prof. Anthony D. Joseph’s slides for course CS162 (2006) atEECS@UCBerkeley (http://inst.eecs.berkeley.edu/~cs162)(Copyright @ 2008 UCB)
MING GAO (SE@ecnu) Introduction to Operating Systems Mar. 2, 2015 56 / 56