Skip to content
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

feat: stop sigprof while calling native #342

Merged
merged 2 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion decoder/primitives.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ func decodeTypedPointer(s string, i int, vt *rt.GoType, vp unsafe.Pointer, sb *_
return 0, err
} else {
rt.MoreStack(_FP_size + _VD_size + native.MaxFrameSize)
return fn(s, i, vp, sb, fv, "", nil)
rt.StopProf()
ret, err := fn(s, i, vp, sb, fv, "", nil)
rt.StartProf()
return ret, err
}
}

Expand Down
10 changes: 8 additions & 2 deletions encoder/primitives.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,16 @@ func encodeTypedPointer(buf *[]byte, vt *rt.GoType, vp *unsafe.Pointer, sb *_Sta
return err
} else if vt.Indirect() {
rt.MoreStack(_FP_size + native.MaxFrameSize)
return fn(buf, *vp, sb, fv)
rt.StopProf()
err := fn(buf, *vp, sb, fv)
rt.StartProf()
return err
} else {
rt.MoreStack(_FP_size + native.MaxFrameSize)
return fn(buf, unsafe.Pointer(vp), sb, fv)
rt.StopProf()
err := fn(buf, unsafe.Pointer(vp), sb, fv)
rt.StartProf()
return err
}
}

Expand Down
44 changes: 40 additions & 4 deletions internal/rt/asm.s
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// +build !noasm !appengine
// Code generated by asm2asm, DO NOT EDIT.
// Code generated by asm2asm, DO NOT EDIT·

#include "go_asm.h"
#include "funcdata.h"
Expand All @@ -13,8 +13,44 @@ _entry:
NOTQ R12
LEAQ (SP)(R12*1), R12
CMPQ R12, 16(R14)
JBE _stack_grow
JBE _stack_grow
RET
_stack_grow:
CALL runtime·morestack_noctxt<>(SB)
JMP _entry
CALL runtime·morestack_noctxt<>(SB)
JMP _entry


TEXT ·StopProf(SB), NOSPLIT, $0-0
NO_LOCAL_POINTERS
MOVL $1, AX
LEAQ github·com∕bytedance∕sonic∕internal∕rt·yieldCount(SB), CX
LOCK
XADDL AX, (CX)
MOVL runtime·prof+4(SB), AX
TESTL AX, AX
JEQ _ret_1
MOVL AX, github·com∕bytedance∕sonic∕internal∕rt·oldHz(SB)
MOVL $0, runtime·prof+4(SB)
_ret_1:
RET


TEXT ·StartProf(SB), NOSPLIT, $0-0
NO_LOCAL_POINTERS
MOVL $-1, AX
LEAQ github·com∕bytedance∕sonic∕internal∕rt·yieldCount(SB), CX
LOCK
XADDL AX, (CX)
CMPL github·com∕bytedance∕sonic∕internal∕rt·yieldCount(SB), $0
JNE _ret_2
CMPL runtime·prof+4(SB), $0
JNE _ret_2
CMPL github·com∕bytedance∕sonic∕internal∕rt·oldHz(SB), $0
JNE _branch_1
MOVL $100, github·com∕bytedance∕sonic∕internal∕rt·oldHz(SB)
_branch_1:
MOVL github·com∕bytedance∕sonic∕internal∕rt·oldHz(SB), AX
MOVL AX, runtime·prof+4(SB)
_ret_2:
RET

3 changes: 0 additions & 3 deletions internal/rt/fastmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,3 @@ func FuncAddr(f interface{}) unsafe.Pointer {
return *(*unsafe.Pointer)(vv.Value)
}
}

//go:nosplit
func MoreStack(size uintptr)
42 changes: 42 additions & 0 deletions internal/rt/gcwb.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,45 @@ func GcwbAddr() uintptr {
return uintptr(fp) + off
}
}

// WARN: must be aligned with runtime.Prof
// type Prof struct {
// signalLock uint32
// hz int32
// }

var (
// // go:linkname runtimeProf runtime.prof
// runtimeProf Prof

// count of native-C calls
yieldCount uint32

// previous value of runtimeProf.hz
oldHz int32
)

//go:nosplit
func MoreStack(size uintptr)

func StopProf()

// func StopProf() {
// atomic.AddUint32(&yieldCount, 1)
// if runtimeProf.hz != 0 {
// oldHz = runtimeProf.hz
// runtimeProf.hz = 0
// }
// }

func StartProf()

// func StartProf() {
// atomic.AddUint32(&yieldCount, ^uint32(0))
// if yieldCount == 0 && runtimeProf.hz == 0 {
// if oldHz == 0 {
// oldHz = 100
// }
// runtimeProf.hz = oldHz
// }
// }