Perkembangan teknologi dan organisasi CPU jauh lebih cepat dari memori Dalam kurun waktu: 1980 2000
Terdapat gap yang semakin lebar antara CPU dan memory. Teknologi memori/storages: Cepat => kapasitas kecil dan mahal. Kapasitas besar dan murah => lambat. Solusi: Cache memory => fast, small memory system (SRAM) antara CPU dan main memory. Tahun 1980: IBM PC (8086) tanpa cache memory Tahun 2004: Pentium 4, L1 cache: 8 KB/96KB, L2 on-chip cache: 512 KB (P4 Xeon: L3 on-chip cache: 1 MB).
OSK/JM-2003/V1.1/2
cache
virtual memory
C a c h e
Memory Bus
Memory Memory
I/O Bus
disk disk
Q1: Where can a block be placed in the upper level? (Block placement) Q2: How is a block found if it is in the upper level?(Block identification) Q3: Which block should be replaced on a miss? (Block replacement) Q4: What happens on a write? (Write strategy) Rujukan: P&H; Bab 5.2 (Hal. 375) Baca Rujukan!!!.
OSK/JM-2003/V1.1/6
OSK/JM-2003/V1.1/5
Memory
Set associative: block 12 dapat menempati pada blok mana saja dari set 0 (12 mod 4) 01234567
01234567
01234567
Block-frame address
Block no.
1111111111222222222233 01234567890123456789012345678901
OSK/JM-2003/V1.1/7
0 1 2 3 4 5 6 7 8 9 A B C D E F
Cache Index 0 1 2 3
Direct Map Cache Lokasi blok 0 pada cache ditempati oleh: Lokasi memory blok: 0, 4, 8, ... Secara umum lokasi nomor blok memory kelipatan 4 (mod 4).
OSK/JM-2003/V1.1/8
Direct-Mapped Cache Example (1/3) Misalkan cache memory: Besar 16 KB direct mapped, dengan ukuran blok 4 word (1 word = 32 bits arsitektur). Tentukan ukuran tag, index, dan offset (field)!!! Offset Diperlukan untuk menentukan byte mana pada blok yang akan diakses. Setiap blok 4 words = 16 bytes = 24 bytes.
Jadi diperlukan 4 bits offset utk identifikasi byte pada suatu blok (16 bytes).
OSK/JM-2003/V1.1/11
Direct-Mapped Cache Example (2/3) Index: (~index memilih dari array of blocks) Diperlukan untuk identifikasi nomor/lokasi blok pada cache. Besarnya cache 16 KB = 214 bytes Besarnya blok: 24 bytes (4 words) Jumlah blok/cache:
= = 214 bytes/cache 24 bytes/block 210 blocks/cache
Direct-Mapped Cache Example (3/3) Tag: Gunakan sisa bits sebagai tag tag length = addr length offset - index = 32 - 4 - 10 bits = 18 bits Jadi tag: leftmost 18 bits dari alamat memory
cache hit: cache block is valid and contains proper address, so read desired word cache miss: nothing in cache in appropriate block, so fetch from memory cache miss, block replacement: wrong data is in cache at appropriate block, so discard it and fetch desired data from memory (cache always copy)
OSK/JM-2003/V1.1/14
2.
18 bits
tag to check if have correct block
10 bits
index to select block
4 bits
byte offset within block
OSK/JM-2003/V1.1/13
3.
Accessing data in a direct mapped cache 4 Addresses: 0x00000014, 0x0000001C, 0x00000034, 0x00008014 Contoh: alamat tsb dalam bentuk field: Tag (18 bits), Index (10 bits), Byte Offset fields (4 bits)
000000000000000000 0000000001 0100 000000000000000000 0000000001 1100 000000000000000000 0000000011 0100 000000000000000010 0000000001 0100 Tag Index Offset
OSK/JM-2003/V1.1/16
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
Memory
Address (hex)Value of Word ... ... a 00000010 b 00000014 c 00000018 d 0000001C ... ... e 00000030 f 00000034 g 00000038 h 0000003C ... ... i 00008010 j 00008014 k 00008018 l 0000801C ... ... OSK/JM-2003/V1.1/15
16 KB Direct Mapped Cache, 16B blocks Valid bit: set saat copy blok memory, Note: 32 bits arsitektur (words= 4 bytes) => Valid Index Tag 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0
... 0x0-3 => 4 bytes dari word pertama
1. Read 0x00000014
000000000000000000 0000000001 0100
0x0-3
0x4-7
0x8-b
0xc-f
...
...
1022 0 1023 0
OSK/JM-2003/V1.1/17
1022 0 1023 0
OSK/JM-2003/V1.1/18
...
...
1022 0 1023 0
OSK/JM-2003/V1.1/19
1022 0 1023 0
OSK/JM-2003/V1.1/20
0x8-b
c
0xc-f
d
0x8-b
c
0xc-f
d
...
...
1022 0 1023 0
OSK/JM-2003/V1.1/21
1022 0 1023 0
OSK/JM-2003/V1.1/22
Index is Valid
000000000000000000 0000000001 1100
Offset 0xc-f
d
0x8-b
c
Offset 0xc-f
d
0x8-b
c
...
...
1022 0 1023 0
OSK/JM-2003/V1.1/23
1022 0 1023 0
OSK/JM-2003/V1.1/24
Offset 0xc-f
d
0x8-b
c
Offset 0xc-f
d
0x8-b
c
...
...
1022 0 1023 0
OSK/JM-2003/V1.1/25
1022 0 1023 0
OSK/JM-2003/V1.1/26
So read block 3
000000000000000000 0000000011 0100
...
1022 0 1023 0
OSK/JM-2003/V1.1/27
1022 0 1023 0
OSK/JM-2003/V1.1/28
No valid data
000000000000000000 0000000011 0100
...
...
1022 0 1023 0
OSK/JM-2003/V1.1/29
1022 0 1023 0
OSK/JM-2003/V1.1/30
...
1022 0 1023 0
OSK/JM-2003/V1.1/31
1022 0 1023 0
OSK/JM-2003/V1.1/32
1022 0 1023 0
OSK/JM-2003/V1.1/33
1022 0 1023 0
OSK/JM-2003/V1.1/34
Cache memory => managed by hardware (chipsets) Manajemen dan transfer blok data antara main memory dan cache memory. Efisien dan cepat => simple is faster. Direct Mapped: cara sederhana rancangan cache, dengan membagi alamat memory => 3 field, yang tetap yakni:
Offset => tergantung besarnya blok (block size) dari cache Index => tergantung jumlah blok pada cache (cache size / block size) Tag => sisa bits (leftmost).
1022 0 1023 0
OSK/JM-2003/V1.1/35
OSK/JM-2003/V1.1/36