diff options
| -rw-r--r-- | cmd/ioworkload/scenario_ipc.go | 29 | ||||
| -rw-r--r-- | integrationtests/ipc_test.go | 10 |
2 files changed, 38 insertions, 1 deletions
diff --git a/cmd/ioworkload/scenario_ipc.go b/cmd/ioworkload/scenario_ipc.go index af22505..207966e 100644 --- a/cmd/ioworkload/scenario_ipc.go +++ b/cmd/ioworkload/scenario_ipc.go @@ -77,11 +77,38 @@ func fdFromAirEventfdUsers() error { fd, _, _ = syscall.RawSyscall(unix.SYS_SIGNALFD4, ^uintptr(0), uintptr(unsafe.Pointer(&mask)), uintptr(unsafe.Sizeof(mask))) closeIfValid(int(fd)) + // Create a timerfd and, while it is still open, arm it with + // timerfd_settime and read it back with timerfd_gettime. Both of those + // syscalls take the timerfd as arg0 (kind=fd@arg0), so tracing them + // exercises the fd_event capture path fixed in commit 6ac9fa4: the enter + // handlers must resolve arg0 to the registered "timerfd:" descriptor + // rather than emitting a null event. We close the fd only after both + // operations so the descriptor stays registered for the duration. fd, _, _ = syscall.RawSyscall(unix.SYS_TIMERFD_CREATE, uintptr(unix.CLOCK_MONOTONIC), uintptr(unix.TFD_CLOEXEC), 0) - closeIfValid(int(fd)) + if int(fd) >= 0 { + armAndReadTimerfd(int(fd)) + closeIfValid(int(fd)) + } return nil } +// armAndReadTimerfd arms the given timerfd via timerfd_settime and reads its +// current setting back via timerfd_gettime. The timer is set to a one-second +// relative expiration: far enough in the future that it never actually fires +// during the scenario, so its only observable effect is that the two syscalls +// are issued against an already-open timerfd descriptor. +func armAndReadTimerfd(fd int) { + newValue := unix.ItimerSpec{ + Value: unix.Timespec{Sec: 1, Nsec: 0}, + } + syscall.RawSyscall6(unix.SYS_TIMERFD_SETTIME, uintptr(fd), 0, + uintptr(unsafe.Pointer(&newValue)), 0, 0, 0) + + var curValue unix.ItimerSpec + syscall.RawSyscall(unix.SYS_TIMERFD_GETTIME, uintptr(fd), + uintptr(unsafe.Pointer(&curValue)), 0) +} + func closeIfValid(fd int) { if fd >= 0 { _ = syscall.Close(fd) diff --git a/integrationtests/ipc_test.go b/integrationtests/ipc_test.go index 8420b9b..ea51ccc 100644 --- a/integrationtests/ipc_test.go +++ b/integrationtests/ipc_test.go @@ -73,10 +73,20 @@ func TestFdFromAirEventfdUsers(t *testing.T) { {Tracepoint: "enter_signalfd", MinCount: 1}, {Tracepoint: "enter_signalfd4", MinCount: 1}, {Tracepoint: "enter_timerfd_create", MinCount: 1}, + // The timerfd is armed and read back while still open, so + // timerfd_settime/gettime fire against the existing descriptor. + {Tracepoint: "enter_timerfd_settime", MinCount: 1}, + {Tracepoint: "enter_timerfd_gettime", MinCount: 1}, }) assertTracepointPathPrefix(t, result, "enter_memfd_create", "memfd:") assertTracepointPathPrefix(t, result, "enter_timerfd_create", "timerfd:") + + // timerfd_settime/gettime take the timerfd as arg0 (kind=fd@arg0). The + // "timerfd:" path prefix proves the enter handlers captured that fd via + // fd_event rather than emitting a null event, locking in the 6ac9fa4 fix. + assertTracepointPathPrefix(t, result, "enter_timerfd_settime", "timerfd:") + assertTracepointPathPrefix(t, result, "enter_timerfd_gettime", "timerfd:") } // TestInotifyBasic asserts end-to-end tracing of the inotify IPC family. |
