From patchwork Thu Dec 22 08:36:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9484539 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 F2401601D3 for ; Thu, 22 Dec 2016 08:44:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC9E227DE0 for ; Thu, 22 Dec 2016 08:44:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E1729281C3; Thu, 22 Dec 2016 08:44:11 +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 9F77327DE0 for ; Thu, 22 Dec 2016 08:44:11 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D1B3E6F1B2; Thu, 22 Dec 2016 08:44:06 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wj0-x241.google.com (mail-wj0-x241.google.com [IPv6:2a00:1450:400c:c01::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id 797DB6F171; Thu, 22 Dec 2016 08:37:01 +0000 (UTC) Received: by mail-wj0-x241.google.com with SMTP id hb5so1997672wjc.2; Thu, 22 Dec 2016 00:37:01 -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=lweeDh3ATz/K5ZTEnaF+BwPzIOJ6VCW51QYQuupImZE=; b=BxM7zpEUt536qMwz7mRVPaO6y36HhSdkyoi39ZlZhAesWJKir4zshFEErZjPIFqXhV 6qrpKVjc+bynZiCJhxpOW9SXl/P+VPAXriIw5+vDpw/6LuZLa5OMGoFPAyWw/MB2ZCno n9fgtjuwqrR/gWaQEtz9mNZg68Q7ba/JHUyRo2LsNTE1LLIrng7jF0MyLzYPuSJIpEvY Gv3WNB+n8gr/esLl7gyO8J73dJdsJLQscIXtu534eHvw+4YPfY35Dapu2vfNh6MyC7Ix ah8ysEQm4KXIIahS1lVZSZzTtKu31IJCvPe5miuvWErxTz+vsxPjN6iImMUmLRkzGu7y H7bA== 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=lweeDh3ATz/K5ZTEnaF+BwPzIOJ6VCW51QYQuupImZE=; b=CZem2DSgbM9YZiSkay5zbVofiWLO43l6I2792l7iygoU85H/SC/+F68SUng9xccMpE xKUcLnJXoox6BoYGQAL4MwJYQNgBj2CKjBfmcC6Pe1sQTcQKngPJVE8g4y4AsJEh1ng0 YUARZutQG2sb9PWuXHocJ5ZT7QT7Wx94I1wY7VAU/SFWsZhlEnWPFATv8zsdVXcpkSJi KXekfrFY/f93lpTIm97z2VuNTdWJbYtUFOLbf8kinob00mCG5R4ulJo+ktGZ6exWNpfT agg/BOiHQbU9PYRwKgEfnkQCYzPUOxYET+jaBZNFXtuCZRjWo7eIE0fGI57Z/1FMttkY qeRA== X-Gm-Message-State: AIkVDXLMBYkMzi24F1weWh4dBNnZrKz2Dyae9EKtBuMjhtbfEWI3Ft+lBo1yRC3sdQenBg== X-Received: by 10.194.89.40 with SMTP id bl8mr7775682wjb.214.1482395819479; Thu, 22 Dec 2016 00:36:59 -0800 (PST) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id di9sm34442318wjc.37.2016.12.22.00.36.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Dec 2016 00:36:58 -0800 (PST) From: Chris Wilson To: dri-devel@lists.freedesktop.org Subject: [PATCH v4 13/38] drm: kselftest for drm_mm and alignment Date: Thu, 22 Dec 2016 08:36:16 +0000 Message-Id: <20161222083641.2691-14-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20161222083641.2691-1-chris@chris-wilson.co.uk> References: <20161222083641.2691-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 afc9274d8086..53ba268e07d9 100644 --- a/drivers/gpu/drm/selftests/test-drm_mm.c +++ b/drivers/gpu/drm/selftests/test-drm_mm.c @@ -1007,6 +1007,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_from(prime, 1, 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 - 2); + + 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)