1
0
mirror of https://github.com/golang/go synced 2024-11-23 16:20:04 -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:
Matthew Dempsky 2015-11-12 14:26:19 -08:00
parent c83c806535
commit dbdd8c2c94
9 changed files with 9 additions and 21 deletions

View File

@ -78,9 +78,8 @@ func goenvs() {
// May run with m.p==nil, so write barriers are not allowed. // May run with m.p==nil, so write barriers are not allowed.
//go:nowritebarrier //go:nowritebarrier
func newosproc(mp *m, stk unsafe.Pointer) { func newosproc(mp *m, stk unsafe.Pointer) {
mp.tls[0] = uintptr(mp.id) // so 386 asm can find it
if false { 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 var oset uint32

View File

@ -74,7 +74,7 @@ func lwp_start(uintptr)
//go:nowritebarrier //go:nowritebarrier
func newosproc(mp *m, stk unsafe.Pointer) { func newosproc(mp *m, stk unsafe.Pointer) {
if false { 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 var oset sigset
@ -88,8 +88,6 @@ func newosproc(mp *m, stk unsafe.Pointer) {
tid2: nil, tid2: nil,
} }
mp.tls[0] = uintptr(mp.id) // XXX so 386 asm can find it
lwp_create(&params) lwp_create(&params)
sigprocmask(_SIG_SETMASK, &oset, nil) sigprocmask(_SIG_SETMASK, &oset, nil)
} }

View File

@ -73,7 +73,7 @@ func thr_start()
//go:nowritebarrier //go:nowritebarrier
func newosproc(mp *m, stk unsafe.Pointer) { func newosproc(mp *m, stk unsafe.Pointer) {
if false { 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 // 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_base: unsafe.Pointer(&mp.tls[0]),
tls_size: unsafe.Sizeof(mp.tls), tls_size: unsafe.Sizeof(mp.tls),
} }
mp.tls[0] = uintptr(mp.id) // so 386 asm can find it
var oset sigset var oset sigset
sigprocmask(_SIG_SETMASK, &sigset_all, &oset) sigprocmask(_SIG_SETMASK, &sigset_all, &oset)

View File

@ -133,9 +133,8 @@ func newosproc(mp *m, stk unsafe.Pointer) {
/* /*
* note: strace gets confused if we use CLONE_PTRACE here. * note: strace gets confused if we use CLONE_PTRACE here.
*/ */
mp.tls[0] = uintptr(mp.id) // so 386 asm can find it
if false { 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 // Disable signals during clone, so that the new thread starts

View File

@ -95,11 +95,9 @@ func semawakeup(mp *m) {
//go:nowritebarrier //go:nowritebarrier
func newosproc(mp *m, stk unsafe.Pointer) { func newosproc(mp *m, stk unsafe.Pointer) {
if false { 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 var uc ucontextt
getcontext(unsafe.Pointer(&uc)) getcontext(unsafe.Pointer(&uc))

View File

@ -105,11 +105,9 @@ func semawakeup(mp *m) {
//go:nowritebarrier //go:nowritebarrier
func newosproc(mp *m, stk unsafe.Pointer) { func newosproc(mp *m, stk unsafe.Pointer) {
if false { 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{ param := tforkt{
tf_tcb: unsafe.Pointer(&mp.tls[0]), tf_tcb: unsafe.Pointer(&mp.tls[0]),
tf_tid: (*int32)(unsafe.Pointer(&mp.procid)), tf_tid: (*int32)(unsafe.Pointer(&mp.procid)),

View File

@ -361,10 +361,8 @@ TEXT runtime·bsdthread_create(SB),NOSPLIT,$32
// SP = stack - C_32_STK_ALIGN // SP = stack - C_32_STK_ALIGN
TEXT runtime·bsdthread_start(SB),NOSPLIT,$0 TEXT runtime·bsdthread_start(SB),NOSPLIT,$0
// set up ldt 7+id to point at m->tls. // 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 LEAL m_tls(DX), BP
MOVL 0(BP), DI MOVL m_id(DX), DI
ADDL $7, DI // m0 is LDT#7. count up. ADDL $7, DI // m0 is LDT#7. count up.
// setldt(tls#, &tls, sizeof tls) // setldt(tls#, &tls, sizeof tls)
PUSHAL // save registers PUSHAL // save registers

View File

@ -25,7 +25,7 @@ TEXT runtime·thr_start(SB),NOSPLIT,$0
MOVL mm+0(FP), AX MOVL mm+0(FP), AX
MOVL m_g0(AX), BX MOVL m_g0(AX), BX
LEAL m_tls(AX), BP LEAL m_tls(AX), BP
MOVL 0(BP), DI MOVL m_id(AX), DI
ADDL $7, DI ADDL $7, DI
PUSHAL PUSHAL
PUSHL $32 PUSHL $32

View File

@ -334,9 +334,8 @@ TEXT runtime·clone(SB),NOSPLIT,$0
MOVL AX, m_procid(BX) // save tid as m->procid MOVL AX, m_procid(BX) // save tid as m->procid
// set up ldt 7+id to point at m->tls. // set up ldt 7+id to point at m->tls.
// newosproc left the id in tls[0].
LEAL m_tls(BX), BP LEAL m_tls(BX), BP
MOVL 0(BP), DI MOVL m_id(BX), DI
ADDL $7, DI // m0 is LDT#7. count up. ADDL $7, DI // m0 is LDT#7. count up.
// setldt(tls#, &tls, sizeof tls) // setldt(tls#, &tls, sizeof tls)
PUSHAL // save registers PUSHAL // save registers