From patchwork Fri Dec 16 19:25:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9478401 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 77CCE601C2 for ; Fri, 16 Dec 2016 19:30:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6816F28772 for ; Fri, 16 Dec 2016 19:30:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5B73B287DB; Fri, 16 Dec 2016 19:30:24 +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 0248228772 for ; Fri, 16 Dec 2016 19:30:24 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 941BD6ED17; Fri, 16 Dec 2016 19:30:06 +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 395C76ECD7; Fri, 16 Dec 2016 19:26:15 +0000 (UTC) Received: by mail-wm0-x244.google.com with SMTP id g23so7267760wme.1; Fri, 16 Dec 2016 11:26:15 -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=eujFLWigFUFkpnSWWamY8A4jdzyMMNgjSVnw7Cj63Pc=; b=pS7piOrwO65dVDFD9P0gjVfqgAGIm9iNaYyeXBLdVlgGM3mCInTTduSW5P0K8IuvVx dbXMjqOQFcR7M6G8A1beNTbBze6p0b34h9PGORAYtwtRYB0oL5Xy0F3pvfCphugLc0ls /bPN4IAWgxdlnq8Oih5mHUn/z2bslaPBTskcTXZvkr8+/WMbKyZLczBejBoUFpsXB4Lb o2OmXEDuWNQGJ3ubLxye/lPPhL0eU8dnPqMuDibNoEPcfyEnBR87WA8SUmTCDaXFpuF7 SftD8jqzf6RFGKSystODJq/KV1u36mXUOR+HRzXYYCuHldf7hf075qE0CCaQiBoXgz2L ughw== 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=eujFLWigFUFkpnSWWamY8A4jdzyMMNgjSVnw7Cj63Pc=; b=taTV9KF/dFP4cynZo6hUnqtwafZZrAL1BILttenmi5YVy89EcBzuzv3+ycQg6vNKxq LCB7tuKOYAzOQ15SBSmE/n7fF69r76OnW6EymgJTbSTlk0Ukil23XmdKcLg+jRsV9qoq C/brs0GIPmWcMpe7V9jdmiQKzsCwqhYkTFWUqY0Rb6W+CkzhEBLWA2OtYmrxZbYygRjH oldtpBwJc75Z4DtqooK37CoqbLcpigsZsKWzfhlpH4azGS0bkkpu0UQ5fu/ZelPj9ufk hPQeGiMZnBWbN8HUeIyMN9BUHp/e8HTE9y0Loaoz+A8un3KgwBFwT+4GNGyg+qXQOmQ4 70qA== X-Gm-Message-State: AIkVDXIKP2F/cJJlhOr6CH8+3C0qQ2yxSaru26XIDIbG8BKQ3paepMetks9yRQlBpbWRvg== X-Received: by 10.28.7.130 with SMTP id 124mr3921948wmh.18.1481916373350; Fri, 16 Dec 2016 11:26:13 -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.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Dec 2016 11:26:12 -0800 (PST) From: Chris Wilson To: dri-devel@lists.freedesktop.org Subject: [PATCH v3 19/38] drm: kselftest for drm_mm and restricted color eviction Date: Fri, 16 Dec 2016 19:25:31 +0000 Message-Id: <20161216192550.8352-20-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 after applying the driver's color adjustment, restricted 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 | 116 ++++++++++++++++++++++++++- 2 files changed, 113 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/selftests/drm_mm_selftests.h b/drivers/gpu/drm/selftests/drm_mm_selftests.h index 0a3a7e32e5f7..6a4575fdc1c0 100644 --- a/drivers/gpu/drm/selftests/drm_mm_selftests.h +++ b/drivers/gpu/drm/selftests/drm_mm_selftests.h @@ -20,3 +20,4 @@ selftest(evict_range, igt_evict_range) selftest(topdown, igt_topdown) selftest(color, igt_color) selftest(color_evict, igt_color_evict) +selftest(color_evict_range, igt_color_evict_range) diff --git a/drivers/gpu/drm/selftests/test-drm_mm.c b/drivers/gpu/drm/selftests/test-drm_mm.c index 9dd94da15bd5..7e90886f5558 100644 --- a/drivers/gpu/drm/selftests/test-drm_mm.c +++ b/drivers/gpu/drm/selftests/test-drm_mm.c @@ -1850,6 +1850,7 @@ static int igt_color(void *ignored) } static int evict_color(struct drm_mm *mm, + u64 range_start, u64 range_end, struct evict_node *nodes, unsigned int *order, unsigned int count, @@ -1863,7 +1864,9 @@ static int evict_color(struct drm_mm *mm, struct drm_mm_node tmp; int err; - drm_mm_init_scan(mm, size, alignment, color); + drm_mm_init_scan_with_range(mm, + size, alignment, color, + range_start, range_end); if (!evict_nodes(mm, nodes, order, count, &evict_list)) @@ -1881,6 +1884,12 @@ static int evict_color(struct drm_mm *mm, return err; } + if (tmp.start < range_start || tmp.start + tmp.size > range_end) { + pr_err("Inserted [address=%llu + %llu] did not fit into the request range [%llu, %llu]\n", + tmp.start, tmp.size, range_start, range_end); + err = -EINVAL; + } + if (colors_abutt(&tmp)) err = -EINVAL; @@ -1949,7 +1958,7 @@ static int igt_color_evict(void *ignored) 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, + err = evict_color(&mm, 0, U64_MAX, nodes, order, total_size, n, 1, color++, mode); @@ -1962,7 +1971,7 @@ static int igt_color_evict(void *ignored) for (n = 1; n < total_size; n <<= 1) { drm_random_reorder(order, total_size, &prng); - err = evict_color(&mm, + err = evict_color(&mm, 0, U64_MAX, nodes, order, total_size, total_size/2, n, color++, mode); @@ -1979,7 +1988,7 @@ static int igt_color_evict(void *ignored) DRM_MM_BUG_ON(!nsize); drm_random_reorder(order, total_size, &prng); - err = evict_color(&mm, + err = evict_color(&mm, 0, U64_MAX, nodes, order, total_size, nsize, n, color++, mode); @@ -2005,6 +2014,105 @@ static int igt_color_evict(void *ignored) return ret; } +static int igt_color_evict_range(void *ignored) +{ + DRM_RND_STATE(prng, random_seed); + const unsigned int total_size = 8192; + const unsigned int range_size = total_size / 2; + const unsigned int range_start = total_size / 4; + const unsigned int range_end = range_start + range_size; + 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; + + /* Like igt_color_evict(), but limited to small portion of the full + * drm_mm range. + */ + + 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++) { + if (!expect_insert(&mm, &nodes[n].node, + 1, 0, color++, + &insert_modes[0])) { + pr_err("insert failed, step %d\n", n); + goto out; + } + } + + for (mode = evict_modes; mode->name; mode++) { + for (n = 1; n <= range_size; n <<= 1) { + drm_random_reorder(order, range_size, &prng); + err = evict_color(&mm, range_start, range_end, + nodes, order, total_size, + n, 1, color++, + mode); + if (err) { + pr_err("%s evict_color(size=%u) failed for range [%x, %x]\n", + mode->name, n, range_start, range_end); + goto out; + } + } + + for (n = 1; n < range_size; n <<= 1) { + drm_random_reorder(order, total_size, &prng); + err = evict_color(&mm, range_start, range_end, + nodes, order, total_size, + range_size/2, n, color++, + mode); + if (err) { + pr_err("%s evict_color(size=%u, alignment=%u) failed for range [%x, %x]\n", + mode->name, total_size/2, n, range_start, range_end); + goto out; + } + } + + for_each_prime_number(n, min(range_size, max_prime)) { + unsigned int nsize = (range_size - n + 1) / 2; + + DRM_MM_BUG_ON(!nsize); + + drm_random_reorder(order, total_size, &prng); + err = evict_color(&mm, range_start, range_end, + nodes, order, total_size, + nsize, n, color++, + mode); + if (err) { + pr_err("%s evict_color(size=%u, alignment=%u) failed for range [%x, %x]\n", + mode->name, nsize, n, range_start, range_end); + 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)