From patchwork Fri Dec 16 19:25:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9478431 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 D53DD601C2 for ; Fri, 16 Dec 2016 19:31:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C804428772 for ; Fri, 16 Dec 2016 19:31:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BCE0C287DB; Fri, 16 Dec 2016 19:31:30 +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 46E2928772 for ; Fri, 16 Dec 2016 19:31:30 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DE67F6ED0D; Fri, 16 Dec 2016 19:31:27 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x241.google.com (mail-wm0-x241.google.com [IPv6:2a00:1450:400c:c09::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id C82566ECD7; Fri, 16 Dec 2016 19:26:10 +0000 (UTC) Received: by mail-wm0-x241.google.com with SMTP id a20so7273937wme.2; Fri, 16 Dec 2016 11:26:10 -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=mROXh3fZPPatGoD84ejMwXfPcPEyMlAubcI9OQTYhsw=; b=Zw50s10JTUo/8Jfa03sOlqJ4mrxKujCwGrKVvhs4t6uiaw/4LoXB+AMWZVcpX4+6HB QtuGeo2L6T9ArP+qAU7p/p5iyChM76Xecr8psvDvR9zxxWPmlu48VgqH0n8/FsDsm2q9 2Ay3vTIgsSLcgF0PHlVOCOk7ctkBIvoZvCjCaSaV7bn8uI0JGs1WF+hDwoCBOQVLmbw/ qPw1U34GEGA2jIlh2XaWjxX8EThtUSXL2EUmxMAwcHlZ3pMH3W1ZV6sgVtHgNHKOEcs0 C1yHK0NBVn7kx2Ep2mxeKq5QBHbuZNXNcHu4SCOZeeLkOIBZsX38RPJP0flIzBB0RjZV 2PCA== 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=mROXh3fZPPatGoD84ejMwXfPcPEyMlAubcI9OQTYhsw=; b=cl8PaCwFIIct87wi341IIXDZdyQffNghuQHTleRUjzPqDDXWbyZpaIgu2/00CEHyG/ +1K7Fgz4gv4y+KlUGJmwY7PpjHPQrjhJIRVXM0j2gdP1PQULyCEA954oe6RU53ikJOWC TFOuXU0OBOGN4JQusVRUyH8YYbJdH0bP7bcNmA41JjrQYePgaL69vXvK7TB/20dsGdad qnxtDx/TEFD/IZQLXAWA+noSGP/Ffbe07xf/uXs0+HSBrxTQGBskYywWC0X2dwWiA0JK 6hR7Ju38CoX+5H0UAn39rsNFo2G5AWsOfunva1agANbJOO6MA07j3WQALGDJNZG0zP+3 +T2w== X-Gm-Message-State: AIkVDXK4y3Gz8p3j8+galPXN7OBxZpHmdQB0zMLezVczEzhKuBARyw3cG/imvkHFGIwXCw== X-Received: by 10.28.41.70 with SMTP id p67mr4463407wmp.4.1481916368367; Fri, 16 Dec 2016 11:26:08 -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.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Dec 2016 11:26:07 -0800 (PST) From: Chris Wilson To: dri-devel@lists.freedesktop.org Subject: [PATCH v3 13/38] drm: kselftest for drm_mm and alignment Date: Fri, 16 Dec 2016 19:25:25 +0000 Message-Id: <20161216192550.8352-14-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 can request alignment to any power-of-two or prime using a plain drm_mm_node_insert(), and also handle a reasonable selection of primes. v2: Exercise all allocation flags Signed-off-by: Chris Wilson Reviewed-by: Joonas Lahtinen --- drivers/gpu/drm/selftests/drm_mm_selftests.h | 3 + drivers/gpu/drm/selftests/test-drm_mm.c | 103 +++++++++++++++++++++++++++ 2 files changed, 106 insertions(+) diff --git a/drivers/gpu/drm/selftests/drm_mm_selftests.h b/drivers/gpu/drm/selftests/drm_mm_selftests.h index 92b2c1cb10fa..a7a3763f8b20 100644 --- a/drivers/gpu/drm/selftests/drm_mm_selftests.h +++ b/drivers/gpu/drm/selftests/drm_mm_selftests.h @@ -12,3 +12,6 @@ selftest(reserve, igt_reserve) selftest(insert, igt_insert) selftest(replace, igt_replace) selftest(insert_range, igt_insert_range) +selftest(align, igt_align) +selftest(align32, igt_align32) +selftest(align64, igt_align64) diff --git a/drivers/gpu/drm/selftests/test-drm_mm.c b/drivers/gpu/drm/selftests/test-drm_mm.c index cbd4f09e6b2f..e1c034ea7e73 100644 --- a/drivers/gpu/drm/selftests/test-drm_mm.c +++ b/drivers/gpu/drm/selftests/test-drm_mm.c @@ -1002,6 +1002,109 @@ static int igt_insert_range(void *ignored) return 0; } +static int igt_align(void *ignored) +{ + const struct insert_mode *mode; + const unsigned int max_count = min(8192u, max_prime); + struct drm_mm mm; + struct drm_mm_node *nodes, *node, *next; + unsigned int prime; + int ret = -EINVAL; + + /* For each of the possible insertion modes, we pick a few + * arbitrary alignments and check that the inserted node + * meets our requirements. + */ + + nodes = vzalloc(max_count * sizeof(*nodes)); + if (!nodes) + goto err; + + drm_mm_init(&mm, 1, U64_MAX - 2); + + for (mode = insert_modes; mode->name; mode++) { + unsigned int i = 0; + + for_each_prime_number(prime, max_count) { + u64 size = next_prime_number(prime); + + if (!expect_insert(&mm, &nodes[i], + size, prime, i, + mode)) { + pr_err("%s insert failed with alignment=%d", + mode->name, prime); + goto out; + } + + i++; + } + + drm_mm_for_each_node_safe(node, next, &mm) + drm_mm_remove_node(node); + DRM_MM_BUG_ON(!drm_mm_clean(&mm)); + } + + ret = 0; +out: + drm_mm_for_each_node_safe(node, next, &mm) + drm_mm_remove_node(node); + drm_mm_takedown(&mm); + vfree(nodes); +err: + return ret; +} + +static int igt_align_pot(int max) +{ + struct drm_mm mm; + struct drm_mm_node *node, *next; + int bit; + int ret = -EINVAL; + + /* Check that we can align to the full u64 address space */ + + drm_mm_init(&mm, 1, U64_MAX - 1); + + for (bit = max - 1; bit; bit--) { + u64 align, size; + + node = kzalloc(sizeof(*node), GFP_KERNEL); + if (!node) { + ret = -ENOMEM; + goto out; + } + + align = BIT_ULL(bit); + size = BIT_ULL(bit-1) + 1; + if (!expect_insert(&mm, node, + size, align, bit, + &insert_modes[0])) { + pr_err("insert failed with alignment=%llx [%d]", + align, bit); + goto out; + } + } + + ret = 0; +out: + drm_mm_for_each_node_safe(node, next, &mm) { + drm_mm_remove_node(node); + kfree(node); + } + drm_mm_takedown(&mm); + return ret; +} + +static int igt_align32(void *ignored) +{ + return igt_align_pot(32); +} + +static int igt_align64(void *ignored) +{ + return igt_align_pot(64); +} + #include "drm_selftest.c" static int __init test_drm_mm_init(void)