cs 31: intro to systems course recap · course recap •this course was a vertical slice of...

22
CS 31: Intro to Systems Course Recap Kevin Webb Swarthmore College April 26, 2016

Upload: others

Post on 19-Jul-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS 31: Intro to Systems Course Recap · Course Recap •This course was a vertical slice of computer –From lowest level: simple logic –To high level: large, complex programs run

CS 31: Intro to Systems Course Recap

Kevin Webb

Swarthmore College

April 26, 2016

Page 2: CS 31: Intro to Systems Course Recap · Course Recap •This course was a vertical slice of computer –From lowest level: simple logic –To high level: large, complex programs run

Reading Quiz

Page 3: CS 31: Intro to Systems Course Recap · Course Recap •This course was a vertical slice of computer –From lowest level: simple logic –To high level: large, complex programs run

Reading Quiz

Just kidding. Did I scare you?

Page 4: CS 31: Intro to Systems Course Recap · Course Recap •This course was a vertical slice of computer –From lowest level: simple logic –To high level: large, complex programs run

Final Exam

• Thursday, May 12, 2:00 PM. SCI 199

• Similar format to the midterm

• You get ~100% more time

• Exam is ~15% longer

• ~2/3 post-midterm material

Page 5: CS 31: Intro to Systems Course Recap · Course Recap •This course was a vertical slice of computer –From lowest level: simple logic –To high level: large, complex programs run

Course Recap

• This course was a vertical slice of computer

– From lowest level: simple logic

– To high level: large, complex programs run on OS

• Big goal: make complex machine easier to use

– Hide details with the right abstractions

– Improve performance when possible

Page 6: CS 31: Intro to Systems Course Recap · Course Recap •This course was a vertical slice of computer –From lowest level: simple logic –To high level: large, complex programs run

Lowest Level

• Storing and representing data

– 2’s complement integers, floating point, etc.

– Arithmetic using bits

• Logic gates: simple hardware

a

b out

a

b out a out

Page 7: CS 31: Intro to Systems Course Recap · Course Recap •This course was a vertical slice of computer –From lowest level: simple logic –To high level: large, complex programs run

Hardware Abstraction: Circuits

• Combining gates to build specific circuits

– arithmetic (adders, ALUs)

– storage (latches, registers)

– control (fetch, decode, multiplex)

= 1-bit adder

Cin

Cout

A

B Sum

Page 8: CS 31: Intro to Systems Course Recap · Course Recap •This course was a vertical slice of computer –From lowest level: simple logic –To high level: large, complex programs run

CPU

• Combine circuits to create a CPU

– Periodic clock: fetch, decode, execute instructions

Data in

32-bit Register #0 WE

Data in

32-bit Register #1 WE

32-bit Register #2 WE

Data in

32-bit Register #3 WE

Data in

MUX

MUX

Register File

A L U

Program Counter (PC):

Memory address of next instr

Instruction Register (IR):

Instruction contents (bits)

Page 9: CS 31: Intro to Systems Course Recap · Course Recap •This course was a vertical slice of computer –From lowest level: simple logic –To high level: large, complex programs run

Instruction Set Architecture

• ISA defines CPU / software interaction

– Machine properties (# registers, address modes)

– Method for controlling hardware (assembly lang)

x = y >> 3 | x * 8

movl -8(%ebp), %eax # R[%eax] x

imull $8, %eax # R[%eax] x*8

movl -12(%ebp), %edx # R[%edx] y

rshl $3, %edx # R[%edx] y >> 3

orl %eax, %edx # R[%edx] y>>3 | x*8

movl %edx, -8(%ebp) # M[R[%ebp-8]] result

Page 10: CS 31: Intro to Systems Course Recap · Course Recap •This course was a vertical slice of computer –From lowest level: simple logic –To high level: large, complex programs run

Conventions

• Agreed upon system for using ISA

– e.g., manipulating the stack, register meaning

… Older stack frames.

Caller’s local variables.

Final Argument to Callee

First Argument to Callee

Return Address

Callee’s local variables.

Caller’s Frame Pointer

Caller’s frame.

Callee’s frame.

Page 11: CS 31: Intro to Systems Course Recap · Course Recap •This course was a vertical slice of computer –From lowest level: simple logic –To high level: large, complex programs run

Storage and Memory

• Allocating memory (stack vs. heap)

• Pointers

– malloc() / free()

– address of (&)

– dereferencing

– arrays, 2D arrays

0x0

0xFFFFFFFF

Operating system

Stack

Text

Data

Heap

Page 12: CS 31: Intro to Systems Course Recap · Course Recap •This course was a vertical slice of computer –From lowest level: simple logic –To high level: large, complex programs run

The Memory Hierarchy

Local secondary storage (disk)

Larger Slower Cheaper per byte

Remote secondary storage (tapes, Web servers / Internet)

~100 M cycles to access

On Chip

Storage

Smaller Faster Costlier per byte

Main memory (DRAM)

~100 cycles to access

CPU instrs

can directly access

slower than local disk to access

Registers 1 cycle to access

Cache(s) (SRAM)

~10’s of cycles to access

Flash SSD / Local network

Page 13: CS 31: Intro to Systems Course Recap · Course Recap •This course was a vertical slice of computer –From lowest level: simple logic –To high level: large, complex programs run

Caching

• Improve performance by keeping a small memory for frequently-used data

– Many parameters inform address division (tag, idx)

• direct map vs. associative

• block size

• Exploit major idea: Locality

– temporal / spatial

Page 14: CS 31: Intro to Systems Course Recap · Course Recap •This course was a vertical slice of computer –From lowest level: simple logic –To high level: large, complex programs run

Operating System

• Software supports: making programs easy/fast

• Three major abstractions:

1. Process

2. Thread

3. Virtual memory

• Mechanism vs. policy

Page 15: CS 31: Intro to Systems Course Recap · Course Recap •This course was a vertical slice of computer –From lowest level: simple logic –To high level: large, complex programs run

Processes

• Program in execution – fork() / exit() to create / terminate

• Represents all of the resources of a task – virtual address space (process memory)

– open files

– process ID, other accounting info

• One or more threads of execution

Page 16: CS 31: Intro to Systems Course Recap · Course Recap •This course was a vertical slice of computer –From lowest level: simple logic –To high level: large, complex programs run

Threads • Execution context within a process

• Independently scheduled

Thread 1 PC1

SP1

Thread 2

Thread 3

PC2

SP2 PC3

SP3

Process 1

Text

Data

Stack 1

OS

Heap

Stack 2

Stack 3

Page 17: CS 31: Intro to Systems Course Recap · Course Recap •This course was a vertical slice of computer –From lowest level: simple logic –To high level: large, complex programs run

Virtual Memory

• Allow processes to behave as if they have the entire memory of the machine

• Translate from virtual (fantasy) address to physical

Physical Memory

Virtual Memory

(OS Mapping)

Virtual Address Page p Offset i

Physical Address

Frame V Perm … R D

Page 18: CS 31: Intro to Systems Course Recap · Course Recap •This course was a vertical slice of computer –From lowest level: simple logic –To high level: large, complex programs run

Virtual Memory

• Use disk to store data that hasn’t been used lately

– (Another instance of exploiting locality)

VM PM

Page Table

Memory Hierarchy

Page 19: CS 31: Intro to Systems Course Recap · Course Recap •This course was a vertical slice of computer –From lowest level: simple logic –To high level: large, complex programs run

Mechanism & Policy

• Mechanism: the ability to do something

• Policy: rules for governing the mechanism(s)

• “Best” policy usually varies by workload!

Mechanism Policy

Context switching CPU scheduling

Cache eviction Cache replacement policy

VM paging to disk Page replacement policy

Page 20: CS 31: Intro to Systems Course Recap · Course Recap •This course was a vertical slice of computer –From lowest level: simple logic –To high level: large, complex programs run

Concurrency & Parallelism

• Single CPU core performance has plateaued

– Hardware giving us more CPU cores instead

• Programmer’s responsibility to use them!

• Big opportunity for performance benefits!

Page 21: CS 31: Intro to Systems Course Recap · Course Recap •This course was a vertical slice of computer –From lowest level: simple logic –To high level: large, complex programs run

Multi-threading in Practice (pthreads)

• Not always intuitive to reason about…

• Potential problems

– race conditions

– deadlock

– priority inversion, etc.

• Requires careful synchronization

Page 22: CS 31: Intro to Systems Course Recap · Course Recap •This course was a vertical slice of computer –From lowest level: simple logic –To high level: large, complex programs run

Questions?

• Thank you for a great semester!