Presentation is loading. Please wait.

Presentation is loading. Please wait.

CML CML CS 230: Computer Organization and Assembly Language Aviral Shrivastava Department of Computer Science and Engineering School of Computing and Informatics.

Similar presentations


Presentation on theme: "CML CML CS 230: Computer Organization and Assembly Language Aviral Shrivastava Department of Computer Science and Engineering School of Computing and Informatics."— Presentation transcript:

1 CML CML CS 230: Computer Organization and Assembly Language Aviral Shrivastava Department of Computer Science and Engineering School of Computing and Informatics Arizona State University Slides courtesy: Prof. Yann Hang Lee, ASU, Prof. Mary Jane Irwin, PSU, Ande Carle, UCB

2 CML CMLAnnouncements This Lecture: Caches Next Lecture: More Caches, Virtual Memory Finals –Tuesday, Dec 08, 2009 –Please come on time (You’ll need all the time) –Open book, notes, and internet –No communication with any other human

3 CML CML Time, Time, Time Making a Single Cycle Implementation is very easy –Difficulty and excitement is in making it fast Two fundamental methods to make Computers fast –Pipelining –Caches AddressInstruction Memory Write Data Reg Addr Register File ALU Data Memory Address Write Data Read Data PC Read Data Read Data

4 CML CML Kinds of Memory CPU Registers 100s Bytes <10s ns SRAM K Bytes 10-20 ns $.00003/bit DRAM M Bytes 50ns-100ns $.00001/bit Disk G Bytes ms 10 -6 cents Tape infinite sec-min Flipflops SRAM DRAM Disk Tape faster larger

5 CML CML Memory Hierarchy: Insights Temporal Locality (Locality in Time): => Keep most recently accessed data items closer to the processor Spatial Locality (Locality in Space): => Move blocks consists of contiguous words to the upper levels Lower Level Memory Upper Level Memory To Processor From Processor Blk X Blk Y

6 CML CML Memory Hierarchy: Terminology Hit: data appears in some block in the upper level (Block X) –Hit Rate: fraction of memory accesses found in the upper level –Hit Time: Time to access the upper level which consists of RAM access time + Time to determine hit/miss Miss: data needs to be retrieve from a block in the lower level (Block Y) –Miss Rate = 1 - (Hit Rate) –Miss Penalty: Time to replace a block in the upper level + Time to deliver the block the processor –Hit Time << Miss Penalty Lower Level Memory Upper Level Memory To Processor From Processor Blk X Blk Y

7 CML CML Memory Hierarchy: Show me numbers Consider application −30% instructions are load/stores −Suppose memory latency = 100 cycles −Time to execute 100 instructions = 70*1 + 30*100 = 3070 cycles Add a cache with latency 2 cycle −Suppose hit rate is 90% −Time to execute 100 instructions = 70*1 + 27*2 + 3*100 = 70+54+300 = 424 cycles

8 CML CML Direct-Mapped Cache (1/2) In a direct-mapped cache, each memory address is associated with one possible block within the cache –Therefore, we only need to look in a single location in the cache for the data if it exists in the cache –Block is the unit of transfer between cache and memory

9 CML CML Direct-Mapped Cache (2/2) Cache Location 0 can be occupied by data from: –Memory location 0, 4, 8,... –4 blocks => any memory location that is multiple of 4 Memory Memory Address 0 1 2 3 4 5 6 7 8 9 A B C D E F 4 Byte Direct Mapped Cache Cache Index 0 1 2 3

10 CML CML Addressing in Direct-Mapped Cache Since multiple memory addresses map to same cache index, how do we tell which one is in there? What if we have a block size > 1 byte? Answer: divide memory address into three fields ttttttttttttttttt iiiiiiiiii oooo tagindexbyte to checkto offset if have selectwithin correct blockblockblock

11 CML CML Direct-Mapped Cache Terminology All fields are read as unsigned integers. Index: specifies the cache index (which “row” of the cache we should look in) Offset: once we’ve found correct block, specifies which byte within the block we want Tag: the remaining bits after offset and index are determined; these are used to distinguish between all the memory addresses that map to the same location

12 CML CML Direct-Mapped Cache Example (1/3) Suppose we have a 16KB of data in a direct-mapped cache with 4 word blocks Determine the size of the tag, index and offset fields if we’re using a 32-bit architecture Offset –need to specify correct byte within a block –block contains 4 words = 16 bytes = 2 4 bytes –need 4 bits to specify correct byte

13 CML CML Direct-Mapped Cache Example (2/3) Index: (~index into an “array of blocks”) –need to specify correct row in cache –cache contains 16 KB = 2 14 bytes –block contains 2 4 bytes (4 words) –# blocks/cache =bytes/cache bytes/block = 2 14 bytes/cache 2 4 bytes/block =2 10 blocks/cache –need 10 bits to specify this many rows

14 CML CML Direct-Mapped Cache Example (3/3) Tag: use remaining bits as tag –tag length = addr length – offset - index = 32 - 4 - 10 bits = 18 bits –so tag is leftmost 18 bits of memory address Why not full 32 bit address as tag? –All bytes within block need same address (4b) –Index must be same for every address within a block, so it’s redundant in tag check, thus can leave off to save memory (here 10 bits)

15 CML CML TIOTIOTIOTIO AREA (cache size, B) = HEIGHT (# of blocks) * WIDTH (size of one block, B/block) WIDTH (size of one block, B/block) HEIGHT (# of blocks) AREA (cache size, B) 2 (H+W) = 2 H * 2 W Tag Index Offset

16 CML CML Accessing data in a direct mapped cache Ex.: 16KB of data, direct-mapped, 4 word blocks Read 4 addresses 1.0x00000014 2.0x0000001C 3.0x00000034 4.0x00008014 Memory values on right: –only cache/ memory level of hierarchy Address (hex) Value of Word Memory 00000010 00000014 00000018 0000001C a b c d... 00000030 00000034 00000038 0000003C e f g h 00008010 00008014 00008018 0000801C i j k l...

17 CML CML Accessing data in a direct mapped cache 4 Addresses: –0x00000014, 0x0000001C, 0x00000034, 0x00008014 4 Addresses divided (for convenience) into Tag, Index, Byte Offset fields 000000000000000000 0000000001 0100 000000000000000000 0000000001 1100 000000000000000000 0000000011 0100 000000000000000010 0000000001 0100 Tag Index Offset

18 CML CML 16 KB Direct Mapped Cache, 16B blocks Valid bit: determines whether anything is stored in that row (when computer initially turned on, all entries invalid)... Valid Tag 0x0-3 0x4-70x8-b0xc-f 0 1 2 3 4 5 6 7 1022 1023... Index 0 0 0 0 0 0 0 0 0 0

19 CML CML 1. Read 0x00000014... Valid Tag 0x0-3 0x4-70x8-b0xc-f 0 1 2 3 4 5 6 7 1022 1023... 000000000000000000 0000000001 0100 Index Tag fieldIndex fieldOffset 0 0 0 0 0 0 0 0 0 0

20 CML CML So we read block 1 (0000000001)... Valid Tag 0x0-3 0x4-70x8-b0xc-f 0 1 2 3 4 5 6 7 1022 1023... 000000000000000000 0000000001 0100 Index Tag fieldIndex fieldOffset 0 0 0 0 0 0 0 0 0 0

21 CML CML No valid data... Valid Tag 0x0-3 0x4-70x8-b0xc-f 0 1 2 3 4 5 6 7 1022 1023... 000000000000000000 0000000001 0100 Index Tag fieldIndex fieldOffset 0 0 0 0 0 0 0 0 0 0

22 CML CML Load data into cache, setting tag & valid... Valid Tag 0x0-3 0x4-70x8-b0xc-f 0 1 2 3 4 5 6 7 1022 1023... 1 0abcd 000000000000000000 0000000001 0100 Index Tag fieldIndex fieldOffset 0 0 0 0 0 0 0 0 0

23 CML CML Read from cache at offset, return word b 000000000000000000 0000000001 0100... Valid Tag 0x0-3 0x4-70x8-b0xc-f 0 1 2 3 4 5 6 7 1022 1023... 1 0abcd Index Tag fieldIndex fieldOffset 0 0 0 0 0 0 0 0 0

24 CML CML 2. Read 0x0000001C = 0…00 0..001 1100... Valid Tag 0x0-3 0x4-70x8-b0xc-f 0 1 2 3 4 5 6 7 1022 1023... 1 0abcd 000000000000000000 0000000001 1100 Index Tag fieldIndex fieldOffset 0 0 0 0 0 0 0 0 0

25 CML CML Index is Valid... Valid Tag 0x0-3 0x4-70x8-b0xc-f 0 1 2 3 4 5 6 7 1022 1023... 1 0abcd 000000000000000000 0000000001 1100 Index Tag fieldIndex fieldOffset 0 0 0 0 0 0 0 0 0

26 CML CML Index valid, Tag Matches... Valid Tag 0x0-3 0x4-70x8-b0xc-f 0 1 2 3 4 5 6 7 1022 1023... 1 0abcd 000000000000000000 0000000001 1100 Index Tag fieldIndex fieldOffset 0 0 0 0 0 0 0 0 0

27 CML CML Index Valid, Tag Matches, return d... Valid Tag 0x0-3 0x4-70x8-b0xc-f 0 1 2 3 4 5 6 7 1022 1023... 1 0abcd 000000000000000000 0000000001 1100 Index Tag fieldIndex fieldOffset 0 0 0 0 0 0 0 0 0

28 CML CML 3. Read 0x00000034 = 0…00 0..011 0100... Valid Tag 0x0-3 0x4-70x8-b0xc-f 0 1 2 3 4 5 6 7 1022 1023... 1 0abcd 000000000000000000 0000000011 0100 Index Tag fieldIndex fieldOffset 0 0 0 0 0 0 0 0 0

29 CML CML So read block 3... Valid Tag 0x0-3 0x4-70x8-b0xc-f 0 1 2 3 4 5 6 7 1022 1023... 1 0abcd 000000000000000000 0000000011 0100 Index Tag fieldIndex fieldOffset 0 0 0 0 0 0 0 0 0

30 CML CML No valid data... Valid Tag 0x0-3 0x4-70x8-b0xc-f 0 1 2 3 4 5 6 7 1022 1023... 1 0abcd 000000000000000000 0000000011 0100 Index Tag fieldIndex fieldOffset 0 0 0 0 0 0 0 0 0

31 CML CML Load that cache block, return word f... Valid Tag 0x0-3 0x4-70x8-b0xc-f 0 1 2 3 4 5 6 7 1022 1023... 1 0abcd 000000000000000000 0000000011 0100 1 0efgh Index Tag fieldIndex fieldOffset 0 0 0 0 0 0 0 0

32 CML CML A Direct Mapped Cache for MIPS What is the block size –32-bits, 4 bytes How many blocks in cache –1024 How long is index –10-bits How many blocks in memory –2^32/4 = 2^30 How many memory blocks map to the same cache block –2^30/1024 = 2^20 How long is tag –20-bits

33 CML CML Yoda says… You will find only what you bring in


Download ppt "CML CML CS 230: Computer Organization and Assembly Language Aviral Shrivastava Department of Computer Science and Engineering School of Computing and Informatics."

Similar presentations


Ads by Google