Home | History | Annotate | only in /src/lib/libpthread/arch
History log of /src/lib/libpthread/arch
RevisionDateAuthorComments
 1.2 25-May-2023  riastradh libpthread: New pthread__smt_wait to put CPU in low power for spin.

This is now distinct from pthread__smt_pause, which is for spin lock
backoff with no paired wakeup.

On Arm, there is a single-bit event register per CPU, and there are two
instructions to manage it:

- wfe, wait for event -- if event register is clear, enter low power
mode and wait until event register is set; then exit low power mode
and clear event register

- sev, signal event -- sets event register on all CPUs (other
circumstances like interrupts also set the event register and cause
wfe to wake)

These can be used to reduce the power consumption of spinning for a
lock, but only if they are actually paired -- if there's no sev, wfe
might hang indefinitely. Currently only pthread_spin(3) actually
pairs them; the other lock primitives (internal lock, mutex, rwlock)
do not -- they have spin lock backoff loops, but no corresponding
wakeup to cancel a wfe.

It may be worthwhile to teach the other lock primitives to pair
wfe/sev, but that requires some performance measurement to verify
it's actually worthwhile. So for now, we just make sure not to use
wfe when there's no sev, and keep everything else the same -- this
should fix severe performance degredation in libpthread on Arm
without hurting anything else.

No change in the generated code on amd64 and i386. No change in the
generated code for pthread_spin.c on arm and aarch64 -- changes only
the generated code for pthread_lock.c, pthread_mutex.c, and
pthread_rwlock.c, as intended.

PR port-arm/57437

XXX pullup-10
 1.1 10-Aug-2014  matt branches: 1.1.4; 1.1.18; 1.1.28; 1.1.36;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.
 1.1.36.1 01-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #296):

lib/libpthread/arch/x86_64/pthread_md.h: revision 1.13
lib/libpthread/pthread_int.h: revision 1.110
lib/libpthread/pthread_int.h: revision 1.111
lib/libpthread/arch/i386/pthread_md.h: revision 1.21
lib/libpthread/arch/arm/pthread_md.h: revision 1.12
lib/libpthread/arch/arm/pthread_md.h: revision 1.13
lib/libpthread/pthread_spin.c: revision 1.11
lib/libpthread/arch/aarch64/pthread_md.h: revision 1.2

libpthread: Use __nothing, not /* nothing */, for empty macros.

No functional change intended -- just safer to do it this way in case
the macros are used in if branches or comma expressions.

PR port-arm/57437 (pthread__smt_pause/wake issue)

libpthread: New pthread__smt_wait to put CPU in low power for spin.

This is now distinct from pthread__smt_pause, which is for spin lock
backoff with no paired wakeup.

On Arm, there is a single-bit event register per CPU, and there are two
instructions to manage it:
- wfe, wait for event -- if event register is clear, enter low power
mode and wait until event register is set; then exit low power mode
and clear event register
- sev, signal event -- sets event register on all CPUs (other
circumstances like interrupts also set the event register and cause
wfe to wake)

These can be used to reduce the power consumption of spinning for a
lock, but only if they are actually paired -- if there's no sev, wfe
might hang indefinitely. Currently only pthread_spin(3) actually
pairs them; the other lock primitives (internal lock, mutex, rwlock)
do not -- they have spin lock backoff loops, but no corresponding
wakeup to cancel a wfe.

It may be worthwhile to teach the other lock primitives to pair
wfe/sev, but that requires some performance measurement to verify
it's actually worthwhile. So for now, we just make sure not to use
wfe when there's no sev, and keep everything else the same -- this
should fix severe performance degredation in libpthread on Arm
without hurting anything else.

No change in the generated code on amd64 and i386. No change in the
generated code for pthread_spin.c on arm and aarch64 -- changes only
the generated code for pthread_lock.c, pthread_mutex.c, and
pthread_rwlock.c, as intended.

PR port-arm/57437
 1.1.28.1 04-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #1700):

lib/libpthread/arch/x86_64/pthread_md.h: revision 1.13
lib/libpthread/pthread_int.h: revision 1.110
lib/libpthread/pthread_int.h: revision 1.111
lib/libpthread/arch/i386/pthread_md.h: revision 1.21
lib/libpthread/arch/arm/pthread_md.h: revision 1.12
lib/libpthread/arch/arm/pthread_md.h: revision 1.13
lib/libpthread/pthread_spin.c: revision 1.11
lib/libpthread/arch/aarch64/pthread_md.h: revision 1.2

libpthread: Use __nothing, not /* nothing */, for empty macros.

No functional change intended -- just safer to do it this way in case
the macros are used in if branches or comma expressions.
PR port-arm/57437 (pthread__smt_pause/wake issue)

libpthread: New pthread__smt_wait to put CPU in low power for spin.

This is now distinct from pthread__smt_pause, which is for spin lock
backoff with no paired wakeup.

On Arm, there is a single-bit event register per CPU, and there are two
instructions to manage it:
- wfe, wait for event -- if event register is clear, enter low power
mode and wait until event register is set; then exit low power mode
and clear event register
- sev, signal event -- sets event register on all CPUs (other
circumstances like interrupts also set the event register and cause
wfe to wake)

These can be used to reduce the power consumption of spinning for a
lock, but only if they are actually paired -- if there's no sev, wfe
might hang indefinitely. Currently only pthread_spin(3) actually
pairs them; the other lock primitives (internal lock, mutex, rwlock)
do not -- they have spin lock backoff loops, but no corresponding
wakeup to cancel a wfe.

It may be worthwhile to teach the other lock primitives to pair
wfe/sev, but that requires some performance measurement to verify
it's actually worthwhile. So for now, we just make sure not to use
wfe when there's no sev, and keep everything else the same -- this
should fix severe performance degredation in libpthread on Arm
without hurting anything else.

No change in the generated code on amd64 and i386. No change in the
generated code for pthread_spin.c on arm and aarch64 -- changes only
the generated code for pthread_lock.c, pthread_mutex.c, and
pthread_rwlock.c, as intended.
PR port-arm/57437
 1.1.18.1 04-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #1878):

lib/libpthread/arch/x86_64/pthread_md.h: revision 1.13
lib/libpthread/pthread_int.h: revision 1.110
lib/libpthread/pthread_int.h: revision 1.111
lib/libpthread/arch/i386/pthread_md.h: revision 1.21
lib/libpthread/arch/arm/pthread_md.h: revision 1.12
lib/libpthread/arch/arm/pthread_md.h: revision 1.13
lib/libpthread/pthread_spin.c: revision 1.11
lib/libpthread/arch/aarch64/pthread_md.h: revision 1.2

libpthread: Use __nothing, not /* nothing */, for empty macros.

No functional change intended -- just safer to do it this way in case
the macros are used in if branches or comma expressions.
PR port-arm/57437 (pthread__smt_pause/wake issue)

libpthread: New pthread__smt_wait to put CPU in low power for spin.

This is now distinct from pthread__smt_pause, which is for spin lock
backoff with no paired wakeup.

On Arm, there is a single-bit event register per CPU, and there are two
instructions to manage it:
- wfe, wait for event -- if event register is clear, enter low power
mode and wait until event register is set; then exit low power mode
and clear event register
- sev, signal event -- sets event register on all CPUs (other
circumstances like interrupts also set the event register and cause
wfe to wake)

These can be used to reduce the power consumption of spinning for a
lock, but only if they are actually paired -- if there's no sev, wfe
might hang indefinitely. Currently only pthread_spin(3) actually
pairs them; the other lock primitives (internal lock, mutex, rwlock)
do not -- they have spin lock backoff loops, but no corresponding
wakeup to cancel a wfe.

It may be worthwhile to teach the other lock primitives to pair
wfe/sev, but that requires some performance measurement to verify
it's actually worthwhile. So for now, we just make sure not to use
wfe when there's no sev, and keep everything else the same -- this
should fix severe performance degredation in libpthread on Arm
without hurting anything else.

No change in the generated code on amd64 and i386. No change in the
generated code for pthread_spin.c on arm and aarch64 -- changes only
the generated code for pthread_lock.c, pthread_mutex.c, and
pthread_rwlock.c, as intended.
PR port-arm/57437
 1.1.4.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.4.1 10-Aug-2014  tls file pthread_md.h was added on branch tls-maxphys on 2014-08-20 00:02:20 +0000
 1.5 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.4 28-Apr-2008  martin branches: 1.4.8;
Remove clause 3 and 4 from TNF licenses
 1.3 08-Oct-2007  skrll branches: 1.3.6;
Provide PTHREAD__ASM_RASOPS for alpha.

The gcc generated lock try RAS is broken as the store needs to be the last
instruction.
 1.2 18-Jan-2003  thorpej branches: 1.2.24;
Merge the nathanw_sa branch.
 1.1 25-Sep-2001  nathanw branches: 1.1.2;
file _context_u.S was initially added on branch nathanw_sa.
 1.1.2.3 14-Jan-2003  nathanw Save and restore process-unique value.
 1.1.2.2 17-Dec-2001  nathanw Update to work with Klaus's mcontext code.
Save and restore FP registers.
 1.1.2.1 25-Sep-2001  nathanw Alpha MD files for the pthread lib.
 1.2.24.1 06-Nov-2007  matt sync with HEAD
 1.3.6.1 18-May-2008  yamt sync with head.
 1.4.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.4.8.1 28-Apr-2008  martin file _context_u.S was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.8 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.7 28-Apr-2008  martin branches: 1.7.8;
Remove clause 3 and 4 from TNF licenses
 1.6 02-Mar-2007  ad branches: 1.6.12;
Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
 1.5 07-Sep-2003  cl Remove possible race condition in upcall recycling.
 1.4 17-Jul-2003  nathanw Adapt to structure name changes.
 1.3 26-Jun-2003  nathanw Remove PT_SLEEPUC and add PT_TRAPUC.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 25-Sep-2001  nathanw branches: 1.1.2;
file genassym.cf was initially added on branch nathanw_sa.
 1.1.2.3 14-Jan-2003  nathanw Save and restore process-unique value.
 1.1.2.2 17-Dec-2001  nathanw Update to work with Klaus's mcontext code.
 1.1.2.1 25-Sep-2001  nathanw Alpha MD files for the pthread lib.
 1.6.12.1 18-May-2008  yamt sync with head.
 1.7.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.7.8.1 28-Apr-2008  martin file genassym.cf was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.1 18-May-2009  njoly Restore PTHREAD__ASM_RASOPS for alpha (from _context_u.S), that was
lost in previous cleanup.

ok by ad@.
 1.1 22-Nov-2024  riastradh branches: 1.1.4;
libpthread: Fix expected symbols on alpha and hppa.

These have PTHREAD__ASM_RASOPS and define a different subset of
symbols which get exported. None of these pthread__ras_* and
pthread__lock_* symbols _should_ be exported but we can fix that in a
future revbump.

PR lib/58838: shared libraries in base should all have expsym lists
 1.1.4.2 02-Aug-2025  perseant Sync with HEAD
 1.1.4.1 22-Nov-2024  perseant file pthread_md.expsym was added on branch perseant-exfatfs on 2025-08-02 05:54:56 +0000
 1.7 25-Jan-2011  christos make pthread__sp unsigned long.
 1.6 16-May-2009  ad branches: 1.6.2;
Remove unused code that's confusing when using cscope/opengrok.
 1.5 28-Apr-2008  martin branches: 1.5.8;
Remove clause 3 and 4 from TNF licenses
 1.4 08-Oct-2007  skrll branches: 1.4.6;
Provide PTHREAD__ASM_RASOPS for alpha.

The gcc generated lock try RAS is broken as the store needs to be the last
instruction.
 1.3 24-Dec-2005  perry branches: 1.3.12;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 25-Sep-2001  nathanw branches: 1.1.2;
file pthread_md.h was initially added on branch nathanw_sa.
 1.1.2.7 16-Jan-2003  thorpej * Move the pthread_sigmask() prototype to <signal.h>.
* Don't include <signal.h> in <pthread.h>.
* Add code to the signal trampoline to convert from the ucontext
to a sigcontext, and back again (XXX though, only callee-save
regs for _UC_USER contexts).

This is necessary in order to support e.g. GCC's libjava, which depends
on the traditional Unix semantics of changes made to the sigcontext
being visible when the handler returns.
 1.1.2.6 06-Dec-2002  nathanw ucontext/sigcontext glue.
 1.1.2.5 22-Oct-2002  nathanw Define _INITCONTEXT_U_MD() to set the status register to a reasonable value.
 1.1.2.4 06-Aug-2002  nathanw Add struct reg/mcontext conversion glue.
 1.1.2.3 17-Dec-2001  nathanw Update to work with Klaus's mcontext code.
 1.1.2.2 14-Nov-2001  briggs Add pthread__uc_pc() to pthread_md.h instead of making assumptions about
the contents of the m.d. mcontext.
 1.1.2.1 25-Sep-2001  nathanw Alpha MD files for the pthread lib.
 1.3.12.1 06-Nov-2007  matt sync with HEAD
 1.4.6.1 18-May-2008  yamt sync with head.
 1.5.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.5.8.1 28-Apr-2008  martin file pthread_md.h was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.6.2.1 08-Feb-2011  bouyer Sync with HEAD
 1.6 02-Mar-2007  ad Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
 1.5 07-Sep-2003  cl Remove possible race condition in upcall recycling.
 1.4 26-Jun-2003  nathanw Adapt to pt_trapuc: change STACK_SWITCH to check for a value in pt_trapuc
and use it preferentially to a value in pt_uc, clearing it once on the new
stack. Move stores into pt_uc back to before the stack switch; storing
after the stack switch opened a one-instruction race condition where an upcall
that had just started a chain could be preempted again, and would bomb when
restarted due to its pt_uc not yet having been updated. Now that pt_trapuc
is what the upcall code writes to, it is safe to store to pt_uc before
switching stacks.

Remove obsolete pt_sleepuc code.
 1.3 12-Jun-2003  nathanw Two fixes:
* In switch-away cases, write PT_SWITCHTO last (after PT_SWITCHTOUC), so
that pthread__resolve_locks() doesn't see an empty SWITCHTOUC value. This
also permits pthread__resolve_locks() to use the presence of PT_SWITCHTO
as a sign that the thread has done all of its necessary chain work.

* Make the return-point of pthread__switch global and visible, so that its
address can be compared to the PC of a thread, again as a sign that its
chain-work is done.

(other architectures in progress, after they get the *previous* asm fix...)
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 25-Sep-2001  nathanw branches: 1.1.2;
file pthread_switch.S was initially added on branch nathanw_sa.
 1.1.2.3 13-Jan-2003  nathanw Rewrite pthread__switch() and adjust pthread__locked_switch() to
avoid storing the new saved-context pointer while still using the old
stack. This avoids a race condition with pthread__find_interrupted()
where a thread could lose its old state if it was interrupted in a
certain window in pthread__switch().
 1.1.2.2 17-Dec-2001  nathanw Update to work with Klaus's mcontext code.
 1.1.2.1 25-Sep-2001  nathanw Alpha MD files for the pthread lib.
 1.5 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.4 21-Aug-2004  rearnsha Use RET macro for returning.
 1.3 05-Apr-2003  bjh21 NetBSD/acorn26 has used APCS-32 for years, so unifdef -U__APCS_26__.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 16-Nov-2001  thorpej branches: 1.1.2;
file _context_u.S was initially added on branch nathanw_sa.
 1.1.2.8 27-Nov-2001  bjh21 In GETC(), rather than faking a CPSR, save the real one if we're can, and
zero otherwise (ie if we're on a 26-bit CPU). I suspect this isn't actually
necessary, but it's cheap, and it should make it easier for debuggers and
suchlike to work out what's going on.
 1.1.2.7 22-Nov-2001  bjh21 _UC_USER | _UC_CPU happens to be a valid ARM constant, so we can load
it in a single cycle.
 1.1.2.6 22-Nov-2001  thorpej In the GETC() macro, don't actually save r14 (lr) and r15 (pc).
r14 is caller-save, so we don't need to save it in the _REG_LR
slot. Instead, we save it in the _REG_PC slot so that when the
context is resumed, we end up at the insn after the call site.

Fixes the "cu6" test in Nathan's test suite. "cu1" - "cu5" also
function correctly (as they did before this change).
 1.1.2.5 21-Nov-2001  thorpej ome improvements, based on suggestions from Ben Harris:
* Don't need to save CPSR in GETC(), since it's a caller-saved
register. However, stuff a fake one (that indicates USR32 mode)
into the ucontext in case it is used later in a setcontext(2)
system call (as is done in one of Nathan's regression tests; this
last bit from me).
* Only restore CPSR if ! _UC_USER (i.e. context was created by
getcontext(2)).
* Determine at run-time if we're in USR26 or USR32 by forcing the Z
flag to be set and then comparing the PC portion of R15 to all of
R15 (if they're not equal, we're in 26-bit mode).
* Restore banked regs properly in 26-bit mode.

Plus one from me: Don't or _UC_USER | _UC_CPU into uc_flags; set uc_flags
to that value instead.
 1.1.2.4 20-Nov-2001  thorpej Clean up SAVE_FLAGS/RESTORE_FLAGS, and make sure to fetch the
flags from the correct place in the ucontext (not past the END
of the ucontext) in the SETC() macro.
 1.1.2.3 20-Nov-2001  thorpej Make sure to set _UC_CPU in _getcontext_u().
 1.1.2.2 18-Nov-2001  thorpej Note that we need to think about what to do regarding hard and
soft FP context.
 1.1.2.1 16-Nov-2001  thorpej First cut at machine-dependent pthread bits for ARM.
 1.8 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.7 02-Mar-2007  ad Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
 1.6 07-Sep-2003  cl Remove possible race condition in upcall recycling.
 1.5 17-Jul-2003  nathanw Adapt to structure name changes.
 1.4 26-Jun-2003  nathanw Remove PT_SLEEPUC and add PT_TRAPUC.
 1.3 13-Mar-2003  thorpej Include <sys/types> before <sys/lock.h>, shuffle <ucontext.h>.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 16-Nov-2001  thorpej branches: 1.1.2;
file genassym.cf was initially added on branch nathanw_sa.
 1.1.2.2 22-Nov-2001  thorpej Move the _REG_PC definition up with the other _REG_* definitions.
 1.1.2.1 16-Nov-2001  thorpej First cut at machine-dependent pthread bits for ARM.
 1.13 25-May-2023  riastradh libpthread: New pthread__smt_wait to put CPU in low power for spin.

This is now distinct from pthread__smt_pause, which is for spin lock
backoff with no paired wakeup.

On Arm, there is a single-bit event register per CPU, and there are two
instructions to manage it:

- wfe, wait for event -- if event register is clear, enter low power
mode and wait until event register is set; then exit low power mode
and clear event register

- sev, signal event -- sets event register on all CPUs (other
circumstances like interrupts also set the event register and cause
wfe to wake)

These can be used to reduce the power consumption of spinning for a
lock, but only if they are actually paired -- if there's no sev, wfe
might hang indefinitely. Currently only pthread_spin(3) actually
pairs them; the other lock primitives (internal lock, mutex, rwlock)
do not -- they have spin lock backoff loops, but no corresponding
wakeup to cancel a wfe.

It may be worthwhile to teach the other lock primitives to pair
wfe/sev, but that requires some performance measurement to verify
it's actually worthwhile. So for now, we just make sure not to use
wfe when there's no sev, and keep everything else the same -- this
should fix severe performance degredation in libpthread on Arm
without hurting anything else.

No change in the generated code on amd64 and i386. No change in the
generated code for pthread_spin.c on arm and aarch64 -- changes only
the generated code for pthread_lock.c, pthread_mutex.c, and
pthread_rwlock.c, as intended.

PR port-arm/57437

XXX pullup-10
 1.12 25-May-2023  riastradh libpthread: Use __nothing, not /* nothing */, for empty macros.

No functional change intended -- just safer to do it this way in case
the macros are used in if branches or comma expressions.

PR port-arm/57437 (pthread__smt_pause/wake issue)

XXX pullup-10
 1.11 22-Nov-2018  skrll branches: 1.11.2; 1.11.10;
G/C __APCS_26__ support
 1.10 17-Jul-2017  skrll branches: 1.10.2; 1.10.4; 1.10.6;
Typo in comment
 1.9 15-Aug-2013  matt branches: 1.9.18;
Use the thumb1 versions of sev/wfe for thumb && armv6+.
if using armv5t don't do anything for thumb.
 1.8 19-Sep-2012  matt Use .inst instead of wfe/sev to shut up gas.
 1.7 16-Aug-2012  matt branches: 1.7.2;
Add a pthread__smt_wake and add support for it on arm along with
pthread__smt_pause. These are implemented using the ARM instructions
SEV (wake) and WFE (pause). These are treated as NOPs on ARM CPUs that
don't support them.
 1.6 25-Jan-2011  christos branches: 1.6.4;
make pthread__sp unsigned long.
 1.5 16-May-2009  ad branches: 1.5.2;
Remove unused code that's confusing when using cscope/opengrok.
 1.4 24-Dec-2005  perry Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.3 18-Jan-2003  christos add missing backslash
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 16-Nov-2001  thorpej branches: 1.1.2;
file pthread_md.h was initially added on branch nathanw_sa.
 1.1.2.4 17-Jan-2003  nathanw Add _INITCONTEXT_U_MD() code that sets up the PC or CPSR.

Adjust PTHREAD_UCONTEXT_TO_REG() to set a plausable value in
reg->r_cpsr when _UC_USER is set in the ucontext; otherwise, GDB gets
very confused and thinks it's dealing with 26-bit ARM state.
 1.1.2.3 20-Dec-2002  thorpej Update for mcontext_t changes.
 1.1.2.2 06-Aug-2002  thorpej Add glue for libpthread_dbg.
 1.1.2.1 16-Nov-2001  thorpej First cut at machine-dependent pthread bits for ARM.
 1.5.2.1 08-Feb-2011  bouyer Sync with HEAD
 1.6.4.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.6.4.1 30-Oct-2012  yamt sync with head
 1.7.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.7.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.9.18.1 04-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #1878):

lib/libpthread/arch/x86_64/pthread_md.h: revision 1.13
lib/libpthread/pthread_int.h: revision 1.110
lib/libpthread/pthread_int.h: revision 1.111
lib/libpthread/arch/i386/pthread_md.h: revision 1.21
lib/libpthread/arch/arm/pthread_md.h: revision 1.12
lib/libpthread/arch/arm/pthread_md.h: revision 1.13
lib/libpthread/pthread_spin.c: revision 1.11
lib/libpthread/arch/aarch64/pthread_md.h: revision 1.2

libpthread: Use __nothing, not /* nothing */, for empty macros.

No functional change intended -- just safer to do it this way in case
the macros are used in if branches or comma expressions.
PR port-arm/57437 (pthread__smt_pause/wake issue)

libpthread: New pthread__smt_wait to put CPU in low power for spin.

This is now distinct from pthread__smt_pause, which is for spin lock
backoff with no paired wakeup.

On Arm, there is a single-bit event register per CPU, and there are two
instructions to manage it:
- wfe, wait for event -- if event register is clear, enter low power
mode and wait until event register is set; then exit low power mode
and clear event register
- sev, signal event -- sets event register on all CPUs (other
circumstances like interrupts also set the event register and cause
wfe to wake)

These can be used to reduce the power consumption of spinning for a
lock, but only if they are actually paired -- if there's no sev, wfe
might hang indefinitely. Currently only pthread_spin(3) actually
pairs them; the other lock primitives (internal lock, mutex, rwlock)
do not -- they have spin lock backoff loops, but no corresponding
wakeup to cancel a wfe.

It may be worthwhile to teach the other lock primitives to pair
wfe/sev, but that requires some performance measurement to verify
it's actually worthwhile. So for now, we just make sure not to use
wfe when there's no sev, and keep everything else the same -- this
should fix severe performance degredation in libpthread on Arm
without hurting anything else.

No change in the generated code on amd64 and i386. No change in the
generated code for pthread_spin.c on arm and aarch64 -- changes only
the generated code for pthread_lock.c, pthread_mutex.c, and
pthread_rwlock.c, as intended.
PR port-arm/57437
 1.10.6.1 10-Jun-2019  christos Sync with HEAD
 1.10.4.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.10.2.2 17-Jul-2017  skrll 2167115
 1.10.2.1 17-Jul-2017  skrll file pthread_md.h was added on branch perseant-stdc-iso10646 on 2017-07-17 20:24:08 +0000
 1.11.10.1 01-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #296):

lib/libpthread/arch/x86_64/pthread_md.h: revision 1.13
lib/libpthread/pthread_int.h: revision 1.110
lib/libpthread/pthread_int.h: revision 1.111
lib/libpthread/arch/i386/pthread_md.h: revision 1.21
lib/libpthread/arch/arm/pthread_md.h: revision 1.12
lib/libpthread/arch/arm/pthread_md.h: revision 1.13
lib/libpthread/pthread_spin.c: revision 1.11
lib/libpthread/arch/aarch64/pthread_md.h: revision 1.2

libpthread: Use __nothing, not /* nothing */, for empty macros.

No functional change intended -- just safer to do it this way in case
the macros are used in if branches or comma expressions.

PR port-arm/57437 (pthread__smt_pause/wake issue)

libpthread: New pthread__smt_wait to put CPU in low power for spin.

This is now distinct from pthread__smt_pause, which is for spin lock
backoff with no paired wakeup.

On Arm, there is a single-bit event register per CPU, and there are two
instructions to manage it:
- wfe, wait for event -- if event register is clear, enter low power
mode and wait until event register is set; then exit low power mode
and clear event register
- sev, signal event -- sets event register on all CPUs (other
circumstances like interrupts also set the event register and cause
wfe to wake)

These can be used to reduce the power consumption of spinning for a
lock, but only if they are actually paired -- if there's no sev, wfe
might hang indefinitely. Currently only pthread_spin(3) actually
pairs them; the other lock primitives (internal lock, mutex, rwlock)
do not -- they have spin lock backoff loops, but no corresponding
wakeup to cancel a wfe.

It may be worthwhile to teach the other lock primitives to pair
wfe/sev, but that requires some performance measurement to verify
it's actually worthwhile. So for now, we just make sure not to use
wfe when there's no sev, and keep everything else the same -- this
should fix severe performance degredation in libpthread on Arm
without hurting anything else.

No change in the generated code on amd64 and i386. No change in the
generated code for pthread_spin.c on arm and aarch64 -- changes only
the generated code for pthread_lock.c, pthread_mutex.c, and
pthread_rwlock.c, as intended.

PR port-arm/57437
 1.11.2.1 04-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #1700):

lib/libpthread/arch/x86_64/pthread_md.h: revision 1.13
lib/libpthread/pthread_int.h: revision 1.110
lib/libpthread/pthread_int.h: revision 1.111
lib/libpthread/arch/i386/pthread_md.h: revision 1.21
lib/libpthread/arch/arm/pthread_md.h: revision 1.12
lib/libpthread/arch/arm/pthread_md.h: revision 1.13
lib/libpthread/pthread_spin.c: revision 1.11
lib/libpthread/arch/aarch64/pthread_md.h: revision 1.2

libpthread: Use __nothing, not /* nothing */, for empty macros.

No functional change intended -- just safer to do it this way in case
the macros are used in if branches or comma expressions.
PR port-arm/57437 (pthread__smt_pause/wake issue)

libpthread: New pthread__smt_wait to put CPU in low power for spin.

This is now distinct from pthread__smt_pause, which is for spin lock
backoff with no paired wakeup.

On Arm, there is a single-bit event register per CPU, and there are two
instructions to manage it:
- wfe, wait for event -- if event register is clear, enter low power
mode and wait until event register is set; then exit low power mode
and clear event register
- sev, signal event -- sets event register on all CPUs (other
circumstances like interrupts also set the event register and cause
wfe to wake)

These can be used to reduce the power consumption of spinning for a
lock, but only if they are actually paired -- if there's no sev, wfe
might hang indefinitely. Currently only pthread_spin(3) actually
pairs them; the other lock primitives (internal lock, mutex, rwlock)
do not -- they have spin lock backoff loops, but no corresponding
wakeup to cancel a wfe.

It may be worthwhile to teach the other lock primitives to pair
wfe/sev, but that requires some performance measurement to verify
it's actually worthwhile. So for now, we just make sure not to use
wfe when there's no sev, and keep everything else the same -- this
should fix severe performance degredation in libpthread on Arm
without hurting anything else.

No change in the generated code on amd64 and i386. No change in the
generated code for pthread_spin.c on arm and aarch64 -- changes only
the generated code for pthread_lock.c, pthread_mutex.c, and
pthread_rwlock.c, as intended.
PR port-arm/57437
 1.9 02-Mar-2007  ad Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
 1.8 21-Aug-2004  rearnsha Use RET macro for returning.
 1.7 07-Sep-2003  cl Remove possible race condition in upcall recycling.
 1.6 24-Jul-2003  skrll Typo in comment.
 1.5 26-Jun-2003  nathanw Adapt to pt_trapuc: change STACK_SWITCH to check for a value in pt_trapuc
and use it preferentially to a value in pt_uc, clearing it once on the new
stack. Move stores into pt_uc back to before the stack switch; storing
after the stack switch opened a one-instruction race condition where an upcall
that had just started a chain could be preempted again, and would bomb when
restarted due to its pt_uc not yet having been updated. Now that pt_trapuc
is what the upcall code writes to, it is safe to store to pt_uc before
switching stacks.

Remove obsolete pt_sleepuc code.
 1.4 12-Jun-2003  nathanw Two fixes:
* In switch-away cases, write PT_SWITCHTO last (after PT_SWITCHTOUC), so
that pthread__resolve_locks() doesn't see an empty SWITCHTOUC value. This
also permits pthread__resolve_locks() to use the presence of PT_SWITCHTO
as a sign that the thread has done all of its necessary chain work.

* Make the return-point of pthread__switch global and visible, so that its
address can be compared to the PC of a thread, again as a sign that its
chain-work is done.

(other architectures in progress, after they get the *previous* asm fix...)
 1.3 05-Apr-2003  bjh21 NetBSD/acorn26 has used APCS-32 for years, so unifdef -U__APCS_26__.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 16-Nov-2001  thorpej branches: 1.1.2;
file pthread_switch.S was initially added on branch nathanw_sa.
 1.1.2.3 14-Jan-2003  nathanw Rewrite pthread__switch() to avoid storing the new saved-context
pointer while still using the old stack. This avoids a race condition
with pthread__find_interrupted() where a thread could lose its old
state if it was interrupted in a certain window in pthread__switch().
 1.1.2.2 22-Nov-2001  bjh21 Correct a typo in STACK_SWITCH(), where it used the wrong register to
compute the stack pointer. This patch gets test "cond2" working on ARM.
 1.1.2.1 16-Nov-2001  thorpej First cut at machine-dependent pthread bits for ARM.
 1.5 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.4 11-Aug-2008  skrll branches: 1.4.6;
Remove unnecessary include.
 1.3 28-Apr-2008  martin branches: 1.3.2;
Remove clause 3 and 4 from TNF licenses
 1.2 24-Sep-2007  skrll branches: 1.2.6;
Resurrect the function pointers for lock operations and allow each
architecture to provide asm versions of the RAS operations.

We do this because relying on the compiler to get the RAS right is not
sensible. (It gets alpha wrong and hppa is suboptimal)

Provide asm RAS ops for hppa.

(A slightly different version) reviewed by Andrew Doran.
 1.1 19-Jul-2004  chs branches: 1.1.18;
add hppa MD libpthread bits. translated from MIPS.
 1.1.18.1 06-Nov-2007  matt sync with HEAD
 1.2.6.1 18-May-2008  yamt sync with head.
 1.3.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.4.6.2 11-Aug-2008  skrll Remove unnecessary include.
 1.4.6.1 11-Aug-2008  skrll file _context_u.S was added on branch christos-time_t on 2008-08-11 21:45:25 +0000
 1.4 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.3 28-Apr-2008  martin branches: 1.3.8;
Remove clause 3 and 4 from TNF licenses
 1.2 02-Mar-2007  ad branches: 1.2.12;
Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
 1.1 19-Jul-2004  chs add hppa MD libpthread bits. translated from MIPS.
 1.2.12.1 18-May-2008  yamt sync with head.
 1.3.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.3.8.1 28-Apr-2008  martin file genassym.cf was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.2 19-May-2022  skrll Use RAS_{START,END}_ASM_HIDDEN
 1.1 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.1 22-Nov-2024  riastradh branches: 1.1.4;
libpthread: Fix expected symbols on alpha and hppa.

These have PTHREAD__ASM_RASOPS and define a different subset of
symbols which get exported. None of these pthread__ras_* and
pthread__lock_* symbols _should_ be exported but we can fix that in a
future revbump.

PR lib/58838: shared libraries in base should all have expsym lists
 1.1.4.2 02-Aug-2025  perseant Sync with HEAD
 1.1.4.1 22-Nov-2024  perseant file pthread_md.expsym was added on branch perseant-exfatfs on 2025-08-02 05:54:56 +0000
 1.8 25-Jan-2011  christos make pthread__sp unsigned long.
 1.7 16-May-2009  ad branches: 1.7.2;
Remove unused code that's confusing when using cscope/opengrok.
 1.6 28-Apr-2008  martin branches: 1.6.8;
Remove clause 3 and 4 from TNF licenses
 1.5 10-Feb-2008  ad branches: 1.5.4;
- Remove libpthread's atomic ops.
- Remove the old spinlock-based mutex and rwlock implementations.
- Use the atomic ops from libc.
 1.4 24-Sep-2007  skrll Resurrect the function pointers for lock operations and allow each
architecture to provide asm versions of the RAS operations.

We do this because relying on the compiler to get the RAS right is not
sensible. (It gets alpha wrong and hppa is suboptimal)

Provide asm RAS ops for hppa.

(A slightly different version) reviewed by Andrew Doran.
 1.3 24-Dec-2005  perry branches: 1.3.12;
__asm__ -> __asm
 1.2 24-Dec-2005  perry Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.1 19-Jul-2004  chs add hppa MD libpthread bits. translated from MIPS.
 1.3.12.2 23-Mar-2008  matt sync with HEAD
 1.3.12.1 06-Nov-2007  matt sync with HEAD
 1.5.4.1 18-May-2008  yamt sync with head.
 1.6.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.6.8.1 28-Apr-2008  martin file pthread_md.h was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.7.2.1 08-Feb-2011  bouyer Sync with HEAD
 1.2 02-Mar-2007  ad Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
 1.1 19-Jul-2004  chs add hppa MD libpthread bits. translated from MIPS.
 1.3 08-Oct-1997  scottr This incarnation of the pthreads library is ancient and not useful, and
should have been mothballed some time ago...
 1.2 07-Jan-1994  mycroft Delete special rules for syscall.S; they are not needed, and one of them
is wrong anyway.
 1.1 14-Nov-1993  proven branches: 1.1.1;
Initial revision
 1.1.1.1 14-Nov-1993  proven Initial release of the POSIX 1003.4a Draft 7 thread implementation.
 1.10 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.9 28-Apr-2008  martin branches: 1.9.8;
Remove clause 3 and 4 from TNF licenses
 1.8 10-Feb-2008  ad branches: 1.8.4;
- Remove libpthread's atomic ops.
- Remove the old spinlock-based mutex and rwlock implementations.
- Use the atomic ops from libc.
 1.7 13-Nov-2007  ad Mutexes:

- Play scrooge again and chop more cycles off acquire/release.
- Spin while the lock holder is running on another CPU (adaptive mutexes).
- Do non-atomic release.

Threadreg:

- Add the necessary hooks to use a thread register.
- Add the code for i386, using %gs.
- Leave i386 code disabled until xen and COMPAT_NETBSD32 have the changes.
 1.6 13-Nov-2007  ad For PR bin/37347:

- Override __libc_thr_init() instead of using our own constructor.
- Add pthread__getenv() and use instead of getenv(). This is used before
we are up and running and unfortunatley getenv() takes locks.

Other changes:

- Cache the spinlock vectors in pthread__st. Internal spinlock operations
now take 1 function call instead of 3 (i386).
- Use pthread__self() internally, not pthread_self().
- Use __attribute__ ((visibility("hidden"))) in some places.
- Kill PTHREAD_MAIN_DEBUG.
 1.5 08-Sep-2007  ad - Get rid of self->pt_mutexhint and use pthread__mutex_owned() instead.
- Update some comments and fix minor bugs. Minor cosmetic changes.
- Replace some spinlocks with mutexes and rwlocks.
- Change the process private semaphores to use mutexes and condition
variables instead of doing the synchronization directly. Spinlocks
are no longer used by the semaphore code.
 1.4 07-Sep-2007  ad - Don't take the mutex's spinlock (ptr_interlock) in pthread_cond_wait().
Instead, make the deferred wakeup list a per-thread array and pass down
the lwpid_t's that way.

- In pthread_cond_wait(), take the mutex before dealing with early wakeup.
In this way there should never be contention on the CV's spinlock if
the app follows POSIX rules (there should only be contention on the
user-provided mutex).

- Add a port of the kernel's rwlocks. The rwlock's spinlock is only taken if
there is contention. This is enabled where atomic ops are available. Right
now that is only i386 and amd64 because I don't have other hardware to
test with. It's trivial to add stubs for other architectures as long as
they have compare-and-swap. When we have proper atomic ops the old rwlock
code can be removed.

- Add a new mutex implementation that's similar to the kernel's mutexes, but
uses compare-and-swap to maintain the waiters list, so no spinlocks are
involved. Same caveats apply as for the rwlocks.
 1.3 07-Sep-2007  ad Add: pthread__atomic_cas_ptr, pthread__atomic_swap_ptr, pthread__membar_full
This is a stopgap until the thorpej-atomic branch is complete.
 1.2 18-Jan-2003  thorpej branches: 1.2.20; 1.2.24;
Merge the nathanw_sa branch.
 1.1 13-Jul-2001  nathanw branches: 1.1.2;
file _context_u.S was initially added on branch nathanw_sa.
 1.1.2.10 06-Sep-2002  nathanw In the xmm case, FPSAVE should be "fxsave", and FPLOAD should be "fxrstor",
not the other way around. Note to self: Lay off the crack.
 1.1.2.9 14-Aug-2002  nathanw Define, initialize, and use function pointers for _{set,get,swap}context_u
routines, with different versions for saving FP state with fnsave or fxsave,
depending on the machdep.osfxsr sysctl.
 1.1.2.8 24-Apr-2002  nathanw Save FP state in user context switches.

XXX1: doing something clever about lazy-FP-switching would be good.
XXX2: coping with SSE/SSE2 regsisters would also be good.
 1.1.2.7 01-Mar-2002  nathanw Restore FP state if the kernel handed us any.
[xmms no longer sounds like it's playing Play-Skool LPs]
 1.1.2.6 11-Feb-2002  nathanw Implement _UC_USER for i386: only save callee-save registers, and set a
flag saying so; on restore, if that flag is set, only restore the callee-save
registers.

Speeds up the user-only version of these routines by 35-40% on a
Pentium MMX 233.
 1.1.2.5 04-Sep-2001  nathanw Generate and use symbolic constants for register offsets in mcontext_t,
instead of hand-coding offset numbers.
 1.1.2.4 02-Aug-2001  nathanw Don't bother even storing 0s into the fields for the caller-save
registers (eax, ecx, edx) and unused fields (esp, trapno, err).

Still need to deal more sanely with segment registers.
 1.1.2.3 02-Aug-2001  nathanw Adjust SETC (used by _setcontext_u and _getcontext_u) to not set the
new stack pointer until all the possibly-interesting data below the
new SP has been preserved. Unfortunately, it's about 3% slower.
 1.1.2.2 31-Jul-2001  nathanw Whitespace cleanup.
 1.1.2.1 13-Jul-2001  nathanw Make userlevel-only *context functions part of libpthread rather than libc.
 1.2.24.3 23-Mar-2008  matt sync with HEAD
 1.2.24.2 09-Jan-2008  matt sync with HEAD
 1.2.24.1 06-Nov-2007  matt sync with HEAD
 1.2.20.1 10-Sep-2007  skrll Sync with HEAD.
 1.8.4.1 18-May-2008  yamt sync with head.
 1.9.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.9.8.1 28-Apr-2008  martin file _context_u.S was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.9 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.8 07-Jul-2008  gmcgarry branches: 1.8.6;
Selector registers are 16-bit and binutils 2.18 insists that only 16-bit
accesses are permitted on them. Therefore, change movl to movw. No change to
machine code generated.
 1.7 28-Apr-2008  martin branches: 1.7.2;
Remove clause 3 and 4 from TNF licenses
 1.6 20-Jan-2007  christos branches: 1.6.12;
fix warning about indirect call without *
 1.5 30-Nov-2004  nathanw Punt to setcontext() system call if the PSL_T bit (single-step trap)
is set, so that the single-step trap happens in the thread's context
and not in the middle of _setcontext_u.

XXX might be able to do something here with iret, too, but it needs
more testing.
 1.4 10-Nov-2004  kent save&restore %fs and %gs registers for USER_LDT applications.
PR#26900
 1.3 30-Oct-2003  yamt branches: 1.3.2;
use explicit "l" suffixes. (eg. lea -> leal)
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 14-Aug-2002  nathanw branches: 1.1.2;
file _getsetc.S was initially added on branch nathanw_sa.
 1.1.2.4 22-Oct-2002  skrll RCSId police.
 1.1.2.3 04-Sep-2002  nathanw The _UC_USER_BIT case of SETC (currently) needs to load FP state.

Found by inspection.
 1.1.2.2 15-Aug-2002  nathanw Bit values are not the same as bit positions; fix the test for the
_UC_FPU flag.
 1.1.2.1 14-Aug-2002  nathanw Define, initialize, and use function pointers for _{set,get,swap}context_u
routines, with different versions for saving FP state with fnsave or fxsave,
depending on the machdep.osfxsr sysctl.
 1.3.2.1 12-Nov-2004  jmc Pullup rev 1.4 (requested by kent in ticket #969)

save&restore %fs and %gs registers for USER_LDT applications. PR#26900
 1.6.12.1 18-May-2008  yamt sync with head.
 1.7.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.8.6.2 07-Jul-2008  gmcgarry Selector registers are 16-bit and binutils 2.18 insists that only 16-bit
accesses are permitted on them. Therefore, change movl to movw. No change to
machine code generated.
 1.8.6.1 07-Jul-2008  gmcgarry file _getsetc.S was added on branch christos-time_t on 2008-07-07 13:07:56 +0000
 1.8 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.7 28-Apr-2008  martin branches: 1.7.8;
Remove clause 3 and 4 from TNF licenses
 1.6 02-Mar-2007  ad branches: 1.6.12;
Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
 1.5 07-Sep-2003  cl Remove possible race condition in upcall recycling.
 1.4 17-Jul-2003  nathanw Adapt to structure name changes.
 1.3 26-Jun-2003  nathanw Remove PT_SLEEPUC and add PT_TRAPUC.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 05-Mar-2001  nathanw branches: 1.1.2;
file genassym.cf was initially added on branch nathanw_sa.
 1.1.2.9 14-Aug-2002  nathanw Define, initialize, and use function pointers for _{set,get,swap}context_u
routines, with different versions for saving FP state with fnsave or fxsave,
depending on the machdep.osfxsr sysctl.
 1.1.2.8 25-Mar-2002  nathanw Define a couple of constants for FP register use.
 1.1.2.7 11-Feb-2002  nathanw Implement _UC_USER for i386: only save callee-save registers, and set a
flag saying so; on restore, if that flag is set, only restore the callee-save
registers.

Speeds up the user-only version of these routines by 35-40% on a
Pentium MMX 233.
 1.1.2.6 04-Sep-2001  nathanw Generate and use symbolic constants for register offsets in mcontext_t,
instead of hand-coding offset numbers.
 1.1.2.5 04-Sep-2001  nathanw Define STACKSPACE in pthread_md.h, not directly in pthread_switch.S
 1.1.2.4 01-Aug-2001  nathanw Create an offset for pt_sleepuc.
 1.1.2.3 31-Jul-2001  nathanw Create an asm symbol for the offset of EIP in the ucontext.
 1.1.2.2 13-Jul-2001  nathanw Note copyright.
Standardize RCS IDs.
 1.1.2.1 05-Mar-2001  nathanw The beginnings of a scheduler activations-based pthread library.
 1.6.12.1 18-May-2008  yamt sync with head.
 1.7.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.7.8.1 28-Apr-2008  martin file genassym.cf was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.4 08-Oct-1997  scottr This incarnation of the pthreads library is ancient and not useful, and
should have been mothballed some time ago...
 1.3 07-Feb-1994  proven More wrapper functions, and some hacks for machine independent sleep
mechanisms.
 1.2 20-Dec-1993  proven Copyrights added to each file.
 1.1 14-Nov-1993  proven branches: 1.1.1;
Initial revision
 1.1.1.1 14-Nov-1993  proven Initial release of the POSIX 1003.4a Draft 7 thread implementation.
 1.4 08-Oct-1997  scottr This incarnation of the pthreads library is ancient and not useful, and
should have been mothballed some time ago...
 1.3 20-Dec-1993  proven Copyrights added to each file.
 1.2 15-Nov-1993  proven OK one more try at getting it right ...
 1.1 14-Nov-1993  proven branches: 1.1.1;
Initial revision
 1.1.1.1 14-Nov-1993  proven Initial release of the POSIX 1003.4a Draft 7 thread implementation.
 1.7 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.6 29-Mar-2009  ad - Make the threadreg code use _lwp_setprivate() instead of MD hooks.

XXX This must not be enabled by default because the LWP private mechanism
is reserved for TLS. It is provided only as a test/demo.

XXX Since ucontext_t does not contain the thread private variable, for a
short time after threads are created their thread specific data is unset.
If a signal arrives during that time we are screwed.

- No longer need pthread__osrev.

- Rearrange _lwp_ctl() calls slightly.
 1.5 28-Apr-2008  martin branches: 1.5.8; 1.5.10;
Remove clause 3 and 4 from TNF licenses
 1.4 13-Nov-2007  ad branches: 1.4.6;
Mutexes:

- Play scrooge again and chop more cycles off acquire/release.
- Spin while the lock holder is running on another CPU (adaptive mutexes).
- Do non-atomic release.

Threadreg:

- Add the necessary hooks to use a thread register.
- Add the code for i386, using %gs.
- Leave i386 code disabled until xen and COMPAT_NETBSD32 have the changes.
 1.3 08-Mar-2003  lukem branches: 1.3.24;
add __RCSID()
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 15-Aug-2002  nathanw branches: 1.1.2;
file pthread_md.c was initially added on branch nathanw_sa.
 1.1.2.1 15-Aug-2002  nathanw Actually add this file.
 1.3.24.1 09-Jan-2008  matt sync with HEAD
 1.4.6.1 18-May-2008  yamt sync with head.
 1.5.10.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.5.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.5.8.1 28-Apr-2008  martin file pthread_md.c was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.21 25-May-2023  riastradh libpthread: New pthread__smt_wait to put CPU in low power for spin.

This is now distinct from pthread__smt_pause, which is for spin lock
backoff with no paired wakeup.

On Arm, there is a single-bit event register per CPU, and there are two
instructions to manage it:

- wfe, wait for event -- if event register is clear, enter low power
mode and wait until event register is set; then exit low power mode
and clear event register

- sev, signal event -- sets event register on all CPUs (other
circumstances like interrupts also set the event register and cause
wfe to wake)

These can be used to reduce the power consumption of spinning for a
lock, but only if they are actually paired -- if there's no sev, wfe
might hang indefinitely. Currently only pthread_spin(3) actually
pairs them; the other lock primitives (internal lock, mutex, rwlock)
do not -- they have spin lock backoff loops, but no corresponding
wakeup to cancel a wfe.

It may be worthwhile to teach the other lock primitives to pair
wfe/sev, but that requires some performance measurement to verify
it's actually worthwhile. So for now, we just make sure not to use
wfe when there's no sev, and keep everything else the same -- this
should fix severe performance degredation in libpthread on Arm
without hurting anything else.

No change in the generated code on amd64 and i386. No change in the
generated code for pthread_spin.c on arm and aarch64 -- changes only
the generated code for pthread_lock.c, pthread_mutex.c, and
pthread_rwlock.c, as intended.

PR port-arm/57437

XXX pullup-10
 1.20 02-Mar-2012  joerg branches: 1.20.24; 1.20.34; 1.20.42;
Avoid getcontext() as it triggers clobbering warnings. Use inline
assembler to get the fields directly. Saves a system call as side
effect.
 1.19 24-Feb-2011  joerg branches: 1.19.4;
Allow storing and receiving the LWP private pointer via ucontext_t
on all platforms except VAX and IA64. Add fast access via register for
AMD64, i386 and SH3 ports. Use this fast access in libpthread to replace
the stack based pthread_self(). Implement skeleton support for Alpha,
HPPA, PowerPC, SPARC and SPARC64, but leave it disabled.

Ports that support this feature provide __HAVE____LWP_GETPRIVATE_FAST in
machine/types.h and a corresponding __lwp_getprivate_fast in
machine/mcontext.h.

This material is based upon work partially supported by
The NetBSD Foundation under a contract with Joerg Sonnenberger.
 1.18 25-Jan-2011  christos make pthread__sp unsigned long.
 1.17 16-May-2009  ad branches: 1.17.2;
Remove unused code that's confusing when using cscope/opengrok.
 1.16 29-Mar-2009  ad - Make the threadreg code use _lwp_setprivate() instead of MD hooks.

XXX This must not be enabled by default because the LWP private mechanism
is reserved for TLS. It is provided only as a test/demo.

XXX Since ucontext_t does not contain the thread private variable, for a
short time after threads are created their thread specific data is unset.
If a signal arrives during that time we are screwed.

- No longer need pthread__osrev.

- Rearrange _lwp_ctl() calls slightly.
 1.15 23-Jun-2008  ad branches: 1.15.6; 1.15.8;
pthread__threadreg_get: mark it const.
 1.14 28-Apr-2008  martin branches: 1.14.2;
Remove clause 3 and 4 from TNF licenses
 1.13 22-Mar-2008  ad branches: 1.13.2;
Cheat and add inlines for _atomic_cas_ptr() to work around gcc emitting
unneeded PIC stuff in mutex_lock() and mutex_unlock(), when a thread
register is used.
 1.12 10-Feb-2008  ad - Remove libpthread's atomic ops.
- Remove the old spinlock-based mutex and rwlock implementations.
- Use the atomic ops from libc.
 1.11 13-Nov-2007  ad Mutexes:

- Play scrooge again and chop more cycles off acquire/release.
- Spin while the lock holder is running on another CPU (adaptive mutexes).
- Do non-atomic release.

Threadreg:

- Add the necessary hooks to use a thread register.
- Add the code for i386, using %gs.
- Leave i386 code disabled until xen and COMPAT_NETBSD32 have the changes.
 1.10 24-Sep-2007  skrll Resurrect the function pointers for lock operations and allow each
architecture to provide asm versions of the RAS operations.

We do this because relying on the compiler to get the RAS right is not
sensible. (It gets alpha wrong and hppa is suboptimal)

Provide asm RAS ops for hppa.

(A slightly different version) reviewed by Andrew Doran.
 1.9 08-Sep-2007  ad - Get rid of self->pt_mutexhint and use pthread__mutex_owned() instead.
- Update some comments and fix minor bugs. Minor cosmetic changes.
- Replace some spinlocks with mutexes and rwlocks.
- Change the process private semaphores to use mutexes and condition
variables instead of doing the synchronization directly. Spinlocks
are no longer used by the semaphore code.
 1.8 07-Sep-2007  ad Add: pthread__atomic_cas_ptr, pthread__atomic_swap_ptr, pthread__membar_full
This is a stopgap until the thorpej-atomic branch is complete.
 1.7 29-Mar-2006  cube branches: 1.7.8; 1.7.12;
Instead of using hard-coded values for various registers, get them from the
current context. Valid values can change depending on how the kernel is
setup. i386 and amd64 happen to be setup differently.
 1.6 24-Dec-2005  perry Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.5 11-Feb-2004  nathanw branches: 1.5.4; 1.5.6;
Add ucontext conversion macros for an "extra" register set.
 1.4 18-Jan-2003  christos delint
 1.3 18-Jan-2003  christos de-lint
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 05-Mar-2001  nathanw branches: 1.1.2;
file pthread_md.h was initially added on branch nathanw_sa.
 1.1.2.11 17-Jan-2003  thorpej Include <sys/ucontext.h> to get ucontext_t for prototypes.
 1.1.2.10 16-Jan-2003  thorpej * Move the pthread_sigmask() prototype to <signal.h>.
* Don't include <signal.h> in <pthread.h>.
* Add code to the signal trampoline to convert from the ucontext
to a sigcontext, and back again (XXX though, only callee-save
regs for _UC_USER contexts).

This is necessary in order to support e.g. GCC's libjava, which depends
on the traditional Unix semantics of changes made to the sigcontext
being visible when the handler returns.
 1.1.2.9 06-Dec-2002  nathanw Clear _UC_USER bit when converting from sigcontext to ucontext.
 1.1.2.8 22-Oct-2002  nathanw Define _INITCONTEXT_U_MD() to set segment registers and flag register
to sensible values.
 1.1.2.7 21-Oct-2002  nathanw Add some macros to convert between ucontext_t and struct sigcontext.
 1.1.2.6 14-Aug-2002  nathanw Define, initialize, and use function pointers for _{set,get,swap}context_u
routines, with different versions for saving FP state with fnsave or fxsave,
depending on the machdep.osfxsr sysctl.
 1.1.2.5 24-Apr-2002  nathanw Add macros to convert between struct ucontext and struct reg/fpreg.
 1.1.2.4 14-Nov-2001  briggs Add pthread__uc_pc() to pthread_md.h instead of making assumptions about
the contents of the m.d. mcontext.
 1.1.2.3 04-Sep-2001  nathanw Define STACKSPACE in pthread_md.h, not directly in pthread_switch.S
 1.1.2.2 13-Jul-2001  nathanw Note copyright.
Standardize RCS IDs.
 1.1.2.1 05-Mar-2001  nathanw The beginnings of a scheduler activations-based pthread library.
 1.5.6.1 19-Apr-2006  tron Pull up following revision(s) (requested by cube in ticket #1265):
lib/libpthread/arch/i386/pthread_md.h: revision 1.7
Instead of using hard-coded values for various registers, get them from the
current context. Valid values can change depending on how the kernel is
setup. i386 and amd64 happen to be setup differently.
 1.5.4.1 21-Apr-2006  tron Pull up following revision(s) (requested by cube in ticket #10448):
lib/libpthread/arch/i386/pthread_md.h: revision 1.7
Instead of using hard-coded values for various registers, get them from the
current context. Valid values can change depending on how the kernel is
setup. i386 and amd64 happen to be setup differently.
 1.7.12.3 23-Mar-2008  matt sync with HEAD
 1.7.12.2 09-Jan-2008  matt sync with HEAD
 1.7.12.1 06-Nov-2007  matt sync with HEAD
 1.7.8.1 10-Sep-2007  skrll Sync with HEAD.
 1.13.2.1 18-May-2008  yamt sync with head.
 1.14.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.15.8.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.15.6.2 23-Jun-2008  ad pthread__threadreg_get: mark it const.
 1.15.6.1 23-Jun-2008  ad file pthread_md.h was added on branch christos-time_t on 2008-06-23 10:39:39 +0000
 1.17.2.2 05-Mar-2011  bouyer Sync with HEAD
 1.17.2.1 08-Feb-2011  bouyer Sync with HEAD
 1.19.4.1 17-Apr-2012  yamt sync with head
 1.20.42.1 01-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #296):

lib/libpthread/arch/x86_64/pthread_md.h: revision 1.13
lib/libpthread/pthread_int.h: revision 1.110
lib/libpthread/pthread_int.h: revision 1.111
lib/libpthread/arch/i386/pthread_md.h: revision 1.21
lib/libpthread/arch/arm/pthread_md.h: revision 1.12
lib/libpthread/arch/arm/pthread_md.h: revision 1.13
lib/libpthread/pthread_spin.c: revision 1.11
lib/libpthread/arch/aarch64/pthread_md.h: revision 1.2

libpthread: Use __nothing, not /* nothing */, for empty macros.

No functional change intended -- just safer to do it this way in case
the macros are used in if branches or comma expressions.

PR port-arm/57437 (pthread__smt_pause/wake issue)

libpthread: New pthread__smt_wait to put CPU in low power for spin.

This is now distinct from pthread__smt_pause, which is for spin lock
backoff with no paired wakeup.

On Arm, there is a single-bit event register per CPU, and there are two
instructions to manage it:
- wfe, wait for event -- if event register is clear, enter low power
mode and wait until event register is set; then exit low power mode
and clear event register
- sev, signal event -- sets event register on all CPUs (other
circumstances like interrupts also set the event register and cause
wfe to wake)

These can be used to reduce the power consumption of spinning for a
lock, but only if they are actually paired -- if there's no sev, wfe
might hang indefinitely. Currently only pthread_spin(3) actually
pairs them; the other lock primitives (internal lock, mutex, rwlock)
do not -- they have spin lock backoff loops, but no corresponding
wakeup to cancel a wfe.

It may be worthwhile to teach the other lock primitives to pair
wfe/sev, but that requires some performance measurement to verify
it's actually worthwhile. So for now, we just make sure not to use
wfe when there's no sev, and keep everything else the same -- this
should fix severe performance degredation in libpthread on Arm
without hurting anything else.

No change in the generated code on amd64 and i386. No change in the
generated code for pthread_spin.c on arm and aarch64 -- changes only
the generated code for pthread_lock.c, pthread_mutex.c, and
pthread_rwlock.c, as intended.

PR port-arm/57437
 1.20.34.1 04-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #1700):

lib/libpthread/arch/x86_64/pthread_md.h: revision 1.13
lib/libpthread/pthread_int.h: revision 1.110
lib/libpthread/pthread_int.h: revision 1.111
lib/libpthread/arch/i386/pthread_md.h: revision 1.21
lib/libpthread/arch/arm/pthread_md.h: revision 1.12
lib/libpthread/arch/arm/pthread_md.h: revision 1.13
lib/libpthread/pthread_spin.c: revision 1.11
lib/libpthread/arch/aarch64/pthread_md.h: revision 1.2

libpthread: Use __nothing, not /* nothing */, for empty macros.

No functional change intended -- just safer to do it this way in case
the macros are used in if branches or comma expressions.
PR port-arm/57437 (pthread__smt_pause/wake issue)

libpthread: New pthread__smt_wait to put CPU in low power for spin.

This is now distinct from pthread__smt_pause, which is for spin lock
backoff with no paired wakeup.

On Arm, there is a single-bit event register per CPU, and there are two
instructions to manage it:
- wfe, wait for event -- if event register is clear, enter low power
mode and wait until event register is set; then exit low power mode
and clear event register
- sev, signal event -- sets event register on all CPUs (other
circumstances like interrupts also set the event register and cause
wfe to wake)

These can be used to reduce the power consumption of spinning for a
lock, but only if they are actually paired -- if there's no sev, wfe
might hang indefinitely. Currently only pthread_spin(3) actually
pairs them; the other lock primitives (internal lock, mutex, rwlock)
do not -- they have spin lock backoff loops, but no corresponding
wakeup to cancel a wfe.

It may be worthwhile to teach the other lock primitives to pair
wfe/sev, but that requires some performance measurement to verify
it's actually worthwhile. So for now, we just make sure not to use
wfe when there's no sev, and keep everything else the same -- this
should fix severe performance degredation in libpthread on Arm
without hurting anything else.

No change in the generated code on amd64 and i386. No change in the
generated code for pthread_spin.c on arm and aarch64 -- changes only
the generated code for pthread_lock.c, pthread_mutex.c, and
pthread_rwlock.c, as intended.
PR port-arm/57437
 1.20.24.1 04-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #1878):

lib/libpthread/arch/x86_64/pthread_md.h: revision 1.13
lib/libpthread/pthread_int.h: revision 1.110
lib/libpthread/pthread_int.h: revision 1.111
lib/libpthread/arch/i386/pthread_md.h: revision 1.21
lib/libpthread/arch/arm/pthread_md.h: revision 1.12
lib/libpthread/arch/arm/pthread_md.h: revision 1.13
lib/libpthread/pthread_spin.c: revision 1.11
lib/libpthread/arch/aarch64/pthread_md.h: revision 1.2

libpthread: Use __nothing, not /* nothing */, for empty macros.

No functional change intended -- just safer to do it this way in case
the macros are used in if branches or comma expressions.
PR port-arm/57437 (pthread__smt_pause/wake issue)

libpthread: New pthread__smt_wait to put CPU in low power for spin.

This is now distinct from pthread__smt_pause, which is for spin lock
backoff with no paired wakeup.

On Arm, there is a single-bit event register per CPU, and there are two
instructions to manage it:
- wfe, wait for event -- if event register is clear, enter low power
mode and wait until event register is set; then exit low power mode
and clear event register
- sev, signal event -- sets event register on all CPUs (other
circumstances like interrupts also set the event register and cause
wfe to wake)

These can be used to reduce the power consumption of spinning for a
lock, but only if they are actually paired -- if there's no sev, wfe
might hang indefinitely. Currently only pthread_spin(3) actually
pairs them; the other lock primitives (internal lock, mutex, rwlock)
do not -- they have spin lock backoff loops, but no corresponding
wakeup to cancel a wfe.

It may be worthwhile to teach the other lock primitives to pair
wfe/sev, but that requires some performance measurement to verify
it's actually worthwhile. So for now, we just make sure not to use
wfe when there's no sev, and keep everything else the same -- this
should fix severe performance degredation in libpthread on Arm
without hurting anything else.

No change in the generated code on amd64 and i386. No change in the
generated code for pthread_spin.c on arm and aarch64 -- changes only
the generated code for pthread_lock.c, pthread_mutex.c, and
pthread_rwlock.c, as intended.
PR port-arm/57437
 1.10 02-Mar-2007  ad Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
 1.9 04-Jan-2006  skrll A couple of fixes to make libpthread really shared, i.e. not have text re-
locations:

- Don't declare pthread__switch_away global
- Do the PIC dance for pthread__switch_return_point and
pthread__locked_switch. Ideally these (and other) symbols would
be hidden.

Thanks to uwe@, dyoung@ and elad@ for help.

XXX sh3 is still to be done.
XXX vax does strange things.
 1.8 23-Apr-2004  simonb branches: 1.8.2;
s/the the/the/ (only in sources that aren't regularly imported from
elsewhere).
 1.7 30-Oct-2003  yamt use explicit "l" suffixes. (eg. lea -> leal)
 1.6 07-Sep-2003  cl Remove possible race condition in upcall recycling.
 1.5 26-Jun-2003  nathanw Adapt to pt_trapuc: change STACK_SWITCH to check for a value in pt_trapuc
and use it preferentially to a value in pt_uc, clearing it once on the new
stack. Move stores into pt_uc back to before the stack switch; storing
after the stack switch opened a one-instruction race condition where an upcall
that had just started a chain could be preempted again, and would bomb when
restarted due to its pt_uc not yet having been updated. Now that pt_trapuc
is what the upcall code writes to, it is safe to store to pt_uc before
switching stacks.

Remove obsolete pt_sleepuc code.
 1.4 12-Jun-2003  nathanw Two fixes:
* In switch-away cases, write PT_SWITCHTO last (after PT_SWITCHTOUC), so
that pthread__resolve_locks() doesn't see an empty SWITCHTOUC value. This
also permits pthread__resolve_locks() to use the presence of PT_SWITCHTO
as a sign that the thread has done all of its necessary chain work.

* Make the return-point of pthread__switch global and visible, so that its
address can be compared to the PC of a thread, again as a sign that its
chain-work is done.

(other architectures in progress, after they get the *previous* asm fix...)
 1.3 10-Feb-2003  fvdl Continue at the plain switch return point in pthread__switch, not the
locked one, in the !PIC case. From Tor Egge via Havard Eidnes.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 05-Mar-2001  nathanw branches: 1.1.2;
file pthread_switch.S was initially added on branch nathanw_sa.
 1.1.2.18 02-Jan-2003  nathanw Rewrite pthread__switch() and adjust pthread__locked_switch() to
avoid storing the new saved-context pointer while still using the old
stack. This avoids a race condition with pthread__find_interrupted()
where a thread could lose its old state if it was interrupted in a
certain window in pthread__switch() or pthread__locked_switch() (the
latter was never actually observed, but appeared possible).
 1.1.2.17 18-Dec-2002  nathanw Comment whitespace.
 1.1.2.16 18-Dec-2002  nathanw Tweak ucontext-alignment code so that it consumes at most 12 bytes of
stack space instead of 16, leaving 20 bytes avaliable.
 1.1.2.15 16-Sep-2002  skrll Fix typo in comment.
 1.1.2.14 06-Sep-2002  nathanw Ensure that stack regions allocated for storing ucontext_t's are
aligned to 16-byte boundaries; this ensures that the XMM save areas
are also 16-byte aligned, which is a requirement for use of the fxsave
and fxrstor instructions.
 1.1.2.13 14-Aug-2002  nathanw Define, initialize, and use function pointers for _{set,get,swap}context_u
routines, with different versions for saving FP state with fnsave or fxsave,
depending on the machdep.osfxsr sysctl.
 1.1.2.12 04-Sep-2001  nathanw Define STACKSPACE in pthread_md.h, not directly in pthread_switch.S
 1.1.2.11 01-Aug-2001  nathanw Rework the whole" ucontext vs. temporary crud on the bottom of the
stack" thing again, placing the burden of weirdness on STACK_SWITCH.

Add a lot of comments to explain why this is so tricky, and document
which functions are external.

In the old_preempt case of pthread__locked switch, save the thread's
real context so we don't try to switch back into the middle of this
code more than once.
 1.1.2.10 31-Jul-2001  nathanw Increase paranoia about keeping the ucontext on the bottom of the
stack: Find the location to put it, but don't move $esp there, so that
subsequent caller-save arguments and return addresses are above it
rather than below it.
 1.1.2.9 31-Jul-2001  nathanw Actually, we *do* need pthread__switch in assembler, in order that
the ucontext_t be the last thing on the stack. Otherwise, the switch
code will overwrite stack data, since it sets the stack to pt_uc.

Use the UT_EIP symbolic constant.

When performing a new_preempt, store into pt_switchto and
pt_switchtouc of the *new* thread, so that resolve_locks stands a
chance of finding the switchto victim.
 1.1.2.8 26-Jul-2001  nathanw pthread__switch() no longer needs to be implemeted in assembler,
and doesn't have a lock parameter.
 1.1.2.7 24-Jul-2001  nathanw Substantial rework:
- Make pthread__switch() just a plain switch, and move the
switch-to-next code to pthread__switch_away. Saves a stack switch,
test, and branch in the pthread_switch case, a _getcontext_u() and
associated stack frobbing in the switch_away case, and several
points of sanity.
- Remove a poorly-thought-out ucontext-dodge in STACK_SWITCH.
- Fill in PT_SWITCHTO and PT_SWITCHTOUC in the new_preempt path as
well as the old_preempt path in pthread__locked_switch() and
pthread__upcall_switch().
 1.1.2.6 23-Jul-2001  nathanw Pushing parameters on the stack is not the same as preserving their
values.
 1.1.2.5 20-Jul-2001  nathanw The %esi and %edi registers are callee-save, not caller-save.
 1.1.2.4 16-Jul-2001  nathanw Make pthread__switch() actually decrement fake spinlock counts when
told to do so by pthread__upcall_switch() or pthread__lock_switch().
 1.1.2.3 13-Jul-2001  nathanw Note copyright.
Standardize RCS IDs.
 1.1.2.2 29-Mar-2001  nathanw Don't frob pt_spinlocks in pthread__switch; we don't use it for
switching with locks held.
 1.1.2.1 05-Mar-2001  nathanw The beginnings of a scheduler activations-based pthread library.
 1.8.2.1 08-Jan-2006  riz Pull up following revision(s) (requested by skrll in ticket #1093):
lib/libpthread/arch/sparc/pthread_switch.S: revision 1.8
lib/libpthread/arch/x86_64/pthread_switch.S: revision 1.11
lib/libpthread/arch/sparc64/pthread_switch.S: revision 1.9
lib/libpthread/arch/i386/pthread_switch.S: revision 1.9
A couple of fixes to make libpthread really shared, i.e. not have text re-
locations:
- Don't declare pthread__switch_away global
- Do the PIC dance for pthread__switch_return_point and
pthread__locked_switch. Ideally these (and other) symbols would
be hidden.
Thanks to uwe@, dyoung@ and elad@ for help.
XXX sh3 is still to be done.
XXX vax does strange things.
 1.4 08-Oct-1997  scottr This incarnation of the pthreads library is ancient and not useful, and
should have been mothballed some time ago...
 1.3 07-Feb-1994  proven More wrapper functions, and some hacks for machine independent sleep
mechanisms.
 1.2 27-Jan-1994  mycroft Stylistic change.
 1.1 14-Nov-1993  proven branches: 1.1.1;
Initial revision
 1.1.1.1 14-Nov-1993  proven Initial release of the POSIX 1003.4a Draft 7 thread implementation.
 1.1 17-Apr-2015  martin Dummy ia64 support
 1.6 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.5 28-Apr-2008  martin branches: 1.5.8;
Remove clause 3 and 4 from TNF licenses
 1.4 12-Oct-2003  chs branches: 1.4.32;
fix typo in previous.
 1.3 01-Mar-2003  scw Don't use FP instructions when building for m68010. Fixes broken sun2 build.
G/C some unused code.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 18-Nov-2001  scw branches: 1.1.2;
file _context_u.S was initially added on branch nathanw_sa.
 1.1.2.7 01-Dec-2001  scw Small cleanup of FP register context goo.
 1.1.2.6 25-Nov-2001  scw Checkpoint user-land context switch glue.

This code still needs some more thought, specifically for FPU context
save/restore. On m68k, it is not possible to completely save/restore
full FPU context from user-mode.
 1.1.2.5 21-Nov-2001  scw Don't bother stashing the CCR in the saved context; it's effectively a
caller saved register. Instead, clear the full 32-bit REG_PS value in
the context since the kernel's setcontext() call validates all 32-bits.

Also overwrite uc_flags with _UC_CPU instead of a logical OR.
 1.1.2.4 20-Nov-2001  scw Can't "rts" at the end of _getcontext_u() since we've already popped
the return address. Fortunately, it's in %a1 so just jmp to it.
 1.1.2.3 19-Nov-2001  scw Set the UC_CPU bit in UC_FLAGS for the GETC case.
Pointed out by Nathan Williams.
 1.1.2.2 19-Nov-2001  scw Tweak the context save/restore code; the first cut was a bit too simplistic.
 1.1.2.1 18-Nov-2001  scw Initial cut of m68k-specific pthreads backend.
Compiles, but testing will have to wait until I've had some sleep.
 1.4.32.1 18-May-2008  yamt sync with head.
 1.5.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.5.8.1 28-Apr-2008  martin file _context_u.S was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.8 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.7 28-Apr-2008  martin branches: 1.7.8;
Remove clause 3 and 4 from TNF licenses
 1.6 02-Mar-2007  ad branches: 1.6.12;
Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
 1.5 07-Sep-2003  cl Remove possible race condition in upcall recycling.
 1.4 17-Jul-2003  nathanw Adapt to structure name changes.
 1.3 26-Jun-2003  nathanw Remove PT_SLEEPUC and add PT_TRAPUC.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 18-Nov-2001  scw branches: 1.1.2;
file genassym.cf was initially added on branch nathanw_sa.
 1.1.2.4 01-Dec-2001  scw Small cleanup of FP register context goo.
 1.1.2.3 25-Nov-2001  scw Add defines for FP registers and for some more uc_flags values.
Ditch CONTEXTSIZE in favour of RND_CTXSIZE which ensure the stack
is always longword aligned (and it brings m68k into line with most
other ports).
 1.1.2.2 19-Nov-2001  scw Tweak the context save/restore code; the first cut was a bit too simplistic.
 1.1.2.1 18-Nov-2001  scw Initial cut of m68k-specific pthreads backend.
Compiles, but testing will have to wait until I've had some sleep.
 1.6.12.1 18-May-2008  yamt sync with head.
 1.7.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.7.8.1 28-Apr-2008  martin file genassym.cf was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.6 25-Nov-2003  christos This is not needed anymore.
 1.5 22-Sep-2003  cl SA_SIGINFO support for m68k (libpthread)
 1.4 26-Jul-2003  mrg need <string.h>
 1.3 08-Mar-2003  lukem add __RCSID()
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 16-Jan-2003  thorpej branches: 1.1.2;
file pthread_md.c was initially added on branch nathanw_sa.
 1.1.2.1 16-Jan-2003  thorpej * Move the pthread_sigmask() prototype to <signal.h>.
* Don't include <signal.h> in <pthread.h>.
* Add code to the signal trampoline to convert from the ucontext
to a sigcontext, and back again (XXX though, only callee-save
regs for _UC_USER contexts).

This is necessary in order to support e.g. GCC's libjava, which depends
on the traditional Unix semantics of changes made to the sigcontext
being visible when the handler returns.
 1.8 25-Jan-2011  christos make pthread__sp unsigned long.
 1.7 16-May-2009  ad branches: 1.7.2;
Remove unused code that's confusing when using cscope/opengrok.
 1.6 28-Apr-2008  martin branches: 1.6.8;
Remove clause 3 and 4 from TNF licenses
 1.5 10-Feb-2008  ad branches: 1.5.4;
- Remove libpthread's atomic ops.
- Remove the old spinlock-based mutex and rwlock implementations.
- Use the atomic ops from libc.
 1.4 24-Dec-2005  perry branches: 1.4.12;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.3 25-Nov-2003  christos m68k does not sigcontext<->mcontext anymore.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 18-Nov-2001  scw branches: 1.1.2;
file pthread_md.h was initially added on branch nathanw_sa.
 1.1.2.5 16-Jan-2003  thorpej * Move the pthread_sigmask() prototype to <signal.h>.
* Don't include <signal.h> in <pthread.h>.
* Add code to the signal trampoline to convert from the ucontext
to a sigcontext, and back again (XXX though, only callee-save
regs for _UC_USER contexts).

This is necessary in order to support e.g. GCC's libjava, which depends
on the traditional Unix semantics of changes made to the sigcontext
being visible when the handler returns.
 1.1.2.4 06-Aug-2002  nathanw struct reg/ucontext conversion glue.
 1.1.2.3 28-Jul-2002  gmcgarry _REG_SP -> _REG_A7 to match definition in mcontext.h.
 1.1.2.2 19-Nov-2001  scw The right value for STACKSPACE is 12, for 3 integer values in this
implementation. (Actually, we only need 10; 2 ints, 1 short, but best
to keep the stack long-word aligned).
 1.1.2.1 18-Nov-2001  scw Initial cut of m68k-specific pthreads backend.
Compiles, but testing will have to wait until I've had some sleep.
 1.4.12.1 23-Mar-2008  matt sync with HEAD
 1.5.4.1 18-May-2008  yamt sync with head.
 1.6.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.6.8.1 28-Apr-2008  martin file pthread_md.h was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.7.2.1 08-Feb-2011  bouyer Sync with HEAD
 1.8 02-Mar-2007  ad Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
 1.7 23-Apr-2004  simonb s/the the/the/ (only in sources that aren't regularly imported from
elsewhere).
 1.6 17-Sep-2003  cl fix pt_trapuc handling errors:
- movl to address register doesn't set flags (add explicit test)
- clr only clears a word (use clrl)
 1.5 07-Sep-2003  cl Remove possible race condition in upcall recycling.
 1.4 26-Jun-2003  nathanw Adapt to pt_trapuc: change STACK_SWITCH to check for a value in pt_trapuc
and use it preferentially to a value in pt_uc, clearing it once on the new
stack. Move stores into pt_uc back to before the stack switch; storing
after the stack switch opened a one-instruction race condition where an upcall
that had just started a chain could be preempted again, and would bomb when
restarted due to its pt_uc not yet having been updated. Now that pt_trapuc
is what the upcall code writes to, it is safe to store to pt_uc before
switching stacks.

Remove obsolete pt_sleepuc code.
 1.3 13-Jun-2003  scw Apply Nathan's switch-away fix and previous save-PT_UC from new stack fix.
Compile-tested only.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 18-Nov-2001  scw branches: 1.1.2;
file pthread_switch.S was initially added on branch nathanw_sa.
 1.1.2.4 01-Dec-2001  scw G/C a superfluous assignment, and fix a PT_SWITCHTOUC bogon which
managed to creep in with the last change...
 1.1.2.3 25-Nov-2001  scw Cleanup of the thread switching MD glue.

With these changes, m68k now passes all Nathan's pthreads tests.
 1.1.2.2 20-Nov-2001  scw Fix a botched reference to a local label.
 1.1.2.1 18-Nov-2001  scw Initial cut of m68k-specific pthreads backend.
Compiles, but testing will have to wait until I've had some sleep.
 1.4 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.3 07-Aug-2003  agc branches: 1.3.48;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 28-Nov-2001  wdk branches: 1.1.2;
file SYS.h was initially added on branch nathanw_sa.
 1.1.2.5 01-Dec-2002  wdk Remove nop
 1.1.2.4 24-Nov-2002  wdk Use __ABICALLS__
 1.1.2.3 23-Nov-2002  wdk PIC_CALL macros had a major side effect - last instruction has a jump
with an unfilled bdslot. Add nop instruction to ensure no side effect
and let the assembler try and remove it.
 1.1.2.2 20-Nov-2002  wdk Jump could not represent target in direct addressing mode.
Error discovered by current toolchain.
 1.1.2.1 28-Nov-2001  wdk Initial pthread support for Mips processors.
 1.3.48.1 16-Aug-2009  matt Make ABI agonstic (first pass).
 1.4 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.3 28-Apr-2008  martin branches: 1.3.8; 1.3.14;
Remove clause 3 and 4 from TNF licenses
 1.2 18-Jan-2003  thorpej branches: 1.2.34;
Merge the nathanw_sa branch.
 1.1 28-Nov-2001  wdk branches: 1.1.2;
file _context_u.S was initially added on branch nathanw_sa.
 1.1.2.3 01-Dec-2002  wdk - Use LEAF functions when nexted calls are not used.
- Reorder branch-delay slots and let teh assembler do the hard work.
 1.1.2.2 29-Nov-2001  wdk setcontext macro incorrectly used the RA (return address) as the target
PC to start the new context (RA == PC in getcontext so one may be lead
to believe it wouldn't matter).
Since the pthread__locked_switch() function updates the PC value we
must use the PC value in the context.

While we are the use T9 register for target PC value to maintain calling
conventions.
 1.1.2.1 28-Nov-2001  wdk Initial pthread support for Mips processors.
 1.2.34.1 18-May-2008  yamt sync with head.
 1.3.14.3 29-Apr-2011  matt Pull in fixes from -current.
 1.3.14.2 24-Aug-2009  matt Fix typo
 1.3.14.1 16-Aug-2009  matt Make ABI agonstic (first pass).
 1.3.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.3.8.1 28-Apr-2008  martin file _context_u.S was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.8 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.7 28-Apr-2008  martin branches: 1.7.8; 1.7.14;
Remove clause 3 and 4 from TNF licenses
 1.6 02-Mar-2007  ad branches: 1.6.14;
Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
 1.5 07-Sep-2003  cl Remove possible race condition in upcall recycling.
 1.4 17-Jul-2003  nathanw Adapt to structure name changes.
 1.3 26-Jun-2003  nathanw Remove PT_SLEEPUC and add PT_TRAPUC.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 28-Nov-2001  wdk branches: 1.1.2;
file genassym.cf was initially added on branch nathanw_sa.
 1.1.2.1 28-Nov-2001  wdk Initial pthread support for Mips processors.
 1.6.14.1 18-May-2008  yamt sync with head.
 1.7.14.1 16-Aug-2009  matt Make ABI agonstic (first pass).
 1.7.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.7.8.1 28-Apr-2008  martin file genassym.cf was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.9 25-Jan-2011  christos make pthread__sp unsigned long.
 1.8 16-May-2009  ad branches: 1.8.2;
Remove unused code that's confusing when using cscope/opengrok.
 1.7 28-Apr-2008  martin branches: 1.7.8;
Remove clause 3 and 4 from TNF licenses
 1.6 24-Dec-2005  perry branches: 1.6.22;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.5 03-Jul-2004  simonb Catch up with changes to __fpregset_t.
In __longjmp14(), copy the FP CSR from the correct array and array slot.

Completes fix for PR port-mips/25942.
 1.4 26-Nov-2003  he branches: 1.4.2;
Hide the register number constants behind an _R_ prefix, and also
rename FPBASE to _FPBASE, so that we avoid polluting the user's
name space when e.g. <sys/ptrace.h> is included. Previously, the
PC symbol in mips/regnum.h would conflict with the declaration of
the external variable by the same name in termcap.h, as discovered
by the ``okheaders'' regression test.
 1.3 12-Jun-2003  nathanw STACKSPACE of 16 is too small, given the use of CALLFRAME_SIZ;
increase to match.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 28-Nov-2001  wdk branches: 1.1.2;
file pthread_md.h was initially added on branch nathanw_sa.
 1.1.2.5 20-Dec-2002  thorpej Update for mcontext_t changes.
 1.1.2.4 05-Dec-2002  thorpej Fix the reg <--> mcontext conversion macros. The reg structure is
equivalent to the frame structure, which has a slightly different
layout from the mcontext.
 1.1.2.3 01-Dec-2002  wdk Implement libpthread_dbg conversion macros.
 1.1.2.2 29-Nov-2001  wdk Drop STACKSPACE to 16 bytes
 1.1.2.1 28-Nov-2001  wdk Initial pthread support for Mips processors.
 1.4.2.1 04-Jul-2004  he Pull up revision 1.5 (requested by simonb in ticket #591):
Changes fixing PR#25942:
o Catch up with changes to __fpregset_t. In __longjmp14(),
copy the FP CSR from the correct array and array slot.
 1.6.22.1 18-May-2008  yamt sync with head.
 1.7.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.7.8.1 28-Apr-2008  martin file pthread_md.h was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.8.2.1 08-Feb-2011  bouyer Sync with HEAD
 1.7 02-Mar-2007  ad Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
 1.6 07-Sep-2003  cl Remove possible race condition in upcall recycling.
 1.5 26-Jun-2003  nathanw Adapt to pt_trapuc: change STACK_SWITCH to check for a value in pt_trapuc
and use it preferentially to a value in pt_uc, clearing it once on the new
stack. Move stores into pt_uc back to before the stack switch; storing
after the stack switch opened a one-instruction race condition where an upcall
that had just started a chain could be preempted again, and would bomb when
restarted due to its pt_uc not yet having been updated. Now that pt_trapuc
is what the upcall code writes to, it is safe to store to pt_uc before
switching stacks.

Remove obsolete pt_sleepuc code.
 1.4 12-Jun-2003  nathanw Oops, that's switch_return_point, not locked_return_point. The perils
of cut-and-paste.
 1.3 12-Jun-2003  nathanw Apply switch-away fix and previous save-PT_UC from new stack fix.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 28-Nov-2001  wdk branches: 1.1.2;
file pthread_switch.S was initially added on branch nathanw_sa.
 1.1.2.4 01-Dec-2002  wdk Reorder branch-delay slot usage, and remove nop's

cond5 test with type 5 upcalls now work!!
 1.1.2.3 24-Nov-2002  wdk Use __ABICALLS__
 1.1.2.2 20-Nov-2002  wdk Use CALLFRAME_RA and CALLFRAME_SIZ instead of static contants.
 1.1.2.1 28-Nov-2001  wdk Initial pthread support for Mips processors.
 1.1 03-Sep-2014  matt New files for OR1K support
 1.6 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.5 10-Jul-2004  nathanw When _SOFT_FLOAT is defined, don't save or restore user FP context.
(note: still needs some mk rules tweaking for MKSOFTFLOAT=yes to pass
-msoft-float to asm builds).
 1.4 02-Jun-2004  nathanw Remove a comment made obsolete by the previous commit.
 1.3 12-Jun-2003  nathanw branches: 1.3.4;
Don't need to set the MSR field here; _INITCONTEXT_U_MD() takes care
of that where necessary.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 13-Nov-2001  briggs branches: 1.1.2;
file _context_u.S was initially added on branch nathanw_sa.
 1.1.2.7 08-Aug-2002  nathanw Use register prefixes everywhere, now that asm.h no longer provides
the intermediate-format macros.
 1.1.2.6 21-Nov-2001  briggs Preserve LR and use CTR to hold new PC when setting new context.
 1.1.2.5 21-Nov-2001  briggs Save FP state as well as integer state.
Save reasonable constant in MSR (supervisor-only).
 1.1.2.4 20-Nov-2001  briggs Some cleanup.
 1.1.2.3 19-Nov-2001  briggs Use r prefixes for registers.
 1.1.2.2 17-Nov-2001  briggs Change SETC to use a fixed register (r4).
 1.1.2.1 13-Nov-2001  briggs Initial stab at pthread support for PPC.
 1.3.4.1 18-May-2005  riz Pull up revision 1.4 (requested by matt in ticket #1526):
Remove a comment made obsolete by the previous commit.
 1.8 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.7 02-Mar-2007  ad Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
 1.6 07-Sep-2003  cl Remove possible race condition in upcall recycling.
 1.5 17-Jul-2003  nathanw Adapt to structure name changes.
 1.4 26-Jun-2003  nathanw Remove PT_SLEEPUC and add PT_TRAPUC.
 1.3 20-Jan-2003  matt Add _REG_foo to ppc mcontext and use them instead of constants.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 13-Nov-2001  briggs branches: 1.1.2;
file genassym.cf was initially added on branch nathanw_sa.
 1.1.2.2 21-Nov-2001  briggs Save FP state as well as integer state.
Save reasonable constant in MSR (supervisor-only).
 1.1.2.1 13-Nov-2001  briggs Initial stab at pthread support for PPC.
 1.9 11-Apr-2020  rin Revert previous:
http://mail-index.netbsd.org/source-changes/2020/02/20/msg114173.html

Comment turned out to be wrong, and KASSERT fires for oea.

XXX
Need to revisit shortly...
 1.8 20-Feb-2020  rin libpthread sets initial value of MSR for lwp's. However, appropriate
value differs b/w oea/booke/ibm4xx, and there's no way to obtain it
from userland. Therefore, this initial value should be corrected by
cpu_setmcontext().

- Comment this in libpthread
- Add KASSERT in cpu_mcontext_validate()
 1.7 25-Jan-2011  christos branches: 1.7.44; 1.7.46;
make pthread__sp unsigned long.
 1.6 16-May-2009  ad branches: 1.6.2;
Remove unused code that's confusing when using cscope/opengrok.
 1.5 24-Dec-2005  perry Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.4 11-Feb-2004  nathanw Add ucontext conversion macros for an "extra" register set.
 1.3 20-Jan-2003  matt Add _REG_foo to ppc mcontext and use them instead of constants.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 13-Nov-2001  briggs branches: 1.1.2;
file pthread_md.h was initially added on branch nathanw_sa.
 1.1.2.8 16-Jan-2003  thorpej * Move the pthread_sigmask() prototype to <signal.h>.
* Don't include <signal.h> in <pthread.h>.
* Add code to the signal trampoline to convert from the ucontext
to a sigcontext, and back again (XXX though, only callee-save
regs for _UC_USER contexts).

This is necessary in order to support e.g. GCC's libjava, which depends
on the traditional Unix semantics of changes made to the sigcontext
being visible when the handler returns.
 1.1.2.7 06-Dec-2002  nathanw sigcontext/ucontext glue.
 1.1.2.6 22-Oct-2002  nathanw Define _INITCONTEXT_U_MD() to set the MSR to a reasonable value.
 1.1.2.5 24-Apr-2002  nathanw Add macros to convert between struct ucontext and struct reg/fpreg.
 1.1.2.4 23-Mar-2002  nathanw Change operand constraint of "mr %0,1" from "=g" to "=r", since mr
really wants a register.

This fixes -g powerpc builds.
 1.1.2.3 20-Nov-2001  briggs Some cleanup.
 1.1.2.2 14-Nov-2001  briggs Add pthread__uc_pc() to pthread_md.h instead of making assumptions about
the contents of the m.d. mcontext.
 1.1.2.1 13-Nov-2001  briggs Initial stab at pthread support for PPC.
 1.6.2.1 08-Feb-2011  bouyer Sync with HEAD
 1.7.46.2 12-Apr-2020  martin Pull up following revision(s) (requested by rin in ticket #826):

lib/libpthread/arch/powerpc/pthread_md.h: revision 1.9
sys/arch/powerpc/powerpc/sig_machdep.c: revision 1.48

Revert previous:
http://mail-index.netbsd.org/source-changes/2020/02/20/msg114173.html
Comment turned out to be wrong, and KASSERT fires for oea.

XXX
Need to revisit shortly...
 1.7.46.1 27-Feb-2020  martin Pull up following revision(s) (requested by rin in ticket #736):

lib/libpthread/arch/powerpc/pthread_md.h: revision 1.8
sys/arch/powerpc/powerpc/sig_machdep.c: revision 1.47

libpthread sets initial value of MSR for lwp's. However, appropriate
value differs b/w oea/booke/ibm4xx, and there's no way to obtain it
from userland. Therefore, this initial value should be corrected by
cpu_setmcontext().

- Comment this in libpthread
- Add KASSERT in cpu_mcontext_validate()
 1.7.44.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.7.44.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.11 02-Mar-2007  ad Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
 1.10 08-Jul-2006  ross remove unreferenced temporary label
 1.9 07-Jul-2004  nathanw Fix a comment to say "Edit" instead of "Exit".
 1.8 07-Sep-2003  cl Remove possible race condition in upcall recycling.
 1.7 26-Jun-2003  nathanw Adapt to pt_trapuc: change STACK_SWITCH to check for a value in pt_trapuc
and use it preferentially to a value in pt_uc, clearing it once on the new
stack. Move stores into pt_uc back to before the stack switch; storing
after the stack switch opened a one-instruction race condition where an upcall
that had just started a chain could be preempted again, and would bomb when
restarted due to its pt_uc not yet having been updated. Now that pt_trapuc
is what the upcall code writes to, it is safe to store to pt_uc before
switching stacks.

Remove obsolete pt_sleepuc code.
 1.6 24-Jun-2003  nathanw Oops, reordering the PT_STATE/PT_SWITCHTOUC/PT_SWITCHTO assembly
killed a live value too soon. Fix by using a different register for
the PT_STATE immediate.
 1.5 23-Jun-2003  nathanw Update the switch_return point name in the static case.
 1.4 12-Jun-2003  nathanw Two fixes:
* In switch-away cases, write PT_SWITCHTO last (after PT_SWITCHTOUC), so
that pthread__resolve_locks() doesn't see an empty SWITCHTOUC value. This
also permits pthread__resolve_locks() to use the presence of PT_SWITCHTO
as a sign that the thread has done all of its necessary chain work.

* Make the return-point of pthread__switch global and visible, so that its
address can be compared to the PC of a thread, again as a sign that its
chain-work is done.

(other architectures in progress, after they get the *previous* asm fix...)
 1.3 06-Jun-2003  nathanw Fix typo in comment.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 13-Nov-2001  briggs branches: 1.1.2;
file pthread_switch.S was initially added on branch nathanw_sa.
 1.1.2.10 14-Jan-2003  nathanw Rewrite pthread__switch() and adjust pthread__locked_switch() to
avoid storing the new saved-context pointer while still using the old
stack. This avoids a race condition with pthread__find_interrupted()
where a thread could lose its old state if it was interrupted in a
certain window in pthread__switch().
 1.1.2.9 09-Nov-2002  nathanw Make pthread__locked_switch() work in a PIC world, now that the linker
is less lenient.

XXX the stack usage is probably overkill for the required alignment.
 1.1.2.8 08-Aug-2002  nathanw Use register prefixes everywhere, now that asm.h no longer provides
the intermediate-format macros.
 1.1.2.7 02-May-2002  nathanw Restore all three registers that are saved before the call to
pthread__sa_recycle. Fixes a problem where pt_switchtouc would end up
containing a small integer, rather than the ucontext pointer.
 1.1.2.6 26-Nov-2001  briggs Correct offset of ucontext on stack in pthread__switch().
Correct saved ucontext in PT_SLEEPUC in pthread__locked_switch().
 1.1.2.5 21-Nov-2001  briggs Update a couple of offsets I missed in earlier stack alignment.
 1.1.2.4 20-Nov-2001  briggs Some cleanup.
 1.1.2.3 19-Nov-2001  briggs Use r prefixes for registers.
 1.1.2.2 16-Nov-2001  briggs What crack was I on to use reg 0 in an addi instruction?
 1.1.2.1 13-Nov-2001  briggs Initial stab at pthread support for PPC.
 1.3 07-May-2023  skrll RISC-V support that works on QEMU with a single hart.

Thanks for Simon Burge for plic(4).
 1.2 31-Mar-2015  matt We have _REG_SP so use it.
 1.1 19-Sep-2014  matt New files for Userland support of UCB RISC-V (both 32-bit and 64-bit)
 1.7 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.6 01-Jun-2008  uwe branches: 1.6.6;
Recycle unused _REG_EXPEVT slot in mcontext for _REG_GBR.

As the size of mcontext is not changed, we avoid the hassle of
versioning all the calls that use it.

_REG_EXPEVT was never used by any code in the tree. Reporting EXPEVT
makes sense only for signals and in that case we pass it to userland
in ksi_trap already which is official MI way to get this (MD) information.

Old binaries running on new kernels will now have their GBR set from
new mcontext, but that's ok too, as GBR was not properly supported by
old kernels (not saved in trapframe), so old binaries couldn't have
possibly used it anyway.
 1.5 04-Jan-2006  uwe branches: 1.5.20; 1.5.22;
In PIC code call setcontext(2) via PLT to avoid text reloc in the
shared library.
 1.4 17-Nov-2003  uwe branches: 1.4.6;
Cause SIGTRAP if NOTREACHED code is reached.
 1.3 05-Jul-2003  uwe Not that the branch in SETC doens't have a delay slot, remove the
.empty comment as it's no longer pertinent.
 1.2 05-Jul-2003  marcus PIC patch from Valeriy E. Ushakov applied.
Also, removed bogus delay slot flag from branch instruction.
 1.1 23-Jun-2003  uwe First bits of SH3 support. Only _context_u.S is implemented (passess
cu[1-6] tests), the pthread_switch.S is stubbed out for now.

Code posted by Christian Groessler (cpg at aladdin dot de) to port-sh3.
 1.4.6.1 11-Jan-2006  tron Pull up following revision(s) (requested by uwe in ticket #1095):
lib/libpthread/arch/sh3/_context_u.S: revision 1.5
In PIC code call setcontext(2) via PLT to avoid text reloc in the
shared library.
 1.5.22.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.5.20.1 04-Jun-2008  yamt sync with head
 1.6.6.2 01-Jun-2008  uwe Recycle unused _REG_EXPEVT slot in mcontext for _REG_GBR.

As the size of mcontext is not changed, we avoid the hassle of
versioning all the calls that use it.

_REG_EXPEVT was never used by any code in the tree. Reporting EXPEVT
makes sense only for signals and in that case we pass it to userland
in ksi_trap already which is official MI way to get this (MD) information.

Old binaries running on new kernels will now have their GBR set from
new mcontext, but that's ok too, as GBR was not properly supported by
old kernels (not saved in trapframe), so old binaries couldn't have
possibly used it anyway.
 1.6.6.1 01-Jun-2008  uwe file _context_u.S was added on branch christos-time_t on 2008-06-01 23:07:21 +0000
 1.9 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.8 01-Jun-2008  uwe branches: 1.8.6;
Recycle unused _REG_EXPEVT slot in mcontext for _REG_GBR.

As the size of mcontext is not changed, we avoid the hassle of
versioning all the calls that use it.

_REG_EXPEVT was never used by any code in the tree. Reporting EXPEVT
makes sense only for signals and in that case we pass it to userland
in ksi_trap already which is official MI way to get this (MD) information.

Old binaries running on new kernels will now have their GBR set from
new mcontext, but that's ok too, as GBR was not properly supported by
old kernels (not saved in trapframe), so old binaries couldn't have
possibly used it anyway.
 1.7 28-Apr-2008  martin branches: 1.7.2;
Remove clause 3 and 4 from TNF licenses
 1.6 02-Mar-2007  ad branches: 1.6.12;
Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
 1.5 18-Nov-2003  uwe Add necessary symbols.
 1.4 07-Sep-2003  cl Remove possible race condition in upcall recycling.
 1.3 17-Jul-2003  nathanw Adapt to structure name changes.
 1.2 05-Jul-2003  marcus The field "pt_sleepuc" doesn't exist in struct pthread_st.
 1.1 23-Jun-2003  uwe First bits of SH3 support. Only _context_u.S is implemented (passess
cu[1-6] tests), the pthread_switch.S is stubbed out for now.

Code posted by Christian Groessler (cpg at aladdin dot de) to port-sh3.
 1.6.12.2 04-Jun-2008  yamt sync with head
 1.6.12.1 18-May-2008  yamt sync with head.
 1.7.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.8.6.2 01-Jun-2008  uwe Recycle unused _REG_EXPEVT slot in mcontext for _REG_GBR.

As the size of mcontext is not changed, we avoid the hassle of
versioning all the calls that use it.

_REG_EXPEVT was never used by any code in the tree. Reporting EXPEVT
makes sense only for signals and in that case we pass it to userland
in ksi_trap already which is official MI way to get this (MD) information.

Old binaries running on new kernels will now have their GBR set from
new mcontext, but that's ok too, as GBR was not properly supported by
old kernels (not saved in trapframe), so old binaries couldn't have
possibly used it anyway.
 1.8.6.1 01-Jun-2008  uwe file genassym.cf was added on branch christos-time_t on 2008-06-01 23:07:21 +0000
 1.8 25-Jan-2011  christos make pthread__sp unsigned long.
 1.7 16-May-2009  ad branches: 1.7.2;
Remove unused code that's confusing when using cscope/opengrok.
 1.6 27-Oct-2008  uwe branches: 1.6.4;
Fix typo in comment.
 1.5 27-Oct-2008  uwe Pull down revision 1.3.6.1 by skrll@ (adapted to include reg::r_gbr).

struct mcontext != struct reg on sh3.

Fix PTHREAD_UCONTEXT_TO_REG / PTHREAD_REG_TO_UCONTEXT to deal with this.
 1.4 10-Feb-2008  ad - Remove libpthread's atomic ops.
- Remove the old spinlock-based mutex and rwlock implementations.
- Use the atomic ops from libc.
 1.3 24-Dec-2005  perry branches: 1.3.4; 1.3.6; 1.3.12;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.2 20-Nov-2003  uwe Add _INITCONTEXT_U_MD, we need to clean _REG_SR.
 1.1 23-Jun-2003  uwe First bits of SH3 support. Only _context_u.S is implemented (passess
cu[1-6] tests), the pthread_switch.S is stubbed out for now.

Code posted by Christian Groessler (cpg at aladdin dot de) to port-sh3.
 1.3.12.1 23-Mar-2008  matt sync with HEAD
 1.3.6.1 26-Feb-2008  skrll struct mcontext != struct reg on sh3.

Fix PTHREAD_UCONTEXT_TO_REG / PTHREAD_REG_TO_UCONTEXT to deal with this.
 1.3.4.1 16-Sep-2008  bouyer Sync with the following revisions (requested by skrll in ticket #1196):
gnu/dist/gdb removed
gnu/usr.bin/gdb53 removed
distrib/cats/instkernel/Makefile 1.14.6.1
gnu/dist/gdb6/bfd/config.bfd 1.3.6.1
gnu/dist/gdb6/bfd/elfxx-sparc.c 1.1.1.2.6.1
gnu/dist/gdb6/bfd/elfxx-sparc.h 1.1.1.2.6.1
gnu/dist/gdb6/gdb/Makefile.in 1.2.2.1.2.2
gnu/dist/gdb6/gdb/alpha-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/alpha-tdep.h 1.1.1.2.6.1
gnu/dist/gdb6/gdb/alphabsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/alphabsd-nat.h 1.1.2.1
gnu/dist/gdb6/gdb/alphabsd-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/alphabsd-tdep.h 1.1.1.2.6.1
gnu/dist/gdb6/gdb/alphanbsd-nat.c 1.1.2.1
gnu/dist/gdb6/gdb/alphanbsd-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/amd64-nat.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/amd64bsd-nat.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/amd64nbsd-nat.c 1.1.1.2.6.3
gnu/dist/gdb6/gdb/amd64nbsd-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/arm-tdep.h 1.1.1.2.6.1
gnu/dist/gdb6/gdb/armbsd-tdep.c 1.1.2.1
gnu/dist/gdb6/gdb/armnbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/armnbsd-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/configure 1.1.1.2.6.1
gnu/dist/gdb6/gdb/configure.ac 1.1.1.2.6.1
gnu/dist/gdb6/gdb/i386bsd-nat.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/i386nbsd-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/m68kbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/mipsnbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/nbsd-thread.c 1.1.2.3
gnu/dist/gdb6/gdb/ppcnbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/ppcnbsd-tdep.c 1.3.6.1
gnu/dist/gdb6/gdb/sh-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/shnbsd-nat.c 1.1.1.2.6.3
gnu/dist/gdb6/gdb/shnbsd-tdep.c 1.1.1.2.6.4
gnu/dist/gdb6/gdb/shnbsd-tdep.h 1.1.1.2.6.1
gnu/dist/gdb6/gdb/sparc-nat.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/sparc64nbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/sparcnbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/tramp-frame.h 1.1.1.2.6.1
gnu/dist/gdb6/gdb/vaxbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/config/alpha/nbsd.mh 1.1.1.2.6.1
gnu/dist/gdb6/gdb/config/arm/nbsd.mt 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/arm/nbsdelf.mh 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/i386/nbsd64.mh 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/m68k/nbsdelf.mh 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/mips/nbsd.mh 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/powerpc/nbsd.mh 1.1.1.2.6.1
gnu/dist/gdb6/gdb/config/sh/nbsd.mh 1.1.1.1.6.2
gnu/dist/gdb6/gdb/config/sh/tm-nbsd.h 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/sparc/nbsd64.mh 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/sparc/nbsdelf.mh 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/vax/nbsdelf.mh 1.1.1.1.6.1
gnu/dist/gdb6/opcodes/configure 1.1.1.2.6.1
gnu/dist/gdb6/opcodes/configure.in 1.1.1.2.6.1
gnu/usr.bin/Makefile 1.126.4.1
gnu/usr.bin/gdb6/arch/alpha/config.h 1.3.4.1
gnu/usr.bin/gdb6/arch/alpha/defs.mk 1.2.6.1
gnu/usr.bin/gdb6/arch/alpha/init.c 1.2.6.1
gnu/usr.bin/gdb6/arch/alpha/nm.h 1.2.6.1
gnu/usr.bin/gdb6/arch/arm/defs.mk 1.2.6.2
gnu/usr.bin/gdb6/arch/arm/init.c 1.1.6.1
gnu/usr.bin/gdb6/arch/armeb/config.h 1.1.6.2
gnu/usr.bin/gdb6/arch/armeb/defs.mk 1.1.6.3
gnu/usr.bin/gdb6/arch/armeb/init.c 1.1.6.2
gnu/usr.bin/gdb6/arch/armeb/tm.h 1.1.6.2
gnu/usr.bin/gdb6/arch/armeb/version.c 1.1.6.2
gnu/usr.bin/gdb6/arch/i386/defs.mk 1.4.4.1
gnu/usr.bin/gdb6/arch/i386/init.c 1.3.6.1
gnu/usr.bin/gdb6/arch/m68000/config.h 1.1.6.2
gnu/usr.bin/gdb6/arch/m68000/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/arch/m68000/init.c 1.1.6.2
gnu/usr.bin/gdb6/arch/m68000/tm.h 1.1.6.2
gnu/usr.bin/gdb6/arch/m68000/version.c 1.1.6.2
gnu/usr.bin/gdb6/arch/m68k/defs.mk 1.1.4.1
gnu/usr.bin/gdb6/arch/m68k/init.c 1.1.4.1
gnu/usr.bin/gdb6/arch/mipseb/config.h 1.3.4.1
gnu/usr.bin/gdb6/arch/mipseb/defs.mk 1.2.6.2
gnu/usr.bin/gdb6/arch/mipseb/init.c 1.2.6.2
gnu/usr.bin/gdb6/arch/mipsel/config.h 1.2.6.3
gnu/usr.bin/gdb6/arch/mipsel/defs.mk 1.2.6.3
gnu/usr.bin/gdb6/arch/mipsel/init.c 1.2.6.3
gnu/usr.bin/gdb6/arch/mipsel/tm.h 1.2.6.2
gnu/usr.bin/gdb6/arch/mipsel/version.c 1.2.6.2
gnu/usr.bin/gdb6/arch/powerpc/defs.mk 1.3.6.1
gnu/usr.bin/gdb6/arch/powerpc/init.c 1.3.6.1
gnu/usr.bin/gdb6/arch/sh3eb/config.h 1.2.2.2
gnu/usr.bin/gdb6/arch/sh3eb/defs.mk 1.2.8.3
gnu/usr.bin/gdb6/arch/sh3eb/init.c 1.1.8.3
gnu/usr.bin/gdb6/arch/sh3eb/nm.h 1.1.8.2
gnu/usr.bin/gdb6/arch/sh3eb/tm.h 1.1.8.2
gnu/usr.bin/gdb6/arch/sh3eb/version.c 1.1.8.2
gnu/usr.bin/gdb6/arch/sh3el/config.h 1.2.2.2
gnu/usr.bin/gdb6/arch/sh3el/defs.mk 1.2.8.3
gnu/usr.bin/gdb6/arch/sh3el/init.c 1.1.8.3
gnu/usr.bin/gdb6/arch/sh3el/nm.h 1.1.8.2
gnu/usr.bin/gdb6/arch/sh3el/tm.h 1.1.8.2
gnu/usr.bin/gdb6/arch/sh3el/version.c 1.1.8.2
gnu/usr.bin/gdb6/arch/sparc/defs.mk 1.2.6.1
gnu/usr.bin/gdb6/arch/sparc/init.c 1.1.6.1
gnu/usr.bin/gdb6/arch/sparc64/defs.mk 1.2.6.1
gnu/usr.bin/gdb6/arch/sparc64/init.c 1.1.6.1
gnu/usr.bin/gdb6/arch/vax/config.h 1.1.6.2
gnu/usr.bin/gdb6/arch/vax/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/arch/vax/init.c 1.1.6.2
gnu/usr.bin/gdb6/arch/vax/tm.h 1.1.6.2
gnu/usr.bin/gdb6/arch/vax/version.c 1.1.6.2
gnu/usr.bin/gdb6/arch/x86_64/defs.mk 1.2.6.1
gnu/usr.bin/gdb6/arch/x86_64/init.c 1.1.6.1
gnu/usr.bin/gdb6/bfd/arch/armeb/bfd.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/armeb/bfdver.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/armeb/config.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/armeb/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/m68000/bfd.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/m68000/bfdver.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/m68000/config.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/m68000/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/mipsel/bfd.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/mipsel/bfdver.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/mipsel/config.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/mipsel/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/sh3eb/bfd.h 1.1.8.3
gnu/usr.bin/gdb6/bfd/arch/sh3eb/bfdver.h 1.1.8.2
gnu/usr.bin/gdb6/bfd/arch/sh3eb/config.h 1.1.8.2
gnu/usr.bin/gdb6/bfd/arch/sh3eb/defs.mk 1.1.8.3
gnu/usr.bin/gdb6/bfd/arch/sh3el/bfd.h 1.1.8.3
gnu/usr.bin/gdb6/bfd/arch/sh3el/bfdver.h 1.1.8.2
gnu/usr.bin/gdb6/bfd/arch/sh3el/config.h 1.1.8.2
gnu/usr.bin/gdb6/bfd/arch/sh3el/defs.mk 1.1.8.3
gnu/usr.bin/gdb6/bfd/arch/vax/bfd.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/vax/bfdver.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/vax/config.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/vax/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/gdb/Makefile 1.5.2.1.2.2
gnu/usr.bin/gdb6/gdbtui/Makefile 1.2.6.1
gnu/usr.bin/gdb6/libiberty/arch/armeb/config.h 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/armeb/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/m68000/config.h 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/m68000/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/mipsel/config.h 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/mipsel/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/sh3eb/config.h 1.1.8.2
gnu/usr.bin/gdb6/libiberty/arch/sh3eb/defs.mk 1.1.8.2
gnu/usr.bin/gdb6/libiberty/arch/sh3el/config.h 1.1.8.2
gnu/usr.bin/gdb6/libiberty/arch/sh3el/defs.mk 1.1.8.2
gnu/usr.bin/gdb6/libiberty/arch/vax/config.h 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/vax/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/armeb/config.h 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/armeb/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/m68000/config.h 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/m68000/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/mipsel/config.h 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/mipsel/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/sh3eb/config.h 1.1.8.2
gnu/usr.bin/gdb6/opcodes/arch/sh3eb/defs.mk 1.1.8.3
gnu/usr.bin/gdb6/opcodes/arch/sh3el/config.h 1.1.8.2
gnu/usr.bin/gdb6/opcodes/arch/sh3el/defs.mk 1.1.8.3
gnu/usr.bin/gdb6/opcodes/arch/vax/config.h 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/vax/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/armeb/config.h 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/armeb/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/m68000/config.h 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/m68000/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/mipsel/config.h 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/mipsel/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/sh3eb/config.h 1.1.8.2
gnu/usr.bin/gdb6/readline/arch/sh3eb/defs.mk 1.1.8.2
gnu/usr.bin/gdb6/readline/arch/sh3el/config.h 1.1.8.2
gnu/usr.bin/gdb6/readline/arch/sh3el/defs.mk 1.1.8.2
gnu/usr.bin/gdb6/readline/arch/vax/config.h 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/vax/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/sim/arch/mipseb/cconfig.h 1.1.2.1
gnu/usr.bin/gdb6/sim/arch/mipseb/config.h 1.1.2.1
gnu/usr.bin/gdb6/sim/arch/mipseb/defs.mk 1.1.2.1
gnu/usr.bin/gdb6/sim/arch/mipsel/cconfig.h 1.1.2.1
gnu/usr.bin/gdb6/sim/arch/mipsel/config.h 1.1.2.1
gnu/usr.bin/gdb6/sim/arch/mipsel/defs.mk 1.1.2.1
lib/libkvm/kvm_sparc64.c 1.10.18.2
lib/libpthread/pthread.c 1.48.6.4
lib/libpthread/pthread_barrier.c 1.6.18.1
lib/libpthread/pthread_cond.c 1.18.12.2
lib/libpthread/pthread_debug.h 1.8.18.1
lib/libpthread/pthread_int.h 1.34.4.5
lib/libpthread/pthread_lock.c 1.14.6.1
lib/libpthread/pthread_mutex.c 1.22.4.2
lib/libpthread/pthread_run.c 1.18.12.4
lib/libpthread/pthread_rwlock.c 1.13.6.2
lib/libpthread/pthread_sa.c 1.37.6.5
lib/libpthread/pthread_sig.c 1.47.4.8
lib/libpthread/pthread_sleep.c 1.7.6.2
lib/libpthread/sem.c 1.9.6.2
lib/libpthread/arch/sh3/pthread_md.h 1.3.6.1
regress/lib/libpthread/resolv/Makefile 1.1.12.1
regress/lib/libpthread/sigrunning/Makefile 1.1.2.1
regress/lib/libpthread/sigrunning/sigrunning.c 1.1.2.1
share/mk/bsd.own.mk 1.489.4.3
sys/arch/amd64/amd64/locore.S 1.18.14.1
sys/arch/amd64/amd64/machdep.c 1.44.2.3.2.1
sys/arch/amd64/conf/kern.ldscript 1.1.70.1
sys/arch/cats/conf/Makefile.cats.inc 1.17.30.1
sys/arch/shark/conf/Makefile.shark.inc 1.6.30.1
sys/arch/sparc64/conf/kern.ldscript 1.7.26.2
sys/arch/sparc64/conf/kern32.ldscript 1.6.26.2
sys/arch/sparc64/include/kcore.h 1.4.92.2
sys/arch/sparc64/sparc64/locore.s 1.232.4.4
sys/arch/sparc64/sparc64/machdep.c 1.193.4.3
sys/arch/sparc64/sparc64/pmap.c 1.184.2.1.2.4
sys/conf/newvers.sh 1.42.26.2
sys/kern/kern_sa.c 1.87.4.11
sys/kern/kern_synch.c 1.173.4.2
sys/sys/savar.h 1.20.10.2
tools/gdb/Makefile 1.9.4.1
tools/gdb/mknative-gdb 1.1.6.1

pullup the wrstuden-fixsa CVS branch to netbsd-4:
toolchain/35540 - GDB 6 support for pthreads.
port-sparc64/37534 - ktrace firefox gives
kernel trap 30: data access expection
GDB changes:
- delete gdb53
- enable gdb6 on all architectures
- add support for amd64 crash dumps
- add support for sparc64 crash dumps
- add support for /proc pid to executable filename for all archs
- enable thread support for all architectures
- add a note section to kernels to all platforms
- support detection/unwinding of signals for most architectures.
- Fix PTHREAD_UCONTEXT_TO_REG / PTHREAD_REG_TO_UCONTEXT on sh3.
- Apply fix from binutils-current so that sparc gdb can be cross built
on a 64bit host.
SA/pthread changes:
Pre-allocate memory needed for event delivery. Eliminates dropped
interrupts under load.
Deliver intra-process signals to running threads
Eliminate some deadlock scenarios
Fix intra-process signal delivery when delivering to a thread waiting
for signals. Makes afs work again!
 1.6.4.2 27-Oct-2008  uwe Fix typo in comment.
 1.6.4.1 27-Oct-2008  uwe file pthread_md.h was added on branch christos-time_t on 2008-10-27 00:52:08 +0000
 1.7.2.1 08-Feb-2011  bouyer Sync with HEAD
 1.8 02-Mar-2007  ad Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
 1.7 06-Jan-2006  uwe Use PLT for PIC calls to avoid text relocs in the shared library.
 1.6 31-Dec-2005  uwe Adapt to new PIC macros that are now in <machine/asm.h>. Same binary
code is generated (still with text relocs, but eliminating them is the
next step).
 1.5 28-May-2004  uwe branches: 1.5.2;
Fix typo in comment.
 1.4 20-Nov-2003  uwe Do not move incoming paramters to callee-save registers when not
necessary. Saves about a dozen of instructions.
 1.3 20-Nov-2003  uwe In pthread__locked_switch set self->pt_uc only when the context is inited.
In STACK_SWITCH subtract STACKSPACE, not add it (it's zero for now anyway).
 1.2 18-Nov-2003  uwe First cut at pthreads MD code for sh3. Based on m68k version.
Regression tests still failing: sem, sigalarm.
 1.1 23-Jun-2003  uwe First bits of SH3 support. Only _context_u.S is implemented (passess
cu[1-6] tests), the pthread_switch.S is stubbed out for now.

Code posted by Christian Groessler (cpg at aladdin dot de) to port-sh3.
 1.5.2.2 11-Jan-2006  tron Pull up following revision(s) (requested by uwe in ticket #1099):
lib/libpthread/arch/sh3/pthread_switch.S: revision 1.7
Use PLT for PIC calls to avoid text relocs in the shared library.
 1.5.2.1 11-Jan-2006  tron Pull up following revision(s) (requested by uwe in ticket #1094):
lib/libpthread/arch/sh3/pthread_switch.S: revision 1.6
Adapt to new PIC macros that are now in <machine/asm.h>. Same binary
code is generated (still with text relocs, but eliminating them is the
next step).
 1.4 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.3 28-Apr-2008  martin branches: 1.3.8;
Remove clause 3 and 4 from TNF licenses
 1.2 18-Jan-2003  thorpej branches: 1.2.32;
Merge the nathanw_sa branch.
 1.1 23-Nov-2002  martin branches: 1.1.2;
file _context_u.S was initially added on branch nathanw_sa.
 1.1.2.4 07-Jan-2003  thorpej UC_GREG -> UC_GREGS
 1.1.2.3 29-Nov-2002  uwe Add _UC_USER to genassym.cf and use it instead of hardcoded magic number.
 1.1.2.2 28-Nov-2002  uwe Save nPC in _getcontext_u() too, so that we can setcontext(2) it.
Cosmetic changes.
All context tests now work.
 1.1.2.1 23-Nov-2002  martin Port of Andrey Petrovs sparc64 support to sparc. With input from
Valeriy E. Ushakov. Not yet tested.
 1.2.32.1 18-May-2008  yamt sync with head.
 1.3.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.3.8.1 28-Apr-2008  martin file _context_u.S was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.9 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.8 02-Mar-2007  ad Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
 1.7 07-Sep-2003  cl Remove possible race condition in upcall recycling.
 1.6 29-Jul-2003  kleink Remove PT_SLEEPUC, which somehow wasn't.
 1.5 17-Jul-2003  nathanw Adapt to structure name changes.
 1.4 26-Jun-2003  nathanw Remove PT_SLEEPUC and add PT_TRAPUC.
 1.3 31-Jan-2003  pk Include <sys/types.h>
Remove v9 register defs.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 23-Nov-2002  martin branches: 1.1.2;
file genassym.cf was initially added on branch nathanw_sa.
 1.1.2.3 18-Dec-2002  skrll Fix up after change to mcontext.h
 1.1.2.2 29-Nov-2002  uwe Add _UC_USER to genassym.cf and use it instead of hardcoded magic number.
 1.1.2.1 23-Nov-2002  martin Port of Andrey Petrovs sparc64 support to sparc. With input from
Valeriy E. Ushakov. Not yet tested.
 1.8 25-Jan-2011  christos make pthread__sp unsigned long.
 1.7 16-May-2009  ad branches: 1.7.2;
Remove unused code that's confusing when using cscope/opengrok.
 1.6 28-Apr-2008  martin branches: 1.6.8;
Remove clause 3 and 4 from TNF licenses
 1.5 10-Feb-2008  ad branches: 1.5.4;
- Remove libpthread's atomic ops.
- Remove the old spinlock-based mutex and rwlock implementations.
- Use the atomic ops from libc.
 1.4 24-Dec-2005  perry branches: 1.4.12;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.3 10-Nov-2003  martin All the ucontext <-> {fp}reg macros were slightly simplistic and untested
before (old gdb support on sparc did not use this).
Pointed out by Christian Limpach.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 23-Nov-2002  martin branches: 1.1.2;
file pthread_md.h was initially added on branch nathanw_sa.
 1.1.2.2 18-Dec-2002  skrll Fix up after change to mcontext.h
 1.1.2.1 23-Nov-2002  martin Port of Andrey Petrovs sparc64 support to sparc. With input from
Valeriy E. Ushakov. Not yet tested.
 1.4.12.1 23-Mar-2008  matt sync with HEAD
 1.5.4.1 18-May-2008  yamt sync with head.
 1.6.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.6.8.1 28-Apr-2008  martin file pthread_md.h was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.7.2.1 08-Feb-2011  bouyer Sync with HEAD
 1.9 02-Mar-2007  ad Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
 1.8 04-Jan-2006  skrll A couple of fixes to make libpthread really shared, i.e. not have text re-
locations:

- Don't declare pthread__switch_away global
- Do the PIC dance for pthread__switch_return_point and
pthread__locked_switch. Ideally these (and other) symbols would
be hidden.

Thanks to uwe@, dyoung@ and elad@ for help.

XXX sh3 is still to be done.
XXX vax does strange things.
 1.7 07-Sep-2003  cl branches: 1.7.6;
Remove possible race condition in upcall recycling.
 1.6 07-Sep-2003  uwe Use delay slot in STACK_SWITCH (catching up with sparc64 changes).
 1.5 07-Sep-2003  uwe Use correct context to switch to.
From sparc64 fix by Andrey Petrov <petrov@netbsd>.
 1.4 26-Jun-2003  nathanw Adapt to pt_trapuc: change STACK_SWITCH to check for a value in pt_trapuc
and use it preferentially to a value in pt_uc, clearing it once on the new
stack. Move stores into pt_uc back to before the stack switch; storing
after the stack switch opened a one-instruction race condition where an upcall
that had just started a chain could be preempted again, and would bomb when
restarted due to its pt_uc not yet having been updated. Now that pt_trapuc
is what the upcall code writes to, it is safe to store to pt_uc before
switching stacks.

Remove obsolete pt_sleepuc code.
 1.3 17-Jun-2003  martin Catch up with Nathan's changes to other archs.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 23-Nov-2002  martin branches: 1.1.2;
file pthread_switch.S was initially added on branch nathanw_sa.
 1.1.2.3 07-Jan-2003  thorpej UC_GREG -> UC_GREGS
 1.1.2.2 28-Nov-2002  uwe Remove few remaining sparc64'isms.
Some cosmetic changes.
 1.1.2.1 23-Nov-2002  martin Port of Andrey Petrovs sparc64 support to sparc. With input from
Valeriy E. Ushakov. Not yet tested.
 1.7.6.1 08-Jan-2006  riz Pull up following revision(s) (requested by skrll in ticket #1093):
lib/libpthread/arch/sparc/pthread_switch.S: revision 1.8
lib/libpthread/arch/x86_64/pthread_switch.S: revision 1.11
lib/libpthread/arch/sparc64/pthread_switch.S: revision 1.9
lib/libpthread/arch/i386/pthread_switch.S: revision 1.9
A couple of fixes to make libpthread really shared, i.e. not have text re-
locations:
- Don't declare pthread__switch_away global
- Do the PIC dance for pthread__switch_return_point and
pthread__locked_switch. Ideally these (and other) symbols would
be hidden.
Thanks to uwe@, dyoung@ and elad@ for help.
XXX sh3 is still to be done.
XXX vax does strange things.
 1.4 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.3 28-Apr-2008  martin branches: 1.3.8;
Remove clause 3 and 4 from TNF licenses
 1.2 18-Jan-2003  thorpej branches: 1.2.32;
Merge the nathanw_sa branch.
 1.1 22-Feb-2002  petrov branches: 1.1.2;
file _context_u.S was initially added on branch nathanw_sa.
 1.1.2.5 23-Nov-2002  martin Minor style nits, express frame size by apropriate macro and reorder
one load sequence to avoid pipeline interlocks. From Valeriy E. Ushakov.
 1.1.2.4 19-Sep-2002  petrov PIC aware, remove debug cruft.
 1.1.2.3 21-May-2002  petrov STACK_SWITCH fix, added debug.
 1.1.2.2 26-Apr-2002  petrov round 2: simplify _get(set)context_u, add pthread__locked_switch.
 1.1.2.1 22-Feb-2002  petrov Initial pthreads support
 1.2.32.1 18-May-2008  yamt sync with head.
 1.3.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.3.8.1 28-Apr-2008  martin file _context_u.S was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.9 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.8 28-Apr-2008  martin branches: 1.8.8;
Remove clause 3 and 4 from TNF licenses
 1.7 02-Mar-2007  ad branches: 1.7.12;
Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
 1.6 07-Sep-2003  cl Remove possible race condition in upcall recycling.
 1.5 17-Jul-2003  nathanw Adapt to structure name changes.
 1.4 26-Jun-2003  nathanw Remove PT_SLEEPUC and add PT_TRAPUC.
 1.3 07-May-2003  petrov Add missing include and copyright.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 22-Feb-2002  petrov branches: 1.1.2;
file genassym.cf was initially added on branch nathanw_sa.
 1.1.2.1 22-Feb-2002  petrov Initial pthreads support
 1.7.12.1 18-May-2008  yamt sync with head.
 1.8.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.8.8.1 28-Apr-2008  martin file genassym.cf was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.7 25-Jan-2011  christos make pthread__sp unsigned long.
 1.6 16-May-2009  ad branches: 1.6.2;
Remove unused code that's confusing when using cscope/opengrok.
 1.5 28-Apr-2008  martin branches: 1.5.8;
Remove clause 3 and 4 from TNF licenses
 1.4 24-Dec-2005  perry branches: 1.4.20;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.3 11-Nov-2003  martin Fix ucontext conversion macros. From Christian Limpach.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 22-Feb-2002  petrov branches: 1.1.2;
file pthread_md.h was initially added on branch nathanw_sa.
 1.1.2.4 16-Jan-2003  thorpej * Move the pthread_sigmask() prototype to <signal.h>.
* Don't include <signal.h> in <pthread.h>.
* Add code to the signal trampoline to convert from the ucontext
to a sigcontext, and back again (XXX though, only callee-save
regs for _UC_USER contexts).

This is necessary in order to support e.g. GCC's libjava, which depends
on the traditional Unix semantics of changes made to the sigcontext
being visible when the handler returns.
 1.1.2.3 10-Sep-2002  petrov regs/mcontext conversion macros.
 1.1.2.2 26-Apr-2002  petrov round 2: simplify _get(set)context_u, add pthread__locked_switch.
 1.1.2.1 22-Feb-2002  petrov Initial pthreads support
 1.4.20.1 18-May-2008  yamt sync with head.
 1.5.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.5.8.1 28-Apr-2008  martin file pthread_md.h was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.6.2.1 08-Feb-2011  bouyer Sync with HEAD
 1.10 02-Mar-2007  ad Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
 1.9 04-Jan-2006  skrll A couple of fixes to make libpthread really shared, i.e. not have text re-
locations:

- Don't declare pthread__switch_away global
- Do the PIC dance for pthread__switch_return_point and
pthread__locked_switch. Ideally these (and other) symbols would
be hidden.

Thanks to uwe@, dyoung@ and elad@ for help.

XXX sh3 is still to be done.
XXX vax does strange things.
 1.8 07-Sep-2003  cl branches: 1.8.6;
Remove possible race condition in upcall recycling.
 1.7 26-Aug-2003  petrov typo in previous commit, annul isn't good there,
noticed by Eduardo Horvath.
 1.6 25-Aug-2003  petrov Use branch-slot in STACK_SWITCH, suggested by Martin Husemann.
 1.5 25-Aug-2003  petrov Use correct context to switch to.
 1.4 26-Jun-2003  nathanw Adapt to pt_trapuc: change STACK_SWITCH to check for a value in pt_trapuc
and use it preferentially to a value in pt_uc, clearing it once on the new
stack. Move stores into pt_uc back to before the stack switch; storing
after the stack switch opened a one-instruction race condition where an upcall
that had just started a chain could be preempted again, and would bomb when
restarted due to its pt_uc not yet having been updated. Now that pt_trapuc
is what the upcall code writes to, it is safe to store to pt_uc before
switching stacks.

Remove obsolete pt_sleepuc code.
 1.3 15-Jun-2003  martin Catch up with changes Nathan did to other archs.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 22-Feb-2002  petrov branches: 1.1.2;
file pthread_switch.S was initially added on branch nathanw_sa.
 1.1.2.6 20-Sep-2002  petrov minor clean-up.
 1.1.2.5 19-Sep-2002  petrov PIC aware, remove debug cruft.
 1.1.2.4 22-May-2002  petrov more fixes.
 1.1.2.3 21-May-2002  petrov STACK_SWITCH fix, added debug.
 1.1.2.2 26-Apr-2002  petrov round 2: simplify _get(set)context_u, add pthread__locked_switch.
 1.1.2.1 22-Feb-2002  petrov Implementation of pthread__switch only so far.
 1.8.6.1 08-Jan-2006  riz Pull up following revision(s) (requested by skrll in ticket #1093):
lib/libpthread/arch/sparc/pthread_switch.S: revision 1.8
lib/libpthread/arch/x86_64/pthread_switch.S: revision 1.11
lib/libpthread/arch/sparc64/pthread_switch.S: revision 1.9
lib/libpthread/arch/i386/pthread_switch.S: revision 1.9
A couple of fixes to make libpthread really shared, i.e. not have text re-
locations:
- Don't declare pthread__switch_away global
- Do the PIC dance for pthread__switch_return_point and
pthread__locked_switch. Ideally these (and other) symbols would
be hidden.
Thanks to uwe@, dyoung@ and elad@ for help.
XXX sh3 is still to be done.
XXX vax does strange things.
 1.5 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.4 28-Apr-2008  martin branches: 1.4.8;
Remove clause 3 and 4 from TNF licenses
 1.3 09-Apr-2005  matt branches: 1.3.20;
Rework and cleanup. Don't use REI, fake a call frame instead.
 1.2 19-Jan-2003  matt Set _UC_USER in ucontext. Call setcontext if _UC_USER is not in
_setcontext_u
 1.1 19-Jan-2003  matt VAX versions of _getcontext_u/_setcontext_u/_swapcontext_u
 1.3.20.1 18-May-2008  yamt sync with head.
 1.4.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.4.8.1 28-Apr-2008  martin file _context_u.S was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.9 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.8 28-Apr-2008  martin branches: 1.8.8;
Remove clause 3 and 4 from TNF licenses
 1.7 02-Mar-2007  ad branches: 1.7.12;
Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
 1.6 09-Apr-2005  matt Add STACKSPACE
 1.5 01-Dec-2004  skrll pt_sleepuc was removed a long time ago.
 1.4 07-Sep-2003  cl Remove possible race condition in upcall recycling.
 1.3 25-Aug-2003  ragge Add PT_TRAPUC and pthread__switch_return_point.
Not tested (as most of the pthread stuff on vax) but at least
allow the system to compile.
 1.2 17-Jul-2003  nathanw Adapt to structure name changes.
 1.1 19-Jan-2003  matt Add of pthread support for VAX.
 1.7.12.1 18-May-2008  yamt sync with head.
 1.8.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.8.8.1 28-Apr-2008  martin file genassym.cf was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.8 25-Jan-2011  christos make pthread__sp unsigned long.
 1.7 16-May-2009  ad branches: 1.7.2;
Remove unused code that's confusing when using cscope/opengrok.
 1.6 28-Apr-2008  martin branches: 1.6.8;
Remove clause 3 and 4 from TNF licenses
 1.5 10-Feb-2008  ad branches: 1.5.4;
- Remove libpthread's atomic ops.
- Remove the old spinlock-based mutex and rwlock implementations.
- Use the atomic ops from libc.
 1.4 24-Dec-2005  perry branches: 1.4.12;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.3 20-Jan-2003  matt Define FPREG macros even though we don't have any.
 1.2 19-Jan-2003  matt Need to define STACKSIZE (even though we don't need any).
 1.1 19-Jan-2003  matt Add of pthread support for VAX.
 1.4.12.1 23-Mar-2008  matt sync with HEAD
 1.5.4.1 18-May-2008  yamt sync with head.
 1.6.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.6.8.1 28-Apr-2008  martin file pthread_md.h was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.7.2.1 08-Feb-2011  bouyer Sync with HEAD
 1.7 02-Mar-2007  ad Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
 1.6 09-Apr-2005  matt Merge updates to algorithms from i386 switch code.
 1.5 07-Sep-2003  cl Remove possible race condition in upcall recycling.
 1.4 25-Aug-2003  ragge Add PT_TRAPUC and pthread__switch_return_point.
Not tested (as most of the pthread stuff on vax) but at least
allow the system to compile.
 1.3 09-Jul-2003  matt Update to new world order. **not tested** But will allow builds to
finish.
 1.2 20-Jan-2003  matt Add myself to the authors list.
 1.1 19-Jan-2003  matt Add of pthread support for VAX.
 1.12 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.11 28-Apr-2008  martin branches: 1.11.8;
Remove clause 3 and 4 from TNF licenses
 1.10 10-Feb-2008  ad branches: 1.10.4;
- Remove libpthread's atomic ops.
- Remove the old spinlock-based mutex and rwlock implementations.
- Use the atomic ops from libc.
 1.9 13-Nov-2007  ad Mutexes:

- Play scrooge again and chop more cycles off acquire/release.
- Spin while the lock holder is running on another CPU (adaptive mutexes).
- Do non-atomic release.

Threadreg:

- Add the necessary hooks to use a thread register.
- Add the code for i386, using %gs.
- Leave i386 code disabled until xen and COMPAT_NETBSD32 have the changes.
 1.8 13-Nov-2007  ad For PR bin/37347:

- Override __libc_thr_init() instead of using our own constructor.
- Add pthread__getenv() and use instead of getenv(). This is used before
we are up and running and unfortunatley getenv() takes locks.

Other changes:

- Cache the spinlock vectors in pthread__st. Internal spinlock operations
now take 1 function call instead of 3 (i386).
- Use pthread__self() internally, not pthread_self().
- Use __attribute__ ((visibility("hidden"))) in some places.
- Kill PTHREAD_MAIN_DEBUG.
 1.7 11-Sep-2007  ad Fix a dodgy bit of assembly.
 1.6 07-Sep-2007  ad - Don't take the mutex's spinlock (ptr_interlock) in pthread_cond_wait().
Instead, make the deferred wakeup list a per-thread array and pass down
the lwpid_t's that way.

- In pthread_cond_wait(), take the mutex before dealing with early wakeup.
In this way there should never be contention on the CV's spinlock if
the app follows POSIX rules (there should only be contention on the
user-provided mutex).

- Add a port of the kernel's rwlocks. The rwlock's spinlock is only taken if
there is contention. This is enabled where atomic ops are available. Right
now that is only i386 and amd64 because I don't have other hardware to
test with. It's trivial to add stubs for other architectures as long as
they have compare-and-swap. When we have proper atomic ops the old rwlock
code can be removed.

- Add a new mutex implementation that's similar to the kernel's mutexes, but
uses compare-and-swap to maintain the waiters list, so no spinlocks are
involved. Same caveats apply as for the rwlocks.
 1.5 07-Sep-2007  ad Add: pthread__atomic_cas_ptr, pthread__atomic_swap_ptr, pthread__membar_full
This is a stopgap until the thorpej-atomic branch is complete.
 1.4 21-Oct-2004  fvdl branches: 1.4.14; 1.4.18;
Fix thread context switching to take the stack ABI into account.
From Wolfgang Solfrank.
 1.3 08-Nov-2003  fvdl branches: 1.3.2;
Restore %rax correctly during a full context restore (oops).
 1.2 26-Jul-2003  salo netbsd.org->NetBSD.org
 1.1 30-Jan-2003  fvdl libpthread support for x86_64.
 1.3.2.1 12-Nov-2004  jmc Pullup rev 1.4 (requested by fvdl in ticket #956)

Fix thread context switching to take the stack ABI into account.
 1.4.18.3 23-Mar-2008  matt sync with HEAD
 1.4.18.2 09-Jan-2008  matt sync with HEAD
 1.4.18.1 06-Nov-2007  matt sync with HEAD
 1.4.14.1 10-Sep-2007  skrll Sync with HEAD.
 1.10.4.1 18-May-2008  yamt sync with head.
 1.11.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.11.8.1 28-Apr-2008  martin file _context_u.S was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.7 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.6 28-Apr-2008  martin branches: 1.6.8;
Remove clause 3 and 4 from TNF licenses
 1.5 02-Mar-2007  ad branches: 1.5.12;
Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
 1.4 07-Sep-2003  cl Remove possible race condition in upcall recycling.
 1.3 17-Jul-2003  nathanw Adapt to structure name changes.
 1.2 26-Jun-2003  nathanw Remove PT_SLEEPUC and add PT_TRAPUC.
 1.1 30-Jan-2003  fvdl libpthread support for x86_64.
 1.5.12.1 18-May-2008  yamt sync with head.
 1.6.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.6.8.1 28-Apr-2008  martin file genassym.cf was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.13 25-May-2023  riastradh libpthread: New pthread__smt_wait to put CPU in low power for spin.

This is now distinct from pthread__smt_pause, which is for spin lock
backoff with no paired wakeup.

On Arm, there is a single-bit event register per CPU, and there are two
instructions to manage it:

- wfe, wait for event -- if event register is clear, enter low power
mode and wait until event register is set; then exit low power mode
and clear event register

- sev, signal event -- sets event register on all CPUs (other
circumstances like interrupts also set the event register and cause
wfe to wake)

These can be used to reduce the power consumption of spinning for a
lock, but only if they are actually paired -- if there's no sev, wfe
might hang indefinitely. Currently only pthread_spin(3) actually
pairs them; the other lock primitives (internal lock, mutex, rwlock)
do not -- they have spin lock backoff loops, but no corresponding
wakeup to cancel a wfe.

It may be worthwhile to teach the other lock primitives to pair
wfe/sev, but that requires some performance measurement to verify
it's actually worthwhile. So for now, we just make sure not to use
wfe when there's no sev, and keep everything else the same -- this
should fix severe performance degredation in libpthread on Arm
without hurting anything else.

No change in the generated code on amd64 and i386. No change in the
generated code for pthread_spin.c on arm and aarch64 -- changes only
the generated code for pthread_lock.c, pthread_mutex.c, and
pthread_rwlock.c, as intended.

PR port-arm/57437

XXX pullup-10
 1.12 25-Jan-2011  christos branches: 1.12.36; 1.12.46; 1.12.54;
make pthread__sp unsigned long.
 1.11 16-May-2009  ad branches: 1.11.2;
Remove unused code that's confusing when using cscope/opengrok.
 1.10 28-Apr-2008  martin branches: 1.10.8;
Remove clause 3 and 4 from TNF licenses
 1.9 22-Mar-2008  ad branches: 1.9.2;
Cheat and add inlines for _atomic_cas_ptr() to work around gcc emitting
unneeded PIC stuff in mutex_lock() and mutex_unlock(), when a thread
register is used.
 1.8 10-Feb-2008  ad - Remove libpthread's atomic ops.
- Remove the old spinlock-based mutex and rwlock implementations.
- Use the atomic ops from libc.
 1.7 13-Nov-2007  ad Mutexes:

- Play scrooge again and chop more cycles off acquire/release.
- Spin while the lock holder is running on another CPU (adaptive mutexes).
- Do non-atomic release.

Threadreg:

- Add the necessary hooks to use a thread register.
- Add the code for i386, using %gs.
- Leave i386 code disabled until xen and COMPAT_NETBSD32 have the changes.
 1.6 24-Sep-2007  skrll Resurrect the function pointers for lock operations and allow each
architecture to provide asm versions of the RAS operations.

We do this because relying on the compiler to get the RAS right is not
sensible. (It gets alpha wrong and hppa is suboptimal)

Provide asm RAS ops for hppa.

(A slightly different version) reviewed by Andrew Doran.
 1.5 07-Sep-2007  ad Add: pthread__atomic_cas_ptr, pthread__atomic_swap_ptr, pthread__membar_full
This is a stopgap until the thorpej-atomic branch is complete.
 1.4 24-Dec-2005  perry branches: 1.4.8; 1.4.12;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.3 26-Jul-2003  salo netbsd.org->NetBSD.org
 1.2 17-Apr-2003  fvdl Catch up with changed struct reg (same as gregs in mcontext now).
 1.1 30-Jan-2003  fvdl libpthread support for x86_64.
 1.4.12.3 23-Mar-2008  matt sync with HEAD
 1.4.12.2 09-Jan-2008  matt sync with HEAD
 1.4.12.1 06-Nov-2007  matt sync with HEAD
 1.4.8.1 10-Sep-2007  skrll Sync with HEAD.
 1.9.2.1 18-May-2008  yamt sync with head.
 1.10.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.10.8.1 28-Apr-2008  martin file pthread_md.h was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.11.2.1 08-Feb-2011  bouyer Sync with HEAD
 1.12.54.1 01-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #296):

lib/libpthread/arch/x86_64/pthread_md.h: revision 1.13
lib/libpthread/pthread_int.h: revision 1.110
lib/libpthread/pthread_int.h: revision 1.111
lib/libpthread/arch/i386/pthread_md.h: revision 1.21
lib/libpthread/arch/arm/pthread_md.h: revision 1.12
lib/libpthread/arch/arm/pthread_md.h: revision 1.13
lib/libpthread/pthread_spin.c: revision 1.11
lib/libpthread/arch/aarch64/pthread_md.h: revision 1.2

libpthread: Use __nothing, not /* nothing */, for empty macros.

No functional change intended -- just safer to do it this way in case
the macros are used in if branches or comma expressions.

PR port-arm/57437 (pthread__smt_pause/wake issue)

libpthread: New pthread__smt_wait to put CPU in low power for spin.

This is now distinct from pthread__smt_pause, which is for spin lock
backoff with no paired wakeup.

On Arm, there is a single-bit event register per CPU, and there are two
instructions to manage it:
- wfe, wait for event -- if event register is clear, enter low power
mode and wait until event register is set; then exit low power mode
and clear event register
- sev, signal event -- sets event register on all CPUs (other
circumstances like interrupts also set the event register and cause
wfe to wake)

These can be used to reduce the power consumption of spinning for a
lock, but only if they are actually paired -- if there's no sev, wfe
might hang indefinitely. Currently only pthread_spin(3) actually
pairs them; the other lock primitives (internal lock, mutex, rwlock)
do not -- they have spin lock backoff loops, but no corresponding
wakeup to cancel a wfe.

It may be worthwhile to teach the other lock primitives to pair
wfe/sev, but that requires some performance measurement to verify
it's actually worthwhile. So for now, we just make sure not to use
wfe when there's no sev, and keep everything else the same -- this
should fix severe performance degredation in libpthread on Arm
without hurting anything else.

No change in the generated code on amd64 and i386. No change in the
generated code for pthread_spin.c on arm and aarch64 -- changes only
the generated code for pthread_lock.c, pthread_mutex.c, and
pthread_rwlock.c, as intended.

PR port-arm/57437
 1.12.46.1 04-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #1700):

lib/libpthread/arch/x86_64/pthread_md.h: revision 1.13
lib/libpthread/pthread_int.h: revision 1.110
lib/libpthread/pthread_int.h: revision 1.111
lib/libpthread/arch/i386/pthread_md.h: revision 1.21
lib/libpthread/arch/arm/pthread_md.h: revision 1.12
lib/libpthread/arch/arm/pthread_md.h: revision 1.13
lib/libpthread/pthread_spin.c: revision 1.11
lib/libpthread/arch/aarch64/pthread_md.h: revision 1.2

libpthread: Use __nothing, not /* nothing */, for empty macros.

No functional change intended -- just safer to do it this way in case
the macros are used in if branches or comma expressions.
PR port-arm/57437 (pthread__smt_pause/wake issue)

libpthread: New pthread__smt_wait to put CPU in low power for spin.

This is now distinct from pthread__smt_pause, which is for spin lock
backoff with no paired wakeup.

On Arm, there is a single-bit event register per CPU, and there are two
instructions to manage it:
- wfe, wait for event -- if event register is clear, enter low power
mode and wait until event register is set; then exit low power mode
and clear event register
- sev, signal event -- sets event register on all CPUs (other
circumstances like interrupts also set the event register and cause
wfe to wake)

These can be used to reduce the power consumption of spinning for a
lock, but only if they are actually paired -- if there's no sev, wfe
might hang indefinitely. Currently only pthread_spin(3) actually
pairs them; the other lock primitives (internal lock, mutex, rwlock)
do not -- they have spin lock backoff loops, but no corresponding
wakeup to cancel a wfe.

It may be worthwhile to teach the other lock primitives to pair
wfe/sev, but that requires some performance measurement to verify
it's actually worthwhile. So for now, we just make sure not to use
wfe when there's no sev, and keep everything else the same -- this
should fix severe performance degredation in libpthread on Arm
without hurting anything else.

No change in the generated code on amd64 and i386. No change in the
generated code for pthread_spin.c on arm and aarch64 -- changes only
the generated code for pthread_lock.c, pthread_mutex.c, and
pthread_rwlock.c, as intended.
PR port-arm/57437
 1.12.36.1 04-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #1878):

lib/libpthread/arch/x86_64/pthread_md.h: revision 1.13
lib/libpthread/pthread_int.h: revision 1.110
lib/libpthread/pthread_int.h: revision 1.111
lib/libpthread/arch/i386/pthread_md.h: revision 1.21
lib/libpthread/arch/arm/pthread_md.h: revision 1.12
lib/libpthread/arch/arm/pthread_md.h: revision 1.13
lib/libpthread/pthread_spin.c: revision 1.11
lib/libpthread/arch/aarch64/pthread_md.h: revision 1.2

libpthread: Use __nothing, not /* nothing */, for empty macros.

No functional change intended -- just safer to do it this way in case
the macros are used in if branches or comma expressions.
PR port-arm/57437 (pthread__smt_pause/wake issue)

libpthread: New pthread__smt_wait to put CPU in low power for spin.

This is now distinct from pthread__smt_pause, which is for spin lock
backoff with no paired wakeup.

On Arm, there is a single-bit event register per CPU, and there are two
instructions to manage it:
- wfe, wait for event -- if event register is clear, enter low power
mode and wait until event register is set; then exit low power mode
and clear event register
- sev, signal event -- sets event register on all CPUs (other
circumstances like interrupts also set the event register and cause
wfe to wake)

These can be used to reduce the power consumption of spinning for a
lock, but only if they are actually paired -- if there's no sev, wfe
might hang indefinitely. Currently only pthread_spin(3) actually
pairs them; the other lock primitives (internal lock, mutex, rwlock)
do not -- they have spin lock backoff loops, but no corresponding
wakeup to cancel a wfe.

It may be worthwhile to teach the other lock primitives to pair
wfe/sev, but that requires some performance measurement to verify
it's actually worthwhile. So for now, we just make sure not to use
wfe when there's no sev, and keep everything else the same -- this
should fix severe performance degredation in libpthread on Arm
without hurting anything else.

No change in the generated code on amd64 and i386. No change in the
generated code for pthread_spin.c on arm and aarch64 -- changes only
the generated code for pthread_lock.c, pthread_mutex.c, and
pthread_rwlock.c, as intended.
PR port-arm/57437
 1.13 02-Mar-2007  ad Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
 1.12 09-Jan-2006  skrll I was a bit over zealous with my last change so revert the
locked_return_point change.

Loading the instruction at locked_return_point as a return value didn't
work so well.

Thanks to uwe, cube, and dsl.
 1.11 04-Jan-2006  skrll A couple of fixes to make libpthread really shared, i.e. not have text re-
locations:

- Don't declare pthread__switch_away global
- Do the PIC dance for pthread__switch_return_point and
pthread__locked_switch. Ideally these (and other) symbols would
be hidden.

Thanks to uwe@, dyoung@ and elad@ for help.

XXX sh3 is still to be done.
XXX vax does strange things.
 1.10 23-Apr-2004  simonb branches: 1.10.2;
s/the the/the/ (only in sources that aren't regularly imported from
elsewhere).
 1.9 08-Nov-2003  fvdl Make register usage more consistent, also in comparison with the i386
version, for easier maintenance.
 1.8 20-Oct-2003  fvdl Correct and simplify computing the return point; just use PC-relative
addressing.
 1.7 19-Oct-2003  fvdl Make sure the stack stays aligned.
 1.6 07-Sep-2003  cl Remove possible race condition in upcall recycling.
 1.5 26-Jul-2003  salo netbsd.org->NetBSD.org
 1.4 26-Jun-2003  nathanw Adapt to pt_trapuc: change STACK_SWITCH to check for a value in pt_trapuc
and use it preferentially to a value in pt_uc, clearing it once on the new
stack. Move stores into pt_uc back to before the stack switch; storing
after the stack switch opened a one-instruction race condition where an upcall
that had just started a chain could be preempted again, and would bomb when
restarted due to its pt_uc not yet having been updated. Now that pt_trapuc
is what the upcall code writes to, it is safe to store to pt_uc before
switching stacks.

Remove obsolete pt_sleepuc code.
 1.3 12-Jun-2003  fvdl Apply Nathan's switch-away fix.
 1.2 10-Feb-2003  fvdl Continue at the plain switch return point in pthread__switch, not the
locked one, in the !PIC case. From Tor Egge via Havard Eidnes.
 1.1 30-Jan-2003  fvdl libpthread support for x86_64.
 1.10.2.2 11-Jan-2006  tron Pull up following revision(s) (requested by skrll in ticket #1115):
lib/libpthread/arch/x86_64/pthread_switch.S: revision 1.12
I was a bit over zealous with my last change so revert the
locked_return_point change.
Loading the instruction at locked_return_point as a return value didn't
work so well.
Thanks to uwe, cube, and dsl.
 1.10.2.1 08-Jan-2006  riz Pull up following revision(s) (requested by skrll in ticket #1093):
lib/libpthread/arch/sparc/pthread_switch.S: revision 1.8
lib/libpthread/arch/x86_64/pthread_switch.S: revision 1.11
lib/libpthread/arch/sparc64/pthread_switch.S: revision 1.9
lib/libpthread/arch/i386/pthread_switch.S: revision 1.9
A couple of fixes to make libpthread really shared, i.e. not have text re-
locations:
- Don't declare pthread__switch_away global
- Do the PIC dance for pthread__switch_return_point and
pthread__locked_switch. Ideally these (and other) symbols would
be hidden.
Thanks to uwe@, dyoung@ and elad@ for help.
XXX sh3 is still to be done.
XXX vax does strange things.

RSS XML Feed