-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
runtime: use epoll_pwait2 where available for sub-millisecond timeout precision on Linux #53824
Comments
Specifically, this will help with #44343 (comment) on Linux. |
Does anybody work on this? I can take on it. |
Thanks. I suggest that you sketch out what you will do before implementing, to make sure that it seems like a good approach. |
@ianlancetaylor, I've just discovered the patch from @prattmic: https://go.dev/cl/363417. |
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, @prattmic. I'll prepare CL then and will do some benchmarking. |
Since this is Linux-only, it could use the new runtime/internal/syscall
package, rather than implementing it in assembly for all architectures.
|
Oh, cool, thanks for the advice Austin! |
I have a few questions. @prattmic, in your CL you use And in a broader context, if we go with Thanks! |
The constant |
For the syscall number constants, I would create new per-arch files in Which packages the runtime can import are very restricted, so it wouldn't be able to import |
Yes, this is what I was thinking to do. To generate those constants (like it's done in Or in this CL I should only have |
Ah, as far as I can see there is no generator for the runtime now. Hence no easy way to generate syscall defs. |
I think for now you can just add the epoll constants you need for the CL. |
Hi, I'm again with questions.
var _zero uintptr
func epollwait2(epfd int, events []epollevent, maxev int, ts *timespec) (n, errno int) {
var ev unsafe.Pointer
if len(events) > 0 {
ev = unsafe.Pointer(&events[0])
} else {
ev = unsafe.Pointer(&_zero)
}
r1, _, e := syscall.Syscall6(syscall.SYS_EPOLL_PWAIT2, uintptr(epfd), uintptr(ev), uintptr(maxev), uintptr(unsafe.Pointer(&ts)), 0, 0)
return int(r1), int(e)
}
... But then I thought, it makes sense to define these funcs in
Cheers! |
I think that sounds good.
They use
I think you should have at least 2 CLs: one (or more) moving things to |
Hi Michael, thank you for the feedback and explanations.
Sounds good to me. Cheers! |
Change https://go.dev/cl/421994 mentions this issue: |
This change moves Linux epoll's syscalls implementation to the "runtime/internal/syscall" package. The intention in this CL was to minimise behavioural changes but make the code more generalised. This also will allow adding new syscalls (like epoll_pwait2) without the need to implement assembly stubs for each arch. It also drops epoll_create as not all architectures provide this call. epoll_create1 was added to the kernel in version 2.6.27 and Go requires Linux kernel version 2.6.32 or later since Go 1.18. So it is safe to always use epoll_create1. For #53824 For #51087 Change-Id: I9a6a26b7f2075a38e041de1bab4691da0ecb94fc Reviewed-on: https://go-review.googlesource.com/c/go/+/421994 Reviewed-by: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Run-TryBot: Michael Pratt <mpratt@google.com> Auto-Submit: Michael Pratt <mpratt@google.com>
Change https://go.dev/cl/437295 mentions this issue: |
This reverts CL 421994. Reason for revert: breaks runtime.TestCheckPtr2 For #53824 For #51087 Change-Id: I044ea4d6efdffe0a4b7fb0d2bb3717d9f391fc59 Reviewed-on: https://go-review.googlesource.com/c/go/+/437295 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Michael Pratt <mpratt@google.com> Auto-Submit: Michael Pratt <mpratt@google.com> Reviewed-by: Bryan Mills <bcmills@google.com>
Change https://go.dev/cl/440115 mentions this issue: |
This change moves Linux epoll's syscalls implementation to the "runtime/internal/syscall" package. The intention in this CL was to minimise behavioural changes but make the code more generalised. This also will allow adding new syscalls (like epoll_pwait2) without the need to implement assembly stubs for each arch. It also drops epoll_create as not all architectures provide this call. epoll_create1 was added to the kernel in version 2.6.27 and Go requires Linux kernel version 2.6.32 or later since Go 1.18. So it is safe to always use epoll_create1. This is a resubmit as the previous CL 421994 was reverted due to test failures after the merge with the master. The issue was fixed in CL 438615 For #53824 For #51087 Change-Id: I1bd0f23a85b4f9b80178c5dd36fd3e95ff4f9648 Reviewed-on: https://go-review.googlesource.com/c/go/+/440115 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Michael Pratt <mpratt@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> Run-TryBot: Michael Pratt <mpratt@google.com>
This change moves Linux epoll's syscalls implementation to the "runtime/internal/syscall" package. The intention in this CL was to minimise behavioural changes but make the code more generalised. This also will allow adding new syscalls (like epoll_pwait2) without the need to implement assembly stubs for each arch. It also drops epoll_create as not all architectures provide this call. epoll_create1 was added to the kernel in version 2.6.27 and Go requires Linux kernel version 2.6.32 or later since Go 1.18. So it is safe to always use epoll_create1. This is a resubmit as the previous CL 421994 was reverted due to test failures after the merge with the master. The issue was fixed in CL 438615 For golang#53824 For golang#51087 Change-Id: I1bd0f23a85b4f9b80178c5dd36fd3e95ff4f9648 Reviewed-on: https://go-review.googlesource.com/c/go/+/440115 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Michael Pratt <mpratt@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> Run-TryBot: Michael Pratt <mpratt@google.com>
Change https://go.dev/cl/449815 mentions this issue: |
It seems this has missed 2 releases. Moving to backlog. Please comment if you plan to work on it in Go 1.22 and I'm happy to move it there. Thanks! |
Change https://go.dev/cl/514275 mentions this issue: |
Updates #44343 Updates #53824 Change-Id: Ia7234fac4b1b88b3c331328aaa98dc85205e09ba Reviewed-on: https://go-review.googlesource.com/c/go/+/514275 Reviewed-by: David Chase <drchase@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Quim Muntal <quimmuntal@gmail.com>
Hi @dAdAbird, are you planning on returning to this? |
Linux kernel 5.11 (February, 2021) added the
epoll_pwait2
system call. It is exactly likeepoll_pwait
except that the timeout argument is astruct timespec
. This permits specifying a timeout with nanosecond precision, whereepoll_pwait
andepoll_wait
only permit millisecond precision. We should change runtime/netpoll_epoll.go to useepoll_pwait2
when available to get higher precision delays.CC @golang/runtime
The text was updated successfully, but these errors were encountered: