This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] Add wake optimisation to PowerPC POSIX semaphores
- From: Anton Blanchard <anton at samba dot org>
- To: libc-alpha at sources dot redhat dot com, sjmunroe at us dot ibm dot com
- Date: Mon, 30 Jul 2007 12:59:55 -0500
- Subject: [PATCH] Add wake optimisation to PowerPC POSIX semaphores
Update PowerPC POSIX semaphores to call lll_futex_wake only when there
are waiters. The performance of calls to sem_wait and sem_post improve
as expected:
baseline of sem_wait+sem_post:
1629.22 cycles
patched:
261.38 cycles
Anton
--
2007-07-30 Anton Blanchard <anton@samba.org>
* sysdeps/unix/sysv/linux/powerpc/sem_post.c: Wake only when there
are waiters.
diff -ru libc/nptl/sysdeps/unix/sysv/linux/powerpc/sem_post.c libc.work/nptl/sysdeps/unix/sysv/linux/powerpc/sem_post.c
--- libc/nptl/sysdeps/unix/sysv/linux/powerpc/sem_post.c 2007-07-23 11:07:10.000000000 -0500
+++ libc.work/nptl/sysdeps/unix/sysv/linux/powerpc/sem_post.c 2007-07-29 12:48:17.000000000 -0500
@@ -29,11 +29,38 @@
int
__new_sem_post (sem_t *sem)
{
+ struct new_sem *isem = (struct new_sem *) sem;
+
+ __asm __volatile (__lll_rel_instr ::: "memory");
+ int nr = atomic_increment_val (&isem->value);
+ __asm __volatile (__lll_acq_instr ::: "memory");
+ if (isem->nwaiters > 0)
+ {
+ int err = lll_futex_wake (&isem->value, 1,
+ // XYZ check mutex flag
+ LLL_SHARED);
+ if (__builtin_expect (err, 0) < 0)
+ {
+ __set_errno (-err);
+ return -1;
+ }
+ }
+ return 0;
+}
+versioned_symbol (libpthread, __new_sem_post, sem_post, GLIBC_2_1);
+
+
+#if SHLIB_COMPAT (libpthread, GLIBC_2_0, GLIBC_2_1)
+int
+attribute_compat_text_section
+__old_sem_post (sem_t *sem)
+{
int *futex = (int *) sem;
__asm __volatile (__lll_rel_instr ::: "memory");
int nr = atomic_increment_val (futex);
- int err = lll_futex_wake (futex, nr, LLL_SHARED);
+ /* We always have to assume it is a shared semaphore. */
+ int err = lll_futex_wake (futex, 1, LLL_SHARED);
if (__builtin_expect (err, 0) < 0)
{
__set_errno (-err);
@@ -41,8 +68,5 @@
}
return 0;
}
-versioned_symbol (libpthread, __new_sem_post, sem_post, GLIBC_2_1);
-#if SHLIB_COMPAT (libpthread, GLIBC_2_0, GLIBC_2_1)
-strong_alias (__new_sem_post, __old_sem_post)
compat_symbol (libpthread, __old_sem_post, sem_post, GLIBC_2_0);
#endif