52
CS162: Operating Systems and Systems Programming Lecture 1: What is an Operating System? 22 June 2015 Charles Reiss https://cs162.eecs.berkeley.edu/

CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

  • Upload
    others

  • View
    13

  • Download
    0

Embed Size (px)

Citation preview

Page 1: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

CS162:Operating Systems andSystems Programming

Lecture 1:What is an Operating System?22 June 2015Charles Reisshttps://cs162.eecs.berkeley.edu/

Page 2: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

2

Example: Search Query

Components to coordinateMany shared resources

Datacenter

Loadbalancer

Ad Server

DNS Servers

SearchIndex

DNSrequest

createresultpage

Page store

Page 3: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

3

Why take CS162?You will build (parts of) operating systems

You will build other software using OS concepts

You will build applications that use OSes

Page 4: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

4

Topics for TodayWhat is (or is not) an operating system?Some common operating system abstractions… interrupted by Logistics

Page 5: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

5

What is an operating system? (1)Layer of software that provides applications access to hardware

― Abstraction of complex hardware― Protected access to shared resources― Security― Communication

Hardware

applnappln

OS

appln

Page 6: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

6

History: The Computer Operator

Page 7: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

7

What is an operating system? (2)Provide programs with a more convenient "abstract" machine instead of the existing machine

Page 8: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

8

The Abstract Virtual Machine (1)#include <stdlib.h>

int main(void) { printf("Hello!\n")}

#include <stdlib.h>

int main(void) { printf("Hello!\n")}

Applications

CPUCPU

Operating SystemProcesses

Address SpacesFiles

WindowsSockets

Threads OS's interface

Proces

sor#

Contr

ol(

Datap

ath(

Review:#

Addin

g#Cach

e#to#C

omputer

# 4#

PC# # #

Registers#

Arithm

eVc#&

#Logic#Un

it#(AL

U)#

Memo

ry(Inp

ut(

Outpu

t(

Bytes#

Enable?#

Read/

Write#

Addre

ss#

Write#

Data# Read

Data#

Proces

sorkMem

ory#Interfac

e#I/O

kMem

ory#Interfac

es#

Progra

m#

Data#

Cache

#

Input/OutputInput/OutputScreenScreen KeyboardKeyboard StorageStorage

#include <stdlib.h>

int main(void) { printf("Hello!\n")}

#include <stdlib.h>

int main(void) { printf("Hello!\n")}

#include <stdlib.h>

int main(void) { printf("Hello!\n")}

#include <stdlib.h>

int main(void) { printf("Hello!\n")}

ISA/Hardware interfaceNetworkNetwork

Page 9: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

9

Abstract VM: Application View#include <stdlib.h>

int main(void) { printf("Hello!\n")}

#include <stdlib.h>

int main(void) { printf("Hello!\n")}

Applications#include <stdlib.h>

int main(void) { printf("Hello!\n")}

#include <stdlib.h>

int main(void) { printf("Hello!\n")}

#include <stdlib.h>

int main(void) { printf("Hello!\n")}

#include <stdlib.h>

int main(void) { printf("Hello!\n")}

Application's "machine" is the OSNo hardware I/O details

― Future-proof

More featureful interfaces than HW

ProcessesAddress Spaces

Files

WindowsSockets

Threads OS's interface

Page 10: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

10

Operating SystemISA/Hardware interface

ProcessesAddress Spaces

Files

WindowsSockets

Threads OS's interface

Abstract VM: OS View

Operating system translates from one interface to the other

Page 11: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

11

Abstraction: Program → Process

CPUCPU

Operating SystemProcess

Address SpacesFiles

WindowsSockets

Threads OS's interface

Proces

sor#

Contr

ol(

Datap

ath(

Revie

w:#Addin

g#Cach

e#to#C

omputer

# 4#

PC# # #

Registers#

Arithm

eVc#&

#Logic#Un

it#(AL

U)#

Memo

ry(Inp

ut(

Outpu

t(

Bytes#

Enabl

e?#Read/W

rite#

Addre

ss#

Write#

Data# Read

Data#

Proces

sorkMem

ory#Interfac

e#I/O

kMem

ory#Int

erface

s#

Progra

m#

Data#

Cache

#

Input/OutputInput/Output

ScreenScreen KeyboardKeyboard StorageStorage

ISA/Hardware interfaceNetworkNetwork

#include <stdlib.h>

int main(void) { printf("Hello!\n")}

#include <stdlib.h>

int main(void) { printf("Hello!\n")}

Start program

Page 12: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

13

Multiple Processes: Context Switch

CPUCPU

Operating System

Address SpacesFiles

WindowsSockets

Threads OS's interface

Input/OutputInput/OutputScreenScreen KeyboardKeyboard StorageStorage

ISA/Hardware interfaceNetworkNetwork

#include <stdlib.h>

int main(void) { printf("Hello!\n")}

#include <stdlib.h>

int main(void) { printf("Hello!\n")}

#include <stdlib.h>

int main(void) { printf("Hello!\n")}

#include <stdlib.h>

int main(void) { printf("Hello!\n")}

ProcessProcess

Page 13: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

14

Abstraction: Input/Output

CPUCPU

Operating SystemProcess

Address Spaces

Files

Windows

SocketsThreads OS's interface

Proces

sor#

Contr

ol(

Datap

ath(

Revie

w:#Addin

g#Cach

e#to#C

omputer

# 4#

PC# # #

Registers#

Arithm

eVc#&

#Logic#Un

it#(AL

U)#

Memo

ry(Inp

ut(

Outpu

t(

Bytes#

Enabl

e?#Read/W

rite#

Addre

ss#

Write#

Data# Read

Data#

Proces

sorkMem

ory#Interfac

e#I/O

kMem

ory#Int

erface

s#

Progra

m#

Data#

Cache

#

ScreenScreen KeyboardKeyboard StorageStorage

ISA/Hardware interfaceNetworkNetwork

#include <stdlib.h>

int main(void) { printf("Hello!\n")}

#include <stdlib.h>

int main(void) { printf("Hello!\n")}

Read/Write/Open/Close

Input/OutputInput/Output

Page 14: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

15

ProcessesAddress Spaces

Files

WindowsSockets

Threads OS's interface

Security and Protection#include <stdio.h>int main(void) { FILE* fh = open("/etc/shadow");}

#include <stdio.h>int main(void) { FILE* fh = open("/etc/shadow");}

Permission Denied

CPUCPU

Operating System

Proces

sor#

Contr

ol(

Datap

ath(

Review:#

Addin

g#Cach

e#to#C

omputer# 4#

PC# # #

Registers#

Arithm

eVc#&

#Logic#Un

it#(AL

U)#

Memo

ry(Inp

ut(

Outpu

t(

Bytes#

Enable?#

Read/W

rite#

Addre

ss#

Write#

Data# Read

Data#

Proces

sorkMem

ory#Int

erface

#I/O

kMem

ory#Interfac

es#

Progra

m#

Data#

Cache

#

ScreenScreen KeyboardKeyboard StorageStorage

ISA/Hardware interfaceNetworkNetwork

Input/OutputInput/Output

Page 15: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

16

ProcessesAddress Spaces

Files

WindowsSockets

Threads OS's interface

Security and Protection#include <stdlib.h>

int main(void) {...

}

#include <stdlib.h>

int main(void) {...

}

Segmentation Fault

CPUCPU

Operating System

Proces

sor#

Contr

ol(

Datap

ath(

Review:#

Addin

g#Cach

e#to#C

omputer# 4#

PC# # #

Registers#

Arithm

eVc#&

#Logic#Un

it#(AL

U)#

Memo

ry(Inp

ut(

Outpu

t(

Bytes#

Enable?#

Read/W

rite#

Addre

ss#

Write#

Data# Read

Data#

Proces

sorkMem

ory#Int

erface

#I/O

kMem

ory#Interfac

es#

Progra

m#

Data#

Cache

#

ScreenScreen KeyboardKeyboard StorageStorage

ISA/Hardware interfaceNetworkNetwork

Input/OutputInput/Output

Page 16: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

17

Interlude: Logistics

Page 17: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

18

InfrastructureWebsite:https://cs162.eecs.berkeley.edu/Piazza: https://piazza.com/berkeley/summer2015/cs162

Page 18: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

19

TextbookAnderson and Dahlin,Operating Systems:Principles and Practice (2nd ed)

Recommended Text:Silberchartz, Galvin, and GagneOperating Systems Concepts (9th ed)

Online supplements― Linked off "readings"

Page 19: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

20

Syllabus SummaryOS Interfaces: processes, I/O, sockets, …Concurrency: threads, scheduling, locks, … Address spaces: virtual memory, protection, … Distributed systems: RPC, consistency, NFS, …File systems: I/O devices, naming, caching, …Reliability & Security: fault tolerance, security, …

Page 20: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

21

Syllabus SummaryOS Interfaces: processes, I/O, sockets, …Concurrency: threads, scheduling, locks, … Address spaces: virtual memory, protection, … Distributed systems: RPC, consistency, NFS, …File systems: I/O devices, naming, caching, …Reliability & Security: fault tolerance, security, …

Project 2Project 1

Project 3

Page 21: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

22

Learn by DoingHomeworks: Individual assignments

― HW0: Tools, Autograding, C, Executables― HW1: Simple Shell― HW2: Malloc― HW3: Trivial Filesystem

Projects: Group― 1: Threads & Scheduling― 2: User programs― 3: Key-value store

Page 22: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

23

Start HW0 ImmediatelyDue Friday at 11:59 PMGets your course accountGets you a class repo repository on githubSetup VM for the course

Page 23: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

24

Group Projects4 person teams

― Never 5

Find teams soon (or we will for you)Communicate!

― Everyone should do work – clear responsibility!― Each group assigned a TA

Design documents

Page 24: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

25

Project Grading[20 pts] Initial Design + Design Review[50 pts] Code (2 checkpoints)[30 pts] Final Design[0 pts] Peer EvaluationSubmission: git push to release branch

Page 25: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

26

Grading20% Midterm 20% Final

― Both during class time, see schedule on web

45% Projects (15% each)15% Homeworks (~4% each)

Page 26: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

27

Collaboration PolicyOK:

― Explaining a concept to someone in another group― Discussing algorithms/testing strategies with other groups― Helping debug someone else’s code (in another group)― Searching online for generic algorithms (e.g., hash table)

NOT OKAY:― Sharing (pseudo-)code or test cases with another group― Copying OR reading another group’s code or test cases― Copying OR reading online code or test cases from prior years― Sharing homework code with other members of your project group

Confused? Ask. We can't help you after you cheat.

Page 27: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

28

Late PolicyAssignments are due 11:59PM Pacific Time (except initial design documents).

― There is a "grace period"; please don't try to test it.

There are no slip days.

Submit up to 48 hours late: 20% deduction― Not for initial design documents for projects

Submit more than 48 hours late: no credit― We'll still tell you how you did, if you want...

Page 28: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

29

StaffInstructor Charles Reiss

― OH: MWF 1-2p 651 Soda

GSI Frank Nothaft― Main discussion TA (both discussions)― Starting Wednesday/Thursday― Possible project TA― OH: TuTh 1-2p 651 Soda

GSI Alex Yang― Lead project/homework TA― Possible project TA― OH: MW 2-3p, Tu 5-6p 651 Soda

Readers: Nick Xu and Leon Wang― Grade your final design docs; manual parts of homeworks; etc.

Page 29: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

30

Topics for TodayWhat is (or is not) an operating system?

Some common operating system abstractions… interrupted by Logistics

Page 30: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

31

What is an operating system? (3)Referee

― Resource sharing, protection, isolation

Illusionist― Clean, easy abstractions

Glue: Common services― Storage― Window systems― Authorization― Networking

Page 31: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

32

Unify theme: ComplexityAll the definitions: operating systems are about hiding complexity

Page 32: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

33

Challenge: ComplexityCompeting applications with

― Unexpected failures― Even malicious applications

Varying hardware with― Diverse, evolving interfaces― Unexpected failures

→ Not feasible to test all configurations!

Page 33: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

34

Complexity Example:Mars PathfinderLots of types of hardware:

― radios, scientific instruments, batteries, solar panels, and locomotion equipment

Reliability requirements:― No reset button: must reboot self automatically― Must always be able to receive commands from Earth

Remote debugging?― Software will crash (e.g. instrument breaks – is that handled?)― Need to debug from earth

Time critical functions― Stop before hitting something― Earth communication

Page 34: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

35

Complexity: VarietyDifferent CPUs

― Pentium, PowerPC, ColdFire, ARM, MIPS

Different amounts of memory, disk, …Different types of devices

― Mice, Keyboards, Sensors, Cameras, …

Different networking equipment― Cable, DSL, Wireless, Ethernet, …

Page 35: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

36

Proc

CachesBusses

Memory

I/O Devices:

Controllers

adapters

DisksDisplaysKeyboards Networks

SandyBridge I/OConfiguration

Complexity: Modern Hardware

Page 36: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

37

Unifying theme:Helping the application programmerWrite once for lots of hardwareWithout reimplementing common functionalityRun alongside other programsOne program crashing doesn't crash everything

Page 37: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

38

Break

Page 38: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

39

Abstract VM GoalsApplication

Operating SystemHardware Physical Machine Interface

Virtual Machine Interface

OS Goals:― Remove hardware/software quirks (fight complexity)― Optimize for convenience, utilization, reliability, … (help

programmer)

Big questions for any area of OS (file systems, scheduling, ...):― What hardware interface to handle? (physical reality)― What software interface to provide? (nicer abstraction)

Page 39: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

40

Side Note: Virtual MachinesDefinition: Software emulation of abstract machine

― Programs believe they own the machine― Simulated "hardware" has the features we want

Two types:― Process VM: run a single program (typical OS)― System VM: run entire OS + its applications

(Virtualbox, VMWare, Parallels, Xen, ...)

Page 40: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

41

Process VMEach process thinks …

― It has all the memory, CPU time, devices, …― All devices have the same interface― Device interfaces more powerful than raw hardware:

● Reliable TCP/IP instead of Ethernet card● Windowing system instead of bitmapped display

Fault isolation:― Can't directly impact other processes― Bugs won't crash everything

Portability: Write application for OS, not hardware

Page 41: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

42

Run entire OSs― Good for OS development, portability

Interface closer to raw HW― to aid porting/running OSs built to use raw HW― different kind of "application programmer" to design for

System VMs: Layers of OSs

Page 42: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

43

What is an operating system? (4)Always:

― Memory management― I/O management― CPU scheduling― Communication?

Sometimes:― Filesystems― ? Multimedia support― ? User interface― ? Internet browser

Page 43: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

44

What is an operating system? (5)No universal definition

One approximation: "Everything a vendor ships when you order an OS"

― But varies a lot!

"The one program running at all times" is the kernel. The rest are

― System programs (ship with operating system) and― Application programs

Page 44: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

45

Topics for TodayWhat is (or is not) an operating system?Some common operating system abstractions

… interrupted by Logistics

Page 45: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

46

OS Goal: Protecting ProcessesMost important task of OSs?

Run multiple applications, and... Keep them from crashing the OSKeep them from crashing each other[Keep parts of OS from crashing other parts?]

Page 46: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

47

Protecting ProcessesAvailable mechanisms (hardware interfaces):

― Address translation― Dual mode operation

Simple policy: Programs are not allowed to read or write memory of other programs or OS

Page 47: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

48

Address TranslationAbstraction: Address space

― Group of memory addresses usable by something― Each process, kernel have different address spaces― Illusion of owning all memory

Mechanism: Address Translation― Translate virtual addresses (emitted by CPU)

to physical addresses― Usually performed in HW by Memory Management Unit (MMU)

CPU MMU

VirtualAddresses

PhysicalAddresses

Page 48: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

Prog 1Virtual

AddressSpace 1

Prog 2Virtual

AddressSpace 2

CodeDataHeapStack

CodeDataHeapStack

Data 2

Stack 1

Heap 1

OS heap & Stacks

Code 1

Stack 2

Data 1

Heap 2

Code 2

OS code

OS dataTranslation Map 1 Translation Map 2

Physical Address Space

Example of Address Translation

Page 49: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

50

Address Translation Details(Covered in 61C?)

Virtual Address

Page Table

indexintopagetable

VAccessRights PA

V page no. offset10

table locatedin physical

memoryP page no. offset

10Physical Address

Implements policy? Can't read/write if no translationProblem:

― Can user change page table pointer?

Page 50: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

51

Dual Mode OperationHardware provides at least two modes:

― "Kernel" (or "supervisor" or "protected")― "User" mode

Some operations prohibited in user mode― e.g. changing the page table pointer

Controlled transitions from user to kernel mode ― Systems calls, interrupts, exceptions, …

Page 51: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

52

UNIX System StructureUser Mode

Kernel Mode

Hardware

Applications

Standard Libs

Page 52: CS162: Operating Systems and Systems Programming Lecture 1 ...inst.eecs.berkeley.edu/~cs162/su15/static/lectures/1.pdf · CS162: Operating Systems and Systems Programming Lecture

53

ConclusionOperating systems

― provide a virtual machine abstraction to handle diverse hardware

― coordinate resources and protect users from each other

― simplify application development by providing standard services

― can provide an array of fault containment, fault tolerance, and fault recovery