2021-06-04 09:06:35 +08:00
|
|
|
/***************************************************************************************
|
2024-07-22 11:09:11 +08:00
|
|
|
* Copyright (c) 2024 Beijing Institute of Open Source Chip (BOSC)
|
|
|
|
* Copyright (c) 2020-2024 Institute of Computing Technology, Chinese Academy of Sciences
|
2021-07-24 23:26:38 +08:00
|
|
|
* Copyright (c) 2020-2021 Peng Cheng Laboratory
|
2021-06-04 09:06:35 +08:00
|
|
|
*
|
|
|
|
* XiangShan is licensed under Mulan PSL v2.
|
|
|
|
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
|
|
* You may obtain a copy of Mulan PSL v2 at:
|
|
|
|
* http://license.coscl.org.cn/MulanPSL2
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
|
|
|
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
|
|
|
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
|
|
*
|
|
|
|
* See the Mulan PSL v2 for more details.
|
|
|
|
***************************************************************************************/
|
|
|
|
|
2020-10-05 20:56:23 +08:00
|
|
|
package xiangshan.mem
|
|
|
|
|
2023-10-08 16:16:14 +08:00
|
|
|
import org.chipsalliance.cde.config.Parameters
|
2020-10-05 20:56:23 +08:00
|
|
|
import chisel3._
|
|
|
|
import chisel3.util._
|
|
|
|
import xiangshan._
|
|
|
|
import utils._
|
2022-12-25 14:52:31 +08:00
|
|
|
import utility._
|
2020-10-05 20:56:23 +08:00
|
|
|
import xiangshan.cache._
|
2024-04-03 02:27:43 +08:00
|
|
|
import xiangshan.mem._
|
|
|
|
import xiangshan.backend.Bundles.DynInst
|
2021-04-19 21:19:20 +08:00
|
|
|
import difftest._
|
2022-08-17 14:18:22 +08:00
|
|
|
import freechips.rocketchip.util._
|
2024-04-03 02:27:43 +08:00
|
|
|
import xiangshan.backend.fu.FuType._
|
2020-10-05 20:56:23 +08:00
|
|
|
|
2021-03-01 11:58:03 +08:00
|
|
|
class SbufferFlushBundle extends Bundle {
|
|
|
|
val valid = Output(Bool())
|
|
|
|
val empty = Input(Bool())
|
|
|
|
}
|
|
|
|
|
|
|
|
trait HasSbufferConst extends HasXSParameter {
|
2021-10-20 15:48:32 +08:00
|
|
|
val EvictCycles = 1 << 20
|
|
|
|
val SbufferReplayDelayCycles = 16
|
|
|
|
require(isPow2(EvictCycles))
|
|
|
|
val EvictCountBits = log2Up(EvictCycles+1)
|
|
|
|
val MissqReplayCountBits = log2Up(SbufferReplayDelayCycles) + 1
|
2021-01-13 21:13:56 +08:00
|
|
|
|
2022-08-10 09:54:52 +08:00
|
|
|
// dcache write hit resp has 2 sources
|
2024-04-25 10:23:18 +08:00
|
|
|
// refill pipe resp and main pipe resp (fixed:only main pipe resp)
|
|
|
|
// val NumDcacheWriteResp = 2 // hardcoded
|
|
|
|
val NumDcacheWriteResp = 1 // hardcoded
|
2022-08-10 09:54:52 +08:00
|
|
|
|
2020-10-05 20:56:23 +08:00
|
|
|
val SbufferIndexWidth: Int = log2Up(StoreBufferSize)
|
2021-08-03 14:28:43 +08:00
|
|
|
// paddr = ptag + offset
|
2020-10-05 20:56:23 +08:00
|
|
|
val CacheLineBytes: Int = CacheLineSize / 8
|
|
|
|
val CacheLineWords: Int = CacheLineBytes / DataBytes
|
|
|
|
val OffsetWidth: Int = log2Up(CacheLineBytes)
|
2020-12-28 16:35:14 +08:00
|
|
|
val WordsWidth: Int = log2Up(CacheLineWords)
|
2021-08-03 14:28:43 +08:00
|
|
|
val PTagWidth: Int = PAddrBits - OffsetWidth
|
|
|
|
val VTagWidth: Int = VAddrBits - OffsetWidth
|
2021-03-06 15:36:27 +08:00
|
|
|
val WordOffsetWidth: Int = PAddrBits - WordsWidth
|
2023-07-24 21:35:30 +08:00
|
|
|
|
|
|
|
val CacheLineVWords: Int = CacheLineBytes / VDataBytes
|
|
|
|
val VWordsWidth: Int = log2Up(CacheLineVWords)
|
|
|
|
val VWordWidth: Int = log2Up(VDataBytes)
|
|
|
|
val VWordOffsetWidth: Int = PAddrBits - VWordWidth
|
2020-10-05 20:56:23 +08:00
|
|
|
}
|
|
|
|
|
2021-10-20 15:48:32 +08:00
|
|
|
class SbufferEntryState (implicit p: Parameters) extends SbufferBundle {
|
|
|
|
val state_valid = Bool() // this entry is active
|
|
|
|
val state_inflight = Bool() // sbuffer is trying to write this entry to dcache
|
2021-11-29 11:34:37 +08:00
|
|
|
val w_timeout = Bool() // with timeout resp, waiting for resend store pipeline req timeout
|
|
|
|
val w_sameblock_inflight = Bool() // same cache block dcache req is inflight
|
2021-10-20 15:48:32 +08:00
|
|
|
|
|
|
|
def isInvalid(): Bool = !state_valid
|
|
|
|
def isValid(): Bool = state_valid
|
|
|
|
def isActive(): Bool = state_valid && !state_inflight
|
|
|
|
def isInflight(): Bool = state_inflight
|
2021-11-29 11:34:37 +08:00
|
|
|
def isDcacheReqCandidate(): Bool = state_valid && !state_inflight && !w_sameblock_inflight
|
2021-10-20 15:48:32 +08:00
|
|
|
}
|
|
|
|
|
2021-04-19 21:19:20 +08:00
|
|
|
class SbufferBundle(implicit p: Parameters) extends XSBundle with HasSbufferConst
|
2020-10-05 20:56:23 +08:00
|
|
|
|
2021-04-19 21:19:20 +08:00
|
|
|
class DataWriteReq(implicit p: Parameters) extends SbufferBundle {
|
2022-07-26 15:11:33 +08:00
|
|
|
// univerisal writemask
|
2021-12-21 17:07:58 +08:00
|
|
|
val wvec = UInt(StoreBufferSize.W)
|
2022-07-26 15:11:33 +08:00
|
|
|
// 2 cycle update
|
2023-07-24 21:35:30 +08:00
|
|
|
val mask = UInt((VLEN/8).W)
|
|
|
|
val data = UInt(VLEN.W)
|
|
|
|
val vwordOffset = UInt(VWordOffsetWidth.W)
|
2022-08-10 09:54:52 +08:00
|
|
|
val wline = Bool() // write full cacheline
|
|
|
|
}
|
|
|
|
|
|
|
|
class MaskFlushReq(implicit p: Parameters) extends SbufferBundle {
|
|
|
|
// univerisal writemask
|
|
|
|
val wvec = UInt(StoreBufferSize.W)
|
2021-03-06 15:36:27 +08:00
|
|
|
}
|
|
|
|
|
2021-04-19 21:19:20 +08:00
|
|
|
class SbufferData(implicit p: Parameters) extends XSModule with HasSbufferConst {
|
2021-03-06 15:36:27 +08:00
|
|
|
val io = IO(new Bundle(){
|
2022-08-10 09:54:52 +08:00
|
|
|
// update data and mask when alloc or merge
|
2022-05-06 23:01:31 +08:00
|
|
|
val writeReq = Vec(EnsbufferWidth, Flipped(ValidIO(new DataWriteReq)))
|
2022-08-10 09:54:52 +08:00
|
|
|
// clean mask when deq
|
|
|
|
val maskFlushReq = Vec(NumDcacheWriteResp, Flipped(ValidIO(new MaskFlushReq)))
|
2023-07-24 21:35:30 +08:00
|
|
|
val dataOut = Output(Vec(StoreBufferSize, Vec(CacheLineVWords, Vec(VDataBytes, UInt(8.W)))))
|
|
|
|
val maskOut = Output(Vec(StoreBufferSize, Vec(CacheLineVWords, Vec(VDataBytes, Bool()))))
|
2021-03-06 15:36:27 +08:00
|
|
|
})
|
|
|
|
|
2023-07-24 21:35:30 +08:00
|
|
|
val data = Reg(Vec(StoreBufferSize, Vec(CacheLineVWords, Vec(VDataBytes, UInt(8.W)))))
|
2022-08-10 09:54:52 +08:00
|
|
|
// val mask = Reg(Vec(StoreBufferSize, Vec(CacheLineWords, Vec(DataBytes, Bool()))))
|
|
|
|
val mask = RegInit(
|
|
|
|
VecInit(Seq.fill(StoreBufferSize)(
|
2023-07-24 21:35:30 +08:00
|
|
|
VecInit(Seq.fill(CacheLineVWords)(
|
|
|
|
VecInit(Seq.fill(VDataBytes)(false.B))
|
2022-08-10 09:54:52 +08:00
|
|
|
))
|
|
|
|
))
|
|
|
|
)
|
|
|
|
|
|
|
|
// 2 cycle line mask clean
|
|
|
|
for(line <- 0 until StoreBufferSize){
|
2024-06-16 19:13:35 +08:00
|
|
|
val line_mask_clean_flag = GatedValidRegNext(
|
2022-08-10 09:54:52 +08:00
|
|
|
io.maskFlushReq.map(a => a.valid && a.bits.wvec(line)).reduce(_ || _)
|
|
|
|
)
|
|
|
|
line_mask_clean_flag.suggestName("line_mask_clean_flag_"+line)
|
|
|
|
when(line_mask_clean_flag){
|
2023-07-24 21:35:30 +08:00
|
|
|
for(word <- 0 until CacheLineVWords){
|
|
|
|
for(byte <- 0 until VDataBytes){
|
2022-08-10 09:54:52 +08:00
|
|
|
mask(line)(word)(byte) := false.B
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-03-06 15:36:27 +08:00
|
|
|
|
2022-07-26 15:11:33 +08:00
|
|
|
// 2 cycle data / mask update
|
|
|
|
for(i <- 0 until EnsbufferWidth) {
|
|
|
|
val req = io.writeReq(i)
|
|
|
|
for(line <- 0 until StoreBufferSize){
|
|
|
|
val sbuffer_in_s1_line_wen = req.valid && req.bits.wvec(line)
|
2024-06-16 19:13:35 +08:00
|
|
|
val sbuffer_in_s2_line_wen = GatedValidRegNext(sbuffer_in_s1_line_wen)
|
2022-07-26 15:11:33 +08:00
|
|
|
val line_write_buffer_data = RegEnable(req.bits.data, sbuffer_in_s1_line_wen)
|
|
|
|
val line_write_buffer_wline = RegEnable(req.bits.wline, sbuffer_in_s1_line_wen)
|
|
|
|
val line_write_buffer_mask = RegEnable(req.bits.mask, sbuffer_in_s1_line_wen)
|
2023-07-24 21:35:30 +08:00
|
|
|
val line_write_buffer_offset = RegEnable(req.bits.vwordOffset(VWordsWidth-1, 0), sbuffer_in_s1_line_wen)
|
2022-07-26 15:11:33 +08:00
|
|
|
sbuffer_in_s1_line_wen.suggestName("sbuffer_in_s1_line_wen_"+line)
|
|
|
|
sbuffer_in_s2_line_wen.suggestName("sbuffer_in_s2_line_wen_"+line)
|
|
|
|
line_write_buffer_data.suggestName("line_write_buffer_data_"+line)
|
|
|
|
line_write_buffer_wline.suggestName("line_write_buffer_wline_"+line)
|
|
|
|
line_write_buffer_mask.suggestName("line_write_buffer_mask_"+line)
|
|
|
|
line_write_buffer_offset.suggestName("line_write_buffer_offset_"+line)
|
2023-07-24 21:35:30 +08:00
|
|
|
for(word <- 0 until CacheLineVWords){
|
|
|
|
for(byte <- 0 until VDataBytes){
|
2022-07-26 15:11:33 +08:00
|
|
|
val write_byte = sbuffer_in_s2_line_wen && (
|
2023-07-24 21:35:30 +08:00
|
|
|
line_write_buffer_mask(byte) && (line_write_buffer_offset === word.U) ||
|
2022-07-26 15:11:33 +08:00
|
|
|
line_write_buffer_wline
|
|
|
|
)
|
|
|
|
when(write_byte){
|
|
|
|
data(line)(word)(byte) := line_write_buffer_data(byte*8+7, byte*8)
|
|
|
|
mask(line)(word)(byte) := true.B
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-06 16:23:37 +08:00
|
|
|
|
2022-07-26 15:11:33 +08:00
|
|
|
// 1 cycle line mask clean
|
2022-08-10 09:54:52 +08:00
|
|
|
// for(i <- 0 until EnsbufferWidth) {
|
|
|
|
// val req = io.writeReq(i)
|
|
|
|
// when(req.valid){
|
|
|
|
// for(line <- 0 until StoreBufferSize){
|
|
|
|
// when(
|
2023-07-24 21:35:30 +08:00
|
|
|
// req.bits.wvec(line) &&
|
2022-08-10 09:54:52 +08:00
|
|
|
// req.bits.cleanMask
|
|
|
|
// ){
|
|
|
|
// for(word <- 0 until CacheLineWords){
|
|
|
|
// for(byte <- 0 until DataBytes){
|
|
|
|
// mask(line)(word)(byte) := false.B
|
|
|
|
// val debug_last_cycle_write_byte = RegNext(req.valid && req.bits.wvec(line) && (
|
2023-07-24 21:35:30 +08:00
|
|
|
// req.bits.mask(byte) && (req.bits.wordOffset(WordsWidth-1, 0) === word.U) ||
|
2022-08-10 09:54:52 +08:00
|
|
|
// req.bits.wline
|
|
|
|
// ))
|
|
|
|
// assert(!debug_last_cycle_write_byte)
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
2021-03-06 15:36:27 +08:00
|
|
|
|
|
|
|
io.dataOut := data
|
2022-07-26 15:11:33 +08:00
|
|
|
io.maskOut := mask
|
2020-10-05 20:56:23 +08:00
|
|
|
}
|
|
|
|
|
2024-04-03 02:27:43 +08:00
|
|
|
class Sbuffer(implicit p: Parameters)
|
|
|
|
extends DCacheModule
|
|
|
|
with HasSbufferConst
|
|
|
|
with HasPerfEvents {
|
2020-10-05 20:56:23 +08:00
|
|
|
val io = IO(new Bundle() {
|
2024-04-10 09:56:00 +08:00
|
|
|
val hartId = Input(UInt(hartIdLen.W))
|
L1 Prefetch (#2261)
* dcache: optimize the ready signal of missqueue
Add a custom arbiter. In the case of multiple sources with the same
cache block address, the arbiter will assign only one entry in
misssqueue but ready for all same cache block address requests.
This will reduce the number of replays of the load instruction which cannot
enter the missqueue
* sta, dcache: add A StorePipe in dcache
When the store command passes through the sta pipeline, access the tag
and meta of dcache to determine whether it hits, if it hits, update the
replacement algorithm, and if miss, send a write intent to missqueue
* sta prefetch: add a queue
Enter this queue when the Store Address pipeline sends a request,
determines that it has a cache miss, and the contention for MSHR fails.
The miss request in this queue will be sent to the Store pipeline later.
* sbuffer, dcache: store prefetch burst
A basic implementation of "Boosting Store Buffer Efficiency with
Store-Prefetch Bursts".
Store prefetch at exe is disabled.
Now, when store goes from sq to sbuffer, it will trigger a store
prefetch; when 48 stores fall into 6 cache lines, trigger a store burst
perfetch, which will bring a whole page back into dcache.
* dcache: restric mshr alloc for prefetch req
* restric the max number of entries which can be used by prefetch
* merge two same cache line address prefetch write req
* dynamically detect memset pattern, all mshr can accept prefetch when
pattern is detected
* spb: constantin support
* dcache: fix missqueue prefetch ready
* make prefetch req goes mshr with bigger id
* Revert "spb: constantin support"
This reverts commit 4ee50b89ba4a62cd28fa22d7fbcb2338ad4b1849.
* spb: fix bug in burst generator
* spb: add load prefetch burst support
* topdown: add defines of topdown counters enum
* redirect: add redirect type for perf
* top-down: add stallReason IOs
frontend -> ctrlBlock -> decode -> rename -> dispatch
* top-down: add dummy connections
* top-down: update TopdownCounters
* top-down: imp backend analysis and counter dump
* top-down: add HartId in `addSource`
* top-down: broadcast lqIdx of ROB head
* top-down: frontend signal done
* top-down: add memblock topdown interface
* Bump HuanCun: add TopDownMonitor
* top-down: receive and handle reasons in dispatch
* top-down: remove previous top-down code
* TopDown: add MemReqSource enum
* TopDown: extend mshr_latency range
* TopDown: add basic Req Source
TODO: distinguish prefetch
* store prefetch: refactor parameters and fix bug
* change some parameters
* fix store pipe bug
* fix load prefetch burst
* dcache: distinguish L1DataPrefetch and CPUData
* top-down: comment out debugging perf counters in ibuffer
* TopDown: add path to pass MemReqSource to HuanCun
* TopDown: use simpler logic to count reqSource and update Probe count
* frontend: update topdown counters
* Update HuanCun Topdown for MemReqSource
* top-down: fix load stalls
* top-down: Change the priority of different stall reasons
* store prefetch: add stride and l2 prefetch
* add a stride prefetcher
* spb and stride will issue prefetch to l2
* when store commits, issue a prefetch to l1
* sbuffer: fix eviction
* when valid count reaches StoreBufferSize, do eviction
* spf: change store prefetch structure
* prefetch @ exe -> l2 cache
* stride -> l2 cache
* sbuffer: fix replaceIdx
* If the way selected by the replacement algorithm cannot be written into dcache, its result is not used.
* Revert "sbuffer: fix replaceIdx"
This reverts commit 40c16aca956af9fb32554a0f12d18db41c22eecd.
* spf: find best interval in stamissqueue
* Revert "spf: find best interval in stamissqueue"
This reverts commit d179f0ce15a5ab989a822de7fe48cc5e2cd96914.
* sms: port store to sms
Miss store will train sms like load.
Now, sms will recieve 4 train sources, 2 for miss load, 2 for miss
store, but prefetcher consume 1 train req per cycle, PrefetchTrainFilter
is added to deal with this case.
* bump huancun
* spf: refactor structure
* miss stores will train sms, and send prefetch to l2
* miss stores will send prefetch to l1 on issue or commit
* spb will send prefetch to l1
* memset: fix memset detection
use lqEmpty to check this
* constantin: storepf constantin support
cherry-pick this to use constantin in storepf
* Revert "constantin: storepf constantin support"
This reverts commit 2b97767b9fa757d920cac3d80d4893a1380592c7.
* storepf: add EnableAtCommitMissTrigger
* trigger prefetch at commit only when the store misses with
EnableAtCommitMissTrigger
* bump coupledl2
* prefetch req from L1 to L2 will Acquire T
* fix merge conflict
* storepf: do not read meta&tag when pf is disabled
* storepf: do not read pcMem when sms store is disabled
* fix verilog check
* fix verilog
* missqueue: support merging prefetch
* prefetch req can be merged to pipeline reg
* merging prefetch write will update cmd
* delay sending out acquire when a prefetch write is about to merge
* missqueue: fix bug of merging prefetch write
* delay sending out acquire when a pipeline reg is about to merging a
prefetch write
* temp: disable store pf
* missqueue: disable merging prefetch
* late prefetch will be ignored
* check alias when merging
* enable store pf at issue
* add L1StreamPrefetcher
* fix assert
* let prefetch req prefer loadunit1 more than 0
* stream prefetcher
* disable stream component in SMS, SMS is only trained on real miss
* add a prefetcher monitor to adjust depth & confidence ..
* add L1 L2 stream prefetch
* add gene support
* Revert "add gene support"
This reverts commit 59ae15640ff3d1cc96347f4d3567d48c740a03bb.
* add miss db
* l1pf: add stride & store source info in cache meta
* add a Stride prefetcher and disable Stride component in sms
* prefetch bit in meta is expanded into 3 bits to store source info of
prefetcher
* prefetch: support sending prefetch req to l3
* l1pf: add FDP & refactor
* add basic FDP counters
* change stride from Block addr to Byte addr
* refactor the code
* bump submodules
* disable load related chiseldb to reduce db size
* fix compile
* fix minimalConfig & enable stream
* fix stride pc problem
* fix minimalconfig compile
* bump submodules
* refactor stream stride helper
* fix compile
* bump huancun
* disable db to save size
* fix l2 assert
* bump submodules
---------
Co-authored-by: tastynoob <934348725@qq.com>
Co-authored-by: Haojin Tang <tanghaojin@outlook.com>
Co-authored-by: Guokai Chen <chenguokai17@mails.ucas.ac.cn>
Co-authored-by: XiChen <chenxi171@mails.ucas.ac.cn>
Co-authored-by: Zhou Yaoyang <shinezyy@qq.com>
2023-09-06 16:07:59 +08:00
|
|
|
val in = Vec(EnsbufferWidth, Flipped(Decoupled(new DCacheWordReqWithVaddrAndPfFlag))) //Todo: store logic only support Width == 2 now
|
2024-04-03 02:27:43 +08:00
|
|
|
val vecDifftestInfo = Vec(EnsbufferWidth, Flipped(Decoupled(new DynInst)))
|
2021-10-20 15:48:32 +08:00
|
|
|
val dcache = Flipped(new DCacheToSbufferIO)
|
2020-10-05 20:56:23 +08:00
|
|
|
val forward = Vec(LoadPipelineWidth, Flipped(new LoadForwardQueryIO))
|
2021-01-19 00:38:21 +08:00
|
|
|
val sqempty = Input(Bool())
|
2021-03-01 11:58:03 +08:00
|
|
|
val flush = Flipped(new SbufferFlushBundle)
|
2021-03-04 08:59:19 +08:00
|
|
|
val csrCtrl = Flipped(new CustomCSRCtrlIO)
|
L1 Prefetch (#2261)
* dcache: optimize the ready signal of missqueue
Add a custom arbiter. In the case of multiple sources with the same
cache block address, the arbiter will assign only one entry in
misssqueue but ready for all same cache block address requests.
This will reduce the number of replays of the load instruction which cannot
enter the missqueue
* sta, dcache: add A StorePipe in dcache
When the store command passes through the sta pipeline, access the tag
and meta of dcache to determine whether it hits, if it hits, update the
replacement algorithm, and if miss, send a write intent to missqueue
* sta prefetch: add a queue
Enter this queue when the Store Address pipeline sends a request,
determines that it has a cache miss, and the contention for MSHR fails.
The miss request in this queue will be sent to the Store pipeline later.
* sbuffer, dcache: store prefetch burst
A basic implementation of "Boosting Store Buffer Efficiency with
Store-Prefetch Bursts".
Store prefetch at exe is disabled.
Now, when store goes from sq to sbuffer, it will trigger a store
prefetch; when 48 stores fall into 6 cache lines, trigger a store burst
perfetch, which will bring a whole page back into dcache.
* dcache: restric mshr alloc for prefetch req
* restric the max number of entries which can be used by prefetch
* merge two same cache line address prefetch write req
* dynamically detect memset pattern, all mshr can accept prefetch when
pattern is detected
* spb: constantin support
* dcache: fix missqueue prefetch ready
* make prefetch req goes mshr with bigger id
* Revert "spb: constantin support"
This reverts commit 4ee50b89ba4a62cd28fa22d7fbcb2338ad4b1849.
* spb: fix bug in burst generator
* spb: add load prefetch burst support
* topdown: add defines of topdown counters enum
* redirect: add redirect type for perf
* top-down: add stallReason IOs
frontend -> ctrlBlock -> decode -> rename -> dispatch
* top-down: add dummy connections
* top-down: update TopdownCounters
* top-down: imp backend analysis and counter dump
* top-down: add HartId in `addSource`
* top-down: broadcast lqIdx of ROB head
* top-down: frontend signal done
* top-down: add memblock topdown interface
* Bump HuanCun: add TopDownMonitor
* top-down: receive and handle reasons in dispatch
* top-down: remove previous top-down code
* TopDown: add MemReqSource enum
* TopDown: extend mshr_latency range
* TopDown: add basic Req Source
TODO: distinguish prefetch
* store prefetch: refactor parameters and fix bug
* change some parameters
* fix store pipe bug
* fix load prefetch burst
* dcache: distinguish L1DataPrefetch and CPUData
* top-down: comment out debugging perf counters in ibuffer
* TopDown: add path to pass MemReqSource to HuanCun
* TopDown: use simpler logic to count reqSource and update Probe count
* frontend: update topdown counters
* Update HuanCun Topdown for MemReqSource
* top-down: fix load stalls
* top-down: Change the priority of different stall reasons
* store prefetch: add stride and l2 prefetch
* add a stride prefetcher
* spb and stride will issue prefetch to l2
* when store commits, issue a prefetch to l1
* sbuffer: fix eviction
* when valid count reaches StoreBufferSize, do eviction
* spf: change store prefetch structure
* prefetch @ exe -> l2 cache
* stride -> l2 cache
* sbuffer: fix replaceIdx
* If the way selected by the replacement algorithm cannot be written into dcache, its result is not used.
* Revert "sbuffer: fix replaceIdx"
This reverts commit 40c16aca956af9fb32554a0f12d18db41c22eecd.
* spf: find best interval in stamissqueue
* Revert "spf: find best interval in stamissqueue"
This reverts commit d179f0ce15a5ab989a822de7fe48cc5e2cd96914.
* sms: port store to sms
Miss store will train sms like load.
Now, sms will recieve 4 train sources, 2 for miss load, 2 for miss
store, but prefetcher consume 1 train req per cycle, PrefetchTrainFilter
is added to deal with this case.
* bump huancun
* spf: refactor structure
* miss stores will train sms, and send prefetch to l2
* miss stores will send prefetch to l1 on issue or commit
* spb will send prefetch to l1
* memset: fix memset detection
use lqEmpty to check this
* constantin: storepf constantin support
cherry-pick this to use constantin in storepf
* Revert "constantin: storepf constantin support"
This reverts commit 2b97767b9fa757d920cac3d80d4893a1380592c7.
* storepf: add EnableAtCommitMissTrigger
* trigger prefetch at commit only when the store misses with
EnableAtCommitMissTrigger
* bump coupledl2
* prefetch req from L1 to L2 will Acquire T
* fix merge conflict
* storepf: do not read meta&tag when pf is disabled
* storepf: do not read pcMem when sms store is disabled
* fix verilog check
* fix verilog
* missqueue: support merging prefetch
* prefetch req can be merged to pipeline reg
* merging prefetch write will update cmd
* delay sending out acquire when a prefetch write is about to merge
* missqueue: fix bug of merging prefetch write
* delay sending out acquire when a pipeline reg is about to merging a
prefetch write
* temp: disable store pf
* missqueue: disable merging prefetch
* late prefetch will be ignored
* check alias when merging
* enable store pf at issue
* add L1StreamPrefetcher
* fix assert
* let prefetch req prefer loadunit1 more than 0
* stream prefetcher
* disable stream component in SMS, SMS is only trained on real miss
* add a prefetcher monitor to adjust depth & confidence ..
* add L1 L2 stream prefetch
* add gene support
* Revert "add gene support"
This reverts commit 59ae15640ff3d1cc96347f4d3567d48c740a03bb.
* add miss db
* l1pf: add stride & store source info in cache meta
* add a Stride prefetcher and disable Stride component in sms
* prefetch bit in meta is expanded into 3 bits to store source info of
prefetcher
* prefetch: support sending prefetch req to l3
* l1pf: add FDP & refactor
* add basic FDP counters
* change stride from Block addr to Byte addr
* refactor the code
* bump submodules
* disable load related chiseldb to reduce db size
* fix compile
* fix minimalConfig & enable stream
* fix stride pc problem
* fix minimalconfig compile
* bump submodules
* refactor stream stride helper
* fix compile
* bump huancun
* disable db to save size
* fix l2 assert
* bump submodules
---------
Co-authored-by: tastynoob <934348725@qq.com>
Co-authored-by: Haojin Tang <tanghaojin@outlook.com>
Co-authored-by: Guokai Chen <chenguokai17@mails.ucas.ac.cn>
Co-authored-by: XiChen <chenxi171@mails.ucas.ac.cn>
Co-authored-by: Zhou Yaoyang <shinezyy@qq.com>
2023-09-06 16:07:59 +08:00
|
|
|
val store_prefetch = Vec(StorePipelineWidth, DecoupledIO(new StorePrefetchReq)) // to dcache
|
|
|
|
val memSetPattenDetected = Input(Bool())
|
2023-07-25 13:30:51 +08:00
|
|
|
val force_write = Input(Bool())
|
2020-10-05 20:56:23 +08:00
|
|
|
})
|
|
|
|
|
2021-03-06 15:36:27 +08:00
|
|
|
val dataModule = Module(new SbufferData)
|
|
|
|
dataModule.io.writeReq <> DontCare
|
L1 Prefetch (#2261)
* dcache: optimize the ready signal of missqueue
Add a custom arbiter. In the case of multiple sources with the same
cache block address, the arbiter will assign only one entry in
misssqueue but ready for all same cache block address requests.
This will reduce the number of replays of the load instruction which cannot
enter the missqueue
* sta, dcache: add A StorePipe in dcache
When the store command passes through the sta pipeline, access the tag
and meta of dcache to determine whether it hits, if it hits, update the
replacement algorithm, and if miss, send a write intent to missqueue
* sta prefetch: add a queue
Enter this queue when the Store Address pipeline sends a request,
determines that it has a cache miss, and the contention for MSHR fails.
The miss request in this queue will be sent to the Store pipeline later.
* sbuffer, dcache: store prefetch burst
A basic implementation of "Boosting Store Buffer Efficiency with
Store-Prefetch Bursts".
Store prefetch at exe is disabled.
Now, when store goes from sq to sbuffer, it will trigger a store
prefetch; when 48 stores fall into 6 cache lines, trigger a store burst
perfetch, which will bring a whole page back into dcache.
* dcache: restric mshr alloc for prefetch req
* restric the max number of entries which can be used by prefetch
* merge two same cache line address prefetch write req
* dynamically detect memset pattern, all mshr can accept prefetch when
pattern is detected
* spb: constantin support
* dcache: fix missqueue prefetch ready
* make prefetch req goes mshr with bigger id
* Revert "spb: constantin support"
This reverts commit 4ee50b89ba4a62cd28fa22d7fbcb2338ad4b1849.
* spb: fix bug in burst generator
* spb: add load prefetch burst support
* topdown: add defines of topdown counters enum
* redirect: add redirect type for perf
* top-down: add stallReason IOs
frontend -> ctrlBlock -> decode -> rename -> dispatch
* top-down: add dummy connections
* top-down: update TopdownCounters
* top-down: imp backend analysis and counter dump
* top-down: add HartId in `addSource`
* top-down: broadcast lqIdx of ROB head
* top-down: frontend signal done
* top-down: add memblock topdown interface
* Bump HuanCun: add TopDownMonitor
* top-down: receive and handle reasons in dispatch
* top-down: remove previous top-down code
* TopDown: add MemReqSource enum
* TopDown: extend mshr_latency range
* TopDown: add basic Req Source
TODO: distinguish prefetch
* store prefetch: refactor parameters and fix bug
* change some parameters
* fix store pipe bug
* fix load prefetch burst
* dcache: distinguish L1DataPrefetch and CPUData
* top-down: comment out debugging perf counters in ibuffer
* TopDown: add path to pass MemReqSource to HuanCun
* TopDown: use simpler logic to count reqSource and update Probe count
* frontend: update topdown counters
* Update HuanCun Topdown for MemReqSource
* top-down: fix load stalls
* top-down: Change the priority of different stall reasons
* store prefetch: add stride and l2 prefetch
* add a stride prefetcher
* spb and stride will issue prefetch to l2
* when store commits, issue a prefetch to l1
* sbuffer: fix eviction
* when valid count reaches StoreBufferSize, do eviction
* spf: change store prefetch structure
* prefetch @ exe -> l2 cache
* stride -> l2 cache
* sbuffer: fix replaceIdx
* If the way selected by the replacement algorithm cannot be written into dcache, its result is not used.
* Revert "sbuffer: fix replaceIdx"
This reverts commit 40c16aca956af9fb32554a0f12d18db41c22eecd.
* spf: find best interval in stamissqueue
* Revert "spf: find best interval in stamissqueue"
This reverts commit d179f0ce15a5ab989a822de7fe48cc5e2cd96914.
* sms: port store to sms
Miss store will train sms like load.
Now, sms will recieve 4 train sources, 2 for miss load, 2 for miss
store, but prefetcher consume 1 train req per cycle, PrefetchTrainFilter
is added to deal with this case.
* bump huancun
* spf: refactor structure
* miss stores will train sms, and send prefetch to l2
* miss stores will send prefetch to l1 on issue or commit
* spb will send prefetch to l1
* memset: fix memset detection
use lqEmpty to check this
* constantin: storepf constantin support
cherry-pick this to use constantin in storepf
* Revert "constantin: storepf constantin support"
This reverts commit 2b97767b9fa757d920cac3d80d4893a1380592c7.
* storepf: add EnableAtCommitMissTrigger
* trigger prefetch at commit only when the store misses with
EnableAtCommitMissTrigger
* bump coupledl2
* prefetch req from L1 to L2 will Acquire T
* fix merge conflict
* storepf: do not read meta&tag when pf is disabled
* storepf: do not read pcMem when sms store is disabled
* fix verilog check
* fix verilog
* missqueue: support merging prefetch
* prefetch req can be merged to pipeline reg
* merging prefetch write will update cmd
* delay sending out acquire when a prefetch write is about to merge
* missqueue: fix bug of merging prefetch write
* delay sending out acquire when a pipeline reg is about to merging a
prefetch write
* temp: disable store pf
* missqueue: disable merging prefetch
* late prefetch will be ignored
* check alias when merging
* enable store pf at issue
* add L1StreamPrefetcher
* fix assert
* let prefetch req prefer loadunit1 more than 0
* stream prefetcher
* disable stream component in SMS, SMS is only trained on real miss
* add a prefetcher monitor to adjust depth & confidence ..
* add L1 L2 stream prefetch
* add gene support
* Revert "add gene support"
This reverts commit 59ae15640ff3d1cc96347f4d3567d48c740a03bb.
* add miss db
* l1pf: add stride & store source info in cache meta
* add a Stride prefetcher and disable Stride component in sms
* prefetch bit in meta is expanded into 3 bits to store source info of
prefetcher
* prefetch: support sending prefetch req to l3
* l1pf: add FDP & refactor
* add basic FDP counters
* change stride from Block addr to Byte addr
* refactor the code
* bump submodules
* disable load related chiseldb to reduce db size
* fix compile
* fix minimalConfig & enable stream
* fix stride pc problem
* fix minimalconfig compile
* bump submodules
* refactor stream stride helper
* fix compile
* bump huancun
* disable db to save size
* fix l2 assert
* bump submodules
---------
Co-authored-by: tastynoob <934348725@qq.com>
Co-authored-by: Haojin Tang <tanghaojin@outlook.com>
Co-authored-by: Guokai Chen <chenguokai17@mails.ucas.ac.cn>
Co-authored-by: XiChen <chenxi171@mails.ucas.ac.cn>
Co-authored-by: Zhou Yaoyang <shinezyy@qq.com>
2023-09-06 16:07:59 +08:00
|
|
|
val prefetcher = Module(new StorePfWrapper())
|
2021-03-06 15:36:27 +08:00
|
|
|
val writeReq = dataModule.io.writeReq
|
|
|
|
|
2021-08-03 14:28:43 +08:00
|
|
|
val ptag = Reg(Vec(StoreBufferSize, UInt(PTagWidth.W)))
|
|
|
|
val vtag = Reg(Vec(StoreBufferSize, UInt(VTagWidth.W)))
|
2022-07-26 15:11:33 +08:00
|
|
|
val debug_mask = Reg(Vec(StoreBufferSize, Vec(CacheLineWords, Vec(DataBytes, Bool()))))
|
2021-11-29 11:34:37 +08:00
|
|
|
val waitInflightMask = Reg(Vec(StoreBufferSize, UInt(StoreBufferSize.W)))
|
2021-03-06 15:36:27 +08:00
|
|
|
val data = dataModule.io.dataOut
|
2022-07-26 15:11:33 +08:00
|
|
|
val mask = dataModule.io.maskOut
|
2021-10-20 15:48:32 +08:00
|
|
|
val stateVec = RegInit(VecInit(Seq.fill(StoreBufferSize)(0.U.asTypeOf(new SbufferEntryState))))
|
|
|
|
val cohCount = RegInit(VecInit(Seq.fill(StoreBufferSize)(0.U(EvictCountBits.W))))
|
|
|
|
val missqReplayCount = RegInit(VecInit(Seq.fill(StoreBufferSize)(0.U(MissqReplayCountBits.W))))
|
2021-03-23 23:46:04 +08:00
|
|
|
|
2022-07-24 18:28:25 +08:00
|
|
|
val sbuffer_out_s0_fire = Wire(Bool())
|
2021-11-15 15:55:13 +08:00
|
|
|
|
2020-10-05 20:56:23 +08:00
|
|
|
/*
|
2021-08-03 21:41:19 +08:00
|
|
|
idle --[flush] --> drain --[buf empty]--> idle
|
2020-10-05 20:56:23 +08:00
|
|
|
--[buf full]--> replace --[dcache resp]--> idle
|
2021-01-13 21:13:56 +08:00
|
|
|
*/
|
2021-08-03 21:41:19 +08:00
|
|
|
// x_drain_all: drain store queue and sbuffer
|
|
|
|
// x_drain_sbuffer: drain sbuffer only, block store queue to sbuffer write
|
|
|
|
val x_idle :: x_replace :: x_drain_all :: x_drain_sbuffer :: Nil = Enum(4)
|
|
|
|
def needDrain(state: UInt): Bool =
|
|
|
|
state(1)
|
2020-10-05 20:56:23 +08:00
|
|
|
val sbuffer_state = RegInit(x_idle)
|
|
|
|
|
|
|
|
// ---------------------- Store Enq Sbuffer ---------------------
|
|
|
|
|
2021-08-03 14:28:43 +08:00
|
|
|
def getPTag(pa: UInt): UInt =
|
|
|
|
pa(PAddrBits - 1, PAddrBits - PTagWidth)
|
|
|
|
|
|
|
|
def getVTag(va: UInt): UInt =
|
|
|
|
va(VAddrBits - 1, VAddrBits - VTagWidth)
|
2020-10-05 20:56:23 +08:00
|
|
|
|
2021-01-04 19:37:37 +08:00
|
|
|
def getWord(pa: UInt): UInt =
|
|
|
|
pa(PAddrBits-1, 3)
|
|
|
|
|
2023-07-24 21:35:30 +08:00
|
|
|
def getVWord(pa: UInt): UInt =
|
|
|
|
pa(PAddrBits-1, 4)
|
|
|
|
|
2020-12-28 16:35:14 +08:00
|
|
|
def getWordOffset(pa: UInt): UInt =
|
|
|
|
pa(OffsetWidth-1, 3)
|
|
|
|
|
2023-07-24 21:35:30 +08:00
|
|
|
def getVWordOffset(pa: UInt): UInt =
|
|
|
|
pa(OffsetWidth-1, 4)
|
|
|
|
|
2021-08-03 14:28:43 +08:00
|
|
|
def getAddr(ptag: UInt): UInt =
|
|
|
|
Cat(ptag, 0.U((PAddrBits - PTagWidth).W))
|
2020-10-05 20:56:23 +08:00
|
|
|
|
2020-12-28 16:35:14 +08:00
|
|
|
def getByteOffset(offect: UInt): UInt =
|
|
|
|
Cat(offect(OffsetWidth - 1, 3), 0.U(3.W))
|
2020-10-05 20:56:23 +08:00
|
|
|
|
2020-10-07 14:43:14 +08:00
|
|
|
def isOneOf(key: UInt, seq: Seq[UInt]): Bool =
|
2023-09-21 10:02:22 +08:00
|
|
|
if(seq.isEmpty) false.B else Cat(seq.map(_===key)).orR
|
2020-10-05 20:56:23 +08:00
|
|
|
|
2020-12-16 10:07:15 +08:00
|
|
|
def widthMap[T <: Data](f: Int => T) = (0 until StoreBufferSize) map f
|
2020-10-05 20:56:23 +08:00
|
|
|
|
2020-12-28 16:35:14 +08:00
|
|
|
// sbuffer entry count
|
|
|
|
|
2023-07-25 13:30:51 +08:00
|
|
|
val plru = new ValidPseudoLRU(StoreBufferSize)
|
2022-05-06 23:01:31 +08:00
|
|
|
val accessIdx = Wire(Vec(EnsbufferWidth + 1, Valid(UInt(SbufferIndexWidth.W))))
|
2021-03-03 12:23:09 +08:00
|
|
|
|
2023-06-02 18:27:43 +08:00
|
|
|
val candidateVec = VecInit(stateVec.map(s => s.isDcacheReqCandidate()))
|
|
|
|
|
2023-07-25 13:30:51 +08:00
|
|
|
val replaceAlgoIdx = plru.way(candidateVec.reverse)._2
|
2023-06-02 18:27:43 +08:00
|
|
|
val replaceAlgoNotDcacheCandidate = !stateVec(replaceAlgoIdx).isDcacheReqCandidate()
|
|
|
|
|
2023-09-21 10:02:22 +08:00
|
|
|
assert(!(candidateVec.asUInt.orR && replaceAlgoNotDcacheCandidate), "we have way to select, but replace algo selects invalid way")
|
2023-07-25 13:30:51 +08:00
|
|
|
|
|
|
|
val replaceIdx = replaceAlgoIdx
|
2021-03-03 12:23:09 +08:00
|
|
|
plru.access(accessIdx)
|
|
|
|
|
2021-03-04 17:16:47 +08:00
|
|
|
//-------------------------cohCount-----------------------------
|
|
|
|
// insert and merge: cohCount=0
|
|
|
|
// every cycle cohCount+=1
|
2021-10-20 15:48:32 +08:00
|
|
|
// if cohCount(EvictCountBits-1)==1, evict
|
|
|
|
val cohTimeOutMask = VecInit(widthMap(i => cohCount(i)(EvictCountBits - 1) && stateVec(i).isActive()))
|
|
|
|
val (cohTimeOutIdx, cohHasTimeOut) = PriorityEncoderWithFlag(cohTimeOutMask)
|
2022-07-28 19:51:17 +08:00
|
|
|
val cohTimeOutOH = PriorityEncoderOH(cohTimeOutMask)
|
2021-10-20 15:48:32 +08:00
|
|
|
val missqReplayTimeOutMask = VecInit(widthMap(i => missqReplayCount(i)(MissqReplayCountBits - 1) && stateVec(i).w_timeout))
|
2022-07-28 19:51:17 +08:00
|
|
|
val (missqReplayTimeOutIdxGen, missqReplayHasTimeOutGen) = PriorityEncoderWithFlag(missqReplayTimeOutMask)
|
2024-06-16 19:13:35 +08:00
|
|
|
val missqReplayHasTimeOut = GatedValidRegNext(missqReplayHasTimeOutGen) && !GatedValidRegNext(sbuffer_out_s0_fire)
|
2022-07-28 19:51:17 +08:00
|
|
|
val missqReplayTimeOutIdx = RegEnable(missqReplayTimeOutIdxGen, missqReplayHasTimeOutGen)
|
2021-03-04 17:16:47 +08:00
|
|
|
|
2022-07-26 15:11:33 +08:00
|
|
|
//-------------------------sbuffer enqueue-----------------------------
|
|
|
|
|
|
|
|
// Now sbuffer enq logic is divided into 3 stages:
|
|
|
|
|
2023-07-24 21:35:30 +08:00
|
|
|
// sbuffer_in_s0:
|
2022-07-26 15:11:33 +08:00
|
|
|
// * read data and meta from store queue
|
|
|
|
// * store them in 2 entry fifo queue
|
|
|
|
|
2023-07-24 21:35:30 +08:00
|
|
|
// sbuffer_in_s1:
|
2022-07-26 15:11:33 +08:00
|
|
|
// * read data and meta from fifo queue
|
|
|
|
// * update sbuffer meta (vtag, ptag, flag)
|
|
|
|
// * prevert that line from being sent to dcache (add a block condition)
|
2023-07-24 21:35:30 +08:00
|
|
|
// * prepare cacheline level write enable signal, RegNext() data and mask
|
2022-07-26 15:11:33 +08:00
|
|
|
|
2023-07-24 21:35:30 +08:00
|
|
|
// sbuffer_in_s2:
|
2022-07-26 15:11:33 +08:00
|
|
|
// * use cacheline level buffer to update sbuffer data and mask
|
|
|
|
// * remove dcache write block (if there is)
|
|
|
|
|
2021-10-20 15:48:32 +08:00
|
|
|
val activeMask = VecInit(stateVec.map(s => s.isActive()))
|
2023-06-02 18:27:43 +08:00
|
|
|
val validMask = VecInit(stateVec.map(s => s.isValid()))
|
2021-10-20 15:48:32 +08:00
|
|
|
val drainIdx = PriorityEncoder(activeMask)
|
2021-01-13 21:13:56 +08:00
|
|
|
|
2021-10-20 15:48:32 +08:00
|
|
|
val inflightMask = VecInit(stateVec.map(s => s.isInflight()))
|
2021-01-04 19:37:37 +08:00
|
|
|
|
2021-08-03 14:28:43 +08:00
|
|
|
val inptags = io.in.map(in => getPTag(in.bits.addr))
|
|
|
|
val invtags = io.in.map(in => getVTag(in.bits.vaddr))
|
2024-08-05 15:25:46 +08:00
|
|
|
val sameTag = inptags(0) === inptags(1) && io.in(0).valid && io.in(1).valid && io.in(0).bits.vecValid && io.in(1).bits.vecValid
|
2023-07-24 21:35:30 +08:00
|
|
|
val firstWord = getVWord(io.in(0).bits.addr)
|
|
|
|
val secondWord = getVWord(io.in(1).bits.addr)
|
2021-01-04 19:37:37 +08:00
|
|
|
// merge condition
|
2022-05-06 23:01:31 +08:00
|
|
|
val mergeMask = Wire(Vec(EnsbufferWidth, Vec(StoreBufferSize, Bool())))
|
2021-12-21 17:07:58 +08:00
|
|
|
val mergeIdx = mergeMask.map(PriorityEncoder(_)) // avoid using mergeIdx for better timing
|
2020-12-28 16:35:14 +08:00
|
|
|
val canMerge = mergeMask.map(ParallelOR(_))
|
2021-12-21 17:07:58 +08:00
|
|
|
val mergeVec = mergeMask.map(_.asUInt)
|
2021-01-04 19:37:37 +08:00
|
|
|
|
2022-05-06 23:01:31 +08:00
|
|
|
for(i <- 0 until EnsbufferWidth){
|
2020-12-28 16:35:14 +08:00
|
|
|
mergeMask(i) := widthMap(j =>
|
2021-10-20 15:48:32 +08:00
|
|
|
inptags(i) === ptag(j) && activeMask(j)
|
2021-02-02 18:30:29 +08:00
|
|
|
)
|
2024-04-05 17:47:56 +08:00
|
|
|
assert(!(PopCount(mergeMask(i).asUInt) > 1.U && io.in(i).fire && io.in(i).bits.vecValid))
|
2020-12-28 16:35:14 +08:00
|
|
|
}
|
|
|
|
|
2021-03-04 17:16:47 +08:00
|
|
|
// insert condition
|
2021-01-04 19:37:37 +08:00
|
|
|
// firstInsert: the first invalid entry
|
2021-08-03 14:28:43 +08:00
|
|
|
// if first entry canMerge or second entry has the same ptag with the first entry,
|
2021-03-04 17:16:47 +08:00
|
|
|
// secondInsert equal the first invalid entry, otherwise, the second invalid entry
|
2021-10-20 15:48:32 +08:00
|
|
|
val invalidMask = VecInit(stateVec.map(s => s.isInvalid()))
|
2022-11-18 14:07:57 +08:00
|
|
|
val evenInvalidMask = GetEvenBits(invalidMask.asUInt)
|
|
|
|
val oddInvalidMask = GetOddBits(invalidMask.asUInt)
|
2021-01-28 17:31:09 +08:00
|
|
|
|
2021-12-21 17:07:58 +08:00
|
|
|
def getFirstOneOH(input: UInt): UInt = {
|
|
|
|
assert(input.getWidth > 1)
|
|
|
|
val output = WireInit(VecInit(input.asBools))
|
|
|
|
(1 until input.getWidth).map(i => {
|
|
|
|
output(i) := !input(i - 1, 0).orR && input(i)
|
|
|
|
})
|
|
|
|
output.asUInt
|
|
|
|
}
|
|
|
|
|
2022-11-18 14:07:57 +08:00
|
|
|
val evenRawInsertVec = getFirstOneOH(evenInvalidMask)
|
|
|
|
val oddRawInsertVec = getFirstOneOH(oddInvalidMask)
|
|
|
|
val (evenRawInsertIdx, evenCanInsert) = PriorityEncoderWithFlag(evenInvalidMask)
|
|
|
|
val (oddRawInsertIdx, oddCanInsert) = PriorityEncoderWithFlag(oddInvalidMask)
|
|
|
|
val evenInsertIdx = Cat(evenRawInsertIdx, 0.U(1.W)) // slow to generate, for debug only
|
|
|
|
val oddInsertIdx = Cat(oddRawInsertIdx, 1.U(1.W)) // slow to generate, for debug only
|
|
|
|
val evenInsertVec = GetEvenBits.reverse(evenRawInsertVec)
|
|
|
|
val oddInsertVec = GetOddBits.reverse(oddRawInsertVec)
|
|
|
|
|
|
|
|
val enbufferSelReg = RegInit(false.B)
|
|
|
|
when(io.in(0).valid) {
|
|
|
|
enbufferSelReg := ~enbufferSelReg
|
2020-12-28 16:35:14 +08:00
|
|
|
}
|
|
|
|
|
2022-11-18 14:07:57 +08:00
|
|
|
val firstInsertIdx = Mux(enbufferSelReg, evenInsertIdx, oddInsertIdx) // slow to generate, for debug only
|
|
|
|
val secondInsertIdx = Mux(sameTag,
|
|
|
|
firstInsertIdx,
|
|
|
|
Mux(~enbufferSelReg, evenInsertIdx, oddInsertIdx)
|
2021-12-21 17:07:58 +08:00
|
|
|
) // slow to generate, for debug only
|
2022-11-18 14:07:57 +08:00
|
|
|
val firstInsertVec = Mux(enbufferSelReg, evenInsertVec, oddInsertVec)
|
|
|
|
val secondInsertVec = Mux(sameTag,
|
|
|
|
firstInsertVec,
|
|
|
|
Mux(~enbufferSelReg, evenInsertVec, oddInsertVec)
|
2021-12-21 17:07:58 +08:00
|
|
|
) // slow to generate, for debug only
|
2022-11-18 14:07:57 +08:00
|
|
|
val firstCanInsert = sbuffer_state =/= x_drain_sbuffer && Mux(enbufferSelReg, evenCanInsert, oddCanInsert)
|
|
|
|
val secondCanInsert = sbuffer_state =/= x_drain_sbuffer && Mux(sameTag,
|
|
|
|
firstCanInsert,
|
|
|
|
Mux(~enbufferSelReg, evenCanInsert, oddCanInsert)
|
|
|
|
) && (EnsbufferWidth >= 1).B
|
2021-11-15 15:55:13 +08:00
|
|
|
val forward_need_uarch_drain = WireInit(false.B)
|
|
|
|
val merge_need_uarch_drain = WireInit(false.B)
|
2024-06-16 19:13:35 +08:00
|
|
|
val do_uarch_drain = GatedValidRegNext(forward_need_uarch_drain) || GatedValidRegNext(GatedValidRegNext(merge_need_uarch_drain))
|
2021-08-03 21:41:19 +08:00
|
|
|
XSPerfAccumulate("do_uarch_drain", do_uarch_drain)
|
2020-12-28 16:35:14 +08:00
|
|
|
|
2022-11-18 14:07:57 +08:00
|
|
|
io.in(0).ready := firstCanInsert
|
2023-07-24 10:22:21 +08:00
|
|
|
io.in(1).ready := secondCanInsert && io.in(0).ready
|
2020-12-28 16:35:14 +08:00
|
|
|
|
2024-03-04 16:02:11 +08:00
|
|
|
for (i <- 0 until EnsbufferWidth) {
|
L1 Prefetch (#2261)
* dcache: optimize the ready signal of missqueue
Add a custom arbiter. In the case of multiple sources with the same
cache block address, the arbiter will assign only one entry in
misssqueue but ready for all same cache block address requests.
This will reduce the number of replays of the load instruction which cannot
enter the missqueue
* sta, dcache: add A StorePipe in dcache
When the store command passes through the sta pipeline, access the tag
and meta of dcache to determine whether it hits, if it hits, update the
replacement algorithm, and if miss, send a write intent to missqueue
* sta prefetch: add a queue
Enter this queue when the Store Address pipeline sends a request,
determines that it has a cache miss, and the contention for MSHR fails.
The miss request in this queue will be sent to the Store pipeline later.
* sbuffer, dcache: store prefetch burst
A basic implementation of "Boosting Store Buffer Efficiency with
Store-Prefetch Bursts".
Store prefetch at exe is disabled.
Now, when store goes from sq to sbuffer, it will trigger a store
prefetch; when 48 stores fall into 6 cache lines, trigger a store burst
perfetch, which will bring a whole page back into dcache.
* dcache: restric mshr alloc for prefetch req
* restric the max number of entries which can be used by prefetch
* merge two same cache line address prefetch write req
* dynamically detect memset pattern, all mshr can accept prefetch when
pattern is detected
* spb: constantin support
* dcache: fix missqueue prefetch ready
* make prefetch req goes mshr with bigger id
* Revert "spb: constantin support"
This reverts commit 4ee50b89ba4a62cd28fa22d7fbcb2338ad4b1849.
* spb: fix bug in burst generator
* spb: add load prefetch burst support
* topdown: add defines of topdown counters enum
* redirect: add redirect type for perf
* top-down: add stallReason IOs
frontend -> ctrlBlock -> decode -> rename -> dispatch
* top-down: add dummy connections
* top-down: update TopdownCounters
* top-down: imp backend analysis and counter dump
* top-down: add HartId in `addSource`
* top-down: broadcast lqIdx of ROB head
* top-down: frontend signal done
* top-down: add memblock topdown interface
* Bump HuanCun: add TopDownMonitor
* top-down: receive and handle reasons in dispatch
* top-down: remove previous top-down code
* TopDown: add MemReqSource enum
* TopDown: extend mshr_latency range
* TopDown: add basic Req Source
TODO: distinguish prefetch
* store prefetch: refactor parameters and fix bug
* change some parameters
* fix store pipe bug
* fix load prefetch burst
* dcache: distinguish L1DataPrefetch and CPUData
* top-down: comment out debugging perf counters in ibuffer
* TopDown: add path to pass MemReqSource to HuanCun
* TopDown: use simpler logic to count reqSource and update Probe count
* frontend: update topdown counters
* Update HuanCun Topdown for MemReqSource
* top-down: fix load stalls
* top-down: Change the priority of different stall reasons
* store prefetch: add stride and l2 prefetch
* add a stride prefetcher
* spb and stride will issue prefetch to l2
* when store commits, issue a prefetch to l1
* sbuffer: fix eviction
* when valid count reaches StoreBufferSize, do eviction
* spf: change store prefetch structure
* prefetch @ exe -> l2 cache
* stride -> l2 cache
* sbuffer: fix replaceIdx
* If the way selected by the replacement algorithm cannot be written into dcache, its result is not used.
* Revert "sbuffer: fix replaceIdx"
This reverts commit 40c16aca956af9fb32554a0f12d18db41c22eecd.
* spf: find best interval in stamissqueue
* Revert "spf: find best interval in stamissqueue"
This reverts commit d179f0ce15a5ab989a822de7fe48cc5e2cd96914.
* sms: port store to sms
Miss store will train sms like load.
Now, sms will recieve 4 train sources, 2 for miss load, 2 for miss
store, but prefetcher consume 1 train req per cycle, PrefetchTrainFilter
is added to deal with this case.
* bump huancun
* spf: refactor structure
* miss stores will train sms, and send prefetch to l2
* miss stores will send prefetch to l1 on issue or commit
* spb will send prefetch to l1
* memset: fix memset detection
use lqEmpty to check this
* constantin: storepf constantin support
cherry-pick this to use constantin in storepf
* Revert "constantin: storepf constantin support"
This reverts commit 2b97767b9fa757d920cac3d80d4893a1380592c7.
* storepf: add EnableAtCommitMissTrigger
* trigger prefetch at commit only when the store misses with
EnableAtCommitMissTrigger
* bump coupledl2
* prefetch req from L1 to L2 will Acquire T
* fix merge conflict
* storepf: do not read meta&tag when pf is disabled
* storepf: do not read pcMem when sms store is disabled
* fix verilog check
* fix verilog
* missqueue: support merging prefetch
* prefetch req can be merged to pipeline reg
* merging prefetch write will update cmd
* delay sending out acquire when a prefetch write is about to merge
* missqueue: fix bug of merging prefetch write
* delay sending out acquire when a pipeline reg is about to merging a
prefetch write
* temp: disable store pf
* missqueue: disable merging prefetch
* late prefetch will be ignored
* check alias when merging
* enable store pf at issue
* add L1StreamPrefetcher
* fix assert
* let prefetch req prefer loadunit1 more than 0
* stream prefetcher
* disable stream component in SMS, SMS is only trained on real miss
* add a prefetcher monitor to adjust depth & confidence ..
* add L1 L2 stream prefetch
* add gene support
* Revert "add gene support"
This reverts commit 59ae15640ff3d1cc96347f4d3567d48c740a03bb.
* add miss db
* l1pf: add stride & store source info in cache meta
* add a Stride prefetcher and disable Stride component in sms
* prefetch bit in meta is expanded into 3 bits to store source info of
prefetcher
* prefetch: support sending prefetch req to l3
* l1pf: add FDP & refactor
* add basic FDP counters
* change stride from Block addr to Byte addr
* refactor the code
* bump submodules
* disable load related chiseldb to reduce db size
* fix compile
* fix minimalConfig & enable stream
* fix stride pc problem
* fix minimalconfig compile
* bump submodules
* refactor stream stride helper
* fix compile
* bump huancun
* disable db to save size
* fix l2 assert
* bump submodules
---------
Co-authored-by: tastynoob <934348725@qq.com>
Co-authored-by: Haojin Tang <tanghaojin@outlook.com>
Co-authored-by: Guokai Chen <chenguokai17@mails.ucas.ac.cn>
Co-authored-by: XiChen <chenxi171@mails.ucas.ac.cn>
Co-authored-by: Zhou Yaoyang <shinezyy@qq.com>
2023-09-06 16:07:59 +08:00
|
|
|
// train
|
2024-03-04 16:02:11 +08:00
|
|
|
if (EnableStorePrefetchSPB) {
|
2024-04-05 17:47:56 +08:00
|
|
|
prefetcher.io.sbuffer_enq(i).valid := io.in(i).fire && io.in(i).bits.vecValid
|
L1 Prefetch (#2261)
* dcache: optimize the ready signal of missqueue
Add a custom arbiter. In the case of multiple sources with the same
cache block address, the arbiter will assign only one entry in
misssqueue but ready for all same cache block address requests.
This will reduce the number of replays of the load instruction which cannot
enter the missqueue
* sta, dcache: add A StorePipe in dcache
When the store command passes through the sta pipeline, access the tag
and meta of dcache to determine whether it hits, if it hits, update the
replacement algorithm, and if miss, send a write intent to missqueue
* sta prefetch: add a queue
Enter this queue when the Store Address pipeline sends a request,
determines that it has a cache miss, and the contention for MSHR fails.
The miss request in this queue will be sent to the Store pipeline later.
* sbuffer, dcache: store prefetch burst
A basic implementation of "Boosting Store Buffer Efficiency with
Store-Prefetch Bursts".
Store prefetch at exe is disabled.
Now, when store goes from sq to sbuffer, it will trigger a store
prefetch; when 48 stores fall into 6 cache lines, trigger a store burst
perfetch, which will bring a whole page back into dcache.
* dcache: restric mshr alloc for prefetch req
* restric the max number of entries which can be used by prefetch
* merge two same cache line address prefetch write req
* dynamically detect memset pattern, all mshr can accept prefetch when
pattern is detected
* spb: constantin support
* dcache: fix missqueue prefetch ready
* make prefetch req goes mshr with bigger id
* Revert "spb: constantin support"
This reverts commit 4ee50b89ba4a62cd28fa22d7fbcb2338ad4b1849.
* spb: fix bug in burst generator
* spb: add load prefetch burst support
* topdown: add defines of topdown counters enum
* redirect: add redirect type for perf
* top-down: add stallReason IOs
frontend -> ctrlBlock -> decode -> rename -> dispatch
* top-down: add dummy connections
* top-down: update TopdownCounters
* top-down: imp backend analysis and counter dump
* top-down: add HartId in `addSource`
* top-down: broadcast lqIdx of ROB head
* top-down: frontend signal done
* top-down: add memblock topdown interface
* Bump HuanCun: add TopDownMonitor
* top-down: receive and handle reasons in dispatch
* top-down: remove previous top-down code
* TopDown: add MemReqSource enum
* TopDown: extend mshr_latency range
* TopDown: add basic Req Source
TODO: distinguish prefetch
* store prefetch: refactor parameters and fix bug
* change some parameters
* fix store pipe bug
* fix load prefetch burst
* dcache: distinguish L1DataPrefetch and CPUData
* top-down: comment out debugging perf counters in ibuffer
* TopDown: add path to pass MemReqSource to HuanCun
* TopDown: use simpler logic to count reqSource and update Probe count
* frontend: update topdown counters
* Update HuanCun Topdown for MemReqSource
* top-down: fix load stalls
* top-down: Change the priority of different stall reasons
* store prefetch: add stride and l2 prefetch
* add a stride prefetcher
* spb and stride will issue prefetch to l2
* when store commits, issue a prefetch to l1
* sbuffer: fix eviction
* when valid count reaches StoreBufferSize, do eviction
* spf: change store prefetch structure
* prefetch @ exe -> l2 cache
* stride -> l2 cache
* sbuffer: fix replaceIdx
* If the way selected by the replacement algorithm cannot be written into dcache, its result is not used.
* Revert "sbuffer: fix replaceIdx"
This reverts commit 40c16aca956af9fb32554a0f12d18db41c22eecd.
* spf: find best interval in stamissqueue
* Revert "spf: find best interval in stamissqueue"
This reverts commit d179f0ce15a5ab989a822de7fe48cc5e2cd96914.
* sms: port store to sms
Miss store will train sms like load.
Now, sms will recieve 4 train sources, 2 for miss load, 2 for miss
store, but prefetcher consume 1 train req per cycle, PrefetchTrainFilter
is added to deal with this case.
* bump huancun
* spf: refactor structure
* miss stores will train sms, and send prefetch to l2
* miss stores will send prefetch to l1 on issue or commit
* spb will send prefetch to l1
* memset: fix memset detection
use lqEmpty to check this
* constantin: storepf constantin support
cherry-pick this to use constantin in storepf
* Revert "constantin: storepf constantin support"
This reverts commit 2b97767b9fa757d920cac3d80d4893a1380592c7.
* storepf: add EnableAtCommitMissTrigger
* trigger prefetch at commit only when the store misses with
EnableAtCommitMissTrigger
* bump coupledl2
* prefetch req from L1 to L2 will Acquire T
* fix merge conflict
* storepf: do not read meta&tag when pf is disabled
* storepf: do not read pcMem when sms store is disabled
* fix verilog check
* fix verilog
* missqueue: support merging prefetch
* prefetch req can be merged to pipeline reg
* merging prefetch write will update cmd
* delay sending out acquire when a prefetch write is about to merge
* missqueue: fix bug of merging prefetch write
* delay sending out acquire when a pipeline reg is about to merging a
prefetch write
* temp: disable store pf
* missqueue: disable merging prefetch
* late prefetch will be ignored
* check alias when merging
* enable store pf at issue
* add L1StreamPrefetcher
* fix assert
* let prefetch req prefer loadunit1 more than 0
* stream prefetcher
* disable stream component in SMS, SMS is only trained on real miss
* add a prefetcher monitor to adjust depth & confidence ..
* add L1 L2 stream prefetch
* add gene support
* Revert "add gene support"
This reverts commit 59ae15640ff3d1cc96347f4d3567d48c740a03bb.
* add miss db
* l1pf: add stride & store source info in cache meta
* add a Stride prefetcher and disable Stride component in sms
* prefetch bit in meta is expanded into 3 bits to store source info of
prefetcher
* prefetch: support sending prefetch req to l3
* l1pf: add FDP & refactor
* add basic FDP counters
* change stride from Block addr to Byte addr
* refactor the code
* bump submodules
* disable load related chiseldb to reduce db size
* fix compile
* fix minimalConfig & enable stream
* fix stride pc problem
* fix minimalconfig compile
* bump submodules
* refactor stream stride helper
* fix compile
* bump huancun
* disable db to save size
* fix l2 assert
* bump submodules
---------
Co-authored-by: tastynoob <934348725@qq.com>
Co-authored-by: Haojin Tang <tanghaojin@outlook.com>
Co-authored-by: Guokai Chen <chenguokai17@mails.ucas.ac.cn>
Co-authored-by: XiChen <chenxi171@mails.ucas.ac.cn>
Co-authored-by: Zhou Yaoyang <shinezyy@qq.com>
2023-09-06 16:07:59 +08:00
|
|
|
prefetcher.io.sbuffer_enq(i).bits := DontCare
|
|
|
|
prefetcher.io.sbuffer_enq(i).bits.vaddr := io.in(i).bits.vaddr
|
2024-03-04 16:02:11 +08:00
|
|
|
} else {
|
L1 Prefetch (#2261)
* dcache: optimize the ready signal of missqueue
Add a custom arbiter. In the case of multiple sources with the same
cache block address, the arbiter will assign only one entry in
misssqueue but ready for all same cache block address requests.
This will reduce the number of replays of the load instruction which cannot
enter the missqueue
* sta, dcache: add A StorePipe in dcache
When the store command passes through the sta pipeline, access the tag
and meta of dcache to determine whether it hits, if it hits, update the
replacement algorithm, and if miss, send a write intent to missqueue
* sta prefetch: add a queue
Enter this queue when the Store Address pipeline sends a request,
determines that it has a cache miss, and the contention for MSHR fails.
The miss request in this queue will be sent to the Store pipeline later.
* sbuffer, dcache: store prefetch burst
A basic implementation of "Boosting Store Buffer Efficiency with
Store-Prefetch Bursts".
Store prefetch at exe is disabled.
Now, when store goes from sq to sbuffer, it will trigger a store
prefetch; when 48 stores fall into 6 cache lines, trigger a store burst
perfetch, which will bring a whole page back into dcache.
* dcache: restric mshr alloc for prefetch req
* restric the max number of entries which can be used by prefetch
* merge two same cache line address prefetch write req
* dynamically detect memset pattern, all mshr can accept prefetch when
pattern is detected
* spb: constantin support
* dcache: fix missqueue prefetch ready
* make prefetch req goes mshr with bigger id
* Revert "spb: constantin support"
This reverts commit 4ee50b89ba4a62cd28fa22d7fbcb2338ad4b1849.
* spb: fix bug in burst generator
* spb: add load prefetch burst support
* topdown: add defines of topdown counters enum
* redirect: add redirect type for perf
* top-down: add stallReason IOs
frontend -> ctrlBlock -> decode -> rename -> dispatch
* top-down: add dummy connections
* top-down: update TopdownCounters
* top-down: imp backend analysis and counter dump
* top-down: add HartId in `addSource`
* top-down: broadcast lqIdx of ROB head
* top-down: frontend signal done
* top-down: add memblock topdown interface
* Bump HuanCun: add TopDownMonitor
* top-down: receive and handle reasons in dispatch
* top-down: remove previous top-down code
* TopDown: add MemReqSource enum
* TopDown: extend mshr_latency range
* TopDown: add basic Req Source
TODO: distinguish prefetch
* store prefetch: refactor parameters and fix bug
* change some parameters
* fix store pipe bug
* fix load prefetch burst
* dcache: distinguish L1DataPrefetch and CPUData
* top-down: comment out debugging perf counters in ibuffer
* TopDown: add path to pass MemReqSource to HuanCun
* TopDown: use simpler logic to count reqSource and update Probe count
* frontend: update topdown counters
* Update HuanCun Topdown for MemReqSource
* top-down: fix load stalls
* top-down: Change the priority of different stall reasons
* store prefetch: add stride and l2 prefetch
* add a stride prefetcher
* spb and stride will issue prefetch to l2
* when store commits, issue a prefetch to l1
* sbuffer: fix eviction
* when valid count reaches StoreBufferSize, do eviction
* spf: change store prefetch structure
* prefetch @ exe -> l2 cache
* stride -> l2 cache
* sbuffer: fix replaceIdx
* If the way selected by the replacement algorithm cannot be written into dcache, its result is not used.
* Revert "sbuffer: fix replaceIdx"
This reverts commit 40c16aca956af9fb32554a0f12d18db41c22eecd.
* spf: find best interval in stamissqueue
* Revert "spf: find best interval in stamissqueue"
This reverts commit d179f0ce15a5ab989a822de7fe48cc5e2cd96914.
* sms: port store to sms
Miss store will train sms like load.
Now, sms will recieve 4 train sources, 2 for miss load, 2 for miss
store, but prefetcher consume 1 train req per cycle, PrefetchTrainFilter
is added to deal with this case.
* bump huancun
* spf: refactor structure
* miss stores will train sms, and send prefetch to l2
* miss stores will send prefetch to l1 on issue or commit
* spb will send prefetch to l1
* memset: fix memset detection
use lqEmpty to check this
* constantin: storepf constantin support
cherry-pick this to use constantin in storepf
* Revert "constantin: storepf constantin support"
This reverts commit 2b97767b9fa757d920cac3d80d4893a1380592c7.
* storepf: add EnableAtCommitMissTrigger
* trigger prefetch at commit only when the store misses with
EnableAtCommitMissTrigger
* bump coupledl2
* prefetch req from L1 to L2 will Acquire T
* fix merge conflict
* storepf: do not read meta&tag when pf is disabled
* storepf: do not read pcMem when sms store is disabled
* fix verilog check
* fix verilog
* missqueue: support merging prefetch
* prefetch req can be merged to pipeline reg
* merging prefetch write will update cmd
* delay sending out acquire when a prefetch write is about to merge
* missqueue: fix bug of merging prefetch write
* delay sending out acquire when a pipeline reg is about to merging a
prefetch write
* temp: disable store pf
* missqueue: disable merging prefetch
* late prefetch will be ignored
* check alias when merging
* enable store pf at issue
* add L1StreamPrefetcher
* fix assert
* let prefetch req prefer loadunit1 more than 0
* stream prefetcher
* disable stream component in SMS, SMS is only trained on real miss
* add a prefetcher monitor to adjust depth & confidence ..
* add L1 L2 stream prefetch
* add gene support
* Revert "add gene support"
This reverts commit 59ae15640ff3d1cc96347f4d3567d48c740a03bb.
* add miss db
* l1pf: add stride & store source info in cache meta
* add a Stride prefetcher and disable Stride component in sms
* prefetch bit in meta is expanded into 3 bits to store source info of
prefetcher
* prefetch: support sending prefetch req to l3
* l1pf: add FDP & refactor
* add basic FDP counters
* change stride from Block addr to Byte addr
* refactor the code
* bump submodules
* disable load related chiseldb to reduce db size
* fix compile
* fix minimalConfig & enable stream
* fix stride pc problem
* fix minimalconfig compile
* bump submodules
* refactor stream stride helper
* fix compile
* bump huancun
* disable db to save size
* fix l2 assert
* bump submodules
---------
Co-authored-by: tastynoob <934348725@qq.com>
Co-authored-by: Haojin Tang <tanghaojin@outlook.com>
Co-authored-by: Guokai Chen <chenguokai17@mails.ucas.ac.cn>
Co-authored-by: XiChen <chenxi171@mails.ucas.ac.cn>
Co-authored-by: Zhou Yaoyang <shinezyy@qq.com>
2023-09-06 16:07:59 +08:00
|
|
|
prefetcher.io.sbuffer_enq(i).valid := false.B
|
|
|
|
prefetcher.io.sbuffer_enq(i).bits := DontCare
|
|
|
|
}
|
|
|
|
|
|
|
|
// prefetch req
|
2024-03-04 16:02:11 +08:00
|
|
|
if (EnableStorePrefetchAtCommit) {
|
|
|
|
if (EnableAtCommitMissTrigger) {
|
2024-04-05 17:47:56 +08:00
|
|
|
io.store_prefetch(i).valid := prefetcher.io.prefetch_req(i).valid || (io.in(i).fire && io.in(i).bits.vecValid && io.in(i).bits.prefetch)
|
2024-03-04 16:02:11 +08:00
|
|
|
} else {
|
2024-04-05 17:47:56 +08:00
|
|
|
io.store_prefetch(i).valid := prefetcher.io.prefetch_req(i).valid || (io.in(i).fire && io.in(i).bits.vecValid)
|
L1 Prefetch (#2261)
* dcache: optimize the ready signal of missqueue
Add a custom arbiter. In the case of multiple sources with the same
cache block address, the arbiter will assign only one entry in
misssqueue but ready for all same cache block address requests.
This will reduce the number of replays of the load instruction which cannot
enter the missqueue
* sta, dcache: add A StorePipe in dcache
When the store command passes through the sta pipeline, access the tag
and meta of dcache to determine whether it hits, if it hits, update the
replacement algorithm, and if miss, send a write intent to missqueue
* sta prefetch: add a queue
Enter this queue when the Store Address pipeline sends a request,
determines that it has a cache miss, and the contention for MSHR fails.
The miss request in this queue will be sent to the Store pipeline later.
* sbuffer, dcache: store prefetch burst
A basic implementation of "Boosting Store Buffer Efficiency with
Store-Prefetch Bursts".
Store prefetch at exe is disabled.
Now, when store goes from sq to sbuffer, it will trigger a store
prefetch; when 48 stores fall into 6 cache lines, trigger a store burst
perfetch, which will bring a whole page back into dcache.
* dcache: restric mshr alloc for prefetch req
* restric the max number of entries which can be used by prefetch
* merge two same cache line address prefetch write req
* dynamically detect memset pattern, all mshr can accept prefetch when
pattern is detected
* spb: constantin support
* dcache: fix missqueue prefetch ready
* make prefetch req goes mshr with bigger id
* Revert "spb: constantin support"
This reverts commit 4ee50b89ba4a62cd28fa22d7fbcb2338ad4b1849.
* spb: fix bug in burst generator
* spb: add load prefetch burst support
* topdown: add defines of topdown counters enum
* redirect: add redirect type for perf
* top-down: add stallReason IOs
frontend -> ctrlBlock -> decode -> rename -> dispatch
* top-down: add dummy connections
* top-down: update TopdownCounters
* top-down: imp backend analysis and counter dump
* top-down: add HartId in `addSource`
* top-down: broadcast lqIdx of ROB head
* top-down: frontend signal done
* top-down: add memblock topdown interface
* Bump HuanCun: add TopDownMonitor
* top-down: receive and handle reasons in dispatch
* top-down: remove previous top-down code
* TopDown: add MemReqSource enum
* TopDown: extend mshr_latency range
* TopDown: add basic Req Source
TODO: distinguish prefetch
* store prefetch: refactor parameters and fix bug
* change some parameters
* fix store pipe bug
* fix load prefetch burst
* dcache: distinguish L1DataPrefetch and CPUData
* top-down: comment out debugging perf counters in ibuffer
* TopDown: add path to pass MemReqSource to HuanCun
* TopDown: use simpler logic to count reqSource and update Probe count
* frontend: update topdown counters
* Update HuanCun Topdown for MemReqSource
* top-down: fix load stalls
* top-down: Change the priority of different stall reasons
* store prefetch: add stride and l2 prefetch
* add a stride prefetcher
* spb and stride will issue prefetch to l2
* when store commits, issue a prefetch to l1
* sbuffer: fix eviction
* when valid count reaches StoreBufferSize, do eviction
* spf: change store prefetch structure
* prefetch @ exe -> l2 cache
* stride -> l2 cache
* sbuffer: fix replaceIdx
* If the way selected by the replacement algorithm cannot be written into dcache, its result is not used.
* Revert "sbuffer: fix replaceIdx"
This reverts commit 40c16aca956af9fb32554a0f12d18db41c22eecd.
* spf: find best interval in stamissqueue
* Revert "spf: find best interval in stamissqueue"
This reverts commit d179f0ce15a5ab989a822de7fe48cc5e2cd96914.
* sms: port store to sms
Miss store will train sms like load.
Now, sms will recieve 4 train sources, 2 for miss load, 2 for miss
store, but prefetcher consume 1 train req per cycle, PrefetchTrainFilter
is added to deal with this case.
* bump huancun
* spf: refactor structure
* miss stores will train sms, and send prefetch to l2
* miss stores will send prefetch to l1 on issue or commit
* spb will send prefetch to l1
* memset: fix memset detection
use lqEmpty to check this
* constantin: storepf constantin support
cherry-pick this to use constantin in storepf
* Revert "constantin: storepf constantin support"
This reverts commit 2b97767b9fa757d920cac3d80d4893a1380592c7.
* storepf: add EnableAtCommitMissTrigger
* trigger prefetch at commit only when the store misses with
EnableAtCommitMissTrigger
* bump coupledl2
* prefetch req from L1 to L2 will Acquire T
* fix merge conflict
* storepf: do not read meta&tag when pf is disabled
* storepf: do not read pcMem when sms store is disabled
* fix verilog check
* fix verilog
* missqueue: support merging prefetch
* prefetch req can be merged to pipeline reg
* merging prefetch write will update cmd
* delay sending out acquire when a prefetch write is about to merge
* missqueue: fix bug of merging prefetch write
* delay sending out acquire when a pipeline reg is about to merging a
prefetch write
* temp: disable store pf
* missqueue: disable merging prefetch
* late prefetch will be ignored
* check alias when merging
* enable store pf at issue
* add L1StreamPrefetcher
* fix assert
* let prefetch req prefer loadunit1 more than 0
* stream prefetcher
* disable stream component in SMS, SMS is only trained on real miss
* add a prefetcher monitor to adjust depth & confidence ..
* add L1 L2 stream prefetch
* add gene support
* Revert "add gene support"
This reverts commit 59ae15640ff3d1cc96347f4d3567d48c740a03bb.
* add miss db
* l1pf: add stride & store source info in cache meta
* add a Stride prefetcher and disable Stride component in sms
* prefetch bit in meta is expanded into 3 bits to store source info of
prefetcher
* prefetch: support sending prefetch req to l3
* l1pf: add FDP & refactor
* add basic FDP counters
* change stride from Block addr to Byte addr
* refactor the code
* bump submodules
* disable load related chiseldb to reduce db size
* fix compile
* fix minimalConfig & enable stream
* fix stride pc problem
* fix minimalconfig compile
* bump submodules
* refactor stream stride helper
* fix compile
* bump huancun
* disable db to save size
* fix l2 assert
* bump submodules
---------
Co-authored-by: tastynoob <934348725@qq.com>
Co-authored-by: Haojin Tang <tanghaojin@outlook.com>
Co-authored-by: Guokai Chen <chenguokai17@mails.ucas.ac.cn>
Co-authored-by: XiChen <chenxi171@mails.ucas.ac.cn>
Co-authored-by: Zhou Yaoyang <shinezyy@qq.com>
2023-09-06 16:07:59 +08:00
|
|
|
}
|
|
|
|
io.store_prefetch(i).bits.paddr := DontCare
|
|
|
|
io.store_prefetch(i).bits.vaddr := Mux(prefetcher.io.prefetch_req(i).valid, prefetcher.io.prefetch_req(i).bits.vaddr, io.in(i).bits.vaddr)
|
|
|
|
prefetcher.io.prefetch_req(i).ready := io.store_prefetch(i).ready
|
2024-03-04 16:02:11 +08:00
|
|
|
} else {
|
L1 Prefetch (#2261)
* dcache: optimize the ready signal of missqueue
Add a custom arbiter. In the case of multiple sources with the same
cache block address, the arbiter will assign only one entry in
misssqueue but ready for all same cache block address requests.
This will reduce the number of replays of the load instruction which cannot
enter the missqueue
* sta, dcache: add A StorePipe in dcache
When the store command passes through the sta pipeline, access the tag
and meta of dcache to determine whether it hits, if it hits, update the
replacement algorithm, and if miss, send a write intent to missqueue
* sta prefetch: add a queue
Enter this queue when the Store Address pipeline sends a request,
determines that it has a cache miss, and the contention for MSHR fails.
The miss request in this queue will be sent to the Store pipeline later.
* sbuffer, dcache: store prefetch burst
A basic implementation of "Boosting Store Buffer Efficiency with
Store-Prefetch Bursts".
Store prefetch at exe is disabled.
Now, when store goes from sq to sbuffer, it will trigger a store
prefetch; when 48 stores fall into 6 cache lines, trigger a store burst
perfetch, which will bring a whole page back into dcache.
* dcache: restric mshr alloc for prefetch req
* restric the max number of entries which can be used by prefetch
* merge two same cache line address prefetch write req
* dynamically detect memset pattern, all mshr can accept prefetch when
pattern is detected
* spb: constantin support
* dcache: fix missqueue prefetch ready
* make prefetch req goes mshr with bigger id
* Revert "spb: constantin support"
This reverts commit 4ee50b89ba4a62cd28fa22d7fbcb2338ad4b1849.
* spb: fix bug in burst generator
* spb: add load prefetch burst support
* topdown: add defines of topdown counters enum
* redirect: add redirect type for perf
* top-down: add stallReason IOs
frontend -> ctrlBlock -> decode -> rename -> dispatch
* top-down: add dummy connections
* top-down: update TopdownCounters
* top-down: imp backend analysis and counter dump
* top-down: add HartId in `addSource`
* top-down: broadcast lqIdx of ROB head
* top-down: frontend signal done
* top-down: add memblock topdown interface
* Bump HuanCun: add TopDownMonitor
* top-down: receive and handle reasons in dispatch
* top-down: remove previous top-down code
* TopDown: add MemReqSource enum
* TopDown: extend mshr_latency range
* TopDown: add basic Req Source
TODO: distinguish prefetch
* store prefetch: refactor parameters and fix bug
* change some parameters
* fix store pipe bug
* fix load prefetch burst
* dcache: distinguish L1DataPrefetch and CPUData
* top-down: comment out debugging perf counters in ibuffer
* TopDown: add path to pass MemReqSource to HuanCun
* TopDown: use simpler logic to count reqSource and update Probe count
* frontend: update topdown counters
* Update HuanCun Topdown for MemReqSource
* top-down: fix load stalls
* top-down: Change the priority of different stall reasons
* store prefetch: add stride and l2 prefetch
* add a stride prefetcher
* spb and stride will issue prefetch to l2
* when store commits, issue a prefetch to l1
* sbuffer: fix eviction
* when valid count reaches StoreBufferSize, do eviction
* spf: change store prefetch structure
* prefetch @ exe -> l2 cache
* stride -> l2 cache
* sbuffer: fix replaceIdx
* If the way selected by the replacement algorithm cannot be written into dcache, its result is not used.
* Revert "sbuffer: fix replaceIdx"
This reverts commit 40c16aca956af9fb32554a0f12d18db41c22eecd.
* spf: find best interval in stamissqueue
* Revert "spf: find best interval in stamissqueue"
This reverts commit d179f0ce15a5ab989a822de7fe48cc5e2cd96914.
* sms: port store to sms
Miss store will train sms like load.
Now, sms will recieve 4 train sources, 2 for miss load, 2 for miss
store, but prefetcher consume 1 train req per cycle, PrefetchTrainFilter
is added to deal with this case.
* bump huancun
* spf: refactor structure
* miss stores will train sms, and send prefetch to l2
* miss stores will send prefetch to l1 on issue or commit
* spb will send prefetch to l1
* memset: fix memset detection
use lqEmpty to check this
* constantin: storepf constantin support
cherry-pick this to use constantin in storepf
* Revert "constantin: storepf constantin support"
This reverts commit 2b97767b9fa757d920cac3d80d4893a1380592c7.
* storepf: add EnableAtCommitMissTrigger
* trigger prefetch at commit only when the store misses with
EnableAtCommitMissTrigger
* bump coupledl2
* prefetch req from L1 to L2 will Acquire T
* fix merge conflict
* storepf: do not read meta&tag when pf is disabled
* storepf: do not read pcMem when sms store is disabled
* fix verilog check
* fix verilog
* missqueue: support merging prefetch
* prefetch req can be merged to pipeline reg
* merging prefetch write will update cmd
* delay sending out acquire when a prefetch write is about to merge
* missqueue: fix bug of merging prefetch write
* delay sending out acquire when a pipeline reg is about to merging a
prefetch write
* temp: disable store pf
* missqueue: disable merging prefetch
* late prefetch will be ignored
* check alias when merging
* enable store pf at issue
* add L1StreamPrefetcher
* fix assert
* let prefetch req prefer loadunit1 more than 0
* stream prefetcher
* disable stream component in SMS, SMS is only trained on real miss
* add a prefetcher monitor to adjust depth & confidence ..
* add L1 L2 stream prefetch
* add gene support
* Revert "add gene support"
This reverts commit 59ae15640ff3d1cc96347f4d3567d48c740a03bb.
* add miss db
* l1pf: add stride & store source info in cache meta
* add a Stride prefetcher and disable Stride component in sms
* prefetch bit in meta is expanded into 3 bits to store source info of
prefetcher
* prefetch: support sending prefetch req to l3
* l1pf: add FDP & refactor
* add basic FDP counters
* change stride from Block addr to Byte addr
* refactor the code
* bump submodules
* disable load related chiseldb to reduce db size
* fix compile
* fix minimalConfig & enable stream
* fix stride pc problem
* fix minimalconfig compile
* bump submodules
* refactor stream stride helper
* fix compile
* bump huancun
* disable db to save size
* fix l2 assert
* bump submodules
---------
Co-authored-by: tastynoob <934348725@qq.com>
Co-authored-by: Haojin Tang <tanghaojin@outlook.com>
Co-authored-by: Guokai Chen <chenguokai17@mails.ucas.ac.cn>
Co-authored-by: XiChen <chenxi171@mails.ucas.ac.cn>
Co-authored-by: Zhou Yaoyang <shinezyy@qq.com>
2023-09-06 16:07:59 +08:00
|
|
|
io.store_prefetch(i) <> prefetcher.io.prefetch_req(i)
|
|
|
|
}
|
2024-03-04 16:02:11 +08:00
|
|
|
io.store_prefetch zip prefetcher.io.prefetch_req drop 2 foreach (x => x._1 <> x._2)
|
L1 Prefetch (#2261)
* dcache: optimize the ready signal of missqueue
Add a custom arbiter. In the case of multiple sources with the same
cache block address, the arbiter will assign only one entry in
misssqueue but ready for all same cache block address requests.
This will reduce the number of replays of the load instruction which cannot
enter the missqueue
* sta, dcache: add A StorePipe in dcache
When the store command passes through the sta pipeline, access the tag
and meta of dcache to determine whether it hits, if it hits, update the
replacement algorithm, and if miss, send a write intent to missqueue
* sta prefetch: add a queue
Enter this queue when the Store Address pipeline sends a request,
determines that it has a cache miss, and the contention for MSHR fails.
The miss request in this queue will be sent to the Store pipeline later.
* sbuffer, dcache: store prefetch burst
A basic implementation of "Boosting Store Buffer Efficiency with
Store-Prefetch Bursts".
Store prefetch at exe is disabled.
Now, when store goes from sq to sbuffer, it will trigger a store
prefetch; when 48 stores fall into 6 cache lines, trigger a store burst
perfetch, which will bring a whole page back into dcache.
* dcache: restric mshr alloc for prefetch req
* restric the max number of entries which can be used by prefetch
* merge two same cache line address prefetch write req
* dynamically detect memset pattern, all mshr can accept prefetch when
pattern is detected
* spb: constantin support
* dcache: fix missqueue prefetch ready
* make prefetch req goes mshr with bigger id
* Revert "spb: constantin support"
This reverts commit 4ee50b89ba4a62cd28fa22d7fbcb2338ad4b1849.
* spb: fix bug in burst generator
* spb: add load prefetch burst support
* topdown: add defines of topdown counters enum
* redirect: add redirect type for perf
* top-down: add stallReason IOs
frontend -> ctrlBlock -> decode -> rename -> dispatch
* top-down: add dummy connections
* top-down: update TopdownCounters
* top-down: imp backend analysis and counter dump
* top-down: add HartId in `addSource`
* top-down: broadcast lqIdx of ROB head
* top-down: frontend signal done
* top-down: add memblock topdown interface
* Bump HuanCun: add TopDownMonitor
* top-down: receive and handle reasons in dispatch
* top-down: remove previous top-down code
* TopDown: add MemReqSource enum
* TopDown: extend mshr_latency range
* TopDown: add basic Req Source
TODO: distinguish prefetch
* store prefetch: refactor parameters and fix bug
* change some parameters
* fix store pipe bug
* fix load prefetch burst
* dcache: distinguish L1DataPrefetch and CPUData
* top-down: comment out debugging perf counters in ibuffer
* TopDown: add path to pass MemReqSource to HuanCun
* TopDown: use simpler logic to count reqSource and update Probe count
* frontend: update topdown counters
* Update HuanCun Topdown for MemReqSource
* top-down: fix load stalls
* top-down: Change the priority of different stall reasons
* store prefetch: add stride and l2 prefetch
* add a stride prefetcher
* spb and stride will issue prefetch to l2
* when store commits, issue a prefetch to l1
* sbuffer: fix eviction
* when valid count reaches StoreBufferSize, do eviction
* spf: change store prefetch structure
* prefetch @ exe -> l2 cache
* stride -> l2 cache
* sbuffer: fix replaceIdx
* If the way selected by the replacement algorithm cannot be written into dcache, its result is not used.
* Revert "sbuffer: fix replaceIdx"
This reverts commit 40c16aca956af9fb32554a0f12d18db41c22eecd.
* spf: find best interval in stamissqueue
* Revert "spf: find best interval in stamissqueue"
This reverts commit d179f0ce15a5ab989a822de7fe48cc5e2cd96914.
* sms: port store to sms
Miss store will train sms like load.
Now, sms will recieve 4 train sources, 2 for miss load, 2 for miss
store, but prefetcher consume 1 train req per cycle, PrefetchTrainFilter
is added to deal with this case.
* bump huancun
* spf: refactor structure
* miss stores will train sms, and send prefetch to l2
* miss stores will send prefetch to l1 on issue or commit
* spb will send prefetch to l1
* memset: fix memset detection
use lqEmpty to check this
* constantin: storepf constantin support
cherry-pick this to use constantin in storepf
* Revert "constantin: storepf constantin support"
This reverts commit 2b97767b9fa757d920cac3d80d4893a1380592c7.
* storepf: add EnableAtCommitMissTrigger
* trigger prefetch at commit only when the store misses with
EnableAtCommitMissTrigger
* bump coupledl2
* prefetch req from L1 to L2 will Acquire T
* fix merge conflict
* storepf: do not read meta&tag when pf is disabled
* storepf: do not read pcMem when sms store is disabled
* fix verilog check
* fix verilog
* missqueue: support merging prefetch
* prefetch req can be merged to pipeline reg
* merging prefetch write will update cmd
* delay sending out acquire when a prefetch write is about to merge
* missqueue: fix bug of merging prefetch write
* delay sending out acquire when a pipeline reg is about to merging a
prefetch write
* temp: disable store pf
* missqueue: disable merging prefetch
* late prefetch will be ignored
* check alias when merging
* enable store pf at issue
* add L1StreamPrefetcher
* fix assert
* let prefetch req prefer loadunit1 more than 0
* stream prefetcher
* disable stream component in SMS, SMS is only trained on real miss
* add a prefetcher monitor to adjust depth & confidence ..
* add L1 L2 stream prefetch
* add gene support
* Revert "add gene support"
This reverts commit 59ae15640ff3d1cc96347f4d3567d48c740a03bb.
* add miss db
* l1pf: add stride & store source info in cache meta
* add a Stride prefetcher and disable Stride component in sms
* prefetch bit in meta is expanded into 3 bits to store source info of
prefetcher
* prefetch: support sending prefetch req to l3
* l1pf: add FDP & refactor
* add basic FDP counters
* change stride from Block addr to Byte addr
* refactor the code
* bump submodules
* disable load related chiseldb to reduce db size
* fix compile
* fix minimalConfig & enable stream
* fix stride pc problem
* fix minimalconfig compile
* bump submodules
* refactor stream stride helper
* fix compile
* bump huancun
* disable db to save size
* fix l2 assert
* bump submodules
---------
Co-authored-by: tastynoob <934348725@qq.com>
Co-authored-by: Haojin Tang <tanghaojin@outlook.com>
Co-authored-by: Guokai Chen <chenguokai17@mails.ucas.ac.cn>
Co-authored-by: XiChen <chenxi171@mails.ucas.ac.cn>
Co-authored-by: Zhou Yaoyang <shinezyy@qq.com>
2023-09-06 16:07:59 +08:00
|
|
|
}
|
|
|
|
prefetcher.io.memSetPattenDetected := io.memSetPattenDetected
|
|
|
|
|
2022-07-26 15:11:33 +08:00
|
|
|
def wordReqToBufLine( // allocate a new line in sbuffer
|
|
|
|
req: DCacheWordReq,
|
|
|
|
reqptag: UInt,
|
|
|
|
reqvtag: UInt,
|
|
|
|
insertIdx: UInt,
|
|
|
|
insertVec: UInt,
|
2022-08-10 09:54:52 +08:00
|
|
|
wordOffset: UInt
|
2022-07-26 15:11:33 +08:00
|
|
|
): Unit = {
|
2021-12-21 17:07:58 +08:00
|
|
|
assert(UIntToOH(insertIdx) === insertVec)
|
2021-11-29 11:34:37 +08:00
|
|
|
val sameBlockInflightMask = genSameBlockInflightMask(reqptag)
|
2021-12-21 17:07:58 +08:00
|
|
|
(0 until StoreBufferSize).map(entryIdx => {
|
|
|
|
when(insertVec(entryIdx)){
|
|
|
|
stateVec(entryIdx).state_valid := true.B
|
|
|
|
stateVec(entryIdx).w_sameblock_inflight := sameBlockInflightMask.orR // set w_sameblock_inflight when a line is first allocated
|
|
|
|
when(sameBlockInflightMask.orR){
|
|
|
|
waitInflightMask(entryIdx) := sameBlockInflightMask
|
|
|
|
}
|
|
|
|
cohCount(entryIdx) := 0.U
|
|
|
|
// missqReplayCount(insertIdx) := 0.U
|
|
|
|
ptag(entryIdx) := reqptag
|
2023-07-24 21:35:30 +08:00
|
|
|
vtag(entryIdx) := reqvtag // update vtag if a new sbuffer line is allocated
|
2020-12-28 16:35:14 +08:00
|
|
|
}
|
2021-12-21 17:07:58 +08:00
|
|
|
})
|
2020-10-05 20:56:23 +08:00
|
|
|
}
|
|
|
|
|
2022-07-26 15:11:33 +08:00
|
|
|
def mergeWordReq( // merge write req into an existing line
|
|
|
|
req: DCacheWordReq,
|
|
|
|
reqptag: UInt,
|
|
|
|
reqvtag: UInt,
|
|
|
|
mergeIdx: UInt,
|
|
|
|
mergeVec: UInt,
|
|
|
|
wordOffset: UInt
|
|
|
|
): Unit = {
|
2021-12-21 17:07:58 +08:00
|
|
|
assert(UIntToOH(mergeIdx) === mergeVec)
|
|
|
|
(0 until StoreBufferSize).map(entryIdx => {
|
|
|
|
when(mergeVec(entryIdx)) {
|
|
|
|
cohCount(entryIdx) := 0.U
|
|
|
|
// missqReplayCount(entryIdx) := 0.U
|
|
|
|
// check if vtag is the same, if not, trigger sbuffer flush
|
|
|
|
when(reqvtag =/= vtag(entryIdx)) {
|
|
|
|
XSDebug("reqvtag =/= sbufvtag req(vtag %x ptag %x) sbuffer(vtag %x ptag %x)\n",
|
|
|
|
reqvtag << OffsetWidth,
|
|
|
|
reqptag << OffsetWidth,
|
|
|
|
vtag(entryIdx) << OffsetWidth,
|
|
|
|
ptag(entryIdx) << OffsetWidth
|
|
|
|
)
|
|
|
|
merge_need_uarch_drain := true.B
|
|
|
|
}
|
2020-10-05 20:56:23 +08:00
|
|
|
}
|
2021-12-21 17:07:58 +08:00
|
|
|
})
|
2020-10-05 20:56:23 +08:00
|
|
|
}
|
|
|
|
|
2023-07-24 21:35:30 +08:00
|
|
|
for(((in, vwordOffset), i) <- io.in.zip(Seq(firstWord, secondWord)).zipWithIndex){
|
2024-04-05 17:47:56 +08:00
|
|
|
writeReq(i).valid := in.fire && in.bits.vecValid
|
2023-07-24 21:35:30 +08:00
|
|
|
writeReq(i).bits.vwordOffset := vwordOffset
|
2021-03-06 15:36:27 +08:00
|
|
|
writeReq(i).bits.mask := in.bits.mask
|
|
|
|
writeReq(i).bits.data := in.bits.data
|
2021-10-20 22:37:06 +08:00
|
|
|
writeReq(i).bits.wline := in.bits.wline
|
2022-07-26 15:11:33 +08:00
|
|
|
val debug_insertIdx = if(i == 0) firstInsertIdx else secondInsertIdx
|
|
|
|
val insertVec = if(i == 0) firstInsertVec else secondInsertVec
|
2024-04-05 17:47:56 +08:00
|
|
|
assert(!((PopCount(insertVec) > 1.U) && in.fire && in.bits.vecValid))
|
2021-12-21 17:07:58 +08:00
|
|
|
val insertIdx = OHToUInt(insertVec)
|
2024-06-16 19:13:35 +08:00
|
|
|
val accessValid = in.fire && in.bits.vecValid
|
|
|
|
accessIdx(i).valid := RegNext(accessValid)
|
|
|
|
accessIdx(i).bits := RegEnable(Mux(canMerge(i), mergeIdx(i), insertIdx), accessValid)
|
|
|
|
when(accessValid){
|
2021-03-04 17:16:47 +08:00
|
|
|
when(canMerge(i)){
|
2021-12-21 17:07:58 +08:00
|
|
|
writeReq(i).bits.wvec := mergeVec(i)
|
2023-07-24 21:35:30 +08:00
|
|
|
mergeWordReq(in.bits, inptags(i), invtags(i), mergeIdx(i), mergeVec(i), vwordOffset)
|
2021-03-04 17:16:47 +08:00
|
|
|
XSDebug(p"merge req $i to line [${mergeIdx(i)}]\n")
|
|
|
|
}.otherwise({
|
2021-12-21 17:07:58 +08:00
|
|
|
writeReq(i).bits.wvec := insertVec
|
2023-07-24 21:35:30 +08:00
|
|
|
wordReqToBufLine(in.bits, inptags(i), invtags(i), insertIdx, insertVec, vwordOffset)
|
2021-03-04 17:16:47 +08:00
|
|
|
XSDebug(p"insert req $i to line[$insertIdx]\n")
|
2021-12-21 17:07:58 +08:00
|
|
|
assert(debug_insertIdx === insertIdx)
|
2021-03-04 17:16:47 +08:00
|
|
|
})
|
2020-10-05 20:56:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-03 12:23:09 +08:00
|
|
|
|
2020-10-06 16:23:37 +08:00
|
|
|
for(i <- 0 until StoreBufferSize){
|
2021-10-20 15:48:32 +08:00
|
|
|
XSDebug(stateVec(i).isValid(),
|
|
|
|
p"[$i] timeout:${cohCount(i)(EvictCountBits-1)} state:${stateVec(i)}\n"
|
2020-10-06 21:15:39 +08:00
|
|
|
)
|
2020-10-06 16:23:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for((req, i) <- io.in.zipWithIndex){
|
2024-04-05 17:47:56 +08:00
|
|
|
XSDebug(req.fire && req.bits.vecValid,
|
2020-10-06 16:23:37 +08:00
|
|
|
p"accept req [$i]: " +
|
|
|
|
p"addr:${Hexadecimal(req.bits.addr)} " +
|
2023-07-24 21:35:30 +08:00
|
|
|
p"mask:${Binary(shiftMaskToLow(req.bits.addr,req.bits.mask))} " +
|
|
|
|
p"data:${Hexadecimal(shiftDataToLow(req.bits.addr,req.bits.data))}\n"
|
2020-10-06 21:15:39 +08:00
|
|
|
)
|
|
|
|
XSDebug(req.valid && !req.ready,
|
|
|
|
p"req [$i] blocked by sbuffer\n"
|
2020-10-06 16:23:37 +08:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
L1 Prefetch (#2261)
* dcache: optimize the ready signal of missqueue
Add a custom arbiter. In the case of multiple sources with the same
cache block address, the arbiter will assign only one entry in
misssqueue but ready for all same cache block address requests.
This will reduce the number of replays of the load instruction which cannot
enter the missqueue
* sta, dcache: add A StorePipe in dcache
When the store command passes through the sta pipeline, access the tag
and meta of dcache to determine whether it hits, if it hits, update the
replacement algorithm, and if miss, send a write intent to missqueue
* sta prefetch: add a queue
Enter this queue when the Store Address pipeline sends a request,
determines that it has a cache miss, and the contention for MSHR fails.
The miss request in this queue will be sent to the Store pipeline later.
* sbuffer, dcache: store prefetch burst
A basic implementation of "Boosting Store Buffer Efficiency with
Store-Prefetch Bursts".
Store prefetch at exe is disabled.
Now, when store goes from sq to sbuffer, it will trigger a store
prefetch; when 48 stores fall into 6 cache lines, trigger a store burst
perfetch, which will bring a whole page back into dcache.
* dcache: restric mshr alloc for prefetch req
* restric the max number of entries which can be used by prefetch
* merge two same cache line address prefetch write req
* dynamically detect memset pattern, all mshr can accept prefetch when
pattern is detected
* spb: constantin support
* dcache: fix missqueue prefetch ready
* make prefetch req goes mshr with bigger id
* Revert "spb: constantin support"
This reverts commit 4ee50b89ba4a62cd28fa22d7fbcb2338ad4b1849.
* spb: fix bug in burst generator
* spb: add load prefetch burst support
* topdown: add defines of topdown counters enum
* redirect: add redirect type for perf
* top-down: add stallReason IOs
frontend -> ctrlBlock -> decode -> rename -> dispatch
* top-down: add dummy connections
* top-down: update TopdownCounters
* top-down: imp backend analysis and counter dump
* top-down: add HartId in `addSource`
* top-down: broadcast lqIdx of ROB head
* top-down: frontend signal done
* top-down: add memblock topdown interface
* Bump HuanCun: add TopDownMonitor
* top-down: receive and handle reasons in dispatch
* top-down: remove previous top-down code
* TopDown: add MemReqSource enum
* TopDown: extend mshr_latency range
* TopDown: add basic Req Source
TODO: distinguish prefetch
* store prefetch: refactor parameters and fix bug
* change some parameters
* fix store pipe bug
* fix load prefetch burst
* dcache: distinguish L1DataPrefetch and CPUData
* top-down: comment out debugging perf counters in ibuffer
* TopDown: add path to pass MemReqSource to HuanCun
* TopDown: use simpler logic to count reqSource and update Probe count
* frontend: update topdown counters
* Update HuanCun Topdown for MemReqSource
* top-down: fix load stalls
* top-down: Change the priority of different stall reasons
* store prefetch: add stride and l2 prefetch
* add a stride prefetcher
* spb and stride will issue prefetch to l2
* when store commits, issue a prefetch to l1
* sbuffer: fix eviction
* when valid count reaches StoreBufferSize, do eviction
* spf: change store prefetch structure
* prefetch @ exe -> l2 cache
* stride -> l2 cache
* sbuffer: fix replaceIdx
* If the way selected by the replacement algorithm cannot be written into dcache, its result is not used.
* Revert "sbuffer: fix replaceIdx"
This reverts commit 40c16aca956af9fb32554a0f12d18db41c22eecd.
* spf: find best interval in stamissqueue
* Revert "spf: find best interval in stamissqueue"
This reverts commit d179f0ce15a5ab989a822de7fe48cc5e2cd96914.
* sms: port store to sms
Miss store will train sms like load.
Now, sms will recieve 4 train sources, 2 for miss load, 2 for miss
store, but prefetcher consume 1 train req per cycle, PrefetchTrainFilter
is added to deal with this case.
* bump huancun
* spf: refactor structure
* miss stores will train sms, and send prefetch to l2
* miss stores will send prefetch to l1 on issue or commit
* spb will send prefetch to l1
* memset: fix memset detection
use lqEmpty to check this
* constantin: storepf constantin support
cherry-pick this to use constantin in storepf
* Revert "constantin: storepf constantin support"
This reverts commit 2b97767b9fa757d920cac3d80d4893a1380592c7.
* storepf: add EnableAtCommitMissTrigger
* trigger prefetch at commit only when the store misses with
EnableAtCommitMissTrigger
* bump coupledl2
* prefetch req from L1 to L2 will Acquire T
* fix merge conflict
* storepf: do not read meta&tag when pf is disabled
* storepf: do not read pcMem when sms store is disabled
* fix verilog check
* fix verilog
* missqueue: support merging prefetch
* prefetch req can be merged to pipeline reg
* merging prefetch write will update cmd
* delay sending out acquire when a prefetch write is about to merge
* missqueue: fix bug of merging prefetch write
* delay sending out acquire when a pipeline reg is about to merging a
prefetch write
* temp: disable store pf
* missqueue: disable merging prefetch
* late prefetch will be ignored
* check alias when merging
* enable store pf at issue
* add L1StreamPrefetcher
* fix assert
* let prefetch req prefer loadunit1 more than 0
* stream prefetcher
* disable stream component in SMS, SMS is only trained on real miss
* add a prefetcher monitor to adjust depth & confidence ..
* add L1 L2 stream prefetch
* add gene support
* Revert "add gene support"
This reverts commit 59ae15640ff3d1cc96347f4d3567d48c740a03bb.
* add miss db
* l1pf: add stride & store source info in cache meta
* add a Stride prefetcher and disable Stride component in sms
* prefetch bit in meta is expanded into 3 bits to store source info of
prefetcher
* prefetch: support sending prefetch req to l3
* l1pf: add FDP & refactor
* add basic FDP counters
* change stride from Block addr to Byte addr
* refactor the code
* bump submodules
* disable load related chiseldb to reduce db size
* fix compile
* fix minimalConfig & enable stream
* fix stride pc problem
* fix minimalconfig compile
* bump submodules
* refactor stream stride helper
* fix compile
* bump huancun
* disable db to save size
* fix l2 assert
* bump submodules
---------
Co-authored-by: tastynoob <934348725@qq.com>
Co-authored-by: Haojin Tang <tanghaojin@outlook.com>
Co-authored-by: Guokai Chen <chenguokai17@mails.ucas.ac.cn>
Co-authored-by: XiChen <chenxi171@mails.ucas.ac.cn>
Co-authored-by: Zhou Yaoyang <shinezyy@qq.com>
2023-09-06 16:07:59 +08:00
|
|
|
// for now, when enq, trigger a prefetch (if EnableAtCommitMissTrigger)
|
2024-03-04 16:02:11 +08:00
|
|
|
require(EnsbufferWidth <= StorePipelineWidth)
|
L1 Prefetch (#2261)
* dcache: optimize the ready signal of missqueue
Add a custom arbiter. In the case of multiple sources with the same
cache block address, the arbiter will assign only one entry in
misssqueue but ready for all same cache block address requests.
This will reduce the number of replays of the load instruction which cannot
enter the missqueue
* sta, dcache: add A StorePipe in dcache
When the store command passes through the sta pipeline, access the tag
and meta of dcache to determine whether it hits, if it hits, update the
replacement algorithm, and if miss, send a write intent to missqueue
* sta prefetch: add a queue
Enter this queue when the Store Address pipeline sends a request,
determines that it has a cache miss, and the contention for MSHR fails.
The miss request in this queue will be sent to the Store pipeline later.
* sbuffer, dcache: store prefetch burst
A basic implementation of "Boosting Store Buffer Efficiency with
Store-Prefetch Bursts".
Store prefetch at exe is disabled.
Now, when store goes from sq to sbuffer, it will trigger a store
prefetch; when 48 stores fall into 6 cache lines, trigger a store burst
perfetch, which will bring a whole page back into dcache.
* dcache: restric mshr alloc for prefetch req
* restric the max number of entries which can be used by prefetch
* merge two same cache line address prefetch write req
* dynamically detect memset pattern, all mshr can accept prefetch when
pattern is detected
* spb: constantin support
* dcache: fix missqueue prefetch ready
* make prefetch req goes mshr with bigger id
* Revert "spb: constantin support"
This reverts commit 4ee50b89ba4a62cd28fa22d7fbcb2338ad4b1849.
* spb: fix bug in burst generator
* spb: add load prefetch burst support
* topdown: add defines of topdown counters enum
* redirect: add redirect type for perf
* top-down: add stallReason IOs
frontend -> ctrlBlock -> decode -> rename -> dispatch
* top-down: add dummy connections
* top-down: update TopdownCounters
* top-down: imp backend analysis and counter dump
* top-down: add HartId in `addSource`
* top-down: broadcast lqIdx of ROB head
* top-down: frontend signal done
* top-down: add memblock topdown interface
* Bump HuanCun: add TopDownMonitor
* top-down: receive and handle reasons in dispatch
* top-down: remove previous top-down code
* TopDown: add MemReqSource enum
* TopDown: extend mshr_latency range
* TopDown: add basic Req Source
TODO: distinguish prefetch
* store prefetch: refactor parameters and fix bug
* change some parameters
* fix store pipe bug
* fix load prefetch burst
* dcache: distinguish L1DataPrefetch and CPUData
* top-down: comment out debugging perf counters in ibuffer
* TopDown: add path to pass MemReqSource to HuanCun
* TopDown: use simpler logic to count reqSource and update Probe count
* frontend: update topdown counters
* Update HuanCun Topdown for MemReqSource
* top-down: fix load stalls
* top-down: Change the priority of different stall reasons
* store prefetch: add stride and l2 prefetch
* add a stride prefetcher
* spb and stride will issue prefetch to l2
* when store commits, issue a prefetch to l1
* sbuffer: fix eviction
* when valid count reaches StoreBufferSize, do eviction
* spf: change store prefetch structure
* prefetch @ exe -> l2 cache
* stride -> l2 cache
* sbuffer: fix replaceIdx
* If the way selected by the replacement algorithm cannot be written into dcache, its result is not used.
* Revert "sbuffer: fix replaceIdx"
This reverts commit 40c16aca956af9fb32554a0f12d18db41c22eecd.
* spf: find best interval in stamissqueue
* Revert "spf: find best interval in stamissqueue"
This reverts commit d179f0ce15a5ab989a822de7fe48cc5e2cd96914.
* sms: port store to sms
Miss store will train sms like load.
Now, sms will recieve 4 train sources, 2 for miss load, 2 for miss
store, but prefetcher consume 1 train req per cycle, PrefetchTrainFilter
is added to deal with this case.
* bump huancun
* spf: refactor structure
* miss stores will train sms, and send prefetch to l2
* miss stores will send prefetch to l1 on issue or commit
* spb will send prefetch to l1
* memset: fix memset detection
use lqEmpty to check this
* constantin: storepf constantin support
cherry-pick this to use constantin in storepf
* Revert "constantin: storepf constantin support"
This reverts commit 2b97767b9fa757d920cac3d80d4893a1380592c7.
* storepf: add EnableAtCommitMissTrigger
* trigger prefetch at commit only when the store misses with
EnableAtCommitMissTrigger
* bump coupledl2
* prefetch req from L1 to L2 will Acquire T
* fix merge conflict
* storepf: do not read meta&tag when pf is disabled
* storepf: do not read pcMem when sms store is disabled
* fix verilog check
* fix verilog
* missqueue: support merging prefetch
* prefetch req can be merged to pipeline reg
* merging prefetch write will update cmd
* delay sending out acquire when a prefetch write is about to merge
* missqueue: fix bug of merging prefetch write
* delay sending out acquire when a pipeline reg is about to merging a
prefetch write
* temp: disable store pf
* missqueue: disable merging prefetch
* late prefetch will be ignored
* check alias when merging
* enable store pf at issue
* add L1StreamPrefetcher
* fix assert
* let prefetch req prefer loadunit1 more than 0
* stream prefetcher
* disable stream component in SMS, SMS is only trained on real miss
* add a prefetcher monitor to adjust depth & confidence ..
* add L1 L2 stream prefetch
* add gene support
* Revert "add gene support"
This reverts commit 59ae15640ff3d1cc96347f4d3567d48c740a03bb.
* add miss db
* l1pf: add stride & store source info in cache meta
* add a Stride prefetcher and disable Stride component in sms
* prefetch bit in meta is expanded into 3 bits to store source info of
prefetcher
* prefetch: support sending prefetch req to l3
* l1pf: add FDP & refactor
* add basic FDP counters
* change stride from Block addr to Byte addr
* refactor the code
* bump submodules
* disable load related chiseldb to reduce db size
* fix compile
* fix minimalConfig & enable stream
* fix stride pc problem
* fix minimalconfig compile
* bump submodules
* refactor stream stride helper
* fix compile
* bump huancun
* disable db to save size
* fix l2 assert
* bump submodules
---------
Co-authored-by: tastynoob <934348725@qq.com>
Co-authored-by: Haojin Tang <tanghaojin@outlook.com>
Co-authored-by: Guokai Chen <chenguokai17@mails.ucas.ac.cn>
Co-authored-by: XiChen <chenxi171@mails.ucas.ac.cn>
Co-authored-by: Zhou Yaoyang <shinezyy@qq.com>
2023-09-06 16:07:59 +08:00
|
|
|
|
2020-10-05 20:56:23 +08:00
|
|
|
// ---------------------- Send Dcache Req ---------------------
|
|
|
|
|
2023-09-21 10:02:22 +08:00
|
|
|
val sbuffer_empty = Cat(invalidMask).andR
|
|
|
|
val sq_empty = !Cat(io.in.map(_.valid)).orR
|
2021-08-03 21:41:19 +08:00
|
|
|
val empty = sbuffer_empty && sq_empty
|
2023-07-25 13:30:51 +08:00
|
|
|
val threshold = Wire(UInt(5.W)) // RegNext(io.csrCtrl.sbuffer_threshold +& 1.U)
|
2024-05-10 09:13:13 +08:00
|
|
|
threshold := Constantin.createRecord(s"StoreBufferThreshold_${p(XSCoreParamsKey).HartId}", initValue = 7)
|
2023-07-25 13:30:51 +08:00
|
|
|
val base = Wire(UInt(5.W))
|
2024-05-10 09:13:13 +08:00
|
|
|
base := Constantin.createRecord(s"StoreBufferBase_${p(XSCoreParamsKey).HartId}", initValue = 4)
|
2023-06-02 18:27:43 +08:00
|
|
|
val ActiveCount = PopCount(activeMask)
|
|
|
|
val ValidCount = PopCount(validMask)
|
2023-07-25 13:30:51 +08:00
|
|
|
val forceThreshold = Mux(io.force_write, threshold - base, threshold)
|
2024-06-16 19:13:35 +08:00
|
|
|
val do_eviction = GatedValidRegNext(ActiveCount >= forceThreshold || ActiveCount === (StoreBufferSize-1).U || ValidCount === (StoreBufferSize).U, init = false.B)
|
2021-09-01 15:04:17 +08:00
|
|
|
require((StoreBufferThreshold + 1) <= StoreBufferSize)
|
2020-12-28 16:35:14 +08:00
|
|
|
|
2023-06-02 18:27:43 +08:00
|
|
|
XSDebug(p"ActiveCount[$ActiveCount]\n")
|
2020-10-06 21:15:39 +08:00
|
|
|
|
2024-06-16 19:13:35 +08:00
|
|
|
io.flush.empty := GatedValidRegNext(empty && io.sqempty)
|
2021-08-03 21:41:19 +08:00
|
|
|
// lru.io.flush := sbuffer_state === x_drain_all && empty
|
2020-10-05 20:56:23 +08:00
|
|
|
switch(sbuffer_state){
|
|
|
|
is(x_idle){
|
|
|
|
when(io.flush.valid){
|
2021-08-03 21:41:19 +08:00
|
|
|
sbuffer_state := x_drain_all
|
|
|
|
}.elsewhen(do_uarch_drain){
|
2020-10-05 20:56:23 +08:00
|
|
|
sbuffer_state := x_drain_sbuffer
|
2020-10-06 21:15:39 +08:00
|
|
|
}.elsewhen(do_eviction){
|
2020-10-05 20:56:23 +08:00
|
|
|
sbuffer_state := x_replace
|
|
|
|
}
|
|
|
|
}
|
2021-08-03 21:41:19 +08:00
|
|
|
is(x_drain_all){
|
2020-10-05 20:56:23 +08:00
|
|
|
when(empty){
|
|
|
|
sbuffer_state := x_idle
|
|
|
|
}
|
|
|
|
}
|
2021-08-03 21:41:19 +08:00
|
|
|
is(x_drain_sbuffer){
|
2021-11-29 11:34:37 +08:00
|
|
|
when(io.flush.valid){
|
|
|
|
sbuffer_state := x_drain_all
|
|
|
|
}.elsewhen(sbuffer_empty){
|
2021-08-03 21:41:19 +08:00
|
|
|
sbuffer_state := x_idle
|
|
|
|
}
|
|
|
|
}
|
2020-10-05 20:56:23 +08:00
|
|
|
is(x_replace){
|
|
|
|
when(io.flush.valid){
|
2021-08-03 21:41:19 +08:00
|
|
|
sbuffer_state := x_drain_all
|
|
|
|
}.elsewhen(do_uarch_drain){
|
2020-10-05 20:56:23 +08:00
|
|
|
sbuffer_state := x_drain_sbuffer
|
2020-10-06 21:15:39 +08:00
|
|
|
}.elsewhen(!do_eviction){
|
2020-10-05 20:56:23 +08:00
|
|
|
sbuffer_state := x_idle
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-06 21:15:39 +08:00
|
|
|
XSDebug(p"sbuffer state:${sbuffer_state} do eviction:${do_eviction} empty:${empty}\n")
|
2020-10-05 20:56:23 +08:00
|
|
|
|
2020-10-07 14:43:14 +08:00
|
|
|
def noSameBlockInflight(idx: UInt): Bool = {
|
2021-03-04 17:16:47 +08:00
|
|
|
// stateVec(idx) itself must not be s_inflight
|
2023-09-21 10:02:22 +08:00
|
|
|
!Cat(widthMap(i => inflightMask(i) && ptag(idx) === ptag(i))).orR
|
2020-10-07 14:43:14 +08:00
|
|
|
}
|
|
|
|
|
2021-11-29 11:34:37 +08:00
|
|
|
def genSameBlockInflightMask(ptag_in: UInt): UInt = {
|
|
|
|
val mask = VecInit(widthMap(i => inflightMask(i) && ptag_in === ptag(i))).asUInt // quite slow, use it with care
|
|
|
|
assert(!(PopCount(mask) > 1.U))
|
|
|
|
mask
|
|
|
|
}
|
|
|
|
|
|
|
|
def haveSameBlockInflight(ptag_in: UInt): Bool = {
|
|
|
|
genSameBlockInflightMask(ptag_in).orR
|
|
|
|
}
|
|
|
|
|
2022-07-24 18:28:25 +08:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// sbuffer to dcache pipeline
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2022-07-26 15:11:33 +08:00
|
|
|
// Now sbuffer deq logic is divided into 2 stages:
|
|
|
|
|
|
|
|
// sbuffer_out_s0:
|
|
|
|
// * read data and meta from sbuffer
|
|
|
|
// * RegNext() them
|
|
|
|
// * set line state to inflight
|
|
|
|
|
|
|
|
// sbuffer_out_s1:
|
|
|
|
// * send write req to dcache
|
|
|
|
|
|
|
|
// sbuffer_out_extra:
|
|
|
|
// * receive write result from dcache
|
|
|
|
// * update line state
|
|
|
|
|
2022-07-24 18:28:25 +08:00
|
|
|
val sbuffer_out_s1_ready = Wire(Bool())
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// sbuffer_out_s0
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2021-08-03 21:41:19 +08:00
|
|
|
val need_drain = needDrain(sbuffer_state)
|
2021-03-04 17:16:47 +08:00
|
|
|
val need_replace = do_eviction || (sbuffer_state === x_replace)
|
2022-07-24 18:28:25 +08:00
|
|
|
val sbuffer_out_s0_evictionIdx = Mux(missqReplayHasTimeOut,
|
2022-07-28 19:51:17 +08:00
|
|
|
missqReplayTimeOutIdx,
|
2021-10-20 15:48:32 +08:00
|
|
|
Mux(need_drain,
|
|
|
|
drainIdx,
|
|
|
|
Mux(cohHasTimeOut, cohTimeOutIdx, replaceIdx)
|
|
|
|
)
|
2021-03-04 17:16:47 +08:00
|
|
|
)
|
2022-07-24 18:28:25 +08:00
|
|
|
|
|
|
|
// If there is a inflight dcache req which has same ptag with sbuffer_out_s0_evictionIdx's ptag,
|
|
|
|
// current eviction should be blocked.
|
2023-07-24 21:35:30 +08:00
|
|
|
val sbuffer_out_s0_valid = missqReplayHasTimeOut ||
|
2022-07-24 18:28:25 +08:00
|
|
|
stateVec(sbuffer_out_s0_evictionIdx).isDcacheReqCandidate() &&
|
|
|
|
(need_drain || cohHasTimeOut || need_replace)
|
|
|
|
assert(!(
|
2024-07-22 11:09:11 +08:00
|
|
|
stateVec(sbuffer_out_s0_evictionIdx).isDcacheReqCandidate() &&
|
2022-07-24 18:28:25 +08:00
|
|
|
!noSameBlockInflight(sbuffer_out_s0_evictionIdx)
|
|
|
|
))
|
|
|
|
val sbuffer_out_s0_cango = sbuffer_out_s1_ready
|
|
|
|
sbuffer_out_s0_fire := sbuffer_out_s0_valid && sbuffer_out_s0_cango
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// sbuffer_out_s1
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2022-07-26 15:11:33 +08:00
|
|
|
// TODO: use EnsbufferWidth
|
2024-06-16 19:13:35 +08:00
|
|
|
val shouldWaitWriteFinish = GatedValidRegNext(VecInit((0 until EnsbufferWidth).map{i =>
|
2022-07-28 19:51:17 +08:00
|
|
|
(writeReq(i).bits.wvec.asUInt & UIntToOH(sbuffer_out_s0_evictionIdx).asUInt).orR &&
|
|
|
|
writeReq(i).valid
|
|
|
|
}).asUInt.orR)
|
2022-07-26 15:11:33 +08:00
|
|
|
// block dcache write if read / write hazard
|
|
|
|
val blockDcacheWrite = shouldWaitWriteFinish
|
|
|
|
|
2022-07-24 18:28:25 +08:00
|
|
|
val sbuffer_out_s1_valid = RegInit(false.B)
|
2022-07-26 15:11:33 +08:00
|
|
|
sbuffer_out_s1_ready := io.dcache.req.ready && !blockDcacheWrite || !sbuffer_out_s1_valid
|
2023-09-21 10:02:22 +08:00
|
|
|
val sbuffer_out_s1_fire = io.dcache.req.fire
|
2022-07-24 18:28:25 +08:00
|
|
|
|
|
|
|
// when sbuffer_out_s1_fire, send dcache req stored in pipeline reg to dcache
|
|
|
|
when(sbuffer_out_s1_fire){
|
|
|
|
sbuffer_out_s1_valid := false.B
|
2021-01-28 14:47:27 +08:00
|
|
|
}
|
2023-07-24 21:35:30 +08:00
|
|
|
// when sbuffer_out_s0_fire, read dcache req data and store them in a pipeline reg
|
2022-07-24 18:28:25 +08:00
|
|
|
when(sbuffer_out_s0_cango){
|
|
|
|
sbuffer_out_s1_valid := sbuffer_out_s0_valid
|
2021-01-05 20:30:25 +08:00
|
|
|
}
|
2022-07-24 18:28:25 +08:00
|
|
|
when(sbuffer_out_s0_fire){
|
|
|
|
stateVec(sbuffer_out_s0_evictionIdx).state_inflight := true.B
|
|
|
|
stateVec(sbuffer_out_s0_evictionIdx).w_timeout := false.B
|
|
|
|
// stateVec(sbuffer_out_s0_evictionIdx).s_pipe_req := true.B
|
|
|
|
XSDebug(p"$sbuffer_out_s0_evictionIdx will be sent to Dcache\n")
|
2021-03-04 17:16:47 +08:00
|
|
|
}
|
2022-07-24 18:28:25 +08:00
|
|
|
|
2021-10-20 15:48:32 +08:00
|
|
|
XSDebug(p"need drain:$need_drain cohHasTimeOut: $cohHasTimeOut need replace:$need_replace\n")
|
|
|
|
XSDebug(p"drainIdx:$drainIdx tIdx:$cohTimeOutIdx replIdx:$replaceIdx " +
|
2022-07-24 18:28:25 +08:00
|
|
|
p"blocked:${!noSameBlockInflight(sbuffer_out_s0_evictionIdx)} v:${activeMask(sbuffer_out_s0_evictionIdx)}\n")
|
|
|
|
XSDebug(p"sbuffer_out_s0_valid:$sbuffer_out_s0_valid evictIdx:$sbuffer_out_s0_evictionIdx dcache ready:${io.dcache.req.ready}\n")
|
2021-03-04 17:16:47 +08:00
|
|
|
// Note: if other dcache req in the same block are inflight,
|
2021-10-20 15:48:32 +08:00
|
|
|
// the lru update may not accurate
|
2022-05-06 23:01:31 +08:00
|
|
|
accessIdx(EnsbufferWidth).valid := invalidMask(replaceIdx) || (
|
2022-07-24 18:28:25 +08:00
|
|
|
need_replace && !need_drain && !cohHasTimeOut && !missqReplayHasTimeOut && sbuffer_out_s0_cango && activeMask(replaceIdx))
|
2022-05-06 23:01:31 +08:00
|
|
|
accessIdx(EnsbufferWidth).bits := replaceIdx
|
2023-09-21 10:02:22 +08:00
|
|
|
val sbuffer_out_s1_evictionIdx = RegEnable(sbuffer_out_s0_evictionIdx, sbuffer_out_s0_fire)
|
|
|
|
val sbuffer_out_s1_evictionPTag = RegEnable(ptag(sbuffer_out_s0_evictionIdx), sbuffer_out_s0_fire)
|
|
|
|
val sbuffer_out_s1_evictionVTag = RegEnable(vtag(sbuffer_out_s0_evictionIdx), sbuffer_out_s0_fire)
|
2021-03-04 17:16:47 +08:00
|
|
|
|
2022-07-26 15:11:33 +08:00
|
|
|
io.dcache.req.valid := sbuffer_out_s1_valid && !blockDcacheWrite
|
2021-10-20 15:48:32 +08:00
|
|
|
io.dcache.req.bits := DontCare
|
2022-07-24 18:28:25 +08:00
|
|
|
io.dcache.req.bits.cmd := MemoryOpConstants.M_XWR
|
|
|
|
io.dcache.req.bits.addr := getAddr(sbuffer_out_s1_evictionPTag)
|
|
|
|
io.dcache.req.bits.vaddr := getAddr(sbuffer_out_s1_evictionVTag)
|
|
|
|
io.dcache.req.bits.data := data(sbuffer_out_s1_evictionIdx).asUInt
|
|
|
|
io.dcache.req.bits.mask := mask(sbuffer_out_s1_evictionIdx).asUInt
|
|
|
|
io.dcache.req.bits.id := sbuffer_out_s1_evictionIdx
|
|
|
|
|
|
|
|
when (sbuffer_out_s1_fire) {
|
2021-10-20 15:48:32 +08:00
|
|
|
assert(!(io.dcache.req.bits.vaddr === 0.U))
|
|
|
|
assert(!(io.dcache.req.bits.addr === 0.U))
|
|
|
|
}
|
|
|
|
|
2022-07-24 18:28:25 +08:00
|
|
|
XSDebug(sbuffer_out_s1_fire,
|
|
|
|
p"send buf [$sbuffer_out_s1_evictionIdx] to Dcache, req fire\n"
|
2020-10-06 16:23:37 +08:00
|
|
|
)
|
|
|
|
|
2021-10-20 15:48:32 +08:00
|
|
|
// update sbuffer status according to dcache resp source
|
|
|
|
|
2021-11-29 11:34:37 +08:00
|
|
|
def id_to_sbuffer_id(id: UInt): UInt = {
|
|
|
|
require(id.getWidth >= log2Up(StoreBufferSize))
|
|
|
|
id(log2Up(StoreBufferSize)-1, 0)
|
|
|
|
}
|
|
|
|
|
2021-10-20 15:48:32 +08:00
|
|
|
// hit resp
|
|
|
|
io.dcache.hit_resps.map(resp => {
|
2021-11-29 11:34:37 +08:00
|
|
|
val dcache_resp_id = resp.bits.id
|
2023-09-21 10:02:22 +08:00
|
|
|
when (resp.fire) {
|
2021-10-20 15:48:32 +08:00
|
|
|
stateVec(dcache_resp_id).state_inflight := false.B
|
|
|
|
stateVec(dcache_resp_id).state_valid := false.B
|
|
|
|
assert(!resp.bits.replay)
|
|
|
|
assert(!resp.bits.miss) // not need to resp if miss, to be opted
|
|
|
|
assert(stateVec(dcache_resp_id).state_inflight === true.B)
|
|
|
|
}
|
2021-11-29 11:34:37 +08:00
|
|
|
|
|
|
|
// Update w_sameblock_inflight flag is delayed for 1 cycle
|
|
|
|
//
|
2023-07-24 21:35:30 +08:00
|
|
|
// When a new req allocate a new line in sbuffer, sameblock_inflight check will ignore
|
2021-11-29 11:34:37 +08:00
|
|
|
// current dcache.hit_resps. Then, in the next cycle, we have plenty of time to check
|
|
|
|
// if the same block is still inflight
|
|
|
|
(0 until StoreBufferSize).map(i => {
|
|
|
|
when(
|
2023-07-24 21:35:30 +08:00
|
|
|
stateVec(i).w_sameblock_inflight &&
|
2021-11-29 11:34:37 +08:00
|
|
|
stateVec(i).state_valid &&
|
2024-06-16 19:13:35 +08:00
|
|
|
GatedValidRegNext(resp.fire) &&
|
|
|
|
waitInflightMask(i) === UIntToOH(RegEnable(id_to_sbuffer_id(dcache_resp_id), resp.fire))
|
2021-11-29 11:34:37 +08:00
|
|
|
){
|
|
|
|
stateVec(i).w_sameblock_inflight := false.B
|
|
|
|
}
|
|
|
|
})
|
2021-10-20 15:48:32 +08:00
|
|
|
})
|
2020-10-05 20:56:23 +08:00
|
|
|
|
2022-08-10 09:54:52 +08:00
|
|
|
io.dcache.hit_resps.zip(dataModule.io.maskFlushReq).map{case (resp, maskFlush) => {
|
2023-09-21 10:02:22 +08:00
|
|
|
maskFlush.valid := resp.fire
|
2022-08-10 09:54:52 +08:00
|
|
|
maskFlush.bits.wvec := UIntToOH(resp.bits.id)
|
|
|
|
}}
|
2021-11-29 11:34:37 +08:00
|
|
|
|
2021-10-20 15:48:32 +08:00
|
|
|
// replay resp
|
|
|
|
val replay_resp_id = io.dcache.replay_resp.bits.id
|
2023-09-21 10:02:22 +08:00
|
|
|
when (io.dcache.replay_resp.fire) {
|
2021-10-20 15:48:32 +08:00
|
|
|
missqReplayCount(replay_resp_id) := 0.U
|
|
|
|
stateVec(replay_resp_id).w_timeout := true.B
|
|
|
|
// waiting for timeout
|
|
|
|
assert(io.dcache.replay_resp.bits.replay)
|
|
|
|
assert(stateVec(replay_resp_id).state_inflight === true.B)
|
2021-01-25 16:56:32 +08:00
|
|
|
}
|
2023-07-24 21:35:30 +08:00
|
|
|
|
2021-10-20 15:48:32 +08:00
|
|
|
// TODO: reuse cohCount
|
|
|
|
(0 until StoreBufferSize).map(i => {
|
|
|
|
when(stateVec(i).w_timeout && stateVec(i).state_inflight && !missqReplayCount(i)(MissqReplayCountBits-1)) {
|
2023-07-24 21:35:30 +08:00
|
|
|
missqReplayCount(i) := missqReplayCount(i) + 1.U
|
2021-10-20 15:48:32 +08:00
|
|
|
}
|
|
|
|
when(activeMask(i) && !cohTimeOutMask(i)){
|
2021-01-13 21:13:56 +08:00
|
|
|
cohCount(i) := cohCount(i)+1.U
|
|
|
|
}
|
2021-10-20 15:48:32 +08:00
|
|
|
})
|
|
|
|
|
2021-11-11 10:03:16 +08:00
|
|
|
if (env.EnableDifftest) {
|
2021-10-20 15:48:32 +08:00
|
|
|
// hit resp
|
|
|
|
io.dcache.hit_resps.zipWithIndex.map{case (resp, index) => {
|
2023-09-10 09:55:52 +08:00
|
|
|
val difftest = DifftestModule(new DiffSbufferEvent, delay = 1)
|
2021-10-20 15:48:32 +08:00
|
|
|
val dcache_resp_id = resp.bits.id
|
2023-09-10 09:55:52 +08:00
|
|
|
difftest.coreid := io.hartId
|
|
|
|
difftest.index := index.U
|
2023-09-21 10:02:22 +08:00
|
|
|
difftest.valid := resp.fire
|
2023-09-10 09:55:52 +08:00
|
|
|
difftest.addr := getAddr(ptag(dcache_resp_id))
|
|
|
|
difftest.data := data(dcache_resp_id).asTypeOf(Vec(CacheLineBytes, UInt(8.W)))
|
|
|
|
difftest.mask := mask(dcache_resp_id).asUInt
|
2021-10-20 15:48:32 +08:00
|
|
|
}}
|
2021-01-13 21:13:56 +08:00
|
|
|
}
|
|
|
|
|
2020-10-05 20:56:23 +08:00
|
|
|
// ---------------------- Load Data Forward ---------------------
|
2021-08-03 14:28:43 +08:00
|
|
|
val mismatch = Wire(Vec(LoadPipelineWidth, Bool()))
|
2022-11-18 14:07:57 +08:00
|
|
|
XSPerfAccumulate("vaddr_match_failed", mismatch(0) || mismatch(1))
|
2020-12-16 14:44:10 +08:00
|
|
|
for ((forward, i) <- io.forward.zipWithIndex) {
|
2021-08-03 14:28:43 +08:00
|
|
|
val vtag_matches = VecInit(widthMap(w => vtag(w) === getVTag(forward.vaddr)))
|
2022-11-18 14:52:30 +08:00
|
|
|
// ptag_matches uses paddr from dtlb, which is far from sbuffer
|
|
|
|
val ptag_matches = VecInit(widthMap(w => RegEnable(ptag(w), forward.valid) === RegEnable(getPTag(forward.paddr), forward.valid)))
|
2021-08-03 23:10:27 +08:00
|
|
|
val tag_matches = vtag_matches
|
2024-06-16 19:13:35 +08:00
|
|
|
val tag_mismatch = GatedValidRegNext(forward.valid) && VecInit(widthMap(w =>
|
|
|
|
GatedValidRegNext(vtag_matches(w)) =/= ptag_matches(w) && GatedValidRegNext((activeMask(w) || inflightMask(w)))
|
2021-08-03 14:28:43 +08:00
|
|
|
)).asUInt.orR
|
|
|
|
mismatch(i) := tag_mismatch
|
|
|
|
when (tag_mismatch) {
|
2021-09-28 09:23:31 +08:00
|
|
|
XSDebug("forward tag mismatch: pmatch %x vmatch %x vaddr %x paddr %x\n",
|
|
|
|
RegNext(ptag_matches.asUInt),
|
2021-08-03 21:41:19 +08:00
|
|
|
RegNext(vtag_matches.asUInt),
|
|
|
|
RegNext(forward.vaddr),
|
|
|
|
RegNext(forward.paddr)
|
|
|
|
)
|
2021-11-15 15:55:13 +08:00
|
|
|
forward_need_uarch_drain := true.B
|
2021-08-03 14:28:43 +08:00
|
|
|
}
|
2021-10-20 15:48:32 +08:00
|
|
|
val valid_tag_matches = widthMap(w => tag_matches(w) && activeMask(w))
|
2021-03-04 17:16:47 +08:00
|
|
|
val inflight_tag_matches = widthMap(w => tag_matches(w) && inflightMask(w))
|
2023-07-24 21:35:30 +08:00
|
|
|
val line_offset_mask = UIntToOH(getVWordOffset(forward.paddr))
|
2020-10-05 20:56:23 +08:00
|
|
|
|
2024-06-16 19:13:35 +08:00
|
|
|
val valid_tag_match_reg = valid_tag_matches.map(RegEnable(_, forward.valid))
|
|
|
|
val inflight_tag_match_reg = inflight_tag_matches.map(RegEnable(_, forward.valid))
|
2021-11-29 11:34:37 +08:00
|
|
|
val forward_mask_candidate_reg = RegEnable(
|
2023-07-24 21:35:30 +08:00
|
|
|
VecInit(mask.map(entry => entry(getVWordOffset(forward.paddr)))),
|
2021-11-29 11:34:37 +08:00
|
|
|
forward.valid
|
|
|
|
)
|
2021-11-15 15:55:13 +08:00
|
|
|
val forward_data_candidate_reg = RegEnable(
|
2023-07-24 21:35:30 +08:00
|
|
|
VecInit(data.map(entry => entry(getVWordOffset(forward.paddr)))),
|
2021-11-15 15:55:13 +08:00
|
|
|
forward.valid
|
|
|
|
)
|
2020-10-05 20:56:23 +08:00
|
|
|
|
2021-11-29 11:34:37 +08:00
|
|
|
val selectedValidMask = Mux1H(valid_tag_match_reg, forward_mask_candidate_reg)
|
2021-11-15 15:55:13 +08:00
|
|
|
val selectedValidData = Mux1H(valid_tag_match_reg, forward_data_candidate_reg)
|
2021-11-29 11:34:37 +08:00
|
|
|
selectedValidMask.suggestName("selectedValidMask_"+i)
|
2021-11-15 15:55:13 +08:00
|
|
|
selectedValidData.suggestName("selectedValidData_"+i)
|
2020-10-05 20:56:23 +08:00
|
|
|
|
2021-11-29 11:34:37 +08:00
|
|
|
val selectedInflightMask = Mux1H(inflight_tag_match_reg, forward_mask_candidate_reg)
|
2021-11-15 15:55:13 +08:00
|
|
|
val selectedInflightData = Mux1H(inflight_tag_match_reg, forward_data_candidate_reg)
|
2021-11-29 11:34:37 +08:00
|
|
|
selectedInflightMask.suggestName("selectedInflightMask_"+i)
|
2021-11-15 15:55:13 +08:00
|
|
|
selectedInflightData.suggestName("selectedInflightData_"+i)
|
2020-10-06 16:23:37 +08:00
|
|
|
|
2021-11-29 11:34:37 +08:00
|
|
|
// currently not being used
|
2023-07-24 21:35:30 +08:00
|
|
|
val selectedInflightMaskFast = Mux1H(line_offset_mask, Mux1H(inflight_tag_matches, mask).asTypeOf(Vec(CacheLineVWords, Vec(VDataBytes, Bool()))))
|
|
|
|
val selectedValidMaskFast = Mux1H(line_offset_mask, Mux1H(valid_tag_matches, mask).asTypeOf(Vec(CacheLineVWords, Vec(VDataBytes, Bool()))))
|
2021-08-20 01:27:12 +08:00
|
|
|
|
2021-04-30 10:40:51 +08:00
|
|
|
forward.dataInvalid := false.B // data in store line merge buffer is always ready
|
2021-08-03 14:28:43 +08:00
|
|
|
forward.matchInvalid := tag_mismatch // paddr / vaddr cam result does not match
|
2023-07-24 21:35:30 +08:00
|
|
|
for (j <- 0 until VDataBytes) {
|
2020-12-16 14:44:10 +08:00
|
|
|
forward.forwardMask(j) := false.B
|
|
|
|
forward.forwardData(j) := DontCare
|
2020-10-06 16:23:37 +08:00
|
|
|
|
2020-12-16 14:44:10 +08:00
|
|
|
// valid entries have higher priority than inflight entries
|
2021-01-02 23:56:29 +08:00
|
|
|
when(selectedInflightMask(j)) {
|
2020-12-16 14:44:10 +08:00
|
|
|
forward.forwardMask(j) := true.B
|
|
|
|
forward.forwardData(j) := selectedInflightData(j)
|
|
|
|
}
|
2021-01-02 23:56:29 +08:00
|
|
|
when(selectedValidMask(j)) {
|
2020-12-16 14:44:10 +08:00
|
|
|
forward.forwardMask(j) := true.B
|
|
|
|
forward.forwardData(j) := selectedValidData(j)
|
|
|
|
}
|
2021-08-20 01:27:12 +08:00
|
|
|
|
|
|
|
forward.forwardMaskFast(j) := selectedInflightMaskFast(j) || selectedValidMaskFast(j)
|
2020-12-16 14:44:10 +08:00
|
|
|
}
|
2023-05-21 19:56:20 +08:00
|
|
|
forward.addrInvalid := DontCare
|
2020-12-28 16:35:14 +08:00
|
|
|
}
|
2021-08-03 14:28:43 +08:00
|
|
|
|
|
|
|
for (i <- 0 until StoreBufferSize) {
|
2021-11-15 15:55:13 +08:00
|
|
|
XSDebug("sbf entry " + i + " : ptag %x vtag %x valid %x active %x inflight %x w_timeout %x\n",
|
2021-08-03 14:28:43 +08:00
|
|
|
ptag(i) << OffsetWidth,
|
|
|
|
vtag(i) << OffsetWidth,
|
2021-10-20 15:48:32 +08:00
|
|
|
stateVec(i).isValid(),
|
|
|
|
activeMask(i),
|
|
|
|
inflightMask(i),
|
|
|
|
stateVec(i).w_timeout
|
2021-08-03 14:28:43 +08:00
|
|
|
)
|
|
|
|
}
|
2024-04-03 02:27:43 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
**********************************************************
|
|
|
|
* ------------- ------------- *
|
|
|
|
* | XiangShan | | NEMU | *
|
|
|
|
* ------------- ------------- *
|
|
|
|
* | | *
|
|
|
|
* V V *
|
|
|
|
* ----- ----- *
|
|
|
|
* | Q | | Q | *
|
|
|
|
* | U | | U | *
|
|
|
|
* | E | | E | *
|
|
|
|
* | U | | U | *
|
|
|
|
* | E | | E | *
|
|
|
|
* | | | | *
|
|
|
|
* ----- ----- *
|
|
|
|
* | | *
|
|
|
|
* | -------------- | *
|
|
|
|
* |>>>>>>>>| DIFFTEST |<<<<<<<<<| *
|
|
|
|
* -------------- *
|
|
|
|
**********************************************************
|
|
|
|
*/
|
2024-05-08 10:01:05 +08:00
|
|
|
// Initialize when unenabled difftest.
|
|
|
|
for (i <- 0 until EnsbufferWidth) {
|
|
|
|
io.vecDifftestInfo(i) := DontCare
|
|
|
|
}
|
2023-12-04 15:10:42 +08:00
|
|
|
if (env.EnableDifftest) {
|
2024-04-03 02:27:43 +08:00
|
|
|
val VecMemFLOWMaxNumber = 16
|
|
|
|
|
|
|
|
def UIntSlice(in: UInt, High: UInt, Low: UInt): UInt = {
|
|
|
|
val maxNum = in.getWidth
|
|
|
|
val result = Wire(Vec(maxNum, Bool()))
|
|
|
|
|
|
|
|
for (i <- 0 until maxNum) {
|
|
|
|
when (Low + i.U <= High) {
|
|
|
|
result(i) := in(Low + i.U)
|
|
|
|
}.otherwise{
|
|
|
|
result(i) := 0.U
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result.asUInt
|
|
|
|
}
|
|
|
|
|
|
|
|
// To align with 'nemu', we need:
|
|
|
|
// For 'unit-store' and 'whole' vector store instr, we re-split here,
|
|
|
|
// and for the res, we do nothing.
|
2023-12-04 15:10:42 +08:00
|
|
|
for (i <- 0 until EnsbufferWidth) {
|
2024-04-03 02:27:43 +08:00
|
|
|
io.vecDifftestInfo(i).ready := io.in(i).ready
|
|
|
|
|
|
|
|
val uop = io.vecDifftestInfo(i).bits
|
|
|
|
|
|
|
|
val isVse = isVStore(uop.fuType) && LSUOpType.isUStride(uop.fuOpType)
|
|
|
|
val isVsm = isVStore(uop.fuType) && VstuType.isMasked(uop.fuOpType)
|
|
|
|
val isVsr = isVStore(uop.fuType) && VstuType.isWhole(uop.fuOpType)
|
|
|
|
|
|
|
|
val vpu = uop.vpu
|
|
|
|
val veew = uop.vpu.veew
|
|
|
|
val eew = EewLog2(veew)
|
|
|
|
val EEB = (1.U << eew).asUInt //Only when VLEN=128 effective element byte
|
|
|
|
val EEWBits = (EEB << 3.U).asUInt
|
|
|
|
val nf = Mux(isVsr, 0.U, vpu.nf)
|
|
|
|
|
|
|
|
val isSegment = nf =/= 0.U && !isVsm
|
|
|
|
val isVSLine = (isVse || isVsm || isVsr) && !isSegment
|
|
|
|
|
|
|
|
// The number of stores generated by a uop theroy.
|
|
|
|
// No other vector instructions need to be considered.
|
|
|
|
val flow = Mux(
|
|
|
|
isVSLine,
|
|
|
|
(16.U >> eew).asUInt,
|
|
|
|
0.U
|
|
|
|
)
|
|
|
|
|
|
|
|
val rawData = io.in(i).bits.data
|
|
|
|
val rawMask = io.in(i).bits.mask
|
|
|
|
val rawAddr = io.in(i).bits.addr
|
|
|
|
|
|
|
|
// A common difftest interface for scalar and vector instr
|
|
|
|
val difftestCommon = DifftestModule(new DiffStoreEvent, delay = 2)
|
|
|
|
when (isVSLine) {
|
|
|
|
val splitMask = UIntSlice(rawMask, EEB - 1.U, 0.U)(7,0) // Byte
|
|
|
|
val splitData = UIntSlice(rawData, EEWBits - 1.U, 0.U)(63,0) // Double word
|
|
|
|
val storeCommit = io.in(i).fire && splitMask.orR && io.in(i).bits.vecValid
|
|
|
|
val waddr = rawAddr
|
|
|
|
val wmask = splitMask
|
|
|
|
val wdata = splitData & MaskExpand(splitMask)
|
|
|
|
|
|
|
|
difftestCommon.coreid := io.hartId
|
|
|
|
difftestCommon.index := (i*VecMemFLOWMaxNumber).U
|
|
|
|
difftestCommon.valid := storeCommit
|
|
|
|
difftestCommon.addr := waddr
|
|
|
|
difftestCommon.data := wdata
|
|
|
|
difftestCommon.mask := wmask
|
|
|
|
|
|
|
|
}.otherwise{
|
|
|
|
val storeCommit = io.in(i).fire
|
|
|
|
val waddr = ZeroExt(Cat(io.in(i).bits.addr(PAddrBits - 1, 3), 0.U(3.W)), 64)
|
|
|
|
val sbufferMask = shiftMaskToLow(io.in(i).bits.addr, io.in(i).bits.mask)
|
|
|
|
val sbufferData = shiftDataToLow(io.in(i).bits.addr, io.in(i).bits.data)
|
|
|
|
val wmask = sbufferMask
|
|
|
|
val wdata = sbufferData & MaskExpand(sbufferMask)
|
|
|
|
|
|
|
|
difftestCommon.coreid := io.hartId
|
|
|
|
difftestCommon.index := (i*VecMemFLOWMaxNumber).U
|
|
|
|
difftestCommon.valid := storeCommit && io.in(i).bits.vecValid
|
|
|
|
difftestCommon.addr := waddr
|
|
|
|
difftestCommon.data := wdata
|
|
|
|
difftestCommon.mask := wmask
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only the interface used by the 'unit-store' and 'whole' vector store instr
|
|
|
|
for (index <- 1 until VecMemFLOWMaxNumber) {
|
|
|
|
val difftest = DifftestModule(new DiffStoreEvent, delay = 2)
|
|
|
|
|
|
|
|
// I've already done something process with 'mask' outside:
|
|
|
|
// Different cases of 'vm' have been considered:
|
|
|
|
// Any valid store will definitely not have all 0 masks,
|
|
|
|
// and the extra part due to unaligned access must have a mask of 0
|
|
|
|
when (index.U < flow && isVSLine) {
|
|
|
|
// Make NEMU-difftest happy
|
|
|
|
val shiftIndex = EEB*index.U
|
|
|
|
val shiftFlag = shiftIndex(2,0).orR // Double word Flag
|
|
|
|
val shiftBytes = Mux(shiftFlag, shiftIndex(2,0), 0.U)
|
|
|
|
val shiftBits = shiftBytes << 3.U
|
|
|
|
val splitMask = UIntSlice(rawMask, (EEB*(index+1).U - 1.U), EEB*index.U)(7,0) // Byte
|
|
|
|
val splitData = UIntSlice(rawData, (EEWBits*(index+1).U - 1.U), EEWBits*index.U)(63,0) // Double word
|
|
|
|
val storeCommit = io.in(i).fire && splitMask.orR && io.in(i).bits.vecValid
|
|
|
|
val waddr = Cat(rawAddr(PAddrBits - 1, 4), Cat(shiftIndex(3), 0.U(3.W)))
|
|
|
|
val wmask = splitMask << shiftBytes
|
|
|
|
val wdata = (splitData & MaskExpand(splitMask)) << shiftBits
|
|
|
|
|
|
|
|
difftest.coreid := io.hartId
|
|
|
|
difftest.index := (i*VecMemFLOWMaxNumber+index).U
|
|
|
|
difftest.valid := storeCommit
|
|
|
|
difftest.addr := waddr
|
|
|
|
difftest.data := wdata
|
|
|
|
difftest.mask := wmask
|
|
|
|
|
|
|
|
}.otherwise{
|
|
|
|
difftest.coreid := 0.U
|
|
|
|
difftest.index := 0.U
|
|
|
|
difftest.valid := 0.U
|
|
|
|
difftest.addr := 0.U
|
|
|
|
difftest.data := 0.U
|
|
|
|
difftest.mask := 0.U
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2023-12-04 15:10:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-05 18:04:28 +08:00
|
|
|
val perf_valid_entry_count = RegNext(PopCount(VecInit(stateVec.map(s => !s.isInvalid())).asUInt))
|
2021-09-01 14:33:26 +08:00
|
|
|
XSPerfHistogram("util", perf_valid_entry_count, true.B, 0, StoreBufferSize, 1)
|
|
|
|
XSPerfAccumulate("sbuffer_req_valid", PopCount(VecInit(io.in.map(_.valid)).asUInt))
|
2023-09-21 10:02:22 +08:00
|
|
|
XSPerfAccumulate("sbuffer_req_fire", PopCount(VecInit(io.in.map(_.fire)).asUInt))
|
2024-04-09 20:40:01 +08:00
|
|
|
XSPerfAccumulate("sbuffer_req_fire_vecinvalid", PopCount(VecInit(io.in.map(data => data.fire && !data.bits.vecValid)).asUInt))
|
2023-09-21 10:02:22 +08:00
|
|
|
XSPerfAccumulate("sbuffer_merge", PopCount(VecInit(io.in.zipWithIndex.map({case (in, i) => in.fire && canMerge(i)})).asUInt))
|
|
|
|
XSPerfAccumulate("sbuffer_newline", PopCount(VecInit(io.in.zipWithIndex.map({case (in, i) => in.fire && !canMerge(i)})).asUInt))
|
2021-09-01 14:33:26 +08:00
|
|
|
XSPerfAccumulate("dcache_req_valid", io.dcache.req.valid)
|
2023-09-21 10:02:22 +08:00
|
|
|
XSPerfAccumulate("dcache_req_fire", io.dcache.req.fire)
|
2021-09-01 14:33:26 +08:00
|
|
|
XSPerfAccumulate("sbuffer_idle", sbuffer_state === x_idle)
|
|
|
|
XSPerfAccumulate("sbuffer_flush", sbuffer_state === x_drain_sbuffer)
|
|
|
|
XSPerfAccumulate("sbuffer_replace", sbuffer_state === x_replace)
|
2022-11-18 14:07:57 +08:00
|
|
|
XSPerfAccumulate("evenCanInsert", evenCanInsert)
|
|
|
|
XSPerfAccumulate("oddCanInsert", oddCanInsert)
|
2023-09-21 10:02:22 +08:00
|
|
|
XSPerfAccumulate("mainpipe_resp_valid", io.dcache.main_pipe_hit_resp.fire)
|
2024-04-25 10:23:18 +08:00
|
|
|
//XSPerfAccumulate("refill_resp_valid", io.dcache.refill_hit_resp.fire)
|
2023-09-21 10:02:22 +08:00
|
|
|
XSPerfAccumulate("replay_resp_valid", io.dcache.replay_resp.fire)
|
2021-11-15 15:55:13 +08:00
|
|
|
XSPerfAccumulate("coh_timeout", cohHasTimeOut)
|
|
|
|
|
2023-09-21 10:02:22 +08:00
|
|
|
// val (store_latency_sample, store_latency) = TransactionLatencyCounter(io.lsu.req.fire, io.lsu.resp.fire)
|
2021-11-15 15:55:13 +08:00
|
|
|
// XSPerfHistogram("store_latency", store_latency, store_latency_sample, 0, 100, 10)
|
2023-09-21 10:02:22 +08:00
|
|
|
// XSPerfAccumulate("store_req", io.lsu.req.fire)
|
2021-10-23 13:38:45 +08:00
|
|
|
|
|
|
|
val perfEvents = Seq(
|
|
|
|
("sbuffer_req_valid ", PopCount(VecInit(io.in.map(_.valid)).asUInt) ),
|
2023-09-21 10:02:22 +08:00
|
|
|
("sbuffer_req_fire ", PopCount(VecInit(io.in.map(_.fire)).asUInt) ),
|
|
|
|
("sbuffer_merge ", PopCount(VecInit(io.in.zipWithIndex.map({case (in, i) => in.fire && canMerge(i)})).asUInt) ),
|
|
|
|
("sbuffer_newline ", PopCount(VecInit(io.in.zipWithIndex.map({case (in, i) => in.fire && !canMerge(i)})).asUInt) ),
|
2021-10-23 13:38:45 +08:00
|
|
|
("dcache_req_valid ", io.dcache.req.valid ),
|
2023-09-21 10:02:22 +08:00
|
|
|
("dcache_req_fire ", io.dcache.req.fire ),
|
2021-11-15 15:55:13 +08:00
|
|
|
("sbuffer_idle ", sbuffer_state === x_idle ),
|
|
|
|
("sbuffer_flush ", sbuffer_state === x_drain_sbuffer ),
|
|
|
|
("sbuffer_replace ", sbuffer_state === x_replace ),
|
2023-09-21 10:02:22 +08:00
|
|
|
("mpipe_resp_valid ", io.dcache.main_pipe_hit_resp.fire ),
|
2024-04-25 10:23:18 +08:00
|
|
|
//("refill_resp_valid ", io.dcache.refill_hit_resp.fire ),
|
2023-09-21 10:02:22 +08:00
|
|
|
("replay_resp_valid ", io.dcache.replay_resp.fire ),
|
2021-11-15 15:55:13 +08:00
|
|
|
("coh_timeout ", cohHasTimeOut ),
|
2021-12-10 09:47:25 +08:00
|
|
|
("sbuffer_1_4_valid ", (perf_valid_entry_count < (StoreBufferSize.U/4.U)) ),
|
|
|
|
("sbuffer_2_4_valid ", (perf_valid_entry_count > (StoreBufferSize.U/4.U)) & (perf_valid_entry_count <= (StoreBufferSize.U/2.U)) ),
|
|
|
|
("sbuffer_3_4_valid ", (perf_valid_entry_count > (StoreBufferSize.U/2.U)) & (perf_valid_entry_count <= (StoreBufferSize.U*3.U/4.U))),
|
2021-10-23 13:38:45 +08:00
|
|
|
("sbuffer_full_valid", (perf_valid_entry_count > (StoreBufferSize.U*3.U/4.U)))
|
|
|
|
)
|
2021-12-10 09:47:25 +08:00
|
|
|
generatePerfEvent()
|
2021-10-23 13:38:45 +08:00
|
|
|
|
2023-07-24 10:22:21 +08:00
|
|
|
}
|