From: Davidlohr Bueso <dave@stgolabs.net>
To: acme@kernel.org
Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
dave@stgolabs.net, Davidlohr Bueso <dbueso@suse.de>
Subject: [PATCH 2/3] perf/bench-futex: Add --mlockall parameter
Date: Thu, 5 Aug 2021 18:33:28 -0700 [thread overview]
Message-ID: <20210806013329.94627-3-dave@stgolabs.net> (raw)
In-Reply-To: <20210806013329.94627-1-dave@stgolabs.net>
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 are deterministic. 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>
---
tools/perf/bench/futex-hash.c | 9 +++++++++
tools/perf/bench/futex-lock-pi.c | 9 +++++++++
tools/perf/bench/futex-requeue.c | 9 +++++++++
tools/perf/bench/futex-wake-parallel.c | 9 +++++++++
tools/perf/bench/futex-wake.c | 9 +++++++++
5 files changed, 45 insertions(+)
diff --git a/tools/perf/bench/futex-hash.c b/tools/perf/bench/futex-hash.c
index 2d86602f89e2..ba8ceff4e098 100644
--- a/tools/perf/bench/futex-hash.c
+++ b/tools/perf/bench/futex-hash.c
@@ -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"
@@ -51,6 +52,7 @@ struct parameters {
unsigned int runtime;
bool silent;
bool fshared;
+ bool mlockall;
};
static struct parameters params = {
@@ -69,6 +71,8 @@ static const struct option options[] = {
"Silent mode: do not display data/details"),
OPT_BOOLEAN( 'S', "shared", ¶ms.fshared,
"Use shared futexes instead of private ones"),
+ OPT_BOOLEAN( 'm', "mlockall", ¶ms.mlockall,
+ "Lock all current and future memory"),
OPT_END()
};
@@ -155,6 +159,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;
diff --git a/tools/perf/bench/futex-lock-pi.c b/tools/perf/bench/futex-lock-pi.c
index 9fc994beb933..ab387e73839e 100644
--- a/tools/perf/bench/futex-lock-pi.c
+++ b/tools/perf/bench/futex-lock-pi.c
@@ -21,6 +21,7 @@
#include <err.h>
#include <stdlib.h>
#include <sys/time.h>
+#include <sys/mman.h>
struct worker {
int tid;
@@ -44,6 +45,7 @@ struct parameters {
bool multi;
bool silent;
bool fshared;
+ bool mlockall;
};
static struct parameters params = {
@@ -61,6 +63,8 @@ static const struct option options[] = {
"Params.Silent mode: do not display data/details"),
OPT_BOOLEAN( 'S', "shared", ¶ms.fshared,
"Use shared futexes instead of private ones"),
+ OPT_BOOLEAN( 'm', "mlockall", ¶ms.mlockall,
+ "Lock all current and future memory"),
OPT_END()
};
@@ -178,6 +182,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;
diff --git a/tools/perf/bench/futex-requeue.c b/tools/perf/bench/futex-requeue.c
index b65761e98245..51f2c0d5e6f8 100644
--- a/tools/perf/bench/futex-requeue.c
+++ b/tools/perf/bench/futex-requeue.c
@@ -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;
@@ -43,6 +44,7 @@ struct parameters {
unsigned int nrequeue;
bool silent;
bool fshared;
+ bool mlockall;
};
static struct parameters params = {
@@ -62,6 +64,8 @@ static const struct option options[] = {
"Silent mode: do not display data/details"),
OPT_BOOLEAN( 'S', "shared", ¶ms.fshared,
"Use shared futexes instead of private ones"),
+ OPT_BOOLEAN( 'm', "mlockall", ¶ms.mlockall,
+ "Lock all current and future memory"),
OPT_END()
};
@@ -145,6 +149,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;
diff --git a/tools/perf/bench/futex-wake-parallel.c b/tools/perf/bench/futex-wake-parallel.c
index a80dfff5fe37..d6d71374f535 100644
--- a/tools/perf/bench/futex-wake-parallel.c
+++ b/tools/perf/bench/futex-wake-parallel.c
@@ -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;
@@ -60,6 +61,7 @@ struct parameters {
unsigned int nblocked_threads;
bool silent;
bool fshared;
+ bool mlockall;
};
static struct parameters params;
@@ -73,6 +75,8 @@ static const struct option options[] = {
"Silent mode: do not display data/details"),
OPT_BOOLEAN( 'S', "shared", ¶ms.fshared,
"Use shared futexes instead of private ones"),
+ OPT_BOOLEAN( 'm', "mlockall", ¶ms.mlockall,
+ "Lock all current and future memory"),
OPT_END()
};
@@ -250,6 +254,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");
diff --git a/tools/perf/bench/futex-wake.c b/tools/perf/bench/futex-wake.c
index 22763774ede7..66f1338d66bc 100644
--- a/tools/perf/bench/futex-wake.c
+++ b/tools/perf/bench/futex-wake.c
@@ -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;
@@ -44,6 +45,7 @@ struct parameters {
unsigned int nwakes;
bool silent;
bool fshared;
+ bool mlockall;
};
static struct parameters params = {
@@ -63,6 +65,8 @@ static const struct option options[] = {
"Silent mode: do not display data/details"),
OPT_BOOLEAN( 'S', "shared", ¶ms.fshared,
"Use shared futexes instead of private ones"),
+ OPT_BOOLEAN( 'm', "mlockall", ¶ms.mlockall,
+ "Lock all current and future memory"),
OPT_END()
};
@@ -153,6 +157,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;
--
2.26.2
next prev parent reply other threads:[~2021-08-06 1:33 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-06 1:33 [PATCH -tip 0/3] perf/bench-futex: Misc updates Davidlohr Bueso
2021-08-06 1:33 ` [PATCH 1/3] perf/bench-futex: Group test parameters cleanup Davidlohr Bueso
2021-08-06 18:30 ` Arnaldo Carvalho de Melo
2021-08-06 1:33 ` Davidlohr Bueso [this message]
2021-08-06 1:33 ` [PATCH 3/3] perf/bench-futex, requeue: Add --pi parameter Davidlohr Bueso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210806013329.94627-3-dave@stgolabs.net \
--to=dave@stgolabs.net \
--cc=acme@kernel.org \
--cc=dbueso@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).