From: SeongJae Park <sj@kernel.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: SeongJae Park <sj@kernel.org>, Shuah Khan <shuah@kernel.org>,
damon@lists.linux.dev, linux-mm@kvack.org,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 3/8] selftests/damon: implement a program for even-numbered memory regions access
Date: Tue, 25 Jun 2024 11:05:33 -0700 [thread overview]
Message-ID: <20240625180538.73134-4-sj@kernel.org> (raw)
In-Reply-To: <20240625180538.73134-1-sj@kernel.org>
To test schemes_tried_regions feature, we need to have a program having
specific number of regions that having different access pattern.
Existing artificial access pattern generator, 'access_memory', cannot be
used for the purpose, since it accesses only one region at a given time.
Extending it could be an option, but since the purpose and the
implementation are pretty simple, implementing another one from the
scratch is better.
Implement such another artificial memory access program that alloctes
user-defined number/size regions and accesses even-numbered regions.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
tools/testing/selftests/damon/Makefile | 2 +-
.../selftests/damon/access_memory_even.c | 42 +++++++++++++++++++
2 files changed, 43 insertions(+), 1 deletion(-)
create mode 100644 tools/testing/selftests/damon/access_memory_even.c
diff --git a/tools/testing/selftests/damon/Makefile b/tools/testing/selftests/damon/Makefile
index 29a22f50e762..7b972b5cf487 100644
--- a/tools/testing/selftests/damon/Makefile
+++ b/tools/testing/selftests/damon/Makefile
@@ -4,7 +4,7 @@
TEST_GEN_FILES += huge_count_read_write
TEST_GEN_FILES += debugfs_target_ids_read_before_terminate_race
TEST_GEN_FILES += debugfs_target_ids_pid_leak
-TEST_GEN_FILES += access_memory
+TEST_GEN_FILES += access_memory access_memory_even
TEST_FILES = _chk_dependency.sh _debugfs_common.sh
diff --git a/tools/testing/selftests/damon/access_memory_even.c b/tools/testing/selftests/damon/access_memory_even.c
new file mode 100644
index 000000000000..3be121487432
--- /dev/null
+++ b/tools/testing/selftests/damon/access_memory_even.c
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Artificial memory access program for testing DAMON.
+ *
+ * Receives number of regions and size of each region from user. Allocate the
+ * regions and repeatedly access even numbered (starting from zero) regions.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+int main(int argc, char *argv[])
+{
+ char **regions;
+ clock_t start_clock;
+ int nr_regions;
+ int sz_region;
+ int access_time_ms;
+ int i;
+
+ if (argc != 3) {
+ printf("Usage: %s <number> <size (bytes)>\n", argv[0]);
+ return -1;
+ }
+
+ nr_regions = atoi(argv[1]);
+ sz_region = atoi(argv[2]);
+
+ regions = malloc(sizeof(*regions) * nr_regions);
+ for (i = 0; i < nr_regions; i++)
+ regions[i] = malloc(sz_region);
+
+ while (1) {
+ for (i = 0; i < nr_regions; i++) {
+ if (i % 2 == 0)
+ memset(regions[i], i, sz_region);
+ }
+ }
+ return 0;
+}
--
2.39.2
next prev parent reply other threads:[~2024-06-25 18:05 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-25 18:05 [PATCH 0/8] selftests/damon: test DAMOS tried regions and {min,max}_nr_regions SeongJae Park
2024-06-25 18:05 ` [PATCH 1/8] selftests/damon/access_memory: use user-defined region size SeongJae Park
2024-06-25 18:05 ` [PATCH 2/8] selftests/damon/_damon_sysfs: support schemes_update_tried_regions SeongJae Park
2024-06-25 18:05 ` SeongJae Park [this message]
2024-06-25 18:05 ` [PATCH 4/8] selftests/damon: implement DAMOS tried regions test SeongJae Park
2024-06-25 18:05 ` [PATCH 5/8] selftests/damon/_damon_sysfs: implement kdamonds stop function SeongJae Park
2024-06-25 18:05 ` [PATCH 6/8] selftests/damon: implement test for min/max_nr_regions SeongJae Park
2024-06-25 18:05 ` [PATCH 7/8] _damon_sysfs: implement commit() for online parameters update SeongJae Park
2024-06-25 18:05 ` [PATCH 8/8] selftests/damon/damon_nr_regions: test online-tuned max_nr_regions SeongJae Park
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=20240625180538.73134-4-sj@kernel.org \
--to=sj@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=damon@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=shuah@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