Skip to contentSkip to conversation

perf, tools/testing: merge futextest into perf bench and tools/testing

PATCH New Hitoshi Mitake 1 participant 4 messages Nov 18, 2012

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover perf, tools/testing: merge futextest into perf bench and tools/testing

Hi perf and futex folks, very sorry for my slow posting...

This patchset merge futextest[1] of Darren Hart into perf bench and tools/testing/selftests with some refactorings.

The benchmarking part of futextest is now "perf bench futex" in the 2nd patch. And the part of functionality test is ported to tools/testing/selftests in the 3rd patch. The 1st one is for preparation. It adds useful header files which implements atomic operations and futex syscall wrappers to tools/include/tools directory for both of perf bench and tools/testing.

[1]: http://git.kernel.org/?p=linux/kernel/git/dvhart/futextest.git

Hitoshi Mitake (3):
tools: add new headers for futex and atomic operations perf bench: port futex_wait.c of futextest to perf bench tools/testing: port functionality tests of futextest to
tools/testing/selftests

 tools/include/tools/atomic.h                       |   95 +++++
 tools/include/tools/futex.h                        |  278 +++++++++++++++
 tools/perf/Makefile                                |    1 +
 tools/perf/bench/bench.h                           |    1 +
 tools/perf/bench/futex-wait.c                      |  295 +++++++++++++++
 tools/perf/builtin-bench.c                         |   13 +
 tools/testing/selftests/Makefile                   |    2 +-
 tools/testing/selftests/futex/.gitignore           |    9 +
 tools/testing/selftests/futex/Makefile             |   32 ++
 tools/testing/selftests/futex/futex_requeue_pi.c   |  376 ++++++++++++++++++++
 .../futex/futex_requeue_pi_mismatched_ops.c        |  151 ++++++++
 .../futex/futex_requeue_pi_signal_restart.c        |  202 +++++++++++
 .../testing/selftests/futex/futex_testing_common.c |   45 +++
 .../testing/selftests/futex/futex_testing_common.h |    9 +
 .../futex/futex_wait_private_mapped_file.c         |  137 +++++++
 tools/testing/selftests/futex/futex_wait_timeout.c |  101 ++++++
 .../futex/futex_wait_uninitialized_heap.c          |  139 +++++++
 .../selftests/futex/futex_wait_wouldblock.c        |   94 +++++
 tools/testing/selftests/futex/logging.c            |   93 +++++
 tools/testing/selftests/futex/logging.h            |   88 +++++
 tools/testing/selftests/futex/run.sh               |   92 +++++
 21 files changed, 2252 insertions(+), 1 deletions(-)
 create mode 100644 tools/include/tools/atomic.h
 create mode 100644 tools/include/tools/futex.h
 create mode 100644 tools/perf/bench/futex-wait.c
 create mode 100644 tools/testing/selftests/futex/.gitignore
 create mode 100644 tools/testing/selftests/futex/Makefile
 create mode 100644 tools/testing/selftests/futex/futex_requeue_pi.c
 create mode 100644 tools/testing/selftests/futex/futex_requeue_pi_mismatched_ops.c
 create mode 100644 tools/testing/selftests/futex/futex_requeue_pi_signal_restart.c
 create mode 100644 tools/testing/selftests/futex/futex_testing_common.c
 create mode 100644 tools/testing/selftests/futex/futex_testing_common.h
 create mode 100644 tools/testing/selftests/futex/futex_wait_private_mapped_file.c
 create mode 100644 tools/testing/selftests/futex/futex_wait_timeout.c
 create mode 100644 tools/testing/selftests/futex/futex_wait_uninitialized_heap.c
 create mode 100644 tools/testing/selftests/futex/futex_wait_wouldblock.c
 create mode 100644 tools/testing/selftests/futex/logging.c
 create mode 100644 tools/testing/selftests/futex/logging.h
 create mode 100755 tools/testing/selftests/futex/run.sh
Signature · 1 line
1.7.5.1
#1 lore raw

PATCH 1/3 tools: add new headers for futex and atomic operations

This patch adds two new header files in tools/ directory. The purpose of adding these two headers is supporting futextest and perf bench futex in the kernel tree. But these can be utilized by other purposes because they are generalized enough.

This patch produces 4 checkpatch warns because of typedefing and volatile declaration. But I think these warns are not essential problems. If these are not acceptable, I'll seek other way.

Cc Darren Hart <[email protected]>
Cc Eric Dumazet <[email protected]>
---
 tools/include/tools/atomic.h |   95 ++++++++++++++
 tools/include/tools/futex.h  |  278 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 373 insertions(+), 0 deletions(-)
 create mode 100644 tools/include/tools/atomic.h
 create mode 100644 tools/include/tools/futex.h
tools/include/tools/atomic.h new file +95 -0
new file mode 100644
index 0000000..8e52957
@@ -0,0 +1,95 @@
+/******************************************************************************
+ *
+ *   Copyright © International Business Machines  Corp., 2009
+ *
+ *   This program is free software;  you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program 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 General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program;  if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * NAME
+ *      atomic.h
+ *
+ * DESCRIPTION
+ *      GCC atomic builtin wrappers
+ *      http://gcc.gnu.org/onlinedocs/gcc-4.1.0/gcc/Atomic-Builtins.html
+ *
+ * AUTHOR
+ *      Darren Hart <[email protected]>
+ *
+ * HISTORY
+ *      2009-Nov-17: Initial version by Darren Hart <[email protected]>
+ *
+ *****************************************************************************/
+
+#ifndef _ATOMIC_H
+#define _ATOMIC_H
+
+typedef struct {
+	volatile int val;
+} atomic_t;
+
+#define ATOMIC_INITIALIZER { 0 }
+
+/**
+ * atomic_cmpxchg() - Atomic compare and exchange
+ * @uaddr:	The address of the futex to be modified
+ * @oldval:	The expected value of the futex
+ * @newval:	The new value to try and assign the futex
+ *
+ * Return the old value of addr->val.
+ */
+static inline int
+atomic_cmpxchg(atomic_t *addr, int oldval, int newval)
+{
+	return __sync_val_compare_and_swap(&addr->val, oldval, newval);
+}
+
+/**
+ * atomic_inc() - Atomic incrememnt
+ * @addr:	Address of the variable to increment
+ *
+ * Return the new value of addr->val.
+ */
+static inline int
+atomic_inc(atomic_t *addr)
+{
+	return __sync_add_and_fetch(&addr->val, 1);
+}
+
+/**
+ * atomic_dec() - Atomic decrement
+ * @addr:	Address of the variable to decrement
+ *
+ * Return the new value of addr-val.
+ */
+static inline int
+atomic_dec(atomic_t *addr)
+{
+	return __sync_sub_and_fetch(&addr->val, 1);
+}
+
+/**
+ * atomic_set() - Atomic set
+ * @addr:	Address of the variable to set
+ * @newval:	New value for the atomic_t
+ *
+ * Return the new value of addr->val.
+ */
+static inline int
+atomic_set(atomic_t *addr, int newval)
+{
+	addr->val = newval;
+	return newval;
+}
+
+#endif
tools/include/tools/futex.h new file +278 -0

278 lines not on this page · raw message

Signature · 1 line
1.7.5.1
#2 lore raw

PATCH 2/3 perf bench: port futex_wait.c of futextest to perf bench

In reply to Hitoshi Mitake

This patch ports futex_wait.c of futextest[1] to perf bench, as subsystem "futex" and its command "wait". This measures performance of iterations of FUTEX_WAIT, unit is kilo iteration of lock and unlock per second. Iterations, numbers of threads and futexes can be specified with command line options: -i for iteration, -t for number of threads, -f for number of futexes.

example of usage:

| # Running futex/wait benchmark...
| # 256 threads and 1 futexes (256 threads for 1 futex)
| 7.15s user, 60.24s system, 8.56s wall, 7.87 cores
| Result: 11682 Kiter/s

[1]: http://git.kernel.org/?p=linux/kernel/git/dvhart/futextest.git

Cc Peter Zijlstra <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Darren Hart <[email protected]>
Cc Eric Dumazet <[email protected]>
---
 tools/perf/Makefile           |    1 +
 tools/perf/bench/bench.h      |    1 +
 tools/perf/bench/futex-wait.c |  295 +++++++++++++++++++++++++++++++++++++++++
 tools/perf/builtin-bench.c    |   13 ++
 4 files changed, 310 insertions(+), 0 deletions(-)
 create mode 100644 tools/perf/bench/futex-wait.c
tools/perf/Makefile +1 -0
index cca5bb8..5c395a3 100644
@@ -443,6 +443,7 @@ BUILTIN_OBJS += $(OUTPUT)bench/mem-memset-x86-64-asm.o
 endif
 BUILTIN_OBJS += $(OUTPUT)bench/mem-memcpy.o
 BUILTIN_OBJS += $(OUTPUT)bench/mem-memset.o
+BUILTIN_OBJS += $(OUTPUT)bench/futex-wait.o
 
 BUILTIN_OBJS += $(OUTPUT)builtin-diff.o
 BUILTIN_OBJS += $(OUTPUT)builtin-evlist.o
tools/perf/bench/bench.h +1 -0
index 8f89998..f188b1d 100644
@@ -6,6 +6,7 @@ extern int bench_sched_pipe(int argc, const char **argv, const char *prefix);
 extern int bench_mem_memcpy(int argc, const char **argv,
 			    const char *prefix __maybe_unused);
 extern int bench_mem_memset(int argc, const char **argv, const char *prefix);
+extern int bench_futex_wait(int argc, const char **argv, const char *prefix);
 
 #define BENCH_FORMAT_DEFAULT_STR	"default"
 #define BENCH_FORMAT_DEFAULT		0
tools/perf/bench/futex-wait.c new file +295 -0

295 lines not on this page · raw message

tools/perf/builtin-bench.c +13 -0
index cae9a5f..0533736 100644
@@ -61,6 +61,16 @@ static struct bench_suite mem_suites[] = {
 	  NULL             }
 };
 
+static struct bench_suite futex_suites[] = {
+	{ "wait",
+	  "futex wait",
+	  bench_futex_wait },
+	suite_all,
+	{ NULL,
+	  NULL,
+	  NULL             }
+};
+
 struct bench_subsys {
 	const char *name;
 	const char *summary;
@@ -74,6 +84,9 @@ static struct bench_subsys subsystems[] = {
 	{ "mem",
 	  "memory access performance",
 	  mem_suites },
+	{ "futex",
+	  "futex performance",
+	  futex_suites },
 	{ "all",		/* sentinel: easy for help */
 	  "all benchmark subsystem",
 	  NULL },
Signature · 1 line
1.7.5.1
#3 lore raw

PATCH 3/3 tools/testing: port functionality tests of futextest to tools/testing/selftests

In reply to Hitoshi Mitake

This patch ports functionality tests of futextest to tools/testing/selftests. After applying this patch, "make run_tests" in tools/testing/selftests will also test functionalities of futex.

checkpatch.pl reports 8 errors and 1warning with this patch. I believe these can be acceptable. Because 1 error is for a line over 80 chars, but the line is a simple function prototype. And 8 errors are for lines which #define constants for line coloring.

If these are not acceptable, please tell me. I'll search other ways.

Cc KOSAKI Motohiro <[email protected]>
Cc Gowrishankar <[email protected]>
Cc Sripathi Kodi <[email protected]>
Cc Darren Hart <[email protected]>
Cc Eric Dumazet <[email protected]>
---
 tools/testing/selftests/Makefile                   |    2 +-
 tools/testing/selftests/futex/.gitignore           |    9 +
 tools/testing/selftests/futex/Makefile             |   32 ++
 tools/testing/selftests/futex/futex_requeue_pi.c   |  376 ++++++++++++++++++++
 .../futex/futex_requeue_pi_mismatched_ops.c        |  151 ++++++++
 .../futex/futex_requeue_pi_signal_restart.c        |  202 +++++++++++
 .../testing/selftests/futex/futex_testing_common.c |   45 +++
 .../testing/selftests/futex/futex_testing_common.h |    9 +
 .../futex/futex_wait_private_mapped_file.c         |  137 +++++++
 tools/testing/selftests/futex/futex_wait_timeout.c |  101 ++++++
 .../futex/futex_wait_uninitialized_heap.c          |  139 +++++++
 .../selftests/futex/futex_wait_wouldblock.c        |   94 +++++
 tools/testing/selftests/futex/logging.c            |   93 +++++
 tools/testing/selftests/futex/logging.h            |   88 +++++
 tools/testing/selftests/futex/run.sh               |   92 +++++
 15 files changed, 1569 insertions(+), 1 deletions(-)
 create mode 100644 tools/testing/selftests/futex/.gitignore
 create mode 100644 tools/testing/selftests/futex/Makefile
 create mode 100644 tools/testing/selftests/futex/futex_requeue_pi.c
 create mode 100644 tools/testing/selftests/futex/futex_requeue_pi_mismatched_ops.c
 create mode 100644 tools/testing/selftests/futex/futex_requeue_pi_signal_restart.c
 create mode 100644 tools/testing/selftests/futex/futex_testing_common.c
 create mode 100644 tools/testing/selftests/futex/futex_testing_common.h
 create mode 100644 tools/testing/selftests/futex/futex_wait_private_mapped_file.c
 create mode 100644 tools/testing/selftests/futex/futex_wait_timeout.c
 create mode 100644 tools/testing/selftests/futex/futex_wait_uninitialized_heap.c
 create mode 100644 tools/testing/selftests/futex/futex_wait_wouldblock.c
 create mode 100644 tools/testing/selftests/futex/logging.c
 create mode 100644 tools/testing/selftests/futex/logging.h
 create mode 100755 tools/testing/selftests/futex/run.sh
tools/testing/selftests/Makefile +1 -1
index 85baf11..adeacbb 100644
@@ -1,4 +1,4 @@
-TARGETS = breakpoints kcmp mqueue vm cpu-hotplug memory-hotplug
+TARGETS = breakpoints kcmp mqueue vm cpu-hotplug memory-hotplug futex
 
 all:
 	for TARGET in $(TARGETS); do \
tools/testing/selftests/futex/.gitignore new file +9 -0
new file mode 100644
index 0000000..c075e7f
@@ -0,0 +1,9 @@
+futex_requeue_pi
+futex_requeue_pi_mismatched_ops
+futex_requeue_pi_signal_restart
+futex_wait_private_mapped_file
+futex_wait_timeout
+futex_wait_uninitialized_heap
+futex_wait_wouldblock
+
+*.o
tools/testing/selftests/futex/Makefile new file +32 -0
new file mode 100644
index 0000000..1b03b22
@@ -0,0 +1,32 @@
+HEADER_DIR := ../../../include/tools
+CFLAGS := $(CFLAGS) -g -O2 -Wall -D_GNU_SOURCE -I$(HEADER_DIR)
+LDFLAGS := $(LDFLAGS) -lpthread -lrt
+
+HEADERS := $(HEADER_DIR)/futex.h $(HEADER_DIR)/atomic.h \
+	logging.h futex_testing_common.h
+
+TARGETS := \
+	futex_wait_timeout \
+	futex_wait_wouldblock \
+	futex_requeue_pi \
+	futex_requeue_pi_signal_restart \
+	futex_requeue_pi_mismatched_ops \
+	futex_wait_uninitialized_heap \
+	futex_wait_private_mapped_file
+
+.PHONY: all clean run_test
+all: $(TARGETS)
+
+$(TARGETS): $(HEADERS) futex_testing_common.o logging.o
+
+futex_testing_common.o: futex_testing_common.c futex_testing_common.h
+	gcc -c futex_testing_common.c
+
+logging.o: logging.c logging.h
+	gcc -c logging.c
+
+run_tests:
+	./run.sh
+
+clean:
+	rm -f $(TARGETS) *.o
tools/testing/selftests/futex/futex_requeue_pi.c new file +376 -0

376 lines not on this page · raw message

tools/testing/selftests/futex/futex_requeue_pi_mismatched_ops.c new file +151 -0

151 lines not on this page · raw message

tools/testing/selftests/futex/futex_requeue_pi_signal_restart.c new file +202 -0

202 lines not on this page · raw message

tools/testing/selftests/futex/futex_testing_common.c new file +45 -0

45 lines not on this page · raw message

tools/testing/selftests/futex/futex_testing_common.h new file +9 -0
new file mode 100644
index 0000000..86c49fb
@@ -0,0 +1,9 @@
+
+#ifndef FUTEX_TESTING_COMMON_H
+#define FUTEX_TESTING_COMMON_H
+
+#include <pthread.h>
+
+int create_rt_thread(pthread_t *pth, void *(*func)(void *), void *arg, int policy, int prio);
+
+#endif	/* FUTEX_TESTING_COMMON_H */
tools/testing/selftests/futex/futex_wait_private_mapped_file.c new file +137 -0

137 lines not on this page · raw message

tools/testing/selftests/futex/futex_wait_timeout.c new file +101 -0

101 lines not on this page · raw message

tools/testing/selftests/futex/futex_wait_uninitialized_heap.c new file +139 -0

139 lines not on this page · raw message

tools/testing/selftests/futex/futex_wait_wouldblock.c new file +94 -0

94 lines not on this page · raw message

tools/testing/selftests/futex/logging.c new file +93 -0

93 lines not on this page · raw message

tools/testing/selftests/futex/logging.h new file +88 -0

88 lines not on this page · raw message

tools/testing/selftests/futex/run.sh new file +92 -0

92 lines not on this page · raw message

Signature · 1 line
1.7.5.1