Skip to content

Commit

Permalink
update endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Mengyang He committed Mar 28, 2024
1 parent 3f2a441 commit dbc6504
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 42 deletions.
40 changes: 19 additions & 21 deletions noc/networking/switching/endpoint/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ func (c *Comp) PlugIn(port sim.Port, srcBufCap int) {
}

// NotifyAvailable triggers the endpoint to continue to tick.
func (c *Comp) NotifyAvailable(now sim.VTimeInSec, _ sim.Port) {
c.TickLater(now)
func (c *Comp) NotifyAvailable(_ sim.Port) {
c.TickLater()
}

// NotifySend is called by a port to notify the connection there are
// messages waiting to be sent, can start tick
func (c *Comp) NotifySend(now sim.VTimeInSec) {
c.TickLater(now)
func (c *Comp) NotifySend() {
c.TickLater()
}

// Unplug removes the association of a port and an endpoint.
Expand All @@ -61,18 +61,18 @@ func (c *Comp) Unplug(_ sim.Port) {
}

// Tick update the endpoint state.
func (c *Comp) Tick(now sim.VTimeInSec) bool {
func (c *Comp) Tick() bool {
c.Lock()
defer c.Unlock()

madeProgress := false

madeProgress = c.sendFlitOut(now) || madeProgress
madeProgress = c.prepareMsg(now) || madeProgress
madeProgress = c.prepareFlits(now) || madeProgress
madeProgress = c.tryDeliver(now) || madeProgress
madeProgress = c.assemble(now) || madeProgress
madeProgress = c.recv(now) || madeProgress
madeProgress = c.sendFlitOut() || madeProgress
madeProgress = c.prepareMsg() || madeProgress
madeProgress = c.prepareFlits() || madeProgress
madeProgress = c.tryDeliver() || madeProgress
madeProgress = c.assemble() || madeProgress
madeProgress = c.recv() || madeProgress

return madeProgress
}
Expand All @@ -85,7 +85,7 @@ func (c *Comp) flitTaskID(flit sim.Msg) string {
return fmt.Sprintf("%s_e2e", flit.Meta().ID)
}

func (c *Comp) sendFlitOut(now sim.VTimeInSec) bool {
func (c *Comp) sendFlitOut() bool {
madeProgress := false

for i := 0; i < c.numOutputChannels; i++ {
Expand All @@ -94,7 +94,6 @@ func (c *Comp) sendFlitOut(now sim.VTimeInSec) bool {
}

flit := c.flitsToSend[0]
flit.SendTime = now
err := c.NetworkPort.Send(flit)

if err == nil {
Expand All @@ -106,7 +105,7 @@ func (c *Comp) sendFlitOut(now sim.VTimeInSec) bool {

if len(c.flitsToSend) == 0 {
for _, p := range c.DevicePorts {
p.NotifyAvailable(now)
p.NotifyAvailable()
}
}

Expand All @@ -117,7 +116,7 @@ func (c *Comp) sendFlitOut(now sim.VTimeInSec) bool {
return madeProgress
}

func (c *Comp) prepareMsg(_ sim.VTimeInSec) bool {
func (c *Comp) prepareMsg() bool {
madeProgress := false
for i := 0; i < len(c.DevicePorts); i++ {
port := c.DevicePorts[i]
Expand All @@ -137,7 +136,7 @@ func (c *Comp) prepareMsg(_ sim.VTimeInSec) bool {
return madeProgress
}

func (c *Comp) prepareFlits(_ sim.VTimeInSec) bool {
func (c *Comp) prepareFlits() bool {
madeProgress := false

for {
Expand All @@ -162,7 +161,7 @@ func (c *Comp) prepareFlits(_ sim.VTimeInSec) bool {
}
}

func (c *Comp) recv(now sim.VTimeInSec) bool {
func (c *Comp) recv() bool {
madeProgress := false

for i := 0; i < c.numInputChannels; i++ {
Expand All @@ -187,7 +186,7 @@ func (c *Comp) recv(now sim.VTimeInSec) bool {
assembling := assemblingElem.Value.(*msgToAssemble)
assembling.numFlitArrived++

c.NetworkPort.RetrieveIncoming(now)
c.NetworkPort.RetrieveIncoming()

c.logFlitE2ETask(flit, true)

Expand All @@ -200,7 +199,7 @@ func (c *Comp) recv(now sim.VTimeInSec) bool {
return madeProgress
}

func (c *Comp) assemble(_ sim.VTimeInSec) bool {
func (c *Comp) assemble() bool {
madeProgress := false

for e := c.assemblingMsgs.Front(); e != nil; e = e.Next() {
Expand All @@ -223,12 +222,11 @@ func (c *Comp) assemble(_ sim.VTimeInSec) bool {
return madeProgress
}

func (c *Comp) tryDeliver(now sim.VTimeInSec) bool {
func (c *Comp) tryDeliver() bool {
madeProgress := false

for len(c.assembledMsgs) > 0 {
msg := c.assembledMsgs[0]
msg.Meta().RecvTime = now

err := msg.Meta().Dst.Deliver(msg)
if err != nil {
Expand Down
24 changes: 11 additions & 13 deletions noc/networking/switching/endpoint/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,36 +60,34 @@ var _ = Describe("End Point", func() {
devicePort.EXPECT().RetrieveOutgoing().Return(msg)
devicePort.EXPECT().PeekOutgoing().Return(nil).AnyTimes()

madeProgress := endPoint.Tick(10)
madeProgress := endPoint.Tick()
Expect(madeProgress).To(BeTrue())

networkPort.EXPECT().Send(gomock.Any()).Do(func(flit *messaging.Flit) {
Expect(flit.SendTime).To(Equal(sim.VTimeInSec(11)))
Expect(flit.Src).To(Equal(networkPort))
Expect(flit.Dst).To(Equal(defaultSwitchPort))
Expect(flit.SeqID).To(Equal(0))
Expect(flit.NumFlitInMsg).To(Equal(2))
Expect(flit.Msg).To(BeIdenticalTo(msg))
})
devicePort.EXPECT().NotifyAvailable(gomock.Any())
devicePort.EXPECT().NotifyAvailable()

madeProgress = endPoint.Tick(11)
madeProgress = endPoint.Tick()
Expect(madeProgress).To(BeTrue())

networkPort.EXPECT().Send(gomock.Any()).Do(func(flit *messaging.Flit) {
Expect(flit.SendTime).To(Equal(sim.VTimeInSec(12)))
Expect(flit.Src).To(Equal(networkPort))
Expect(flit.Dst).To(Equal(defaultSwitchPort))
Expect(flit.SeqID).To(Equal(1))
Expect(flit.NumFlitInMsg).To(Equal(2))
Expect(flit.Msg).To(BeIdenticalTo(msg))
})

madeProgress = endPoint.Tick(12)
madeProgress = endPoint.Tick()

Expect(madeProgress).To(BeTrue())

madeProgress = endPoint.Tick(13)
madeProgress = endPoint.Tick()

Expect(madeProgress).To(BeFalse())
})
Expand All @@ -112,23 +110,23 @@ var _ = Describe("End Point", func() {
networkPort.EXPECT().PeekIncoming().Return(flit0)
networkPort.EXPECT().PeekIncoming().Return(flit1)
networkPort.EXPECT().PeekIncoming().Return(nil).Times(3)
networkPort.EXPECT().RetrieveIncoming(gomock.Any()).Times(2)
networkPort.EXPECT().RetrieveIncoming().Times(2)
devicePort.EXPECT().Deliver(msg)
devicePort.EXPECT().PeekOutgoing().Return(nil).AnyTimes()

madeProgress := endPoint.Tick(10)
madeProgress := endPoint.Tick()
Expect(madeProgress).To(BeTrue())

madeProgress = endPoint.Tick(11)
madeProgress = endPoint.Tick()
Expect(madeProgress).To(BeTrue())

madeProgress = endPoint.Tick(12)
madeProgress = endPoint.Tick()
Expect(madeProgress).To(BeTrue())

madeProgress = endPoint.Tick(13)
madeProgress = endPoint.Tick()
Expect(madeProgress).To(BeTrue())

madeProgress = endPoint.Tick(14)
madeProgress = endPoint.Tick()
Expect(madeProgress).To(BeFalse())
})
})
17 changes: 9 additions & 8 deletions noc/networking/switching/endpoint/mock_sim_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dbc6504

Please sign in to comment.