From 88f4f7da809e5b8113599069f50749af7d2a9c5c Mon Sep 17 00:00:00 2001 From: flamingcow Date: Wed, 5 Aug 2026 08:18:44 -0700 Subject: [PATCH] Poll the nic on the sampler's cadence, and reboot rather than exit when a clean return reaches PID 1 --- counters.go | 8 ++++---- main.go | 8 ++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/counters.go b/counters.go index 4ce8f7d..c34305f 100644 --- a/counters.go +++ b/counters.go @@ -80,10 +80,10 @@ func sumFields(base string, fields []string) uint64 { // A poll is an ioctl and a handful of sysfs attributes, each costing // microseconds of open and read, so it runs here rather than on the goroutine -// that has a frame to draw every sixteen milliseconds. Off that path the -// interval can be short enough that an unplugged cable shows up as a link error -// while the hand is still on it. -const nicInterval = 200 * time.Millisecond +// that has a frame to draw every sixteen milliseconds. Off that path it can +// match the sampler's cadence, so a link error lands on the panel as quickly +// as a lost frame rather than stepping five times a second. +const nicInterval = sampleInterval type nicPoller struct { txBase string diff --git a/main.go b/main.go index a241f4d..c97d7b8 100644 --- a/main.go +++ b/main.go @@ -535,6 +535,14 @@ func main() { if err := run(*aName, *bName, *nsPerM); err != nil { panic(err) } + // A clean return is ctrl-alt-delete, which the kernel hands PID 1 as a + // SIGINT. Exiting on it would panic the kernel over the reboot it was asking + // for, so init asks for the reboot by name. + if os.Getpid() == 1 { + if err := unix.Reboot(unix.LINUX_REBOOT_CMD_RESTART); err != nil { + panic(err) + } + } } const (