From: Chris Wilson <chris@chris-wilson.co.uk>
To: linux-kernel@vger.kernel.org
Cc: dri-devel@lists.freedesktop.org
Subject: [PATCH v2 4/7] async: Add kselftests for async-domains
Date: Sun, 17 Jul 2016 13:58:04 +0100 [thread overview]
Message-ID: <1468760287-731-5-git-send-email-chris@chris-wilson.co.uk> (raw)
In-Reply-To: <1468760287-731-1-git-send-email-chris@chris-wilson.co.uk>
A preparatory patch for adding new features (and their tests). First we
want to add coverage of existing features to kselftest.
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
lib/Kconfig.debug | 9 ++
lib/Makefile | 1 +
lib/test-async-domain.c | 131 ++++++++++++++++++++++++++++
tools/testing/selftests/lib/Makefile | 2 +-
tools/testing/selftests/lib/async-domain.sh | 10 +++
5 files changed, 152 insertions(+), 1 deletion(-)
create mode 100644 lib/test-async-domain.c
create mode 100755 tools/testing/selftests/lib/async-domain.sh
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index df1182d41f06..4b180aed88b6 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -1784,6 +1784,15 @@ config KFENCE_CHECK_DAG
graphs (DAG), as otherwise the cycles in the graph means that they
will never be signaled (or the corresponding task executed).
+config ASYNC_DOMAIN_SELFTEST
+ tristate "Asynchronous domain self tests"
+ depends on DEBUG_KERNEL
+ default n
+ help
+ the asynchronous task execution. This option is not useful for
+ distributions or general kernels, but only for kernel developers
+ working on the async_domain facility.
+
Say N if you are unsure.
config BACKTRACE_SELF_TEST
diff --git a/lib/Makefile b/lib/Makefile
index 943781cfe8d1..5864053cf63e 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -28,6 +28,7 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \
earlycpio.o seq_buf.o nmi_backtrace.o nodemask.o
obj-$(CONFIG_ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS) += usercopy.o
+obj-$(CONFIG_ASYNC_DOMAIN_SELFTEST) += test-async-domain.o
obj-$(CONFIG_KFENCE_SELFTEST) += test-kfence.o
lib-$(CONFIG_MMU) += ioremap.o
lib-$(CONFIG_SMP) += cpumask.o
diff --git a/lib/test-async-domain.c b/lib/test-async-domain.c
new file mode 100644
index 000000000000..558a71414fb6
--- /dev/null
+++ b/lib/test-async-domain.c
@@ -0,0 +1,131 @@
+/*
+ * Test cases for async-domain facility.
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/async.h>
+#include <linux/module.h>
+#include <linux/delay.h>
+
+static void task_A(void *data, async_cookie_t cookie)
+{
+ long *result = data;
+ smp_store_mb(*result, 'A');
+}
+
+static void task_B(void *data, async_cookie_t cookie)
+{
+ long *result = data;
+ usleep_range(100, 200);
+ smp_store_mb(*result, 'B');
+}
+
+static int __init test_implicit(struct async_domain *domain)
+{
+ const long expected = 'B';
+ long result = 0;
+
+ if (!async_schedule_domain(task_B, &result, domain))
+ return -ENOMEM;
+
+ async_synchronize_full_domain(domain);
+
+ if (READ_ONCE(result) != expected) {
+ pr_warn("%s expected %c [%ld], got %ld\n",
+ __func__, (char)expected, expected, result);
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int __init test_registered(struct async_domain *domain)
+{
+ const long expected = 'B';
+ long result = 0;
+
+ if (!async_schedule_domain(task_B, &result, domain))
+ return -ENOMEM;
+
+ async_synchronize_full();
+
+ if (READ_ONCE(result) != expected) {
+ pr_warn("%s expected %c [%ld], got %ld\n",
+ __func__, (char)expected, expected, result);
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static void task_nop(void *data, async_cookie_t cookie)
+{
+ async_cookie_t *result = data;
+ smp_store_mb(*result, cookie);
+}
+
+static int __init perf_nop(int batch, long timeout_us)
+{
+ ktime_t start;
+ async_cookie_t nop, last;
+ long count, delay;
+
+ count = 0;
+ nop = last = 0;
+ start = ktime_get();
+ do {
+ ktime_t delta;
+ int n;
+
+ for (n = 0; n < batch; n++)
+ last = async_schedule(task_nop, &nop);
+ async_synchronize_full();
+ delta = ktime_sub(ktime_get(), start);
+ delay = ktime_to_ns(delta) >> 10;
+ count += batch;
+ } while (delay < timeout_us);
+
+ pr_info("%ld nop tasks (batches of %d) completed in %ldus; last queued %lld, saw %lld last\n",
+ count, batch, delay,
+ (long long)last, (long long)READ_ONCE(nop));
+ return 0;
+}
+
+static int __init test_async_domain_init(void)
+{
+ ASYNC_DOMAIN(domain);
+ int ret;
+
+ pr_info("Testing async-domains\n");
+
+ ret = test_implicit(&domain);
+ if (ret)
+ return ret;
+
+ ret = test_registered(&domain);
+ if (ret)
+ return ret;
+
+ ret = perf_nop(1, 100);
+ if (ret)
+ return ret;
+
+ ret = perf_nop(128, 1000);
+ if (ret)
+ return ret;
+
+ async_unregister_domain(&domain);
+ return 0;
+}
+
+static void __exit test_async_domain_cleanup(void)
+{
+ async_synchronize_full();
+}
+
+module_init(test_async_domain_init);
+module_exit(test_async_domain_cleanup);
+
+MODULE_AUTHOR("Intel Corporation");
+MODULE_LICENSE("GPL");
diff --git a/tools/testing/selftests/lib/Makefile b/tools/testing/selftests/lib/Makefile
index 08360060ab14..46a77ac5b4c6 100644
--- a/tools/testing/selftests/lib/Makefile
+++ b/tools/testing/selftests/lib/Makefile
@@ -3,6 +3,6 @@
# No binaries, but make sure arg-less "make" doesn't trigger "run_tests"
all:
-TEST_PROGS := printf.sh bitmap.sh
+TEST_PROGS := printf.sh bitmap.sh async-domain.sh
include ../lib.mk
diff --git a/tools/testing/selftests/lib/async-domain.sh b/tools/testing/selftests/lib/async-domain.sh
new file mode 100755
index 000000000000..22c270051de7
--- /dev/null
+++ b/tools/testing/selftests/lib/async-domain.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+# Runs infrastructure tests using test-async-domain kernel module
+
+if /sbin/modprobe -q test-async-domain; then
+ /sbin/modprobe -q -r test-async-domain
+ echo "async-domain: ok"
+else
+ echo "async-domain: [FAIL]"
+ exit 1
+fi
--
2.8.1
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2016-07-17 12:59 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1466759333-4703-1-git-send-email-chris@chris-wilson.co.uk>
2016-06-24 9:08 ` [PATCH 2/9] async: Introduce kfence, a N:M completion mechanism Chris Wilson
2016-07-13 9:38 ` Peter Zijlstra
2016-07-13 10:20 ` Chris Wilson
2016-07-13 11:02 ` Daniel Vetter
2016-07-13 10:26 ` Peter Zijlstra
2016-06-24 9:08 ` [PATCH 3/9] async: Extend kfence to allow struct embedding Chris Wilson
2016-07-13 10:31 ` Peter Zijlstra
2016-06-24 9:08 ` [PATCH 4/9] async: Extend kfences for listening on DMA fences Chris Wilson
2016-06-24 9:08 ` [PATCH 5/9] async: Wrap hrtimer to provide a time source for a kfence Chris Wilson
2016-07-13 10:32 ` Peter Zijlstra
2016-06-24 9:08 ` [PATCH 6/9] async: Add a convenience wrapper for waiting on implicit dma-buf Chris Wilson
2016-06-24 9:08 ` [PATCH 7/9] async: Add support for explicit fine-grained barriers Chris Wilson
2016-06-24 9:08 ` [PATCH 8/9] async: Add execution barriers Chris Wilson
2016-06-24 9:08 ` [PATCH 9/9] async: Introduce a dependency resolver for parallel execution Chris Wilson
2016-07-17 12:58 ` Introduce fences for N:M completion variables [v2] Chris Wilson
2016-07-17 12:58 ` [PATCH v2 1/7] kfence: Introduce kfence, a N:M completion mechanism Chris Wilson
2016-07-17 12:58 ` [PATCH v2 2/7] kfence: Wrap hrtimer to provide a time source for a kfence Chris Wilson
2016-07-17 12:58 ` [PATCH v2 3/7] kfence: Extend kfences for listening on DMA fences Chris Wilson
2016-07-17 12:58 ` Chris Wilson [this message]
2016-07-17 12:58 ` [PATCH v2 5/7] async: Add support for explicit fine-grained barriers Chris Wilson
2016-07-17 12:58 ` [PATCH v2 6/7] async: Add execution barriers Chris Wilson
2016-07-17 12:58 ` [PATCH v2 7/7] async: Introduce a dependency resolver for parallel execution Chris Wilson
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=1468760287-731-5-git-send-email-chris@chris-wilson.co.uk \
--to=chris@chris-wilson.co.uk \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.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;
as well as URLs for NNTP newsgroup(s).