From: Peter Newman <peternewman@google.com>
To: Fenghua Yu <fenghua.yu@intel.com>,
Reinette Chatre <reinette.chatre@intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H . Peter Anvin" <hpa@zytor.com>,
Tony Luck <tony.luck@intel.com>, Babu Moger <babu.moger@amd.com>,
James Morse <james.morse@arm.com>,
Martin Kletzander <nert.pinx@gmail.com>,
Shaopeng Tan <tan.shaopeng@fujitsu.com>,
linux-kernel@vger.kernel.org, eranian@google.com,
Peter Newman <peternewman@google.com>
Subject: [PATCH 1/2] selftests/resctrl: fastcat for benchmarking counter reads
Date: Thu, 31 Oct 2024 15:25:52 +0100 [thread overview]
Message-ID: <20241031142553.3963058-1-peternewman@google.com> (raw)
This patch is provided for reference and not intended for submission.
This test program is used to evaluate the cost of reading resctrl
counters. It is essentially a drop-in replacement for cat, allowing
presumably small files, like resctrl nodes, to be read repeatedly using
pread(). In contrast, repeated invocations of cat would open and close
the counter files, which is an order of magnitude more costly than the
actual counter file read operations.
For example, the steps below were used to determine the cost of reading
a large number of local or remote counters on a dual-socket AMD Zen2:
Bind to a CPU in L3 domain 6:
# taskset -c 25 bash
Record the setup cost for the groups /sys/fs/resctrl/mon_groups/*:
# cd /sys/fs/resctrl
# FASTCAT_READ_COUNT=0 perf stat -r 1000 /tmp/fastcat mon_groups/*/mon_data/mon_L3_06/mbm_*
Measure local read cost:
# perf stat -r 1000 /tmp/fastcat mon_groups/*/mon_data/mon_L3_06/mbm_*
Measure remote read cost:
# perf stat -r 1000 /tmp/fastcat mon_groups/*/mon_data/mon_L3_07/mbm_*
Signed-off-by: Peter Newman <peternewman@google.com>
---
tools/testing/selftests/resctrl/.gitignore | 1 +
tools/testing/selftests/resctrl/Makefile | 6 ++-
tools/testing/selftests/resctrl/fastcat.c | 63 ++++++++++++++++++++++
3 files changed, 68 insertions(+), 2 deletions(-)
create mode 100644 tools/testing/selftests/resctrl/fastcat.c
diff --git a/tools/testing/selftests/resctrl/.gitignore b/tools/testing/selftests/resctrl/.gitignore
index ab68442b6bc8d..11a40e331f4ad 100644
--- a/tools/testing/selftests/resctrl/.gitignore
+++ b/tools/testing/selftests/resctrl/.gitignore
@@ -1,2 +1,3 @@
# SPDX-License-Identifier: GPL-2.0-only
resctrl_tests
+fastcat
diff --git a/tools/testing/selftests/resctrl/Makefile b/tools/testing/selftests/resctrl/Makefile
index f408bd6bfc3d4..c5ec1e8289390 100644
--- a/tools/testing/selftests/resctrl/Makefile
+++ b/tools/testing/selftests/resctrl/Makefile
@@ -3,10 +3,12 @@
CFLAGS = -g -Wall -O2 -D_FORTIFY_SOURCE=2
CFLAGS += $(KHDR_INCLUDES)
-TEST_GEN_PROGS := resctrl_tests
+TEST_GEN_PROGS := resctrl_tests fastcat
LOCAL_HDRS += $(wildcard *.h)
include ../lib.mk
-$(OUTPUT)/resctrl_tests: $(wildcard *.c)
+$(OUTPUT)/resctrl_tests: cache.c cat_test.c cmt_test.c fill_buf.c mba_test.c mbm_test.c resctrlfs.c resctrl_tests.c resctrl_val.c
+
+$(OUTPUT)/fastcat: fastcat.c
diff --git a/tools/testing/selftests/resctrl/fastcat.c b/tools/testing/selftests/resctrl/fastcat.c
new file mode 100644
index 0000000000000..ac7a56f82a7c2
--- /dev/null
+++ b/tools/testing/selftests/resctrl/fastcat.c
@@ -0,0 +1,63 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+int main(int argc, char **argv)
+{
+ int nfiles = argc - 1;
+ char *nread_str;
+ int nread;
+ int *fds;
+ int i, j;
+
+ nread_str = getenv("FASTCAT_READ_COUNT");
+ if (!nread_str)
+ nread = 1;
+ else
+ nread = atoi(nread_str);
+
+ if (nfiles < 1)
+ exit(1);
+
+ fds = malloc(sizeof(*fds) * (argc));
+ if (!fds) {
+ perror("malloc");
+ exit(1);
+ }
+
+ printf("opening %d files\n", nfiles);
+
+ for (i = 1; i < argc; i++) {
+ fds[i - 1] = open(argv[i], O_RDONLY);
+ if (fds[i - 1] < 0) {
+ perror(argv[i]);
+ exit(1);
+ }
+ }
+
+ printf("reading %d files %d times\n", nfiles, nread);
+
+ for (j = 0; j < nread; j++) {
+ for (i = 0; i < nfiles; i++) {
+ // Assumed to be large enough for any output of
+ // mbm_*_bytes
+ char buf[40];
+ ssize_t r;
+
+ r = pread(fds[i], buf, sizeof(buf), 0);
+ if (r < 0) {
+ perror(argv[i + 1]);
+ exit(1);
+ }
+ }
+ }
+
+ printf("closing %d files\n", nfiles);
+ for (i = 0; i < nfiles; i++)
+ close(fds[i]);
+
+ return 0;
+}
base-commit: 81983758430957d9a5cb3333fe324fd70cf63e7e
--
2.47.0.199.ga7371fff76-goog
next reply other threads:[~2024-10-31 14:26 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-31 14:25 Peter Newman [this message]
2024-10-31 14:25 ` [PATCH 2/2] x86/resctrl: Don't workqueue local event counter reads Peter Newman
2024-11-01 18:35 ` Luck, Tony
2024-11-04 22:36 ` Fenghua Yu
2024-11-04 22:56 ` Luck, Tony
2024-11-04 23:59 ` Fenghua Yu
2024-11-05 0:12 ` Luck, Tony
2024-11-05 3:29 ` Fenghua Yu
2024-11-05 11:25 ` Peter Newman
2024-11-05 23:20 ` Reinette Chatre
2024-11-05 23:39 ` Luck, Tony
2024-11-06 0:13 ` Reinette Chatre
2024-11-06 9:42 ` Peter Newman
2024-11-06 17:12 ` Luck, Tony
2024-11-06 15:52 ` Peter Newman
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=20241031142553.3963058-1-peternewman@google.com \
--to=peternewman@google.com \
--cc=babu.moger@amd.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=eranian@google.com \
--cc=fenghua.yu@intel.com \
--cc=hpa@zytor.com \
--cc=james.morse@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=nert.pinx@gmail.com \
--cc=reinette.chatre@intel.com \
--cc=tan.shaopeng@fujitsu.com \
--cc=tglx@linutronix.de \
--cc=tony.luck@intel.com \
--cc=x86@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.