Commit Graph

1429 Commits

Author SHA1 Message Date
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
Vladimir Nikulichev e1f0b2cfa1 BZ #12310: pthread_exit in static app. segfaults
Static applications that call pthread_exit on the main
thread segfault. This is because after a thread terminates
__libc_start_main decrements __nptl_nthreads which is only
defined in pthread_create. Therefore the right solution is
to add a requirement to pthread_create from pthread_exit.

~~~
nptl/

2013-06-24  Vladimir Nikulichev  <v.nikulichev@gmail.com>

	[BZ #12310]
	* pthread_exit.c: Add reference to pthread_create.
2013-06-24 17:12:30 -04:00
Joseph Myers e781d7c58f Include <string.h> in nptl/pthread_setattr_default_np.c. 2013-06-22 19:32:50 +00: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 e3f36662ee Silence warning: __inline is not at beginning of declaration. 2013-06-08 20:03:24 +02:00
Ondrej Bilka 350635a59a Fix leading whitespaces. 2013-06-06 20:36:07 +02:00
Joseph Myers c7afae94ca Remove trailing whitespace in nptl. 2013-06-06 12:06:15 +00:00
Joseph Myers fab7ce3f5b Link extra-libs consistently with libc and ld.so. 2013-05-31 16:16:33 +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
Andi Kleen 66c13581af Fix tst-mutexpi8
2013-05-09  Andi Kleen  <ak@linux.intel.com>

	* tst-mutex8.c (do_test): Check for ENABLE_PI.
2013-05-09 16:15:50 +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
Roland McGrath e57b0c6100 Avoid unconditional __call_tls_dtors calls in static linking. 2013-03-28 16:52:57 -07:00
Siddhesh Poyarekar 5cebee5db0 Fix up ChangeLog
I forgot to fix up the ChangeLog after renaming __default_attr to
__default_pthread_attr in code.
2013-03-19 15:00:08 +05:30
Siddhesh Poyarekar e903a7138b Move __default_stacksize into __default_pthread_attr
Make __default_pthread_attr object to store default attribute values
for threads.
2013-03-19 14:34:13 +05:30
Siddhesh Poyarekar 69854bb5e9 Rename some static variables
Rename some static variables to give them unique names.
2013-03-18 13:44:05 +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
Carlos O'Donell 4e9b599577 Revert GLIBC_PTHREAD_DEFAULT_STACKSIZE changes.
This reverts the change that allows the POSIX Thread default stack size
to be changed by the environment variable
GLIBC_PTHREAD_DEFAULT_STACKSIZE. It has been requested that more
discussion happen before this change goes into 2.18.
2013-03-01 16:18:08 -05:00
Siddhesh Poyarekar ace4acc8ac Fix build warning 2013-03-01 20:45:17 +05:30
Siddhesh Poyarekar e23872c8db Set default stack size from program environment
New environment variable GLIBC_PTHREAD_DEFAULT_STACKSIZE to do this.
2013-03-01 14:15:39 +05:30
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 f4804ca2bb Fix ChangeLogs 2013-02-18 21:41:34 +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
Andreas Schwab 903ae060db Don't use GLIBC_PRIVATE errno outside of libraries 2013-02-04 10:01:54 +01:00
Andreas Schwab cfa8054fbb Hide reference to mktemp in libpthread 2013-01-16 15:57:11 +01:00
Carlos O'Donell c0609c5c5e Remove unnecessary assert on attr in allocate_stack(). 2013-01-11 20:52:05 -05:00
H.J. Lu 740b3dbee8 Add --enable-hardcoded-path-in-tests configure option 2013-01-11 07:14:18 -08: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
Andi Kleen c93c5dec54 Convert pthread_rwlock_try(rd/wr)lock to prototypes
2012-12-28  Andi Kleen  <ak@linux.intel.com>

        * pthread_rwlock_tryrdlock.c (__pthread_rwlock_tryrdlock):
        * Convert
	to prototype.
        * pthread_rwlock_trywrlock.c (__pthread_rwlock_trywrlock):
	Likewise.
2012-12-28 21:25:07 +01: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
Allan McRae e30907c3a4 Remove unneeded linking in nptl testsuite 2012-12-03 13:56:07 +10: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
Joseph Myers fac9916c96 Remove unused variable from pthread_cond_timedwait.c. 2012-11-21 20:00:11 +00:00
Marcus Shawcroft c485e4d2cc Adding missing -fexception CFLAGS 2012-11-14 12:35:10 +00:00
Chris Metcalf 91e0d40e89 Bump timeouts on some new nptl tests to support tilepro. 2012-11-06 13:10:19 -05: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