From patchwork Mon Dec 12 11:53:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9470595 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 0713060760 for ; Mon, 12 Dec 2016 11:56:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE13F28472 for ; Mon, 12 Dec 2016 11:56:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E2C7D28478; Mon, 12 Dec 2016 11:56:31 +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 A324E28472 for ; Mon, 12 Dec 2016 11:56:31 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7C3DC6E2D6; Mon, 12 Dec 2016 11:55:03 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@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 CB8F46E2DB; Mon, 12 Dec 2016 11:54:14 +0000 (UTC) Received: by mail-wm0-x244.google.com with SMTP id m203so10708201wma.3; Mon, 12 Dec 2016 03:54:14 -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=HFIIROposadToyImyas4tAYRPXO8L2cbfOC6GfU/uUo=; b=Ip69BE2jpYD4SBUZ7/bgDpJFUvQAbHrrnksjqA/ogjSHW0m+GPtOP/z97+tSIL6V5h bczdePJXYVZ+j79G+IFSKX1vIncsApRtB6ObhuYb2klQ/Wq1u0ip6y+wUxpiHECzOMK/ PtSwRmeCuHV2XZhKCTBjgsLDJR8uEceRQ/nQoo6JqOwOAOptRAF5HfAxNZNk3UJGSVcj J7CIql33g8ozSriuyhO42ErlmEuN2mpKr5Wv8OiurXY9m/2EyCPT19/IbY6It2kAP5z7 B6+WXChDzVDJyjJBbXlDSg9HLvV4YvhNEok5ZnESK9aTdqQW1vql5R2czKbVe//33QUX ZK2A== 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=HFIIROposadToyImyas4tAYRPXO8L2cbfOC6GfU/uUo=; b=WsXK01nsKhn6G2zucMcP0Usz/UKQjzGLLpvQE6kNURamKFZQzVSpRaoJE3M9urEJgo 5PLSzGPWtNj3AHhlZ0WjS4wTbMkexX04x3MY/yTH+67ENC+Kh8lVoBJxH4M8UIKACL0B uHwsQbNVABKZt+Ijz8sGw1uzfejpEvnPLCRtowzjL6wIrz1kjlpoBlIqKjVSSdJO9nzd 2UVMey9hYcQmJjhBhKQTM8nj4/DI+j1U/e74CNGoF2kgCMfkrOUg4XQVJlldOCdPumu5 eGQKn672qQW+aoWSNdyHMn+ovsaS0No9pnC5PlrhjIZ+9JitkNsUK9owWN7lxAuvAXgG E7jg== X-Gm-Message-State: AKaTC00I+o7qLKzKVJyAm4/3i3Ih9jwJ4xJlFsHGJS9tDcIE9Iupge3Dt/aCyRhOPBDxBw== X-Received: by 10.28.103.134 with SMTP id b128mr16648608wmc.54.1481543652833; Mon, 12 Dec 2016 03:54:12 -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.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Dec 2016 03:54:12 -0800 (PST) From: Chris Wilson To: dri-devel@lists.freedesktop.org Subject: [PATCH 16/34] drm: kselftest for drm_mm and top-down alignment Date: Mon, 12 Dec 2016 11:53:32 +0000 Message-Id: <20161212115350.780-17-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 if we request top-down allocation with a particular alignment from drm_mm_insert_node() that the start of the node 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 | 92 ++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) diff --git a/drivers/gpu/drm/selftests/drm_mm_selftests.h b/drivers/gpu/drm/selftests/drm_mm_selftests.h index 357fe430e36e..a7cceeb21356 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(topdown_align, igt_topdown_align) selftest(topdown, igt_topdown) selftest(evict_range, igt_evict_range) selftest(evict, igt_evict) diff --git a/drivers/gpu/drm/selftests/test-drm_mm.c b/drivers/gpu/drm/selftests/test-drm_mm.c index 22e7904cdaea..078511c76efb 100644 --- a/drivers/gpu/drm/selftests/test-drm_mm.c +++ b/drivers/gpu/drm/selftests/test-drm_mm.c @@ -1311,6 +1311,98 @@ static int igt_topdown(void *ignored) return ret; } +static int igt_topdown_align(void *ignored) +{ + struct drm_mm mm; + struct drm_mm_node tmp, resv; + int ret = -EINVAL; + int n, m, err; + + drm_mm_init(&mm, 0, ~0ull); + memset(&tmp, 0, sizeof(tmp)); + memset(&resv, 0, sizeof(resv)); + + for (m = 0; m < 32; m++) { + u64 end = ~0ull; + + if (m) { + resv.size = BIT_ULL(m); + end -= resv.size; + resv.start = end; + + err = drm_mm_reserve_node(&mm, &resv); + if (err) { + pr_err("reservation of sentinel node failed\n"); + ret = err; + goto out; + } + } + + for (n = 0; n < 63 - m; n++) { + u64 align = BIT_ULL(n); + + err = drm_mm_insert_node_generic(&mm, &tmp, 1, align, 0, + DRM_MM_SEARCH_BELOW, + DRM_MM_CREATE_TOP); + drm_mm_remove_node(&tmp); + if (err) { + pr_err("insert failed, ret=%d\n", err); + ret = err; + goto out; + } + + if (tmp.start & (align - 1)) { + pr_err("insert alignment failed, aligment=%llx, start=%llx\n", + align, tmp.start); + goto out; + } + + if (tmp.start < end - align) { + pr_err("topdown insert failed, start=%llx, align=%llx, end=%llx\n", + tmp.start, align, end); + goto out; + } + } + + drm_for_each_prime(n, min(8192ull, end - 1)) { + u64 rem; + + err = drm_mm_insert_node_generic(&mm, &tmp, 1, n, 0, + DRM_MM_SEARCH_BELOW, + DRM_MM_CREATE_TOP); + drm_mm_remove_node(&tmp); + if (err) { + pr_err("insert failed, ret=%d\n", err); + ret = err; + goto out; + } + + div64_u64_rem(tmp.start, n, &rem); + if (rem) { + pr_err("insert alignment failed, aligment=%d, start=%llx (offset %d)\n", + n, tmp.start, (int)rem); + goto out; + } + + if (tmp.start < end - n) { + pr_err("topdown insert failed, start=%llx, align=%d, end=%llx\n", + tmp.start, n, end); + goto out; + } + } + + if (resv.allocated) + drm_mm_remove_node(&resv); + } + + ret = 0; +out: + if (resv.allocated) + drm_mm_remove_node(&resv); + drm_mm_takedown(&mm); + return ret; +} + #include "drm_selftest.c" static int __init test_drm_mm_init(void)