From patchwork Tue Aug 16 10:42:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9283273 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 24007607FD for ; Tue, 16 Aug 2016 10:43:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 14620285CC for ; Tue, 16 Aug 2016 10:43:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0949A285D2; Tue, 16 Aug 2016 10:43:28 +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 A71D2285CC for ; Tue, 16 Aug 2016 10:43:27 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E5F196E66C; Tue, 16 Aug 2016 10:43:26 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wm0-x243.google.com (mail-wm0-x243.google.com [IPv6:2a00:1450:400c:c09::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id 25AF76E668 for ; Tue, 16 Aug 2016 10:43:23 +0000 (UTC) Received: by mail-wm0-x243.google.com with SMTP id q128so15688407wma.1 for ; Tue, 16 Aug 2016 03:43:23 -0700 (PDT) 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=+dGhVLPmmzUFORi8MMHIy/XR6vllNwXYm7eW76AkPNI=; b=r/Cbp84Bmk9rECZsQolQQxm+MwWk2nvBRU/w5SfJNlyniOTTayAE/YnMjBiN2lwUco YfrKFDr9wGbpS9JP6QR8ZOKzlk836HKzSqEhqnvLqf9bxk7uCaSliTIlTNUXy3qJd9nw PR0d/O0xXaS7qybQ9+lH6ns+U/im3tXiqnSn/rH6x6Fi1hV3xXIbXaK0GFZJj6d5dnWx uigaf5ebj0Ht55ANLnbeqcw8gJ2ml+G0kBFbOGLakEiOmifP5LdVafJTTkupYR7QRW0q ahj7XkGLPj+7JCNvQ3qLn7B5htPqmxGAD5A+we31LZ2Sk7a+z+aV9UOWwhGygbWKOK5U 73oQ== 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=+dGhVLPmmzUFORi8MMHIy/XR6vllNwXYm7eW76AkPNI=; b=E/eMQ1UKTn+tlAGlbW2xqGLbZL80JQKHElCtbN47XCbNuYPu9/gLEVWobcayZ2UULU 0BOfKO1XU1KLBOwcXi6qMNDzG5LX6Ek/KMup3juWIai9spOtHYAIniugwPc6+aTbaGBJ //zFl3VHStZQ7SkfTu9G4xraboC70z98GycYUXLlcrHwQPpAg0ljXd5Rsgr/GRYGsD07 Be1V31U3SDSfsArMsVtBm0kPXBUomv8GGgZN3H4vXyzxiINP5OcA9HJWv5fhQUizP8AQ DoP5LxFlPPnuQh1BY5z4uI4zbEr5ZeEoVN/v6sdqsMnBXLwP+gsdBWOezjJUkwE8ZzQC roDw== X-Gm-Message-State: AEkoouv1x9LPnBgJ8e9cffzfPwYp4QgqZ/lrZTDkLjNQ9jsqdvl84CQkdo1SQ9EQY7aKcw== X-Received: by 10.194.107.33 with SMTP id gz1mr42805173wjb.178.1471344201755; Tue, 16 Aug 2016 03:43:21 -0700 (PDT) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id d62sm21175546wmd.7.2016.08.16.03.43.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Aug 2016 03:43:20 -0700 (PDT) From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Tue, 16 Aug 2016 11:42:44 +0100 Message-Id: <1471344168-28136-19-git-send-email-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1471344168-28136-1-git-send-email-chris@chris-wilson.co.uk> References: <1471344168-28136-1-git-send-email-chris@chris-wilson.co.uk> Subject: [Intel-gfx] [PATCH 18/22] drm/i915: Choose not to evict faultable objects from the GGTT 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 Often times we do not want to evict mapped objects from the GGTT as these are quite expensive to teardown and frequently reused (causing an equally, if not more so, expensive setup). In particular, when faulting in a new object we want to avoid evicting an active object, or else we may trigger a page-fault-of-doom as we ping-pong between evicting two objects. Signed-off-by: Chris Wilson Reviewed-by: Joonas Lahtinen --- drivers/gpu/drm/i915/i915_gem.c | 18 ++++++++++++++++-- drivers/gpu/drm/i915/i915_gem_evict.c | 7 +++++-- drivers/gpu/drm/i915/i915_gem_gtt.h | 1 + 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index 74ea0926ad70..e28d283256f0 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -1700,6 +1700,7 @@ int i915_gem_fault(struct vm_area_struct *area, struct vm_fault *vmf) struct i915_vma *vma; pgoff_t page_offset; unsigned long pfn; + unsigned int flags; int ret; /* We don't use vmf->pgoff since that has the fake offset */ @@ -1729,9 +1730,16 @@ int i915_gem_fault(struct vm_area_struct *area, struct vm_fault *vmf) goto err_unlock; } + /* If the object is smaller than a couple of partial vma, it is + * not worth only creating a single partial vma - we may as well + * clear enough space for the full object. + */ + flags = PIN_MAPPABLE; + if (obj->base.size > 2 * MIN_CHUNK_PAGES << PAGE_SHIFT) + flags |= PIN_NONBLOCK | PIN_NONFAULT; + /* Now pin it into the GTT as needed */ - vma = i915_gem_object_ggtt_pin(obj, NULL, 0, 0, - PIN_MAPPABLE | PIN_NONBLOCK); + vma = i915_gem_object_ggtt_pin(obj, NULL, 0, 0, flags); if (IS_ERR(vma)) { struct i915_ggtt_view partial; unsigned int chunk_size; @@ -1751,6 +1759,12 @@ int i915_gem_fault(struct vm_area_struct *area, struct vm_fault *vmf) (area->vm_end - area->vm_start) / PAGE_SIZE - partial.params.partial.offset); + /* If the partial covers the entire object, just create a + * normal VMA. + */ + if (chunk_size <= obj->base.size >> PAGE_SHIFT) + partial.type = I915_GGTT_VIEW_NORMAL; + vma = i915_gem_object_ggtt_pin(obj, &partial, 0, 0, PIN_MAPPABLE); } diff --git a/drivers/gpu/drm/i915/i915_gem_evict.c b/drivers/gpu/drm/i915/i915_gem_evict.c index f76c06e92677..815d5fbe07ac 100644 --- a/drivers/gpu/drm/i915/i915_gem_evict.c +++ b/drivers/gpu/drm/i915/i915_gem_evict.c @@ -47,7 +47,7 @@ gpu_is_idle(struct drm_i915_private *dev_priv) } static bool -mark_free(struct i915_vma *vma, struct list_head *unwind) +mark_free(struct i915_vma *vma, unsigned int flags, struct list_head *unwind) { if (i915_vma_is_pinned(vma)) return false; @@ -55,6 +55,9 @@ mark_free(struct i915_vma *vma, struct list_head *unwind) if (WARN_ON(!list_empty(&vma->exec_list))) return false; + if (flags & PIN_NONFAULT && vma->obj->fault_mappable) + return false; + list_add(&vma->exec_list, unwind); return drm_mm_scan_add_block(&vma->node); } @@ -129,7 +132,7 @@ search_again: phase = phases; do { list_for_each_entry(vma, *phase, vm_link) - if (mark_free(vma, &eviction_list)) + if (mark_free(vma, flags, &eviction_list)) goto found; } while (*++phase); diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.h b/drivers/gpu/drm/i915/i915_gem_gtt.h index 4b67347834b5..52fded446390 100644 --- a/drivers/gpu/drm/i915/i915_gem_gtt.h +++ b/drivers/gpu/drm/i915/i915_gem_gtt.h @@ -639,6 +639,7 @@ void i915_gem_gtt_finish_object(struct drm_i915_gem_object *obj); #define PIN_NONBLOCK BIT(0) #define PIN_MAPPABLE BIT(1) #define PIN_ZONE_4G BIT(2) +#define PIN_NONFAULT BIT(3) #define PIN_MBZ BIT(5) /* I915_VMA_PIN_OVERFLOW */ #define PIN_GLOBAL BIT(6) /* I915_VMA_GLOBAL_BIND */