S3.5.1 Write-Through or Write-Back

MediumImplement22 minIcarus Verilog · serverReview the topic

Count what two write policies send to memory for the same writes, and what the dirty bit saves.

Hardware context: A direct-mapped cache with its controller in front of a memory on the bus, acted out edge by edge as a script. Designing and timing the miss path of a cache

A cache has four lines of one block each, and starts empty. Under write-through, every write goes to the cache and to memory at once. Under write-back, a write goes to the cache only and sets the dirty bit of its line. A dirty block is written to memory when another block pushes it out. Both policies allocate: a write that misses fetches its block first. A memory write takes 10 cycles.

This worksheet uses named constants. The first three entries show how to record your decisions.

Signals in the Timeline

SignalWidthRole
question8input of each check
Full specification

Enter counts and cycles as whole numbers. For a yes-or-no entry, enter 1 for yes and 2 for no.

EntryYour decision
WT_WRITESBlock A is written 6 times, and then block B pushes it out. How many memory writes under write-through?
WB_WRITESThe same under write-back?
DIRTY_AFTER_ONEUnder write-back, is the line of A dirty after the first write? Enter 1 for yes, 2 for no.
CLEAN_GOESUnder write-back, block C was only read, and is then pushed out. Is a memory write needed? Enter 1 for yes, 2 for no.
FETCHESHow many times is block A fetched from memory for its 6 writes, with allocate?
WT_CYCLESHow many cycles of memory writing does write-through spend on those 6 writes?
WB_CYCLESAnd write-back, counting the write when B pushes A out?
TWO_BLOCKS_WTBlocks X and Y use different lines. Each is written 3 times, and then both are pushed out. Memory writes under write-through?
TWO_BLOCKS_WBThe same under write-back?
DIRTY_LEFTUnder write-back, block A is written 6 times and nothing pushes it out. How many lines are dirty when the power is switched off?
SAVED_WRITESBlock A is written N_WRITES times and is then pushed out. How many memory writes does write-back save, compared with write-through?

Examples

Example 1

WT WRITES
Input
Block A is written 6 times, and then block B pushes it out. How many memory writes under write-through?
Output
matches = 1

Every write goes to memory at once: 6. Pushing the block out costs nothing more.

Example 2

WB WRITES
Input
The same under write-back?
Output
matches = 1

The six writes only make the line dirty. The block goes to memory once, when B pushes it out.

Example 3

DIRTY AFTER ONE
Input
Under write-back, is the line of A dirty after the first write? Enter 1 for yes, 2 for no.
Output
matches = 1

One write is enough: memory no longer has the latest content.

Constraints and Contract

  • Keep the parameter and named constants. Use the numeric codes and units on this page.
  • For SAVED_WRITES, enter a constant expression using N_WRITES. Only this entry changes with the parameter. The supported integer range is 1 through 100, inclusive.

Hints

Hint 1

Under write-through: cache and memory. Under write-back: cache only, and the dirty bit.

Hint 2

Only a dirty block must be written to memory first.

Hint 3

Write-back costs at most one memory write for each time a block is pushed out.

What the grader checks: Each check compares the full eight-bit answer. Parameter trials change one condition and keep the other decisions fixed.

11 checks on Icarus Verilog · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain your source only; samples require the simulation service. A passing result establishes the tested cases, not a proof for all possible inputs.

See all 4 problems on this path

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

WT WRITES

Input
Block A is written 6 times, and then block B pushes it out. How many memory writes under write-through?
Expected output
matches = 1

Every write goes to memory at once: 6. Pushing the block out costs nothing more.

Run samples executes all 3 public checks. Check all tests runs 11 checks on the server.

Icarus Verilog · server