去调度程序填充P的本地运行队列?

看看这张来自 morsmachine.dk/go-scheduler </ p>

”在此处输入图片描述“ </ p>

灰色列表是P的本地运行队列</ em>。如果此队列为空,则将使用全局运行队列</ em>中的go例程填充它们。</ p>
\ n

问题是,谁填补了P的本地运行队列</ em>? </ p>

调度程序,没有同步或每个 P </ strong>都自己完成(互斥)? </ p>

P.S。 这篇文章省略了此信息。</ p>
</ div>

展开原文

原文

Look at this well known image taken from morsmachine.dk/go-scheduler

enter image description here

The gray lists are local runqueues of P. If this queue get empty they will be filled with go routines from the global runqueue.

The Question is, who fills the local runqueue of P?

Scheduler, without synchronisation or every P do it for himself (mutex)?

P.S. The article omits this information.

1个回答

All of this is taken from src/runtime/proc1.go:

Function schedule (the scheduler) calls findrunnable which attempts to steal a G from another P. If that fails, it'll return a G from the global run queue. That G is then executed on the "current" M.

In addition, schedule checks the global run queue occasionally "for fairness":

// Check the global runnable queue once in a while to ensure fairness.
// Otherwise two goroutines can completely occupy the local runqueue
// by constantly respawning each other.

In all of that, only one lock is involved, which is lock(&sched.lock).

doufeng2877
doufeng2877 代码有点难读(因为它是自动翻译的C),但是是的,这就是它的工作方式。
大约 5 年之前 回复
douxu5233
douxu5233 好的,这意味着每个M都会执行此操作,但是并不会填充本地运行队列,它只需要执行一个就可以了。 因此,本地运行队列在清空后再也不会填充。 如果我们有32个CPU,因此有32 M,它们将通过互斥锁(锁)同步。 对?
大约 5 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐