Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
DX990307 committed Nov 25, 2024
1 parent fcdfc76 commit 38e693b
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 38 deletions.
7 changes: 7 additions & 0 deletions akita.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"folders": [
{
"path": "."
}
]
}
27 changes: 27 additions & 0 deletions mem/mem/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -461,6 +471,18 @@ func (b ControlMsgBuilder) ToNotifyDone() ControlMsgBuilder {
return b
}

// WithEnable sets the enable bit of the control messages to 1.

Check failure on line 474 in mem/mem/protocol.go

View workflow job for this annotation

GitHub Actions / Akita Compilation

ST1020: comment on exported method WithCtrlInfo should be of the form "WithCtrlInfo ..." (stylecheck)
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{}
Expand All @@ -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
}
Expand Down
7 changes: 6 additions & 1 deletion mem/vm/tlb/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Builder struct {
pageSize uint64
lowModule sim.Port
numMSHREntry int
state string
}

// MakeBuilder returns a Builder
Expand All @@ -23,6 +24,7 @@ func MakeBuilder() Builder {
numWays: 32,
pageSize: 4096,
numMSHREntry: 4,
state: "enable",
}
}

Expand Down Expand Up @@ -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
Expand Down
48 changes: 48 additions & 0 deletions mem/vm/tlb/ctrlMiddleware.go
Original file line number Diff line number Diff line change
@@ -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 {

// }
64 changes: 64 additions & 0 deletions mem/vm/tlb/ctrlMiddleware_test.go
Original file line number Diff line number Diff line change
@@ -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())
})

})
31 changes: 16 additions & 15 deletions mem/vm/tlb/tlb.go → mem/vm/tlb/tlbMiddleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Comp struct {
numWays int
pageSize uint64
numReqPerCycle int
state string

Check failure on line 28 in mem/vm/tlb/tlbMiddleware.go

View workflow job for this annotation

GitHub Actions / Akita Compilation

field `state` is unused (unused)

Sets []internal.Set

Expand All @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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() {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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).
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -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).
Expand Down Expand Up @@ -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).
Expand Down
Loading

0 comments on commit 38e693b

Please sign in to comment.