Anda di halaman 1dari 6

Rekap: Technology Memory

Perkembangan teknologi dan organisasi CPU jauh lebih cepat dari memori Dalam kurun waktu: 1980 2000

Review: Dasar Cache Memory

Peningkatan kecepatan DRAM memory access: 6x CPU cycle time: 750x

IKI 30210: Organisasi Sistim Komputer


Johny Moningka (moningka@cs.ui.ac.id),
Fakultas Ilmu Komputer Universitas Indonesia

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

Rekap: Memory Hirarkis


Pengamatan sifat program: Tidak semua kode/data program mempunyai kemungkinan yang sama diakses oleh CPU Program menganut prinsip lokalitas: temporal dan spatial BIG IDEA: Memori hirarkis adalah pilihan terbaik dalam menyediakan sistim memori yang cepat dengan kapasitas besar dan cost yang termurah Caching merupakan prinsip umum manajemen storages mendukung memori hirarkis. Penulisan program => menganut prinsip lokalitas supaya kinerja lebih cepat memanfaatkan memori hirarkis.
OSK/JM-2003/V1.1/3

Memory Technology: implementation

cache

virtual memory

CPU CPU regs regs

C a c h e

Memory Bus

Memory Memory
I/O Bus

disk disk

Register size: speed: $/Mbyte: 500 B 0.25 ns

Cache 64 KB 1 - 10 ns $20/MB SRAM

Memory 512 MB 20 60 ns $ 0.175/MB ($90/512MB) SDRAM

Disk Memory 120 GB 5.000.000 ns $0.00075/MB ($90/120GB)

larger, slower, cheaper


Source: CAQA, Harga: http://bhinneka.com (Juni, 2004)
OSK/JM-2003/V1.1/4

Accessing Data in Cache


Kapasitas memory kedua level dibagi atas: blok, yg sama besar Ukuran blok: tipikal 2x s/d 16x word size. Data dipindahkan sesuai dengan kebutuhan, dan dalam kelompok blok (block-sized chunks). Upper-level blocks a subset of lower-level blocks (copy)
Access word w in block a (hit) w High Level a a a b b Low Level b a a b a b Access word v in block b (miss) v

Four Questions for Caches and Memory Hierarchy

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

Q1: Where can a block be placed in the upper level?


Contoh: Kemungkinan Blok 12 dari memory berada pada cache dengan jumlah blok: 8
Direct mapped: block 12 hanya dapat menempati blok 4 (12 mod 8)
Block no.

Q2: How is a block found if it is in the upper level?


Block Memory Address

Memory

Fully associative: block 12 dapat menempati di mana saja


Block no. Block no.

Set associative: block 12 dapat menempati pada blok mana saja dari set 0 (12 mod 4) 01234567

01234567

01234567

Block-frame address

Set Set Set Set 0 1 2 3

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

4 Byte Direct Mapped Cache

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

Finding block in cache: Direct-Mapped


Sebab lebih dari satu nomor blok memory dapat menempati suatu blok pada cache, Bagaimana kita dapat mengetahui (identifikasi) nomor blok memory mana yang berada di cache? Memory byte addressable! Bagaimana kita dapat mengetahui byte mana yang akan diambil pada blok tersebut (ukuran blok > 1 byte)? Answer: divide memory address into three fields

Direct-Mapped Cache Terminology


Semua fields => unsigned integers Index: merupakan indeks blok cache (blok mana pada cache) Offset: setelah menentukan blok pada cache, offset menentukan byte mana pada blok yang akan diakses Tag: sisa dari bits setelah offset dan index ditentukan; digunakan untuk membedakan antara blok-blok pada main memory yang dipetakan (mapping) pada blok yang sama di cache memory.
OSK/JM-2003/V1.1/10

ttttttttttttttttt iiiiiiiiii oooo


tag to check if have correct block index to select block byte offset within block
OSK/JM-2003/V1.1/9

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

Perlu 10 bits untuk menentukan nomor blok


OSK/JM-2003/V1.1/12

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

Caching Terminology When we try to read memory, 3 things can happen:


1.

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.

Example: Accessing data in a direct mapped cache

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

Valid Index Tag 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0


...

Tag field 0x0-3 0x4-7

Index field Offset 0x8-b 0xc-f

...

...

1022 0 1023 0
OSK/JM-2003/V1.1/17

1022 0 1023 0
OSK/JM-2003/V1.1/18

So we read block 1 (0000000001)


000000000000000000 0000000001 0100

No valid data pada cache!


000000000000000000 0000000001 0100

Valid Index Tag 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0


...

Tag field 0x0-3 0x4-7

Index field Offset 0x8-b 0xc-f

Valid Index Tag 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0


...

Tag field 0x0-3 0x4-7

Index field Offset 0x8-b 0xc-f

...

...

1022 0 1023 0
OSK/JM-2003/V1.1/19

1022 0 1023 0
OSK/JM-2003/V1.1/20

So load that data into cache, setting tag, valid


000000000000000000 0000000001 0100

Read from cache at offset, return word b


000000000000000000 0000000001 0100

Valid Index Tag 0 0 1 1 0 2 0 3 0 4 0 5 0 6 0 7 0


...

Tag field 0x0-3


a

Index field Offset 0x4-7


b

0x8-b
c

0xc-f
d

Valid Index Tag 0 0 1 1 0 2 0 3 0 4 0 5 0 6 0 7 0


...

Tag field 0x0-3


a

Index field Offset 0x4-7


b

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

2. Read 0x0000001C = 000 0..001 1100


000000000000000000 0000000001 1100

Index is Valid
000000000000000000 0000000001 1100

Valid Index Tag 0 0 1 1 0 2 0 3 0 4 0 5 0 6 0 7 0


...

Tag field 0x0-3


a

Index field 0x4-7


b

Offset 0xc-f
d

0x8-b
c

Valid Index Tag 0 0 1 1 0 2 0 3 0 4 0 5 0 6 0 7 0


...

Tag field 0x0-3


a

Index field 0x4-7


b

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

Index valid, Tag Matches


000000000000000000 0000000001 1100

Index Valid, Tag Matches, return d


000000000000000000 0000000001 1100

Valid Index Tag 0 0 1 1 0 2 0 3 0 4 0 5 0 6 0 7 0


...

Tag field 0x0-3


a

Index field 0x4-7


b

Offset 0xc-f
d

0x8-b
c

Valid Index Tag 0 0 1 1 0 2 0 3 0 4 0 5 0 6 0 7 0


...

Tag field 0x0-3


a

Index field 0x4-7


b

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

3. Read 0x00000034 = 000 0..011 0100 000000000000000000 0000000011 0100

So read block 3
000000000000000000 0000000011 0100

Tag field Valid 0x0-3 Index Tag 0 0 a 1 1 0 2 0 3 0 4 0 5 0 6 0 7 0


... ...

Index field Offset 0x4-7 0x8-b 0xc-f


b c d

Valid Index Tag 0 0 1 1 0 2 0 3 0 4 0 5 0 6 0 7 0


...

Tag field 0x0-3


a

Index field Offset 0x4-7 0x8-b 0xc-f


b c d

...

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

Load that cache block, return word f


000000000000000000 0000000011 0100

Valid Index Tag 0 0 1 1 0 2 0 3 0 4 0 5 0 6 0 7 0


...

Tag field 0x0-3


a

Index field Offset 0x4-7 0x8-b 0xc-f


b c d

Valid Index Tag 0 0 1 1 0 2 0 3 1 0 4 0 5 0 6 0 7 0


...

Tag field 0x0-3


a e

Index field Offset 0x4-7 0x8-b 0xc-f


b f c g d h

...

...

1022 0 1023 0
OSK/JM-2003/V1.1/29

1022 0 1023 0
OSK/JM-2003/V1.1/30

4. Read 0x00008014 = 010 0..001 0100 000000000000000010 0000000001 0100

So read Cache Block 1, Data is Valid


000000000000000010 0000000001 0100

Tag field Valid 0x0-3 Index Tag 0 0 a 1 1 0 2 0 e 3 1 0 4 0 5 0 6 0 7 0


... ...

Index field Offset 0x4-7 0x8-b 0xc-f


b f c g d h

Valid Index Tag 0 0 1 1 0 2 0 3 1 0 4 0 5 0 6 0 7 0


...

Tag field 0x0-3


a e

Index field Offset 0x4-7 0x8-b 0xc-f


b f c g d h

...

1022 0 1023 0
OSK/JM-2003/V1.1/31

1022 0 1023 0
OSK/JM-2003/V1.1/32

Cache Block 1 Tag does not match (0 != 2)


000000000000000010 0000000001 0100

Miss, so replace block 1 with new data & tag


000000000000000010 0000000001 0100

Tag field Valid 0x0-3 Index Tag 0 0 a 1 1 0 2 0 e 3 1 0 4 0 5 0 6 0 7 0


... ...

Index field Offset 0x4-7 0x8-b 0xc-f


b f c g d h

Tag field Valid 0x0-3 Index Tag 0 0 i 1 1 2 2 0 e 3 1 0 4 0 5 0 6 0 7 0


... ...

Index field Offset 0x4-7 0x8-b 0xc-f


j f k g l h

1022 0 1023 0
OSK/JM-2003/V1.1/33

1022 0 1023 0
OSK/JM-2003/V1.1/34

And return word j


000000000000000010 0000000001 0100

Summary Index field Offset 0x4-7 0x8-b 0xc-f


j f k g l h

Tag field Valid 0x0-3 Index Tag 0 0 i 1 1 2 2 0 e 3 1 0 4 0 5 0 6 0 7 0


... ...

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

Anda mungkin juga menyukai