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

sysmon是不是和某个M共用?该M也进行执行G? #31

Open
JayenLee opened this issue Feb 9, 2020 · 0 comments
Open

sysmon是不是和某个M共用?该M也进行执行G? #31

JayenLee opened this issue Feb 9, 2020 · 0 comments

Comments

@JayenLee
Copy link

JayenLee commented Feb 9, 2020

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

1.13.6
我在阅读您的blog 《深入golang-runtime的调度》看到
main goroutine启动的时候是在m0中启动,然后在执行proc.go main函数中有一个newm(sysmon, nil) 好像是新建一个m线程去执行sysmon监控,也就是说sysmon是不是独立一个线程运行?
但是我在测试调度的时候发现,如果gorouine里面做了一个无限循环,在用户main函数循环内创建多个goroutine(超过runtime.GOMAXPROCS个)发现在最终调用的时候就只要runtime.GOMAXPROCS个被执行,另外其他的goroutine并没有被执行,如果按照源代码中以及您的分析,应该会被sysmon进行抢占,把P和m剥离再创建新的m线程去执行其他的goroutine,但是从结果来看,好像sysmon并不是独立线程而是和某个m共用了,导致m如果被占用就无法做出抢占和调度,不知道是否是这个原因?代码如下:

package main
import (
	"fmt"
	"sync"
)

var wg sync.WaitGroup

func process(id int) {
	fmt.Printf("id: %d\n", id)
	for {
		// time.Sleep(time.Second)
	}
	// wg.Done()
}
func main() {
	runtime.GOMAXPROCS(4)
	// println(runtime.NumCPU())
	 wg.Add(1)
	 for i := 0; i < 10; i++ {
	 	go process(i)
	 }
	wg.Wait()
}

最终输出的只要 4个

@JayenLee JayenLee changed the title sysmon是不是在主线程运行的?主线程也参与goroutine调度 sysmon是不是和某个M共用?该M也进行执行G? Feb 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant