go: runtime: use epoll_pwait2 where available for sub-millisecond timeout precision on Linux

Linux kernel 5.11 (February, 2021) added the epoll_pwait2 system call. It is exactly like epoll_pwait except that the timeout argument is a struct timespec. This permits specifying a timeout with nanosecond precision, where epoll_pwait and epoll_wait only permit millisecond precision. We should change runtime/netpoll_epoll.go to use epoll_pwait2 when available to get higher precision delays.

CC @golang/runtime

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 9
  • Comments: 24 (24 by maintainers)

Commits related to this issue

Most upvoted comments

I think for now you can just add the epoll constants you need for the CL.

For the syscall number constants, I would create new per-arch files in runtime/internal/syscall to define those constants. Eventually, we’ll want to shift all of the constants out of sys_linux_xxx.s and into that package (and ideally generate them).

Which packages the runtime can import are very restricted, so it wouldn’t be able to import golang.org/x/sys/unix. We might eventually want to use the same code generation mechanism for both, but that’s down the road.

The constant _ENOSYS was removed from the runtime package in https://go.dev/cl/389354. It would be fine to revert that part of that CL for this purpose.

Since this is Linux-only, it could use the new runtime/internal/syscall package, rather than implementing it in assembly for all architectures.

Mostly because I simply haven’t gotten around to it. You are welcome to base a change off of my CL.

I also did want to do some benchmarking (probably with https://cs.opensource.google/go/x/benchmarks/+/master:sweet/) to check for performance regressions, since more precise timeouts could potentially lead to more frequent wakeups.

Thanks. I suggest that you sketch out what you will do before implementing, to make sure that it seems like a good approach.

Does anybody work on this? I can take on it.