From: Steven Munroe <munroesj@us.ibm.com>
To: GNU libc hacker <libc-hacker@sources.redhat.com>,
Paul Mackerras <paulus@samba.org>
Cc: Ryan Arnold <rsa@us.ibm.com>, Alan Modra <amodra@bigpond.net.au>
Subject: [PATCH] clean up PPC for private futex changes.
Date: Fri, 13 Jul 2007 20:44:00 -0000 [thread overview]
Message-ID: <4697E92C.1010403@us.ibm.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 473 bytes --]
PPC is broken in mainline due to missing private futex support. The
attached patch attempts to enable PPC for private futexes. I am not sure
if I reverse engineered the i386/x86_64 changes correctly so a close
inspection would be appreciated (especially for lll_futex_wake_unlock!).
With the attached patch powerpc32/powerpc64 makes/make checks cleanly on
a none-private futex eanbled kernel.
Paul what is the status of private futex support powerpc64 kernels?
thanks
[-- Attachment #2: ppc-private-futex-20070710.txt --]
[-- Type: text/plain, Size: 11114 bytes --]
2007-07-10 Steven Munroe <sjmunroe@us.ibm.com>
* pthread_rwlock_rdlock.c (__pthread_rwlock_rdlock): Add LLL_SHARED
parameter to lll_futex_wait call.
* pthread_rwlock_wrlock.c (__pthread_rwlock_wrlock): Likewise.
* sysdeps/unix/sysv/linux/powerpc/pthread_once.c (__pthread_once):
Replace lll_futex_wait with lll_private_futex_wait.
* sysdeps/unix/sysv/linux/powerpc/sem_post.c (__new_sem_post):
Add LLL_SHARED parameter to lll_futex_wake().
* sysdeps/unix/sysv/linux/powerpc/lowlevellock.h: Define LLL_PRIVATE
LLL_SHARED, lll_private_futex_wait, lll_private_futex_timed_wait and
lll_private_futex_wake.
(lll_futex_wait): Add private parameter. Adjust FUTEX_PRIVATE_FLAG
bit from private parm before syscall.
(lll_futex_timed_wait): Likewise.
(lll_futex_wake): Likewise.
(lll_futex_wake_unlock): Likewise.
(lll_mutex_unlock): Add LLL_SHARED parm to lll_futex_wake call.
(lll_robust_mutex_unlock): Likewise.
(lll_mutex_unlock_force): Likewise.
(lll_wait_tid): Add LLL_SHARED parm to lll_futex_wait call.
diff -urN libc25-cvstip-20070710/nptl/pthread_rwlock_rdlock.c libc25/nptl/pthread_rwlock_rdlock.c
--- libc25-cvstip-20070710/nptl/pthread_rwlock_rdlock.c 2007-05-26 17:11:31.000000000 -0500
+++ libc25/nptl/pthread_rwlock_rdlock.c 2007-07-11 15:46:33.775044328 -0500
@@ -77,7 +77,9 @@
lll_mutex_unlock (rwlock->__data.__lock);
/* Wait for the writer to finish. */
- lll_futex_wait (&rwlock->__data.__readers_wakeup, waitval);
+ lll_futex_wait (&rwlock->__data.__readers_wakeup, waitval,
+ // XYZ check mutex flag
+ LLL_SHARED);
/* Get the lock. */
lll_mutex_lock (rwlock->__data.__lock);
diff -urN libc25-cvstip-20070710/nptl/pthread_rwlock_wrlock.c libc25/nptl/pthread_rwlock_wrlock.c
--- libc25-cvstip-20070710/nptl/pthread_rwlock_wrlock.c 2006-10-28 00:11:15.000000000 -0500
+++ libc25/nptl/pthread_rwlock_wrlock.c 2007-07-13 15:45:04.763093928 -0500
@@ -1,4 +1,4 @@
-/* Copyright (C) 2003 Free Software Foundation, Inc.
+/* Copyright (C) 2003, 2007 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Martin Schwidefsky <schwidefsky@de.ibm.com>, 2003.
@@ -68,7 +68,9 @@
lll_mutex_unlock (rwlock->__data.__lock);
/* Wait for the writer or reader(s) to finish. */
- lll_futex_wait (&rwlock->__data.__writer_wakeup, waitval);
+ lll_futex_wait (&rwlock->__data.__writer_wakeup, waitval,
+ // XYZ check mutex flag
+ LLL_SHARED);
/* Get the lock. */
lll_mutex_lock (rwlock->__data.__lock);
diff -urN libc25-cvstip-20070710/nptl/sysdeps/unix/sysv/linux/powerpc/lowlevellock.h libc25/nptl/sysdeps/unix/sysv/linux/powerpc/lowlevellock.h
--- libc25-cvstip-20070710/nptl/sysdeps/unix/sysv/linux/powerpc/lowlevellock.h 2007-05-29 23:44:54.000000000 -0500
+++ libc25/nptl/sysdeps/unix/sysv/linux/powerpc/lowlevellock.h 2007-07-13 14:41:43.810089800 -0500
@@ -39,37 +39,46 @@
#define FUTEX_TRYLOCK_PI 8
#define FUTEX_PRIVATE_FLAG 128
+/* Values for 'private' parameter of locking macros. Yes, the
+ definition seems to be backwards. But it is not. The bit will be
+ reversed before passing to the system call. */
+#define LLL_PRIVATE 0
+#define LLL_SHARED FUTEX_PRIVATE_FLAG
+
/* Initializer for compatibility lock. */
#define LLL_MUTEX_LOCK_INITIALIZER (0)
-#define lll_futex_wait(futexp, val) \
+#define lll_futex_wait(futexp, val, private) \
({ \
INTERNAL_SYSCALL_DECL (__err); \
+ long int opt_flags = (FUTEX_WAIT | LLL_SHARED) ^ private; \
long int __ret; \
\
__ret = INTERNAL_SYSCALL (futex, __err, 4, \
- (futexp), FUTEX_WAIT, (val), 0); \
+ (futexp), opt_flags, (val), 0); \
INTERNAL_SYSCALL_ERROR_P (__ret, __err) ? -__ret : __ret; \
})
-#define lll_futex_timed_wait(futexp, val, timespec) \
+#define lll_futex_timed_wait(futexp, val, timespec, private) \
({ \
INTERNAL_SYSCALL_DECL (__err); \
+ long int opt_flags = (FUTEX_WAIT | LLL_SHARED) ^ private; \
long int __ret; \
\
__ret = INTERNAL_SYSCALL (futex, __err, 4, \
- (futexp), FUTEX_WAIT, (val), (timespec)); \
+ (futexp), opt_flags, (val), (timespec)); \
INTERNAL_SYSCALL_ERROR_P (__ret, __err) ? -__ret : __ret; \
})
-#define lll_futex_wake(futexp, nr) \
+#define lll_futex_wake(futexp, nr, private) \
({ \
INTERNAL_SYSCALL_DECL (__err); \
+ long int opt_flags = (FUTEX_WAKE | LLL_SHARED) ^ private; \
long int __ret; \
\
__ret = INTERNAL_SYSCALL (futex, __err, 4, \
- (futexp), FUTEX_WAKE, (nr), 0); \
+ (futexp), opt_flags, (nr), 0); \
INTERNAL_SYSCALL_ERROR_P (__ret, __err) ? -__ret : __ret; \
})
@@ -97,17 +106,69 @@
})
/* Returns non-zero if error happened, zero if success. */
-#define lll_futex_wake_unlock(futexp, nr_wake, nr_wake2, futexp2) \
+#define lll_futex_wake_unlock(futexp, nr_wake, nr_wake2, futexp2, private) \
({ \
INTERNAL_SYSCALL_DECL (__err); \
+ long int opt_flags = (FUTEX_WAKE_OP | LLL_SHARED) ^ private; \
+ long int opt_flag2 = (FUTEX_OP_CLEAR_WAKE_IF_GT_ONE | LLL_SHARED) \
+ ^ private; \
long int __ret; \
\
__ret = INTERNAL_SYSCALL (futex, __err, 6, \
- (futexp), FUTEX_WAKE_OP, (nr_wake), \
+ (futexp), opt_flags, (nr_wake), \
(nr_wake2), (futexp2), \
- FUTEX_OP_CLEAR_WAKE_IF_GT_ONE); \
+ opt_flag2); \
INTERNAL_SYSCALL_ERROR_P (__ret, __err); \
})
+
+
+#define lll_private_futex_wait(futexp, val) \
+ lll_private_futex_timed_wait (futexp, val, NULL)
+
+
+#ifdef __ASSUME_PRIVATE_FUTEX
+# define lll_private_futex_timed_wait(futexp, val, timeout) \
+ ({ \
+ INTERNAL_SYSCALL_DECL (__err); \
+ long int __ret; \
+ \
+ __ret = INTERNAL_SYSCALL (futex, __err, 4, \
+ (futexp), (FUTEX_WAIT | FUTEX_PRIVATE_FLAG), \
+ (val), (timeout)); \
+ INTERNAL_SYSCALL_ERROR_P (__ret, __err) ? -__ret : __ret; \
+ })
+
+# define lll_private_futex_wake(futexp, val) \
+ ({ \
+ INTERNAL_SYSCALL_DECL (__err); \
+ long int __ret; \
+ \
+ __ret = INTERNAL_SYSCALL (futex, __err, 4, \
+ (futexp), (FUTEX_WAKE | FUTEX_PRIVATE_FLAG), \
+ (val), 0); \
+ INTERNAL_SYSCALL_ERROR_P (__ret, __err) ? -__ret : __ret; \
+ })
+#else
+# define lll_private_futex_timed_wait(futexp, val, timeout) \
+ ({ \
+ INTERNAL_SYSCALL_DECL (__err); \
+ long int __ret; \
+ \
+ __ret = INTERNAL_SYSCALL (futex, __err, 4, \
+ (futexp), FUTEX_WAIT, (val), (timeout)); \
+ INTERNAL_SYSCALL_ERROR_P (__ret, __err) ? -__ret : __ret; \
+ })
+
+# define lll_private_futex_wake(futexp, val) \
+ ({ \
+ INTERNAL_SYSCALL_DECL (__err); \
+ long int __ret; \
+ \
+ __ret = INTERNAL_SYSCALL (futex, __err, 4, \
+ (futexp), FUTEX_WAKE, (val), 0); \
+ INTERNAL_SYSCALL_ERROR_P (__ret, __err) ? -__ret : __ret; \
+ })
+#endif
#ifdef UP
# define __lll_acq_instr ""
@@ -230,7 +291,7 @@
int *__futex = &(lock); \
int __val = atomic_exchange_rel (__futex, 0); \
if (__builtin_expect (__val > 1, 0)) \
- lll_futex_wake (__futex, 1); \
+ lll_futex_wake (__futex, 1, LLL_SHARED); \
}))
#define lll_robust_mutex_unlock(lock) \
@@ -238,7 +299,7 @@
int *__futex = &(lock); \
int __val = atomic_exchange_rel (__futex, 0); \
if (__builtin_expect (__val & FUTEX_WAITERS, 0)) \
- lll_futex_wake (__futex, 1); \
+ lll_futex_wake (__futex, 1, LLL_SHARED); \
}))
#define lll_mutex_unlock_force(lock) \
@@ -246,7 +307,7 @@
int *__futex = &(lock); \
*__futex = 0; \
__asm __volatile (__lll_rel_instr ::: "memory"); \
- lll_futex_wake (__futex, 1); \
+ lll_futex_wake (__futex, 1, LLL_SHARED); \
}))
#define lll_mutex_islocked(futex) \
@@ -281,7 +342,7 @@
do { \
__typeof (tid) __tid; \
while ((__tid = (tid)) != 0) \
- lll_futex_wait (&(tid), __tid); \
+ lll_futex_wait (&(tid), __tid, LLL_SHARED); \
} while (0)
extern int __lll_timedwait_tid (int *, const struct timespec *)
diff -urN libc25-cvstip-20070710/nptl/sysdeps/unix/sysv/linux/powerpc/pthread_once.c libc25/nptl/sysdeps/unix/sysv/linux/powerpc/pthread_once.c
--- libc25-cvstip-20070710/nptl/sysdeps/unix/sysv/linux/powerpc/pthread_once.c 2004-09-08 01:07:35.000000000 -0500
+++ libc25/nptl/sysdeps/unix/sysv/linux/powerpc/pthread_once.c 2007-07-13 15:44:06.908102352 -0500
@@ -1,4 +1,4 @@
-/* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+/* Copyright (C) 2003, 2004, 2007 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Paul Mackerras <paulus@au.ibm.com>, 2003.
@@ -30,7 +30,7 @@
pthread_once_t *once_control = (pthread_once_t *) arg;
*once_control = 0;
- lll_futex_wake (once_control, INT_MAX);
+ lll_private_futex_wake (once_control, INT_MAX);
}
@@ -74,7 +74,7 @@
break;
/* Same generation, some other thread was faster. Wait. */
- lll_futex_wait (once_control, oldval);
+ lll_private_futex_wait (once_control, oldval);
}
@@ -92,7 +92,7 @@
atomic_increment (once_control);
/* Wake up all other threads. */
- lll_futex_wake (once_control, INT_MAX);
+ lll_private_futex_wake (once_control, INT_MAX);
return 0;
}
diff -urN libc25-cvstip-20070710/nptl/sysdeps/unix/sysv/linux/powerpc/sem_post.c libc25/nptl/sysdeps/unix/sysv/linux/powerpc/sem_post.c
--- libc25-cvstip-20070710/nptl/sysdeps/unix/sysv/linux/powerpc/sem_post.c 2007-05-15 01:31:57.000000000 -0500
+++ libc25/nptl/sysdeps/unix/sysv/linux/powerpc/sem_post.c 2007-07-13 15:43:52.523158896 -0500
@@ -1,5 +1,5 @@
/* sem_post -- post to a POSIX semaphore. Powerpc version.
- Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ Copyright (C) 2003, 2004, 2007 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Paul Mackerras <paulus@au.ibm.com>, 2003.
@@ -33,7 +33,7 @@
__asm __volatile (__lll_rel_instr ::: "memory");
int nr = atomic_increment_val (futex);
- int err = lll_futex_wake (futex, nr);
+ int err = lll_futex_wake (futex, nr, LLL_SHARED);
if (__builtin_expect (err, 0) < 0)
{
__set_errno (-err);
next reply other threads:[~2007-07-13 20:44 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-13 20:44 Steven Munroe [this message]
2007-07-23 16:10 ` Ulrich Drepper
2007-07-23 20:43 ` Jakub Jelinek
2007-07-23 22:09 ` Steven Munroe
2007-07-24 7:11 ` Jakub Jelinek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4697E92C.1010403@us.ibm.com \
--to=munroesj@us.ibm.com \
--cc=amodra@bigpond.net.au \
--cc=libc-hacker@sources.redhat.com \
--cc=paulus@samba.org \
--cc=rsa@us.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).