summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/ioworkload/scenario_polling.go31
-rw-r--r--cmd/ioworkload/scenario_polling_test.go33
-rw-r--r--integrationtests/polling_test.go58
3 files changed, 103 insertions, 19 deletions
diff --git a/cmd/ioworkload/scenario_polling.go b/cmd/ioworkload/scenario_polling.go
index 6a97f57..1531511 100644
--- a/cmd/ioworkload/scenario_polling.go
+++ b/cmd/ioworkload/scenario_polling.go
@@ -1,6 +1,7 @@
package main
import (
+ "errors"
"fmt"
"runtime"
"syscall"
@@ -29,6 +30,7 @@ func pollingEpoll() error {
return fmt.Errorf("epoll_ctl add: %w", err)
}
+ pwait2Supported := true
deadline := time.Now().Add(5 * time.Second)
for time.Now().Before(deadline) {
if err := waitAndDrain(epfd, pipefd, callEpollWait); err != nil {
@@ -37,8 +39,16 @@ func pollingEpoll() error {
if err := waitAndDrain(epfd, pipefd, callEpollPwait); err != nil {
return err
}
- if err := waitAndDrain(epfd, pipefd, callEpollPwait2); err != nil {
- return err
+ if pwait2Supported {
+ if err := waitAndDrain(epfd, pipefd, callEpollPwait2); err != nil {
+ if !isUnsupportedEpollPwait2Err(err) {
+ return err
+ }
+ if drainErr := drainWakeByte(pipefd[0]); drainErr != nil {
+ return drainErr
+ }
+ pwait2Supported = false
+ }
}
}
@@ -57,8 +67,12 @@ func waitAndDrain(epfd int, pipefd [2]int, waitFn func(int, []unix.EpollEvent) (
if ready < 1 {
return fmt.Errorf("epoll wait returned %d ready events", ready)
}
+ return drainWakeByte(pipefd[0])
+}
+
+func drainWakeByte(readFD int) error {
var buf [1]byte
- if _, err := syscall.Read(pipefd[0], buf[:]); err != nil {
+ if _, err := syscall.Read(readFD, buf[:]); err != nil {
return fmt.Errorf("drain wake byte: %w", err)
}
return nil
@@ -119,3 +133,14 @@ func callEpollPwait2(epfd int, events []unix.EpollEvent) (int, error) {
}
return int(r1), nil
}
+
+func isUnsupportedEpollPwait2Err(err error) bool {
+ if err == nil {
+ return false
+ }
+ var errno syscall.Errno
+ if !errors.As(err, &errno) {
+ return false
+ }
+ return errno == syscall.ENOSYS || errno == syscall.ENOTSUP
+}
diff --git a/cmd/ioworkload/scenario_polling_test.go b/cmd/ioworkload/scenario_polling_test.go
new file mode 100644
index 0000000..83e6d7c
--- /dev/null
+++ b/cmd/ioworkload/scenario_polling_test.go
@@ -0,0 +1,33 @@
+package main
+
+import (
+ "fmt"
+ "syscall"
+ "testing"
+)
+
+func TestIsUnsupportedEpollPwait2Err(t *testing.T) {
+ t.Parallel()
+
+ tests := []struct {
+ name string
+ err error
+ want bool
+ }{
+ {name: "nil", err: nil, want: false},
+ {name: "enosys", err: fmt.Errorf("epoll_pwait2: %w", syscall.ENOSYS), want: true},
+ {name: "enotsup", err: fmt.Errorf("epoll_pwait2: %w", syscall.ENOTSUP), want: true},
+ {name: "einval", err: fmt.Errorf("epoll_pwait2: %w", syscall.EINVAL), want: false},
+ {name: "opaque", err: fmt.Errorf("epoll_pwait2: not-supported"), want: false},
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ t.Parallel()
+ got := isUnsupportedEpollPwait2Err(tt.err)
+ if got != tt.want {
+ t.Fatalf("isUnsupportedEpollPwait2Err(%v) = %v, want %v", tt.err, got, tt.want)
+ }
+ })
+ }
+}
diff --git a/integrationtests/polling_test.go b/integrationtests/polling_test.go
index af3806a..cea535e 100644
--- a/integrationtests/polling_test.go
+++ b/integrationtests/polling_test.go
@@ -1,6 +1,9 @@
package integrationtests
-import "testing"
+import (
+ "strings"
+ "testing"
+)
const (
pollingParquetDuration = 10
@@ -21,8 +24,11 @@ func TestPollingEpollTracepoints(t *testing.T) {
{Tracepoint: "enter_epoll_ctl", Comm: "ioworkload", MinCount: 1},
{Tracepoint: "enter_epoll_wait", Comm: "ioworkload", MinCount: 1},
{Tracepoint: "enter_epoll_pwait", Comm: "ioworkload", MinCount: 1},
- {Tracepoint: "enter_epoll_pwait2", Comm: "ioworkload", MinCount: 1},
})
+
+ if !hasTracepoint(result, "enter_epoll_pwait2") {
+ t.Log("enter_epoll_pwait2 not observed; treating as unsupported-kernel path")
+ }
}
func TestPollingEpollReadyCountInParquet(t *testing.T) {
@@ -38,21 +44,26 @@ func TestPollingEpollReadyCountInParquet(t *testing.T) {
t.Fatalf("expected parquet rows for workload PID %d", pid)
}
- wantReadyCount := map[string]bool{
- "epoll_wait": false,
- "epoll_pwait": false,
- "epoll_pwait2": false,
- }
+ wantReadyCount := map[string]bool{"epoll_wait": false, "epoll_pwait": false}
+ var sawPwait2 bool
+ var sawPwait2ReadyCount bool
for _, row := range rows {
- _, tracked := wantReadyCount[row.Syscall]
- if !tracked {
- continue
- }
- if row.Ret > 0 {
- wantReadyCount[row.Syscall] = true
- }
- if row.Bytes != 0 {
- t.Fatalf("%s bytes = %d, want 0 for ready-count events", row.Syscall, row.Bytes)
+ switch row.Syscall {
+ case "epoll_wait", "epoll_pwait":
+ if row.Ret > 0 {
+ wantReadyCount[row.Syscall] = true
+ }
+ if row.Bytes != 0 {
+ t.Fatalf("%s bytes = %d, want 0 for ready-count events", row.Syscall, row.Bytes)
+ }
+ case "epoll_pwait2":
+ sawPwait2 = true
+ if row.Ret > 0 {
+ sawPwait2ReadyCount = true
+ }
+ if row.Bytes != 0 {
+ t.Fatalf("%s bytes = %d, want 0 for ready-count events", row.Syscall, row.Bytes)
+ }
}
}
@@ -61,4 +72,19 @@ func TestPollingEpollReadyCountInParquet(t *testing.T) {
t.Fatalf("expected %s row with positive ready-count ret in parquet output", syscall)
}
}
+ if sawPwait2 && !sawPwait2ReadyCount {
+ t.Fatalf("expected epoll_pwait2 row with positive ready-count ret when epoll_pwait2 is present")
+ }
+ if !sawPwait2 {
+ t.Log("epoll_pwait2 parquet rows not observed; treating as unsupported-kernel path")
+ }
+}
+
+func hasTracepoint(result TestResult, tracepoint string) bool {
+ for _, rec := range result.Records {
+ if strings.Contains(rec.TraceID.String(), tracepoint) {
+ return true
+ }
+ }
+ return false
}