From 38e693b5d5eec7cc37aeffeaf69ab8fd7c25a2cc Mon Sep 17 00:00:00 2001 From: DX990307 <101349164+DX990307@users.noreply.github.com> Date: Mon, 25 Nov 2024 16:29:05 -0500 Subject: [PATCH] update --- akita.code-workspace | 7 +++ mem/mem/protocol.go | 27 +++++++++++ mem/vm/tlb/builder.go | 7 ++- mem/vm/tlb/ctrlMiddleware.go | 48 +++++++++++++++++++ mem/vm/tlb/ctrlMiddleware_test.go | 64 +++++++++++++++++++++++++ mem/vm/tlb/{tlb.go => tlbMiddleware.go} | 31 ++++++------ mem/vm/tlb/tlb_test.go | 44 ++++++++--------- 7 files changed, 190 insertions(+), 38 deletions(-) create mode 100644 akita.code-workspace create mode 100644 mem/vm/tlb/ctrlMiddleware.go create mode 100644 mem/vm/tlb/ctrlMiddleware_test.go rename mem/vm/tlb/{tlb.go => tlbMiddleware.go} (88%) diff --git a/akita.code-workspace b/akita.code-workspace new file mode 100644 index 00000000..ef9f5d27 --- /dev/null +++ b/akita.code-workspace @@ -0,0 +1,7 @@ +{ + "folders": [ + { + "path": "." + } + ] +} \ No newline at end of file diff --git a/mem/mem/protocol.go b/mem/mem/protocol.go index 6aea00f9..e4045428 100644 --- a/mem/mem/protocol.go +++ b/mem/mem/protocol.go @@ -407,6 +407,11 @@ type ControlMsg struct { DiscardTransations bool Restart bool NotifyDone bool + Enable bool + Drain bool + Flush bool + Pause bool + Invalid bool } // Meta returns the meta data assocated with the ControlMsg. @@ -428,6 +433,11 @@ type ControlMsgBuilder struct { discardTransactions bool restart bool notifyDone bool + Enable bool + Drain bool + Flush bool + Pause bool + Invalid bool } // WithSrc sets the source of the request to build. @@ -461,6 +471,18 @@ func (b ControlMsgBuilder) ToNotifyDone() ControlMsgBuilder { return b } +// WithEnable sets the enable bit of the control messages to 1. +func (b ControlMsgBuilder) WithCtrlInfo( + enable bool, drain bool, flush bool, pause bool, invalid bool, +) ControlMsgBuilder { + b.Enable = enable + b.Drain = drain + b.Flush = flush + b.Pause = pause + b.Invalid = invalid + return b +} + // Build creates a new ControlMsg. func (b ControlMsgBuilder) Build() *ControlMsg { m := &ControlMsg{} @@ -472,6 +494,11 @@ func (b ControlMsgBuilder) Build() *ControlMsg { m.DiscardTransations = b.discardTransactions m.Restart = b.restart m.NotifyDone = b.notifyDone + m.Enable = b.Enable + m.Drain = b.Drain + m.Flush = b.Flush + m.Pause = b.Pause + m.Invalid = b.Invalid return m } diff --git a/mem/vm/tlb/builder.go b/mem/vm/tlb/builder.go index 8c3f80a6..8d3d2810 100644 --- a/mem/vm/tlb/builder.go +++ b/mem/vm/tlb/builder.go @@ -12,6 +12,7 @@ type Builder struct { pageSize uint64 lowModule sim.Port numMSHREntry int + state string } // MakeBuilder returns a Builder @@ -23,6 +24,7 @@ func MakeBuilder() Builder { numWays: 32, pageSize: 4096, numMSHREntry: 4, + state: "enable", } } @@ -95,7 +97,10 @@ func (b Builder) Build(name string) *Comp { tlb.reset() - middleware := &middleware{Comp: tlb} + ctrlMiddleware := &ctrlMiddleware{Comp: tlb} + tlb.AddMiddleware(ctrlMiddleware) + + middleware := &tlbMiddleware{Comp: tlb} tlb.AddMiddleware(middleware) return tlb diff --git a/mem/vm/tlb/ctrlMiddleware.go b/mem/vm/tlb/ctrlMiddleware.go new file mode 100644 index 00000000..0f7aba48 --- /dev/null +++ b/mem/vm/tlb/ctrlMiddleware.go @@ -0,0 +1,48 @@ +package tlb + +import "github.com/sarchlab/akita/v4/mem/mem" + +type ctrlMiddleware struct { + *Comp +} + +func (m *ctrlMiddleware) Tick() bool { + madeProgress := false + madeProgress = m.handleIncomingCommands() || madeProgress + // madeProgress = m.handleStatusUpdate() || madeProgress + return madeProgress +} + +func (m *ctrlMiddleware) handleIncomingCommands() bool { + madeProgress := false + msg := m.controlPort.PeekIncoming() + + if msg == nil { + return false + } + + switch msg := msg.(type) { + case *mem.ControlMsg: + madeProgress = m.handleControlMsg(msg) || madeProgress + default: + panic("Unhandled message") + } + + return madeProgress +} + +func (m *ctrlMiddleware) handleControlMsg( + msg *mem.ControlMsg) (madeProgress bool) { + m.ctrlMsgMustBeValid(msg) + return madeProgress +} + +func (m *ctrlMiddleware) ctrlMsgMustBeValid(msg *mem.ControlMsg) { + if msg.Enable { + + } +} + +// func (m *ctrlMiddleware) handleStatusUpdate() bool { + +// } diff --git a/mem/vm/tlb/ctrlMiddleware_test.go b/mem/vm/tlb/ctrlMiddleware_test.go new file mode 100644 index 00000000..1be67881 --- /dev/null +++ b/mem/vm/tlb/ctrlMiddleware_test.go @@ -0,0 +1,64 @@ +package tlb + +import ( + "github.com/golang/mock/gomock" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + "github.com/sarchlab/akita/v4/mem/vm/tlb/internal" +) + +var _ = FDescribe("TLB", func() { + + var ( + mockCtrl *gomock.Controller + engine *MockEngine + comp *Comp + tlbMW *tlbMiddleware + ctrlMW *ctrlMiddleware + set *MockSet + topPort *MockPort + bottomPort *MockPort + controlPort *MockPort + ) + + BeforeEach(func() { + mockCtrl = gomock.NewController(GinkgoT()) + engine = NewMockEngine(mockCtrl) + set = NewMockSet(mockCtrl) + topPort = NewMockPort(mockCtrl) + bottomPort = NewMockPort(mockCtrl) + controlPort = NewMockPort(mockCtrl) + + comp = MakeBuilder().WithEngine(engine).Build("TLB") + comp.topPort = topPort + comp.bottomPort = bottomPort + comp.controlPort = controlPort + comp.Sets = []internal.Set{set} + + ctrlMW = comp.Middlewares()[0].(*ctrlMiddleware) + tlbMW = comp.Middlewares()[1].(*tlbMiddleware) + }) + + AfterEach(func() { + mockCtrl.Finish() + }) + + It("should do nothing if there is no req in TopPort", func() { + topPort.EXPECT().PeekIncoming().Return(nil) + + madeProgress := tlbMW.lookup() + + Expect(madeProgress).To(BeFalse()) + }) + + It("should do nothing if there is no req in ctrlPort", func() { + topPort.EXPECT().PeekIncoming().Return(nil) + controlPort.EXPECT().PeekIncoming().Return(nil) + + madeProgress := tlbMW.lookup() + madeProgress = ctrlMW.Tick() || madeProgress + + Expect(madeProgress).To(BeFalse()) + }) + +}) diff --git a/mem/vm/tlb/tlb.go b/mem/vm/tlb/tlbMiddleware.go similarity index 88% rename from mem/vm/tlb/tlb.go rename to mem/vm/tlb/tlbMiddleware.go index 42d5bbaa..ca6bb372 100644 --- a/mem/vm/tlb/tlb.go +++ b/mem/vm/tlb/tlbMiddleware.go @@ -25,6 +25,7 @@ type Comp struct { numWays int pageSize uint64 numReqPerCycle int + state string Sets []internal.Set @@ -47,12 +48,12 @@ func (c *Comp) Tick() bool { return c.MiddlewareHolder.Tick() } -type middleware struct { +type tlbMiddleware struct { *Comp } // Tick defines how TLB update states at each cycle -func (m *middleware) Tick() bool { +func (m *tlbMiddleware) Tick() bool { madeProgress := false madeProgress = m.performCtrlReq() || madeProgress @@ -74,7 +75,7 @@ func (m *middleware) Tick() bool { return madeProgress } -func (m *middleware) respondMSHREntry() bool { +func (m *tlbMiddleware) respondMSHREntry() bool { if m.respondingMSHREntry == nil { return false } @@ -102,7 +103,7 @@ func (m *middleware) respondMSHREntry() bool { return true } -func (m *middleware) lookup() bool { +func (m *tlbMiddleware) lookup() bool { msg := m.topPort.PeekIncoming() if msg == nil { return false @@ -125,7 +126,7 @@ func (m *middleware) lookup() bool { return m.handleTranslationMiss(req) } -func (m *middleware) handleTranslationHit( +func (m *tlbMiddleware) handleTranslationHit( req *vm.TranslationReq, setID, wayID int, page vm.Page, @@ -145,7 +146,7 @@ func (m *middleware) handleTranslationHit( return true } -func (m *middleware) handleTranslationMiss( +func (m *tlbMiddleware) handleTranslationMiss( req *vm.TranslationReq, ) bool { if m.mshr.IsFull() { @@ -163,11 +164,11 @@ func (m *middleware) handleTranslationMiss( return false } -func (m *middleware) vAddrToSetID(vAddr uint64) (setID int) { +func (m *tlbMiddleware) vAddrToSetID(vAddr uint64) (setID int) { return int(vAddr / m.pageSize % uint64(m.numSets)) } -func (m *middleware) sendRspToTop( +func (m *tlbMiddleware) sendRspToTop( req *vm.TranslationReq, page vm.Page, ) bool { @@ -183,7 +184,7 @@ func (m *middleware) sendRspToTop( return err == nil } -func (m *middleware) processTLBMSHRHit( +func (m *tlbMiddleware) processTLBMSHRHit( mshrEntry *mshrEntry, req *vm.TranslationReq, ) bool { @@ -196,7 +197,7 @@ func (m *middleware) processTLBMSHRHit( return true } -func (m *middleware) fetchBottom(req *vm.TranslationReq) bool { +func (m *tlbMiddleware) fetchBottom(req *vm.TranslationReq) bool { fetchBottom := vm.TranslationReqBuilder{}. WithSrc(m.bottomPort). WithDst(m.LowModule). @@ -219,7 +220,7 @@ func (m *middleware) fetchBottom(req *vm.TranslationReq) bool { return true } -func (m *middleware) parseBottom() bool { +func (m *tlbMiddleware) parseBottom() bool { if m.respondingMSHREntry != nil { return false } @@ -258,7 +259,7 @@ func (m *middleware) parseBottom() bool { return true } -func (m *middleware) performCtrlReq() bool { +func (m *tlbMiddleware) performCtrlReq() bool { item := m.controlPort.PeekIncoming() if item == nil { return false @@ -278,12 +279,12 @@ func (m *middleware) performCtrlReq() bool { return true } -func (m *middleware) visit(setID, wayID int) { +func (m *tlbMiddleware) visit(setID, wayID int) { set := m.Sets[setID] set.Visit(wayID) } -func (m *middleware) handleTLBFlush(req *FlushReq) bool { +func (m *tlbMiddleware) handleTLBFlush(req *FlushReq) bool { rsp := FlushRspBuilder{}. WithSrc(m.controlPort). WithDst(req.Src). @@ -311,7 +312,7 @@ func (m *middleware) handleTLBFlush(req *FlushReq) bool { return true } -func (m *middleware) handleTLBRestart(req *RestartReq) bool { +func (m *tlbMiddleware) handleTLBRestart(req *RestartReq) bool { rsp := RestartRspBuilder{}. WithSrc(m.controlPort). WithDst(req.Src). diff --git a/mem/vm/tlb/tlb_test.go b/mem/vm/tlb/tlb_test.go index 58af7ff5..22f60191 100644 --- a/mem/vm/tlb/tlb_test.go +++ b/mem/vm/tlb/tlb_test.go @@ -13,14 +13,14 @@ import ( var _ = Describe("TLB", func() { var ( - mockCtrl *gomock.Controller - engine *MockEngine - tlb *Comp - tlbMiddleware *middleware - set *MockSet - topPort *MockPort - bottomPort *MockPort - controlPort *MockPort + mockCtrl *gomock.Controller + engine *MockEngine + tlb *Comp + tlbMW *tlbMiddleware + set *MockSet + topPort *MockPort + bottomPort *MockPort + controlPort *MockPort ) BeforeEach(func() { @@ -37,7 +37,7 @@ var _ = Describe("TLB", func() { tlb.controlPort = controlPort tlb.Sets = []internal.Set{set} - tlbMiddleware = tlb.Middlewares()[0].(*middleware) + tlbMW = tlb.Middlewares()[0].(*tlbMiddleware) }) AfterEach(func() { @@ -47,7 +47,7 @@ var _ = Describe("TLB", func() { It("should do nothing if there is no req in TopPort", func() { topPort.EXPECT().PeekIncoming().Return(nil) - madeProgress := tlbMiddleware.lookup() + madeProgress := tlbMW.lookup() Expect(madeProgress).To(BeFalse()) }) @@ -84,7 +84,7 @@ var _ = Describe("TLB", func() { set.EXPECT().Visit(wayID) - madeProgress := tlbMiddleware.lookup() + madeProgress := tlbMW.lookup() Expect(madeProgress).To(BeTrue()) }) @@ -94,7 +94,7 @@ var _ = Describe("TLB", func() { topPort.EXPECT().Send(gomock.Any()). Return(&sim.SendError{}) - madeProgress := tlbMiddleware.lookup() + madeProgress := tlbMW.lookup() Expect(madeProgress).To(BeFalse()) }) @@ -138,7 +138,7 @@ var _ = Describe("TLB", func() { }). Return(nil) - madeProgress := tlbMiddleware.lookup() + madeProgress := tlbMW.lookup() Expect(madeProgress).To(BeTrue()) Expect(tlb.mshr.IsEntryPresent(vm.PID(1), uint64(0x100))).To(Equal(true)) @@ -149,7 +149,7 @@ var _ = Describe("TLB", func() { topPort.EXPECT().PeekIncoming().Return(req) topPort.EXPECT().RetrieveIncoming() - madeProgress := tlbMiddleware.lookup() + madeProgress := tlbMW.lookup() Expect(tlb.mshr.IsEntryPresent(vm.PID(1), uint64(0x100))). To(Equal(true)) Expect(madeProgress).To(BeTrue()) @@ -160,7 +160,7 @@ var _ = Describe("TLB", func() { bottomPort.EXPECT().Send(gomock.Any()). Return(&sim.SendError{}) - madeProgress := tlbMiddleware.lookup() + madeProgress := tlbMW.lookup() Expect(madeProgress).To(BeFalse()) }) @@ -202,7 +202,7 @@ var _ = Describe("TLB", func() { It("should do nothing if no return", func() { bottomPort.EXPECT().PeekIncoming().Return(nil) - madeProgress := tlbMiddleware.parseBottom() + madeProgress := tlbMW.parseBottom() Expect(madeProgress).To(BeFalse()) }) @@ -212,7 +212,7 @@ var _ = Describe("TLB", func() { mshrEntry.Requests = append(mshrEntry.Requests, req) tlb.respondingMSHREntry = mshrEntry - madeProgress := tlbMiddleware.parseBottom() + madeProgress := tlbMW.parseBottom() Expect(madeProgress).To(BeFalse()) }) @@ -234,7 +234,7 @@ var _ = Describe("TLB", func() { // Expect(rsp.RespondTo).To(Equal(req.ID)) // }) - madeProgress := tlbMiddleware.parseBottom() + madeProgress := tlbMW.parseBottom() Expect(madeProgress).To(BeTrue()) Expect(tlb.respondingMSHREntry).NotTo(BeNil()) @@ -249,7 +249,7 @@ var _ = Describe("TLB", func() { topPort.EXPECT().Send(gomock.Any()).Return(nil) - madeProgress := tlbMiddleware.respondMSHREntry() + madeProgress := tlbMW.respondMSHREntry() Expect(madeProgress).To(BeTrue()) Expect(mshrEntry.Requests).To(HaveLen(0)) @@ -274,7 +274,7 @@ var _ = Describe("TLB", func() { It("should do nothing if no req", func() { controlPort.EXPECT().PeekIncoming().Return(nil) - madeProgress := tlbMiddleware.performCtrlReq() + madeProgress := tlbMW.performCtrlReq() Expect(madeProgress).To(BeFalse()) }) @@ -303,7 +303,7 @@ var _ = Describe("TLB", func() { controlPort.EXPECT().RetrieveIncoming().Return(flushReq) controlPort.EXPECT().Send(gomock.Any()) - madeProgress := tlbMiddleware.performCtrlReq() + madeProgress := tlbMW.performCtrlReq() Expect(madeProgress).To(BeTrue()) Expect(tlb.isPaused).To(BeTrue()) @@ -322,7 +322,7 @@ var _ = Describe("TLB", func() { topPort.EXPECT().RetrieveIncoming().Return(nil) bottomPort.EXPECT().RetrieveIncoming().Return(nil) - madeProgress := tlbMiddleware.performCtrlReq() + madeProgress := tlbMW.performCtrlReq() Expect(madeProgress).To(BeTrue()) Expect(tlb.isPaused).To(BeFalse())