cs 31: intro to systems course recapkwebb/cs31/s15/19-course... · 2015-05-01 · •combine...
TRANSCRIPT
![Page 1: CS 31: Intro to Systems Course Recapkwebb/cs31/s15/19-Course... · 2015-05-01 · •Combine circuits to create a CPU –Periodic clock: fetch, decode, execute instructions Data in](https://reader035.vdocuments.mx/reader035/viewer/2022080720/5f7a22def01c1857826ebafd/html5/thumbnails/1.jpg)
CS 31: Intro to Systems Course Recap
Kevin Webb
Swarthmore College
April 30, 2015
![Page 2: CS 31: Intro to Systems Course Recapkwebb/cs31/s15/19-Course... · 2015-05-01 · •Combine circuits to create a CPU –Periodic clock: fetch, decode, execute instructions Data in](https://reader035.vdocuments.mx/reader035/viewer/2022080720/5f7a22def01c1857826ebafd/html5/thumbnails/2.jpg)
Reading Quiz
![Page 3: CS 31: Intro to Systems Course Recapkwebb/cs31/s15/19-Course... · 2015-05-01 · •Combine circuits to create a CPU –Periodic clock: fetch, decode, execute instructions Data in](https://reader035.vdocuments.mx/reader035/viewer/2022080720/5f7a22def01c1857826ebafd/html5/thumbnails/3.jpg)
Reading Quiz
Just kidding. Did I scare you?
![Page 4: CS 31: Intro to Systems Course Recapkwebb/cs31/s15/19-Course... · 2015-05-01 · •Combine circuits to create a CPU –Periodic clock: fetch, decode, execute instructions Data in](https://reader035.vdocuments.mx/reader035/viewer/2022080720/5f7a22def01c1857826ebafd/html5/thumbnails/4.jpg)
Course Survey
• >95 % have responded
• Thank you!
• Extra quiz/participation grade to be dropped
![Page 5: CS 31: Intro to Systems Course Recapkwebb/cs31/s15/19-Course... · 2015-05-01 · •Combine circuits to create a CPU –Periodic clock: fetch, decode, execute instructions Data in](https://reader035.vdocuments.mx/reader035/viewer/2022080720/5f7a22def01c1857826ebafd/html5/thumbnails/5.jpg)
Final Exam
• Thursday, May 14, 2:00 PM. SCI 199
• Similar format to the midterm
• You get ~100% more time
• Exam is ~20% longer
• ~2/3 post-midterm material
![Page 6: CS 31: Intro to Systems Course Recapkwebb/cs31/s15/19-Course... · 2015-05-01 · •Combine circuits to create a CPU –Periodic clock: fetch, decode, execute instructions Data in](https://reader035.vdocuments.mx/reader035/viewer/2022080720/5f7a22def01c1857826ebafd/html5/thumbnails/6.jpg)
Review Session
A. Monday
B. Tuesday
C. Wednesday
D. Thursday (morning / early afternoon)
E. Don’t care and/or don’t plan to attend
![Page 7: CS 31: Intro to Systems Course Recapkwebb/cs31/s15/19-Course... · 2015-05-01 · •Combine circuits to create a CPU –Periodic clock: fetch, decode, execute instructions Data in](https://reader035.vdocuments.mx/reader035/viewer/2022080720/5f7a22def01c1857826ebafd/html5/thumbnails/7.jpg)
_______day Review Session
A. early morning
B. late morning
C. early afternoon
D. late afternoon
E. evening
![Page 8: CS 31: Intro to Systems Course Recapkwebb/cs31/s15/19-Course... · 2015-05-01 · •Combine circuits to create a CPU –Periodic clock: fetch, decode, execute instructions Data in](https://reader035.vdocuments.mx/reader035/viewer/2022080720/5f7a22def01c1857826ebafd/html5/thumbnails/8.jpg)
_______day Review Session
A. early morning
B. late morning
C. early afternoon
D. late afternoon
E. evening
![Page 9: CS 31: Intro to Systems Course Recapkwebb/cs31/s15/19-Course... · 2015-05-01 · •Combine circuits to create a CPU –Periodic clock: fetch, decode, execute instructions Data in](https://reader035.vdocuments.mx/reader035/viewer/2022080720/5f7a22def01c1857826ebafd/html5/thumbnails/9.jpg)
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 10: CS 31: Intro to Systems Course Recapkwebb/cs31/s15/19-Course... · 2015-05-01 · •Combine circuits to create a CPU –Periodic clock: fetch, decode, execute instructions Data in](https://reader035.vdocuments.mx/reader035/viewer/2022080720/5f7a22def01c1857826ebafd/html5/thumbnails/10.jpg)
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 11: CS 31: Intro to Systems Course Recapkwebb/cs31/s15/19-Course... · 2015-05-01 · •Combine circuits to create a CPU –Periodic clock: fetch, decode, execute instructions Data in](https://reader035.vdocuments.mx/reader035/viewer/2022080720/5f7a22def01c1857826ebafd/html5/thumbnails/11.jpg)
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 12: CS 31: Intro to Systems Course Recapkwebb/cs31/s15/19-Course... · 2015-05-01 · •Combine circuits to create a CPU –Periodic clock: fetch, decode, execute instructions Data in](https://reader035.vdocuments.mx/reader035/viewer/2022080720/5f7a22def01c1857826ebafd/html5/thumbnails/12.jpg)
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 13: CS 31: Intro to Systems Course Recapkwebb/cs31/s15/19-Course... · 2015-05-01 · •Combine circuits to create a CPU –Periodic clock: fetch, decode, execute instructions Data in](https://reader035.vdocuments.mx/reader035/viewer/2022080720/5f7a22def01c1857826ebafd/html5/thumbnails/13.jpg)
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 14: CS 31: Intro to Systems Course Recapkwebb/cs31/s15/19-Course... · 2015-05-01 · •Combine circuits to create a CPU –Periodic clock: fetch, decode, execute instructions Data in](https://reader035.vdocuments.mx/reader035/viewer/2022080720/5f7a22def01c1857826ebafd/html5/thumbnails/14.jpg)
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 15: CS 31: Intro to Systems Course Recapkwebb/cs31/s15/19-Course... · 2015-05-01 · •Combine circuits to create a CPU –Periodic clock: fetch, decode, execute instructions Data in](https://reader035.vdocuments.mx/reader035/viewer/2022080720/5f7a22def01c1857826ebafd/html5/thumbnails/15.jpg)
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 16: CS 31: Intro to Systems Course Recapkwebb/cs31/s15/19-Course... · 2015-05-01 · •Combine circuits to create a CPU –Periodic clock: fetch, decode, execute instructions Data in](https://reader035.vdocuments.mx/reader035/viewer/2022080720/5f7a22def01c1857826ebafd/html5/thumbnails/16.jpg)
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 17: CS 31: Intro to Systems Course Recapkwebb/cs31/s15/19-Course... · 2015-05-01 · •Combine circuits to create a CPU –Periodic clock: fetch, decode, execute instructions Data in](https://reader035.vdocuments.mx/reader035/viewer/2022080720/5f7a22def01c1857826ebafd/html5/thumbnails/17.jpg)
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 18: CS 31: Intro to Systems Course Recapkwebb/cs31/s15/19-Course... · 2015-05-01 · •Combine circuits to create a CPU –Periodic clock: fetch, decode, execute instructions Data in](https://reader035.vdocuments.mx/reader035/viewer/2022080720/5f7a22def01c1857826ebafd/html5/thumbnails/18.jpg)
Operating System
• Software supports: making programs easy/fast
• Three major abstractions:
1. Process
2. Thread
3. Virtual memory
• Mechanism vs. policy
![Page 19: CS 31: Intro to Systems Course Recapkwebb/cs31/s15/19-Course... · 2015-05-01 · •Combine circuits to create a CPU –Periodic clock: fetch, decode, execute instructions Data in](https://reader035.vdocuments.mx/reader035/viewer/2022080720/5f7a22def01c1857826ebafd/html5/thumbnails/19.jpg)
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 20: CS 31: Intro to Systems Course Recapkwebb/cs31/s15/19-Course... · 2015-05-01 · •Combine circuits to create a CPU –Periodic clock: fetch, decode, execute instructions Data in](https://reader035.vdocuments.mx/reader035/viewer/2022080720/5f7a22def01c1857826ebafd/html5/thumbnails/20.jpg)
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 21: CS 31: Intro to Systems Course Recapkwebb/cs31/s15/19-Course... · 2015-05-01 · •Combine circuits to create a CPU –Periodic clock: fetch, decode, execute instructions Data in](https://reader035.vdocuments.mx/reader035/viewer/2022080720/5f7a22def01c1857826ebafd/html5/thumbnails/21.jpg)
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 22: CS 31: Intro to Systems Course Recapkwebb/cs31/s15/19-Course... · 2015-05-01 · •Combine circuits to create a CPU –Periodic clock: fetch, decode, execute instructions Data in](https://reader035.vdocuments.mx/reader035/viewer/2022080720/5f7a22def01c1857826ebafd/html5/thumbnails/22.jpg)
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 23: CS 31: Intro to Systems Course Recapkwebb/cs31/s15/19-Course... · 2015-05-01 · •Combine circuits to create a CPU –Periodic clock: fetch, decode, execute instructions Data in](https://reader035.vdocuments.mx/reader035/viewer/2022080720/5f7a22def01c1857826ebafd/html5/thumbnails/23.jpg)
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 24: CS 31: Intro to Systems Course Recapkwebb/cs31/s15/19-Course... · 2015-05-01 · •Combine circuits to create a CPU –Periodic clock: fetch, decode, execute instructions Data in](https://reader035.vdocuments.mx/reader035/viewer/2022080720/5f7a22def01c1857826ebafd/html5/thumbnails/24.jpg)
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 25: CS 31: Intro to Systems Course Recapkwebb/cs31/s15/19-Course... · 2015-05-01 · •Combine circuits to create a CPU –Periodic clock: fetch, decode, execute instructions Data in](https://reader035.vdocuments.mx/reader035/viewer/2022080720/5f7a22def01c1857826ebafd/html5/thumbnails/25.jpg)
Multi-threading in Practice (pthreads)
• Not always intuitive to reason about…
• Potential problems
– race conditions
– deadlock
– priority inversion, etc.
• Requires careful synchronization
![Page 26: CS 31: Intro to Systems Course Recapkwebb/cs31/s15/19-Course... · 2015-05-01 · •Combine circuits to create a CPU –Periodic clock: fetch, decode, execute instructions Data in](https://reader035.vdocuments.mx/reader035/viewer/2022080720/5f7a22def01c1857826ebafd/html5/thumbnails/26.jpg)
Next Systems Courses
• Fall 2015 – Networks
• Spring 2016 – Compilers
– Parallel & Distributed
• Fall 2016 – TBD
• Spring 2017 – Databases
![Page 27: CS 31: Intro to Systems Course Recapkwebb/cs31/s15/19-Course... · 2015-05-01 · •Combine circuits to create a CPU –Periodic clock: fetch, decode, execute instructions Data in](https://reader035.vdocuments.mx/reader035/viewer/2022080720/5f7a22def01c1857826ebafd/html5/thumbnails/27.jpg)
Questions?
• Thank you for a great semester!