aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Gleixner <tglx@linutronix.de>2016-05-05 20:44:07 +0000
committerSebastian Andrzej Siewior <bigeasy@linutronix.de>2016-10-06 17:29:33 +0200
commit83afd52526d1bc9725d8a8fed8807e165a136355 (patch)
tree31efc960106e23d4022c232b1019f8a09ccbfdea
parentf27b22b247bcfb51beef2556ff28e6afa411fc94 (diff)
downloadlinux-futex-futex_v10_per_task_hash.tar.gz
perf/bench/futex-hash: Support preallocate hash tablefutex_v10_per_task_hash
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>
-rw-r--r--tools/perf/bench/futex-hash.c16
-rw-r--r--tools/perf/bench/futex.h7
2 files changed, 21 insertions, 2 deletions
diff --git a/tools/perf/bench/futex-hash.c b/tools/perf/bench/futex-hash.c
index e075d6f5a4c602..0625f2e79cad06 100644
--- a/tools/perf/bench/futex-hash.c
+++ b/tools/perf/bench/futex-hash.c
@@ -35,6 +35,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;
@@ -56,6 +57,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
@@ -143,6 +145,7 @@ int bench_futex_hash(int argc, const char **argv,
unsigned int i, ncpus;
pthread_attr_t thread_attr;
struct worker *worker = NULL;
+ char *prealloc_str = NULL;
char *node_str = NULL;
unsigned int cpunum;
@@ -197,11 +200,20 @@ int bench_futex_hash(int argc, const char **argv,
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);
diff --git a/tools/perf/bench/futex.h b/tools/perf/bench/futex.h
index b2e06d1190d076..dc02397875bccb 100644
--- a/tools/perf/bench/futex.h
+++ b/tools/perf/bench/futex.h
@@ -99,4 +99,11 @@ static inline int pthread_attr_setaffinity_np(pthread_attr_t *attr,
}
#endif
+#define FUTEX_PREALLOC_HASH 13
+
+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 */