From patchwork Mon Dec 12 11:53:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9470631 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 677B360760 for ; Mon, 12 Dec 2016 11:57:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5C13127F89 for ; Mon, 12 Dec 2016 11:57:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 50DA3283F4; Mon, 12 Dec 2016 11:57:51 +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 F257A27F89 for ; Mon, 12 Dec 2016 11:57:50 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C598E6E302; Mon, 12 Dec 2016 11:56:40 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wj0-x243.google.com (mail-wj0-x243.google.com [IPv6:2a00:1450:400c:c01::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9A6336E2DB; Mon, 12 Dec 2016 11:54:15 +0000 (UTC) Received: by mail-wj0-x243.google.com with SMTP id he10so11124334wjc.2; Mon, 12 Dec 2016 03:54:15 -0800 (PST) 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=MlUn8H1864CWjIPVqjKf3mRuUAjMJYKT0WoFzi6oAHk=; b=J8JFqa37IxpMJ2KfOKrHlcChNUgZE/y2klhX/VTZZ2hVlKxMgIwdhuSIex5VlMO4si RP3YrTEBoeJyBkbJZ8wOHtC1uwJG/wIbbngOXwcBAzxP7tVZAlhuAxSXz2nf9J7wPFGL yWIs1gM+KmvDkzg8Xj30f77UnEYM4ELV+AfVWvDLQXFiXsVyznF3162F/iMahCIeE78b UMgidAVk97WYjSTVWUu/Y4mnVW2VPpgv8btezzBYkYFXms0eklX1CVzOVWZfRLl9TEH9 xS10g7xrWmXeMOszcqV5/xJkssXof60uCiF6BPqJA/GBEwXrbnw57JqUQZ3+FdZ04mf4 Vscw== 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=MlUn8H1864CWjIPVqjKf3mRuUAjMJYKT0WoFzi6oAHk=; b=YYg8rKDjFjMpfLAQ38GMF3reMo1BY6aPvtRfPKORfLOeHsn5GUF2e4KvJeVPdU6KXr q7Ake9m/3kE5Rg1Nb4bRMPHRVJd3lppTyGlLmFms88NqUfxYXQ4MMeqQ7vEeFUfRDTZ3 8CnqdPWwbGB9x80ng0pMbehCouDNuJuEGThBfk1vyUgkqtkwnxAlcwwJ4sq0r/031OAH Jh8yY0AdzK2yas/CvbqgIZASkk/E5bItXfEPPqzNAMUVOglAoEcy8DDQY2p/SSOlEgM/ WxHisDT+omkAvgEr/LTwkfWtKhMdyh+AgXnQKPpsijAxgjPycFubBVodRisZFtiLKsKK OmUg== X-Gm-Message-State: AKaTC03sl/WxKefg3T3mLRXcNmkAMmR7k+5RVgg5ocbE/8NZFIYHBi1ORQQJMdVaOAv+BA== X-Received: by 10.194.187.103 with SMTP id fr7mr76493366wjc.99.1481543653831; Mon, 12 Dec 2016 03:54:13 -0800 (PST) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id u81sm35077381wmu.10.2016.12.12.03.54.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Dec 2016 03:54:13 -0800 (PST) From: Chris Wilson To: dri-devel@lists.freedesktop.org Subject: [PATCH 17/34] drm: kselftest for drm_mm and color adjustment Date: Mon, 12 Dec 2016 11:53:33 +0000 Message-Id: <20161212115350.780-18-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20161212115350.780-1-chris@chris-wilson.co.uk> References: <20161212115350.780-1-chris@chris-wilson.co.uk> Cc: intel-gfx@lists.freedesktop.org, joonas.lahtinen@linux.intel.com 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, fitting of the node and its alignment are still correct. 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 | 183 +++++++++++++++++++++++++++ 2 files changed, 184 insertions(+) diff --git a/drivers/gpu/drm/selftests/drm_mm_selftests.h b/drivers/gpu/drm/selftests/drm_mm_selftests.h index a7cceeb21356..408083b54177 100644 --- a/drivers/gpu/drm/selftests/drm_mm_selftests.h +++ b/drivers/gpu/drm/selftests/drm_mm_selftests.h @@ -5,6 +5,7 @@ * * Tests are executed in reverse order by igt/drm_mm */ +selftest(color, igt_color) selftest(topdown_align, igt_topdown_align) selftest(topdown, igt_topdown) 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 078511c76efb..0fe5344fe789 100644 --- a/drivers/gpu/drm/selftests/test-drm_mm.c +++ b/drivers/gpu/drm/selftests/test-drm_mm.c @@ -1403,6 +1403,189 @@ static int igt_topdown_align(void *ignored) return ret; } +static void no_color_touching(struct drm_mm_node *node, + unsigned long color, + u64 *start, + u64 *end) +{ + if (node->allocated && node->color != color) + ++*start; + + node = list_next_entry(node, node_list); + if (node->allocated && node->color != color) + --*end; +} + +static int igt_color(void *ignored) +{ + const int count = 4096; + struct drm_mm mm; + struct drm_mm_node *node, *nn; + const struct modes { + const char *name; + unsigned int search; + unsigned int create; + } modes[] = { + { "default", DRM_MM_SEARCH_DEFAULT, DRM_MM_CREATE_DEFAULT }, + { "best", DRM_MM_SEARCH_BEST, DRM_MM_CREATE_DEFAULT }, + { "top-down", DRM_MM_SEARCH_BELOW, DRM_MM_CREATE_TOP }, + }; + int ret = -EINVAL; + int n, m; + + drm_mm_init(&mm, 0, ~0ull); + + for (n = 1; n <= count; n++) { + int err; + + node = kzalloc(sizeof(*node), GFP_KERNEL); + if (!node) { + ret = -ENOMEM; + goto out; + } + + err = drm_mm_insert_node_generic(&mm, node, n, 0, n, + DRM_MM_SEARCH_DEFAULT, + DRM_MM_CREATE_DEFAULT); + if (err) { + pr_err("insert failed, step %d\n", n); + kfree(node); + ret = err; + goto out; + } + } + + drm_mm_for_each_node_safe(node, nn, &mm) { + if (node->color != node->size) { + pr_err("invalid color stored: expected %lld, found %ld\n", + node->size, node->color); + + goto out; + } + + drm_mm_remove_node(node); + kfree(node); + } + + /* Now, let's start experimenting with applying a color callback */ + mm.color_adjust = no_color_touching; + for (m = 0; m < ARRAY_SIZE(modes); m++) { + u64 last; + int err; + + node = kzalloc(sizeof(*node), GFP_KERNEL); + if (!node) { + ret = -ENOMEM; + goto out; + } + + node->size = 1 + 2*count; + node->color = node->size; + + err = drm_mm_reserve_node(&mm, node); + if (err) { + pr_err("initial reserve failed!\n"); + goto out; + } + + last = node->start + node->size; + + for (n = 1; n <= count; n++) { + int rem; + + node = kzalloc(sizeof(*node), GFP_KERNEL); + if (!node) { + ret = -ENOMEM; + goto out; + } + + node->start = last; + node->size = n + count; + node->color = node->size; + + err = drm_mm_reserve_node(&mm, node); + if (err != -ENOSPC) { + pr_err("reserve %d did not report color overlap! err=%d\n", + n, err); + goto out; + } + + node->start += n + 1; + rem = node->start; + rem %= n + count; + node->start += n + count - rem; + + err = drm_mm_reserve_node(&mm, node); + if (err) { + pr_err("reserve %d failed, err=%d\n", n, err); + goto out; + } + + last = node->start + node->size; + } + + for (n = 1; n <= count; n++) { + node = kzalloc(sizeof(*node), GFP_KERNEL); + if (!node) { + ret = -ENOMEM; + goto out; + } + + err = drm_mm_insert_node_generic(&mm, node, n, n, n, + modes[m].search, + modes[m].create); + if (err) { + pr_err("%s insert failed, step %d, err=%d\n", + modes[m].name, n, err); + kfree(node); + ret = err; + goto out; + } + } + + drm_mm_for_each_node_safe(node, nn, &mm) { + u64 rem; + + if (node->color != node->size) { + pr_err("%s invalid color stored: expected %lld, found %ld\n", + modes[m].name, node->size, node->color); + + goto out; + } + + if (!node->hole_follows && + list_next_entry(node, node_list)->allocated) { + pr_err("%s colors abutt; %ld [%llx + %llx] is next to %ld [%llx + %llx]!\n", + modes[m].name, + node->color, node->start, node->size, + list_next_entry(node, node_list)->color, + list_next_entry(node, node_list)->start, + list_next_entry(node, node_list)->size); + goto out; + } + + div64_u64_rem(node->start, node->size, &rem); + if (rem) { + pr_err("%s colored node misaligned, start=%llx expected alignment=%lld [rem=%lld]\n", + modes[m].name, node->start, node->size, rem); + goto out; + } + + drm_mm_remove_node(node); + kfree(node); + } + } + + ret = 0; +out: + drm_mm_for_each_node_safe(node, nn, &mm) { + drm_mm_remove_node(node); + kfree(node); + } + drm_mm_takedown(&mm); + return ret; +} + #include "drm_selftest.c" static int __init test_drm_mm_init(void)