Restructure stats into delta, mask, and aggregate layers

This commit is contained in:
flamingcow
2026-08-31 09:35:32 -07:00
parent ea272e489c
commit 06fa759b1a
11 changed files with 316 additions and 364 deletions
+17 -23
View File
@@ -110,14 +110,14 @@ func fillBack(frames, bytes []uint64) {
}
type rxWorker struct {
fd int
batch int
stream uint16
spec *frameSpec
stats *rxStats
loss *lossWindow
measuring *atomic.Bool
ready *sync.WaitGroup
fd int
batch int
stream uint16
spec *frameSpec
stats *rxStats
loss *lossWindow
masked *atomic.Bool
ready *sync.WaitGroup
}
func (w *rxWorker) run(done *atomic.Bool) {
@@ -133,12 +133,13 @@ func (w *rxWorker) run(done *atomic.Bool) {
w.ready.Done()
for !done.Load() {
// One flag load covers the batch: failures seen while a cable measure
// runs are its own link blip and are never counted.
quiet := w.measuring.Load()
// The worker just counts; the mask gate above decides what a masked
// tick's counts are worth. One flag load covers the batch for the loss
// window, whose gap charges outlive the tick they happened in.
masked := w.masked.Load()
n, err := recvmmsg(w.fd, hdrs, unix.MSG_WAITFORONE)
if n <= 0 {
if err != nil && err != unix.EAGAIN && err != unix.EINTR && !quiet {
if err != nil && err != unix.EAGAIN && err != unix.EINTR {
w.stats.rxErrs.Add(1)
}
continue
@@ -149,9 +150,6 @@ func (w *rxWorker) run(done *atomic.Bool) {
buf := bufs[i][:int(hdrs[i].len)]
p, st := parseHeader(buf)
if st != hdrOK {
if quiet {
continue
}
if st == hdrForeign {
w.stats.badMagic.Add(1)
} else {
@@ -165,22 +163,18 @@ func (w *rxWorker) run(done *atomic.Bool) {
// The ethertype this socket is bound to already says which stream the
// frame belongs to, so a header naming another one is damaged, as is a
// sequence number the sender never reached.
if p.stream != w.stream || !w.loss.observe(p.seq, quiet) {
if !quiet {
w.stats.badHdr.Add(1)
}
if p.stream != w.stream || !w.loss.observe(p.seq, masked) {
w.stats.badHdr.Add(1)
continue
}
want, ok := w.spec.expectedCRC(p.patIdx, p.payLen)
if !ok {
if !quiet {
w.stats.badLen.Add(1)
}
w.stats.badLen.Add(1)
continue
}
pay := buf[minFrame : minFrame+p.payLen]
if crc32.Checksum(pay, crcTable) != want && !quiet {
if crc32.Checksum(pay, crcTable) != want {
w.stats.crcErr.Add(1)
}
}