From patchwork Fri Dec 16 07:46:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9477481 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 3A3786047D for ; Fri, 16 Dec 2016 07:52:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2F6BC28810 for ; Fri, 16 Dec 2016 07:52:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1FBDF28798; Fri, 16 Dec 2016 07:52: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=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 C25FC28798 for ; Fri, 16 Dec 2016 07:52:28 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5FB5D6EB78; Fri, 16 Dec 2016 07:52:11 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@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 1F86B6EB23; Fri, 16 Dec 2016 07:47:48 +0000 (UTC) Received: by mail-wm0-x244.google.com with SMTP id a20so3538601wme.2; Thu, 15 Dec 2016 23:47:48 -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=ncm3BRe1J5XKqMQKsIvr0m6EVmXD263mL/xHDZ8XUws=; b=Q035RwspaKWObpDzLJaJUalCyCQSZezjOYIsKR+ZQnGg54+QTga/J9/JCBQFwPtpcG Z7woD2bo3YXh6E1dafkVT6Ily2va+QG1anyj05IKaZxO9WDJyBObg2pgqb8rMBx7KW1m nGkS1jcOSLV0jsP/smj6JYOiLFZjoFCvsDYB+RS+ykgFmLlsCGoPsAqLNMOse+E2JwVW S11Q83L3h3eho6L8HE0or1J+8d0OEjnH6KP8QMjsVW0jRD9qNgoPA+7U9K/CRJ+R3090 gx/Bz1/NeS8AqWvgbbOtDom7KPZw7cUxkdCZ+/3P9y3kmBDeaUwYhp4SvG7y5kXMYFH2 fFqA== 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=ncm3BRe1J5XKqMQKsIvr0m6EVmXD263mL/xHDZ8XUws=; b=Jo8jwPs3RHnEgAF+CrNoiX0BkHrm0HafHe9KqPQ1iuQ+Xf0Lal2fV6pDOp/JoXxsjA mjNzevXNbAIRnXVKUopzRZwc/XDGRXRJiYBDFPg0EUXJQI+DlKriyg0rwlMbgW0hKuBG QMF89lIDJCGoJGh3G+doQ7op+y8ORby6L3Zyl7SEPO1r82XkkyhPT0zQnXZNHro7iu/y K8QA0g7K5uwoHLAFqvPCFGkD5QGuCDaz8xzHyBFJ/2qTvXPW1y5fdXnzFbfn8uUQWYhz au01IVKr0MmfmCR8NdrJrbLCDh91ve5ZWzKheEkk9s+1bI8MQKbxpGOt31e5CniNuuuF SWpg== X-Gm-Message-State: AIkVDXJHiL587ZFHLiumdJ1QRZ/BS3iAtP4AMvhdwaWOdeNggGkLXnWXBfxG5jXdz3hbeg== X-Received: by 10.28.161.67 with SMTP id k64mr1966112wme.69.1481874466247; Thu, 15 Dec 2016 23:47:46 -0800 (PST) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id c202sm2792407wme.1.2016.12.15.23.47.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Dec 2016 23:47:45 -0800 (PST) From: Chris Wilson To: dri-devel@lists.freedesktop.org Date: Fri, 16 Dec 2016 07:46:58 +0000 Message-Id: <20161216074718.32500-21-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20161216074718.32500-1-chris@chris-wilson.co.uk> References: <20161216074718.32500-1-chris@chris-wilson.co.uk> Cc: intel-gfx@lists.freedesktop.org Subject: [Intel-gfx] [PATCH v2 20/40] drm: kselftest for drm_mm and color 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 after applying the driver's color adjustment, eviction scanning find 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 | 159 +++++++++++++++++++++++++++ 2 files changed, 160 insertions(+) diff --git a/drivers/gpu/drm/selftests/drm_mm_selftests.h b/drivers/gpu/drm/selftests/drm_mm_selftests.h index ff44f39a1826..0a3a7e32e5f7 100644 --- a/drivers/gpu/drm/selftests/drm_mm_selftests.h +++ b/drivers/gpu/drm/selftests/drm_mm_selftests.h @@ -19,3 +19,4 @@ selftest(evict, igt_evict) selftest(evict_range, igt_evict_range) selftest(topdown, igt_topdown) selftest(color, igt_color) +selftest(color_evict, igt_color_evict) diff --git a/drivers/gpu/drm/selftests/test-drm_mm.c b/drivers/gpu/drm/selftests/test-drm_mm.c index 6b3af04eb582..0a051abc8f13 100644 --- a/drivers/gpu/drm/selftests/test-drm_mm.c +++ b/drivers/gpu/drm/selftests/test-drm_mm.c @@ -1830,6 +1830,165 @@ static int igt_color(void *ignored) return ret; } +static int evict_color(struct drm_mm *mm, + struct evict_node *nodes, + unsigned int *order, + unsigned int count, + unsigned int size, + unsigned int alignment, + unsigned long color, + const struct insert_mode *mode) +{ + LIST_HEAD(evict_list); + struct evict_node *e; + struct drm_mm_node tmp; + int err; + + drm_mm_init_scan(mm, size, alignment, color); + if (!evict_nodes(mm, + nodes, order, count, + &evict_list)) + return -EINVAL; + + memset(&tmp, 0, sizeof(tmp)); + err = drm_mm_insert_node_generic(mm, &tmp, size, alignment, color, + mode->search_flags, + mode->create_flags); + if (err) { + pr_err("Failed to insert into eviction hole: size=%d, align=%d, color=%lu, err=%d\n", + size, alignment, color, err); + show_scan(mm); + show_holes(mm, 3); + return err; + } + + if (colors_abutt(&tmp)) + err = -EINVAL; + + if (!assert_node(&tmp, mm, size, alignment, color)) { + pr_err("Inserted did not fit the eviction hole: size=%lld [%d], align=%d [rem=%lld], start=%llx\n", + tmp.size, size, + alignment, misaligned(&tmp, alignment), tmp.start); + err = -EINVAL; + } + + drm_mm_remove_node(&tmp); + if (err) + return err; + + list_for_each_entry(e, &evict_list, link) { + err = drm_mm_reserve_node(mm, &e->node); + if (err) { + pr_err("Failed to reinsert node after eviction: start=%llx\n", + e->node.start); + return err; + } + } + + return 0; +} + +static int igt_color_evict(void *ignored) +{ + RND_STATE(prng, random_seed); + const unsigned int total_size = min(8192u, max_iterations); + 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; + + /* Check that the drm_mm_scan also honours color adjustment when + * choosing its victims to create a hole. Our color_adjust does not + * allow two nodes to be placed together without an intervening hole + * enlarging the set of victims that must be evicted. + */ + + 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++) { + err = drm_mm_insert_node_generic(&mm, &nodes[n].node, + 1, 0, color++, + DRM_MM_SEARCH_DEFAULT, + DRM_MM_CREATE_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 <= total_size; n <<= 1) { + drm_random_reorder(order, total_size, &prng); + err = evict_color(&mm, + nodes, order, total_size, + n, 1, color++, + mode); + if (err) { + pr_err("%s evict_color(size=%u) failed\n", + mode->name, n); + goto out; + } + } + + for (n = 1; n < total_size; n <<= 1) { + drm_random_reorder(order, total_size, &prng); + err = evict_color(&mm, + nodes, order, total_size, + total_size/2, n, color++, + mode); + if (err) { + pr_err("%s evict_color(size=%u, alignment=%u) failed\n", + mode->name, total_size/2, n); + goto out; + } + } + + drm_for_each_prime(n, min(total_size, max_prime)) { + unsigned int nsize = (total_size - n + 1) / 2; + + DRM_MM_BUG_ON(!nsize); + + drm_random_reorder(order, total_size, &prng); + err = evict_color(&mm, + nodes, order, total_size, + nsize, n, color++, + mode); + if (err) { + pr_err("%s evict_color(size=%u, alignment=%u) failed\n", + mode->name, nsize, n); + 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)