forked from lshpku/hwd-prefetch-study
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBankedL2Params.scala
183 lines (156 loc) · 6.02 KB
/
BankedL2Params.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// See LICENSE.SiFive for license details.
package freechips.rocketchip.subsystem
import chisel3._
import chisel3.util._
import freechips.rocketchip.config._
import freechips.rocketchip.devices.tilelink.BuiltInDevices
import freechips.rocketchip.diplomacy._
import freechips.rocketchip.interrupts._
import freechips.rocketchip.tilelink._
import freechips.rocketchip.util._
import CoherenceManagerWrapper._
/** Global cache coherence granularity, which applies to all caches, for now. */
case object CacheBlockBytes extends Field[Int](64)
/** L2 Broadcast Hub configuration */
case object BroadcastKey extends Field(BroadcastParams())
case class BroadcastParams(
nTrackers: Int = 4,
bufferless: Boolean = false,
controlAddress: Option[BigInt] = None,
filterFactory: TLBroadcast.ProbeFilterFactory = BroadcastFilter.factory)
/** L2 memory subsystem configuration */
case object BankedL2Key extends Field(BankedL2Params())
case class BankedL2Params(
nBanks: Int = 1,
coherenceManager: CoherenceManagerInstantiationFn = broadcastManager
) {
require (isPow2(nBanks) || nBanks == 0)
}
case class CoherenceManagerWrapperParams(
blockBytes: Int,
beatBytes: Int,
nBanks: Int,
name: String,
dtsFrequency: Option[BigInt] = None)
(val coherenceManager: CoherenceManagerInstantiationFn)
extends HasTLBusParams
with TLBusWrapperInstantiationLike
{
def instantiate(context: HasTileLinkLocations, loc: Location[TLBusWrapper])(implicit p: Parameters): CoherenceManagerWrapper = {
val cmWrapper = LazyModule(new CoherenceManagerWrapper(this, context))
cmWrapper.suggestName(loc.name + "_wrapper")
cmWrapper.halt.foreach { context.anyLocationMap += loc.halt(_) }
context.tlBusWrapperLocationMap += (loc -> cmWrapper)
cmWrapper
}
}
class CoherenceManagerWrapper(params: CoherenceManagerWrapperParams, context: HasTileLinkLocations)(implicit p: Parameters) extends TLBusWrapper(params, params.name) {
val (tempIn, tempOut, halt) = params.coherenceManager(context)
private val coherent_jbar = LazyModule(new TLJbar)
def busView: TLEdge = coherent_jbar.node.edges.out.head
val inwardNode = tempIn :*= coherent_jbar.node
val builtInDevices = BuiltInDevices.none
val prefixNode = None
println ("params.nBanks", params.nBanks)
println ("params.blockBytes", params.blockBytes)
private def banked(node: TLOutwardNode): TLOutwardNode =
if (params.nBanks == 0) node else { TLTempNode() :=* BankBinder(params.nBanks, params.blockBytes) :*= node }
val outwardNode = TLBuffer(BufferParams.none, DelayerParams(100, 8)) :=* banked(tempOut)
}
object CoherenceManagerWrapper {
type CoherenceManagerInstantiationFn = HasTileLinkLocations => (TLInwardNode, TLOutwardNode, Option[IntOutwardNode])
def broadcastManagerFn(
name: String,
location: HierarchicalLocation,
controlPortsSlaveWhere: TLBusWrapperLocation
): CoherenceManagerInstantiationFn = { context =>
implicit val p = context.p
val cbus = context.locateTLBusWrapper(controlPortsSlaveWhere)
val BroadcastParams(nTrackers, bufferless, controlAddress, filterFactory) = p(BroadcastKey)
val bh = LazyModule(new TLBroadcast(TLBroadcastParams(
lineBytes = p(CacheBlockBytes),
numTrackers = nTrackers,
bufferless = bufferless,
control = controlAddress.map(x => TLBroadcastControlParams(AddressSet(x, 0xfff), cbus.beatBytes)),
filterFactory = filterFactory)))
bh.suggestName(name)
bh.controlNode.foreach { _ := cbus.coupleTo(s"${name}_ctrl") { TLBuffer(1) := TLFragmenter(cbus) := _ } }
bh.intNode.foreach { context.ibus.fromSync := _ }
(bh.node, bh.node, None)
}
val broadcastManager = broadcastManagerFn("broadcast", InSystem, CBUS)
val incoherentManager: CoherenceManagerInstantiationFn = { _ =>
val node = TLNameNode("no_coherence_manager")
(node, node, None)
}
}
class TokenDelayer[T <: Data](gen: T, delay: Int, entries: Int) extends Module {
val io = IO(new Bundle {
val enq = Flipped(Decoupled(gen))
val deq = Decoupled(gen)
})
require(delay > 1, "Use a normal Queue if you want a delay of 1")
class DebugData extends Bundle {
val data = gen.cloneType
val debug_id = UInt(log2Ceil(delay + 1).W)
}
val debug_id = RegInit(0.U(log2Ceil(delay + 1).W))
val cycle = freechips.rocketchip.util.WideCounter(32).value
val aging = RegInit(0.U((delay - 1).W))
val tokens = RegInit(0.U(log2Ceil(entries + 1).W))
val queue = Module(new Queue(new DebugData, entries))
aging := aging << 1
when (aging(delay - 2) === 1.U) {
assert (tokens < entries.U, "Tokens overflow")
tokens := tokens + 1.U
}
// enqueue logic
io.enq.ready := queue.io.enq.ready
queue.io.enq.valid := io.enq.valid
queue.io.enq.bits.data := io.enq.bits
queue.io.enq.bits.debug_id := debug_id
when (io.enq.fire) {
aging := (aging << 1).asUInt | 1.U
when (debug_id =/= delay.U) {
debug_id := debug_id + 1.U
} .otherwise {
debug_id := 0.U
}
}
// dequeue logic
io.deq.valid := false.B
io.deq.bits := queue.io.deq.bits.data
queue.io.deq.ready := false.B
when (tokens > 0.U) {
io.deq.valid := queue.io.deq.valid
queue.io.deq.ready := io.deq.ready
when (io.deq.fire) {
when (aging(delay - 2) === 0.U) {
tokens := tokens - 1.U
} .otherwise {
tokens := tokens
}
}
}
assert (!(queue.io.deq.valid && tokens === 0.U && aging === 0.U), "Tokens leaked")
}
class DelayerParams(delay: Int, entries: Int) extends BufferParams(delay, false, false) {
require (delay >= 0, "Delay must be >= 0")
override def apply[T <: Data](x: DecoupledIO[T]): DecoupledIO[T] = {
if (delay > 1) {
val delayer = Module(new TokenDelayer(chiselTypeOf(x.bits), delay, entries))
println("TokenDelayer", delay, entries)
delayer.io.enq <> x
delayer.io.deq
} else if (delay > 0) {
Queue(x)
} else {
x
}
}
}
object DelayerParams
{
def apply(delay: Int): DelayerParams = apply(delay, delay)
def apply(delay: Int, entries: Int): DelayerParams = new DelayerParams(delay, entries)
}