Skip to content

Commit

Permalink
more fixes again.
Browse files Browse the repository at this point in the history
  • Loading branch information
doujiang24 committed Jun 23, 2022
1 parent b93187b commit 4447bd5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/runtime/cgocall.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func cgocallbackg(fn, frame unsafe.Pointer, ctxt uintptr) {
gp.m.curg.goid = newgoid(gp.m.p.ptr())

if trace.enabled {
// delay emit events here, after get P.
// delay emit trace events here, after getting a P.
systemstack(func() {
traceGoCreate(gp, 0) // no start pc for locked g in extra M
traceGoStart()
Expand Down
29 changes: 15 additions & 14 deletions src/runtime/proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2509,7 +2509,7 @@ func execute(gp *g, inheritTime bool) {
}

if trace.enabled {
// delay emit trace events when first enter go from c
// delay emit trace events when entering go from c thread at the first level.
if !_g_.m.isextra || _g_.m.cgolevel != 0 {
if gp.syscallsp != 0 && gp.sysblocktraced {
// GoSysExit has to happen when we have a P, but before GoStart.
Expand Down Expand Up @@ -3647,13 +3647,13 @@ func reentersyscall(pc, sp uintptr) {
_g_.m.p = 0

if backToCThread {
// For a real syscall, we can assume it will back to go in a very short time,
// at least in most cases. So, keep the P in _Psyscall may be a better choice.
// For a real syscall, we assume it will back to go after a very short time,
// it's reasonable in most cases. So, keep the P in _Psyscall is a better choice.
// But in the c to go scene, we can not assume there will be a short time
// for the next c to go call, to reuse the oldp in exitsyscall.
// And the Psyscall status P can only be retake by sysmon after 20us ~ 10ms,
// means wasting P.
// So, it's better to handoff the P here.
// it means wasting P.
// So, it's better to handoffp here.
atomic.Store(&pp.status, _Pidle)
systemstack(func() {
handoffp(pp)
Expand Down Expand Up @@ -3784,7 +3784,7 @@ func exitsyscall() {
_g_.m.oldp = 0
if exitsyscallfast(oldp) {
if trace.enabled {
// delay emit trace events when first enter go from c
// delay emit trace events when entering go from c thread at the first level.
if !_g_.m.isextra || _g_.m.cgolevel != 0 {
if oldp != _g_.m.p.ptr() || _g_.m.syscalltick != _g_.m.p.ptr().syscalltick {
systemstack(traceGoStart)
Expand Down Expand Up @@ -3877,7 +3877,7 @@ func exitsyscallfast(oldp *p) bool {
osyield()
}
}
// delay emit trace events when first enter go from c
// delay emit trace events when entering go from c thread at the first level.
if !_g_.m.isextra || _g_.m.cgolevel != 0 {
traceGoSysExit(0)
}
Expand All @@ -3897,19 +3897,20 @@ func exitsyscallfast(oldp *p) bool {
//go:nosplit
func exitsyscallfast_reacquired() {
_g_ := getg()
// there is no oldp when entering go from c thread at the first level.
if _g_.m.isextra && _g_.m.cgolevel != 0 {
panic("oldp should not existing")
}
if _g_.m.syscalltick != _g_.m.p.ptr().syscalltick {
if trace.enabled {
// The p was retaken and then enter into syscall again (since _g_.m.syscalltick has changed).
// traceGoSysBlock for this syscall was already emitted,
// but here we effectively retake the p from the new syscall running on the same p.
systemstack(func() {
// delay emit trace events when first enter go from c
if !_g_.m.isextra || _g_.m.cgolevel != 0 {
// Denote blocking of the new syscall.
traceGoSysBlock(_g_.m.p.ptr())
// Denote completion of the current syscall.
traceGoSysExit(0)
}
// Denote blocking of the new syscall.
traceGoSysBlock(_g_.m.p.ptr())
// Denote completion of the current syscall.
traceGoSysExit(0)
})
}
_g_.m.p.ptr().syscalltick++
Expand Down
6 changes: 3 additions & 3 deletions src/runtime/runtime2.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,13 +540,13 @@ type m struct {
printlock int8
incgo bool // m is executing a cgo call
isextra bool // m is an extra m
cgolevel int32 // level of cgo(c=>go) calls currently in progress
cgolevel int32 // level of cgo(c to go) calls currently in progress
freeWait uint32 // if == 0, safe to free g0 and delete m (atomic)
fastrand uint64
needextram bool
traceback uint8
ncgocall uint64 // number of cgo(go=>c) calls in total
ncgo int32 // number of cgo(go=>c) calls currently in progress
ncgocall uint64 // number of cgo(go to c) calls in total
ncgo int32 // number of cgo(go to c) calls currently in progress
cgoCallersUse uint32 // if non-zero, cgoCallers in use temporarily
cgoCallers *cgoCallers // cgo traceback if crashing in cgo call
park note
Expand Down

0 comments on commit 4447bd5

Please sign in to comment.