Commit Graph

1087 Commits

Author SHA1 Message Date
Siddhesh Poyarekar c8886d0abf Use the mutex member of the argumen in __libc_lock_*_recursive 2013-09-27 07:59:26 +05:30
Joseph Myers 3f2e46a494 Remove --disable-versioning. 2013-09-04 15:25:42 +00:00
Ondřej Bílka 382466e04e Fix typos. 2013-08-30 18:08:59 +02:00
Ondřej Bílka c0c3f78afb Fix typos. 2013-08-21 19:48:48 +02:00
Dominik Vogt 075b9322c9 Clean up whitespace in lock elision patches.
Signed-off-by: Carlos O'Donell <carlos@redhat.com>
2013-07-19 02:35:04 -04:00
Dominik Vogt d3d3ce982a Remove remains of rwlock elision which is not implemented yet.
Signed-off-by: Carlos O'Donell <carlos@redhat.com>

---

nptl/
2013-07-19  Dominik Vogt  <vogt@de.ibm.com>

	* sysdeps/unix/sysv/linux/x86/elision-conf.c:
	Remove __rwlock_rtm_enabled and __rwlock_rtm_read_retries.
	(elision_init): Don't set __rwlock_rtm_enabled.
	* sysdeps/unix/sysv/linux/x86/elision-conf.h:
	Remove __rwlock_rtm_enabled.
2013-07-19 02:23:28 -04:00
H.J. Lu e2a32bee75 Add x86 init-arch to nptl 2013-07-03 09:22:31 -07:00
Andi Kleen 1717da59ae Add a configure option to enable lock elision and disable by default
Can be enabled with --enable-lock-elision=yes at configure time.
2013-07-02 08:46:55 -07:00
Andi Kleen e8c659d74e Add elision to pthread_mutex_{try,timed,un}lock
Add elision paths to the basic mutex locks.

The normal path has a check for RTM and upgrades the lock
to RTM when available. Trylocks cannot automatically upgrade,
so they check for elision every time.

We use a 4 byte value in the mutex to store the lock
elision adaptation state. This is separate from the adaptive
spin state and uses a separate field.

Condition variables currently do not support elision.

Recursive mutexes and condition variables may be supported at some point,
but are not in the current implementation. Also "trylock" will
not automatically enable elision unless some other lock call
has been already called on the lock.

This version does not use IFUNC, so it means every lock has one
additional check for elision. Benchmarking showed the overhead
to be negligible.
2013-07-02 08:46:55 -07:00
Andi Kleen b023e4ca99 Add new internal mutex type flags for elision.
Add Enable/disable flags used internally

Extend the mutex initializers to have the fields needed for
elision. The layout stays the same, and this is not visible
to programs.

These changes are not exposed outside pthread
2013-07-02 08:46:54 -07:00
Andi Kleen 1cdbe57948 Add the low level infrastructure for pthreads lock elision with TSX
Lock elision using TSX is a technique to optimize lock scaling
It allows to run locks in parallel using hardware support for
a transactional execution mode in 4th generation Intel Core CPUs.
See http://www.intel.com/software/tsx for more Information.

This patch implements a simple adaptive lock elision algorithm based
on RTM. It enables elision for the pthread mutexes and rwlocks.
The algorithm keeps track whether a mutex successfully elides or not,
and stops eliding for some time when it is not.

When the CPU supports RTM the elision path is automatically tried,
otherwise any elision is disabled.

The adaptation algorithm and its tuning is currently preliminary.

The code adds some checks to the lock fast paths. Micro-benchmarks
show little to no difference without RTM.

This patch implements the low level "lll_" code for lock elision.
Followon patches hook this into the pthread implementation

Changes with the RTM mutexes:
-----------------------------
Lock elision in pthreads is generally compatible with existing programs.
There are some obscure exceptions, which are expected to be uncommon.
See the manual for more details.

- A broken program that unlocks a free lock will crash.
  There are ways around this with some tradeoffs (more code in hot paths)
  I'm still undecided on what approach to take here; have to wait for testing reports.
- pthread_mutex_destroy of a lock mutex will not return EBUSY but 0.
- There's also a similar situation with trylock outside the mutex,
  "knowing" that the mutex must be held due to some other condition.
  In this case an assert failure cannot be recovered. This situation is
  usually an existing bug in the program.
- Same applies to the rwlocks. Some of the return values changes
  (for example there is no EDEADLK for an elided lock, unless it aborts.
   However when elided it will also never deadlock of course)
- Timing changes, so broken programs that make assumptions about specific timing
  may expose already existing latent problems.  Note that these broken programs will
  break in other situations too (loaded system, new faster hardware, compiler
  optimizations etc.)
- Programs with non recursive mutexes that take them recursively in a thread and
  which would always deadlock without elision may not always see a deadlock.
  The deadlock will only happen on an early or delayed abort (which typically
  happens at some point)
  This only happens for mutexes not explicitely set to PTHREAD_MUTEX_NORMAL
  or PTHREAD_MUTEX_ADAPTIVE_NP.  PTHREAD_MUTEX_NORMAL mutexes do not elide.

The elision default can be set at configure time.

This patch implements the basic infrastructure for elision.
2013-07-02 08:46:54 -07:00
Adhemerval Zanella e55a9b256d PowerPC: Reserve TCB space for EBB framework
This patch reserves four pointer to be used in future Event-Based
Branch framework for PowerPC.
2013-06-17 15:50:53 -05:00
Siddhesh Poyarekar 61dd6208fb New API to set default thread attributes
This patch introduces two new convenience functions to set the default
thread attributes used for creating threads.  This allows a programmer
to set the default thread attributes just once in a process and then
run pthread_create without additional attributes.
2013-06-15 12:24:15 +05:30
Siddhesh Poyarekar 5865a56bf4 Avoid access beyond memory bounds in pthread_attr_getaffinity_np
Resolves BZ #15618.

pthread_attr_getaffinity_np may write beyond bounds of the input
cpuset buffer if the size of the input buffer is smaller than the
buffer present in the input pthread attributes.  Fix is to copy to the
extent of the minimum of the source and the destination.
2013-06-14 01:20:06 +05:30
Carlos O'Donell be11d71394 x86*: Return syscall error for lll_futex_wake.
It is very very possible that the futex syscall returns an
error and that the caller of lll_futex_wake may want to
look at that error and propagate the failure.

This patch allows a caller to see the syscall error.

There are no users of the syscall error at present, but
future cleanups are now be able to check for the error.

--

nplt/

2013-06-10  Carlos O'Donell  <carlos@redhat.com>

	* sysdeps/unix/sysv/linux/i386/lowlevellock.h
	(lll_futex_wake): Return syscall error.
	* sysdeps/unix/sysv/linux/x86_64/lowlevellock.h
	(lll_futex_wake): Return syscall error.
2013-06-10 12:05:11 -04:00
Ondrej Bilka 416641e687 Fix previous commit. 2013-06-08 23:07:18 +02:00
Ondrej Bilka e3f36662ee Silence warning: __inline is not at beginning of declaration. 2013-06-08 20:03:24 +02:00
Joseph Myers c7afae94ca Remove trailing whitespace in nptl. 2013-06-06 12:06:15 +00:00
Ryan S. Arnold e054f49430 Add #include <stdint.h> for uint[32|64]_t usage (except installed headers). 2013-05-16 11:32:54 -05:00
Andreas Jaeger ecbf434213 Reserve new TLS field for x86 and x86_64
[BZ #10686]
	* sysdeps/x86_64/tls.h (struct tcbhead_t): Add __private_ss
	field.
	* sysdeps/i386/tls.h (struct tcbhead_t): Likewise.
2013-05-15 20:20:54 +02:00
Siddhesh Poyarekar da1304bcc8 Consolidate pthread_attr value validation
Define inline functions that wrap around validation for each of the
pthread attributes to reduce duplication in code.
2013-04-22 10:28:31 +05:30
Andreas Schwab 4f682b2ae9 Extend i486 pthread_cond_timedwait to use futex syscall with absolute timeout 2013-04-11 10:40:39 +02:00
Carlos O'Donell 96497bb806 sem_post.c: Include atomic.h.
The sem_post.c file uses atomic functions without including
atomic.h. Add `#include <atomic.h>' to the file to prevent
any compile time warnings when other headers change and
atomic.h isn't implicitly included.

---
nptl/

2013-04-07  Carlos O'Donell  <carlos@redhat.com>

	* sysdeps/unix/sysv/linux/sem_post.c: Include atomic.h.
2013-04-07 16:13:02 -04:00
Siddhesh Poyarekar 9ac3b5047e Fix static build when configured with --disable-hidden-plt
Fixes BZ #15337.

Static builds fail with the following warning:

/home/tools/glibc/glibc/nptl/../nptl/sysdeps/unix/sysv/linux/x86_64/cancellation.S:80:
undefined reference to `__GI___pthread_unwind'

When the source is configured with --disable-hidden-plt.  This is
because the preprocessor conditional in cancellation.S only checks if
the build is for SHARED, whereas hidden_def is defined appropriately
only for a SHARED build that will have symbol versioning *and* hidden
defs are enabled.  The last case is false here.
2013-04-04 19:43:56 +05:30
Carlos O'Donell 05087fbb0d Include atomic.h in generic lowlevellock.c. 2013-03-12 23:27:24 -04:00
Roland McGrath b43769a3f5 Rejigger i386 dl-sysdep.h files. 2013-03-04 09:40:25 -08:00
David S. Miller 2b7ae1b27f Add priority inheritance futex support on sparc.
* sysdeps/unix/sysv/linux/sparc/lowlevellock.h
	(FUTEX_WAIT_REQUEUE_PI): Define.
	(FUTEX_CMP_REQUEUE_PI): Likewise.
	(lll_futex_wait_requeue_pi): Likewise.
	(lll_futex_timed_wait_requeue_pi): Likewise.
	(lll_futex_cmp_requeue_pi): Likewise.
2013-02-21 15:20:27 -08:00
Carlos O'Donell 9bf95cbc35 nptl: Fix comment typo in fork.c. 2013-02-21 09:36:43 -05:00
Siddhesh Poyarekar ffaa74cf68 Fix build warnings in some test cases
Include stdlib.h to get declaration of exit(3)
2013-02-18 18:17:05 +05:30
Siddhesh Poyarekar 8313cb997d FUTEX_*_REQUEUE_PI support for non-x86 code
Add FUTEX_*_REQUEUE_PI support for the default C code and also add
implementations for s-390 and ppc.
2013-02-18 16:07:10 +05:30
Joseph Myers e97ed6ddbe Remove bp-sym.h and BP_SYM uses from C code. 2013-02-14 13:12:02 +00:00
Andreas Schwab e3f45e2bbe Revert "Extend i486 pthread_cond_timedwait to use futex syscall with absolute timeout"
This reverts commit 1bd57044e9.
2013-01-10 10:44:05 +01:00
Andreas Schwab 1bd57044e9 Extend i486 pthread_cond_timedwait to use futex syscall with absolute timeout
* sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S
	(__pthread_cond_timedwait): If possible use FUTEX_WAIT_BITSET to
	directly use absolute timeout.
2013-01-10 09:59:58 +01:00
Joseph Myers 568035b787 Update copyright notices with scripts/update-copyrights. 2013-01-02 19:05:09 +00:00
Joseph Myers f4cf5f2d8b Add script to update copyright notices and reformat some to facilitate its use. 2013-01-01 16:29:10 +00:00
David S. Miller 9c7595bda2 Add sparc implementation of lll_futex_timed_wait_bitset
nptl/

	* sysdeps/unix/sysv/linux/sparc/lowlevellock.h
	(lll_futex_timed_wait_bitset): New macro.
2012-12-27 08:20:46 -08:00
Siddhesh Poyarekar 8ebac7785b [s390] Replace lll_futex_* assembly code with INTERNAL_SYSCALL 2012-12-27 20:43:02 +05:30
Siddhesh Poyarekar 56e7d3ad5c Fix some build warnings on s390x 2012-12-08 13:03:24 +05:30
Joseph Myers d39b954531 Remove unused variable from powerpc sem_post.c. 2012-12-04 21:39:04 +00:00
H.J. Lu c515fb5148 Cast to __intptr_t before casting pointer to int64 2012-11-26 16:45:36 -08:00
Joseph Myers 09e958ed42 Remove unused variable from sem_post.c. 2012-11-21 20:00:52 +00:00
Siddhesh Poyarekar 8f861542dd [S390,PPC] Implement FUTEX_WAIT_BITSET for timedwait functions
Since the FUTEX_WAIT operation takes a relative timeout, the
pthread_cond_timedwait and other timed function implementations have
to get a relative timeout from the absolute timeout parameter it gets
before it makes the futex syscall.  This value is then converted back
into an absolute timeout within the kernel.  This is a waste and has
hence been improved upon by a FUTEX_WAIT_BITSET operation (OR'd with
FUTEX_CLOCK_REALTIME to make the kernel use the realtime clock instead
of the default monotonic clock).  This was implemented only in the x86
and sh assembly code and not in the C code.  This patch implements
support for FUTEX_WAIT_BITSET whenever available (since linux-2.6.29)
for s390 and powerpc.
2012-11-05 21:12:52 +05:30
David S. Miller d3bd58cf0a Fix coding style in sparc lowlevellock.h
nptl/

	* sysdeps/unix/sysv/linux/sparc/lowlevellock.h (BUSY_WAIT_NOP):
	Add missing spaces.
	(__cpu_relax): Likewise.
2012-11-03 15:25:55 -07:00
H.J. Lu f62c8abcfb Compile x86 rtld with -mno-sse -mno-mmx 2012-11-02 18:43:27 -07:00
David S. Miller 19f1dd5f2d Define a BUSY_WAIT_NOP for sparc.
nptl/

	* sysdeps/unix/sysv/linux/sparc/lowlevellock.h (BUSY_WAIT_NOP):
	Define when we have v9 instructions available.
	* sysdeps/unix/sysv/linux/sparc/sparc64/cpu_relax.S: New file.
	* sysdeps/unix/sysv/linux/sparc/sparc32/sparcv9/cpu_relax.S: New
	file.
	* sysdeps/unix/sysv/linux/sparc/sparc32/sparcv9/Makefile: New
	file.
	* sysdeps/unix/sysv/linux/sparc/sparc64/Makefile: Add cpu_relax
	to libpthread-routines.
2012-10-28 23:19:00 -07:00
Siddhesh Poyarekar 9485a40444 Adjust mutex lock in condvar_cleanup if we got it from requeue_pi
This completes the fix to bz #14652.
2012-10-16 14:23:35 +05:30
Carlos O'Donell 0d522f6417 Fix formatting in nptl/sysdeps/pthread/pthread.h.
The macro pthread_cleanup_push_defer_np in pthread.h has a misaligned
line continuation marker. This marker was previously aligned, but
recent changes have moved it out of alignment. This change realigns
the marker. This also reduces the diff against the hppa version of
pthread.h where the marker is aligned.
2012-10-10 23:28:52 -04:00
Siddhesh Poyarekar 0e3b5d6a68 Take lock in pthread_cond_wait cleanup handler only when needed
[BZ #14652]
When a thread waiting in pthread_cond_wait with a PI mutex is
cancelled after it has returned successfully from the futex syscall
but just before async cancellation is disabled, it enters its
cancellation handler with the mutex held and simply calling a
mutex_lock again will result in a deadlock.  Hence, it is necessary to
see if the thread owns the lock and try to lock it only if it doesn't.
2012-10-10 12:52:56 +05:30
Roland McGrath b8493de0ec Add missing magic to GLIBC_PROVIDES. 2012-10-09 15:41:30 -07:00
David S. Miller f076216468 Correct libthreadb register access for 64-bit sparc.
[BZ #14568]
	* sysdeps/sparc/tls.h (DB_THREAD_SELF_INCLUDE): Delete.
	(DB_THREAD_SELF): Use constants for the register offsets.  Correct
	the case of a 64-bit debugger with a 32-bit inferior.
2012-10-05 21:22:41 -07:00