This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [RFC][BZ #16549, #16410] Remove pthread_(cond)wait assembly implementations?
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: Roland McGrath <roland at hack dot frob dot com>
- Cc: libc-alpha at sourceware dot org
- Date: Tue, 11 Feb 2014 19:45:30 +0100
- Subject: Re: [RFC][BZ #16549, #16410] Remove pthread_(cond)wait assembly implementations?
- Authentication-results: sourceware.org; auth=none
- References: <20140211172324 dot GA31923 at domone dot podge> <20140211172720 dot 52ABB7445F at topped-with-meat dot com>
On Tue, Feb 11, 2014 at 09:27:20AM -0800, Roland McGrath wrote:
> These were written in assembly to begin with because C versions did not
> perform adequately. It's entirely possible the compiler has improved
> enough to change that calculus. But actual performance analysis is
> required.
I used following benchmark for timedwait and deleting assembly
implementation actually improves performance by around 5000 cycles.
old one:
cond wait spend time: 0.000067360
cond wait spend time: 0.000064957
cond wait spend time: 0.000055014
cond wait spend time: 0.000063775
cond wait spend time: 0.000064073
cond wait spend time: 0.000063578
cond wait spend time: 0.000063339
cond wait spend time: 0.000064064
cond wait spend time: 0.000063312
cond wait spend time: 0.000063331
new one:
cond wait spend time: 0.000064140
cond wait spend time: 0.000062096
cond wait spend time: 0.000061748
cond wait spend time: 0.000061601
cond wait spend time: 0.000061581
cond wait spend time: 0.000061620
cond wait spend time: 0.000061725
cond wait spend time: 0.000061611
cond wait spend time: 0.000061601
cond wait spend time: 0.000061591
diff --git a/benchtests/Makefile b/benchtests/Makefile
index 8bfb039..2736f58 100644
--- a/benchtests/Makefile
+++ b/benchtests/Makefile
@@ -33,8 +33,12 @@ string-bench-all := $(string-bench)
stdlib-bench := strtod
-benchset := $(string-bench-all) $(stdlib-bench)
+nptl-bench := pthread_cond_timedwait
+
+benchset := $(nptl-bench) $(string-bench-all) $(stdlib-bench)
+
+LDLIBS-bench-pthread_cond_timedwait = -lpthread
LDLIBS-bench-acos = -lm
LDLIBS-bench-acosh = -lm
LDLIBS-bench-asin = -lm
diff --git a/benchtests/bench-pthread_cond_timedwait.c b/benchtests/bench-pthread_cond_timedwait.c
new file mode 100644
index 0000000..ec21893
--- /dev/null
+++ b/benchtests/bench-pthread_cond_timedwait.c
@@ -0,0 +1,42 @@
+#include <stdio.h>
+#include <pthread.h>
+
+int
+main ()
+{
+ struct timespec t1, t2, t3;
+ pthread_mutex_t mutex;
+ pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
+ pthread_mutex_init (&mutex, NULL);
+
+
+ for (int i = 0; i < 10; i++)
+ {
+ clock_gettime (CLOCK_REALTIME, &t1);
+ t3 = t1;
+ t3.tv_nsec += 10000;
+ pthread_mutex_lock (&mutex);
+ pthread_cond_timedwait (&cond, &mutex, &t3);
+ pthread_mutex_unlock (&mutex);
+
+ clock_gettime (CLOCK_REALTIME, &t2);
+
+ if (t2.tv_nsec >= t1.tv_nsec)
+ {
+ t2.tv_sec -= t1.tv_sec;
+ t2.tv_nsec -= t1.tv_nsec;
+ }
+ else
+ {
+ t2.tv_sec = t2.tv_sec - t1.tv_sec - 1;
+ t2.tv_nsec = t2.tv_nsec + (1000000000 - t1.tv_nsec);
+ }
+
+ printf ("cond wait spend time: %d.%.9d\n", t2.tv_sec, t2.tv_nsec);
+ }
+ pthread_mutex_destroy (&mutex);
+ pthread_cond_destroy (&cond);
+
+
+ return 0;
+}