Fold the shutdown flags into one, take the smallest frame to the wire minimum, drop the speed column
This commit is contained in:
@@ -437,7 +437,7 @@ func buildDirection(label string, tx, rx endpoint) (*direction, error) {
|
||||
return d, nil
|
||||
}
|
||||
|
||||
func (d *direction) start(wg *sync.WaitGroup, doneTx, doneRx *atomic.Bool, rxReady *sync.WaitGroup, startTx <-chan struct{}) {
|
||||
func (d *direction) start(wg *sync.WaitGroup, done *atomic.Bool, rxReady *sync.WaitGroup, startTx <-chan struct{}) {
|
||||
for i, fd := range d.txFDs {
|
||||
w := &txWorker{
|
||||
fd: fd,
|
||||
@@ -450,7 +450,7 @@ func (d *direction) start(wg *sync.WaitGroup, doneTx, doneRx *atomic.Bool, rxRea
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
w.run(doneTx)
|
||||
w.run(done)
|
||||
}()
|
||||
}
|
||||
for i, fd := range d.rxFDs {
|
||||
@@ -466,7 +466,7 @@ func (d *direction) start(wg *sync.WaitGroup, doneTx, doneRx *atomic.Bool, rxRea
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
w.run(doneRx)
|
||||
w.run(done)
|
||||
}()
|
||||
}
|
||||
|
||||
@@ -474,20 +474,20 @@ func (d *direction) start(wg *sync.WaitGroup, doneTx, doneRx *atomic.Bool, rxRea
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
sender.run(doneTx, startTx)
|
||||
sender.run(done, startTx)
|
||||
}()
|
||||
|
||||
receiver := &probeReceiver{fd: d.probeRxFD, stats: d.cable, ready: rxReady}
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
receiver.run(doneRx)
|
||||
receiver.run(done)
|
||||
}()
|
||||
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
d.poller.run(doneRx, startTx)
|
||||
d.poller.run(done, startTx)
|
||||
}()
|
||||
}
|
||||
|
||||
@@ -514,7 +514,9 @@ const (
|
||||
linkSpeed = 10.0
|
||||
)
|
||||
|
||||
var frameSizes = []int{64, 128, 256, 512, 1024, 1280, 1514}
|
||||
// The mac appends the fcs, so 60 and 1514 here are the smallest and largest
|
||||
// standard frames, 64 and 1518 on the wire.
|
||||
var frameSizes = []int{60, 128, 256, 512, 1024, 1280, 1514}
|
||||
|
||||
func main() {
|
||||
// The names the kernel gives the only two ports built into it, since as
|
||||
@@ -611,19 +613,18 @@ func run(aName, bName string, nsPerM float64) error {
|
||||
var linkRows [][]string
|
||||
for _, e := range []endpoint{a, b} {
|
||||
linkRows = append(linkRows, []string{
|
||||
paint(e.tag, cCyan), e.name, e.macString(),
|
||||
fmt.Sprintf("%.0f Gb/s", linkSpeed), fmt.Sprintf("%d", e.mtu),
|
||||
paint(e.tag, cCyan), e.name, e.macString(), fmt.Sprintf("%d", e.mtu),
|
||||
})
|
||||
}
|
||||
fmt.Println(renderBox("LINKS",
|
||||
[]string{"TAG", "INTERFACE", "MAC", "SPEED", "MTU"},
|
||||
[]bool{false, false, false, true, true}, linkRows))
|
||||
[]string{"TAG", "INTERFACE", "MAC", "MTU"},
|
||||
[]bool{false, false, false, true}, linkRows))
|
||||
fmt.Println()
|
||||
|
||||
// One row carries both directions, so line rate is both links at once.
|
||||
target := linkSpeed * float64(len(dirs))
|
||||
|
||||
var doneTx, doneRx atomic.Bool
|
||||
var done atomic.Bool
|
||||
var wg sync.WaitGroup
|
||||
var rxReady sync.WaitGroup
|
||||
startTx := make(chan struct{})
|
||||
@@ -631,13 +632,13 @@ func run(aName, bName string, nsPerM float64) error {
|
||||
rxReady.Add(len(d.rxFDs) + 1)
|
||||
}
|
||||
for _, d := range dirs {
|
||||
d.start(&wg, &doneTx, &doneRx, &rxReady, startTx)
|
||||
d.start(&wg, &done, &rxReady, startTx)
|
||||
}
|
||||
samp := &sampler{dirs: dirs}
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
samp.run(&doneRx, startTx)
|
||||
samp.run(&done, startTx)
|
||||
}()
|
||||
rxReady.Wait()
|
||||
|
||||
@@ -673,8 +674,7 @@ func run(aName, bName string, nsPerM float64) error {
|
||||
for {
|
||||
select {
|
||||
case <-sig:
|
||||
doneTx.Store(true)
|
||||
doneRx.Store(true)
|
||||
done.Store(true)
|
||||
wg.Wait()
|
||||
return nil
|
||||
case <-space:
|
||||
|
||||
Reference in New Issue
Block a user