Skip to content
Snippets Groups Projects
Commit 27b9e533 authored by Yifan Sun's avatar Yifan Sun
Browse files

Bug fix

parent 0d9a306c
No related branches found
No related tags found
Loading
Pipeline #59010504 failed
......@@ -86,16 +86,16 @@ func main() {
t1.setMaxAddr(64)
wg.Add(1)
// t2 := newTest("Max_1024")
// t2.setMaxAddr(1024)
// wg.Add(1)
t2 := newTest("Max_1024")
t2.setMaxAddr(1024)
wg.Add(1)
// t3 := newTest("Max_1M")
// t3.setMaxAddr(1048576)
// wg.Add(1)
t3 := newTest("Max_1M")
t3.setMaxAddr(1048576)
wg.Add(1)
go t1.run(&wg)
// go t2.run(&wg)
// go t3.run(&wg)
go t2.run(&wg)
go t3.run(&wg)
wg.Wait()
}
......@@ -10,6 +10,7 @@ type bankStage struct {
inBuf util.Buffer
storage *mem.Storage
latency int
log2BlockSize uint64
cycleLeft int
currTrans *transaction
......@@ -75,13 +76,24 @@ func (s *bankStage) finalizeReadHitTrans(now akita.VTimeInSec) bool {
func (s *bankStage) finalizeWriteTrans(now akita.VTimeInSec) bool {
trans := s.currTrans
write := trans.write
block := trans.block
blockSize := 1 << s.log2BlockSize
err := s.storage.Write(block.CacheAddress, trans.write.Data)
data, err := s.storage.Read(block.CacheAddress, uint64(blockSize))
offset := write.Address - block.Tag
for i := 0; i < len(write.Data); i++ {
if write.DirtyMask[i] {
data[offset+uint64(i)] = write.Data[i]
}
}
err = s.storage.Write(block.CacheAddress, data)
if err != nil {
panic(err)
}
block.DirtyMask = trans.write.DirtyMask
block.DirtyMask = write.DirtyMask
block.IsLocked = false
s.currTrans = nil
......
......@@ -24,6 +24,7 @@ var _ = Describe("Bankstage", func() {
inBuf: inBuf,
storage: storage,
latency: 10,
log2BlockSize: 6,
}
})
......@@ -140,6 +141,16 @@ var _ = Describe("Bankstage", func() {
1, 2, 3, 4, 5, 6, 7, 8,
1, 2, 3, 4, 5, 6, 7, 8,
}
write.DirtyMask = []bool{
false, false, false, false, false, false, false, false,
true, true, true, true, true, true, true, true,
false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false,
}
trans = &transaction{
write: write,
block: block,
......@@ -157,7 +168,16 @@ var _ = Describe("Bankstage", func() {
Expect(s.currTrans).To(BeNil())
Expect(block.IsLocked).To(BeFalse())
data, _ := storage.Read(0x400, 64)
Expect(data).To(Equal(write.Data))
Expect(data).To(Equal([]byte{
0, 0, 0, 0, 0, 0, 0, 0,
1, 2, 3, 4, 5, 6, 7, 8,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
}))
})
})
......
......@@ -141,6 +141,7 @@ func (b *Builder) Build(name string) *Cache {
inBuf: c.bankBufs[i],
storage: storage,
latency: b.bankLatency,
log2BlockSize: b.log2BlockSize,
}
c.bankStages = append(c.bankStages, bs)
}
......
......@@ -180,14 +180,28 @@ func (d *directory) partialWriteMiss(
blockSize := uint64(1 << d.log2BlockSize)
cacheLineID := addr / blockSize * blockSize
sentThisCycle := false
if trans.writeToBottom == nil {
ok := d.writeBottom(now, trans)
if !ok {
return false
}
sentThisCycle = true
}
if d.mshr.IsFull() {
if sentThisCycle {
return true
}
return false
}
victim := d.dir.FindVictim(cacheLineID)
ok = d.fetchFromBottom(now, trans, victim)
ok := d.fetchFromBottom(now, trans, victim)
if !ok {
if sentThisCycle {
return true
}
return false
}
trans.fetchAndWrite = true
......
......@@ -379,10 +379,63 @@ var _ = Describe("Directory", func() {
mshrEntry = &cache.MSHREntry{}
})
It("should stall if mshr is full", func() {
inBuf.EXPECT().Peek().Return(trans)
mshr.EXPECT().Query(ca.PID(1), uint64(0x100)).Return(nil)
mshr.EXPECT().IsFull().Return(true)
dir.EXPECT().Lookup(ca.PID(1), uint64(0x100)).Return(nil)
lowModuleFinder.EXPECT().Find(uint64(0x104))
bottomPort.EXPECT().Send(gomock.Any()).
Do(func(write *mem.WriteReq) {
Expect(write.Address).To(Equal(uint64(0x104)))
Expect(write.Data).To(HaveLen(4))
Expect(write.PID).To(Equal(ca.PID(1)))
})
madeProgress := d.Tick(10)
Expect(madeProgress).To(BeTrue())
Expect(trans.writeToBottom).NotTo(BeNil())
})
It("should not write again if write already happened", func() {
trans.writeToBottom = mem.NewWriteReq(0, nil, nil, 0)
inBuf.EXPECT().Peek().Return(trans)
inBuf.EXPECT().Pop()
mshr.EXPECT().Query(ca.PID(1), uint64(0x100)).Return(nil)
mshr.EXPECT().IsFull().Return(false)
mshr.EXPECT().Add(ca.PID(1), uint64(0x100)).Return(mshrEntry)
dir.EXPECT().Lookup(ca.PID(1), uint64(0x100)).Return(nil)
dir.EXPECT().FindVictim(uint64(0x100)).Return(block)
dir.EXPECT().Visit(block)
lowModuleFinder.EXPECT().Find(uint64(0x100))
bottomPort.EXPECT().Send(gomock.Any()).
Do(func(read *mem.ReadReq) {
Expect(read.Address).To(Equal(uint64(0x100)))
Expect(read.MemByteSize).To(Equal(uint64(64)))
Expect(read.PID).To(Equal(ca.PID(1)))
})
madeProgress := d.Tick(10)
Expect(madeProgress).To(BeTrue())
Expect(trans.writeToBottom).NotTo(BeNil())
Expect(trans.readToBottom).NotTo(BeNil())
Expect(trans.fetchAndWrite).To(BeTrue())
Expect(mshrEntry.Requests).To(ContainElement(trans))
Expect(mshrEntry.Block).To(BeIdenticalTo(block))
Expect(block.Tag).To(Equal(uint64(0x100)))
Expect(block.PID).To(Equal(ca.PID(1)))
Expect(block.IsLocked).To(BeTrue())
Expect(block.IsValid).To(BeTrue())
})
It("should write partial block", func() {
inBuf.EXPECT().Peek().Return(trans)
inBuf.EXPECT().Pop()
mshr.EXPECT().Query(ca.PID(1), uint64(0x100)).Return(nil)
mshr.EXPECT().IsFull().Return(false)
mshr.EXPECT().Add(ca.PID(1), uint64(0x100)).Return(mshrEntry)
dir.EXPECT().Lookup(ca.PID(1), uint64(0x100)).Return(nil)
dir.EXPECT().FindVictim(uint64(0x100)).Return(block)
......
......@@ -39,6 +39,9 @@ func (s *respondStage) respondReadTrans(
}
*s.transactions = (*s.transactions)[1:]
trace(now, "r-done", read.Address, dr.Data)
return true
}
......@@ -58,5 +61,7 @@ func (s *respondStage) respondWriteTrans(
}
*s.transactions = (*s.transactions)[1:]
trace(now, "w-done", write.Address, write.Data)
return true
}
package l1v
import (
"fmt"
"gitlab.com/akita/akita"
)
func trace(now akita.VTimeInSec, what string, addr uint64, data []byte) {
s := ""
s += fmt.Sprintf("%.15f, %s, 0x%x", now, what, addr)
if data != nil {
s += ", ["
for _, b := range data {
s += fmt.Sprintf("%02x, ", b)
}
s += "]"
}
s += "\n"
fmt.Print(s)
// s := ""
// s += fmt.Sprintf("%.15f, %s, 0x%x", now, what, addr)
// if data != nil {
// s += ", ["
// for _, b := range data {
// s += fmt.Sprintf("%02x, ", b)
// }
// s += "]"
// }
// s += "\n"
// fmt.Print(s)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment