在线观看www成人影院-在线观看www日本免费网站-在线观看www视频-在线观看操-欧美18在线-欧美1级

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

golang的調(diào)度模型-GPM 模型的源碼結(jié)構(gòu)

Linux愛(ài)好者 ? 來(lái)源:博客園 ? 作者:九卷 ? 2021-07-06 11:55 ? 次閱讀

【導(dǎo)讀】GMP 模型是讓 go 語(yǔ)言輕量快速高效的重要調(diào)度模型,本文從 GMP 源碼出發(fā)直觀地解析了這一模型。

這篇文章就來(lái)看看 golang 的調(diào)度模型-GPM 模型的源碼結(jié)構(gòu)。

Go 版本:go1.13.9

M 結(jié)構(gòu)體

M 結(jié)構(gòu)體是 OS 線程的一個(gè)抽象,主要負(fù)責(zé)結(jié)合 P 運(yùn)行 G。它里面有很多字段,差不多有 60 個(gè)字段,我們看看里面主要的字段意思。/src/runtime/runtime2.go

Copytype m struct {

// 系統(tǒng)管理的一個(gè) g,執(zhí)行調(diào)度代碼時(shí)使用的。比如執(zhí)行用戶的 goroutine 時(shí),就需要把把用戶

// 的棧信息換到內(nèi)核線程的棧,以便能夠執(zhí)行用戶 goroutine

g0 *g // goroutine with scheduling stack

morebuf gobuf // gobuf arg to morestack

divmod uint32 // div/mod denominator for arm - known to liblink

// Fields not known to debuggers.

procid uint64 // for debuggers, but offset not hard-coded

//處理 signal 的 g

gsignal *g // signal-handling g

goSigStack gsignalStack // Go-allocated signal handling stack

sigmask sigset // storage for saved signal mask

//線程的本地存儲(chǔ) TLS,這里就是為什么 OS 線程能運(yùn)行 M 關(guān)鍵地方

tls [6]uintptr // thread-local storage (for x86 extern register)

//go 關(guān)鍵字運(yùn)行的函數(shù)

mstartfn func()

//當(dāng)前運(yùn)行的用戶 goroutine 的 g 結(jié)構(gòu)體對(duì)象

curg *g // current running goroutine

caughtsig guintptr // goroutine running during fatal signal

//當(dāng)前工作線程綁定的 P,如果沒(méi)有就為 nil

p puintptr // attached p for executing go code (nil if not executing go code)

//暫存與當(dāng)前 M 潛在關(guān)聯(lián)的 P

nextp puintptr

//M 之前調(diào)用的 P

oldp puintptr // the p that was attached before executing a syscall

id int64

mallocing int32

throwing int32

//當(dāng)前 M 是否關(guān)閉搶占式調(diào)度

preemptoff string // if != “”, keep curg running on this m

locks int32

dying int32

profilehz int32

//M 的自旋狀態(tài),為 true 時(shí) M 處于自旋狀態(tài),正在從其他線程偷 G; 為 false,休眠狀態(tài)

spinning bool // m is out of work and is actively looking for work

blocked bool // m is blocked on a note

newSigstack bool // minit on C thread called sigaltstack

printlock int8

incgo bool // m is executing a cgo call

freeWait uint32 // if == 0, safe to free g0 and delete m (atomic)

fastrand [2]uint32

needextram bool

traceback uint8

ncgocall uint64 // number of cgo calls in total

ncgo int32 // number of cgo calls currently in progress

cgoCallersUse uint32 // if non-zero, cgoCallers in use temporarily

cgoCallers *cgoCallers // cgo traceback if crashing in cgo call

//沒(méi)有 goroutine 運(yùn)行時(shí),工作線程睡眠

//通過(guò)這個(gè)來(lái)喚醒工作線程

park note // 休眠鎖

//記錄所有工作線程的鏈表

alllink *m // on allm

schedlink muintptr

//當(dāng)前線程內(nèi)存分配的本地緩存

mcache *mcache

//當(dāng)前 M 鎖定的 G,

lockedg guintptr

createstack [32]uintptr // stack that created this thread.

lockedExt uint32 // tracking for external LockOSThread

lockedInt uint32 // tracking for internal lockOSThread

nextwaitm muintptr // next m waiting for lock

waitunlockf func(*g, unsafe.Pointer) bool

waitlock unsafe.Pointer

waittraceev byte

waittraceskip int

startingtrace bool

syscalltick uint32

//操作系統(tǒng)線程 id

thread uintptr // thread handle

freelink *m // on sched.freem

// these are here because they are too large to be on the stack

// of low-level NOSPLIT functions.

libcall libcall

libcallpc uintptr // for cpu profiler

libcallsp uintptr

libcallg guintptr

syscall libcall // stores syscall parameters on windows

vdsoSP uintptr // SP for traceback while in VDSO call (0 if not in call)

vdsoPC uintptr // PC for traceback while in VDSO call

dlogPerM

mOS

}

看看幾個(gè)比較重要的字段:g0:用于執(zhí)行調(diào)度器的 g0gsignal:用于信號(hào)處理tls:線程本地存儲(chǔ)的 tlsp:goroutine 綁定的本地資源

P 結(jié)構(gòu)體

一個(gè) M 要運(yùn)行,必須綁定 P 才能運(yùn)行 goroutine,M 阻塞時(shí),P 會(huì)被傳給其他 M。

/src/runtime/runtime2.go

Copytype p struct {

//allp 中的索引

id int32

//p 的狀態(tài)

status uint32 // one of pidle/prunning/。。.

link puintptr

schedtick uint32 // incremented on every scheduler call-》每次 scheduler 調(diào)用+1

syscalltick uint32 // incremented on every system call-》每次系統(tǒng)調(diào)用+1

sysmontick sysmontick // last tick observed by sysmon

//指向綁定的 m,如果 p 是 idle 的話,那這個(gè)指針是 nil

m muintptr // back-link to associated m (nil if idle)

mcache *mcache

raceprocctx uintptr

//不同大小可用 defer 結(jié)構(gòu)池

deferpool [5][]*_defer // pool of available defer structs of different sizes (see panic.go)

deferpoolbuf [5][32]*_defer

// Cache of goroutine ids, amortizes accesses to runtime·sched.goidgen.

goidcache uint64

goidcacheend uint64

//本地運(yùn)行隊(duì)列,可以無(wú)鎖訪問(wèn)

// Queue of runnable goroutines. Accessed without lock.

runqhead uint32 //隊(duì)列頭

runqtail uint32 //隊(duì)列尾

//數(shù)組實(shí)現(xiàn)的循環(huán)隊(duì)列

runq [256]guintptr

// runnext, if non-nil, is a runnable G that was ready‘d by

// the current G and should be run next instead of what’s in

// runq if there‘s time remaining in the running G’s time

// slice. It will inherit the time left in the current time

// slice. If a set of goroutines is locked in a

// communicate-and-wait pattern, this schedules that set as a

// unit and eliminates the (potentially large) scheduling

// latency that otherwise arises from adding the ready‘d

// goroutines to the end of the run queue.

// runnext 非空時(shí),代表的是一個(gè) runnable 狀態(tài)的 G,

//這個(gè) G 被 當(dāng)前 G 修改為 ready 狀態(tài),相比 runq 中的 G 有更高的優(yōu)先級(jí)。

//如果當(dāng)前 G 還有剩余的可用時(shí)間,那么就應(yīng)該運(yùn)行這個(gè) G

//運(yùn)行之后,該 G 會(huì)繼承當(dāng)前 G 的剩余時(shí)間

runnext guintptr

// Available G’s (status == Gdead)

//空閑的 g

gFree struct {

gList

n int32

}

sudogcache []*sudog

sudogbuf [128]*sudog

tracebuf traceBufPtr

// traceSweep indicates the sweep events should be traced.

// This is used to defer the sweep start event until a span

// has actually been swept.

traceSweep bool

// traceSwept and traceReclaimed track the number of bytes

// swept and reclaimed by sweeping in the current sweep loop.

traceSwept, traceReclaimed uintptr

palloc persistentAlloc // per-P to avoid mutex

_ uint32 // Alignment for atomic fields below

// Per-P GC state

gcAssistTime int64 // Nanoseconds in assistAlloc

gcFractionalMarkTime int64 // Nanoseconds in fractional mark worker (atomic)

gcBgMarkWorker guintptr // (atomic)

gcMarkWorkerMode gcMarkWorkerMode

// gcMarkWorkerStartTime is the nanotime() at which this mark

// worker started.

gcMarkWorkerStartTime int64

// gcw is this P‘s GC work buffer cache. The work buffer is

// filled by write barriers, drained by mutator assists, and

// disposed on certain GC state transitions.

gcw gcWork

// wbBuf is this P’s GC write barrier buffer.

//

// TODO: Consider caching this in the running G.

wbBuf wbBuf

runSafePointFn uint32 // if 1, run sched.safePointFn at next safe point

pad cpu.CacheLinePad

}

其他的一些字段就是 gc,trace,debug 信息

G 結(jié)構(gòu)體

G 就是 goroutine。主要保存 goroutine 的所有信息以及棧信息,gobuf 結(jié)構(gòu)體:cpu 里的寄存器信息,以便在輪到本 goroutine 執(zhí)行時(shí),知道從哪里開始執(zhí)行。

/src/runtime/runtime2.go

Copytype stack struct {

lo uintptr //棧頂,指向內(nèi)存低地址

hi uintptr //棧底,指向內(nèi)存搞地址

}

type g struct {

// Stack parameters.

// stack describes the actual stack memory: [stack.lo, stack.hi)。

// stackguard0 is the stack pointer compared in the Go stack growth prologue.

// It is stack.lo+StackGuard normally, but can be StackPreempt to trigger a preemption.

// stackguard1 is the stack pointer compared in the C stack growth prologue.

// It is stack.lo+StackGuard on g0 and gsignal stacks.

// It is ~0 on other goroutine stacks, to trigger a call to morestackc (and crash)。

// 記錄該 goroutine 使用的棧

stack stack // offset known to runtime/cgo

//下面兩個(gè)成員用于棧溢出檢查,實(shí)現(xiàn)棧的自動(dòng)伸縮,搶占調(diào)度也會(huì)用到 stackguard0

stackguard0 uintptr // offset known to liblink

stackguard1 uintptr // offset known to liblink

_panic *_panic // innermost panic - offset known to liblink

_defer *_defer // innermost defer

// 此 goroutine 正在被哪個(gè)工作線程執(zhí)行

m *m // current m; offset known to arm liblink

//這個(gè)字段跟調(diào)度切換有關(guān),G 切換時(shí)用來(lái)保存上下文,保存什么,看下面 gobuf 結(jié)構(gòu)體

sched gobuf

syscallsp uintptr // if status==Gsyscall, syscallsp = sched.sp to use during gc

syscallpc uintptr // if status==Gsyscall, syscallpc = sched.pc to use during gc

stktopsp uintptr // expected sp at top of stack, to check in traceback

param unsafe.Pointer // passed parameter on wakeup,wakeup 喚醒時(shí)傳遞的參數(shù)

// 狀態(tài) Gidle,Grunnable,Grunning,Gsyscall,Gwaiting,Gdead

atomicstatus uint32

stackLock uint32 // sigprof/scang lock; TODO: fold in to atomicstatus

goid int64

//schedlink 字段指向全局運(yùn)行隊(duì)列中的下一個(gè) g,

//所有位于全局運(yùn)行隊(duì)列中的 g 形成一個(gè)鏈表

schedlink guintptr

waitsince int64 // approx time when the g become blocked

waitreason waitReason // if status==Gwaiting,g 被阻塞的原因

//搶占信號(hào),stackguard0 = stackpreempt,如果需要搶占調(diào)度,設(shè)置 preempt 為 true

preempt bool // preemption signal, duplicates stackguard0 = stackpreempt

paniconfault bool // panic (instead of crash) on unexpected fault address

preemptscan bool // preempted g does scan for gc

gcscandone bool // g has scanned stack; protected by _Gscan bit in status

gcscanvalid bool // false at start of gc cycle, true if G has not run since last scan; TODO: remove?

throwsplit bool // must not split stack

raceignore int8 // ignore race detection events

sysblocktraced bool // StartTrace has emitted EvGoInSyscall about this goroutine

sysexitticks int64 // cputicks when syscall has returned (for tracing)

traceseq uint64 // trace event sequencer

tracelastp puintptr // last P emitted an event for this goroutine

// 如果調(diào)用了 LockOsThread,那么這個(gè) g 會(huì)綁定到某個(gè) m 上

lockedm muintptr

sig uint32

writebuf []byte

sigcode0 uintptr

sigcode1 uintptr

sigpc uintptr

// 創(chuàng)建這個(gè) goroutine 的 go 表達(dá)式的 pc

gopc uintptr // pc of go statement that created this goroutine

ancestors *[]ancestorInfo // ancestor information goroutine(s) that created this goroutine (only used if debug.tracebackancestors)

startpc uintptr // pc of goroutine function

racectx uintptr

waiting *sudog // sudog structures this g is waiting on (that have a valid elem ptr); in lock order

cgoCtxt []uintptr // cgo traceback context

labels unsafe.Pointer // profiler labels

timer *timer // cached timer for time.Sleep, 為 time.Sleep 緩存的計(jì)時(shí)器

selectDone uint32 // are we participating in a select and did someone win the race?

// Per-G GC state

// gcAssistBytes is this G‘s GC assist credit in terms of

// bytes allocated. If this is positive, then the G has credit

// to allocate gcAssistBytes bytes without assisting. If this

// is negative, then the G must correct this by performing

// scan work. We track this in bytes to make it fast to update

// and check for debt in the malloc hot path. The assist ratio

// determines how this corresponds to scan work debt.

gcAssistBytes int64

}

gobuf

gobuf 結(jié)構(gòu)體用于保存 goroutine 的調(diào)度信息,主要包括 CPU 的幾個(gè)寄存器的值。

/src/runtime/runtime2.go

Copytype gobuf struct {

// The offsets of sp, pc, and g are known to (hard-coded in) libmach.

//

// ctxt is unusual with respect to GC: it may be a

// heap-allocated funcval, so GC needs to track it, but it

// needs to be set and cleared from assembly, where it’s

// difficult to have write barriers. However, ctxt is really a

// saved, live register, and we only ever exchange it between

// the real register and the gobuf. Hence, we treat it as a

// root during stack scanning, which means assembly that saves

// and restores it doesn‘t need write barriers. It’s still

// typed as a pointer so that any other writes from Go get

// write barriers.

sp uintptr // 保存 CPU 的 rsp 寄存器的值

pc uintptr // 保存 CPU 的 rip 寄存器的值

g guintptr // 記錄當(dāng)前這個(gè) gobuf 對(duì)象屬于哪個(gè) goroutine

ctxt unsafe.Pointer

//保存系統(tǒng)調(diào)用的返回值,因?yàn)閺南到y(tǒng)調(diào)用返回之后如果 p 被其它工作線程搶占,

//則這個(gè) goroutine 會(huì)被放入全局運(yùn)行隊(duì)列被其它工作線程調(diào)度,其它線程需要知道系統(tǒng)調(diào)用的返回值。

ret sys.Uintreg // 保存系統(tǒng)調(diào)用的返回值

lr uintptr

//保存 CPU 的 rip 寄存器的值

bp uintptr // for GOEXPERIMENT=framepointer

}

調(diào)度器 sched 結(jié)構(gòu)

所有的 gorouteine 都是被調(diào)度器調(diào)度運(yùn)行,調(diào)度器持有全局資源

sched

/src/runtime/runtime2.go

Copytype schedt struct {

// accessed atomically. keep at top to ensure alignment on 32-bit systems.

// 需以原子訪問(wèn)訪問(wèn)。

// 保持在 struct 頂部,以使其在 32 位系統(tǒng)上可以對(duì)齊

goidgen uint64

lastpoll uint64

lock mutex

// When increasing nmidle, nmidlelocked, nmsys, or nmfreed, be

// sure to call checkdead()。

//由空閑的工作線程組成的鏈表

midle muintptr // idle m‘s waiting for work

//空閑的工作線程的數(shù)量

nmidle int32 // number of idle m’s waiting for work

//空閑的且被 lock 的 m 計(jì)數(shù)

nmidlelocked int32 // number of locked m‘s waiting for work

//已經(jīng)創(chuàng)建的多個(gè) m,下一個(gè) m id

mnext int64 // number of m’s that have been created and next M ID

//被允許創(chuàng)建的最大 m 線程數(shù)量

maxmcount int32 // maximum number of m‘s allowed (or die)

nmsys int32 // number of system m’s not counted for deadlock

//累積空閑的 m 數(shù)量

nmfreed int64 // cumulative number of freed m‘s

//系統(tǒng) goroutine 的數(shù)量,自動(dòng)更新

ngsys uint32 // number of system goroutines; updated atomically

//由空閑的 p 結(jié)構(gòu)體對(duì)象組成的鏈表

pidle puintptr // idle p’s

//空閑的 p 結(jié)構(gòu)體對(duì)象的數(shù)量

npidle uint32

nmspinning uint32 // See “Worker thread parking/unparking” comment in proc.go.

// Global runnable queue.

//全局運(yùn)行隊(duì)列 G 隊(duì)列

runq gQueue //這個(gè)結(jié)構(gòu)體在 proc.go 里

//元素?cái)?shù)量

runqsize int32

// disable controls selective disabling of the scheduler.

//

// Use schedEnableUser to control this.

//

// disable is protected by sched.lock.

disable struct {

// user disables scheduling of user goroutines.

user bool

runnable gQueue // pending runnable Gs

n int32 // length of runnable

}

// Global cache of dead G‘s. 有效 dead G 全局緩存

gFree struct {

lock mutex

stack gList // Gs with stacks

noStack gList // Gs without stacks

n int32

}

// Central cache of sudog structs. dusog 結(jié)構(gòu)的集中緩存

sudoglock mutex

sudogcache *sudog

// Central pool of available defer structs of different sizes. 不同大小有效的 defer 結(jié)構(gòu)的池

deferlock mutex

deferpool [5]*_defer

// freem is the list of m’s waiting to be freed when their

// m.exited is set. Linked through m.freelink.

freem *m

gcwaiting uint32 // gc is waiting to run

stopwait int32

stopnote note

sysmonwait uint32

sysmonnote note

// safepointFn should be called on each P at the next GC

// safepoint if p.runSafePointFn is set.

safePointFn func(*p)

safePointWait int32

safePointNote note

profilehz int32 // cpu profiling rate

procresizetime int64 // nanotime() of last change to gomaxprocs

totaltime int64 // ∫gomaxprocs dt up to procresizetime

}

gQueue

/src/runtime/proc.go

Copytype gQueue struct {

head guintptr //隊(duì)列頭

tail guintptr //隊(duì)列尾

}

一些重要全局變量

/src/runtime/proc.go

Copym0 m //代表主線程

g0 g //m0 綁定的 g0,也就是 M 結(jié)構(gòu)體中 m0.g0=&g0

allgs []*g //保存所有的 g

/src/runtime/runtime2.go

Copyallm *m //所有的 m 構(gòu)成的一個(gè)鏈表,包括上面的 m0

allp []*p //保存所有的 p, len(allp) == gomaxprocs

sched schedt //調(diào)度器的結(jié)構(gòu)體,保存了調(diào)度器的各種信息

ncpu int32 //系統(tǒng) cpu 核的數(shù)量,程序啟動(dòng)時(shí)由 runtime 初始化

gomaxprocs int32 //p 的最大數(shù)量,默認(rèn)等于 ncpu,可以通過(guò) GOMAXPROCS 修改

在程序初始化時(shí),這些變量都會(huì)被初始化為 0 值,指針會(huì)被初始化為 nil 指針,切片初始化為 nil 切片,int 被初始化為數(shù)字 0,結(jié)構(gòu)體的所有成員變量按其本類型初始化為其類型的 0 值。

調(diào)度器初始化

調(diào)度器初始化有一個(gè)主要的函數(shù) schedinit(), 這個(gè)函數(shù)在 /src/runtime/proc.go 文件中。函數(shù)開頭還把初始化的順序給列出來(lái)了:

// The bootstrap sequence is://// call osinit// call schedinit// make & queue new G// call runtime·mstart//// The new G calls runtime·main.

Copyfunc schedinit() {

// raceinit must be the first call to race detector.

// In particular, it must be done before mallocinit below calls racemapshadow.

_g_ := getg() //getg() 在 src/runtime/stubs.go 中聲明,真正的代碼由編譯器生成

if raceenabled {

_g_.racectx, raceprocctx0 = raceinit()

}

//設(shè)置最大 M 的數(shù)量

sched.maxmcount = 10000

tracebackinit()

moduledataverify()

//初始化??臻g常用管理鏈表

stackinit()

mallocinit()

//初始化當(dāng)前 m

mcommoninit(_g_.m)

cpuinit() // must run before alginit

alginit() // maps must not be used before this call

modulesinit() // provides activeModules

typelinksinit() // uses maps, activeModules

itabsinit() // uses activeModules

msigsave(_g_.m)

initSigmask = _g_.m.sigmask

goargs()

goenvs()

parsedebugvars()

gcinit()

sched.lastpoll = uint64(nanotime())

// 把 p 數(shù)量從 1 調(diào)整到默認(rèn)的 CPU Core 數(shù)量

procs := ncpu

if n, ok := atoi32(gogetenv(“GOMAXPROCS”)); ok && n 》 0 {

procs = n

}

//調(diào)整 P 數(shù)量

//這里的 P 都是新建的,所以不返回有本地任務(wù)的 p

if procresize(procs) != nil {

throw(“unknown runnable goroutine during bootstrap”)

}

// For cgocheck 》 1, we turn on the write barrier at all times

// and check all pointer writes. We can‘t do this until after

// procresize because the write barrier needs a P.

if debug.cgocheck 》 1 {

writeBarrier.cgo = true

writeBarrier.enabled = true

for _, p := range allp {

p.wbBuf.reset()

}

}

if buildVersion == “” {

// Condition should never trigger. This code just serves

// to ensure runtime·buildVersion is kept in the resulting binary.

buildVersion = “unknown”

}

if len(modinfo) == 1 {

// Condition should never trigger. This code just serves

// to ensure runtime·modinfo is kept in the resulting binary.

modinfo = “”

}

}

開頭的這個(gè)函數(shù) getg(),跳轉(zhuǎn)到了 func getg() *g ,定義這么一個(gè)形式,什么意思?函數(shù)首先調(diào)用 getg() 函數(shù)獲取當(dāng)前正在運(yùn)行的 g,getg() 在 src/runtime/stubs.go 中聲明,真正的代碼由編譯器生成。

Copy// getg returns the pointer to the current g.// The compiler rewrites calls to this function into instructions// that fetch the g directly (from TLS or from the dedicated register).func getg() *g

注釋里也說(shuō)了,getg 返回當(dāng)前正在運(yùn)行的 goroutine 的指針,它會(huì)從 tls 里取出 tls[0],也就是當(dāng)前運(yùn)行的 goroutine 的地址。編譯器插入類似下面的代碼:

Copyget_tls(CX)

MOVQ g(CX), BX; // BX 存器里面現(xiàn)在放的是當(dāng)前 g 結(jié)構(gòu)體對(duì)象的地址

原來(lái)是這么個(gè)意思。

調(diào)度器初始化大致過(guò)程:M 初始化 --》 P 初始化 - -》 G 初始化mcommoninit Procresize newproc-------------------------------------------------------allm 池 allp 池 g.sched 執(zhí)行現(xiàn)場(chǎng)p.runq 調(diào)度隊(duì)列

M/P/G 初始化:mcommoninit、procresize、newproc,他們負(fù)責(zé) M 資源池(allm)、p 資源池(allp)、G 的運(yùn)行現(xiàn)場(chǎng)(g.sched) 以及調(diào)度隊(duì)列(p.runq)

調(diào)度循環(huán)

所有的工作初始化完成后,就要啟動(dòng)運(yùn)行器了。準(zhǔn)備工作做好了,就要啟動(dòng) mstart 了。這個(gè)工作在匯編語(yǔ)言中也可以看出來(lái)

/src/runtime/asm_amd64.s (在 linux 下)

CopyTEXT runtime·rt0_go(SB),NOSPLIT,$0

。。. 。。. 。。.

MOVL 16(SP), AX // copy argc

MOVL AX, 0(SP)

MOVQ 24(SP), AX // copy argv

MOVQ AX, 8(SP)

CALL runtime·args(SB)

CALL runtime·osinit(SB) //OS 初始化

CALL runtime·schedinit(SB) //調(diào)度器初始化

// create a new goroutine to start program

MOVQ $runtime·mainPC(SB), AX // entry

PUSHQ AX

PUSHQ $0 // arg size

CALL runtime·newproc(SB) // G 初始化

POPQ AX

// start this M , 啟動(dòng) M

CALL runtime·mstart(SB)

CALL runtime·abort(SB) // mstart should never return

RET

轉(zhuǎn)自:九卷

cnblogs.com/jiujuan/p/12977832.html

編輯:jq

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場(chǎng)。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問(wèn)題,請(qǐng)聯(lián)系本站處理。 舉報(bào)投訴
  • GMP
    GMP
    +關(guān)注

    關(guān)注

    0

    文章

    11

    瀏覽量

    9006
  • 源碼
    +關(guān)注

    關(guān)注

    8

    文章

    653

    瀏覽量

    29511
  • 代碼
    +關(guān)注

    關(guān)注

    30

    文章

    4837

    瀏覽量

    69122

原文標(biāo)題:深入理解 Go scheduler 調(diào)度器:GPM 源碼分析

文章出處:【微信號(hào):LinuxHub,微信公眾號(hào):Linux愛(ài)好者】歡迎添加關(guān)注!文章轉(zhuǎn)載請(qǐng)注明出處。

收藏 人收藏

    評(píng)論

    相關(guān)推薦

    【「大模型啟示錄」閱讀體驗(yàn)】對(duì)大模型更深入的認(rèn)知

    閱讀《大模型啟示錄》這本書,我得說(shuō),它徹底顛覆了我對(duì)大模型的理解。作為一個(gè)經(jīng)常用KIMI和豆包這類AI工具來(lái)完成作業(yè)、整理資料的大學(xué)生,我原以為大模型就是這些工具背后的技術(shù)。但這本書讓我意識(shí)到
    發(fā)表于 12-20 15:46

    AI模型部署邊緣設(shè)備的奇妙之旅:目標(biāo)檢測(cè)模型

    提升一倍 導(dǎo)出模型將后處理包含在網(wǎng)絡(luò)中,預(yù)測(cè)直接輸出 box 結(jié)果,無(wú)需二次開發(fā),遷移成本更低,端到端預(yù)測(cè)速度提升10%-20%。 2.2 模型結(jié)構(gòu) PP-PicoDet 網(wǎng)絡(luò)結(jié)構(gòu)圖如
    發(fā)表于 12-19 14:33

    【「大模型啟示錄」閱讀體驗(yàn)】如何在客服領(lǐng)域應(yīng)用大模型

    在客服領(lǐng)域是大模型落地場(chǎng)景中最多的,也是最容易實(shí)現(xiàn)的。本身客服領(lǐng)域的特點(diǎn)就是問(wèn)答形式,大模型接入難度低。今天跟隨《大模型啟示錄 》這本書,學(xué)習(xí)大模型在客服領(lǐng)域的改變。選擇大
    發(fā)表于 12-17 16:53

    原子結(jié)構(gòu)模型及特點(diǎn) 原子的組成及結(jié)構(gòu)解析

    原子是物質(zhì)的基本單位,由原子核和電子組成。原子結(jié)構(gòu)模型的發(fā)展經(jīng)歷了幾個(gè)階段,每個(gè)階段都有其特點(diǎn)和局限性。 一、原子結(jié)構(gòu)模型的演變 道爾頓模型(1803年) 英國(guó)化學(xué)家約翰·道爾頓提出了原子論,認(rèn)為
    的頭像 發(fā)表于 12-17 15:22 ?1315次閱讀

    【《大語(yǔ)言模型應(yīng)用指南》閱讀體驗(yàn)】+ 基礎(chǔ)知識(shí)學(xué)習(xí)

    收集海量的文本數(shù)據(jù)作為訓(xùn)練材料。這些數(shù)據(jù)集不僅包括語(yǔ)法結(jié)構(gòu)的學(xué)習(xí),還包括對(duì)語(yǔ)言的深層次理解,如文化背景、語(yǔ)境含義和情感色彩等。 自監(jiān)督學(xué)習(xí):模型采用自監(jiān)督學(xué)習(xí)策略,在大量無(wú)標(biāo)簽文本數(shù)據(jù)上學(xué)
    發(fā)表于 08-02 11:03

    多層感知機(jī)模型結(jié)構(gòu)

    多層感知機(jī)(MLP,Multilayer Perceptron)是一種基本且廣泛應(yīng)用的人工神經(jīng)網(wǎng)絡(luò)模型,其結(jié)構(gòu)由多個(gè)層次組成,包括輸入層、一個(gè)或多個(gè)隱藏層以及輸出層。MLP以其強(qiáng)大的非線性映射能力
    的頭像 發(fā)表于 07-11 17:57 ?1782次閱讀

    LLM模型和LMM模型的區(qū)別

    在重復(fù)測(cè)量或分層數(shù)據(jù)中。 LMM(線性混合效應(yīng)模型)是一種特殊類型的線性混合模型,它包括固定效應(yīng)和隨機(jī)效應(yīng)。它通常用于分析具有多個(gè)層次的數(shù)據(jù)結(jié)構(gòu),例如在多層次或分組數(shù)據(jù)中。 固定效應(yīng)與隨機(jī)效應(yīng): 在LLM中,固定效應(yīng)是指在整個(gè)研
    的頭像 發(fā)表于 07-09 09:57 ?1278次閱讀

    大語(yǔ)言模型:原理與工程時(shí)間+小白初識(shí)大語(yǔ)言模型

    解鎖 我理解的是基于深度學(xué)習(xí),需要訓(xùn)練各種數(shù)據(jù)知識(shí)最后生成自己的的語(yǔ)言理解和能力的交互模型。 對(duì)于常說(shuō)的RNN是處理短序列的數(shù)據(jù)時(shí)表現(xiàn)出色,耳真正厲害的是Transformer,此框架被推出后直接
    發(fā)表于 05-12 23:57

    【大語(yǔ)言模型:原理與工程實(shí)踐】大語(yǔ)言模型的應(yīng)用

    ,它通過(guò)抽象思考和邏輯推理,協(xié)助我們應(yīng)對(duì)復(fù)雜的決策。 相應(yīng)地,我們?cè)O(shè)計(jì)了兩類任務(wù)來(lái)檢驗(yàn)大語(yǔ)言模型的能力。一類是感性的、無(wú)需理性能力的任務(wù),類似于人類的系統(tǒng)1,如情感分析和抽取式問(wèn)答等。大語(yǔ)言模型在這
    發(fā)表于 05-07 17:21

    【大語(yǔ)言模型:原理與工程實(shí)踐】大語(yǔ)言模型的評(píng)測(cè)

    :翻譯準(zhǔn)確性、文本流暢度和語(yǔ)言覆蓋范圍。翻譯準(zhǔn)確性評(píng)估模型是否能準(zhǔn)確傳達(dá)原文的意思,包括詞匯、語(yǔ)法和句子結(jié)構(gòu)的準(zhǔn)確性;文本流暢度則衡量翻譯結(jié)果是否自然、通順;語(yǔ)言覆蓋范圍則量化模型能夠處理和翻譯
    發(fā)表于 05-07 17:12

    【大語(yǔ)言模型:原理與工程實(shí)踐】大語(yǔ)言模型的預(yù)訓(xùn)練

    具有以下三個(gè)非常顯著的特點(diǎn),一個(gè)就是模型參數(shù)規(guī)模更大,訓(xùn)練數(shù)據(jù)更多。當(dāng)然,對(duì)計(jì)算資源的要求也會(huì)更高。 構(gòu)建強(qiáng)大的語(yǔ)言模型時(shí),模型的選型至關(guān)重要,涉及模型的基本架構(gòu),包括
    發(fā)表于 05-07 17:10

    【大語(yǔ)言模型:原理與工程實(shí)踐】大語(yǔ)言模型的基礎(chǔ)技術(shù)

    全面剖析大語(yǔ)言模型的核心技術(shù)與基礎(chǔ)知識(shí)。首先,概述自然語(yǔ)言的基本表示,這是理解大語(yǔ)言模型技術(shù)的前提。接著,詳細(xì)介紹自然語(yǔ)言處理預(yù)訓(xùn)練的經(jīng)典結(jié)構(gòu)Transformer,以及其工作原理,為構(gòu)建大語(yǔ)言
    發(fā)表于 05-05 12:17

    【大語(yǔ)言模型:原理與工程實(shí)踐】揭開大語(yǔ)言模型的面紗

    維基百科、網(wǎng)頁(yè)內(nèi)容和書籍等,不僅掌握了語(yǔ)言的語(yǔ)法、語(yǔ)義和上下文信息,還能生成結(jié)構(gòu)連貫、語(yǔ)義合理的句子和段落。大語(yǔ)言模型的一個(gè)顯著特點(diǎn)是其龐大的參數(shù)量,已達(dá)數(shù)億甚至數(shù)十億級(jí)別。這種規(guī)模賦予模型強(qiáng)大的表示和學(xué)習(xí)
    發(fā)表于 05-04 23:55

    【大語(yǔ)言模型:原理與工程實(shí)踐】探索《大語(yǔ)言模型原理與工程實(shí)踐》

    《大語(yǔ)言模型》是一本深入探討人工智能領(lǐng)域中語(yǔ)言模型的著作。作者通過(guò)對(duì)語(yǔ)言模型的基本概念、基礎(chǔ)技術(shù)、應(yīng)用場(chǎng)景分析,為讀者揭開了這一領(lǐng)域的神秘面紗。本書不僅深入討論了語(yǔ)言模型的理論基礎(chǔ),還
    發(fā)表于 04-30 15:35

    Stage 模型深入解讀

    設(shè)備的遷移和協(xié)同機(jī)制。本文為大家詳細(xì)介紹 Stage 模型。 一、Stage 模型概念 應(yīng)用開發(fā)模型是運(yùn)行在不同 OS 上的抽象結(jié)構(gòu)。OS 通過(guò)這種抽象
    的頭像 發(fā)表于 02-18 09:28 ?1279次閱讀
    Stage <b class='flag-5'>模型</b>深入解讀
    主站蜘蛛池模板: 成人的天堂视频一区二区三区 | 亚洲youjizz| 磁力bt种子搜索在线 | 四虎影院在线播放 | 色多多·com 色多多18免费观看 色多多a | 午夜久久久久久亚洲国产精品 | 香蕉久久久久久狠狠色 | 色综合久久88 | 一级特黄性生活大片免费观看 | 26uuu另类欧美亚洲曰本 | 激情5月婷婷 | 成在线人视频免费视频 | www我要色综合com | 性欧美xxxx| 日本三级强在线观看 | 国模私拍在线观看 | 久草老司机 | 亚洲热热久久九九精品 | 中国一级生活片 | 日韩精品系列产品 | 午夜视频福利在线 | 国模精品 | 国产女人在线观看 | 免费看你懂的 | 男男憋尿play按小腹 | 天天摸天天草 | 模特精品视频一区 | 亚洲日本在线观看视频 | 四虎一影院区永久精品 | 午夜影院性 | 失禁h啪肉尿出来高h受 | ts人妖另类国产 | 亚洲一二三区在线观看 | 人人艹在线 | 色噜噜人体337p人体 | 亚洲精品在线视频 | 性视频网 | 欧美一级做一级做片性十三 | 欧美国产一区二区二区 | 黄色成人毛片 | 天天做天天爰夜夜爽 |