This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Benchmark for sem_timedwait v1.1


On Thu, Feb 13, 2014 at 03:52:00PM +0530, Siddhesh Poyarekar wrote:
> On Tue, Feb 11, 2014 at 09:47:51PM +0100, OndÅej BÃlka wrote:
> > I used a same test for sem_timedwait. Results look inconclusive for
> > uncontended case and in contended case assembly is bit faster.
> > 
> > There is again question if assembly implementation is worth it, or if it
> > suffices to write only hot path in assembly and refactor a cold
> > implementation to have a futex path in separate function that would be
> > called from assembly.
> > 
> > Comments on this?
> 
> Please try to use bench-skeleton.c.  I think Torvald had proposed some
> patches a while back that should enable you to do this, although the
> actual benchmarks to use those patches didn't make it in AFAICT.
> 
> If using bench-skeleton.c is not possible directly, I would appreciate
> improvements to it to actually make it work.
> 
> Siddhesh

Here.


	* benchtests/Makefile (nptl-bench): Add.
	(benchset): Add nptl-bench.
	* benchtests/bench-sem_timedwait.c: New file.

---
 benchtests/Makefile              |  6 +++-
 benchtests/bench-sem_timedwait.c | 78 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 83 insertions(+), 1 deletion(-)
 create mode 100644 benchtests/bench-sem_timedwait.c

diff --git a/benchtests/Makefile b/benchtests/Makefile
index 8bfb039..c8fd3c3 100644
--- a/benchtests/Makefile
+++ b/benchtests/Makefile
@@ -33,7 +33,11 @@ string-bench-all := $(string-bench)
 
 stdlib-bench := strtod
 
-benchset := $(string-bench-all) $(stdlib-bench)
+nptl-bench := sem_timedwait
+
+benchset := $(nptl-bench) $(string-bench-all) $(stdlib-bench)
+
+LDLIBS-bench-sem_timedwait = -lpthread
 
 LDLIBS-bench-acos = -lm
 LDLIBS-bench-acosh = -lm
diff --git a/benchtests/bench-sem_timedwait.c b/benchtests/bench-sem_timedwait.c
new file mode 100644
index 0000000..9c3144b
--- /dev/null
+++ b/benchtests/bench-sem_timedwait.c
@@ -0,0 +1,78 @@
+/* Measure sem_timedwait function.
+   Copyright (C) 2014 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
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+
+#define TEST_MAIN
+#define TEST_NAME "strtok"
+#include "bench-string.h"
+
+#include <stdio.h>
+#include <pthread.h>
+#include <semaphore.h>
+
+static int
+test_main (void)
+{
+  test_init ();
+
+  struct timespec t1, t2, t3;
+  sem_t sem;
+  sem_init (&sem, 0, 0);
+  int iters = 1;
+
+  puts ("\nuncontended\n\n");
+  for (int i = 0; i < 10; i++)
+    {
+      timing_t start, stop, cur;
+      TIMING_NOW (start);
+
+      clock_gettime (CLOCK_REALTIME, &t1);
+      t3 = t1;
+      t3.tv_nsec += 10000;
+      sem_post (&sem);
+      sem_timedwait (&sem, &t3);
+      
+      TIMING_NOW (stop);
+
+      TIMING_DIFF (cur, start, stop);
+
+      TIMING_PRINT_MEAN ((double) cur, (double) iters);
+    }
+
+  puts ("\n\ncontended\n\n");
+  for (int i = 0; i < 10; i++)
+    {
+      timing_t start, stop, cur;
+      TIMING_NOW (start);
+
+      clock_gettime (CLOCK_REALTIME, &t1);
+      t3 = t1;
+      t3.tv_nsec += 10000;
+      sem_timedwait (&sem, &t3);
+      
+      TIMING_NOW (stop);
+
+      TIMING_DIFF (cur, start, stop);
+
+      TIMING_PRINT_MEAN ((double) cur, (double) iters);
+    }
+
+  return 0;
+}
+
+#include "../test-skeleton.c"
-- 
1.8.4.rc3




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]