You are on page 1of 69

Operating Systems

(Honor Track)

What is an Operating System?

Xin Jin
Spring 2024

Acknowledgments: Ion Stoica, Berkeley CS 162


Course Staff
• Instructor: Xin Jin
ØResearch interests: Computer systems and networking
» Serverless computing
» Training and serving large language models
» Network testing and verification
» Disaggregated storage with RDMA and DPUs

• Teaching assistants

Chao Jin Yingbo Sun Zili Zhang Yinmin Zhong


2
Infrastructure & Recommended Readings

• Infrastructure
Ø Website: https://pku-os.github.io/sp24
Ø Piazza: https://piazza.com/pku.edu.cn/spring2024/04834490
Ø Course feedback: https://www.wjx.cn/vm/PZaRCka.aspx
Ø Office hour: Friday 4-5pm, Yanyuan Building 811, or by appointment

• Recommended textbook: Operating Systems: Three Easy Pieces,


by Remzi and Andrea Arpaci-Dusseau
Ø Available for free online (https://pages.cs.wisc.edu/~remzi/OSTEP)
Ø Try to keep up with materials in book as well as lectures

• Supplementary Materials
Ø Operating Systems: Principles and Practice, 2nd Edition, by Anderson and Dahlin
Ø Linux Kernel Development, 3rd edition, by Robert Love

3
Preparing Yourself for this Class
• The assignments will require you to be very comfortable with programming and
debugging C
ØPointers (including function pointers, void*)
ØMemory Management (malloc, free, stack vs heap)
ØDebugging with GDB

• You will be working on a larger, more sophisticated code base than anything you've
likely seen in other courses!

• Others
ØC tutorial (https://cs162.org/ladder/)
ØMarkdown tutorial (https://www.markdowntutorial.com/zh-cn/)

4
Goals

• Prepare students for advanced study and research in computer systems, by


providing the necessary foundation and context.

• Enable students to understand the internal core logic of the operating system in
depth and have a chance to design and implement their own operating systems.

• Empower students to write and debug large programs, design and implement
useful abstractions and especially practice their ability to write and debug multi-
threading programs.

5
Class Workload
• Lectures
ØCore concepts and principles of operating systems, which form the foundation of
computer systems in general (based on Berkeley CS 162)
ØRecent developments and frontiers in computer systems (new in this course)
» Big data systems: Google’s three papers (GFS, MapReduce, Bigtable), Hadoop, Spark, etc.
» Machine learning systems: TensorFlow, PyTorch, Ray, LLM training and serving, etc.
» Cloud computing: resource disaggregation, serverless computing, etc.
» We will read and discuss interesting research papers in computer systems
ØGuest lectures from both academia and industry
• Programming assignments: VERY CHALLENGING
ØDesign and implement your own operating systems
ØPintos from Stanford (used by OS courses at Stanford, Berkeley, CMU, etc.)
ØNew this year: a new instructional OS based on Rust and RISC-V 😀
• Two exams
ØMidterm, final
6
Syllabus
• OS Concepts: How to Navigate as a Systems Programmer
ØProcess, I/O, networks
• Concurrency
ØThreads, scheduling, locks, deadlock, scalability, fairness
• Address Space
ØVirtual memory, address translation, protection, sharing
• File Systems
ØI/O devices, file objects, storage, naming, caching, performance, paging,
transactions, databases
• Distributed Systems
ØProtocols, RPC, NFS, DHTs, Consistency, Scalability
• Reliability & Security
ØFault tolerance, protection, security
• Cloud Infrastructure

7
Grading
• Participation: 5%
• Programming assignments (5 labs): 30%
Ø5 labs: 4% + 6.5% + 6.5% + 6.5% + 6.5%
ØDesign (design doc) + Implementation (code)
ØDifference from Berkeley CS 162
» Done individually
» We reorganize the labs
» We provide TA sessions that give you enough tips to help you go through the
assignments
» We do not have other programming assignments in addition to the 5 labs (there
are 7 extra programming assignments in Berkeley CS 162)
• Midterm exam: 25%
• Final exam: 40%

8
Collaboration Policy
Explaining a concept to other students
Discussing algorithms/testing strategies with other students
Searching online for generic algorithms (e.g., hash table)

Sharing code or test cases with other students


Copying OR reading another student’s code or test cases
Copying OR reading online code or test cases
Uploading your solutions online (during AND after the course)

We compare all homework submissions against each other and


online solutions and will take actions against offenders

9
Feedback
• Feedback survey: https://www.wjx.cn/vm/PZaRCka.aspx
ØFeel free to send us your feedback about the course.
ØIt is available throughput the semester.
ØIt is anonymous. A private channel to talk to me.
ØYour suggestions, comments, concerns and questions are very valuable.
ØWe will summarize the feedback and make changes to the course.
» Let’s make the course better together.

10
Lecture Goal

Interactive!!!

11
Goals for Today
• What is an Operating System?
ØAnd – what is it not?
• What makes Operating Systems so exciting?

Interactive is important!
Ask Questions!

Slides courtesy of David Culler, Anthony D. Joseph, John Kubiatowicz, AJ Shankar, George
Necula, Alex Aiken, Eric Brewer, Ras Bodik, Ion Stoica, Doug Tygar, and David Wagner.
12
What is an operating system?
• Special layer of software that provides application software access
to hardware resources
ØConvenient abstraction of complex hardware devices
ØProtected access to shared resources
ØSecurity and authentication
ØCommunication amongst logical entities

appl n
appln
appln
OS

Hardware

13
What Does an OS do?
• Provide abstractions to apps
ØFile systems
ØProcesses, threads
ØVM, containers
ØNaming system
Ø…
• Manage resources:
ØMemory, CPU, storage, …
• Achieves the above by implementing specific algorithms and techniques:
ØScheduling
ØConcurrency
ØTransactions
ØSecurity
Ø…
14
Hardware/Software Interface
Running
Software Program
What you learned in
Instruction Set Architecture (ISA) Introduction to
Hardware Memory
Page Computer Systems (ICS)
Table
& TLB Cache
Processor

OS Memory

Ctrlr Networks The OS abstracts these


hardware details from the
Storage
application
Displays
Inputs

15
What is an Operating System?

• Illusionist
ØProvide clean, easy-to-use abstractions of physical resources
» Infinite memory, dedicated machine
» Higher level objects: files, users, messages
» Masking limitations, virtualization

16
OS Basics: Virtualizing the Machine

Compiled
Program

System Libs

Process: Execution environment with restricted rights provided by OS


Threads Address Spaces Files Sockets

Operating System
ISA
PgTbl Networks
Processor Memory
& TLB Storage
Hardware OS
Mem

I/O Ctrlr

17
Compiled Program’s View of the World

Compiled
Program

System Libs

Process: Execution environment with restricted rights provided by OS


Threads Address Spaces Files Sockets

Operating System
ISA • Application’s “machine” is the process abstraction provided by the OS
Networks
• Processor
Each running program
PgTbl runs in its own process
Memory
& TLB Storage
Hardware • Processes provide nicer interfaces than
OS
raw hardware
Mem

I/O Ctrlr

18
System Programmer’s View of the World

Program
Linker
System Libs

Process: Execution environment with restricted rights provided by OS


Compiler Threads Address Spaces Files Sockets

Operating System
ISA • Application’s “machine” is the process abstraction provided by the OS
Networks
• Processor
Each running program
PgTbl runs in its own process
Memory
& TLB Storage
Hardware • Processes provide nicer interfaces than
OS
raw hardware
Mem

I/O Ctrlr

19
What’s in a Process?
A process consists of:
• Address Space
• One or more threads of control executing in that address space
• Additional system state associated with it
ØOpen files
ØOpen sockets (network connections)
Ø…

20
For Example…

21
Operating System’s View of the World

Compiled Compiled
Program 1 Program 2

System Libs System Libs

Process 1 Process 2
Compiler Threads Address Spaces Files Sockets Threads Address Spaces Files Sockets

Operating System
ISA
PgTbl Networks
Processor Memory
& TLB Storage
Hardware OS
Mem

I/O Ctrlr

22
Operating System’s View of the World

Runninginterface to application interface


• OS translates from hardware Running
Program
• OS provides each running 1
program with its own process Program 2

System Libs System Libs

Process 1 Process 2
Compiler Threads Address Spaces Files Sockets Threads Address Spaces Files Sockets

Operating System
ISA
PgTbl Networks
Processor Memory
& TLB Storage
Hardware OS
Mem

I/O Ctrlr

23
What is an Operating System?

• Referee
ØManage protection, isolation, and sharing of resources
» Resource allocation and communication
• Illusionist
ØProvide clean, easy-to-use abstractions of physical resources
» Infinite memory, dedicated machine
» Higher level objects: files, users, messages
» Masking limitations, virtualization

24
OS Basics: Running a Process

Compiled Compiled
Program 1 Program 2

System Libs System Libs

Process 1 Process 2
Compiler Threads Address Spaces Files Sockets Threads Address Spaces Files Sockets

Operating System
ISA
PgTbl Networks
Processor Memory
& TLB Storage
Hardware

I/O Ctrlr

25
OS Basics: Switching Processes

Compiled Compiled
Program 1 Program 2

System Libs System Libs

Process 1 Process 2
Compiler Threads Address Spaces Files Sockets Threads Address Spaces Files Sockets

Operating System
ISA
PgTbl Networks
Processor Memory
& TLB Storage
Hardware
OS
Mem

I/O Ctrlr

26
OS Basics: Switching Processes

Compiled Compiled
Program 1 Program 2

System Libs System Libs

Process 1 Process 2
Compiler Threads Address Spaces Files Sockets Threads Address Spaces Files Sockets

Operating System
ISA
PgTbl Networks
Processor Memory
& TLB Storage
Hardware
OS
Mem

I/O Ctrlr

27
OS Basics: Switching Processes

Compiled Compiled
Program 1 Program 2

System Libs System Libs

Process 1 Process 2
Compiler Threads Address Spaces Files Sockets Threads Address Spaces Files Sockets

Operating System
ISA
PgTbl Networks
Processor Memory
& TLB Storage
Hardware
OS
Mem

I/O Ctrlr

28
OS Basics: Switching Processes

Compiled Compiled
Program 1 Program 2

System Libs System Libs

Process 1 Process 2
Compiler Threads Address Spaces Files Sockets Threads Address Spaces Files Sockets

Operating System
ISA
PgTbl Networks
Processor Memory
& TLB Storage
Hardware
OS
Mem

I/O Ctrlr

29
OS Basics: Protection

Compiled Compiled
Program 1 Program 2

System Libs System Libs

Process 1 Process 2
Compiler Threads Address Spaces Files Sockets Threads Address Spaces Files Sockets

Operating System
ISA
PgTbl Networks
Processor Memory
& TLB Storage
Hardware
OS
Mem

I/O Ctrlr

30
OS Basics: Protection

Compiled Compiled
Program 1 Program 2

System Libs System Libs

Process 1 Process 2
Compiler Threads Address Spaces Files Sockets Threads Address Spaces Files Sockets

Operating System
ISA
PgTbl Networks
Processor Memory
& TLB Storage
Hardware
OS
Mem

I/O Ctrlr

31
OS Basics: Protection

Process 1 Process 2 Process 3

Software OS Hardware Virtualization • OS isolates processes from


Hardware ISA
each other
Memory

Processor
• OS isolates itself from other
Protection
Boundary processes
OS Memory

Ctrlr
Networks Displays • … even though they are
actually running on the
Storage same hardware!
Inputs

32
What is an Operating System?

• Referee
ØManage protection, isolation, and sharing of resources
» Resource allocation and communication
• Illusionist
ØProvide clean, easy-to-use abstractions of physical resources
» Infinite memory, dedicated machine
» Higher level objects: files, users, messages
» Masking limitations, virtualization
• Glue
ØCommon services
» Storage, Window system, Networking
» Sharing, Authorization
» Look and feel
33
OS Basics: I/O

Process 1 Process 2 Process 3

Software OS Hardware Virtualization

Hardware ISA
Memory
• OS provides common
services in the form of
Processor Protection
Boundary
I/O
OS Memory

Ctrlr
Networks Displays

Storage

Inputs

34
OS Basics: Look and Feel

Compiled
Program

System Libs

Process: Execution environment with restricted rights provided by OS


Compiler Threads Address Spaces Files Sockets Windows

Operating System
ISA
PgTbl Networks Displays
Processor Memory
& TLB Storage
Hardware OS
Mem

I/O Ctrlr

35
OS Basics: Background Management

Compiled
Program

System Libs

Process: Execution environment with restricted rights provided by OS


Compiler Threads Address Spaces Files Sockets Windows

Operating System Network Power


Manager Manager
ISA
PgTbl Networks Displays Battery
Processor Memory
& TLB Storage
Hardware OS
Mem

I/O Ctrlr

36
What is an Operating System?

• Referee
ØManage protection, isolation, and sharing of resources
» Resource allocation and communication
• Illusionist
ØProvide clean, easy-to-use abstractions of physical resources
» Infinite memory, dedicated machine
» Higher level objects: files, users, messages
» Masking limitations, virtualization
• Glue
ØCommon services
» Storage, Window system, Networking
» Sharing, Authorization
» Look and feel
37
Why take Operating Systems?
• Some of you will actually design and build operating systems or components of
them.
ØPerhaps more now than ever
• Many of you will create systems that utilize the core concepts in operating
systems.
ØWhether you build software or hardware
ØThe concepts and design patterns appear at many levels
• All of you will build applications, etc. that utilize operating systems
ØThe better you understand their design and implementation, the better use you’ll
make of them.

38
What makes Operating Systems
Exciting and Challenging?

39
Technology Trends: Moore’s Law

Moore’s Law

2X transistors/Chip Every 2 years


Called “Moore’s Law”
Gordon Moore (co-founder of Intel) predicted in 1965 that the transistor density of
semiconductor chips would double roughly every 2 years
• Microprocessors have become smaller, denser, and more powerful
Corollary: Performance double roughly every 1.5 years (18 months)
• Faster growth because transistors are closer to each other so electrical signals travel faster

40
The end of the Moore’s Law

From 2x every 18 months to


1.05x every 18 months!

John L. Hennessy and David A. Patterson.A New Golden Age for Computer Architecture. Communications of the ACM 2019.
41
AI Compute demands

nths
mo
y 18
r
eve
x
35

(https://openai.com/blog/ai-and-compute//) 42
AI Compute demands

GPT-3

nths
mo
y 18
r
eve
x
35

2020
(https://openai.com/blog/ai-and-compute//) 43
Growing gap between demand and supply
GPT-4 and beyond

GPT-3

nths
mo
y 18
r
eve
x
35

months)
or e’s Law (2x every 18 CPU
Mo

2020
(https://openai.com/blog/ai-and-compute//) 44
Specialized processors to the rescue?

Nvidia A100 AWS’s Inferentia


TPU v3

AMD Radeon Intel Alchemist


Cerebras

45
Specialized hardware not enough
GPT-4 and beyond

GPT-3

nths
mo
y 18
r
eve
x
35 TPU*
GPU*

months)
or e’s Law (2x every 18 CPU
Mo

2020
* assume 0.33 utilization (https://openai.com/blog/ai-and-compute//) 46
Memory demands growing as fast

Wu Dao 2.0 (1.75T)


Number of parameters

GPT-3 (175B)

Turing Proj. (17B)


GPT-2 (8.3 B)

GPT-1 (1.5B)

BERT
Transformer
GPT-1
ResNet-50

47
Memory demands growing as fast

Wu Dao 2.0 (1.75T)


Number of parameters

GPT-3 (175B)
t hs
hs on
nt mTuring Proj. (17B)
mo 18
8 y
y 1 er GPT-2 (8.3 B)
v er ev
0xe 0x GPT-1 (1.5B)
4 34
BERT
Transformer
GPT-1
ResNet-50

48
Huge Gap between memory demands and single-chip memory

Wu Dao 2.0 (1.75T)


Number of parameters

1,000+ GPUs just


GPT-3 (175B)
to store
t hs parameters!
hs on
nt m Turing Proj. (17B)
mo 18
r y 18
v
n e
t
r
h
y
s
GPT-2 (8.3 B) GPU
evxe every 18 mxoe
0x1.7 40 GPT-1 (1.5B)
4 3
BERT
Transformer
GPT-1
ResNet-50

49
Storage Capacity is Still Growing!

50
Storage Capacity

Largest SSD 3.5-inch drive: Largest HDD 3.5-inch drive:


100 TB @ $40K ($400/TB) 18 TB @ $600 ($33/TB)

Cheaper, but
• Slower (10x-100x)
• Consumes more power
• Less reliable
Samsung SSD 2.5-inch drive:
4 TB @ $380K ($95/TB)

51
SSD/Flash will Dominate

52
Network Capacity

(source: http://www.ospmag.com/issue/article/Time-Is-Not-Always-On-Our-Side )
53
People-to-Computer Ratio Over Time

From David Culler

• Today: multiple CPUs/person!


ØApproaching 100s?
54
And Range of Timescales

Jeff Dean: “Numbers


Everyone Should Know”

55
Challenge: Complexity
• Applications consisting of…
Ø… a variety of software modules that …
Ø… run on a variety of devices (machines) that
» … implement different hardware architectures
» … run competing applications
» … fail in unexpected ways
» … can be under a variety of attacks

• Not feasible to test software for all possible environments and combinations of
components and devices
ØThe question is not whether there are bugs but how serious are the bugs!

56
A Modern Processor: Intel Sandy Bridge

• Package: LGA 1155 • Transistor count:


Ø 1155 pins Ø 504 Million (2 cores, 3MB L3)
Ø 95W design envelope Ø 2.27 Billion (8 cores, 20MB L3)
• Cache: • Note that ring bus is on high metal layers –
Ø L1: 32K Inst, 32K Data above the Shared L3 Cache
(3 clock access)
Ø L2: 256K (8 clock access)
Ø Shared L3: 3MB – 20MB
57
HW Functionality comes with great complexity!
Intel Sandy Bridge I/O
Configuration

Proc

Caches
Busses

adapters
Memory

Controllers

Disks
I/O Devices:
Displays Networks
Keyboards

58
Not only specialized processors…
• Multi-core processors
ØIntel Xeon Phi: 64+ cores
ØAMD Epyc: 64+ cores

• System On a Chip (SOC): accelerating trend

59
Increasing Software Complexity

From MIT’s 6.033 course

60
Everything going distributed
• Need to scale
ØMachine learning workloads, especially large language models
ØBig data analytics
ØScientific computing
Ø…

• Everything is connected!

61
Greatest Artifact of Human Civilization…

Map of the Internet


62
Running Systems at Internet Scale

Worldwide Internet Users


70% 5,000

Internet WWW 4,500


60%
4,000

RFC 675 TCP/IP


50% 3,500

HTTP 0.9
ARPANet 3,000
40%
2,500

30%
2,000

1,500
20%

1,000
10%
500

0% 0
1965 1975 1985 1995 2005 2015 2025
1965 1975 1985 1995 2005 2015 2025

% Population Million

1969 1974 1990

63
Societal Scale Information Systems
(Or the “Internet of Things”?) Massive Cluster

• The world is a large distributed system Gigabit Ethernet


ØMicroprocessors in everything Clusters
Massive Cluster
ØVast infrastructure behind them
Gigabit Ethernet Clusters

Internet Scalable, Reliable,


Connectivity Secure Services

Databases
Information Collection
Remote Storage
Online Games
Commerce

MEMS for
Sensor Nets
64
Example: What’s in a Search Query?
DNS
Servers Datacenter
DNS create
request Search
result Index
page

Page
store
Load
balancer

Ad Server

• Complex interaction of multiple components in multiple


administrative domains
ØSystems, services, protocols, …
65
How do we tame complexity?
• Every piece of computer hardware different
ØDifferent CPU
» x86 (Intel, AMD), ARM, RISC-V
ØDifferent specialized hardware
» Nvidia GPUs, TPUs, AWS Inferentia, …
ØDifferent amounts of memory, disk, …
ØDifferent types of devices
» Mice, Keyboards, Sensors, Cameras, Fingerprint readers, Face recognotion
ØDifferent networking environment
» Fiber, Cable, DSL, Wireless, Firewalls,…
• Questions:
ØDoes the programmer need to write a single program that performs many independent
activities?
ØDoes every program have to be altered for every piece of hardware?
ØDoes a faulty program crash everything?
ØDoes every program have access to all hardware?
66
Lab 0
• Booting Pintos
• Debugging
• Kernel Monitor

• Deadline: February 29 (next Thursday)

67
Discussion
• What is an operating system?

• Operating systems vs. computer systems vs. system software

• Operating systems vs. distributed systems vs. networked systems vs. storage
systems vs. database systems

68
Conclusion

• Operating systems provide high-level abstractions to handle


diverse hardware
ØOperating systems simplify application development by providing
standard services
• Operating systems coordinate resources and protect users from
each other
ØOperating systems can provide an array of fault containment, fault
tolerance, and fault recovery
• Operating systems combine things from many other areas of
computer science
ØLanguages, data structures, hardware, and algorithms

• Feedback: https://www.wjx.cn/vm/PZaRCka.aspx
69

You might also like