From: David Howells <dhowells@redhat.com>
To: Al Viro <viro@zeniv.linux.org.uk>,
Linus Torvalds <torvalds@linux-foundation.org>
Cc: David Howells <dhowells@redhat.com>, Jens Axboe <axboe@kernel.dk>,
Christoph Hellwig <hch@lst.de>,
Christian Brauner <christian@brauner.io>,
David Laight <David.Laight@ACULAB.COM>,
Matthew Wilcox <willy@infradead.org>,
Jeff Layton <jlayton@kernel.org>,
linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org,
linux-mm@kvack.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Subject: [PATCH v4 13/13] iov_iter: Create a fake device to allow iov_iter testing/benchmarking
Date: Wed, 13 Sep 2023 17:56:48 +0100 [thread overview]
Message-ID: <20230913165648.2570623-14-dhowells@redhat.com> (raw)
In-Reply-To: <20230913165648.2570623-1-dhowells@redhat.com>
Create a fake device to allow testing and benchmarking of UBUF and IOVEC
iterators. /dev/iov-test is created and can be driven with pwritev() in
which case it copies everything to a sink page and it can be written with
preadv() in which case it copies repeatedly from a patterned page.
The time taken is logged with tracepoints.
This can be driven by something like:
echo 1 >/sys/kernel/debug/tracing/events/iov_test/enable
cmd="r -b 1M -V 256 0 256M"; xfs_io -c "open /dev/iov-test" \
-c "$cmd" -c "$cmd" -c "$cmd" -c "$cmd" \
-c "$cmd" -c "$cmd" -c "$cmd" -c "$cmd" \
-c "$cmd" -c "$cmd" -c "$cmd" -c "$cmd" \
-c "$cmd" -c "$cmd" -c "$cmd" -c "$cmd"
cmd="w -b 1M -V 256 0 256M"; xfs_io -c "open /dev/iov-test" \
-c "$cmd" -c "$cmd" -c "$cmd" -c "$cmd" \
-c "$cmd" -c "$cmd" -c "$cmd" -c "$cmd" \
-c "$cmd" -c "$cmd" -c "$cmd" -c "$cmd" \
-c "$cmd" -c "$cmd" -c "$cmd" -c "$cmd"
showing something like:
...: iov_test_read: size=10000000 done=10000000 ty=1 nr=256 dur=27653
...: iov_test_write: size=10000000 done=10000000 ty=1 nr=256 dur=31792
in the trace log.
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Alexander Viro <viro@zeniv.linux.org.uk>
cc: Jens Axboe <axboe@kernel.dk>
cc: Christoph Hellwig <hch@lst.de>
cc: Christian Brauner <christian@brauner.io>
cc: Matthew Wilcox <willy@infradead.org>
cc: Linus Torvalds <torvalds@linux-foundation.org>
cc: David Laight <David.Laight@ACULAB.COM>
cc: "David S. Miller" <davem@davemloft.net>
cc: Eric Dumazet <edumazet@google.com>
cc: Jakub Kicinski <kuba@kernel.org>
cc: Paolo Abeni <pabeni@redhat.com>
cc: linux-block@vger.kernel.org
cc: linux-fsdevel@vger.kernel.org
cc: linux-mm@kvack.org
cc: netdev@vger.kernel.org
---
lib/Kconfig.debug | 8 +++
lib/Makefile | 1 +
lib/test_iov_iter.c | 134 ++++++++++++++++++++++++++++++++++++++
lib/test_iov_iter_trace.h | 80 +++++++++++++++++++++++
4 files changed, 223 insertions(+)
create mode 100644 lib/test_iov_iter.c
create mode 100644 lib/test_iov_iter_trace.h
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index fa307f93fa2e..cf8392c51344 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -2524,6 +2524,14 @@ config TEST_SYSCTL
If unsure, say N.
+config TEST_IOV_ITER
+ tristate "iov_iter test driver"
+ help
+ This creates a misc device that can be used as a way to test various
+ I/O iterator functions through the use of readv/writev and ioctl.
+
+ If unsure, say N.
+
config BITFIELD_KUNIT
tristate "KUnit test bitfield functions at runtime" if !KUNIT_ALL_TESTS
depends on KUNIT
diff --git a/lib/Makefile b/lib/Makefile
index 740109b6e2c8..f6419544a749 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -65,6 +65,7 @@ CFLAGS_test_bitops.o += -Werror
obj-$(CONFIG_CPUMASK_KUNIT_TEST) += cpumask_kunit.o
obj-$(CONFIG_TEST_SYSCTL) += test_sysctl.o
obj-$(CONFIG_TEST_IOV_ITER) += kunit_iov_iter.o
+obj-$(CONFIG_TEST_IOV_ITER) += test_iov_iter.o
obj-$(CONFIG_HASH_KUNIT_TEST) += test_hash.o
obj-$(CONFIG_TEST_IDA) += test_ida.o
obj-$(CONFIG_TEST_UBSAN) += test_ubsan.o
diff --git a/lib/test_iov_iter.c b/lib/test_iov_iter.c
new file mode 100644
index 000000000000..afa70647dbde
--- /dev/null
+++ b/lib/test_iov_iter.c
@@ -0,0 +1,134 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* I/O iterator testing device.
+ *
+ * Copyright (C) 2023 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/module.h>
+#include <linux/uio.h>
+#include <linux/fs.h>
+#include <linux/pagemap.h>
+#include <linux/miscdevice.h>
+#define CREATE_TRACE_POINTS
+#include "test_iov_iter_trace.h"
+
+MODULE_DESCRIPTION("iov_iter testing");
+MODULE_AUTHOR("David Howells <dhowells@redhat.com>");
+MODULE_LICENSE("GPL");
+
+static ssize_t iov_test_read_iter(struct kiocb *iocb, struct iov_iter *iter)
+{
+ struct folio *folio = iocb->ki_filp->private_data;
+ unsigned int nr_segs = iter->nr_segs;
+ size_t size = iov_iter_count(iter), fsize = folio_size(folio);
+ size_t copied = 0, offset = 0, i;
+ ktime_t a, b;
+ u8 *p;
+
+ /* Pattern the buffer */
+ p = kmap_local_folio(folio, 0);
+ for (i = 0; i < folio_size(folio); i++)
+ p[i] = i & 0xff;
+ kunmap_local(p);
+
+ a = ktime_get_real();
+ while (iov_iter_count(iter)) {
+ size_t done, part = min(iov_iter_count(iter), fsize - offset);
+
+ done = copy_folio_to_iter(folio, offset, part, iter);
+ if (done == 0)
+ break;
+ copied += done;
+ offset = (offset + done) & (fsize - 1);
+ }
+
+ b = ktime_get_real();
+ trace_iov_test_read(size, copied, iov_iter_type(iter), nr_segs,
+ ktime_to_us(ktime_sub(b, a)));
+ return copied;
+}
+
+static ssize_t iov_test_write_iter(struct kiocb *iocb, struct iov_iter *iter)
+{
+ struct folio *folio = iocb->ki_filp->private_data;
+ unsigned int nr_segs = iter->nr_segs;
+ size_t size = iov_iter_count(iter), fsize = folio_size(folio);
+ size_t copied = 0, offset = 0;
+ ktime_t a = ktime_get_real(), b;
+
+ while (iov_iter_count(iter)) {
+ size_t done, part = min(iov_iter_count(iter), fsize - offset);
+
+ done = copy_page_from_iter(folio_page(folio, 0), offset, part, iter);
+ if (done == 0)
+ break;
+ copied += done;
+ offset = (offset + done) & (fsize - 1);
+ }
+
+ b = ktime_get_real();
+ trace_iov_test_write(size, copied, iov_iter_type(iter), nr_segs,
+ ktime_to_us(ktime_sub(b, a)));
+ return copied;
+}
+
+static int iov_test_open(struct inode *inode, struct file *file)
+{
+ struct folio *folio;
+
+ if (!capable(CAP_SYS_ADMIN))
+ return -EPERM;
+
+ folio = folio_alloc(GFP_KERNEL, 0);
+ if (!folio)
+ return -ENOMEM;
+ file->private_data = folio;
+ return 0;
+}
+
+static int iov_test_release(struct inode *inode, struct file *file)
+{
+ struct folio *folio = file->private_data;
+
+ folio_put(folio);
+ return 0;
+}
+
+static const struct file_operations iov_test_fops = {
+ .owner = THIS_MODULE,
+ .open = iov_test_open,
+ .release = iov_test_release,
+ .read_iter = iov_test_read_iter,
+ .write_iter = iov_test_write_iter,
+ .splice_read = copy_splice_read,
+ .llseek = noop_llseek,
+};
+
+static struct miscdevice iov_test_dev = {
+ .minor = MISC_DYNAMIC_MINOR,
+ .name = "iov-test",
+ .fops = &iov_test_fops,
+};
+
+static int __init iov_test_init(void)
+{
+ int ret;
+
+ ret = misc_register(&iov_test_dev);
+ if (ret < 0)
+ return ret;
+ pr_info("Loaded\n");
+ return 0;
+}
+module_init(iov_test_init);
+
+static void __exit iov_test_exit(void)
+{
+ pr_info("Unloading\n");
+
+ misc_deregister(&iov_test_dev);
+}
+module_exit(iov_test_exit);
diff --git a/lib/test_iov_iter_trace.h b/lib/test_iov_iter_trace.h
new file mode 100644
index 000000000000..b99cade5d004
--- /dev/null
+++ b/lib/test_iov_iter_trace.h
@@ -0,0 +1,80 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* I/O iterator testing device.
+ *
+ * Copyright (C) 2023 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ */
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM iov_test
+
+#if !defined(_IOV_TEST_TRACE_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _IOV_TEST_TRACE_H
+
+#include <linux/tracepoint.h>
+
+TRACE_EVENT(iov_test_read,
+ TP_PROTO(size_t size, size_t done, enum iter_type type,
+ unsigned int nr_segs, u64 duration),
+
+ TP_ARGS(size, done, type, nr_segs, duration),
+
+ TP_STRUCT__entry(
+ __field(size_t, size)
+ __field(size_t, done)
+ __field(enum iter_type, type)
+ __field(unsigned int, nr_segs)
+ __field(u64, duration)
+ ),
+
+ TP_fast_assign(
+ __entry->size = size;
+ __entry->done = done;
+ __entry->type = type;
+ __entry->nr_segs = nr_segs;
+ __entry->duration = duration;
+ ),
+
+ TP_printk("size=%zx done=%zx ty=%u nr=%u dur=%llu",
+ __entry->size,
+ __entry->done,
+ __entry->type,
+ __entry->nr_segs,
+ __entry->duration)
+ );
+
+TRACE_EVENT(iov_test_write,
+ TP_PROTO(size_t size, size_t done, enum iter_type type,
+ unsigned int nr_segs, u64 duration),
+
+ TP_ARGS(size, done, type, nr_segs, duration),
+
+ TP_STRUCT__entry(
+ __field(size_t, size)
+ __field(size_t, done)
+ __field(enum iter_type, type)
+ __field(unsigned int, nr_segs)
+ __field(u64, duration)
+ ),
+
+ TP_fast_assign(
+ __entry->size = size;
+ __entry->done = done;
+ __entry->type = type;
+ __entry->nr_segs = nr_segs;
+ __entry->duration = duration;
+ ),
+
+ TP_printk("size=%zx done=%zx ty=%u nr=%u dur=%llu",
+ __entry->size,
+ __entry->done,
+ __entry->type,
+ __entry->nr_segs,
+ __entry->duration)
+ );
+
+#endif /* _IOV_TEST_TRACE_H */
+
+#undef TRACE_INCLUDE_PATH
+#define TRACE_INCLUDE_PATH .
+#define TRACE_INCLUDE_FILE test_iov_iter_trace
+#include <trace/define_trace.h>
prev parent reply other threads:[~2023-09-13 16:58 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-13 16:56 [PATCH v4 00/13] iov_iter: Convert the iterator macros into inline funcs David Howells
2023-09-13 16:56 ` [PATCH v4 01/13] iov_iter: Add a benchmarking kunit test David Howells
2023-09-14 6:04 ` Johannes Thumshirn
2023-09-13 16:56 ` [PATCH v4 02/13] iov_iter: Renumber ITER_* constants David Howells
2023-09-13 16:56 ` [PATCH v4 03/13] iov_iter: Derive user-backedness from the iterator type David Howells
2023-09-13 16:56 ` [PATCH v4 04/13] iov_iter: Convert iterate*() to inline funcs David Howells
2023-09-13 16:56 ` [PATCH v4 05/13] iov: Move iterator functions to a header file David Howells
2023-09-14 9:06 ` David Laight
2023-09-15 9:38 ` David Howells
2023-09-13 16:56 ` [PATCH v4 06/13] iov_iter: Add a kernel-type iterator-only iteration function David Howells
2023-09-13 16:56 ` [PATCH v4 07/13] iov_iter: Make copy_from_iter() always handle MCE David Howells
2023-09-13 19:43 ` Linus Torvalds
2023-09-13 16:56 ` [PATCH v4 08/13] iov_iter: Remove the copy_mc flag and associated functions David Howells
2023-09-13 16:56 ` [PATCH v4 09/13] iov_iter, net: Move csum_and_copy_to/from_iter() to net/ David Howells
2023-09-13 16:56 ` [PATCH v4 10/13] iov_iter, net: Fold in csum_and_memcpy() David Howells
2023-09-13 16:56 ` [PATCH v4 11/13] iov_iter, net: Merge csum_and_copy_from_iter{,_full}() together David Howells
2023-09-13 16:56 ` [PATCH v4 12/13] iov_iter, net: Move hash_and_copy_to_iter() to net/ David Howells
2023-09-13 16:56 ` David Howells [this message]
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=20230913165648.2570623-14-dhowells@redhat.com \
--to=dhowells@redhat.com \
--cc=David.Laight@ACULAB.COM \
--cc=axboe@kernel.dk \
--cc=christian@brauner.io \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hch@lst.de \
--cc=jlayton@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=torvalds@linux-foundation.org \
--cc=viro@zeniv.linux.org.uk \
--cc=willy@infradead.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).