tun: Read the clock once per staged loop iteration

The TX reader timed its slot wait with a second pair of clock reads only to
subtract it again. It now waits for a free slot before it starts the busy
clock, so a read costs one time.Now and one time.Since. The RX listener
likewise ends its busy time when it has to wait for a batch instead of
timing the wait, and pool workers time a run of queued jobs with one pair
of reads. A test checks the read stages still leave backpressure out.
This commit is contained in:
Ryan Huber committed 2026-10-16 21:23:34 +00:00
1 parent 130ef730b4
commit eccaf1ca23
4 files changed
+69 -20

No files matched your search

+15 -1
View File
@@ -108,8 +108,12 @@ func newFlowPool(workers, queueLen int, busy metrics.Counter) *flowPool {
p.wg.Go(func() {
nb := make([]byte, 12)
for job := range p.jobs {
// One pair of clock reads covers a run of jobs that are queued back to back
t := time.Now()
job.run(nb)
for job != nil {
job.run(nb)
job = p.next()
}
busy.Inc(int64(time.Since(t)))
}
})
@@ -117,6 +121,16 @@ func newFlowPool(workers, queueLen int, busy metrics.Counter) *flowPool {
return p
}
// next returns the next queued job without waiting, or nil.
func (p *flowPool) next() flowJob {
select {
case job := <-p.jobs:
return job
default:
return nil
}
}
func (p *flowPool) close() { close(p.jobs); p.wg.Wait() }
// stageBusy is the busy time counter of one stage of routine q.