Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

CS 354 - Machine Organization

Friday, October 14, 2016

Project p3 (6%) due 10 pm Monday, October 24th (exam week)


Homework hw4 (1.5%) due 10 pm TODAY Friday, October 14th
Homework hw5 (1.5%) assigned Monday, due 10 pm Friday, October 21st
Midterm Exam Thursday October 27th, 7:15 - 9:15 pm
makeup requests handled by early next week
Last Time
Locality (from last time)
Memory Hierarchies (from last time)
Processor Layout
Cache Idea & Terms
Today
Designing a Cache
 blocks
 sets & tags
 lines
Basic Cache Operation
Next Time
Read: B&O 6.4.3 - 6.4.5
Varying Set Size
Writing to Caches

Copyright 2016 Jim Skrentny

CS 354 (F16): L17 - 1

Designing a Cache - Blocks

Cache memory is much, much smaller than the address space of the processor.

 Implications?

 How do we map the entire AS to particular blocks in the cache?

1.) How big is a block?

32-bit Address
24
bit 31

16

 Given a specific address, how do we find a particular word in the block?

How many blocks of memory for a 32-bit AS?

How many blocks in a cache?


cache size
32KB
256KB
8MB

number of 32 byte blocks

 How many blocks results in an effective cache???

Copyright 2016 Jim Skrentny

CS 354 (F16): L17 - 2

Designing a Cache - Sets & Tags

Using a random placement policy makes finding a block in the cache SLOW!

 Why?

2.) How many sets in the cache?

32-bit Address
24
bit 31

16

b bits

 Given a specific address, how do we know which set to look in?

 How many blocks of memory map to each set for a 32-bit AS with 256 sets? 1024?

 Implications?

3.) How do we identify which block is in a set?

32-bit Address
24
bit 31

16

s bits

Copyright 2016 Jim Skrentny

b bits

CS 354 (F16): L17 - 3

Designing a Cache - Lines


What?

SET 0 (s bits)
TAG (t bits)

BLOCK OF MEMORY (size B = 2b, b bits)

TAG

BLOCK OF MEMORY

SET 1

...
SET S-1 (size S = 2s)
TAG

BLOCK OF MEMORY

 How do you know if a line in the cache is used or not?

 How big is a cache given S sets with blocks having B bytes?

Copyright 2016 Jim Skrentny

CS 354 (F16): L17 - 4

Basic Cache Operation

SET 0
V

TAG (17 bits)

BLOCK OF MEMORY (25 = 32 bytes)

TAG

BLOCK OF MEMORY

SET 1
V

...
SET 1023 = 210 - 1
V

TAG

BLOCK OF MEMORY

How does a cache process a request for a word at a particular address?


1. Set Selection

2. Line Matching

32-bit Address
24
bit 31

t bits

16

s bits

b bits

if no match

if match

Copyright 2016 Jim Skrentny

CS 354 (F16): L17 - 5

Project p3
Directory Structure
p3 Directory
mem.c, mem.h, mem.o, Makefile
tests Subdirectory
align2.c, ..., Makefile, ..., testlist.txt, ...
Implicit Free List Structure
word (4 bytes) aligned NOT double word
singly linked list of free and allocd blocks NOT just free blocks
list_head global stores address of first block
block layout: next, size_status, payload, possibly padding
NOTE: size excludes header, status is 0 = free, 1 = allocd
For example: if payload is 1 character (1 byte)
size is 4 bytes = payload 1 byte + 3 bytes padding
block total is 12 bytes with header (next and size_status)
if free then size_status is 4, if allocated then size_status is 5 = size 4 + 1 for allocd
Operations
Mem_free() must verify pointer is to an allocated block (search required)
splitting adds blocks to linked list
coalescing removes 1 or 2 blocks from linked list
Debugging
develop code incrementally using our tests
see testlist.txt (if test fails - add Mem_dump() to our test code)
our tests are not exhaustive!
use printf within your mem.c
Use gdb to Find Segmentation Faults
make
gdb alloc
help
run
kill
where
frame...
list
print...
break...
quit

Copyright 2016 Jim Skrentny

CS 354 (F16): L17 - 6

You might also like