writeback

package
Version: v1.8.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2020 License: MIT Imports: 10 Imported by: 0

README

Writeback Cache

A writeback cache is a cache module that uses the writeback policy.

A writeback cache has 3 ports, including the TopPort, the BottomPort, and the ControlPort. The Top Port receives a read and write requests and replies data-ready and write-done responses. The BottomPort sends read and write requests to another cache or memory component and expects data-ready and write-done responses. The control port handles special controlling requests, such as pause, continue, and flush.

Write Back Cache Stage

Here is a graph that illustrates the internal sub-components of a writeback cache. Rather than introducing each component, we introduce the component by describing the life cycles of different types of cache transactions and their journeys through all the components.

Cache Transactions

All the cache transactions start from requests arriving at the top port. The Top Parser extracts requests from the Top Port buffer and wraps the requests as a transaction. One request produces one cache transaction. The Top Parser forwards all the transactions to the Directory Stage. The directory stages compare the request address with the current MSHR status and the data that is stored in the directory to determine what to do next. Here, we define the directory as the tags stored in the cache, rather than the directory for cache coherency protocols.

So the common first and second step for all the cache transactions are:

  • Step 1: The Top Parser parses the request from a higher-level module.

  • Step 2: The Directory Stage checks the MSHR state and the meta-data in the directory to determine the following actions.

The directory maintains the read and write reference count of each cache line. When the read reference is greater than 1, other reads can proceed, but writes have to wait. If the write reference is greater than 1, all reads and writes have to wait.

Read, MSHR Hit
  • Step 2: The Directory Stage attaches the transaction to the MSHR entry.

  • Step 3: The MSHR Stage prepares the response when the data is ready. The MSHR Stage sends the response through the Top Port.

Read, MSHR Miss, Directory Hit
  • Step 2: The Directory Stage add the cache line read reference count by 1 and sends the transaction to the bank stage.

  • Step 3: The Bank Stage read from its local storage. When the local read is completed, the bank reduces the read reference of the cache line by 1. The bank also sends the response through the Top Port.

Read, MSHR Miss, Directory Miss, No Eviction

In the case of a read miss, the writeback cache needs to read from a lower-level module. The directory needs to find a cache line to hold the data. The cache line is called a victim. When the cache line does not hold any dirty data, the data in that cache line can be safely removed without writing back to a lower-level model.

  • Step 2: The Directory Stage add write reference count by 1 to the cache line. Since the bank needs to "write" the data to the cache line later, the directory adds the write reference rather than read reference. The directory stage also creates an MSHR entry. Eventually, the directory stage sends the request to the write buffer to fetch the cache line.

  • Step 3: The Write Buffer checks if the cacheline is currently in the buffer. If not, send a read request to a lower-level module to fetch the data.

  • Step 4: The Write Buffer collects the data for the fetch. The data can either reside in the write buffer. Otherwise, the write buffer waits for the return request sent to the lower-level module to return. When the write buffer has the data, the write buffer combines writes with the fetched data. The write buffer sends the data to the bank to write to the local storage. The corresponding MSHR entry is removed at this moment.

    The MSHR entry cannot be removed at a later cycle, since the write-combining take place in this cycle. If the MSHR entry is still there, a new write may attach to the MSHR entry, and no logic can combine the write with the fetched data.

  • Step 5: The Bank Stage writes the data locally. When complete, the Bank Stage reduces the write reference count by 1. The Bank Stage then sends the transaction to the MSHR stage.

  • Step 6: The MSHR Stage prepares the responses for each request associated with the MSHR entry. The MSHR Stage sends the responses through the Top Port.

Read, MSHR Miss, Directory Miss, Need Eviction

In this case, the victim cacheline has dirty data and needs to write to the lower-level module.

  • Step 2: The Directory Stage adds the write reference of the cache line by 1. Since fetch is required, the Directory Stage also creates an MSHR entry. Then the Directory Stage sends the transaction to the Bank Stage.

  • Step 3: The Bank Stage reads the data to be evicted and sends the transaction to the write buffer.

  • Step 4: The Write Buffer adds the evicted data to the write buffer, and the write request will be issued to the lower-level module at a later time.

  • Step 5: The Write Buffer fetches the reading data, either from the local write buffer or from a lower-level module. Once the data is ready, the Write Buffer combines the fetched data with the write requests associated with the MSHR entry. The Write Buffer also removes the MSHR entry. Finally, the Write Buffer sends the transaction to the bank (for the 2nd time).

  • Step 6: The Bank Stage writes the fetched data to local storage and sends the transaction to the MSHR stage.

  • Step 7: The MSHR Stage prepares the responses for each request associated with the MSHR entry.

Write, MSHR Hit
  • Step 2: The Directory Stage attaches the transaction with the MSHR entry.

  • Step 3: The Write Buffer, once collected the data for the MSHR entry, combines the write with the collected data.

  • Step 4: The Bank Stage writes the Write Buffer collected data to the local storage.

  • Step 5: The MSHR Stage prepares the responses and sends the responses through the Top Port.

Write, MSHR Miss, Directory Hit

This is the typical write hit case.

  • Step 2: The Directory Stage adds the write reference by 1 and sends the transaction to the Bank Stage.

  • Step 3: The Bank Stage writes the data locally, reduces the write reference by 1, and sends the response through the Top Port.

Write, MSHR Miss, Directory Miss, No Eviction, Full Cacheline

This case is generally considered as "write miss." However, since it does not need to fetch data from a lower-level module, it is equivalent to a "write hit."

  • Step 2: The Directory Stage adds the write reference by 1. It sends the transaction to the bank as if it is a write hit.

  • Step 3: The Bank Stage writes the data, reduces the write reference by 1, and sends the response through the Top Port.

Write, MSHR Miss, Directory Miss, Need Eviction, Full Cacheline
  • Step 2: The Directory Stage adds the write reference by 1. It sends the transaction to the bank.

  • Step 3: The Bank Stage reads the data for eviction and sends the transaction to the write buffer.

  • Step 4: The Write Buffer buffers the evicted data. And send the transaction back to the bank as a write hit.

  • Step 5: The Bank Stage writes the data to the local storage, reduces the write reference by 1, and sends the response through the Top Port.

Write, MSHR Miss, Directory Miss, No Eviction, Partial Cacheline
  • Step 2: The Directory Stage adds the write reference by 1. Since fetch is necessary, the directory stage creates an MSHR entry. The write is attached to the MSHR entry. The Directory Stage sends the transaction to the write buffer.

  • Step 3: The Write Buffer collects the data, either from local write buffer or from a lower-level module. The write is combined with the fetched data.

  • Step 4: The Bank Stage writes the data to local storage. It also reduces the write reference by 1.

  • Step 5: The MSHR Stage generates the response and sends it through the Top Port.

Write, MSHR Miss, Directory Miss, Need Eviction, Partial Cacheline.

  • Step 2: The Directory Stage adds the write reference by 1. It also creates an MSHR entry for the write. The transaction is then sent to the bank.

  • Step 3: The Bank Stage reads the victim data.

  • Step 4: The Write Buffer sends the buffers the eviction.

  • Step 5: The Write Buffer collects the data, either from local write buffer or from a lower-level module. The write is combined with the fetched data.

  • Step 6: The Bank Stage writes the data to local storage. It also reduces the write reference by 1.

  • Step 7: The MSHR Stage generates the response and send it through the Top Port.

Control Requests

Documentation

Overview

Package writeback implement a writeback cache.=

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

A Builder can build writeback caches

func MakeBuilder

func MakeBuilder() Builder

func (*Builder) Build

func (b *Builder) Build(name string) *Cache

Build creates a usable writeback cache.

func (Builder) WithByteSize

func (b Builder) WithByteSize(byteSize uint64) Builder

func (Builder) WithEngine

func (b Builder) WithEngine(engine akita.Engine) Builder

func (Builder) WithFreq

func (b Builder) WithFreq(freq akita.Freq) Builder

func (Builder) WithLog2BlockSize

func (b Builder) WithLog2BlockSize(n uint64) Builder

func (Builder) WithLowModuleFinder

func (b Builder) WithLowModuleFinder(f cache.LowModuleFinder) Builder

func (Builder) WithMaxInflightEviction

func (b Builder) WithMaxInflightEviction(n int) Builder

WithMaxInflightEviction sets the number of concurrent eviction that the write buffer can write to a low-level module.

func (Builder) WithMaxInflightFetch

func (b Builder) WithMaxInflightFetch(n int) Builder

WithMaxInflightFetch sets the number of concurrent fetch that the write-back cache can issue at the same time.

func (Builder) WithNumMSHREntry

func (b Builder) WithNumMSHREntry(n int) Builder

func (Builder) WithNumReqPerCycle

func (b Builder) WithNumReqPerCycle(n int) Builder

func (Builder) WithWayAssociativity

func (b Builder) WithWayAssociativity(n int) Builder

func (Builder) WithWriteBufferSize

func (b Builder) WithWriteBufferSize(n int) Builder

WithWriteBufferSize sets the number of cachlines that can reside in the writebuffer.

type Cache

type Cache struct {
	*akita.TickingComponent

	TopPort     akita.Port
	BottomPort  akita.Port
	ControlPort akita.Port
	// contains filtered or unexported fields
}

A Cache in writeback package is a cache that performs the write-back policy

func (*Cache) Tick

func (c *Cache) Tick(now akita.VTimeInSec) bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL