From patchwork Sun Jul 17 12:58:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9233647 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 72D9E60865 for ; Sun, 17 Jul 2016 12:59:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 65B602015F for ; Sun, 17 Jul 2016 12:59:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5A1DC20855; Sun, 17 Jul 2016 12:59:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DDEF62015F for ; Sun, 17 Jul 2016 12:59:28 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F2F646E1C2; Sun, 17 Jul 2016 12:59:19 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x244.google.com (mail-wm0-x244.google.com [IPv6:2a00:1450:400c:c09::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id D52576E1BE for ; Sun, 17 Jul 2016 12:59:09 +0000 (UTC) Received: by mail-wm0-x244.google.com with SMTP id x83so8714618wma.3 for ; Sun, 17 Jul 2016 05:59:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=0udkSaQi1JK1TRfeBNstp2oPVzjW+NM8Ms1KYWJQdcQ=; b=eF1IeDng1fY8tOW4u6axupCB1qkFmLrGO5u58zqkq3r4dji1R2jrXPM/xbHkpuYW8U n5YXmCONDoK0nYB2Cyzf2iXa6hUBIO7OUkZWOJ/cE5Wb1GZszwkVOZUhoamNe6lo9Hx6 H/AVZ6lC27lBK+jZY8aYY64uVYXq62n6P8/Osja7pIWHhm4gqdzhurTsXL72KfdYEi/Z +BuUFRPR/PI44x1tC0hZmypR/8BfRW8Sbw+j4Xnq8CPP8JWRAEL+TZUgLjXQeXTGLWWS U0RH13b1wDqHBvy3BiB0UAuf+FxwlRGBmBsMAAertSooUKu4b7HqNfZr+A5k3b5xDuKl tNFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=0udkSaQi1JK1TRfeBNstp2oPVzjW+NM8Ms1KYWJQdcQ=; b=SpL+GhdY1dqPT4hcUjTfkjGlVs0om8DvE3ghW/5wyEZuR1kysVKpPRIJW936ivb/iA BYuoacgZ4daI6lahj/SCLqVTWneApgU5GtFi4980PBhVwZyvZ83qNGoE6nMYbsPQqyKD v3DM22vup5yoXs5ktQQ60rgjS/qD2YCObf3YtYaHU+v+W3ak9JKHmnytXiP8lMuchGc2 5cyRlNRvfOSo4IK3RFWWBU9iJgqt6Ric5WGmSsAiFMIQDhVZv+v5l6weNSnsQpcTLkxo d265KWLeSVTJ+zgzgimRAI6vjt67W0qSfm2yalHOGgbf/cVTD5T9f5dSlsQKOJ1aO/s6 dVDg== X-Gm-Message-State: ALyK8tIR8jp/SWUnL/fh4tp3/if+7g5/ctJljzCOeK1qBQ0VfsP+LTXVCHjKrF8//oAp3A== X-Received: by 10.28.38.2 with SMTP id m2mr9598838wmm.70.1468760347284; Sun, 17 Jul 2016 05:59:07 -0700 (PDT) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id p76sm8125371wmd.10.2016.07.17.05.59.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 17 Jul 2016 05:59:06 -0700 (PDT) From: Chris Wilson To: linux-kernel@vger.kernel.org Subject: [PATCH v2 4/7] async: Add kselftests for async-domains Date: Sun, 17 Jul 2016 13:58:04 +0100 Message-Id: <1468760287-731-5-git-send-email-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1468760287-731-1-git-send-email-chris@chris-wilson.co.uk> References: <1466759333-4703-1-git-send-email-chris@chris-wilson.co.uk> <1468760287-731-1-git-send-email-chris@chris-wilson.co.uk> Cc: dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 +#include +#include + +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