Poll the nic on the sampler's cadence, and reboot rather than exit when a clean return reaches PID 1

This commit is contained in:
flamingcow
2026-08-05 08:18:44 -07:00
parent ab60cc1cfc
commit 88f4f7da80
2 changed files with 12 additions and 4 deletions
+4 -4
View File
@@ -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
+8
View File
@@ -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 (