[PATCH] benchtests: Add pthread mutex trylock recursive throughput test (BZ #33704)

Sunil K Pandey sunil.k.pandey@intel.com
Wed Dec 17 00:39:42 GMT 2025


This benchmark measures number of successful updates per second
under high cache contention.

Tested on x86_64.
---
 benchtests/Makefile                           |  2 ++
 ...hread-mutex-trylock-recursive-throughput.c | 21 +++++++++++++++++++
 2 files changed, 23 insertions(+)
 create mode 100644 benchtests/bench-pthread-mutex-trylock-recursive-throughput.c

diff --git a/benchtests/Makefile b/benchtests/Makefile
index c3368a7603..59f4503ebb 100644
--- a/benchtests/Makefile
+++ b/benchtests/Makefile
@@ -175,6 +175,7 @@ bench-pthread := \
   pthread-locks \
   pthread-mutex-lock \
   pthread-mutex-trylock \
+  pthread-mutex-trylock-recursive-throughput \
   pthread-mutex-trylock-throughput \
   pthread-spin-lock \
   pthread-spin-trylock \
@@ -189,6 +190,7 @@ bench-resolv := \
 
 LDLIBS-bench-pthread-mutex-lock += -lm
 LDLIBS-bench-pthread-mutex-trylock += -lm
+LDLIBS-bench-pthread-mutex-trylock-recursive-throughput += -lm
 LDLIBS-bench-pthread-mutex-trylock-throughput += -lm
 LDLIBS-bench-pthread-spin-lock += -lm
 LDLIBS-bench-pthread-spin-trylock += -lm
diff --git a/benchtests/bench-pthread-mutex-trylock-recursive-throughput.c b/benchtests/bench-pthread-mutex-trylock-recursive-throughput.c
new file mode 100644
index 0000000000..9bfc4f1140
--- /dev/null
+++ b/benchtests/bench-pthread-mutex-trylock-recursive-throughput.c
@@ -0,0 +1,21 @@
+/* Measure pthread trylock recursive throughput under high cache contention.
+   Copyright (C) 2025 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
+   <https://www.gnu.org/licenses/>.  */
+
+#define TEST_NAME "pthread-mutex-trylock-recursive-throughput"
+#define PTHREAD_MUTEX_TYPE_INITIALIZER PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
+#include "bench-pthread-mutex-trylock-base.c"
-- 
2.51.0



More information about the Libc-alpha mailing list