34
CMSC 313 Lecture 26 • DigSim Assignment 3 • Cache Memory • Virtual Memory + Cache Memory • I/O Architecture UMBC, CMSC313, Richard Chang <[email protected]>

•DigSim Assignment 3 •Cache Memory •Virtual Memory + …chang/cs313.f04/topics/Slides26.pdfVirtual Memory + Cache Memory 1.CPU instruction generates a virtual address. 2.Translation

  • Upload
    others

  • View
    9

  • Download
    0

Embed Size (px)

Citation preview

Page 1: •DigSim Assignment 3 •Cache Memory •Virtual Memory + …chang/cs313.f04/topics/Slides26.pdfVirtual Memory + Cache Memory 1.CPU instruction generates a virtual address. 2.Translation

CMSC 313 Lecture 26

• DigSim Assignment 3

• Cache Memory• Virtual Memory + Cache Memory

• I/O Architecture

UMBC, CMSC313, Richard Chang <[email protected]>

Page 2: •DigSim Assignment 3 •Cache Memory •Virtual Memory + …chang/cs313.f04/topics/Slides26.pdfVirtual Memory + Cache Memory 1.CPU instruction generates a virtual address. 2.Translation

CMSC 313, Computer Organization & Assembly Language Programming Section 0101Fall 2004

DigSim Assignment 3: Finite State Machine SimplificationsDue: Tuesday, December 14, 2004

ObjectiveThe objective is to design and simplify a moderately complex a finite state machine.

AssignmentYou have already completed the design and simplification steps in Homework 5. Your assignment

here is to implement the finite state machine you designed in Question #5 of Homework 5. You should use the state assignment and flip-flop selection that uses the smallest total number of gates. Note that the gates used for the output z might be different for different state assignments.

What to submit1) If the finite state machine you implemented differs significantly from the one you turned in

for Homework 5, then submit the transition diagram, truth tables and formulas you used to implement this finite state machine in class on Tuesday, December 14.

2) Save your circuit as you did in DigSim Assignment 1. Submit the circuit file using the Unix submit command as in previous assignments. The submission name for this assignment is: digsim3. The UNIX command to do this should look something like:

submit cs313_0101 digsim3 d3.sim

Page 3: •DigSim Assignment 3 •Cache Memory •Virtual Memory + …chang/cs313.f04/topics/Slides26.pdfVirtual Memory + Cache Memory 1.CPU instruction generates a virtual address. 2.Translation

Last Time

• Memory Organization

• Technological advances in DRAM

• SDRAM allows quick access to successive memory locations in the same row.

Why is this helpful??

UMBC, CMSC313, Richard Chang <[email protected]>

Page 4: •DigSim Assignment 3 •Cache Memory •Virtual Memory + …chang/cs313.f04/topics/Slides26.pdfVirtual Memory + Cache Memory 1.CPU instruction generates a virtual address. 2.Translation

Chapter 7: Memory7-3

Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring

The Memory Hierarchy

Registers

Cache

Main memory

Secondary storage (disks)

Off-line storage (tape)

Fast and expensive

Slow and inexpensive

Increasing performance andincreasing cost

Page 5: •DigSim Assignment 3 •Cache Memory •Virtual Memory + …chang/cs313.f04/topics/Slides26.pdfVirtual Memory + Cache Memory 1.CPU instruction generates a virtual address. 2.Translation

Chapter 7: Memory7-14

Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring

Placement of Cache in a ComputerSystem

CPU400 MHz

MainMemory10 MHz

Bus 66 MHz

MainMemory10 MHz

Bus 66 MHz

CPU

Cache

400 MHz

Without cache With cache

• The locality principle : a recently referenced memory location islikely to be referenced again ( temporal locality ); a neighbor of arecently referenced memory location is likely to be referenced(spatial locality ).

Page 6: •DigSim Assignment 3 •Cache Memory •Virtual Memory + …chang/cs313.f04/topics/Slides26.pdfVirtual Memory + Cache Memory 1.CPU instruction generates a virtual address. 2.Translation

Chapter 7: Memory7-15

Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring

An Associative Mapping Scheme for aCache Memory

Slot 0

Slot 1

Slot 2

Slot 214–1

.

.

.

.

.

.

Block 0

Block 1

Block 128

Block 129

Block 227–1

Cache Memory

Main Memory

TagValid Dirty

32 words per block

27

.

.

.

Page 7: •DigSim Assignment 3 •Cache Memory •Virtual Memory + …chang/cs313.f04/topics/Slides26.pdfVirtual Memory + Cache Memory 1.CPU instruction generates a virtual address. 2.Translation

Chapter 7: Memory7-16

Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring

Associative Mapping Example• Consider how an access to memory location (A035F014) 16 is

mapped to the cache for a 2 32 word memory. The memory is di-vided into 2 27 blocks of 2 5 = 32 words per block, and the cacheconsists of 2 14 slots:

27 bits 5 bits

Tag Word

Tag Word

1 0 1 0 0 0 0 0 0 0 1 1 0 1 0 1 1 1 1 1 0 0 0 0 0 0 0 1 0 1 0 0

• If the addressed word is in the cache, it will be found in word (14) 16of a slot that has tag (501AF80) 16, which is made up of the 27 mostsignificant bits of the address. If the addressed word is not in thecache, then the block corresponding to tag field (501AF80) 16 isbrought into an available slot in the cache from the main memory,and the memory reference is then satisfied from the cache.

Page 8: •DigSim Assignment 3 •Cache Memory •Virtual Memory + …chang/cs313.f04/topics/Slides26.pdfVirtual Memory + Cache Memory 1.CPU instruction generates a virtual address. 2.Translation

Chapter 7: Memory7-17

Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring

Replacement Policies• When there are no available slots in which to place a block, a re-

placement policy is implemented. The replacement policy gov-erns the choice of which slot is freed up for the new block.

• Replacement policies are used for associative and set-associativemapping schemes, and also for virtual memory.

• Least recently used (LRU)

• First-in/first-out (FIFO)

• Least frequently used (LFU)

• Random

• Optimal (used for analysis only – look backward in time and re-verse-engineer the best possible strategy for a particular se-quence of memory references.)

Page 9: •DigSim Assignment 3 •Cache Memory •Virtual Memory + …chang/cs313.f04/topics/Slides26.pdfVirtual Memory + Cache Memory 1.CPU instruction generates a virtual address. 2.Translation

Chapter 7: Memory7-18

Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring

A Direct Mapping Scheme for CacheMemory

Slot 0

Slot 1

Slot 2

Slot 214–1

.

..

.

.

.

.

.

.

Block 0

Block 1

Block 2

Block 2

Block 227

+1

Cache Memory

Main Memory

TagValid Dirty

32 words per block

13

14

14

Page 10: •DigSim Assignment 3 •Cache Memory •Virtual Memory + …chang/cs313.f04/topics/Slides26.pdfVirtual Memory + Cache Memory 1.CPU instruction generates a virtual address. 2.Translation

Chapter 7: Memory7-19

Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring

Direct Mapping Example• For a direct mapped cache, each main memory block can be

mapped to only one slot, but each slot can receive more than oneblock. Consider how an access to memory location (A035F014) 16is mapped to the cache for a 2 32 word memory. The memory is di-vided into 2 27 blocks of 2 5 = 32 words per block, and the cacheconsists of 2 14 slots:

• If the addressed word is in the cache, it will be found in word (14) 16of slot (2F80) 16, which will have a tag of (1406) 16.

13 bits 5 bits14 bits

Tag WordSlot

Tag Word

1 0 1 0 0 0 0 0 0 0 1 1 0 1 0 1 1 1 1 1 0 0 0 0 0 0 0 1 0 1 0 0

Slot

Page 11: •DigSim Assignment 3 •Cache Memory •Virtual Memory + …chang/cs313.f04/topics/Slides26.pdfVirtual Memory + Cache Memory 1.CPU instruction generates a virtual address. 2.Translation

Chapter 7: Memory7-20

Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring

A Set Associative Mapping Schemefor a Cache Memory

Slot 0

Slot 1

Slot 2

Slot 214–1

.

.

.

.

.

.

.

.

.

Block 0

Block 1

Block 213

Block 213+1

Block 227–1

Cache

Main Memory

TagValid Dirty

32 words per block

Set 0

Set 1

Set 213–1

14

Page 12: •DigSim Assignment 3 •Cache Memory •Virtual Memory + …chang/cs313.f04/topics/Slides26.pdfVirtual Memory + Cache Memory 1.CPU instruction generates a virtual address. 2.Translation

Chapter 7: Memory7-21

Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring

Set-Associative Mapping Example• Consider how an access to memory location (A035F014) 16 is

mapped to the cache for a 2 32 word memory. The memory is di-vided into 2 27 blocks of 2 5 = 32 words per block, there are twoblocks per set, and the cache consists of 2 14 slots:

• The leftmost 14 bits form the tag field, followed by 13 bits for theset field, followed by five bits for the word field:

Tag WordSet

14 bits 5 bits13 bits

Tag Word

1 0 1 0 0 0 0 0 0 0 1 1 0 1 0 1 1 1 1 1 0 0 0 0 0 0 0 1 0 1 0 0

Set

Page 13: •DigSim Assignment 3 •Cache Memory •Virtual Memory + …chang/cs313.f04/topics/Slides26.pdfVirtual Memory + Cache Memory 1.CPU instruction generates a virtual address. 2.Translation

Chapter 7: Memory7-22

Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring

Cache Read and Write Policies Cache

Read Cache

Write

Data is in the cache

Data is not in the cache

Data is in the cache

Data is not in the cache

Forward to CPU.

Write Through: Write data to both cache and main memory,

Write Back: Write data to cache only. Defer main memory write until block is flushed.

Load Through: Forward the word as cache line is filled, -or- Fill cache line and then forward word.

Write Allocate: Bring line into cache, then update it, -or- Write No-AllocatUpdate main memory only.

-or-

Page 14: •DigSim Assignment 3 •Cache Memory •Virtual Memory + …chang/cs313.f04/topics/Slides26.pdfVirtual Memory + Cache Memory 1.CPU instruction generates a virtual address. 2.Translation

Virtual Memory + Cache Memory

1. CPU instruction generates a virtual address.

2. Translation Lookaside Buffer (TLB) used to locate recently accessed page frames.

3. In case of a TLB miss, use page table(s) to find page frame for virtual address. TLB updated.Note: page frame may have been swapped to disk!

4. Virtual address is now converted into a physical address.

5. Search cache for recently accessed physical addresses.

6. In case of a cache miss, use main memory. Cache updated.

UMBC, CMSC313, Richard Chang <[email protected]>

Page 15: •DigSim Assignment 3 •Cache Memory •Virtual Memory + …chang/cs313.f04/topics/Slides26.pdfVirtual Memory + Cache Memory 1.CPU instruction generates a virtual address. 2.Translation

Input/Output

UMBC, CMSC313, Richard Chang <[email protected]>

Page 16: •DigSim Assignment 3 •Cache Memory •Virtual Memory + …chang/cs313.f04/topics/Slides26.pdfVirtual Memory + Cache Memory 1.CPU instruction generates a virtual address. 2.Translation

Basic Issues in I/O

• Allow many components to communicate.

• Do not want to have n2/2 connections to connectn components together.

• Devices communicate a different speeds.

• Some devices transfer lots of data, others very few.

UMBC, CMSC313, Richard Chang <[email protected]>

Page 17: •DigSim Assignment 3 •Cache Memory •Virtual Memory + …chang/cs313.f04/topics/Slides26.pdfVirtual Memory + Cache Memory 1.CPU instruction generates a virtual address. 2.Translation

Chapter 8: Input and Output8-18

Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring

A Magnetic Disk with Three Platters

Direction ofarm (comb)

motion

Surface 3Surface 2

Surface 1Surface 0

Top surface not used

Bottom surface not used

Spindle

Platter

Head

SurfaceAir cushion

5 µ m

Comb

Read/write head(1 per surface)

Page 18: •DigSim Assignment 3 •Cache Memory •Virtual Memory + …chang/cs313.f04/topics/Slides26.pdfVirtual Memory + Cache Memory 1.CPU instruction generates a virtual address. 2.Translation

Chapter 8: Input and Output8-22

Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring

Magnetic Tape• A portion of a magnetic tape (adapted from [Hamacher, 1990]).

File mark

Record

Inter-record gap

Record Record

File

Frames

Page 19: •DigSim Assignment 3 •Cache Memory •Virtual Memory + …chang/cs313.f04/topics/Slides26.pdfVirtual Memory + Cache Memory 1.CPU instruction generates a virtual address. 2.Translation

Chapter 8: Input and Output8-28

Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring

Mouse and Trackball• A three-button mouse (left) and a three-button trackball (right).

To host

Mousepad (improves traction) Trackball

Mouse

Buttons

To host

Buttons

Page 20: •DigSim Assignment 3 •Cache Memory •Virtual Memory + …chang/cs313.f04/topics/Slides26.pdfVirtual Memory + Cache Memory 1.CPU instruction generates a virtual address. 2.Translation

System Bus Issues

• Only n connections needed for n components.

• Bus can become a performance bottleneck.

• Synchronous vs asynchronous

• Bus arbitration.

UMBC, CMSC313, Richard Chang <[email protected]>

Page 21: •DigSim Assignment 3 •Cache Memory •Virtual Memory + …chang/cs313.f04/topics/Slides26.pdfVirtual Memory + Cache Memory 1.CPU instruction generates a virtual address. 2.Translation

Chapter 8: Input and Output8-3

Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring

Simple Bus Architecture• A simplified motherboard of a personal computer (top view):

Motherboard

I/O Bus

Board traces (wires)

Connectors for plug-in cards

Integrated Circuits

Plug-in card

I/O bus connector

Memory

CPU

Page 22: •DigSim Assignment 3 •Cache Memory •Virtual Memory + …chang/cs313.f04/topics/Slides26.pdfVirtual Memory + Cache Memory 1.CPU instruction generates a virtual address. 2.Translation

Chapter 8: Input and Output8-4

Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring

Simplified Illustration of a Bus

CPU DiskMemory

Control (C0 – C9)Address (A0 – A31)Data (D0 – D31)Power (GND, +5V, –15V)

Page 23: •DigSim Assignment 3 •Cache Memory •Virtual Memory + …chang/cs313.f04/topics/Slides26.pdfVirtual Memory + Cache Memory 1.CPU instruction generates a virtual address. 2.Translation

Chapter 8: Input and Output8-5

Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring

100 MHz Bus Clock

CrystalOscillator

1 0 1 0 1 0 1 0

Logical 0 (0V)

Logical 1 (+5V)

10 ns

Page 24: •DigSim Assignment 3 •Cache Memory •Virtual Memory + …chang/cs313.f04/topics/Slides26.pdfVirtual Memory + Cache Memory 1.CPU instruction generates a virtual address. 2.Translation

Chapter 8: Input and Output8-6

Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring

The Synchronous Bus• Timing diagram for a synchronous memory read (adapted from

[Tanenbaum, 1999]).

Φ

Address

Data

MREQ

RD

T1 T2 T3Leading edge

Trailing edge

Data valid

Time

Address valid

Page 25: •DigSim Assignment 3 •Cache Memory •Virtual Memory + …chang/cs313.f04/topics/Slides26.pdfVirtual Memory + Cache Memory 1.CPU instruction generates a virtual address. 2.Translation

Chapter 8: Input and Output8-7

Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring

The Asynchronous Bus• Timing diagram for asynchronous memory read (adapted from

[Tanenbaum, 1999]).

Address

MSYN

RD

Data

Time

Memory address to be read

MREQ

SSYN

Data valid

Page 26: •DigSim Assignment 3 •Cache Memory •Virtual Memory + …chang/cs313.f04/topics/Slides26.pdfVirtual Memory + Cache Memory 1.CPU instruction generates a virtual address. 2.Translation

Chapter 8: Input and Output8-9

Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring

BridgeBased

Bus Ar-chitecture

• Bridging withdual Pentium IIXeon proces-sors on Slot 2.

(Source: http://www.intel.com.)

3200 MB/sec 3200 MB/sec

800 MB/sec

100-MHz System Bus

533 MB/sec 800 MB/sec

AGP 100 MHz

133 MB/sec 33-MHz PCI Bus

40 M

B/s

ec

16.7 MB/sec

ISA Bus

USB #2IDE Bus #2

USB #1

SC

SI B

us

1.5 MB/sec

33 MB/sec

IDE Bus #133 MB/sec

Intel 440GX AGPset

(Host Bridge)

400-MHz Core

512KB-2MB Cache

400-MHz Core

512KB-2MB Cache

2GB 100-MHz SDRAM

AGP 2X Graphics

PCI to ISA Bridge

Keyboard Audio

CD-ROMMouseSnapshot

Camera

Hard Disk

Hard Disk

SCSI Interface

Ethernet Interface

Page 27: •DigSim Assignment 3 •Cache Memory •Virtual Memory + …chang/cs313.f04/topics/Slides26.pdfVirtual Memory + Cache Memory 1.CPU instruction generates a virtual address. 2.Translation

Chapter 8: Input and Output8-8

Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring

Bus Arbitration

• (a)Simplecentralized busarbitration; (b)centralizedarbitration withpriority levels; (c)decentralized busarbitration.(Adapted from[Tanenbaum,1999]).

Arbiter Bus grant

Bus request

0 1 2 n. . .

(a)

Arbiter

Bus grant level 0

Bus request level 0

0 1 2 n. . .

(b)

Bus grant

Bus request

0 1 2 n. . .

(c)Busy+5V

Bus grant level k

Bus request level k...

Page 28: •DigSim Assignment 3 •Cache Memory •Virtual Memory + …chang/cs313.f04/topics/Slides26.pdfVirtual Memory + Cache Memory 1.CPU instruction generates a virtual address. 2.Translation

Types of I/O Control

• Programmed I/O = polling

• Interrupt driven.

• DMA = Direct Memory Access.

• Channel I/O: uses dedicated I/O processors.

UMBC, CMSC313, Richard Chang <[email protected]>

Page 29: •DigSim Assignment 3 •Cache Memory •Virtual Memory + …chang/cs313.f04/topics/Slides26.pdfVirtual Memory + Cache Memory 1.CPU instruction generates a virtual address. 2.Translation

Chapter 8: Input and Output8-10

Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring

Programmed I/OFlowchart for aDisk Transfer

Check status of disk

Disk ready?No

Yes

Send data from memory to disk (when writing) or from disk

to memory (when reading).

Done?No

Yes

Continue

Enter

Page 30: •DigSim Assignment 3 •Cache Memory •Virtual Memory + …chang/cs313.f04/topics/Slides26.pdfVirtual Memory + Cache Memory 1.CPU instruction generates a virtual address. 2.Translation

Chapter 8: Input and Output8-11

Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring

Interrupt DrivenI/O Flowchart

for a DiskTransfer

Transfer data between disk and memory.

Done?No

Yes

Continue

Return from interrupt. Normal processing

resumes.

Do other processing, until disk issues an

interrupt.

Interrupt causes current processing to stop.

Issue read or write request to disk.

Enter

Page 31: •DigSim Assignment 3 •Cache Memory •Virtual Memory + …chang/cs313.f04/topics/Slides26.pdfVirtual Memory + Cache Memory 1.CPU instruction generates a virtual address. 2.Translation

Chapter 8: Input and Output8-12

Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring

DMA Transfer from Disk to MemoryBypasses the CPU

CPU DiskMemory

Without DMA With DMA

Bus

Page 32: •DigSim Assignment 3 •Cache Memory •Virtual Memory + …chang/cs313.f04/topics/Slides26.pdfVirtual Memory + Cache Memory 1.CPU instruction generates a virtual address. 2.Translation

Chapter 8: Input and Output8-13

Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring

DMA Flowchart for a Disk Transfer

CPU executes another process

Continue

DMA device begins transfer independent of

CPU

DMA device interrupts CPU when finished

CPU sets up disk for DMA transfer

Enter

Page 33: •DigSim Assignment 3 •Cache Memory •Virtual Memory + …chang/cs313.f04/topics/Slides26.pdfVirtual Memory + Cache Memory 1.CPU instruction generates a virtual address. 2.Translation

Buffering

• Many I/O devices have on-board memory.

• Communication can be done at memory-to-memory speeds.

• More expensive, requires local controller.

• I/O becomes more like networking.

UMBC, CMSC313, Richard Chang <[email protected]>

Page 34: •DigSim Assignment 3 •Cache Memory •Virtual Memory + …chang/cs313.f04/topics/Slides26.pdfVirtual Memory + Cache Memory 1.CPU instruction generates a virtual address. 2.Translation

Next Time

• Performance Metrics

• Trends

UMBC, CMSC313, Richard Chang <[email protected]>