From b42a214c1807dc596cf3647fc35a0eb42ccc7e68 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Mon, 24 Aug 2009 16:23:47 -0700 Subject: Hint to kernel that thread stack memory can be removed. --- nptl/ChangeLog | 28 +++++++++++++++++----------- nptl/pthread_create.c | 13 +++++++++++++ 2 files changed, 30 insertions(+), 11 deletions(-) (limited to 'nptl') diff --git a/nptl/ChangeLog b/nptl/ChangeLog index 098ef3ba2d..3887969cb8 100644 --- a/nptl/ChangeLog +++ b/nptl/ChangeLog @@ -1,3 +1,9 @@ +2009-08-24 Ulrich Drepper + + * pthread_create.c (start_thread): Hint to the kernel that memory for + the stack can be reused. We do not mark all the memory. The part + still in use and some reserve are kept. + 2009-08-23 Ulrich Drepper * sysdeps/unix/sysv/linux/bits/posix_opt.h: Clean up namespace. @@ -1847,9 +1853,9 @@ * sysdeps/unix/sysv/linux/sh/bits/pthreadtypes.h: Include endian.h. Split __flags into __flags, __shared, __pad1 and __pad2. * sysdeps/unix/sysv/linux/sh/libc-lowlevellock.S: Use private - futexes if they are available. + futexes if they are available. * sysdeps/unix/sysv/linux/sh/lowlevellock.S: Adjust so that change - in libc-lowlevellock.S allow using private futexes. + in libc-lowlevellock.S allow using private futexes. * sysdeps/unix/sysv/linux/sh/lowlevellock.h: Define FUTEX_PRIVATE_FLAG. Add additional parameter to lll_futex_wait, lll_futex_timed_wait and lll_futex_wake. Change lll_futex_wait @@ -1857,12 +1863,12 @@ lll_private_futex_timed_wait and lll_private_futex_wake. (lll_robust_mutex_unlock): Fix typo. * sysdeps/unix/sysv/linux/sh/pthread_barrier_wait.S: Use private - field in futex command setup. + field in futex command setup. * sysdeps/unix/sysv/linux/sh/pthread_cond_timedwait.S: Use COND_NWAITERS_SHIFT instead of COND_CLOCK_BITS. * sysdeps/unix/sysv/linux/sh/pthread_cond_wait.S: Likewise. * sysdeps/unix/sysv/linux/sh/pthread_once.S: Use private futexes - if they are available. Remove clear_once_control. + if they are available. Remove clear_once_control. * sysdeps/unix/sysv/linux/sh/pthread_rwlock_rdlock.S: Use private futexes if they are available. * sysdeps/unix/sysv/linux/sh/pthread_rwlock_timedrdlock.S: Likewise. @@ -1873,7 +1879,7 @@ Wake only when there are waiters. * sysdeps/unix/sysv/linux/sh/sem_wait.S: Add private futex support. Indicate that there are waiters. Remove unnecessary - extra cancellation test. + extra cancellation test. * sysdeps/unix/sysv/linux/sh/sem_timedwait.S: Likewise. Removed left-over duplication of __sem_wait_cleanup. @@ -2587,14 +2593,14 @@ * tst-cancel25.c: New file. 2006-09-05 Jakub Jelinek - Ulrich Drepper + Ulrich Drepper * sysdeps/pthread/gai_misc.h (GAI_MISC_NOTIFY): Don't decrement counterp if it is already zero. * sysdeps/pthread/aio_misc.h (AIO_MISC_NOTIFY): Likewise.. 2006-03-04 Jakub Jelinek - Roland McGrath + Roland McGrath * sysdeps/unix/sysv/linux/i386/lowlevellock.h (LLL_STUB_UNWIND_INFO_START, LLL_STUB_UNWIND_INFO_END, @@ -2608,7 +2614,7 @@ * sysdeps/unix/sysv/linux/i386/i486/lowlevelrobustlock.S: Likewise. 2006-03-03 Jakub Jelinek - Roland McGrath + Roland McGrath * sysdeps/unix/sysv/linux/x86_64/lowlevellock.h (LLL_STUB_UNWIND_INFO_START, LLL_STUB_UNWIND_INFO_END, @@ -3181,7 +3187,7 @@ * sysdeps/pthread/pthread.h: Adjust mutex initializers. * sysdeps/unix/sysv/linux/i386/not-cancel.h: Define openat_not_cancel, - openat_not_cancel_3, openat64_not_cancel, and openat64_not_cancel_3. + openat_not_cancel_3, openat64_not_cancel, and openat64_not_cancel_3. 2006-02-08 Jakub Jelinek @@ -3603,7 +3609,7 @@ * Makefile ($(test-modules)): Remove static pattern rule. 2005-10-14 Jakub Jelinek - Ulrich Drepper + Ulrich Drepper * sysdeps/unix/sysv/linux/x86_64/pthread_once.S: Fix stack alignment in callback function. @@ -3621,7 +3627,7 @@ atomic_compare_and_exchange_bool_acq. 2005-10-01 Ulrich Drepper - Jakub Jelinek + Jakub Jelinek * descr.h: Define SETXID_BIT and SETXID_BITMASK. Adjust CANCEL_RESTMASK. diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c index c69397906f..89938b3fb8 100644 --- a/nptl/pthread_create.c +++ b/nptl/pthread_create.c @@ -377,6 +377,19 @@ start_thread (void *arg) } #endif + /* Mark the memory of the stack as usable to the kernel. We free + everything except for the space used for the TCB itself. */ + size_t pagesize_m1 = __getpagesize () - 1; +#ifdef _STACK_GROWS_DOWN + char *sp = CURRENT_STACK_FRAME; + size_t freesize = (sp - (char *) pd->stackblock) & ~pagesize_m1; +#else +# error "to do" +#endif + assert (freesize < pd->stackblock_size); + if (freesize > PTHREAD_STACK_MIN) + madvise (pd->stackblock, freesize - PTHREAD_STACK_MIN, MADV_DONTNEED); + /* If the thread is detached free the TCB. */ if (IS_DETACHED (pd)) /* Free the TCB. */ -- cgit 1.4.1 From 84088310ce06bfc5759b37f0cd043dce80f578b6 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Tue, 25 Aug 2009 10:42:30 -0700 Subject: Handle AVX saving on x86-64 in interrupted smbol lookups. If a signal arrived during a symbol lookup and the signal handler also required a symbol lookup, the end of the lookup in the signal handler reset the flag whether restoring AVX/SSE registers is needed. Resetting means in this case that the tail part of the outer lookup code will try to restore the registers and this can fail miserably. We now restore to the previous value which makes nesting calls possible. --- ChangeLog | 5 +++++ nptl/ChangeLog | 7 +++++++ nptl/sysdeps/x86_64/tls.h | 10 ++++++++-- sysdeps/x86_64/dl-trampoline.S | 1 - 4 files changed, 20 insertions(+), 3 deletions(-) (limited to 'nptl') diff --git a/ChangeLog b/ChangeLog index b2d98e4ee7..560f5db55c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2009-08-25 Ulrich Drepper + + * sysdeps/x86_64/dl-trampoline.S (_dl_runtime_profile): Remove + leftover YMM_SIZE definition. + 2009-08-24 Ulrich Drepper * math/math_private.h (ieee_double_shape_type): Add uint64_t word to diff --git a/nptl/ChangeLog b/nptl/ChangeLog index 3887969cb8..a9a0168357 100644 --- a/nptl/ChangeLog +++ b/nptl/ChangeLog @@ -1,3 +1,10 @@ +2009-08-25 Ulrich Drepper + + * sysdeps/x86_64/tls.h (RTLD_ENABLE_FOREIGN_CALL): Store old value + of the field in local variables. + (RTLD_FINALIZE_FOREIGN_CALL): Restore rtld_must_xmm_save from local + variable and don't unconditionally clear it. + 2009-08-24 Ulrich Drepper * pthread_create.c (start_thread): Hint to the kernel that memory for diff --git a/nptl/sysdeps/x86_64/tls.h b/nptl/sysdeps/x86_64/tls.h index 4212038ab5..e39eb5f69d 100644 --- a/nptl/sysdeps/x86_64/tls.h +++ b/nptl/sysdeps/x86_64/tls.h @@ -188,7 +188,7 @@ typedef struct The contained asm must *not* be marked volatile since otherwise assignments like - pthread_descr self = thread_self(); + pthread_descr self = thread_self(); do not get optimized away. */ # define THREAD_SELF \ ({ struct pthread *__self; \ @@ -404,7 +404,12 @@ extern void _dl_x86_64_restore_sse (void); # define RTLD_CHECK_FOREIGN_CALL \ (THREAD_GETMEM (THREAD_SELF, header.rtld_must_xmm_save) != 0) +/* NB: Don't use the xchg operation because that would imply a lock + prefix which is expensive and unnecessary. The cache line is also + not contested at all. */ # define RTLD_ENABLE_FOREIGN_CALL \ + int old_rtld_must_xmm_save = THREAD_GETMEM (THREAD_SELF, \ + header.rtld_must_xmm_save); \ THREAD_SETMEM (THREAD_SELF, header.rtld_must_xmm_save, 1) # define RTLD_PREPARE_FOREIGN_CALL \ @@ -419,7 +424,8 @@ extern void _dl_x86_64_restore_sse (void); do { \ if (THREAD_GETMEM (THREAD_SELF, header.rtld_must_xmm_save) == 0) \ _dl_x86_64_restore_sse (); \ - THREAD_SETMEM (THREAD_SELF, header.rtld_must_xmm_save, 0); \ + THREAD_SETMEM (THREAD_SELF, header.rtld_must_xmm_save, \ + old_rtld_must_xmm_save); \ } while (0) # endif diff --git a/sysdeps/x86_64/dl-trampoline.S b/sysdeps/x86_64/dl-trampoline.S index f9c60ad5cf..5564a11af2 100644 --- a/sysdeps/x86_64/dl-trampoline.S +++ b/sysdeps/x86_64/dl-trampoline.S @@ -197,7 +197,6 @@ _dl_x86_64_save_sse: ret L(no_avx5): # endif -# define YMM_SIZE 16 movdqa %xmm0, %fs:RTLD_SAVESPACE_SSE+0*XMM_SIZE movdqa %xmm1, %fs:RTLD_SAVESPACE_SSE+1*XMM_SIZE movdqa %xmm2, %fs:RTLD_SAVESPACE_SSE+2*XMM_SIZE -- cgit 1.4.1