Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1395364

[patch V2 6/7] perf/bench/futex-hash: Support preallocate hash table

From Thomas Gleixner <tglx@linutronix.de>
Newsgroups linux.kernel
Subject [patch V2 6/7] perf/bench/futex-hash: Support preallocate hash table
Date 2016-05-05 22:50 +0200
Message-ID <rvynF-79b-25@gated-at.bofh.it> (permalink)
References <rvynE-79b-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Instead of using the default hash size on the first allocation it is
possible to allocate a specific number of slots upfront.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 tools/perf/bench/futex-hash.c |   16 ++++++++++++++--
 tools/perf/bench/futex.h      |    5 +++++
 2 files changed, 19 insertions(+), 2 deletions(-)

--- a/tools/perf/bench/futex-hash.c
+++ b/tools/perf/bench/futex-hash.c
@@ -30,6 +30,7 @@ static unsigned int nsecs    = 10;
 static unsigned int nfutexes = 1024;
 static bool fshared = false, done = false, silent = false;
 static int futex_flag = 0;
+static unsigned int prealloc;
 static int numa_node = -1;
 
 struct timeval start, end, runtime;
@@ -51,6 +52,7 @@ static const struct option options[] = {
 	OPT_UINTEGER('f', "futexes", &nfutexes, "Specify amount of futexes per threads"),
 	OPT_BOOLEAN( 's', "silent",  &silent,   "Silent mode: do not display data/details"),
 	OPT_BOOLEAN( 'S', "shared",  &fshared,  "Use shared futexes instead of private ones"),
+	OPT_UINTEGER('p', "prealloc",&prealloc, "Specify number of preallocated hash slots"),
 #ifdef CONFIG_NUMA
 	OPT_INTEGER( 'n', "numa",   &numa_node,  "Specify the NUMA node"),
 #endif
@@ -138,6 +140,7 @@ int bench_futex_hash(int argc, const cha
 	unsigned int i, ncpus;
 	pthread_attr_t thread_attr;
 	struct worker *worker = NULL;
+	char *prealloc_str = NULL;
 	char *node_str = NULL;
 	unsigned int cpunum;
 
@@ -192,11 +195,20 @@ int bench_futex_hash(int argc, const cha
 	if (!fshared)
 		futex_flag = FUTEX_PRIVATE_FLAG;
 
-	printf("Run summary [PID %d]: %d threads%s, each operating on %d [%s] futexes for %d secs.\n\n",
+	if (prealloc) {
+		ret = futex_preallocate(prealloc);
+		if (ret < 0)
+			err(EXIT_FAILURE, "futex_prealloate");
+		ret = asprintf(&prealloc_str, " P %u %d", prealloc, ret);
+		if (ret < 0)
+			err(EXIT_FAILURE, "futex_preallocate, asprintf");
+	}
+
+	printf("Run summary [PID %d]: %d threads%s, each operating on %d [%s%s] futexes for %d secs.\n\n",
 	       getpid(), nthreads,
 	       node_str ? : "",
 	       nfutexes, fshared ? "shared":"private",
-	       nsecs);
+	       prealloc_str ? : "", nsecs);
 
 	init_stats(&throughput_stats);
 	pthread_mutex_init(&thread_lock, NULL);
--- a/tools/perf/bench/futex.h
+++ b/tools/perf/bench/futex.h
@@ -101,4 +101,9 @@ static inline int pthread_attr_setaffini
 }
 #endif
 
+static inline int futex_preallocate(u_int32_t hash_size)
+{
+	return futex(0, FUTEX_PREALLOC_HASH, hash_size, NULL, NULL, 0, 0);
+}
+
 #endif /* _FUTEX_H */

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[patch V2 0/7] futex: Add support for process private hashing Thomas Gleixner <tglx@linutronix.de> - 2016-05-05 22:50 +0200
  [patch V2 4/7] futex: Add sysctl knobs for process private hash Thomas Gleixner <tglx@linutronix.de> - 2016-05-05 22:50 +0200
    Re: [patch V2 4/7] futex: Add sysctl knobs for process private hash Darren Hart <dvhart@infradead.org> - 2016-05-06 20:30 +0200
  [patch V2 5/7] perf/bench/futex-hash: Support NUMA Thomas Gleixner <tglx@linutronix.de> - 2016-05-05 22:50 +0200
  [patch V2 2/7] futex: Hash private futexes per process Thomas Gleixner <tglx@linutronix.de> - 2016-05-05 22:50 +0200
    Re: [patch V2 2/7] futex: Hash private futexes per process Darren Hart <dvhart@infradead.org> - 2016-05-06 20:10 +0200
      Re: [patch V2 2/7] futex: Hash private futexes per process Darren Hart <dvhart@infradead.org> - 2016-05-07 00:00 +0200
        Re: [patch V2 2/7] futex: Hash private futexes per process Thomas Gleixner <tglx@linutronix.de> - 2016-05-07 10:50 +0200
          Re: [patch V2 2/7] futex: Hash private futexes per process Darren Hart <dvhart@infradead.org> - 2016-05-11 23:10 +0200
      Re: [patch V2 2/7] futex: Hash private futexes per process Thomas Gleixner <tglx@linutronix.de> - 2016-05-07 10:50 +0200
        Re: [patch V2 2/7] futex: Hash private futexes per process Darren Hart <dvhart@infradead.org> - 2016-05-11 23:10 +0200
  [patch V2 6/7] perf/bench/futex-hash: Support preallocate hash table Thomas Gleixner <tglx@linutronix.de> - 2016-05-05 22:50 +0200
  [patch V2 1/7] futex: Add some more function commentry Thomas Gleixner <tglx@linutronix.de> - 2016-05-05 22:50 +0200
    Re: [patch V2 1/7] futex: Add some more function commentry Darren Hart <dvhart@infradead.org> - 2016-05-06 19:40 +0200
  [patch V2 7/7] futex.2: Document hash preallocation opcode Thomas Gleixner <tglx@linutronix.de> - 2016-05-05 22:50 +0200

csiph-web