Skip to content

Commit

Permalink
perf: gopool update schedwhen
Browse files Browse the repository at this point in the history
  • Loading branch information
joway committed Sep 18, 2023
1 parent f58f78a commit 1be40f9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lang/runtimex/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import (
//go:linkname Fastrand runtime.fastrand
func Fastrand() uint32

//go:linkname Nanotime runtime.nanotime
func Nanotime() int64

func getg() uintptr

type puintptr uintptr
Expand Down
11 changes: 11 additions & 0 deletions util/gopool/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"sync"
"sync/atomic"

"github.com/bytedance/gopkg/lang/runtimex"
"github.com/bytedance/gopkg/util/logger"
)

Expand All @@ -39,8 +40,12 @@ func newWorker() interface{} {

func (w *worker) run() {
go func() {
g := runtimex.GetG()
m := g.M()
p := m.P()
for {
var t *task
now := runtimex.Nanotime()
w.pool.taskLock.Lock()
if w.pool.taskHead != nil {
t = w.pool.taskHead
Expand All @@ -54,6 +59,12 @@ func (w *worker) run() {
w.Recycle()
return
}

// update sysmon tick
st := *p.Sysmontick()
st.Schedwhen = now
*p.Sysmontick() = st

w.pool.taskLock.Unlock()
func() {
defer func() {
Expand Down

0 comments on commit 1be40f9

Please sign in to comment.