Oslecture1 2
Oslecture1 2
Operating Systems
Lecture 1-2 - Introduction and overview, operating system structure
Ardalan Amiri Sani ([email protected])
[lecture slides contains some content adapted from : Silberschatz textbook authors, Anerson textbook
authors, John Kubiatowicz (Berkeley), John Ousterhout(Stanford), previous slides by Prof. Nalini
Venkatasubramanian, http://www-inst.eecs.berkeley.edu/~cs162/ and others]
Staff
The course will be co-taught by
Nalini Venkatasubramanian ([email protected])
Ardalan Amiri Sani ([email protected])
Staff
Teaching Assistants:
Kyle Benson ( [email protected] )
Joseph Nash ( [email protected] )
Qiuxi Zhu ( [email protected] )
Readers:
Hao Zhang ( [email protected] )
Purvi Kaul ( [email protected] )
Alternate Books
Operating Systems: Principles and Practice, by T. Anderson and M. Dahlin (second
edition)
Modern Operating Systems, by Tanenbaum (Third edition)
Principles of Operating Systems, by L.F. Bic and A.C. Shaw, 2003.
Tests
Midterm tentatively Thursday, Week 6 in class
Final Exam per UCI course catalog
Grading Policy
Homeworks - 30%
4 written homeworks each worth 5% of the final grade.
1 programming assignment worth 10% of the final grade
Lecture Schedule
Week 1: Prof. Amiri Sani
Introduction to Operating Systems, Computer System Structures,
Operating System Structures
Course Schedule
Week 6 Prof. Venkat
Deadlocks, Midterm review and exam
Office hours
Instructors
Mondays 3-4:30pm
Weeks 2-6 at Prof. Venkats office (DBH 2086)
Weeks 7-10 at Prof. Amiri Sanis office (DBH 3062)
TAs
TBD
10
Piazza
https://piazza.com/uci/spring2016/compsci143a
Post questions here.
11
Overview
What is an operating system?
Operating systems history
Computer system and operating system structure
12
13
14
Operating System
Controls and coordinates the use of hardware among application programs.
Application Programs
Solve computing problems of users (compilers, database systems, video
games, business programs such as banking software).
Users
People, machines, other computers
15
compiler
User
2
User
3
assembler
Text editor
...
User
n
Database
system
Application Programs
Operating System
Computer
Hardware
16
17
18
19
Illusionist
Files can grow (nearly) arbitrarily large
Files persist even when the machine crashes in the middle of a
save
Glue
Named directories, printf,
20
OS challenges
21
OS challenges
Reliability
Does the system do what it was designed to do?
22
OS challenges
Availability
What portion of the time is the system working?
Mean Time To Failure (MTTF), Mean Time to Repair
23
OS challenges
Security
Can the system be compromised by an attacker?
24
OS challenges
Privacy
Data is accessible only to authorized users
25
OS challenges
Performance
Latency/response time
How long does an operation take to complete?
Throughput
How many operations can be done per unit of time?
Overhead
How much extra work is done by the OS?
Fairness
How equal is the performance received by different users?
Predictability
How consistent is the performance over time?
26
OS challenges
Portability
For programs:
Application programming interface (API)
For the kernel
Hardware abstraction layer
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
I/O sharing
42
43
44
Application layer
Application
Application
Daemons, Libraries
Daemons, Libraries
User space
Kernel
Device driver
I/O device
Client
User space
Kernel
Device driver
IP Webcam
Wi-Fi Speaker
MightyText
I/O device
Server
45
46
Ardalan Amiri Sani, Kevin Boos, Min Hong Yun, and Lin Zhong, "Rio: A System Solution for Sharing I/O between Mobile
Systems," in Proc. ACM MobiSys, June 2014. (Best Paper Award)
47
48
User space
Kernel
Device file
/dev/foo
Device driver
I/O device
49
User space
User space
Kernel
Kernel
Device file
/dev/foo
Device driver
I/O device
Client
Server
50
User space
User space
Kernel
Kernel
Device file
/dev/foo
/dev/foo
Device driver
I/O device
Client
Server
51
User space
Wireless
Link
Kernel
User space
Stub
Kernel
Stub
Device file
/dev/foo
Device driver
I/O device
Client
Server
52
53
54
55
56
57
Overview
What is an operating system?
Operating systems history
Computer system and operating system structure
58
59
60
Early software
Assemblers, compilers, linkers, loaders,
device drivers, libraries of common subroutines.
Secure execution
Inefficient use of expensive resources
Low CPU utilization, high setup time.
61
Resident Monitor
Holds initial control, control transfers to job
and then back to monitor.
Problem
Need to distinguish job from job and data from program.
Special cards indicate what to do.
User program prevented from performing I/O
62
Problems
Long turnaround time - up to 2 DAYS!!!
Low CPU utilization
I/O and CPU could not overlap; slow mechanical devices.
63
64
CPU
I/O instructions
I/O devices
65
Interrupts:
On completion of I/O, device forces CPU to jump to a specific
instruction address that contains the interrupt service routine.
After the interrupt has been processed, CPU returns to code it was
executing prior to servicing the interrupt.
66
Multiprogramming
Use interrupts to run multiple programs simultaneously
When a program performs I/O, instead of polling, execute another
program till interrupt is received.
67
Timesharing
Hardware getting cheaper; Human getting expensive
Programs queued for execution in FIFO order.
Like multiprogramming, but timer device interrupts after
a quantum (timeslice).
Interrupted program is returned to end of FIFO
Next program is taken from head of FIFO
68
Timesharing (cont.)
Interactive (action/response)
when OS finishes execution of one command, it seeks the next
control statement from user.
File systems
online filesystem is required for users to access data and code.
Virtual memory
Job is swapped in and out of memory to disk.
69
70
71
Overview
What is an operating system?
Operating systems history
Computer system and operating system structure
72
74
CPU execution
Addr 232-1
R0
R31
F0
F30
PC
Fetch
Exec
Execution sequence:
Fetch Instruction at PC
Decode
Execute (possibly using registers)
Write results to registers/mem
PC = Next Instruction(PC)
Repeat
Data1
Data0
Inst237
Inst236
Inst5
Inst4
Inst3
Inst2
Inst1
Inst0
PC
PC
PC
PC
Addr 0
From Berkeley OS course
75
76
I/O devices
I/O devices and the CPU execute concurrently.
Each device controller is in charge of a particular
device type
Each device controller has a local buffer. I/O is from the
device to local buffer of controller
77
Interrupts
Interrupt transfers control to the interrupt service routine
Interrupt Service Routine: Segments of code that determine action
to be taken for interrupt.
78
Interrupt handling
OS preserves the state of the CPU
stores registers and the program counter (address of interrupted
instruction).
79
Asynchronous I/O
After I/O is requested, control returns to user program
without waiting for I/O completion.Device Status table - holds
type, address and state for each device
OS indexes into I/O device table to determine device status and
modify table entry to include interrupt.
80
Memory
CPU
I/O instructions
I/O devices
81
Process Abstraction
82
Process Abstraction
Process: an instance of a program, running
with limited rights
83
Process Abstraction
Process: an instance of a program, running
with limited rights
Thread: a sequence of instructions within a
process
Potentially many threads per process (for now 1:1)
84
85
Hardware Protection
Dual Mode Operation
Memory Protection
CPU Protection
I/O Protection
86
87
How to prevent?
88
Dual-mode operation
Provide hardware support to differentiate between at
least two modes of operation:
1. User mode -- execution done on behalf of a user.
2. Kernel mode (monitor/supervisor/system mode) -execution done on behalf of operating system.
89
Dual-mode operation(cont.)
Mode bit added to computer
hardware to indicate the current
mode: kernel(0) or user(1).
When an interrupt or trap
occurs, hardware switches to
kernel mode.
User
Interrupt/
fault
Set
user
mode
Kernel
90
91
92
Virtual Address
93
Code
Data
Heap
Stack
Data 2
Code
Data
Heap
Stack
Stack 1
Heap 1
Code 1
Stack 2
Prog 1
Virtual
Address
Space 1
Prog 2
Virtual
Address
Space 2
Data 1
Heap 2
Code 2
kernel code
Translation Map 1
kernel data
kernel heap &
Stacks
Translation Map 2
Load new Translation Map on Switch
94
Virtual
address
Translation Invalid
Raise
Exception
Valid
Data
Physical
address
Physical
Memory
Data
95
Memory Protection
Must provide memory protection at least for the interrupt
vector and the interrupt service routines.
When a process is running, only memory in that process
address space must be accessible.
When executing in kernel mode, the kernel has
unrestricted access to all memory.
96
300040
420940
Base register
300040
120900
Limit register
1024000
97
CPU Protection
99
CPU Protection
Timer - interrupts computer after specified period to
ensure that OS maintains control.
Timer is decremented every clock tick.
When timer reaches a value of 0, an interrupt occurs.
100
I/O Protection
All I/O instructions are privileged instructions.
Must ensure that a user program could never gain
control of the computer in kernel mode, for e.g. a
user program that as part of its execution, stores a
new address in the interrupt vector.
101
Question
Given the I/O instructions are privileged, how do
users perform I/O?
102
Question
Given the I/O instructions are privileged, how do
users perform I/O?
Via system calls - the method used by a process to
request action by the operating system.
103
System Calls
User code can issue a syscall, which causes a trap
Kernel handles the syscall
104
System Calls
Interface between running
program and the OS.
Assembly language instructions
(macros and subroutines)
Some higher level languages
allow system calls to be made
directly (e.g. C)
105
106
107
108
System Generation
OS written for a class of machines, must be
configured for each specific site.
SYSGEN is the process to customize OS for the
exact hardware
Source code can be customized
Pre-compiled modules selected and linked based on hardware
All code is compiled, but right code is chosen at execution time,
e.g., by using a table
109
System Boot
110
Storage Structure
Main memory - only large storage media that the
CPU can access directly.
Secondary storage - extension of main memory
that has large nonvolatile storage capacity.
Magnetic disks - rigid metal or glass platters covered with
magnetic recording material.
Disk surface is logically divided into tracks, subdivided into
sectors.
Disk controller determines logical interaction between device
and computer.
111
Storage Hierarchy
Storage systems are organized in a hierarchy
based on
Speed
Cost
Volatility
112
113
Layered
Lower levels independent of upper levels
Modular
Core kernel with Dynamically loadable modules
Microkernel
OS built from many user-level processes
114
115
116
Layered OS Structure
118
Modules-based Structure
Most modern operating systems implement modules
Each core component is separate
Each talks to the others over known interfaces
Each is loadable as needed within the kernel
119
Detriments:
Performance overhead severe for nave implementation
120
A microkernel OS
121
122
123
124
125
126
OS Task: Networking
Connecting processors in a distributed system
Distributed System is a collection of processors
that do not share memory or a clock.
Processors are connected via a communication
network.
Advantages:
Allows users and system to exchange information
provide computational speedup
increased reliability and availability of information
127
Virtual Machines
Physical Machine
Application
OS
Hardware
128
Virtual Machines
Virtual Machine 1
Virtual Machine 2
Virtual Machine 3
Application
Application
Application
OS
OS
OS
Hardware
129
Virtual Machines
Use cases
Resource configuration
Running multiple OSes, either the same or different
OSes
Run existing OS binaries on different architecture
130
131