Skip to content

Commit

Permalink
feat GenerateRsp
Browse files Browse the repository at this point in the history
  • Loading branch information
Mengyang He committed Jun 11, 2024
1 parent f93d7b9 commit 50ff1ec
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 8 deletions.
28 changes: 28 additions & 0 deletions mem/cache/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ func (r *FlushReq) Clone() sim.Msg {
return &cloneMsg
}

func (r *FlushReq) GenerateRsp() sim.Rsp {
rsp := FlushRspBuilder{}.
WithSrc(r.Dst).
WithDst(r.Src).
WithRspTo(r.ID).
Build()

return rsp
}

// FlushReqBuilder can build flush requests.
type FlushReqBuilder struct {
src, dst sim.Port
Expand Down Expand Up @@ -100,6 +110,10 @@ func (r *FlushRsp) Clone() sim.Msg {
return &cloneMsg
}

func (r *FlushRsp) GetRspTo() string {
return r.RspTo
}

// FlushRspBuilder can build data ready responds.
type FlushRspBuilder struct {
src, dst sim.Port
Expand Down Expand Up @@ -153,6 +167,16 @@ func (r *RestartReq) Clone() sim.Msg {
return &cloneMsg
}

func (r *RestartReq) GenerateRsp() sim.Rsp {
rsp := RestartRspBuilder{}.
WithSrc(r.Dst).
WithDst(r.Src).
WithRspTo(r.ID).
Build()

return rsp
}

// RestartReqBuilder can build data ready responds.
type RestartReqBuilder struct {
src, dst sim.Port
Expand Down Expand Up @@ -199,6 +223,10 @@ func (r *RestartRsp) Clone() sim.Msg {
return &cloneMsg
}

func (r *RestartRsp) GetRspTo() string {
return r.RspTo
}

// RestartRspBuilder can build data ready responds.
type RestartRspBuilder struct {
src, dst sim.Port
Expand Down
34 changes: 34 additions & 0 deletions mem/mem/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ func (r *ReadReq) Clone() sim.Msg {
return &cloneMsg
}

// GenerateRsp generate DataReadyRsp to ReadReq
func (r *ReadReq) GenerateRsp(data []byte) sim.Rsp {
rsp := DataReadyRspBuilder{}.
WithSrc(r.Dst).
WithDst(r.Src).
WithRspTo(r.ID).
WithData(data).
Build()

return rsp
}

// GetByteSize returns the number of byte that the request is accessing.
func (r *ReadReq) GetByteSize() uint64 {
return r.AccessByteSize
Expand Down Expand Up @@ -154,6 +166,17 @@ func (r *WriteReq) Clone() sim.Msg {
return &cloneMsg
}

// GenerateRsp generate WriteDoneRsp to the original WriteReq
func (r *WriteReq) GenerateRsp() sim.Rsp {
rsp := WriteDoneRspBuilder{}.
WithSrc(r.Dst).
WithDst(r.Src).
WithRspTo(r.ID).
Build()

return rsp
}

// GetByteSize returns the number of byte that the request is writing.
func (r *WriteReq) GetByteSize() uint64 {
return uint64(len(r.Data))
Expand Down Expand Up @@ -472,6 +495,17 @@ func (r *GL0InvalidateReq) Clone() sim.Msg {
return &cloneMsg
}

func (r *GL0InvalidateReq) GenerateRsp(pid vm.PID) sim.Rsp {
rsp := GL0InvalidateRspBuilder{}.
WithSrc(r.Dst).
WithDst(r.Src).
WithRspTo(r.ID).
WithPID(pid).
Build()

return rsp
}

// GetByteSize returns the number of byte that the request is accessing.
func (r *GL0InvalidateReq) GetByteSize() uint64 {
return 0
Expand Down
2 changes: 1 addition & 1 deletion mem/vm/mmu/mmu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ var _ = Describe("MMU", func() {
Build()
migrating = transaction{req: req, cycleLeft: 0}
mmu.currentOnDemandMigration = migrating
migrationDone = vm.NewPageMigrationRspFromDriver(nil, nil)
migrationDone = vm.NewPageMigrationRspFromDriver(nil, nil, req)
})

It("should do nothing if no respond", func() {
Expand Down
21 changes: 21 additions & 0 deletions mem/vm/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ func (r *TranslationReq) Clone() sim.Msg {
return &cloneMsg
}

// GenerateRsp generates response to originral translation request
func (r *TranslationReq) GenerateRsp(page Page) sim.Rsp {
rsp := TranslationRspBuilder{}.WithSrc(r.Dst).WithDst(r.Src).WithRspTo(r.ID).WithPage(page).Build()

return rsp
}

// TranslationReqBuilder can build translation requests
type TranslationReqBuilder struct {
src, dst sim.Port
Expand Down Expand Up @@ -174,6 +181,12 @@ func (m *PageMigrationReqToDriver) Clone() sim.Msg {
return m
}

func (m *PageMigrationReqToDriver) GenerateRsp() sim.Rsp {
rsp := NewPageMigrationRspFromDriver(m.Dst, m.Src, m)

return rsp
}

// NewPageMigrationReqToDriver creates a PageMigrationReqToDriver.
func NewPageMigrationReqToDriver(
src, dst sim.Port,
Expand All @@ -192,6 +205,8 @@ type PageMigrationRspFromDriver struct {
EndTime sim.VTimeInSec
VAddr []uint64
RspToTop bool

OriginalReq sim.Msg
}

// Meta returns the meta data associated with the message.
Expand All @@ -204,12 +219,18 @@ func (m *PageMigrationRspFromDriver) Clone() sim.Msg {
return m
}

func (m *PageMigrationRspFromDriver) GetRspTo() string {
return m.OriginalReq.Meta().ID
}

// NewPageMigrationRspFromDriver creates a new PageMigrationRspFromDriver.
func NewPageMigrationRspFromDriver(
src, dst sim.Port,
originalReq sim.Msg,
) *PageMigrationRspFromDriver {
cmd := new(PageMigrationRspFromDriver)
cmd.Src = src
cmd.Dst = dst
cmd.OriginalReq = originalReq
return cmd
}
18 changes: 11 additions & 7 deletions sim/examples/ping/comp.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ping
import (
"fmt"
"reflect"
"strconv"

"github.com/sarchlab/akita/v4/sim"
"github.com/sarchlab/akita/v4/sim/directconnection"
Expand All @@ -22,6 +23,12 @@ func (p *PingMsg) Clone() sim.Msg {
return p
}

func (p *PingMsg) GenerateRsp() sim.Rsp {
rsp := &PingRsp{}

return rsp
}

type PingRsp struct {
sim.MsgMeta

Expand All @@ -36,6 +43,10 @@ func (p *PingRsp) Clone() sim.Msg {
return p
}

func (p *PingRsp) GetRspTo() string {
return strconv.Itoa(p.SeqID)
}

type StartPingEvent struct {
*sim.EventBase
Dst sim.Port
Expand All @@ -56,13 +67,6 @@ type Comp struct {
nextSeqID int
}

// func NewPingAgent(name string, engine sim.Engine) *PingAgent {
// agent := &PingAgent{Engine: engine}
// agent.ComponentBase = sim.NewComponentBase(name)
// agent.OutPort = sim.NewLimitNumMsgPort(agent, 4, name+".OutPort")
// return agent
// }

func (c *Comp) Handle(e sim.Event) error {
c.Lock()
defer c.Unlock()
Expand Down
11 changes: 11 additions & 0 deletions sim/examples/ticking_ping/comp.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ticking_ping

import (
"fmt"
"strconv"

"github.com/sarchlab/akita/v4/sim"
"github.com/sarchlab/akita/v4/sim/directconnection"
Expand All @@ -24,6 +25,12 @@ func (p *PingMsg) Clone() sim.Msg {
return &cloneMsg
}

func (p *PingRsp) GenerateRsp() sim.Rsp {
rsp := &PingRsp{}

return rsp
}

type PingRsp struct {
sim.MsgMeta

Expand All @@ -41,6 +48,10 @@ func (p *PingRsp) Clone() sim.Msg {
return &cloneMsg
}

func (p *PingRsp) GetRspTo() string {
return strconv.Itoa(p.SeqID)
}

type pingTransaction struct {
req *PingMsg
cycleLeft int
Expand Down
14 changes: 14 additions & 0 deletions sim/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package sim
type Msg interface {
Meta() *MsgMeta
Clone() Msg
// GenerateRsp() Rsp
}

// MsgMeta contains the meta data that is attached to every message.
Expand Down Expand Up @@ -125,6 +126,19 @@ func (c *ControlMsg) Clone() Msg {
return &cloneMsg
}

// GenerateRsp generate response to the original request
func (c *ControlMsg) GenerateRsp() Rsp {
rsp := GeneralRspBuilder{}.
WithSrc(c.Dst).
WithDst(c.Src).
WithTrafficClass(c.TrafficClass).
WithTrafficBytes(c.TrafficBytes).
WithOriginalReq(c).
Build()

return rsp
}

// ControlMsgBuilder can build control messages.
type ControlMsgBuilder struct {
Src, Dst Port
Expand Down

0 comments on commit 50ff1ec

Please sign in to comment.