This is the mail archive of the
libc-ports@sources.redhat.com
mailing list for the libc-ports project.
Re: performance problems with linuxthreads on arm
- From: Daniel Jacobowitz <drow at false dot org>
- To: Peter Menzebach <pm-libc at mw-itcon dot de>
- Cc: libc-ports at sources dot redhat dot com
- Date: Fri, 7 Oct 2005 11:37:01 -0400
- Subject: Re: performance problems with linuxthreads on arm
- References: <43469474.3050302@mw-itcon.de>
On Fri, Oct 07, 2005 at 05:29:56PM +0200, Peter Menzebach wrote:
> Dear all,
> I am using glibc-2.3.4 with linuxthreads (pthread library) for an
> application (running on an armv4 processor). Under certain conditions I
> had massive performance problems. The cpu load was < 10 %, but the
> handling of a message through some threads and due to locking costs up
> to 10 seconds instead of expected ~10 ms. I broke the problem down to
> the point, that I had exact the problem described here:
>
> http://lists.arm.linux.org.uk/pipermail/linux-arm/2002-June/003710.html
>
> I tested now solution 1, which is to take compare_and_swap from the
> glibc, and put it into linuxthreads too. This cured the problem on first
> sight.
>
> But since my knowledge about possible implications is very limited (and
> I fear, that this is a very bad idea), it would be nice, if someone has
> a comment or alternative.
It's nto a _great_ idea: this implementation is not quite atomic. You
can find a description of the race in the libc-alpha archives;
mid-2004, I think. However, it should work well enough in practice.
There are two other options. If your kernel is sufficiently new, you
can use the kernel atomic operations helpers above 0xffff0000; I'll be
posting patches in the next week or two for NPTL, and they'll require
those.
Or, you can fix the bug in LinuxThreads that causes performance to be
so lousy. I'm not completely sure, but I think the attached patch will
fix it. Want to give it a try?
--- glibc-2.3.2/linuxthreads/spinlock.c.orig 2004-02-11 10:34:59.000000000 -0500
+++ glibc-2.3.2/linuxthreads/spinlock.c 2004-02-11 10:39:05.000000000 -0500
@@ -637,8 +637,20 @@
#if defined HAS_COMPARE_AND_SWAP
wait_node_dequeue(pp_head, pp_max_prio, p_max_prio);
#endif
+
+ /* Release the spinlock before restarting. */
+#if defined TEST_FOR_COMPARE_AND_SWAP
+ if (!__pthread_has_cas)
+#endif
+#if !defined HAS_COMPARE_AND_SWAP || defined TEST_FOR_COMPARE_AND_SWAP
+ {
+ __pthread_release(&lock->__spinlock);
+ }
+#endif
+
restart(p_max_prio->thr);
- break;
+
+ return;
}
}
--
Daniel Jacobowitz
CodeSourcery, LLC