From patchwork Thu Dec 22 08:36:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9484469 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 00FA6601D2 for ; Thu, 22 Dec 2016 08:39:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F0C30277D9 for ; Thu, 22 Dec 2016 08:39:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E4AC8281C3; Thu, 22 Dec 2016 08:39:38 +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=unavailable 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 8C716277D9 for ; Thu, 22 Dec 2016 08:39:38 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 501436F1A5; Thu, 22 Dec 2016 08:39:11 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wj0-x242.google.com (mail-wj0-x242.google.com [IPv6:2a00:1450:400c:c01::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3626C6F173; Thu, 22 Dec 2016 08:37:07 +0000 (UTC) Received: by mail-wj0-x242.google.com with SMTP id kp2so35174537wjc.0; Thu, 22 Dec 2016 00:37:07 -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=jTIQaMLZMw8fCgs4LsmiWD7kMKUFOS33GjFpzjwqvbQ=; b=WVAjvV57Au6aTttgMxQ5eFsRFtV0R51f5TmpLrM9OMoz56MtBAIn7EtGKJppO+3K9k 1b4OVsBTRyo7fOCLD2itWjWhmaO+IhOvRNOsycphnKPvQJzdVPPwFoMRnppkLtTe7bJU YYlsvVIsOu8ZIgpCk9e7sL30kgtSUxwyK8jLKj7mB+D9RGFyOLfsWEmTgn/BB/Et5ily mDNnHMl/5FCWeosaJSVsSsMMzmIdTu1Of+5ludeMNxfMt8XIl/MdpOIeCHCUG8BR1zgc s78VUHNk/u1jnXGlhMNR/S4IKzuLPBpwgI1yVQfFDkV7TaBzEykgMqhZluPVNMsJ8Wea 4G0Q== 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=jTIQaMLZMw8fCgs4LsmiWD7kMKUFOS33GjFpzjwqvbQ=; b=thLyyoXkPeIbLSxcJaIa3Eln0cBIKePJZHHQd5QH2iu0okzJKXlet8x+9WwSSsjwQe UMQdzRCHO+e5XJ91D1fble/86qisMg8DGtajpLXbKBda0JtKtGLdaPEzOMfg7WIeKaWm kxbxD0r+4YMhfOKJtBP1DYjgM3hiVeXzIbURbxnEui9PpeWxECzyUwxeqLd4zV98Fa3c J8e5RpMJKYxOI0pgO6/8t+ENCj2yg5oauwOUpNHiFn1UO0exKMSRTagN8JKjr15OZtRM vKMOhYZCDcVL+OEwrZ0WIbE8d7AGH0w25EU4ZXvbb8H9agk+1E1zA/Urx+6B3EJCYewH x1fg== X-Gm-Message-State: AIkVDXKrhTIMsI+N1ckyG7pOQbrFJMBBGTAiGu8MFkWIgdb9X6uPrBHEjQlbMF+4isp0wQ== X-Received: by 10.194.99.38 with SMTP id en6mr8142864wjb.184.1482395825334; Thu, 22 Dec 2016 00:37:05 -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.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Dec 2016 00:37:04 -0800 (PST) From: Chris Wilson To: dri-devel@lists.freedesktop.org Subject: [PATCH v4 19/38] drm: kselftest for drm_mm and restricted color eviction Date: Thu, 22 Dec 2016 08:36:22 +0000 Message-Id: <20161222083641.2691-20-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 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 Check that after applying the driver's color adjustment, restricted eviction scanning finds a suitable hole. 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 | 116 ++++++++++++++++++++++++++- 2 files changed, 113 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/selftests/drm_mm_selftests.h b/drivers/gpu/drm/selftests/drm_mm_selftests.h index 0a3a7e32e5f7..6a4575fdc1c0 100644 --- a/drivers/gpu/drm/selftests/drm_mm_selftests.h +++ b/drivers/gpu/drm/selftests/drm_mm_selftests.h @@ -20,3 +20,4 @@ selftest(evict_range, igt_evict_range) selftest(topdown, igt_topdown) selftest(color, igt_color) selftest(color_evict, igt_color_evict) +selftest(color_evict_range, igt_color_evict_range) diff --git a/drivers/gpu/drm/selftests/test-drm_mm.c b/drivers/gpu/drm/selftests/test-drm_mm.c index 6584e4ce96af..fb8f7056225b 100644 --- a/drivers/gpu/drm/selftests/test-drm_mm.c +++ b/drivers/gpu/drm/selftests/test-drm_mm.c @@ -1855,6 +1855,7 @@ static int igt_color(void *ignored) } static int evict_color(struct drm_mm *mm, + u64 range_start, u64 range_end, struct evict_node *nodes, unsigned int *order, unsigned int count, @@ -1868,7 +1869,9 @@ static int evict_color(struct drm_mm *mm, struct drm_mm_node tmp; int err; - drm_mm_init_scan(mm, size, alignment, color); + drm_mm_init_scan_with_range(mm, + size, alignment, color, + range_start, range_end); if (!evict_nodes(mm, nodes, order, count, &evict_list)) @@ -1886,6 +1889,12 @@ static int evict_color(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 (colors_abutt(&tmp)) err = -EINVAL; @@ -1954,7 +1963,7 @@ static int igt_color_evict(void *ignored) for (mode = evict_modes; mode->name; mode++) { for (n = 1; n <= total_size; n <<= 1) { drm_random_reorder(order, total_size, &prng); - err = evict_color(&mm, + err = evict_color(&mm, 0, U64_MAX, nodes, order, total_size, n, 1, color++, mode); @@ -1967,7 +1976,7 @@ static int igt_color_evict(void *ignored) for (n = 1; n < total_size; n <<= 1) { drm_random_reorder(order, total_size, &prng); - err = evict_color(&mm, + err = evict_color(&mm, 0, U64_MAX, nodes, order, total_size, total_size/2, n, color++, mode); @@ -1984,7 +1993,7 @@ static int igt_color_evict(void *ignored) DRM_MM_BUG_ON(!nsize); drm_random_reorder(order, total_size, &prng); - err = evict_color(&mm, + err = evict_color(&mm, 0, U64_MAX, nodes, order, total_size, nsize, n, color++, mode); @@ -2010,6 +2019,105 @@ static int igt_color_evict(void *ignored) return ret; } +static int igt_color_evict_range(void *ignored) +{ + DRM_RND_STATE(prng, random_seed); + const unsigned int total_size = 8192; + const unsigned int range_size = total_size / 2; + const unsigned int range_start = total_size / 4; + const unsigned int range_end = range_start + range_size; + const struct insert_mode *mode; + unsigned long color = 0; + struct drm_mm mm; + struct evict_node *nodes; + struct drm_mm_node *node, *next; + unsigned int *order, n; + int ret, err; + + /* Like igt_color_evict(), but limited to small portion of the full + * drm_mm range. + */ + + ret = -ENOMEM; + nodes = vzalloc(total_size * sizeof(*nodes)); + if (!nodes) + goto err; + + order = drm_random_order(total_size, &prng); + if (!order) + goto err_nodes; + + ret = -EINVAL; + drm_mm_init(&mm, 0, 2*total_size - 1); + mm.color_adjust = separate_adjacent_colors; + for (n = 0; n < total_size; n++) { + if (!expect_insert(&mm, &nodes[n].node, + 1, 0, color++, + &insert_modes[0])) { + pr_err("insert failed, step %d\n", n); + goto out; + } + } + + for (mode = evict_modes; mode->name; mode++) { + for (n = 1; n <= range_size; n <<= 1) { + drm_random_reorder(order, range_size, &prng); + err = evict_color(&mm, range_start, range_end, + nodes, order, total_size, + n, 1, color++, + mode); + if (err) { + pr_err("%s evict_color(size=%u) failed for range [%x, %x]\n", + mode->name, n, range_start, range_end); + goto out; + } + } + + for (n = 1; n < range_size; n <<= 1) { + drm_random_reorder(order, total_size, &prng); + err = evict_color(&mm, range_start, range_end, + nodes, order, total_size, + range_size/2, n, color++, + mode); + if (err) { + pr_err("%s evict_color(size=%u, alignment=%u) failed for range [%x, %x]\n", + mode->name, total_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, total_size, &prng); + err = evict_color(&mm, range_start, range_end, + nodes, order, total_size, + nsize, n, color++, + mode); + if (err) { + pr_err("%s evict_color(size=%u, alignment=%u) failed for range [%x, %x]\n", + mode->name, nsize, n, range_start, range_end); + goto out; + } + } + } + + ret = 0; +out: + if (ret) + drm_mm_debug_table(&mm, __func__); + 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)