Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

L1TLB: fix support for configurable Sets/Ways #2621

Merged
merged 3 commits into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class DCacheLogicalTreeNode(dcache: HellaCache, deviceOpt: Option[SimpleDevice],
dataMemorySizeBytes = params.nSets * params.nWays * params.blockBytes,
dataECC = params.dataECC.map(OMECC.fromString),
tagECC = params.tagECC.map(OMECC.fromString),
nTLBEntries = params.nTLBSets * params.nTLBWays,
nTLBSets = params.nTLBSets,
nTLBWays = params.nTLBWays,
memories = dcache.getOMSRAMs(),
Expand All @@ -50,6 +51,7 @@ class ICacheLogicalTreeNode(icache: ICache, deviceOpt: Option[SimpleDevice], par
dataMemorySizeBytes = params.nSets * params.nWays * params.blockBytes,
dataECC = params.dataECC.map(OMECC.fromString),
tagECC = params.tagECC.map(OMECC.fromString),
nTLBEntries = params.nTLBSets * params.nTLBWays,
nTLBSets = params.nTLBSets,
nTLBWays = params.nTLBWays,
maxTimSize = params.nSets * (params.nWays-1) * params.blockBytes,
Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/diplomaticobjectmodel/model/OMCaches.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ case class OMICache(
dataMemorySizeBytes: Int,
dataECC: Option[OMECC],
tagECC: Option[OMECC],
nTLBEntries: Int,
nTLBSets: Int,
nTLBWays: Int,
maxTimSize: Int,
Expand All @@ -41,6 +42,7 @@ case class OMDCache(
dataMemorySizeBytes: Int,
dataECC: Option[OMECC],
tagECC: Option[OMECC],
nTLBEntries: Int,
nTLBSets: Int,
nTLBWays: Int,
memories: Seq[OMSRAM],
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/rocket/TLB.scala
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class TLBEntry(val nSectors: Int, val superpage: Boolean, val superpageOnly: Boo

case class TLBConfig(
nSets: Int,
nEntries: Int,
nWays: Int,
nSectors: Int = 4,
nSuperpageEntries: Int = 4)

Expand All @@ -162,7 +162,7 @@ class TLB(instruction: Boolean, lgMaxSize: Int, cfg: TLBConfig)(implicit edge: T
val pageGranularityPMPs = pmpGranularity >= (1 << pgIdxBits)
val vpn = io.req.bits.vaddr(vaddrBits-1, pgIdxBits)
val memIdx = vpn.extract(cfg.nSectors.log2 + cfg.nSets.log2 - 1, cfg.nSectors.log2)
val sectored_entries = Reg(Vec(cfg.nSets, Vec(cfg.nEntries / cfg.nSectors, new TLBEntry(cfg.nSectors, false, false))))
val sectored_entries = Reg(Vec(cfg.nSets, Vec(cfg.nWays / cfg.nSectors, new TLBEntry(cfg.nSectors, false, false))))
val superpage_entries = Reg(Vec(cfg.nSuperpageEntries, new TLBEntry(1, true, true)))
val special_entry = (!pageGranularityPMPs).option(Reg(new TLBEntry(1, true, false)))
def ordinary_entries = sectored_entries(memIdx) ++ superpage_entries
Expand Down Expand Up @@ -324,7 +324,7 @@ class TLB(instruction: Boolean, lgMaxSize: Int, cfg: TLBConfig)(implicit edge: T
val tlb_hit = real_hits.orR
val tlb_miss = vm_enabled && !bad_va && !tlb_hit

val sectored_plru = new SetAssocLRU(cfg.nSets, cfg.nEntries, "plru")
val sectored_plru = new SetAssocLRU(cfg.nSets, sectored_entries(0).size, "plru")
val superpage_plru = new PseudoLRU(superpage_entries.size)
when (io.req.valid && vm_enabled) {
when (sector_hits.orR) { sectored_plru.access(memIdx, OHToUInt(sector_hits)) }
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/tile/L1Cache.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ trait L1CacheParams {
def nWays: Int
def rowBits: Int
def nTLBSets: Int
def nTLBWays: Int
def nTLBWays: Int
def blockBytes: Int // TODO this is ignored in favor of p(CacheBlockBytes) in BaseTile
}

Expand Down
12 changes: 12 additions & 0 deletions src/main/scala/util/Replacement.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ abstract class SeqReplacementPolicy {

abstract class SetAssocReplacementPolicy {
def access(set: UInt, touch_way: UInt): Unit
def access(sets: Seq[UInt], touch_ways: Seq[Valid[UInt]]): Unit
def way(set: UInt): UInt
}

Expand Down Expand Up @@ -301,6 +302,17 @@ class SetAssocLRU(n_sets: Int, n_ways: Int, policy: String) extends SetAssocRepl
state_vec(set) := logic.get_next_state(state_vec(set), touch_way)
}

def access(sets: Seq[UInt], touch_ways: Seq[Valid[UInt]]) = {
require(sets.size == touch_ways.size, "internal consistency check: should be same number of simultaneous updates for sets and touch_ways")
for (set <- 0 until n_sets) {
val set_touch_ways = (sets zip touch_ways).map { case (touch_set, touch_way) =>
Pipe(touch_way.valid && (touch_set === set.U), touch_way.bits, 0)}
when (set_touch_ways.map(_.valid).orR) {
state_vec(set) := logic.get_next_state(state_vec(set), set_touch_ways)
}
}
}

def way(set: UInt) = logic.get_replace_way(state_vec(set))

}
Expand Down