From patchwork Thu Dec 22 08:36:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9484411 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 3CDF0601D2 for ; Thu, 22 Dec 2016 08:37:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 392B9277D9 for ; Thu, 22 Dec 2016 08:37:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2E00727F8C; Thu, 22 Dec 2016 08:37:49 +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]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C0B92277D9 for ; Thu, 22 Dec 2016 08:37:48 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AE1606F17B; Thu, 22 Dec 2016 08:37:45 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wj0-x241.google.com (mail-wj0-x241.google.com [IPv6:2a00:1450:400c:c01::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5D05D6F171; Thu, 22 Dec 2016 08:37:03 +0000 (UTC) Received: by mail-wj0-x241.google.com with SMTP id hb5so1997768wjc.2; Thu, 22 Dec 2016 00:37:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=QnH+bA7F51HsJsvVwInlWuYqM2KRQvYJB7QcSvsHrNM=; b=hTeaCTfNnQc0kPdi7BPJ8FtlmNZ6Uk0HXzem97xllZoTKOadjIKFmOABCjnoQR1rjl S18MTFXL4NdyvEM3uIY5tDkRz3JBjqVOz9xeJMfNT9lpupBMDlHsRkONSSBSLoDD6Qat L29QdQJTLY85ZscKmGp+aZJ1qqqeWs8byBkfRUZtIV0X0yq3lz/0aWpnHGV7uOFfOg2F rbJlx/3nBVYO0bFUgWKC/AUNmgdrTWkVVtcDR7NXSYnAyKVFAIardDixItLkJ1c4CxnA 2Wzl4ytdGOHSHNIyW9bkZZbmp0syBkYdnricE7I4POopjQ+Ci/cMrA262SO03CJ1YPDo G9aA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=QnH+bA7F51HsJsvVwInlWuYqM2KRQvYJB7QcSvsHrNM=; b=cWjnBgFwEla2ag7wBNSLgfZ2kr4bBVxhHPuZMHTNaFUl1g6sLhp6lM0dW+UV/6QRVh QAdi1ZKiw2GZIvvVOpY+ISZI3D4wnU6KoiSmabwxqTXU+sgipnE67bQ7jXBegWHm8PjQ qbqzqfYVpXi927AJaEX1p/ix99s/X2POyj2ro1ATSQ/H8AFFU8Yh4puw67Euq9qI1Nr/ 9EV9Y1IYjZl7qlpaXp9Z8W2AL2nQARTqZZWgD9+IbVFUT+ivFe441WH4Tg5/qbyANcmF /VldN6lhni3gvvjyW9rhW97pelz7wZrTPFqL8XcCWb1J2d6143SsNfFcl468Uh2cAYZk cygQ== X-Gm-Message-State: AIkVDXJBszkAwnMat3emTv3+TuwDb2QD7WetQA9o2Ib0arDqFryRuhfQt/4gKBBzbP8upg== X-Received: by 10.194.66.101 with SMTP id e5mr7778762wjt.172.1482395821350; Thu, 22 Dec 2016 00:37:01 -0800 (PST) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id di9sm34442318wjc.37.2016.12.22.00.37.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Dec 2016 00:37:00 -0800 (PST) From: Chris Wilson To: dri-devel@lists.freedesktop.org Date: Thu, 22 Dec 2016 08:36:18 +0000 Message-Id: <20161222083641.2691-16-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20161222083641.2691-1-chris@chris-wilson.co.uk> References: <20161222083641.2691-1-chris@chris-wilson.co.uk> Cc: intel-gfx@lists.freedesktop.org Subject: [Intel-gfx] [PATCH v4 15/38] drm: kselftest for drm_mm and range restricted eviction X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP Check that we add arbitrary blocks to a restrited eviction scanner in order to find the first minimal hole that matches our request. Signed-off-by: Chris Wilson Reviewed-by: Joonas Lahtinen --- drivers/gpu/drm/selftests/drm_mm_selftests.h | 1 + drivers/gpu/drm/selftests/test-drm_mm.c | 113 ++++++++++++++++++++++++++- 2 files changed, 110 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/selftests/drm_mm_selftests.h b/drivers/gpu/drm/selftests/drm_mm_selftests.h index a31b4458c7eb..965aca65c160 100644 --- a/drivers/gpu/drm/selftests/drm_mm_selftests.h +++ b/drivers/gpu/drm/selftests/drm_mm_selftests.h @@ -16,3 +16,4 @@ selftest(align, igt_align) selftest(align32, igt_align32) selftest(align64, igt_align64) selftest(evict, igt_evict) +selftest(evict_range, igt_evict_range) diff --git a/drivers/gpu/drm/selftests/test-drm_mm.c b/drivers/gpu/drm/selftests/test-drm_mm.c index 065e2c72845b..d49115186967 100644 --- a/drivers/gpu/drm/selftests/test-drm_mm.c +++ b/drivers/gpu/drm/selftests/test-drm_mm.c @@ -1279,6 +1279,7 @@ static bool evict_everything(struct drm_mm *mm, } static int evict_something(struct drm_mm *mm, + u64 range_start, u64 range_end, struct evict_node *nodes, unsigned int *order, unsigned int count, @@ -1291,7 +1292,9 @@ static int evict_something(struct drm_mm *mm, struct drm_mm_node tmp; int err; - drm_mm_init_scan(mm, size, alignment, 0); + drm_mm_init_scan_with_range(mm, + size, alignment, 0, + range_start, range_end); if (!evict_nodes(mm, nodes, order, count, &evict_list)) @@ -1309,6 +1312,12 @@ static int evict_something(struct drm_mm *mm, return err; } + if (tmp.start < range_start || tmp.start + tmp.size > range_end) { + pr_err("Inserted [address=%llu + %llu] did not fit into the request range [%llu, %llu]\n", + tmp.start, tmp.size, range_start, range_end); + err = -EINVAL; + } + if (!assert_node(&tmp, mm, size, alignment, 0) || tmp.hole_follows) { pr_err("Inserted did not fill the eviction hole: size=%lld [%d], align=%d [rem=%lld], start=%llx, hole-follows?=%d\n", tmp.size, size, @@ -1390,7 +1399,7 @@ static int igt_evict(void *ignored) for (mode = evict_modes; mode->name; mode++) { for (n = 1; n <= size; n <<= 1) { drm_random_reorder(order, size, &prng); - err = evict_something(&mm, + err = evict_something(&mm, 0, U64_MAX, nodes, order, size, n, 1, mode); @@ -1404,7 +1413,7 @@ static int igt_evict(void *ignored) for (n = 1; n < size; n <<= 1) { drm_random_reorder(order, size, &prng); - err = evict_something(&mm, + err = evict_something(&mm, 0, U64_MAX, nodes, order, size, size/2, n, mode); @@ -1422,7 +1431,7 @@ static int igt_evict(void *ignored) DRM_MM_BUG_ON(!nsize); drm_random_reorder(order, size, &prng); - err = evict_something(&mm, + err = evict_something(&mm, 0, U64_MAX, nodes, order, size, nsize, n, mode); @@ -1447,6 +1456,102 @@ static int igt_evict(void *ignored) return ret; } +static int igt_evict_range(void *ignored) +{ + DRM_RND_STATE(prng, random_seed); + const unsigned int size = 8192; + const unsigned int range_size = size / 2; + const unsigned int range_start = size / 4; + const unsigned int range_end = range_start + range_size; + const struct insert_mode *mode; + struct drm_mm mm; + struct evict_node *nodes; + struct drm_mm_node *node, *next; + unsigned int *order, n; + int ret, err; + + /* Like igt_evict() but now we are limiting the search to a + * small portion of the full drm_mm. + */ + + ret = -ENOMEM; + nodes = vzalloc(size * sizeof(*nodes)); + if (!nodes) + goto err; + + order = drm_random_order(size, &prng); + if (!order) + goto err_nodes; + + ret = -EINVAL; + drm_mm_init(&mm, 0, size); + for (n = 0; n < size; n++) { + err = drm_mm_insert_node(&mm, &nodes[n].node, 1, 0, + DRM_MM_SEARCH_DEFAULT); + if (err) { + pr_err("insert failed, step %d\n", n); + ret = err; + goto out; + } + } + + for (mode = evict_modes; mode->name; mode++) { + for (n = 1; n <= range_size; n <<= 1) { + drm_random_reorder(order, size, &prng); + err = evict_something(&mm, range_start, range_end, + nodes, order, size, + n, 1, + mode); + if (err) { + pr_err("%s evict_something(size=%u) failed with range [%u, %u]\n", + mode->name, n, range_start, range_end); + goto out; + } + } + + for (n = 1; n <= range_size; n <<= 1) { + drm_random_reorder(order, size, &prng); + err = evict_something(&mm, range_start, range_end, + nodes, order, size, + range_size/2, n, + mode); + if (err) { + pr_err("%s evict_something(size=%u, alignment=%u) failed with range [%u, %u]\n", + mode->name, range_size/2, n, range_start, range_end); + goto out; + } + } + + for_each_prime_number_from(n, 1, min(range_size, max_prime)) { + unsigned int nsize = (range_size - n + 1) / 2; + + DRM_MM_BUG_ON(!nsize); + + drm_random_reorder(order, size, &prng); + err = evict_something(&mm, range_start, range_end, + nodes, order, size, + nsize, n, + mode); + if (err) { + pr_err("%s evict_something(size=%u, alignment=%u) failed with range [%u, %u]\n", + mode->name, nsize, n, range_start, range_end); + goto out; + } + } + } + + ret = 0; +out: + drm_mm_for_each_node_safe(node, next, &mm) + drm_mm_remove_node(node); + drm_mm_takedown(&mm); + kfree(order); +err_nodes: + vfree(nodes); +err: + return ret; +} + #include "drm_selftest.c" static int __init test_drm_mm_init(void)