From patchwork Wed Jan 11 21:09:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9511439 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 3847460710 for ; Wed, 11 Jan 2017 21:11:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2B83A28655 for ; Wed, 11 Jan 2017 21:11:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2052328696; Wed, 11 Jan 2017 21:11:07 +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=ham 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 BE90A28655 for ; Wed, 11 Jan 2017 21:11:06 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D514B6EA2D; Wed, 11 Jan 2017 21:10:20 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@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 8E0BF6EA80 for ; Wed, 11 Jan 2017 21:10:16 +0000 (UTC) Received: by mail-wm0-x244.google.com with SMTP id l2so815011wml.2 for ; Wed, 11 Jan 2017 13:10:16 -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=VsfL+l+6Dr654vetIDaGiSc4GdNgZOMEC1W5PbM9EHE=; b=kfAGcmz5j/h+oj/eFBQLFhVTN87zSVAAd15XnZgdoz6n5N8hFOoIyvD8e5RnQ9FTEo NJaQn5kymAdHbYD7ZusMnkBo+WYszvVYZCycMPaixiVjVRak1tj9mcp5S023k5z569Wl ySYcTLYhYpIAqRowTngl731yS6YAxmTEwUqdAcU2P0Chd4ci1OI4RmP5ur82+ATiRwWo +OSvGGuZeJX0qOBxZdtaFe7S0bbAaqKooMH3y6eohlLadwI5ysoYQd1U+/irEWZZ3PRT Ws1z1p8Wn8KRD0pQBsPjNbcDTKxRItReCTnof2NfHN3lrnzNrMbnHHo3gmms10dssZuh YcKA== 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=VsfL+l+6Dr654vetIDaGiSc4GdNgZOMEC1W5PbM9EHE=; b=KQgelP3AimTTkXL6tQCu6rS1fr81SNckfKMkIunBezfLT4HKU1JPqsjqtrpZf6i9oo amuhc7k90gZa4oZya4OvQtCezF/QPHtZRJNzX4bP+6GD7Xo3yQRpfNuZZaObBmOFtu4D HbhYfsuPKyfCLaaiJsPUh9nuSqhKFQES1LDz1bewiLpm5F8teOghinhFSzNcRIBjoRNl emQV1obSlhLNKEw6RjpfpPNYY0zWZZAwEKPYXPhBit87G5RZrcBRQGrgvFAk6VDGguEg s5hw0EtUwVJVbQYDUf9J2Oi2PUEJXTykijGVTpwz4YW7UfH9oO4IcJqRrv+NhFy/uoFi KAZQ== X-Gm-Message-State: AIkVDXLPQeYYBWz9IhkVy9v0MPKLURaJ+XRsuNrd5PZaoP5mkx4N4ZstQYG7O3YhHOTnog== X-Received: by 10.223.160.213 with SMTP id n21mr5894578wrn.134.1484169014928; Wed, 11 Jan 2017 13:10:14 -0800 (PST) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id y4sm10354906wjp.0.2017.01.11.13.10.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jan 2017 13:10:13 -0800 (PST) From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Wed, 11 Jan 2017 21:09:30 +0000 Message-Id: <20170111210937.29252-31-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170111210937.29252-1-chris@chris-wilson.co.uk> References: <20170111210937.29252-1-chris@chris-wilson.co.uk> Subject: [Intel-gfx] [PATCH 30/37] drm/i915: Exercise filling and removing random ranges from the live GTT X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP Test the low-level i915_address_space interfaces to sanity check the live insertion/removal of address ranges. Signed-off-by: Chris Wilson --- drivers/gpu/drm/i915/selftests/i915_gem_gtt.c | 140 ++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) diff --git a/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c b/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c index 68f7bfb7502e..b20406631120 100644 --- a/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c +++ b/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c @@ -25,6 +25,7 @@ #include #include "i915_selftest.h" +#include "i915_random.h" #include "fake_drm.h" #include "huge_gem_object.h" @@ -290,6 +291,74 @@ static int walk_hole(struct drm_i915_private *i915, return err; } +static u64 scale(u64 offset, unsigned int shift) +{ + return offset << shift; +} + +static int random_hole(struct drm_i915_private *i915, + struct i915_address_space *vm, + u64 hole_start, u64 hole_end) +{ + I915_RND_STATE(prng); + unsigned int size; + + for (size = 12; (hole_end - hole_start) >> (size + 2); size++) { + I915_SELFTEST_TIMEOUT(end_time); + struct drm_i915_gem_object *obj; + unsigned int *order, count, n; + u64 hole_size; + + hole_size = (hole_end - hole_start) >> size; + if (hole_size > KMALLOC_MAX_SIZE / sizeof(u32)) + hole_size = KMALLOC_MAX_SIZE / sizeof(u32); + count = hole_size; + do { + count >>= 1; + order = i915_random_order(count, &prng); + } while (!order && count); + + obj = huge_gem_object(i915, PAGE_SIZE, scale(1, size)); + if (IS_ERR(obj)) + break; + + GEM_BUG_ON(obj->base.size != scale(1, size)); + + if (i915_gem_object_pin_pages(obj)) { + i915_gem_object_put(obj); + break; + } + + for (n = 0; n < count; n++) { + if (vm->allocate_va_range && + vm->allocate_va_range(vm, + scale(order[n], size), + scale(1, size))) + break; + + vm->insert_entries(vm, obj->mm.pages, + scale(order[n], size), + I915_CACHE_NONE, 0); + if (time_after(jiffies, end_time)) + break; + } + count = n; + + i915_random_reorder(order, count, &prng); + for (n = 0; n < count; n++) + vm->clear_range(vm, + scale(order[n], size), + scale(1, size)); + + i915_gem_object_unpin_pages(obj); + i915_gem_object_put(obj); + + kfree(order); + } + + return 0; +} + static int igt_ppgtt_fill(void *arg) { struct drm_i915_private *dev_priv = arg; @@ -356,6 +425,39 @@ static int igt_ppgtt_walk(void *arg) return err; } +static int igt_ppgtt_drunk(void *arg) +{ + struct drm_i915_private *dev_priv = arg; + struct drm_file *file; + struct i915_hw_ppgtt *ppgtt; + int err; + + if (!USES_FULL_PPGTT(dev_priv)) + return 0; + + file = fake_file(dev_priv); + if (IS_ERR(file)) + return PTR_ERR(file); + + mutex_lock(&dev_priv->drm.struct_mutex); + ppgtt = i915_ppgtt_create(dev_priv, file->driver_priv, "mock"); + if (IS_ERR(ppgtt)) { + err = PTR_ERR(ppgtt); + goto err_unlock; + } + GEM_BUG_ON(ppgtt->base.total & ~PAGE_MASK); + + err = random_hole(dev_priv, &ppgtt->base, 0, ppgtt->base.total); + + i915_ppgtt_close(&ppgtt->base); + i915_ppgtt_put(ppgtt); +err_unlock: + mutex_unlock(&dev_priv->drm.struct_mutex); + + fake_file_free(dev_priv, file); + return err; +} + static int igt_ggtt_fill(void *arg) { struct drm_i915_private *i915 = arg; @@ -428,12 +530,50 @@ static int igt_ggtt_walk(void *arg) return err; } +static int igt_ggtt_drunk(void *arg) +{ + struct drm_i915_private *i915 = arg; + struct i915_ggtt *ggtt = &i915->ggtt; + u64 hole_start = U64_MAX, hole_end = 0, hole_size = 0; + u64 this_start, this_end; + struct drm_mm_node *node; + int err; + + GEM_BUG_ON(ggtt->base.total & ~PAGE_MASK); + + mutex_lock(&i915->drm.struct_mutex); + drm_mm_for_each_hole(node, &ggtt->base.mm, this_start, this_end) { + u64 this_size; + + if (ggtt->base.mm.color_adjust) + ggtt->base. mm.color_adjust(node, 0, + &this_start, &this_end); + + this_size = this_end - this_start; + if (this_size > hole_size) { + hole_size = this_size; + hole_start = this_start; + hole_end = this_end; + } + } + pr_info("Found GGTT hole [%llx, %llx], size %llx\n", + hole_start, hole_end, hole_size); + GEM_BUG_ON(hole_start >= hole_end); + + err = random_hole(i915, &ggtt->base, hole_start, hole_end); + mutex_unlock(&i915->drm.struct_mutex); + + return err; +} + int i915_gem_gtt_live_selftests(struct drm_i915_private *i915) { static const struct i915_subtest tests[] = { SUBTEST(igt_ppgtt_alloc), + SUBTEST(igt_ppgtt_drunk), SUBTEST(igt_ppgtt_walk), SUBTEST(igt_ppgtt_fill), + SUBTEST(igt_ggtt_drunk), SUBTEST(igt_ggtt_walk), SUBTEST(igt_ggtt_fill), };