Skip to content

Commit

Permalink
update writeevict
Browse files Browse the repository at this point in the history
  • Loading branch information
Mengyang He committed Mar 31, 2024
1 parent 432ba1d commit a38fbd2
Show file tree
Hide file tree
Showing 16 changed files with 179 additions and 256 deletions.
23 changes: 10 additions & 13 deletions mem/cache/writeevict/bankstage.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ func (s *bankStage) Reset() {
s.pipeline.Clear()
}

func (s *bankStage) Tick(now sim.VTimeInSec) bool {
func (s *bankStage) Tick() bool {
madeProgress := false

for i := 0; i < s.numReqPerCycle; i++ {
madeProgress = s.finalizeTrans(now) || madeProgress
madeProgress = s.finalizeTrans() || madeProgress
}

madeProgress = s.pipeline.Tick(now) || madeProgress
madeProgress = s.pipeline.Tick() || madeProgress

for i := 0; i < s.numReqPerCycle; i++ {
madeProgress = s.extractFromBuf(now) || madeProgress
madeProgress = s.extractFromBuf() || madeProgress
}

return madeProgress
}

func (s *bankStage) extractFromBuf(now sim.VTimeInSec) bool {
func (s *bankStage) extractFromBuf() bool {
item := s.cache.bankBufs[s.bankID].Peek()
if item == nil {
return false
Expand All @@ -54,14 +54,14 @@ func (s *bankStage) extractFromBuf(now sim.VTimeInSec) bool {
return false
}

s.pipeline.Accept(now, &bankTransaction{
s.pipeline.Accept(&bankTransaction{
transaction: item.(*transaction),
})
s.cache.bankBufs[s.bankID].Pop()
return true
}

func (s *bankStage) finalizeTrans(now sim.VTimeInSec) bool {
func (s *bankStage) finalizeTrans() bool {
item := s.postPipelineBuf.Peek()
if item == nil {
return false
Expand All @@ -71,18 +71,17 @@ func (s *bankStage) finalizeTrans(now sim.VTimeInSec) bool {

switch trans.bankAction {
case bankActionReadHit:
return s.finalizeReadHitTrans(now, trans)
return s.finalizeReadHitTrans(trans)
case bankActionWrite:
return s.finalizeWriteTrans(now, trans)
return s.finalizeWriteTrans(trans)
case bankActionWriteFetched:
return s.finalizeWriteFetchedTrans(now, trans)
return s.finalizeWriteFetchedTrans(trans)
default:
panic("cannot handle trans bank action")
}
}

func (s *bankStage) finalizeReadHitTrans(
now sim.VTimeInSec,
trans *transaction,
) bool {
block := trans.block
Expand All @@ -108,7 +107,6 @@ func (s *bankStage) finalizeReadHitTrans(
}

func (s *bankStage) finalizeWriteTrans(
now sim.VTimeInSec,
trans *transaction,
) bool {
write := trans.write
Expand Down Expand Up @@ -141,7 +139,6 @@ func (s *bankStage) finalizeWriteTrans(
}

func (s *bankStage) finalizeWriteFetchedTrans(
now sim.VTimeInSec,
trans *transaction,
) bool {
block := trans.block
Expand Down
27 changes: 12 additions & 15 deletions mem/cache/writeevict/bankstage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ var _ = Describe("Bankstage", func() {
})

It("should do nothing if no request", func() {
pipeline.EXPECT().Tick(sim.VTimeInSec(10)).Return(false)
pipeline.EXPECT().Tick().Return(false)
inBuf.EXPECT().Peek().Return(nil)
postPipelineBuf.EXPECT().Peek().Return(nil)

madeProgress := s.Tick(10)
madeProgress := s.Tick()

Expect(madeProgress).To(BeFalse())
})
Expand All @@ -63,16 +63,16 @@ var _ = Describe("Bankstage", func() {

inBuf.EXPECT().Peek().Return(trans)
inBuf.EXPECT().Pop()
pipeline.EXPECT().Tick(sim.VTimeInSec(10)).Return(false)
pipeline.EXPECT().Tick().Return(false)
pipeline.EXPECT().CanAccept().Return(true)
pipeline.EXPECT().
Accept(sim.VTimeInSec(10), gomock.Any()).
Do(func(now sim.VTimeInSec, t *bankTransaction) {
Accept(gomock.Any()).
Do(func(t *bankTransaction) {
Expect(t.transaction).To(BeIdenticalTo(trans))
})
postPipelineBuf.EXPECT().Peek().Return(nil)

madeProgress := s.Tick(10)
madeProgress := s.Tick()

Expect(madeProgress).To(BeTrue())
})
Expand Down Expand Up @@ -101,12 +101,10 @@ var _ = Describe("Bankstage", func() {
ReadCount: 1,
}
preCRead1 = mem.ReadReqBuilder{}.
WithSendTime(1).
WithAddress(0x104).
WithByteSize(4).
Build()
preCRead2 = mem.ReadReqBuilder{}.
WithSendTime(2).
WithAddress(0x108).
WithByteSize(8).
Build()
Expand All @@ -133,11 +131,11 @@ var _ = Describe("Bankstage", func() {
})

It("should read", func() {
pipeline.EXPECT().Tick(sim.VTimeInSec(10))
pipeline.EXPECT().Tick()
inBuf.EXPECT().Peek().Return(nil)
postPipelineBuf.EXPECT().Pop()

madeProgress := s.Tick(10)
madeProgress := s.Tick()

Expect(madeProgress).To(BeTrue())
Expect(preCTrans1.data).To(Equal([]byte{5, 6, 7, 8}))
Expand All @@ -164,7 +162,6 @@ var _ = Describe("Bankstage", func() {
}

write = mem.WriteReqBuilder{}.
WithSendTime(1).
WithAddress(0x100).
WithData([]byte{
1, 2, 3, 4, 5, 6, 7, 8,
Expand Down Expand Up @@ -199,11 +196,11 @@ var _ = Describe("Bankstage", func() {
})

It("should write", func() {
pipeline.EXPECT().Tick(sim.VTimeInSec(10))
pipeline.EXPECT().Tick()
inBuf.EXPECT().Peek().Return(nil)
postPipelineBuf.EXPECT().Pop()

madeProgress := s.Tick(10)
madeProgress := s.Tick()

Expect(madeProgress).To(BeTrue())
Expect(block.IsLocked).To(BeFalse())
Expand Down Expand Up @@ -256,11 +253,11 @@ var _ = Describe("Bankstage", func() {
})

It("should write fetched", func() {
pipeline.EXPECT().Tick(sim.VTimeInSec(10))
pipeline.EXPECT().Tick()
inBuf.EXPECT().Peek().Return(nil)
postPipelineBuf.EXPECT().Pop()

madeProgress := s.Tick(10)
madeProgress := s.Tick()

Expect(madeProgress).To(BeTrue())
// Expect(s.currTrans).To(BeNil())
Expand Down
23 changes: 9 additions & 14 deletions mem/cache/writeevict/bottomparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,26 @@ type bottomParser struct {
cache *Comp
}

func (p *bottomParser) Tick(now sim.VTimeInSec) bool {
func (p *bottomParser) Tick() bool {
item := p.cache.bottomPort.PeekIncoming()
if item == nil {
return false
}

switch rsp := item.(type) {
case *mem.WriteDoneRsp:
return p.processDoneRsp(now, rsp)
return p.processDoneRsp(rsp)
case *mem.DataReadyRsp:
return p.processDataReady(now, rsp)
return p.processDataReady(rsp)
default:
panic("cannot process response")
}
}

func (p *bottomParser) processDoneRsp(
now sim.VTimeInSec,
done *mem.WriteDoneRsp,
) bool {
func (p *bottomParser) processDoneRsp(done *mem.WriteDoneRsp) bool {
trans := p.findTransactionByWriteToBottomID(done.GetRspTo())
if trans == nil || trans.fetchAndWrite {
p.cache.bottomPort.RetrieveIncoming(now)
p.cache.bottomPort.RetrieveIncoming()
return true
}

Expand All @@ -42,7 +39,7 @@ func (p *bottomParser) processDoneRsp(
}

p.removeTransaction(trans)
p.cache.bottomPort.RetrieveIncoming(now)
p.cache.bottomPort.RetrieveIncoming()

tracing.TraceReqFinalize(trans.writeToBottom, p.cache)
tracing.EndTask(trans.id, p.cache)
Expand All @@ -51,12 +48,11 @@ func (p *bottomParser) processDoneRsp(
}

func (p *bottomParser) processDataReady(
now sim.VTimeInSec,
dr *mem.DataReadyRsp,
) bool {
trans := p.findTransactionByReadToBottomID(dr.GetRspTo())
if trans == nil {
p.cache.bottomPort.RetrieveIncoming(now)
p.cache.bottomPort.RetrieveIncoming()
return true
}
pid := trans.readToBottom.PID
Expand All @@ -71,15 +67,15 @@ func (p *bottomParser) processDataReady(
dirtyMask := make([]bool, 1<<p.cache.log2BlockSize)
mshrEntry := p.cache.mshr.Query(pid, cachelineID)
p.mergeMSHRData(mshrEntry, data, dirtyMask)
p.finalizeMSHRTrans(mshrEntry, data, now)
p.finalizeMSHRTrans(mshrEntry, data)
p.cache.mshr.Remove(pid, cachelineID)

trans.bankAction = bankActionWriteFetched
trans.data = data
trans.writeFetchedDirtyMask = dirtyMask
bankBuf.Push(trans)
p.removeTransaction(trans)
p.cache.bottomPort.RetrieveIncoming(now)
p.cache.bottomPort.RetrieveIncoming()

tracing.TraceReqFinalize(trans.readToBottom, p.cache)

Expand Down Expand Up @@ -112,7 +108,6 @@ func (p *bottomParser) mergeMSHRData(
func (p *bottomParser) finalizeMSHRTrans(
mshrEntry *cache.MSHREntry,
data []byte,
now sim.VTimeInSec,
) {
for _, t := range mshrEntry.Requests {
trans := t.(*transaction)
Expand Down
Loading

0 comments on commit a38fbd2

Please sign in to comment.