* [LTP] [PATCH v3 1/5] Add cachestat fallback definitions
2024-07-22 14:28 [LTP] [PATCH v3 0/5] cachestat testing suite Andrea Cervesato
@ 2024-07-22 14:28 ` Andrea Cervesato
2024-07-22 14:28 ` [LTP] [PATCH v3 2/5] Add cachestat01 test Andrea Cervesato
` (3 subsequent siblings)
4 siblings, 0 replies; 10+ messages in thread
From: Andrea Cervesato @ 2024-07-22 14:28 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
configure.ac | 4 ++++
include/lapi/mman.h | 44 ++++++++++++++++++++++++++++++++++++++
include/lapi/syscalls/aarch64.in | 1 +
include/lapi/syscalls/arc.in | 1 +
include/lapi/syscalls/arm.in | 1 +
include/lapi/syscalls/hppa.in | 1 +
include/lapi/syscalls/i386.in | 1 +
include/lapi/syscalls/ia64.in | 1 +
include/lapi/syscalls/loongarch.in | 1 +
include/lapi/syscalls/mips_n32.in | 1 +
include/lapi/syscalls/mips_n64.in | 1 +
include/lapi/syscalls/mips_o32.in | 1 +
include/lapi/syscalls/powerpc.in | 1 +
include/lapi/syscalls/powerpc64.in | 1 +
include/lapi/syscalls/s390.in | 1 +
include/lapi/syscalls/s390x.in | 1 +
include/lapi/syscalls/sh.in | 1 +
include/lapi/syscalls/sparc.in | 1 +
include/lapi/syscalls/sparc64.in | 1 +
include/lapi/syscalls/x86_64.in | 1 +
20 files changed, 66 insertions(+)
diff --git a/configure.ac b/configure.ac
index 1f8796c87..cbcf308e5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -91,6 +91,7 @@ AC_SUBST(HAVE_FTS_H, $have_fts)
AC_CHECK_HEADERS(linux/vm_sockets.h, [], [], [#include <sys/socket.h>])
AC_CHECK_FUNCS_ONCE([ \
+ cachestat \
clone3 \
close_range \
copy_file_range \
@@ -243,6 +244,9 @@ AC_CHECK_TYPES([struct mount_attr],,,[
#endif
])
+AC_CHECK_TYPES([struct cachestat_range],,,[#include <sys/mman.h>])
+AC_CHECK_TYPES([struct cachestat],,,[#include <sys/mman.h>])
+
# Tools knobs
# Bash
diff --git a/include/lapi/mman.h b/include/lapi/mman.h
new file mode 100644
index 000000000..244ad9f31
--- /dev/null
+++ b/include/lapi/mman.h
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+#ifndef LAPI_MMAN_H__
+#define LAPI_MMAN_H__
+
+#include <stdint.h>
+#include <sys/mman.h>
+#include "config.h"
+#include "syscalls.h"
+
+#ifndef HAVE_STRUCT_CACHESTAT_RANGE
+struct cachestat_range {
+ uint64_t off;
+ uint64_t len;
+};
+#endif
+
+#ifndef HAVE_STRUCT_CACHESTAT
+struct cachestat {
+ uint64_t nr_cache;
+ uint64_t nr_dirty;
+ uint64_t nr_writeback;
+ uint64_t nr_evicted;
+ uint64_t nr_recently_evicted;
+};
+#endif
+
+#ifndef HAVE_CACHESTAT
+/*
+ * cachestat: wrapper function of cachestat
+ *
+ * Returns: It returns status of cachestat syscall
+ */
+static inline int cachestat(int fd, struct cachestat_range *cstat_range,
+ struct cachestat *cstat, unsigned int flags)
+{
+ return tst_syscall(__NR_cachestat, fd, cstat_range, cstat, flags);
+}
+#endif
+
+#endif /* LAPI_MMAN_H__ */
diff --git a/include/lapi/syscalls/aarch64.in b/include/lapi/syscalls/aarch64.in
index 3e7797718..ef0aa04a3 100644
--- a/include/lapi/syscalls/aarch64.in
+++ b/include/lapi/syscalls/aarch64.in
@@ -300,4 +300,5 @@ landlock_create_ruleset 444
landlock_add_rule 445
landlock_restrict_self 446
futex_waitv 449
+cachestat 451
_sysctl 1078
diff --git a/include/lapi/syscalls/arc.in b/include/lapi/syscalls/arc.in
index 7fde1d263..3eaa6a8f1 100644
--- a/include/lapi/syscalls/arc.in
+++ b/include/lapi/syscalls/arc.in
@@ -320,3 +320,4 @@ landlock_create_ruleset 444
landlock_add_rule 445
landlock_restrict_self 446
futex_waitv 449
+cachestat 451
diff --git a/include/lapi/syscalls/arm.in b/include/lapi/syscalls/arm.in
index 8e76ad164..b52a32b6b 100644
--- a/include/lapi/syscalls/arm.in
+++ b/include/lapi/syscalls/arm.in
@@ -399,3 +399,4 @@ landlock_add_rule (__NR_SYSCALL_BASE+445)
landlock_restrict_self (__NR_SYSCALL_BASE+446)
memfd_secret (__NR_SYSCALL_BASE+447)
futex_waitv (__NR_SYSCALL_BASE+449)
+cachestat (__NR_SYSCALL_BASE+451)
diff --git a/include/lapi/syscalls/hppa.in b/include/lapi/syscalls/hppa.in
index 60c02aff2..4919ee65d 100644
--- a/include/lapi/syscalls/hppa.in
+++ b/include/lapi/syscalls/hppa.in
@@ -47,3 +47,4 @@ landlock_create_ruleset 444
landlock_add_rule 445
landlock_restrict_self 446
futex_waitv 449
+cachestat 451
diff --git a/include/lapi/syscalls/i386.in b/include/lapi/syscalls/i386.in
index 31ec1ecb2..cff40957a 100644
--- a/include/lapi/syscalls/i386.in
+++ b/include/lapi/syscalls/i386.in
@@ -434,3 +434,4 @@ landlock_create_ruleset 444
landlock_add_rule 445
landlock_restrict_self 446
futex_waitv 449
+cachestat 451
diff --git a/include/lapi/syscalls/ia64.in b/include/lapi/syscalls/ia64.in
index 2e56da7f9..11d4b46f4 100644
--- a/include/lapi/syscalls/ia64.in
+++ b/include/lapi/syscalls/ia64.in
@@ -347,3 +347,4 @@ landlock_create_ruleset 1468
landlock_add_rule 1469
landlock_restrict_self 1470
futex_waitv 1473
+cachestat 1475
diff --git a/include/lapi/syscalls/loongarch.in b/include/lapi/syscalls/loongarch.in
index 301f611f6..9bf6a7deb 100644
--- a/include/lapi/syscalls/loongarch.in
+++ b/include/lapi/syscalls/loongarch.in
@@ -305,3 +305,4 @@ memfd_secret 447
process_mrelease 448
futex_waitv 449
set_mempolicy_home_node 450
+cachestat 451
diff --git a/include/lapi/syscalls/mips_n32.in b/include/lapi/syscalls/mips_n32.in
index 5f0fe65eb..a76c82593 100644
--- a/include/lapi/syscalls/mips_n32.in
+++ b/include/lapi/syscalls/mips_n32.in
@@ -374,3 +374,4 @@ landlock_create_ruleset 6444
landlock_add_rule 6445
landlock_restrict_self 6446
futex_waitv 6449
+cachestat 6451
diff --git a/include/lapi/syscalls/mips_n64.in b/include/lapi/syscalls/mips_n64.in
index f81c60e66..df991efd5 100644
--- a/include/lapi/syscalls/mips_n64.in
+++ b/include/lapi/syscalls/mips_n64.in
@@ -350,3 +350,4 @@ landlock_create_ruleset 5444
landlock_add_rule 5445
landlock_restrict_self 5446
futex_waitv 5449
+cachestat 5451
diff --git a/include/lapi/syscalls/mips_o32.in b/include/lapi/syscalls/mips_o32.in
index c2beffb75..826b7d66e 100644
--- a/include/lapi/syscalls/mips_o32.in
+++ b/include/lapi/syscalls/mips_o32.in
@@ -420,3 +420,4 @@ landlock_create_ruleset 4444
landlock_add_rule 4445
landlock_restrict_self 4446
futex_waitv 4449
+cachestat 4451
diff --git a/include/lapi/syscalls/powerpc.in b/include/lapi/syscalls/powerpc.in
index 5460e4197..798ed9050 100644
--- a/include/lapi/syscalls/powerpc.in
+++ b/include/lapi/syscalls/powerpc.in
@@ -427,3 +427,4 @@ landlock_create_ruleset 444
landlock_add_rule 445
landlock_restrict_self 446
futex_waitv 449
+cachestat 451
diff --git a/include/lapi/syscalls/powerpc64.in b/include/lapi/syscalls/powerpc64.in
index 5460e4197..798ed9050 100644
--- a/include/lapi/syscalls/powerpc64.in
+++ b/include/lapi/syscalls/powerpc64.in
@@ -427,3 +427,4 @@ landlock_create_ruleset 444
landlock_add_rule 445
landlock_restrict_self 446
futex_waitv 449
+cachestat 451
diff --git a/include/lapi/syscalls/s390.in b/include/lapi/syscalls/s390.in
index 275b27f47..126938095 100644
--- a/include/lapi/syscalls/s390.in
+++ b/include/lapi/syscalls/s390.in
@@ -414,3 +414,4 @@ landlock_create_ruleset 444
landlock_add_rule 445
landlock_restrict_self 446
futex_waitv 449
+cachestat 451
diff --git a/include/lapi/syscalls/s390x.in b/include/lapi/syscalls/s390x.in
index c200d02b2..18f2496a0 100644
--- a/include/lapi/syscalls/s390x.in
+++ b/include/lapi/syscalls/s390x.in
@@ -362,3 +362,4 @@ landlock_create_ruleset 444
landlock_add_rule 445
landlock_restrict_self 446
futex_waitv 449
+cachestat 451
diff --git a/include/lapi/syscalls/sh.in b/include/lapi/syscalls/sh.in
index 6f482a77b..ae6f26050 100644
--- a/include/lapi/syscalls/sh.in
+++ b/include/lapi/syscalls/sh.in
@@ -408,3 +408,4 @@ landlock_create_ruleset 444
landlock_add_rule 445
landlock_restrict_self 446
futex_waitv 449
+cachestat 451
diff --git a/include/lapi/syscalls/sparc.in b/include/lapi/syscalls/sparc.in
index 7181e80a0..409fa2729 100644
--- a/include/lapi/syscalls/sparc.in
+++ b/include/lapi/syscalls/sparc.in
@@ -413,3 +413,4 @@ landlock_create_ruleset 444
landlock_add_rule 445
landlock_restrict_self 446
futex_waitv 449
+cachestat 451
diff --git a/include/lapi/syscalls/sparc64.in b/include/lapi/syscalls/sparc64.in
index c96ab2021..e13cf163e 100644
--- a/include/lapi/syscalls/sparc64.in
+++ b/include/lapi/syscalls/sparc64.in
@@ -378,3 +378,4 @@ landlock_create_ruleset 444
landlock_add_rule 445
landlock_restrict_self 446
futex_waitv 449
+cachestat 451
diff --git a/include/lapi/syscalls/x86_64.in b/include/lapi/syscalls/x86_64.in
index 3082ca110..05b1bee55 100644
--- a/include/lapi/syscalls/x86_64.in
+++ b/include/lapi/syscalls/x86_64.in
@@ -355,6 +355,7 @@ landlock_create_ruleset 444
landlock_add_rule 445
landlock_restrict_self 446
futex_waitv 449
+cachestat 451
rt_sigaction 512
rt_sigreturn 513
ioctl 514
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 10+ messages in thread* [LTP] [PATCH v3 2/5] Add cachestat01 test
2024-07-22 14:28 [LTP] [PATCH v3 0/5] cachestat testing suite Andrea Cervesato
2024-07-22 14:28 ` [LTP] [PATCH v3 1/5] Add cachestat fallback definitions Andrea Cervesato
@ 2024-07-22 14:28 ` Andrea Cervesato
2024-07-23 10:40 ` Cyril Hrubis
2024-07-22 14:28 ` [LTP] [PATCH v3 3/5] Add cachestat02 test Andrea Cervesato
` (2 subsequent siblings)
4 siblings, 1 reply; 10+ messages in thread
From: Andrea Cervesato @ 2024-07-22 14:28 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
This test verifies that cachestat() syscall is properly counting
cached pages written inside a file. If storage device synchronization
is requested, test will check if the number of dirty pages is zero.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/syscalls | 2 +
testcases/kernel/syscalls/cachestat/.gitignore | 1 +
testcases/kernel/syscalls/cachestat/Makefile | 10 ++
testcases/kernel/syscalls/cachestat/cachestat.h | 27 ++++++
testcases/kernel/syscalls/cachestat/cachestat01.c | 106 ++++++++++++++++++++++
5 files changed, 146 insertions(+)
diff --git a/runtest/syscalls b/runtest/syscalls
index 27eb9a86b..ce974b317 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -62,6 +62,8 @@ capset04 capset04
cacheflush01 cacheflush01
+cachestat01 cachestat01
+
chdir01 chdir01
chdir01A symlink01 -T chdir01
chdir04 chdir04
diff --git a/testcases/kernel/syscalls/cachestat/.gitignore b/testcases/kernel/syscalls/cachestat/.gitignore
new file mode 100644
index 000000000..daea1f4be
--- /dev/null
+++ b/testcases/kernel/syscalls/cachestat/.gitignore
@@ -0,0 +1 @@
+cachestat01
diff --git a/testcases/kernel/syscalls/cachestat/Makefile b/testcases/kernel/syscalls/cachestat/Makefile
new file mode 100644
index 000000000..62b00d2f4
--- /dev/null
+++ b/testcases/kernel/syscalls/cachestat/Makefile
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+
+top_srcdir ?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+LDLIBS += -lrt
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/cachestat/cachestat.h b/testcases/kernel/syscalls/cachestat/cachestat.h
new file mode 100644
index 000000000..efce6dc7f
--- /dev/null
+++ b/testcases/kernel/syscalls/cachestat/cachestat.h
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+#ifndef CACHESTAT_H__
+#define CACHESTAT_H__
+
+#include "tst_test.h"
+#include "lapi/mman.h"
+
+static inline void print_cachestat(struct cachestat *cs)
+{
+ tst_res(TDEBUG,
+ "nr_cache=%lu "
+ "nr_dirty=%lu "
+ "nr_writeback=%lu "
+ "nr_evicted=%lu "
+ "nr_recently_evicted=%lu",
+ cs->nr_cache,
+ cs->nr_dirty,
+ cs->nr_writeback,
+ cs->nr_evicted,
+ cs->nr_recently_evicted);
+}
+
+#endif
diff --git a/testcases/kernel/syscalls/cachestat/cachestat01.c b/testcases/kernel/syscalls/cachestat/cachestat01.c
new file mode 100644
index 000000000..7b0700f2c
--- /dev/null
+++ b/testcases/kernel/syscalls/cachestat/cachestat01.c
@@ -0,0 +1,106 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * This test verifies that cachestat() syscall is properly counting cached pages
+ * written inside a file. If storage device synchronization is requested, test
+ * will check if the number of dirty pages is zero.
+ *
+ * [Algorithm]
+ *
+ * - create a file with specific amount of pages
+ * - synchronize storage device, if needed
+ * - monitor file with cachestat()
+ * - check if the right amount of pages have been moved into cache
+ * - if storage device synchronization is requested, check that dirty pages is
+ * zero
+ */
+
+#include <stdlib.h>
+#include "cachestat.h"
+
+#define MNTPOINT "mntpoint"
+#define FILENAME MNTPOINT "/myfile.bin"
+
+static int page_size;
+static char *page_data;
+static struct cachestat *cs;
+static struct cachestat_range *cs_range;
+
+static void test_cached_pages(const unsigned int use_sync, const int num_pages)
+{
+ int fd;
+
+ tst_res(TINFO, "%s file synchronization", use_sync ? "Enable" : "Disable");
+ tst_res(TINFO, "Number of pages: %d", num_pages);
+
+ memset(cs, 0, sizeof(struct cachestat));
+
+ fd = SAFE_OPEN(FILENAME, O_RDWR | O_CREAT, 0600);
+
+ for (int i = 0; i < num_pages; i++)
+ SAFE_WRITE(0, fd, page_data, page_size);
+
+ if (use_sync)
+ fsync(fd);
+
+ cs_range->off = 0;
+ cs_range->len = page_size * num_pages;
+
+ TST_EXP_PASS(cachestat(fd, cs_range, cs, 0));
+ print_cachestat(cs);
+
+ TST_EXP_EQ_LI(cs->nr_cache + cs->nr_evicted, num_pages);
+
+ if (use_sync)
+ TST_EXP_EQ_LI(cs->nr_dirty, 0);
+
+ SAFE_CLOSE(fd);
+ SAFE_UNLINK(FILENAME);
+}
+
+static void run(unsigned int use_sync)
+{
+ for (int i = 0; i < 15; i++)
+ test_cached_pages(use_sync, 1 << i);
+}
+
+static void setup(void)
+{
+ page_size = (int)sysconf(_SC_PAGESIZE);
+
+ page_data = SAFE_MALLOC(page_size);
+ memset(page_data, 'a', page_size);
+}
+
+static void cleanup(void)
+{
+ if (page_data)
+ free(page_data);
+}
+
+static struct tst_test test = {
+ .test = run,
+ .tcnt = 2,
+ .setup = setup,
+ .cleanup = cleanup,
+ .needs_tmpdir = 1,
+ .min_kver = "6.5",
+ .mount_device = 1,
+ .mntpoint = MNTPOINT,
+ .all_filesystems = 1,
+ .skip_filesystems = (const char *const []) {
+ "fuse",
+ "tmpfs",
+ NULL
+ },
+ .bufs = (struct tst_buffers []) {
+ {&cs, .size = sizeof(struct cachestat)},
+ {&cs_range, .size = sizeof(struct cachestat_range)},
+ {}
+ },
+};
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [LTP] [PATCH v3 2/5] Add cachestat01 test
2024-07-22 14:28 ` [LTP] [PATCH v3 2/5] Add cachestat01 test Andrea Cervesato
@ 2024-07-23 10:40 ` Cyril Hrubis
0 siblings, 0 replies; 10+ messages in thread
From: Cyril Hrubis @ 2024-07-23 10:40 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi!
Pushed with a two minor changes, thanks.
> +static void test_cached_pages(const unsigned int use_sync, const int num_pages)
> +{
> + int fd;
> +
> + tst_res(TINFO, "%s file synchronization", use_sync ? "Enable" : "Disable");
> + tst_res(TINFO, "Number of pages: %d", num_pages);
> +
> + memset(cs, 0, sizeof(struct cachestat));
> +
> + fd = SAFE_OPEN(FILENAME, O_RDWR | O_CREAT, 0600);
> +
> + for (int i = 0; i < num_pages; i++)
> + SAFE_WRITE(0, fd, page_data, page_size);
> +
> + if (use_sync)
> + fsync(fd);
> +
> + cs_range->off = 0;
> + cs_range->len = page_size * num_pages;
> +
I've added memset(cs, 0xff, sizeof(*cs)) here to make sure that the
structure is initialized with bogus data before the syscall. With that
we will make sure that the nr_dirty have been written to (the tst_bufers
are initialized to zero to begin with).
> + TST_EXP_PASS(cachestat(fd, cs_range, cs, 0));
> + print_cachestat(cs);
> +
> + TST_EXP_EQ_LI(cs->nr_cache + cs->nr_evicted, num_pages);
> +
> + if (use_sync)
> + TST_EXP_EQ_LI(cs->nr_dirty, 0);
> +
> + SAFE_CLOSE(fd);
> + SAFE_UNLINK(FILENAME);
> +}
> +
> +static void run(unsigned int use_sync)
> +{
> + for (int i = 0; i < 15; i++)
> + test_cached_pages(use_sync, 1 << i);
> +}
> +
> +static void setup(void)
> +{
> + page_size = (int)sysconf(_SC_PAGESIZE);
> +
> + page_data = SAFE_MALLOC(page_size);
> + memset(page_data, 'a', page_size);
> +}
> +
> +static void cleanup(void)
> +{
> + if (page_data)
> + free(page_data);
free(NULL) is no-op so I've removed the if ().
> +}
> +
> +static struct tst_test test = {
> + .test = run,
> + .tcnt = 2,
> + .setup = setup,
> + .cleanup = cleanup,
> + .needs_tmpdir = 1,
> + .min_kver = "6.5",
> + .mount_device = 1,
> + .mntpoint = MNTPOINT,
> + .all_filesystems = 1,
> + .skip_filesystems = (const char *const []) {
> + "fuse",
> + "tmpfs",
> + NULL
> + },
> + .bufs = (struct tst_buffers []) {
> + {&cs, .size = sizeof(struct cachestat)},
> + {&cs_range, .size = sizeof(struct cachestat_range)},
> + {}
> + },
> +};
>
> --
> 2.43.0
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 10+ messages in thread
* [LTP] [PATCH v3 3/5] Add cachestat02 test
2024-07-22 14:28 [LTP] [PATCH v3 0/5] cachestat testing suite Andrea Cervesato
2024-07-22 14:28 ` [LTP] [PATCH v3 1/5] Add cachestat fallback definitions Andrea Cervesato
2024-07-22 14:28 ` [LTP] [PATCH v3 2/5] Add cachestat01 test Andrea Cervesato
@ 2024-07-22 14:28 ` Andrea Cervesato
2024-07-23 10:43 ` Cyril Hrubis
2024-07-22 14:28 ` [LTP] [PATCH v3 4/5] Add cachestat03 test Andrea Cervesato
2024-07-22 14:28 ` [LTP] [PATCH v3 5/5] Add cachestat04 test Andrea Cervesato
4 siblings, 1 reply; 10+ messages in thread
From: Andrea Cervesato @ 2024-07-22 14:28 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
This test verifies that cachestat() syscall is properly counting cached
pages written inside a shared memory.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/syscalls | 1 +
testcases/kernel/syscalls/cachestat/.gitignore | 1 +
testcases/kernel/syscalls/cachestat/cachestat02.c | 90 +++++++++++++++++++++++
3 files changed, 92 insertions(+)
diff --git a/runtest/syscalls b/runtest/syscalls
index ce974b317..294e3cebf 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -63,6 +63,7 @@ capset04 capset04
cacheflush01 cacheflush01
cachestat01 cachestat01
+cachestat02 cachestat02
chdir01 chdir01
chdir01A symlink01 -T chdir01
diff --git a/testcases/kernel/syscalls/cachestat/.gitignore b/testcases/kernel/syscalls/cachestat/.gitignore
index daea1f4be..0f70fb801 100644
--- a/testcases/kernel/syscalls/cachestat/.gitignore
+++ b/testcases/kernel/syscalls/cachestat/.gitignore
@@ -1 +1,2 @@
cachestat01
+cachestat02
diff --git a/testcases/kernel/syscalls/cachestat/cachestat02.c b/testcases/kernel/syscalls/cachestat/cachestat02.c
new file mode 100644
index 000000000..deaaa6d32
--- /dev/null
+++ b/testcases/kernel/syscalls/cachestat/cachestat02.c
@@ -0,0 +1,90 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * This test verifies that cachestat() syscall is properly counting cached pages
+ * written inside a shared memory.
+ *
+ * [Algorithm]
+ *
+ * - create a shared memory with a specific amount of pages
+ * - monitor file with cachestat()
+ * - check if the right amount of pages have been moved into cache
+ */
+
+#include <stdlib.h>
+#include "cachestat.h"
+
+#define FILENAME "myfile.bin"
+
+static int page_size;
+static char *page_data;
+static struct cachestat *cs;
+static struct cachestat_range *cs_range;
+
+static void test_cached_pages(const int num_pages)
+{
+ int fd, file_size;
+
+ tst_res(TINFO, "Number of pages: %d", num_pages);
+
+ memset(cs, 0, sizeof(struct cachestat));
+
+ fd = shm_open(FILENAME, O_RDWR | O_CREAT, 0600);
+ if (fd < 0)
+ tst_brk(TBROK | TERRNO, "shm_open error");
+
+ file_size = page_size * num_pages;
+
+ cs_range->off = 0;
+ cs_range->len = file_size;
+
+ SAFE_FTRUNCATE(fd, file_size);
+ for (int i = 0; i < num_pages; i++)
+ SAFE_WRITE(0, fd, page_data, page_size);
+
+ TST_EXP_PASS(cachestat(fd, cs_range, cs, 0));
+ print_cachestat(cs);
+
+ TST_EXP_EQ_LI(cs->nr_cache + cs->nr_evicted, num_pages);
+
+ SAFE_CLOSE(fd);
+ shm_unlink(FILENAME);
+}
+
+static void run(void)
+{
+ for (int i = 0; i < 10; i++)
+ test_cached_pages(1 << i);
+}
+
+static void setup(void)
+{
+ page_size = (int)sysconf(_SC_PAGESIZE);
+
+ page_data = SAFE_MALLOC(page_size);
+ memset(page_data, 'a', page_size);
+}
+
+static void cleanup(void)
+{
+ if (page_data)
+ free(page_data);
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .setup = setup,
+ .cleanup = cleanup,
+ .needs_tmpdir = 1,
+ .min_kver = "6.5",
+ .bufs = (struct tst_buffers []) {
+ {&cs, .size = sizeof(struct cachestat)},
+ {&cs_range, .size = sizeof(struct cachestat_range)},
+ {}
+ },
+};
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 10+ messages in thread* [LTP] [PATCH v3 4/5] Add cachestat03 test
2024-07-22 14:28 [LTP] [PATCH v3 0/5] cachestat testing suite Andrea Cervesato
` (2 preceding siblings ...)
2024-07-22 14:28 ` [LTP] [PATCH v3 3/5] Add cachestat02 test Andrea Cervesato
@ 2024-07-22 14:28 ` Andrea Cervesato
2024-07-24 9:20 ` Cyril Hrubis
2024-07-22 14:28 ` [LTP] [PATCH v3 5/5] Add cachestat04 test Andrea Cervesato
4 siblings, 1 reply; 10+ messages in thread
From: Andrea Cervesato @ 2024-07-22 14:28 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
This test verifies that cachestat() syscall is properly failing with
relative error codes according to input parameters.
- EFAULT: cstat or cstat_range points to an illegal address
- EINVAL: invalid flags
- EBADF: invalid file descriptor
- EOPNOTSUPP: file descriptor is of a hugetlbfs file
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/syscalls | 1 +
testcases/kernel/syscalls/cachestat/.gitignore | 1 +
testcases/kernel/syscalls/cachestat/cachestat03.c | 80 +++++++++++++++++++++++
3 files changed, 82 insertions(+)
diff --git a/runtest/syscalls b/runtest/syscalls
index 294e3cebf..8a297429b 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -64,6 +64,7 @@ cacheflush01 cacheflush01
cachestat01 cachestat01
cachestat02 cachestat02
+cachestat03 cachestat03
chdir01 chdir01
chdir01A symlink01 -T chdir01
diff --git a/testcases/kernel/syscalls/cachestat/.gitignore b/testcases/kernel/syscalls/cachestat/.gitignore
index 0f70fb801..6cfa3fa10 100644
--- a/testcases/kernel/syscalls/cachestat/.gitignore
+++ b/testcases/kernel/syscalls/cachestat/.gitignore
@@ -1,2 +1,3 @@
cachestat01
cachestat02
+cachestat03
diff --git a/testcases/kernel/syscalls/cachestat/cachestat03.c b/testcases/kernel/syscalls/cachestat/cachestat03.c
new file mode 100644
index 000000000..35f6bdfb3
--- /dev/null
+++ b/testcases/kernel/syscalls/cachestat/cachestat03.c
@@ -0,0 +1,80 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * This test verifies that cachestat() syscall is properly failing with relative
+ * error codes according to input parameters.
+ *
+ * - EFAULT: cstat or cstat_range points to an illegal address
+ * - EINVAL: invalid flags
+ * - EBADF: invalid file descriptor
+ * - EOPNOTSUPP: file descriptor is of a hugetlbfs file
+ */
+
+#define MNTPOINT "mnt"
+
+#include "cachestat.h"
+
+static int fd;
+static int fd_hugepage;
+static int invalid_fd = -1;
+static struct cachestat *cs;
+static struct cachestat *cs_null;
+static struct cachestat_range *cs_range;
+static struct cachestat_range *cs_range_null;
+
+static struct tcase {
+ int *fd;
+ struct cachestat_range **range;
+ struct cachestat **data;
+ int flags;
+ int exp_errno;
+ char *msg;
+} tcases[] = {
+ {&invalid_fd, &cs_range, &cs, 0, EBADF, "Invalid fd (-1)"},
+ {&fd, &cs_range_null, &cs, 0, EFAULT, "Invalid range (NULL)"},
+ {&fd, &cs_range, &cs_null, 0, EFAULT, "Invalid data (NULL)"},
+ {&fd, &cs_range, &cs, -1, EINVAL, "Invalid args (-1)"},
+ {&fd_hugepage, &cs_range, &cs, 0, EOPNOTSUPP, "Unsupported hugetlbfs"},
+};
+
+static void run(unsigned int i)
+{
+ struct tcase *tc = &tcases[i];
+
+ TST_EXP_FAIL(cachestat(*tc->fd, *tc->range, *tc->data, tc->flags),
+ tc->exp_errno, "%s", tc->msg);
+}
+
+static void setup(void)
+{
+ fd = SAFE_OPEN("test", O_CREAT | O_RDWR, 0700);
+ fd_hugepage = SAFE_OPEN(MNTPOINT"/test", O_CREAT | O_RDWR, 0700);
+}
+
+static void cleanup(void)
+{
+ SAFE_CLOSE(fd);
+ SAFE_CLOSE(fd_hugepage);
+}
+
+static struct tst_test test = {
+ .test = run,
+ .setup = setup,
+ .cleanup = cleanup,
+ .mntpoint = MNTPOINT,
+ .needs_hugetlbfs = 1,
+ .hugepages = {1, TST_NEEDS},
+ .tcnt = ARRAY_SIZE(tcases),
+ .min_kver = "6.5",
+ .needs_tmpdir = 1,
+ .bufs = (struct tst_buffers []) {
+ {&cs, .size = sizeof(struct cachestat)},
+ {&cs_range, .size = sizeof(struct cachestat_range)},
+ {}
+ },
+};
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 10+ messages in thread* [LTP] [PATCH v3 5/5] Add cachestat04 test
2024-07-22 14:28 [LTP] [PATCH v3 0/5] cachestat testing suite Andrea Cervesato
` (3 preceding siblings ...)
2024-07-22 14:28 ` [LTP] [PATCH v3 4/5] Add cachestat03 test Andrea Cervesato
@ 2024-07-22 14:28 ` Andrea Cervesato
2024-07-24 9:55 ` Cyril Hrubis
4 siblings, 1 reply; 10+ messages in thread
From: Andrea Cervesato @ 2024-07-22 14:28 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
This test verifies cachestat() for all possible file descriptors,
checking that returned statistics are always zero, unless file
descriptor is unsupported and EBADF is raised.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/syscalls | 1 +
testcases/kernel/syscalls/cachestat/.gitignore | 1 +
testcases/kernel/syscalls/cachestat/cachestat04.c | 58 +++++++++++++++++++++++
3 files changed, 60 insertions(+)
diff --git a/runtest/syscalls b/runtest/syscalls
index 8a297429b..9b041b03d 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -65,6 +65,7 @@ cacheflush01 cacheflush01
cachestat01 cachestat01
cachestat02 cachestat02
cachestat03 cachestat03
+cachestat04 cachestat04
chdir01 chdir01
chdir01A symlink01 -T chdir01
diff --git a/testcases/kernel/syscalls/cachestat/.gitignore b/testcases/kernel/syscalls/cachestat/.gitignore
index 6cfa3fa10..a3611a533 100644
--- a/testcases/kernel/syscalls/cachestat/.gitignore
+++ b/testcases/kernel/syscalls/cachestat/.gitignore
@@ -1,3 +1,4 @@
cachestat01
cachestat02
cachestat03
+cachestat04
diff --git a/testcases/kernel/syscalls/cachestat/cachestat04.c b/testcases/kernel/syscalls/cachestat/cachestat04.c
new file mode 100644
index 000000000..0913dd57a
--- /dev/null
+++ b/testcases/kernel/syscalls/cachestat/cachestat04.c
@@ -0,0 +1,58 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * This test verifies cachestat() for all the possible file descriptors,
+ * checking that cache statistics are always zero, except for unsupported file
+ * descriptors which cause EBADF to be raised.
+ */
+
+#include "tst_test.h"
+#include "lapi/mman.h"
+
+#define MNTPOINT "mnt"
+
+static struct cachestat *cs;
+static struct cachestat_range *cs_range;
+
+static void check_cachestat(struct tst_fd *fd_in)
+{
+ int ret;
+
+ ret = cachestat(fd_in->fd, cs_range, cs, 0);
+ if (ret == -1) {
+ TST_EXP_EQ_LI(errno, EBADF);
+ return;
+ }
+
+ TST_EXP_EQ_LI(cs->nr_cache, 0);
+ TST_EXP_EQ_LI(cs->nr_dirty, 0);
+ TST_EXP_EQ_LI(cs->nr_writeback, 0);
+ TST_EXP_EQ_LI(cs->nr_evicted, 0);
+ TST_EXP_EQ_LI(cs->nr_recently_evicted, 0);
+}
+
+static void run(void)
+{
+ TST_FD_FOREACH(fd) {
+ tst_res(TINFO, "%s -> ...", tst_fd_desc(&fd));
+ check_cachestat(&fd);
+ }
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .min_kver = "6.5",
+ .mount_device = 1,
+ .mntpoint = MNTPOINT,
+ .bufs = (struct tst_buffers []) {
+ {&cs, .size = sizeof(struct cachestat)},
+ {&cs_range, .size = sizeof(struct cachestat_range)},
+ {}
+ },
+};
+
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 10+ messages in thread