]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
benchtests: New benchmark for sem_timedwait siddhesh/sem_timedwait
authorSiddhesh Poyarekar <siddhesh@redhat.com>
Mon, 24 Feb 2014 02:38:14 +0000 (08:08 +0530)
committerSiddhesh Poyarekar <siddhesh@redhat.com>
Mon, 24 Feb 2014 02:38:14 +0000 (08:08 +0530)
Measure performance of the sem_timedwait function for a max wait of
1us in the contended and uncontended case.

benchtests/Makefile
benchtests/sem_timedwait_test-inputs [new file with mode: 0644]
benchtests/src-sem_timedwait_test.c [new file with mode: 0644]

index 792f61fdf9db6899e1bd146ee34e3f44dcc6f5f0..1f38ff1afc2c1ff08f436a3eca9e13767b8bbc4c 100644 (file)
 # Add benchmark functions in alphabetical order.
 
 subdir := benchtests
-bench := acos acosh asin asinh atan atanh cos cosh exp exp2 log log2 modf pow \
+math-bench := acos acosh asin asinh atan atanh cos cosh exp exp2 log log2 modf pow \
         rint sin sincos sinh sqrt tan tanh
 
+pthread-bench := sem_timedwait_test
+
+bench := $(math-bench) $(pthread-bench)
+
 # String function benchmarks.
 string-bench := bcopy bzero memccpy memchr memcmp memcpy memmem memmove \
                mempcpy memset rawmemchr stpcpy stpncpy strcasecmp strcasestr \
@@ -35,27 +39,6 @@ stdlib-bench := strtod
 
 benchset := $(string-bench-all) $(stdlib-bench)
 
-LDLIBS-bench-acos = -lm
-LDLIBS-bench-acosh = -lm
-LDLIBS-bench-asin = -lm
-LDLIBS-bench-asinh = -lm
-LDLIBS-bench-atan = -lm
-LDLIBS-bench-atanh = -lm
-LDLIBS-bench-cos = -lm
-LDLIBS-bench-cosh = -lm
-LDLIBS-bench-exp = -lm
-LDLIBS-bench-exp2 = -lm
-LDLIBS-bench-log = -lm
-LDLIBS-bench-log2 = -lm
-LDLIBS-bench-pow = -lm
-LDLIBS-bench-rint = -lm
-LDLIBS-bench-sin = -lm
-LDLIBS-bench-sinh = -lm
-LDLIBS-bench-sqrt = -lm
-LDLIBS-bench-tan = -lm
-LDLIBS-bench-tanh = -lm
-LDLIBS-bench-sincos = -lm
-
 \f
 
 # Rules to build and execute the benchmarks.  Do not put any benchmark
@@ -71,6 +54,22 @@ include ../Rules
 binaries-bench := $(addprefix $(objpfx)bench-,$(bench))
 binaries-benchset := $(addprefix $(objpfx)bench-,$(benchset))
 
+# Link to pthread
+ifeq ($(build-shared),yes)
+$(addprefix $(objpfx)bench-, \
+           $(pthread-bench)): $(objpfx)$(..)nptl/libpthread.so \
+                              $(objpfx)$(..)nptl/libpthread_nonshared.a
+else
+$(addprefix $(objpfx)bench-,$(pthread-bench)): $(objpfx)$(..)libpthread.a
+endif
+
+# Link to libm
+ifeq ($(build-shared),yes)
+$(addprefix $(objpfx)bench-, $(math-bench)): $(objpfx)$(..)math/libm.so
+else
+$(addprefix $(objpfx)bench-,$(math-bench)): $(objpfx)$(..)math/libm.a
+endif
+
 # The default duration: 10 seconds.
 ifndef BENCH_DURATION
 BENCH_DURATION := 10
diff --git a/benchtests/sem_timedwait_test-inputs b/benchtests/sem_timedwait_test-inputs
new file mode 100644 (file)
index 0000000..88a64f5
--- /dev/null
@@ -0,0 +1,10 @@
+## includes: stdbool.h,pthread.h,semaphore.h
+## include-sources: src-sem_timedwait_test.c
+## init: init_test
+#  The sole argument differentiates between the default uncontended and
+#  the contended case.
+## args: bool
+## name: uncontended
+false
+## name: contended
+true
diff --git a/benchtests/src-sem_timedwait_test.c b/benchtests/src-sem_timedwait_test.c
new file mode 100644 (file)
index 0000000..e50affd
--- /dev/null
@@ -0,0 +1,18 @@
+sem_t sem;
+
+void
+init_test (void)
+{
+  sem_init (&sem, 0, 0);
+}
+
+static inline void __always_inline
+sem_timedwait_test (bool contended)
+{
+  struct timespec t;
+  clock_gettime (CLOCK_REALTIME, &t);
+  t.tv_nsec += 10000;
+  if (!contended)
+    sem_post (&sem);
+  sem_timedwait (&sem, &t);
+}