1/*************************************************************************************** 2* Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences 3* Copyright (c) 2020-2021 Peng Cheng Laboratory 4* 5* XiangShan is licensed under Mulan PSL v2. 6* You can use this software according to the terms and conditions of the Mulan PSL v2. 7* You may obtain a copy of Mulan PSL v2 at: 8* http://license.coscl.org.cn/MulanPSL2 9* 10* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 11* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 12* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 13* 14* See the Mulan PSL v2 for more details. 15***************************************************************************************/ 16 17package xiangshan.cache 18 19import chisel3._ 20import chisel3.util._ 21import org.chipsalliance.cde.config.Parameters 22import utils._ 23import utility._ 24import xiangshan._ 25import xiangshan.mem._ 26import coupledL2.MemBackTypeMM 27import coupledL2.MemPageTypeNC 28import freechips.rocketchip.diplomacy.{IdRange, LazyModule, LazyModuleImp, TransferSizes} 29import freechips.rocketchip.tilelink.{TLArbiter, TLBundleA, TLBundleD, TLClientNode, TLEdgeOut, TLMasterParameters, TLMasterPortParameters} 30import coupledL2.{MemBackTypeMMField, MemPageTypeNCField} 31 32trait HasUncacheBufferParameters extends HasXSParameter with HasDCacheParameters { 33 34 def doMerge(oldData: UInt, oldMask: UInt, newData:UInt, newMask: UInt):(UInt, UInt) = { 35 val resData = VecInit((0 until DataBytes).map(j => 36 Mux(newMask(j), newData(8*(j+1)-1, 8*j), oldData(8*(j+1)-1, 8*j)) 37 )).asUInt 38 val resMask = newMask | oldMask 39 (resData, resMask) 40 } 41 42 def INDEX_WIDTH = log2Up(UncacheBufferSize) 43 def BLOCK_OFFSET = log2Up(XLEN / 8) 44 def getBlockAddr(x: UInt) = x >> BLOCK_OFFSET 45} 46 47abstract class UncacheBundle(implicit p: Parameters) extends XSBundle with HasUncacheBufferParameters 48 49abstract class UncacheModule(implicit p: Parameters) extends XSModule with HasUncacheBufferParameters 50 51 52class UncacheFlushBundle extends Bundle { 53 val valid = Output(Bool()) 54 val empty = Input(Bool()) 55} 56 57class UncacheEntry(implicit p: Parameters) extends UncacheBundle { 58 val cmd = UInt(M_SZ.W) 59 val addr = UInt(PAddrBits.W) 60 val vaddr = UInt(VAddrBits.W) 61 val data = UInt(XLEN.W) 62 val mask = UInt(DataBytes.W) 63 val nc = Bool() 64 val atomic = Bool() 65 val memBackTypeMM = Bool() 66 67 val resp_nderr = Bool() 68 69 /* NOTE: if it support the internal forward logic, here can uncomment */ 70 // val fwd_data = UInt(XLEN.W) 71 // val fwd_mask = UInt(DataBytes.W) 72 73 def set(x: UncacheWordReq): Unit = { 74 cmd := x.cmd 75 addr := x.addr 76 vaddr := x.vaddr 77 data := x.data 78 mask := x.mask 79 nc := x.nc 80 memBackTypeMM := x.memBackTypeMM 81 atomic := x.atomic 82 resp_nderr := false.B 83 // fwd_data := 0.U 84 // fwd_mask := 0.U 85 } 86 87 def update(x: UncacheWordReq): Unit = { 88 val (resData, resMask) = doMerge(data, mask, x.data, x.mask) 89 // mask -> get the first position as 1 -> for address align 90 val (resOffset, resFlag) = PriorityEncoderWithFlag(resMask) 91 data := resData 92 mask := resMask 93 when(resFlag){ 94 addr := (getBlockAddr(addr) << BLOCK_OFFSET) | resOffset 95 vaddr := (getBlockAddr(vaddr) << BLOCK_OFFSET) | resOffset 96 } 97 } 98 99 def update(x: TLBundleD): Unit = { 100 when(cmd === MemoryOpConstants.M_XRD) { 101 data := x.data 102 } 103 resp_nderr := x.denied || x.corrupt 104 } 105 106 // def update(forwardData: UInt, forwardMask: UInt): Unit = { 107 // fwd_data := forwardData 108 // fwd_mask := forwardMask 109 // } 110 111 def toUncacheWordResp(eid: UInt): UncacheWordResp = { 112 // val resp_fwd_data = VecInit((0 until DataBytes).map(j => 113 // Mux(fwd_mask(j), fwd_data(8*(j+1)-1, 8*j), data(8*(j+1)-1, 8*j)) 114 // )).asUInt 115 val resp_fwd_data = data 116 val r = Wire(new UncacheWordResp) 117 r := DontCare 118 r.data := resp_fwd_data 119 r.id := eid 120 r.nderr := resp_nderr 121 r.nc := nc 122 r.is2lq := cmd === MemoryOpConstants.M_XRD 123 r.miss := false.B 124 r.replay := false.B 125 r.tag_error := false.B 126 r.error := false.B 127 r 128 } 129} 130 131class UncacheEntryState(implicit p: Parameters) extends DCacheBundle { 132 // valid (-> waitSame) -> inflight -> waitReturn 133 val valid = Bool() 134 val inflight = Bool() // uncache -> L2 135 val waitSame = Bool() 136 val waitReturn = Bool() // uncache -> LSQ 137 138 def init: Unit = { 139 valid := false.B 140 inflight := false.B 141 waitSame := false.B 142 waitReturn := false.B 143 } 144 145 def isValid(): Bool = valid 146 def isInflight(): Bool = valid && inflight 147 def isWaitReturn(): Bool = valid && waitReturn 148 def isWaitSame(): Bool = valid && waitSame 149 def can2Bus(): Bool = valid && !inflight && !waitSame && !waitReturn 150 def can2Lsq(): Bool = valid && waitReturn 151 152 def setValid(x: Bool): Unit = { valid := x} 153 def setInflight(x: Bool): Unit = { inflight := x} 154 def setWaitReturn(x: Bool): Unit = { waitReturn := x } 155 def setWaitSame(x: Bool): Unit = { waitSame := x} 156 157 def updateUncacheResp(): Unit = { 158 assert(inflight, "The request was not sent and a response was received") 159 inflight := false.B 160 waitReturn := true.B 161 } 162 def updateReturn(): Unit = { 163 valid := false.B 164 inflight := false.B 165 waitSame := false.B 166 waitReturn := false.B 167 } 168} 169 170class UncacheIO(implicit p: Parameters) extends DCacheBundle { 171 val hartId = Input(UInt()) 172 val enableOutstanding = Input(Bool()) 173 val flush = Flipped(new UncacheFlushBundle) 174 val lsq = Flipped(new UncacheWordIO) 175 val forward = Vec(LoadPipelineWidth, Flipped(new LoadForwardQueryIO)) 176} 177 178// convert DCacheIO to TileLink 179// for Now, we only deal with TL-UL 180 181class Uncache()(implicit p: Parameters) extends LazyModule with HasXSParameter { 182 override def shouldBeInlined: Boolean = false 183 def idRange: Int = UncacheBufferSize 184 185 val clientParameters = TLMasterPortParameters.v1( 186 clients = Seq(TLMasterParameters.v1( 187 "uncache", 188 sourceId = IdRange(0, idRange) 189 )), 190 requestFields = Seq(MemBackTypeMMField(), MemPageTypeNCField()) 191 ) 192 val clientNode = TLClientNode(Seq(clientParameters)) 193 194 lazy val module = new UncacheImp(this) 195} 196 197/* Uncache Buffer */ 198class UncacheImp(outer: Uncache)extends LazyModuleImp(outer) 199 with HasTLDump 200 with HasXSParameter 201 with HasUncacheBufferParameters 202 with HasPerfEvents 203{ 204 println(s"Uncahe Buffer Size: $UncacheBufferSize entries") 205 val io = IO(new UncacheIO) 206 207 val (bus, edge) = outer.clientNode.out.head 208 209 val req = io.lsq.req 210 val resp = io.lsq.resp 211 val mem_acquire = bus.a 212 val mem_grant = bus.d 213 val req_ready = WireInit(false.B) 214 215 // assign default values to output signals 216 bus.b.ready := false.B 217 bus.c.valid := false.B 218 bus.c.bits := DontCare 219 bus.d.ready := false.B 220 bus.e.valid := false.B 221 bus.e.bits := DontCare 222 io.lsq.req.ready := req_ready 223 io.lsq.resp.valid := false.B 224 io.lsq.resp.bits := DontCare 225 226 227 /****************************************************************** 228 * Data Structure 229 ******************************************************************/ 230 231 val entries = Reg(Vec(UncacheBufferSize, new UncacheEntry)) 232 val states = RegInit(VecInit(Seq.fill(UncacheBufferSize)(0.U.asTypeOf(new UncacheEntryState)))) 233 val fence = RegInit(Bool(), false.B) 234 val s_idle :: s_inflight :: s_wait_return :: Nil = Enum(3) 235 val uState = RegInit(s_idle) 236 237 // drain buffer 238 val empty = Wire(Bool()) 239 val f1_needDrain = Wire(Bool()) 240 val do_uarch_drain = RegNext(f1_needDrain) 241 242 val q0_entry = Wire(new UncacheEntry) 243 val q0_canSentIdx = Wire(UInt(INDEX_WIDTH.W)) 244 val q0_canSent = Wire(Bool()) 245 246 247 /****************************************************************** 248 * Functions 249 ******************************************************************/ 250 def sizeMap[T <: Data](f: Int => T) = VecInit((0 until UncacheBufferSize).map(f)) 251 def sizeForeach[T <: Data](f: Int => Unit) = (0 until UncacheBufferSize).map(f) 252 def isStore(e: UncacheEntry): Bool = e.cmd === MemoryOpConstants.M_XWR 253 def isStore(x: UInt): Bool = x === MemoryOpConstants.M_XWR 254 def addrMatch(x: UncacheEntry, y: UncacheWordReq) : Bool = getBlockAddr(x.addr) === getBlockAddr(y.addr) 255 def addrMatch(x: UncacheWordReq, y: UncacheEntry) : Bool = getBlockAddr(x.addr) === getBlockAddr(y.addr) 256 def addrMatch(x: UncacheEntry, y: UncacheEntry) : Bool = getBlockAddr(x.addr) === getBlockAddr(y.addr) 257 def addrMatch(x: UInt, y: UInt) : Bool = getBlockAddr(x) === getBlockAddr(y) 258 259 def continueAndAlign(mask: UInt): Bool = { 260 val res = 261 PopCount(mask) === 1.U || 262 mask === 0b00000011.U || 263 mask === 0b00001100.U || 264 mask === 0b00110000.U || 265 mask === 0b11000000.U || 266 mask === 0b00001111.U || 267 mask === 0b11110000.U || 268 mask === 0b11111111.U 269 res 270 } 271 272 def canMergePrimary(x: UncacheWordReq, e: UncacheEntry): Bool = { 273 // vaddr same, properties same 274 getBlockAddr(x.vaddr) === getBlockAddr(e.vaddr) && 275 x.cmd === e.cmd && x.nc && e.nc && 276 x.memBackTypeMM === e.memBackTypeMM && !x.atomic && !e.atomic && 277 continueAndAlign(x.mask | e.mask) 278 } 279 280 def canMergeSecondary(eid: UInt): Bool = { 281 // old entry is not inflight and senting 282 !states(eid).isInflight() && !(q0_canSent && q0_canSentIdx === eid) 283 } 284 285 /****************************************************************** 286 * uState for non-outstanding 287 ******************************************************************/ 288 289 switch(uState){ 290 is(s_idle){ 291 when(mem_acquire.fire){ 292 uState := s_inflight 293 } 294 } 295 is(s_inflight){ 296 when(mem_grant.fire){ 297 uState := s_wait_return 298 } 299 } 300 is(s_wait_return){ 301 when(resp.fire){ 302 uState := s_idle 303 } 304 } 305 } 306 307 308 /****************************************************************** 309 * Enter Buffer 310 * Version 0 (better timing) 311 * e0 judge: alloc/merge write vec 312 * e1 alloc 313 * 314 * Version 1 (better performance) 315 * e0: solved in one cycle for achieving the original performance. 316 * e1: return idResp to set sid for handshake 317 ******************************************************************/ 318 319 /* e0: merge/alloc */ 320 val e0_fire = req.fire 321 val e0_req_valid = req.valid 322 val e0_req = req.bits 323 324 val e0_rejectVec = Wire(Vec(UncacheBufferSize, Bool())) 325 val e0_mergeVec = Wire(Vec(UncacheBufferSize, Bool())) 326 val e0_allocWaitSameVec = Wire(Vec(UncacheBufferSize, Bool())) 327 sizeForeach(i => { 328 val valid = e0_req_valid && states(i).isValid() 329 val isAddrMatch = addrMatch(e0_req, entries(i)) 330 val canMerge1 = canMergePrimary(e0_req, entries(i)) 331 val canMerge2 = canMergeSecondary(i.U) 332 e0_rejectVec(i) := valid && isAddrMatch && !canMerge1 333 e0_mergeVec(i) := valid && isAddrMatch && canMerge1 && canMerge2 334 e0_allocWaitSameVec(i) := valid && isAddrMatch && canMerge1 && !canMerge2 335 }) 336 assert(PopCount(e0_mergeVec) <= 1.U, "Uncache buffer should not merge multiple entries") 337 338 val e0_invalidVec = sizeMap(i => !states(i).isValid()) 339 val e0_reject = do_uarch_drain || !e0_invalidVec.asUInt.orR || e0_rejectVec.reduce(_ || _) 340 val (e0_mergeIdx, e0_canMerge) = PriorityEncoderWithFlag(e0_mergeVec) 341 val (e0_allocIdx, e0_canAlloc) = PriorityEncoderWithFlag(e0_invalidVec) 342 val e0_allocWaitSame = e0_allocWaitSameVec.reduce(_ || _) 343 val e0_sid = Mux(e0_canMerge, e0_mergeIdx, e0_allocIdx) 344 345 // e0_fire is used to guarantee that it will not be rejected 346 when(e0_canMerge && e0_fire){ 347 entries(e0_mergeIdx).update(e0_req) 348 }.elsewhen(e0_canAlloc && e0_fire){ 349 entries(e0_allocIdx).set(e0_req) 350 states(e0_allocIdx).setValid(true.B) 351 when(e0_allocWaitSame){ 352 states(e0_allocIdx).setWaitSame(true.B) 353 } 354 } 355 356 req_ready := !e0_reject 357 358 /* e1: return accept */ 359 io.lsq.idResp.valid := RegNext(e0_fire) 360 io.lsq.idResp.bits.mid := RegEnable(e0_req.id, e0_fire) 361 io.lsq.idResp.bits.sid := RegEnable(e0_sid, e0_fire) 362 io.lsq.idResp.bits.is2lq := RegEnable(!isStore(e0_req.cmd), e0_fire) 363 io.lsq.idResp.bits.nc := RegEnable(e0_req.nc, e0_fire) 364 365 /****************************************************************** 366 * Uncache Req 367 * Version 0 (better timing) 368 * q0: choose which one is sent 369 * q0: sent 370 * 371 * Version 1 (better performance) 372 * solved in one cycle for achieving the original performance. 373 * NOTE: "Enter Buffer" & "Uncache Req" not a continuous pipeline, 374 * because there is no guarantee that mem_aquire will be always ready. 375 ******************************************************************/ 376 377 val q0_canSentVec = sizeMap(i => 378 (io.enableOutstanding || uState === s_idle) && 379 states(i).can2Bus() 380 ) 381 val q0_res = PriorityEncoderWithFlag(q0_canSentVec) 382 q0_canSentIdx := q0_res._1 383 q0_canSent := q0_res._2 384 q0_entry := entries(q0_canSentIdx) 385 386 val size = PopCount(q0_entry.mask) 387 val (lgSize, legal) = PriorityMuxWithFlag(Seq( 388 1.U -> 0.U, 389 2.U -> 1.U, 390 4.U -> 2.U, 391 8.U -> 3.U 392 ).map(m => (size===m._1) -> m._2)) 393 assert(!(q0_canSent && !legal)) 394 395 val q0_load = edge.Get( 396 fromSource = q0_canSentIdx, 397 toAddress = q0_entry.addr, 398 lgSize = lgSize 399 )._2 400 401 val q0_store = edge.Put( 402 fromSource = q0_canSentIdx, 403 toAddress = q0_entry.addr, 404 lgSize = lgSize, 405 data = q0_entry.data, 406 mask = q0_entry.mask 407 )._2 408 409 val q0_isStore = q0_entry.cmd === MemoryOpConstants.M_XWR 410 411 mem_acquire.valid := q0_canSent 412 mem_acquire.bits := Mux(q0_isStore, q0_store, q0_load) 413 mem_acquire.bits.user.lift(MemBackTypeMM).foreach(_ := q0_entry.memBackTypeMM) 414 mem_acquire.bits.user.lift(MemPageTypeNC).foreach(_ := q0_entry.nc) 415 when(mem_acquire.fire){ 416 states(q0_canSentIdx).setInflight(true.B) 417 418 // q0 should judge whether wait same block 419 (0 until UncacheBufferSize).map(j => 420 when(states(j).isValid() && !states(j).isWaitReturn() && addrMatch(q0_entry, entries(j))){ 421 states(j).setWaitSame(true.B) 422 } 423 ) 424 } 425 426 427 /****************************************************************** 428 * Uncache Resp 429 ******************************************************************/ 430 431 val (_, _, refill_done, _) = edge.addr_inc(mem_grant) 432 433 mem_grant.ready := true.B 434 when (mem_grant.fire) { 435 val id = mem_grant.bits.source 436 entries(id).update(mem_grant.bits) 437 states(id).updateUncacheResp() 438 assert(refill_done, "Uncache response should be one beat only!") 439 440 // remove state of wait same block 441 (0 until UncacheBufferSize).map(j => 442 when(states(j).isValid() && states(j).isWaitSame() && addrMatch(entries(id), entries(j))){ 443 states(j).setWaitSame(false.B) 444 } 445 ) 446 } 447 448 449 /****************************************************************** 450 * Return to LSQ 451 ******************************************************************/ 452 453 val r0_canSentVec = sizeMap(i => states(i).can2Lsq()) 454 val (r0_canSentIdx, r0_canSent) = PriorityEncoderWithFlag(r0_canSentVec) 455 resp.valid := r0_canSent 456 resp.bits := entries(r0_canSentIdx).toUncacheWordResp(r0_canSentIdx) 457 when(resp.fire){ 458 states(r0_canSentIdx).updateReturn() 459 } 460 461 462 /****************************************************************** 463 * Buffer Flush 464 * 1. when io.flush.valid is true: drain store queue and ubuffer 465 * 2. when io.lsq.req.bits.atomic is true: not support temporarily 466 ******************************************************************/ 467 empty := !VecInit(states.map(_.isValid())).asUInt.orR 468 io.flush.empty := empty 469 470 471 /****************************************************************** 472 * Load Data Forward to loadunit 473 * f0: vaddr match, fast resp 474 * f1: mask & data select, merge; paddr match; resp 475 * NOTE: forward.paddr from dtlb, which is far from uncache f0 476 ******************************************************************/ 477 478 val f0_validMask = sizeMap(i => isStore(entries(i)) && states(i).isValid()) 479 val f0_fwdMaskCandidates = VecInit(entries.map(e => e.mask)) 480 val f0_fwdDataCandidates = VecInit(entries.map(e => e.data)) 481 val f1_fwdMaskCandidates = sizeMap(i => RegEnable(entries(i).mask, f0_validMask(i))) 482 val f1_fwdDataCandidates = sizeMap(i => RegEnable(entries(i).data, f0_validMask(i))) 483 val f1_tagMismatchVec = Wire(Vec(LoadPipelineWidth, Bool())) 484 f1_needDrain := f1_tagMismatchVec.asUInt.orR && !empty 485 486 for ((forward, i) <- io.forward.zipWithIndex) { 487 val f0_fwdValid = forward.valid 488 val f1_fwdValid = RegNext(f0_fwdValid) 489 490 /* f0 */ 491 // vaddr match 492 val f0_vtagMatches = sizeMap(w => addrMatch(entries(w).vaddr, forward.vaddr)) 493 val f0_flyTagMatches = sizeMap(w => f0_vtagMatches(w) && f0_validMask(w) && f0_fwdValid && states(i).inflight) 494 val f0_idleTagMatches = sizeMap(w => f0_vtagMatches(w) && f0_validMask(w) && f0_fwdValid && !states(i).inflight) 495 // ONLY for fast use to get better timing 496 val f0_flyMaskFast = shiftMaskToHigh( 497 forward.vaddr, 498 Mux1H(f0_flyTagMatches, f0_fwdMaskCandidates) 499 ).asTypeOf(Vec(VDataBytes, Bool())) 500 val f0_idleMaskFast = shiftMaskToHigh( 501 forward.vaddr, 502 Mux1H(f0_idleTagMatches, f0_fwdMaskCandidates) 503 ).asTypeOf(Vec(VDataBytes, Bool())) 504 505 /* f1 */ 506 val f1_flyTagMatches = RegEnable(f0_flyTagMatches, f0_fwdValid) 507 val f1_idleTagMatches = RegEnable(f0_idleTagMatches, f0_fwdValid) 508 val f1_fwdPAddr = RegEnable(forward.paddr, f0_fwdValid) 509 // select 510 val f1_flyMask = Mux1H(f1_flyTagMatches, f1_fwdMaskCandidates) 511 val f1_flyData = Mux1H(f1_flyTagMatches, f1_fwdDataCandidates) 512 val f1_idleMask = Mux1H(f1_idleTagMatches, f1_fwdMaskCandidates) 513 val f1_idleData = Mux1H(f1_idleTagMatches, f1_fwdDataCandidates) 514 // merge old(inflight) and new(idle) 515 val (f1_fwdDataTmp, f1_fwdMaskTmp) = doMerge(f1_flyData, f1_flyMask, f1_idleData, f1_idleMask) 516 val f1_fwdMask = shiftMaskToHigh(f1_fwdPAddr, f1_fwdMaskTmp).asTypeOf(Vec(VDataBytes, Bool())) 517 val f1_fwdData = shiftDataToHigh(f1_fwdPAddr, f1_fwdDataTmp).asTypeOf(Vec(VDataBytes, UInt(8.W))) 518 // paddr match and mismatch judge 519 val f1_ptagMatches = sizeMap(w => addrMatch(RegEnable(entries(w).addr, f0_fwdValid), f1_fwdPAddr)) 520 f1_tagMismatchVec(i) := sizeMap(w => 521 RegEnable(f0_vtagMatches(w), f0_fwdValid) =/= f1_ptagMatches(w) && RegEnable(f0_validMask(w), f0_fwdValid) && f1_fwdValid 522 ).asUInt.orR 523 when(f1_tagMismatchVec(i)) { 524 XSDebug("forward tag mismatch: pmatch %x vmatch %x vaddr %x paddr %x\n", 525 f1_ptagMatches.asUInt, 526 RegEnable(f0_vtagMatches.asUInt, f0_fwdValid), 527 RegEnable(forward.vaddr, f0_fwdValid), 528 RegEnable(forward.paddr, f0_fwdValid) 529 ) 530 } 531 // response 532 forward.addrInvalid := false.B // addr in ubuffer is always ready 533 forward.dataInvalid := false.B // data in ubuffer is always ready 534 forward.matchInvalid := f1_tagMismatchVec(i) // paddr / vaddr cam result does not match 535 for (j <- 0 until VDataBytes) { 536 forward.forwardMaskFast(j) := f0_flyMaskFast(j) || f0_idleMaskFast(j) 537 538 forward.forwardData(j) := f1_fwdData(j) 539 forward.forwardMask(j) := false.B 540 when(f1_fwdMask(j) && f1_fwdValid) { 541 forward.forwardMask(j) := true.B 542 } 543 } 544 545 } 546 547 548 /****************************************************************** 549 * Debug / Performance 550 ******************************************************************/ 551 552 /* Debug Counters */ 553 // print all input/output requests for debug purpose 554 // print req/resp 555 XSDebug(req.fire, "req cmd: %x addr: %x data: %x mask: %x\n", 556 req.bits.cmd, req.bits.addr, req.bits.data, req.bits.mask) 557 XSDebug(resp.fire, "data: %x\n", req.bits.data) 558 // print tilelink messages 559 XSDebug(mem_acquire.valid, "mem_acquire valid, ready=%d ", mem_acquire.ready) 560 mem_acquire.bits.dump(mem_acquire.valid) 561 562 XSDebug(mem_grant.fire, "mem_grant fire ") 563 mem_grant.bits.dump(mem_grant.fire) 564 565 /* Performance Counters */ 566 XSPerfAccumulate("e0_reject", e0_reject && e0_req_valid) 567 XSPerfAccumulate("e0_total_enter", e0_fire) 568 XSPerfAccumulate("e0_merge", e0_fire && e0_canMerge) 569 XSPerfAccumulate("e0_alloc_simple", e0_fire && e0_canAlloc && !e0_allocWaitSame) 570 XSPerfAccumulate("e0_alloc_wait_same", e0_fire && e0_canAlloc && e0_allocWaitSame) 571 XSPerfAccumulate("q0_acquire", q0_canSent) 572 XSPerfAccumulate("q0_acquire_store", q0_canSent && q0_isStore) 573 XSPerfAccumulate("q0_acquire_load", q0_canSent && !q0_isStore) 574 XSPerfAccumulate("uncache_memBackTypeMM", io.lsq.req.fire && io.lsq.req.bits.memBackTypeMM) 575 XSPerfAccumulate("uncache_mmio_store", io.lsq.req.fire && isStore(io.lsq.req.bits.cmd) && !io.lsq.req.bits.nc) 576 XSPerfAccumulate("uncache_mmio_load", io.lsq.req.fire && !isStore(io.lsq.req.bits.cmd) && !io.lsq.req.bits.nc) 577 XSPerfAccumulate("uncache_nc_store", io.lsq.req.fire && isStore(io.lsq.req.bits.cmd) && io.lsq.req.bits.nc) 578 XSPerfAccumulate("uncache_nc_load", io.lsq.req.fire && !isStore(io.lsq.req.bits.cmd) && io.lsq.req.bits.nc) 579 XSPerfAccumulate("uncache_outstanding", uState =/= s_idle && mem_acquire.fire) 580 XSPerfAccumulate("forward_count", PopCount(io.forward.map(_.forwardMask.asUInt.orR))) 581 XSPerfAccumulate("forward_vaddr_match_failed", PopCount(f1_tagMismatchVec)) 582 583 val perfEvents = Seq( 584 ("uncache_mmio_store", io.lsq.req.fire && isStore(io.lsq.req.bits.cmd) && !io.lsq.req.bits.nc), 585 ("uncache_mmio_load", io.lsq.req.fire && !isStore(io.lsq.req.bits.cmd) && !io.lsq.req.bits.nc), 586 ("uncache_nc_store", io.lsq.req.fire && isStore(io.lsq.req.bits.cmd) && io.lsq.req.bits.nc), 587 ("uncache_nc_load", io.lsq.req.fire && !isStore(io.lsq.req.bits.cmd) && io.lsq.req.bits.nc), 588 ("uncache_outstanding", uState =/= s_idle && mem_acquire.fire), 589 ("forward_count", PopCount(io.forward.map(_.forwardMask.asUInt.orR))), 590 ("forward_vaddr_match_failed", PopCount(f1_tagMismatchVec)) 591 ) 592 593 generatePerfEvent() 594 // End 595} 596