From patchwork Fri Dec 16 19:25:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9478355 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 585FB601C2 for ; Fri, 16 Dec 2016 19:28:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4946C28772 for ; Fri, 16 Dec 2016 19:28:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3E13B287DB; Fri, 16 Dec 2016 19:28:47 +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 DAAA428772 for ; Fri, 16 Dec 2016 19:28:46 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D89126ECFE; Fri, 16 Dec 2016 19:28:40 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x242.google.com (mail-wm0-x242.google.com [IPv6:2a00:1450:400c:c09::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id 341376ECD7; Fri, 16 Dec 2016 19:26:12 +0000 (UTC) Received: by mail-wm0-x242.google.com with SMTP id a20so7274048wme.2; Fri, 16 Dec 2016 11:26:12 -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=EnK0AuzRf5+W4yvCHdvVPYSQm8UaJnRD3WJ83z05PF0=; b=l0S8X4GqFweYbshco/WG1m7R0oTTpOUt0osDiNFd7Ydf5yLsiZSrP/ExdwW3/l+q96 ciFFUqqx2hY06qKpWRCHksBMoqQgaT/0LYuNYB0yI4+5xnYtVOeCdh7m/f3xR5hYoK2q vGOmi28WxuvM0yGWkOEkSJVXCHQtYoCwLLt+4wlTYfxGGopNBZe8aw5wnMtOTfrtX/SY moogX+PFa3EQXYBNoR2AzDM9A1tUHXRrUvEOv7ZKWqMZXeGKgzI4te/Ze21ttpBzL9US ODZxYH+BB3gYVOWAslm5BljYPlidm9f3sJFrLC+AVUfUx+pCbuHpWH/4nPeKmPGXUKMm tjHQ== 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=EnK0AuzRf5+W4yvCHdvVPYSQm8UaJnRD3WJ83z05PF0=; b=goi69fAEhn8MYQEgsf5TdrVJCH9PzlwA6Go+XFx7hBqk7DGCun9/jRkdRpGzWemMU1 dLi4R5ztXBzD6rDknT5IxjBVcHZDVPmcDwROOZWO4ySH+M2ekwtHm/zC1xzx7cswlwhK BuY0oNRtCyFBVsp+l9vbDr1qiArD+VSWEbWEcXSKWfE0lZb2SEzhPIJNWcRdOwO4k+3i k+Ek82wpQEg5BJyWzCRbzrLdH0MX+z3MPUIB6M1nHELTNBcPkeg+faIJcjLfeTyThJme 7R4FfCMxhxXWAN7/ACH0bBULQZ+tfxqwoZjEz85MVamaOC2VOMIx/E3/O0XRbt+duBlT SCOw== X-Gm-Message-State: AIkVDXIsff26O1ZuU+aKdPsSVaVKmU44XB3AexL82TWuCKFz3qzDNub0Mq2HlZyFVV2WgA== X-Received: by 10.28.168.137 with SMTP id r131mr4404594wme.16.1481916370238; Fri, 16 Dec 2016 11:26:10 -0800 (PST) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id v2sm8125856wja.41.2016.12.16.11.26.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Dec 2016 11:26:09 -0800 (PST) From: Chris Wilson To: dri-devel@lists.freedesktop.org Subject: [PATCH v3 15/38] drm: kselftest for drm_mm and range restricted eviction Date: Fri, 16 Dec 2016 19:25:27 +0000 Message-Id: <20161216192550.8352-16-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20161216192550.8352-1-chris@chris-wilson.co.uk> References: <20161216192550.8352-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 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 10142bc4e07e..f662d98177ee 100644 --- a/drivers/gpu/drm/selftests/test-drm_mm.c +++ b/drivers/gpu/drm/selftests/test-drm_mm.c @@ -1274,6 +1274,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, @@ -1286,7 +1287,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)) @@ -1304,6 +1307,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, @@ -1385,7 +1394,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); @@ -1399,7 +1408,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); @@ -1417,7 +1426,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); @@ -1442,6 +1451,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(n, 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)