mirror of
https://github.com/golang/go
synced 2024-11-23 14:40:02 -07:00
runtime: update newosproc asm to access m.id directly
darwin/386, freebsd/386, and linux/386 use a setldt system call to setup each M's thread-local storage area, and they need access to the M's id for this. The current code copies m.id into m.tls[0] (and this logic has been cargo culted to OSes like NetBSD and OpenBSD, which don't even need m.id to configure TLS), and then the 386 assembly loads m.tls[0]... but since the assembly code already has a pointer to the M, it might as well just load m.id directly. Change-Id: I1a7278f1ec8ebda8d1de3aa3a61993070e3a8cdf Reviewed-on: https://go-review.googlesource.com/16881 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
c83c806535
commit
dbdd8c2c94
@ -78,9 +78,8 @@ func goenvs() {
|
||||
// May run with m.p==nil, so write barriers are not allowed.
|
||||
//go:nowritebarrier
|
||||
func newosproc(mp *m, stk unsafe.Pointer) {
|
||||
mp.tls[0] = uintptr(mp.id) // so 386 asm can find it
|
||||
if false {
|
||||
print("newosproc stk=", stk, " m=", mp, " g=", mp.g0, " id=", mp.id, "/", int(mp.tls[0]), " ostk=", &mp, "\n")
|
||||
print("newosproc stk=", stk, " m=", mp, " g=", mp.g0, " id=", mp.id, " ostk=", &mp, "\n")
|
||||
}
|
||||
|
||||
var oset uint32
|
||||
|
@ -74,7 +74,7 @@ func lwp_start(uintptr)
|
||||
//go:nowritebarrier
|
||||
func newosproc(mp *m, stk unsafe.Pointer) {
|
||||
if false {
|
||||
print("newosproc stk=", stk, " m=", mp, " g=", mp.g0, " lwp_start=", funcPC(lwp_start), " id=", mp.id, "/", mp.tls[0], " ostk=", &mp, "\n")
|
||||
print("newosproc stk=", stk, " m=", mp, " g=", mp.g0, " lwp_start=", funcPC(lwp_start), " id=", mp.id, " ostk=", &mp, "\n")
|
||||
}
|
||||
|
||||
var oset sigset
|
||||
@ -88,8 +88,6 @@ func newosproc(mp *m, stk unsafe.Pointer) {
|
||||
tid2: nil,
|
||||
}
|
||||
|
||||
mp.tls[0] = uintptr(mp.id) // XXX so 386 asm can find it
|
||||
|
||||
lwp_create(¶ms)
|
||||
sigprocmask(_SIG_SETMASK, &oset, nil)
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ func thr_start()
|
||||
//go:nowritebarrier
|
||||
func newosproc(mp *m, stk unsafe.Pointer) {
|
||||
if false {
|
||||
print("newosproc stk=", stk, " m=", mp, " g=", mp.g0, " thr_start=", funcPC(thr_start), " id=", mp.id, "/", mp.tls[0], " ostk=", &mp, "\n")
|
||||
print("newosproc stk=", stk, " m=", mp, " g=", mp.g0, " thr_start=", funcPC(thr_start), " id=", mp.id, " ostk=", &mp, "\n")
|
||||
}
|
||||
|
||||
// NOTE(rsc): This code is confused. stackbase is the top of the stack
|
||||
@ -88,7 +88,6 @@ func newosproc(mp *m, stk unsafe.Pointer) {
|
||||
tls_base: unsafe.Pointer(&mp.tls[0]),
|
||||
tls_size: unsafe.Sizeof(mp.tls),
|
||||
}
|
||||
mp.tls[0] = uintptr(mp.id) // so 386 asm can find it
|
||||
|
||||
var oset sigset
|
||||
sigprocmask(_SIG_SETMASK, &sigset_all, &oset)
|
||||
|
@ -133,9 +133,8 @@ func newosproc(mp *m, stk unsafe.Pointer) {
|
||||
/*
|
||||
* note: strace gets confused if we use CLONE_PTRACE here.
|
||||
*/
|
||||
mp.tls[0] = uintptr(mp.id) // so 386 asm can find it
|
||||
if false {
|
||||
print("newosproc stk=", stk, " m=", mp, " g=", mp.g0, " clone=", funcPC(clone), " id=", mp.id, "/", mp.tls[0], " ostk=", &mp, "\n")
|
||||
print("newosproc stk=", stk, " m=", mp, " g=", mp.g0, " clone=", funcPC(clone), " id=", mp.id, " ostk=", &mp, "\n")
|
||||
}
|
||||
|
||||
// Disable signals during clone, so that the new thread starts
|
||||
|
@ -95,11 +95,9 @@ func semawakeup(mp *m) {
|
||||
//go:nowritebarrier
|
||||
func newosproc(mp *m, stk unsafe.Pointer) {
|
||||
if false {
|
||||
print("newosproc stk=", stk, " m=", mp, " g=", mp.g0, " id=", mp.id, "/", int32(mp.tls[0]), " ostk=", &mp, "\n")
|
||||
print("newosproc stk=", stk, " m=", mp, " g=", mp.g0, " id=", mp.id, " ostk=", &mp, "\n")
|
||||
}
|
||||
|
||||
mp.tls[0] = uintptr(mp.id) // so 386 asm can find it
|
||||
|
||||
var uc ucontextt
|
||||
getcontext(unsafe.Pointer(&uc))
|
||||
|
||||
|
@ -105,11 +105,9 @@ func semawakeup(mp *m) {
|
||||
//go:nowritebarrier
|
||||
func newosproc(mp *m, stk unsafe.Pointer) {
|
||||
if false {
|
||||
print("newosproc stk=", stk, " m=", mp, " g=", mp.g0, " id=", mp.id, "/", int32(mp.tls[0]), " ostk=", &mp, "\n")
|
||||
print("newosproc stk=", stk, " m=", mp, " g=", mp.g0, " id=", mp.id, " ostk=", &mp, "\n")
|
||||
}
|
||||
|
||||
mp.tls[0] = uintptr(mp.id) // so 386 asm can find it
|
||||
|
||||
param := tforkt{
|
||||
tf_tcb: unsafe.Pointer(&mp.tls[0]),
|
||||
tf_tid: (*int32)(unsafe.Pointer(&mp.procid)),
|
||||
|
@ -361,10 +361,8 @@ TEXT runtime·bsdthread_create(SB),NOSPLIT,$32
|
||||
// SP = stack - C_32_STK_ALIGN
|
||||
TEXT runtime·bsdthread_start(SB),NOSPLIT,$0
|
||||
// set up ldt 7+id to point at m->tls.
|
||||
// m->tls is at m+40. newosproc left
|
||||
// the m->id in tls[0].
|
||||
LEAL m_tls(DX), BP
|
||||
MOVL 0(BP), DI
|
||||
MOVL m_id(DX), DI
|
||||
ADDL $7, DI // m0 is LDT#7. count up.
|
||||
// setldt(tls#, &tls, sizeof tls)
|
||||
PUSHAL // save registers
|
||||
|
@ -25,7 +25,7 @@ TEXT runtime·thr_start(SB),NOSPLIT,$0
|
||||
MOVL mm+0(FP), AX
|
||||
MOVL m_g0(AX), BX
|
||||
LEAL m_tls(AX), BP
|
||||
MOVL 0(BP), DI
|
||||
MOVL m_id(AX), DI
|
||||
ADDL $7, DI
|
||||
PUSHAL
|
||||
PUSHL $32
|
||||
|
@ -334,9 +334,8 @@ TEXT runtime·clone(SB),NOSPLIT,$0
|
||||
MOVL AX, m_procid(BX) // save tid as m->procid
|
||||
|
||||
// set up ldt 7+id to point at m->tls.
|
||||
// newosproc left the id in tls[0].
|
||||
LEAL m_tls(BX), BP
|
||||
MOVL 0(BP), DI
|
||||
MOVL m_id(BX), DI
|
||||
ADDL $7, DI // m0 is LDT#7. count up.
|
||||
// setldt(tls#, &tls, sizeof tls)
|
||||
PUSHAL // save registers
|
||||
|
Loading…
Reference in New Issue
Block a user