Skip to content

Commit 6b67a23

Browse files
committed
fix: make block syscall in asm
1 parent bd07a46 commit 6b67a23

File tree

4 files changed

+98
-12
lines changed

4 files changed

+98
-12
lines changed

poll_default_linux.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ func (p *defaultPoll) Wait() (err error) {
9999
}
100100
// msec: 0(raw) => 1ms(sched,raw) => -1(block_syscall)
101101
// poller's G will hold P at most 1ms
102-
if msec > 0 {
103-
n, err = EpollWaitRaw(p.fd, p.events, msec)
104-
} else if msec == 0 {
102+
if msec >= 0 {
105103
n, err = EpollWaitRaw(p.fd, p.events, msec)
106104
} else { // < 0
107105
n, err = EpollWaitBlock(p.fd, p.events, msec)

sys_epoll_linux.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ func entersyscallblock()
2828
//go:linkname exitsyscall runtime.exitsyscall
2929
func exitsyscall()
3030

31+
//go:nosplit
32+
func callEntersyscallblock() {
33+
entersyscallblock()
34+
}
35+
36+
//go:nosplit
37+
func callExitsyscall() {
38+
exitsyscall()
39+
}
40+
3141
// EpollCreate implements epoll_create1.
3242
func EpollCreate(flag int) (fd int, err error) {
3343
var r0 uintptr
@@ -68,18 +78,13 @@ func EpollWaitRaw(epfd int, events []epollevent, msec int) (n int, err error) {
6878

6979
func EpollWaitBlock(epfd int, events []epollevent, msec int) (n int, err error) {
7080
r0, _, errno := BlockSyscall6(SYS_EPOLL_WAIT, uintptr(epfd), uintptr(unsafe.Pointer(&events[0])), uintptr(len(events)), uintptr(msec), 0, 0)
71-
if errno == syscall.Errno(0) {
81+
if errno == 0 {
7282
err = nil
7383
} else {
74-
err = errno
84+
err = syscall.Errno(errno)
7585
}
7686
return int(r0), err
7787
}
7888

79-
//go:nosplit
80-
func BlockSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err syscall.Errno) {
81-
entersyscallblock()
82-
r1, r2, err = syscall.RawSyscall6(trap, a1, a2, a3, a4, a5, a6)
83-
exitsyscall()
84-
return r1, r2, err
85-
}
89+
//go:noescape
90+
func BlockSyscall6(num, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, errno uintptr)

sys_epoll_linux_amd64.s

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2024 CloudWeGo Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "textflag.h"
16+
17+
// func BlockSyscall6(num, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, errno uintptr)
18+
TEXT ·BlockSyscall6<ABIInternal>(SB),NOSPLIT,$0
19+
CALL ·callEntersyscallblock(SB)
20+
// a6 already in R9.
21+
// a5 already in R8.
22+
MOVQ SI, R10 // a4
23+
MOVQ DI, DX // a3
24+
MOVQ CX, SI // a2
25+
MOVQ BX, DI // a1
26+
// num already in AX.
27+
SYSCALL
28+
CMPQ AX, $0xfffffffffffff001
29+
JLS ok
30+
NEGQ AX
31+
MOVQ AX, CX // errno
32+
MOVQ $-1, AX // r1
33+
MOVQ $0, BX // r2
34+
CALL ·callExitsyscall(SB)
35+
RET
36+
ok:
37+
// r1 already in AX.
38+
MOVQ DX, BX // r2
39+
MOVQ $0, CX // errno
40+
CALL ·callExitsyscall(SB)
41+
RET

sys_epoll_linux_arm64.s

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2024 CloudWeGo Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "textflag.h"
16+
17+
// func BlockSyscall6(num, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, errno uintptr)
18+
TEXT ·BlockSyscall6(SB),NOSPLIT,$0-80
19+
BL ·callEntersyscallblock(SB)
20+
MOVD num+0(FP), R8 // syscall entry
21+
MOVD a1+8(FP), R0
22+
MOVD a2+16(FP), R1
23+
MOVD a3+24(FP), R2
24+
MOVD a4+32(FP), R3
25+
MOVD a5+40(FP), R4
26+
MOVD a6+48(FP), R5
27+
SVC
28+
CMN $4095, R0
29+
BCC ok
30+
MOVD $-1, R4
31+
MOVD R4, r1+56(FP)
32+
MOVD ZR, r2+64(FP)
33+
NEG R0, R0
34+
MOVD R0, errno+72(FP)
35+
BL ·callExitsyscall(SB)
36+
RET
37+
ok:
38+
MOVD R0, r1+56(FP)
39+
MOVD R1, r2+64(FP)
40+
MOVD ZR, errno+72(FP)
41+
BL ·callExitsyscall(SB)
42+
RET

0 commit comments

Comments
 (0)