perf bench futex: Add --mlockall parameter
authorDavidlohr Bueso <dave@stgolabs.net>
Mon, 9 Aug 2021 04:32:58 +0000 (21:32 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 9 Aug 2021 15:00:04 +0000 (12:00 -0300)
This adds, across all futex benchmarks, the -m/--mlockall option
which is a common operation for realtime workloads by not incurring
in page faults in paths that want determinism. As such, threads
started after a call to mlockall(2) will generate page faults
immediately since the new stack is immediately forced to memory,
due to the MCL_FUTURE flag.

Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
Cc: Davidlohr Bueso <dbueso@suse.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lore.kernel.org/lkml/20210809043301.66002-5-dave@stgolabs.net
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/bench/futex-hash.c
tools/perf/bench/futex-lock-pi.c
tools/perf/bench/futex-requeue.c
tools/perf/bench/futex-wake-parallel.c
tools/perf/bench/futex-wake.c
tools/perf/bench/futex.h

index ddca755..fcdea3e 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/kernel.h>
 #include <linux/zalloc.h>
 #include <sys/time.h>
+#include <sys/mman.h>
 #include <perf/cpumap.h>
 
 #include "../util/stat.h"
@@ -56,6 +57,7 @@ static const struct option options[] = {
        OPT_UINTEGER('f', "futexes", &params.nfutexes, "Specify amount of futexes per threads"),
        OPT_BOOLEAN( 's', "silent",  &params.silent, "Silent mode: do not display data/details"),
        OPT_BOOLEAN( 'S', "shared",  &params.fshared, "Use shared futexes instead of private ones"),
+       OPT_BOOLEAN( 'm', "mlockall", &params.mlockall, "Lock all current and future memory"),
        OPT_END()
 };
 
@@ -142,6 +144,11 @@ int bench_futex_hash(int argc, const char **argv)
        act.sa_sigaction = toggle_done;
        sigaction(SIGINT, &act, NULL);
 
+       if (params.mlockall) {
+               if (mlockall(MCL_CURRENT | MCL_FUTURE))
+                       err(EXIT_FAILURE, "mlockall");
+       }
+
        if (!params.nthreads) /* default to the number of CPUs */
                params.nthreads = cpu->nr;
 
index ce980df..5d1fe9c 100644 (file)
@@ -21,6 +21,7 @@
 #include <err.h>
 #include <stdlib.h>
 #include <sys/time.h>
+#include <sys/mman.h>
 
 struct worker {
        int tid;
@@ -48,6 +49,7 @@ static const struct option options[] = {
        OPT_BOOLEAN( 'M', "multi",   &params.multi, "Use multiple futexes"),
        OPT_BOOLEAN( 's', "silent",  &params.silent, "Silent mode: do not display data/details"),
        OPT_BOOLEAN( 'S', "shared",  &params.fshared, "Use shared futexes instead of private ones"),
+       OPT_BOOLEAN( 'm', "mlockall", &params.mlockall, "Lock all current and future memory"),
        OPT_END()
 };
 
@@ -165,6 +167,11 @@ int bench_futex_lock_pi(int argc, const char **argv)
        act.sa_sigaction = toggle_done;
        sigaction(SIGINT, &act, NULL);
 
+       if (params.mlockall) {
+               if (mlockall(MCL_CURRENT | MCL_FUTURE))
+                       err(EXIT_FAILURE, "mlockall");
+       }
+
        if (!params.nthreads)
                params.nthreads = cpu->nr;
 
index 66747bf..73d4a6c 100644 (file)
@@ -27,6 +27,7 @@
 #include <err.h>
 #include <stdlib.h>
 #include <sys/time.h>
+#include <sys/mman.h>
 
 static u_int32_t futex1 = 0, futex2 = 0;
 
@@ -51,6 +52,7 @@ static const struct option options[] = {
        OPT_UINTEGER('q', "nrequeue", &params.nrequeue, "Specify amount of threads to requeue at once"),
        OPT_BOOLEAN( 's', "silent",   &params.silent, "Silent mode: do not display data/details"),
        OPT_BOOLEAN( 'S', "shared",   &params.fshared, "Use shared futexes instead of private ones"),
+       OPT_BOOLEAN( 'm', "mlockall", &params.mlockall, "Lock all current and future memory"),
        OPT_END()
 };
 
@@ -134,6 +136,11 @@ int bench_futex_requeue(int argc, const char **argv)
        act.sa_sigaction = toggle_done;
        sigaction(SIGINT, &act, NULL);
 
+       if (params.mlockall) {
+               if (mlockall(MCL_CURRENT | MCL_FUTURE))
+                       err(EXIT_FAILURE, "mlockall");
+       }
+
        if (!params.nthreads)
                params.nthreads = cpu->nr;
 
index 958372a..e970e6b 100644 (file)
@@ -34,6 +34,7 @@ int bench_futex_wake_parallel(int argc __maybe_unused, const char **argv __maybe
 #include <err.h>
 #include <stdlib.h>
 #include <sys/time.h>
+#include <sys/mman.h>
 
 struct thread_data {
        pthread_t worker;
@@ -62,6 +63,8 @@ static const struct option options[] = {
        OPT_UINTEGER('w', "nwakers", &params.nwakes, "Specify amount of waking threads"),
        OPT_BOOLEAN( 's', "silent",  &params.silent, "Silent mode: do not display data/details"),
        OPT_BOOLEAN( 'S', "shared",  &params.fshared, "Use shared futexes instead of private ones"),
+       OPT_BOOLEAN( 'm', "mlockall", &params.mlockall, "Lock all current and future memory"),
+
        OPT_END()
 };
 
@@ -239,6 +242,11 @@ int bench_futex_wake_parallel(int argc, const char **argv)
        act.sa_sigaction = toggle_done;
        sigaction(SIGINT, &act, NULL);
 
+       if (params.mlockall) {
+               if (mlockall(MCL_CURRENT | MCL_FUTURE))
+                       err(EXIT_FAILURE, "mlockall");
+       }
+
        cpu = perf_cpu_map__new(NULL);
        if (!cpu)
                err(EXIT_FAILURE, "calloc");
index 9ed4d65..77f058a 100644 (file)
@@ -27,6 +27,7 @@
 #include <err.h>
 #include <stdlib.h>
 #include <sys/time.h>
+#include <sys/mman.h>
 
 /* all threads will block on the same futex */
 static u_int32_t futex1 = 0;
@@ -52,6 +53,8 @@ static const struct option options[] = {
        OPT_UINTEGER('w', "nwakes",  &params.nwakes, "Specify amount of threads to wake at once"),
        OPT_BOOLEAN( 's', "silent",  &params.silent, "Silent mode: do not display data/details"),
        OPT_BOOLEAN( 'S', "shared",  &params.fshared, "Use shared futexes instead of private ones"),
+       OPT_BOOLEAN( 'm', "mlockall", &params.mlockall, "Lock all current and future memory"),
+
        OPT_END()
 };
 
@@ -142,6 +145,11 @@ int bench_futex_wake(int argc, const char **argv)
        act.sa_sigaction = toggle_done;
        sigaction(SIGINT, &act, NULL);
 
+       if (params.mlockall) {
+               if (mlockall(MCL_CURRENT | MCL_FUTURE))
+                       err(EXIT_FAILURE, "mlockall");
+       }
+
        if (!params.nthreads)
                params.nthreads = cpu->nr;
 
index 6f8b85b..fca4eee 100644 (file)
@@ -16,6 +16,7 @@
 struct bench_futex_parameters {
        bool silent;
        bool fshared;
+       bool mlockall;
        bool multi; /* lock-pi */
        unsigned int runtime; /* seconds*/
        unsigned int nthreads;