Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests/damon/access_memory: add repeat mode

'access_memory' is an artificial memory access generator program that is
used for a few DAMON selftests. It accesses a given number of regions one
by one only once, and exits. Depending on systems, the test workload may
exit faster than expected, making the tests unreliable. For reliable
control of the artificial memory access pattern, add a mode to make it
repeat running.

Link: https://lkml.kernel.org/r/20260117020731.226785-4-sj@kernel.org
Signed-off-by: SeongJae Park <sj@kernel.org>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

SeongJae Park and committed by
Andrew Morton
514d1bcb 891d206e

+21 -8
+21 -8
tools/testing/selftests/damon/access_memory.c
··· 8 8 #include <string.h> 9 9 #include <time.h> 10 10 11 + enum access_mode { 12 + ACCESS_MODE_ONCE, 13 + ACCESS_MODE_REPEAT, 14 + }; 15 + 11 16 int main(int argc, char *argv[]) 12 17 { 13 18 char **regions; ··· 20 15 int nr_regions; 21 16 int sz_region; 22 17 int access_time_ms; 18 + enum access_mode mode = ACCESS_MODE_ONCE; 19 + 23 20 int i; 24 21 25 - if (argc != 4) { 26 - printf("Usage: %s <number> <size (bytes)> <time (ms)>\n", 22 + if (argc < 4) { 23 + printf("Usage: %s <number> <size (bytes)> <time (ms)> [mode]\n", 27 24 argv[0]); 28 25 return -1; 29 26 } ··· 34 27 sz_region = atoi(argv[2]); 35 28 access_time_ms = atoi(argv[3]); 36 29 30 + if (argc > 4 && !strcmp(argv[4], "repeat")) 31 + mode = ACCESS_MODE_REPEAT; 32 + 37 33 regions = malloc(sizeof(*regions) * nr_regions); 38 34 for (i = 0; i < nr_regions; i++) 39 35 regions[i] = malloc(sz_region); 40 36 41 - for (i = 0; i < nr_regions; i++) { 42 - start_clock = clock(); 43 - while ((clock() - start_clock) * 1000 / CLOCKS_PER_SEC < 44 - access_time_ms) 45 - memset(regions[i], i, sz_region); 46 - } 37 + do { 38 + for (i = 0; i < nr_regions; i++) { 39 + start_clock = clock(); 40 + while ((clock() - start_clock) * 1000 / CLOCKS_PER_SEC 41 + < access_time_ms) 42 + memset(regions[i], i, sz_region); 43 + } 44 + } while (mode == ACCESS_MODE_REPEAT); 45 + 47 46 return 0; 48 47 }