aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/netpoll_kqueue.go
diff options
context:
space:
mode:
authorAndy Pan <i@andypan.me>2024-04-10 16:48:09 +0800
committerGopher Robot <gobot@golang.org>2024-04-12 21:17:22 +0000
commit519f6a00e4dabb871eadaefc8ac295c09fd9b56f (patch)
tree8c18ffe9cc2a7199823dcd81c48e1b841dde92f7 /src/runtime/netpoll_kqueue.go
parent19626726205b5653ff9a1820d35bf1b7e820d4ce (diff)
downloadgo-519f6a00e4dabb871eadaefc8ac295c09fd9b56f.tar.xz
runtime: utilize EVFILT_USER to wake up kevent for kqueue
Fixes #66760 Change-Id: I6ba5bc5b00506b66cb8dc3984a61f32a6358d9bc Reviewed-on: https://go-review.googlesource.com/c/go/+/577895 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Run-TryBot: Andy Pan <panjf2000@gmail.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Diffstat (limited to 'src/runtime/netpoll_kqueue.go')
-rw-r--r--src/runtime/netpoll_kqueue.go54
1 files changed, 7 insertions, 47 deletions
diff --git a/src/runtime/netpoll_kqueue.go b/src/runtime/netpoll_kqueue.go
index 32c21a2b2b..6cd80d5c30 100644
--- a/src/runtime/netpoll_kqueue.go
+++ b/src/runtime/netpoll_kqueue.go
@@ -15,10 +15,7 @@ import (
)
var (
- kq int32 = -1
-
- netpollBreakRd, netpollBreakWr uintptr // for netpollBreak
-
+ kq int32 = -1
netpollWakeSig atomic.Uint32 // used to avoid duplicate calls of netpollBreak
)
@@ -29,27 +26,7 @@ func netpollinit() {
throw("runtime: netpollinit failed")
}
closeonexec(kq)
- r, w, errno := nonblockingPipe()
- if errno != 0 {
- println("runtime: pipe failed with", -errno)
- throw("runtime: pipe failed")
- }
- ev := keventt{
- filter: _EVFILT_READ,
- flags: _EV_ADD,
- }
- *(*uintptr)(unsafe.Pointer(&ev.ident)) = uintptr(r)
- n := kevent(kq, &ev, 1, nil, 0, nil)
- if n < 0 {
- println("runtime: kevent failed with", -n)
- throw("runtime: kevent failed")
- }
- netpollBreakRd = uintptr(r)
- netpollBreakWr = uintptr(w)
-}
-
-func netpollIsPollDescriptor(fd uintptr) bool {
- return fd == uintptr(kq) || fd == netpollBreakRd || fd == netpollBreakWr
+ addWakeupEvent(kq)
}
func netpollopen(fd uintptr, pd *pollDesc) int32 {
@@ -99,18 +76,7 @@ func netpollBreak() {
return
}
- for {
- var b byte
- n := write(netpollBreakWr, unsafe.Pointer(&b), 1)
- if n == 1 || n == -_EAGAIN {
- break
- }
- if n == -_EINTR {
- continue
- }
- println("runtime: netpollBreak write failed with", -n)
- throw("runtime: netpollBreak write failed")
- }
+ wakeNetpoll(kq)
}
// netpoll checks for ready network connections.
@@ -159,17 +125,11 @@ retry:
for i := 0; i < int(n); i++ {
ev := &events[i]
- if uintptr(ev.ident) == netpollBreakRd {
- if ev.filter != _EVFILT_READ {
- println("runtime: netpoll: break fd ready for", ev.filter)
- throw("runtime: netpoll: break fd ready for something unexpected")
- }
+ if isWakeup(ev) {
if delay != 0 {
- // netpollBreak could be picked up by a
- // nonblocking poll. Only read the byte
- // if blocking.
- var tmp [16]byte
- read(int32(netpollBreakRd), noescape(unsafe.Pointer(&tmp[0])), int32(len(tmp)))
+ // netpollBreak could be picked up by a nonblocking poll.
+ // Only call drainWakeupEvent and reset the netpollWakeSig if blocking.
+ drainWakeupEvent(kq)
netpollWakeSig.Store(0)
}
continue