summaryrefslogtreecommitdiff
path: root/libc/nptl
diff options
context:
space:
mode:
authorjoseph <joseph@7b3dc134-2b1b-0410-93df-9e9f96275f8d>2007-05-16 14:10:16 +0000
committerjoseph <joseph@7b3dc134-2b1b-0410-93df-9e9f96275f8d>2007-05-16 14:10:16 +0000
commite4899a03d1fd17fac542f34f2b3d3e0087b26908 (patch)
tree8c29dafd63320636b4b89385bf44d927653618b7 /libc/nptl
parent0b586afcbc9a2e292ebf44d2f8f4b968ba82e10f (diff)
Merge changes between r2162 and r2243 from /fsf/trunk.
git-svn-id: svn://svn.eglibc.org/trunk@2244 7b3dc134-2b1b-0410-93df-9e9f96275f8d
Diffstat (limited to 'libc/nptl')
-rw-r--r--libc/nptl/ChangeLog45
-rw-r--r--libc/nptl/TODO15
-rw-r--r--libc/nptl/allocatestack.c24
-rw-r--r--libc/nptl/descr.h8
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/lowlevelrobustlock.c22
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/pthread_setaffinity.c8
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_setaffinity.c14
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S19
-rw-r--r--libc/nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S15
-rw-r--r--libc/nptl/tst-align2.c11
-rw-r--r--libc/nptl/tst-cancel-wrappers.sh3
-rw-r--r--libc/nptl/tst-cancel4.c44
-rw-r--r--libc/nptl/tst-getpid1.c7
13 files changed, 186 insertions, 49 deletions
diff --git a/libc/nptl/ChangeLog b/libc/nptl/ChangeLog
index ce3ca4101..47d36966c 100644
--- a/libc/nptl/ChangeLog
+++ b/libc/nptl/ChangeLog
@@ -1,3 +1,48 @@
+2007-05-14 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/x86_64/sem_wait.S: Remove unnecessary
+ extra cancellation test.
+ * sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S: Likewise.
+
+2007-05-10 Ulrich Drepper <drepper@redhat.com>
+
+ * descr.h (struct pthread): Rearrange members to fill hole in
+ 64-bit layout.
+
+ * sysdeps/unix/sysv/linux/pthread_setaffinity.c
+ (__pthread_setaffinity_new): If syscall was successful and
+ RESET_VGETCPU_CACHE is defined, use it before returning.
+ * sysdeps/unix/sysv/linux/x86_64/pthread_setaffinity.c: New file.
+
+2007-05-10 Jakub Jelinek <jakub@redhat.com>
+
+ [BZ #4455]
+ * tst-align2.c: Include stackinfo.h.
+ * tst-getpid1.c: Likewise.
+
+2007-05-02 Carlos O'Donell <carlos@systemhalted.org>
+
+ [BZ #4455]
+ * tst-align2.c (do_test): Add _STACK_GROWS_UP case.
+ * tst-getpid1.c (do_test): Likewise.
+
+ [BZ #4456]
+ * allocatestack.c (change_stack_perm): Add _STACK_GROWS_UP case.
+ (allocate_stack): Likewise.
+
+2007-05-07 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/lowlevelrobustlock.c
+ (__lll_robust_lock_wait): Fix race caused by reloading of futex value.
+ (__lll_robust_timedlock_wait): Likewise.
+ Reported by Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>.
+
+2007-05-06 Mike Frysinger <vapier@gentoo.org>
+
+ [BZ #4465]
+ * tst-cancel-wrappers.sh: Set C["fdatasync"] to 1.
+ * tst-cancel4.c (tf_fdatasync): New test.
+
2007-04-27 Ulrich Drepper <drepper@redhat.com>
[BZ #4392]
diff --git a/libc/nptl/TODO b/libc/nptl/TODO
index d59717651..70b8fe4f7 100644
--- a/libc/nptl/TODO
+++ b/libc/nptl/TODO
@@ -14,3 +14,18 @@ syscall needed.
- test with threaded process terminating and semadj (?) being applied
only after all threads are gone
+
+
+
+- semaphore changes:
+
+ - sem_post should only wake one thread and only when the state of
+ the semaphore changed from 0 to 1
+
+ this also requires that sem_wait and sem_timedwait don't drop the
+ post if they get canceled.
+
+ - possibly add counter field. This requires reviving the
+ differences between old and new semaphose funtions. The old ones
+ stay as they are now. The new once can use an additional field
+ wich is the counter for the number of waiters
diff --git a/libc/nptl/allocatestack.c b/libc/nptl/allocatestack.c
index c05cd47df..6b6064204 100644
--- a/libc/nptl/allocatestack.c
+++ b/libc/nptl/allocatestack.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+/* Copyright (C) 2002,2003,2004,2005,2006,2007 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
@@ -288,9 +288,14 @@ change_stack_perm (struct pthread *pd
+ (((((pd->stackblock_size - pd->guardsize) / 2)
& pagemask) + pd->guardsize) & pagemask));
size_t len = pd->stackblock + pd->stackblock_size - stack;
-#else
+#elif _STACK_GROWS_DOWN
void *stack = pd->stackblock + pd->guardsize;
size_t len = pd->stackblock_size - pd->guardsize;
+#elif _STACK_GROWS_UP
+ void *stack = pd->stackblock;
+ size_t len = (uintptr_t) pd - pd->guardsize - (uintptr_t) pd->stackblock;
+#else
+# error "Define either _STACK_GROWS_DOWN or _STACK_GROWS_UP"
#endif
if (mprotect (stack, len, PROT_READ | PROT_WRITE | PROT_EXEC) != 0)
return errno;
@@ -570,8 +575,10 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
{
#ifdef NEED_SEPARATE_REGISTER_STACK
char *guard = mem + (((size - guardsize) / 2) & ~pagesize_m1);
-#else
+#elif _STACK_GROWS_DOWN
char *guard = mem;
+# elif _STACK_GROWS_UP
+ char *guard = (char *) (((uintptr_t) pd - guardsize) & ~pagesize_m1);
#endif
if (mprotect (guard, guardsize, PROT_NONE) != 0)
{
@@ -618,10 +625,14 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
oldguard + pd->guardsize - guard - guardsize,
prot) != 0)
goto mprot_error;
-#else
+#elif _STACK_GROWS_DOWN
if (mprotect ((char *) mem + guardsize, pd->guardsize - guardsize,
prot) != 0)
goto mprot_error;
+#elif _STACK_GROWS_UP
+ if (mprotect ((char *) pd - pd->guardsize,
+ pd->guardsize - guardsize, prot) != 0)
+ goto mprot_error;
#endif
pd->guardsize = guardsize;
@@ -661,8 +672,11 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
#ifdef NEED_SEPARATE_REGISTER_STACK
*stack = pd->stackblock;
*stacksize = stacktop - *stack;
-#else
+#elif _STACK_GROWS_DOWN
*stack = stacktop;
+#elif _STACK_GROWS_UP
+ *stack = pd->stackblock;
+ assert (*stack > 0);
#endif
return 0;
diff --git a/libc/nptl/descr.h b/libc/nptl/descr.h
index 321ce8508..00cad1aa8 100644
--- a/libc/nptl/descr.h
+++ b/libc/nptl/descr.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+/* Copyright (C) 2002-2006, 2007 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
@@ -268,6 +268,9 @@ struct pthread
| EXITING_BITMASK | CANCEL_RESTMASK | TERMINATED_BITMASK)) \
== (CANCELTYPE_BITMASK | CANCELED_BITMASK))
+ /* Flags. Including those copied from the thread attribute. */
+ int flags;
+
/* We allocate one block of references here. This should be enough
to avoid allocating any memory dynamically for most applications. */
struct pthread_key_data
@@ -321,9 +324,6 @@ struct pthread
/* Check whether a thread is detached. */
#define IS_DETACHED(pd) ((pd)->joinid == (pd))
- /* Flags. Including those copied from the thread attribute. */
- int flags;
-
/* The result of the thread function. */
void *result;
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/lowlevelrobustlock.c b/libc/nptl/sysdeps/unix/sysv/linux/lowlevelrobustlock.c
index 3e88ee186..30ef991bd 100644
--- a/libc/nptl/sysdeps/unix/sysv/linux/lowlevelrobustlock.c
+++ b/libc/nptl/sysdeps/unix/sysv/linux/lowlevelrobustlock.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2006 Free Software Foundation, Inc.
+/* Copyright (C) 2006, 2007 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Jakub Jelinek <jakub@redhat.com>, 2006.
@@ -30,6 +30,10 @@ __lll_robust_lock_wait (int *futex)
int oldval = *futex;
int tid = THREAD_GETMEM (THREAD_SELF, tid);
+ /* If the futex changed meanwhile try locking again. */
+ if (oldval == 0)
+ goto try;
+
do
{
if (__builtin_expect (oldval & FUTEX_OWNER_DIED, 0))
@@ -41,6 +45,9 @@ __lll_robust_lock_wait (int *futex)
continue;
lll_futex_wait (futex, newval);
+
+ try:
+ ;
}
while ((oldval = atomic_compare_and_exchange_val_acq (futex,
tid | FUTEX_WAITERS,
@@ -57,6 +64,11 @@ __lll_robust_timedlock_wait (int *futex, const struct timespec *abstime)
return EINVAL;
int tid = THREAD_GETMEM (THREAD_SELF, tid);
+ int oldval = *futex;
+
+ /* If the futex changed meanwhile try locking again. */
+ if (oldval == 0)
+ goto try;
do
{
@@ -80,7 +92,6 @@ __lll_robust_timedlock_wait (int *futex, const struct timespec *abstime)
return ETIMEDOUT;
/* Wait. */
- int oldval = *futex;
if (__builtin_expect (oldval & FUTEX_OWNER_DIED, 0))
return oldval;
@@ -90,8 +101,13 @@ __lll_robust_timedlock_wait (int *futex, const struct timespec *abstime)
continue;
lll_futex_timed_wait (futex, newval, &rt);
+
+ try:
+ ;
}
- while (atomic_compare_and_exchange_bool_acq (futex, tid | FUTEX_WAITERS, 0));
+ while ((oldval = atomic_compare_and_exchange_val_acq (futex,
+ tid | FUTEX_WAITERS,
+ 0)) != 0);
return 0;
}
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/pthread_setaffinity.c b/libc/nptl/sysdeps/unix/sysv/linux/pthread_setaffinity.c
index 3776e26e4..fa0f46fee 100644
--- a/libc/nptl/sysdeps/unix/sysv/linux/pthread_setaffinity.c
+++ b/libc/nptl/sysdeps/unix/sysv/linux/pthread_setaffinity.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2003, 2004, 2006 Free Software Foundation, Inc.
+/* Copyright (C) 2003, 2004, 2006, 2007 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
@@ -79,6 +79,12 @@ __pthread_setaffinity_new (pthread_t th, size_t cpusetsize,
res = INTERNAL_SYSCALL (sched_setaffinity, err, 3, pd->tid, cpusetsize,
cpuset);
+
+#ifdef RESET_VGETCPU_CACHE
+ if (!INTERNAL_SYSCALL_ERROR_P (res, err))
+ RESET_VGETCPU_CACHE ();
+#endif
+
return (INTERNAL_SYSCALL_ERROR_P (res, err)
? INTERNAL_SYSCALL_ERRNO (res, err)
: 0);
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_setaffinity.c b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_setaffinity.c
new file mode 100644
index 000000000..640d3044f
--- /dev/null
+++ b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_setaffinity.c
@@ -0,0 +1,14 @@
+#include <tls.h>
+
+#define RESET_VGETCPU_CACHE() \
+ do { \
+ asm volatile ("movl %0, %%fs:%P1\n\t" \
+ "movl %0, %%fs:%P2" \
+ : \
+ : "ir" (0), "i" (offsetof (struct pthread, \
+ header.vgetcpu_cache[0])), \
+ "i" (offsetof (struct pthread, \
+ header.vgetcpu_cache[1]))); \
+ } while (0)
+
+#include "../pthread_setaffinity.c"
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S
index c44d3f5e7..76a566b98 100644
--- a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S
+++ b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
+/* Copyright (C) 2002, 2003, 2005, 2007 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
@@ -40,12 +40,6 @@
.align 16
cfi_startproc
sem_timedwait:
- /* First check for cancellation. */
- movl %fs:CANCELHANDLING, %eax
- andl $0xfffffff9, %eax
- cmpl $8, %eax
- je 11f
-
movl (%rdi), %eax
2: testl %eax, %eax
je 1f
@@ -160,16 +154,5 @@ sem_timedwait:
orl $-1, %eax
jmp 10b
- cfi_adjust_cfa_offset(-48)
- cfi_restore(14)
- cfi_restore(13)
- cfi_restore(12)
-
-11: /* Canceled. */
- movq $0xffffffffffffffff, %fs:RESULT
- LOCK
- orl $0x10, %fs:CANCELHANDLING
- movq %fs:CLEANUP_JMP_BUF, %rdi
- jmp HIDDEN_JUMPTARGET (__pthread_unwind)
cfi_endproc
.size sem_timedwait,.-sem_timedwait
diff --git a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S
index 63ecd063a..5bd78eb94 100644
--- a/libc/nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S
+++ b/libc/nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
+/* Copyright (C) 2002, 2003, 2005, 2007 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
@@ -37,12 +37,6 @@
.align 16
cfi_startproc
sem_wait:
- /* First check for cancellation. */
- movl %fs:CANCELHANDLING, %eax
- andl $0xfffffff9, %eax
- cmpl $8, %eax
- je 4f
-
pushq %r12
cfi_adjust_cfa_offset(8)
cfi_offset(12, -16)
@@ -109,12 +103,5 @@ sem_wait:
cfi_restore(12)
retq
-
-4: /* Canceled. */
- movq $0xffffffffffffffff, %fs:RESULT
- LOCK
- orl $0x10, %fs:CANCELHANDLING
- movq %fs:CLEANUP_JMP_BUF, %rdi
- jmp HIDDEN_JUMPTARGET (__pthread_unwind)
cfi_endproc
.size sem_wait,.-sem_wait
diff --git a/libc/nptl/tst-align2.c b/libc/nptl/tst-align2.c
index ec85f435b..9c300ecd1 100644
--- a/libc/nptl/tst-align2.c
+++ b/libc/nptl/tst-align2.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2004 Free Software Foundation, Inc.
+/* Copyright (C) 2004, 2007 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -24,6 +24,7 @@
#include <sys/wait.h>
#include <unistd.h>
#include <tst-stack-align.h>
+#include <stackinfo.h>
static int
f (void *arg)
@@ -53,8 +54,14 @@ do_test (void)
char st[256 * 1024];
pid_t p = __clone2 (f, st, sizeof (st), 0, 0);
#else
- char st[128 * 1024];
+ char st[128 * 1024] __attribute__ ((aligned));
+# if _STACK_GROWS_DOWN
pid_t p = clone (f, st + sizeof (st), 0, 0);
+# elif _STACK_GROWS_UP
+ pid_t p = clone (f, st, 0, 0);
+# else
+# error "Define either _STACK_GROWS_DOWN or _STACK_GROWS_UP"
+# endif
#endif
if (p == -1)
{
diff --git a/libc/nptl/tst-cancel-wrappers.sh b/libc/nptl/tst-cancel-wrappers.sh
index 4e0252911..281bc1ee7 100644
--- a/libc/nptl/tst-cancel-wrappers.sh
+++ b/libc/nptl/tst-cancel-wrappers.sh
@@ -1,6 +1,6 @@
#! /bin/sh
# Test whether all cancelable functions are cancelable.
-# Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+# Copyright (C) 2002, 2003, 2007 Free Software Foundation, Inc.
# This file is part of the GNU C Library.
# Contributed by Jakub Jelinek <jakub@redhat.com>, 2002.
@@ -27,6 +27,7 @@ C["close"]=1
C["connect"]=1
C["creat"]=1
C["fcntl"]=1
+C["fdatasync"]=1
C["fsync"]=1
C["msgrcv"]=1
C["msgsnd"]=1
diff --git a/libc/nptl/tst-cancel4.c b/libc/nptl/tst-cancel4.c
index 73cfa4461..45df6ce07 100644
--- a/libc/nptl/tst-cancel4.c
+++ b/libc/nptl/tst-cancel4.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
+/* Copyright (C) 2002, 2003, 2004, 2006, 2007 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
@@ -1571,6 +1571,47 @@ tf_fsync (void *arg)
static void *
+tf_fdatasync (void *arg)
+{
+ if (arg == NULL)
+ // XXX If somebody can provide a portable test case in which fdatasync()
+ // blocks we can enable this test to run in both rounds.
+ abort ();
+
+ tempfd = open ("Makefile", O_RDONLY);
+ if (tempfd == -1)
+ {
+ printf ("%s: cannot open Makefile\n", __FUNCTION__);
+ exit (1);
+ }
+
+ int r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ r = pthread_barrier_wait (&b2);
+ if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+ {
+ printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
+ exit (1);
+ }
+
+ pthread_cleanup_push (cl, NULL);
+
+ fdatasync (tempfd);
+
+ pthread_cleanup_pop (0);
+
+ printf ("%s: fdatasync returned\n", __FUNCTION__);
+
+ exit (1);
+}
+
+
+static void *
tf_msync (void *arg)
{
if (arg == NULL)
@@ -2078,6 +2119,7 @@ static struct
ADD_TEST (pread, 2, 1),
ADD_TEST (pwrite, 2, 1),
ADD_TEST (fsync, 2, 1),
+ ADD_TEST (fdatasync, 2, 1),
ADD_TEST (msync, 2, 1),
ADD_TEST (sendto, 2, 1),
ADD_TEST (sendmsg, 2, 1),
diff --git a/libc/nptl/tst-getpid1.c b/libc/nptl/tst-getpid1.c
index f9fd4fc0c..253ebf2e1 100644
--- a/libc/nptl/tst-getpid1.c
+++ b/libc/nptl/tst-getpid1.c
@@ -5,6 +5,7 @@
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
+#include <stackinfo.h>
#ifndef TEST_CLONE_FLAGS
#define TEST_CLONE_FLAGS 0
@@ -48,7 +49,13 @@ do_test (void)
pid_t p = __clone2 (f, st, sizeof (st), TEST_CLONE_FLAGS, 0);
#else
char st[128 * 1024] __attribute__ ((aligned));
+# if _STACK_GROWS_DOWN
pid_t p = clone (f, st + sizeof (st), TEST_CLONE_FLAGS, 0);
+# elif _STACK_GROWS_UP
+ pid_t p = clone (f, st, TEST_CLONE_FLAGS, 0);
+# else
+# error "Define either _STACK_GROWS_DOWN or _STACK_GROWS_UP"
+# endif
#endif
if (p == -1)
{