From patchwork Mon Jan 11 11:01:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 8002461 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C5371BEEE5 for ; Mon, 11 Jan 2016 11:04:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B45BD202FE for ; Mon, 11 Jan 2016 11:04:15 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 7C116202F0 for ; Mon, 11 Jan 2016 11:04:14 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 14EF36E4A5; Mon, 11 Jan 2016 03:04:11 -0800 (PST) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com [74.125.82.67]) by gabe.freedesktop.org (Postfix) with ESMTPS id 766DE6E475 for ; Mon, 11 Jan 2016 03:02:08 -0800 (PST) Received: by mail-wm0-f67.google.com with SMTP id b14so25766174wmb.1 for ; Mon, 11 Jan 2016 03:02:08 -0800 (PST) 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=y/BmTEdncB4xbrDlqhe2s7W+WiKPmUubBeYjzK20ByQ=; b=lYH+rvrjzRSynf59W/Bk28+qE64tnuEGYU8VE1Yaoc2hzGN/Qiaik+MhQ2dxu0MgUW H75Y13XHM1OrNfwxeTDn7gdFtkpbnq4E9oUyQpkWyE7i2PoeBP2Gcng2LAWKWFl80a8a PvQCJ+SZvh9+Sj2hJK8IIX2BkrFxdIB6MrXsu7oId1JFrrthqP4mY88Q9afZ7O8Heh2P uUf98RYKuMISuDFtQcLlC8QvPuatXTOap7npKJTkHvRsBu4Tb8wKjrzuJIDxw0gG0DRL AGheiX/iAAaIUpwL5w7CfXXKFkeiMoX1Qgh5JDhKWdUdU6FXlp5+UYixLE9KcV5hkCoE 5OJA== X-Received: by 10.28.54.209 with SMTP id y78mr13712013wmh.26.1452510127171; Mon, 11 Jan 2016 03:02:07 -0800 (PST) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id 73sm12311579wmm.7.2016.01.11.03.02.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 11 Jan 2016 03:02:06 -0800 (PST) From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Mon, 11 Jan 2016 11:01:04 +0000 Message-Id: <1452510091-6833-22-git-send-email-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.7.0.rc3 In-Reply-To: <1452510091-6833-1-git-send-email-chris@chris-wilson.co.uk> References: <1452503961-14837-1-git-send-email-chris@chris-wilson.co.uk> <1452510091-6833-1-git-send-email-chris@chris-wilson.co.uk> Subject: [Intel-gfx] [PATCH 163/190] drm/i915: Fix i915_gem_evict_for_vma (soft-pinning) 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-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Soft-pinning depends upon being able to check for availabilty of an inverval and evict overlapping object fro a drm_mm range manager very quickly. Currently it uses a linear list which makes performance dire, and softpinning not a suitable replacement. It also helps if the routine reports the correct error codes as expected by its callers and emits a tracepoint upon use. For posterity since the wrong patch was pushed (i.e. that missed these key points), this is the changelog that should have been on commit 506a8e87d8d2746b9e9d2433503fe237c54e4750 Author: Chris Wilson Date: Tue Dec 8 11:55:07 2015 +0000 drm/i915: Add soft-pinning API for execbuffer Userspace can pass in an offset that it presumes the object is located at. The kernel will then do its utmost to fit the object into that location. The assumption is that userspace is handling its own object locations (for example along with full-ppgtt) and that the kernel will rarely have to make space for the user's requests. This extends the DRM_IOCTL_I915_GEM_EXECBUFFER2 to do the following: * if the user supplies a virtual address via the execobject->offset *and* sets the EXEC_OBJECT_PINNED flag in execobject->flags, then that object is placed at that offset in the address space selected by the context specifier in execbuffer. * the location must be aligned to the GTT page size, 4096 bytes * as the object is placed exactly as specified, it may be used by this execbuffer call without relocations pointing to it It may fail to do so if: * EINVAL is returned if the object does not have a 4096 byte aligned address * the object conflicts with another pinned object (either pinned by hardware in that address space, e.g. scanouts in the aliasing ppgtt) or within the same batch. EBUSY is returned if the location is pinned by hardware EINVAL is returned if the location is already in use by the batch * EINVAL is returned if the object conflicts with its own alignment (as meets the hardware requirements) or if the placement of the object does not fit within the address space All other execbuffer errors apply. Presence of this execbuf extension may be queried by passing I915_PARAM_HAS_EXEC_SOFTPIN to DRM_IOCTL_I915_GETPARAM and checking for a reported value of 1 (or greater). Signed-off-by: Chris Wilson --- drivers/gpu/drm/i915/i915_drv.h | 2 +- drivers/gpu/drm/i915/i915_gem.c | 2 +- drivers/gpu/drm/i915/i915_gem_evict.c | 69 ++++++++++++++++++++++------------- drivers/gpu/drm/i915/i915_trace.h | 23 ++++++++++++ 4 files changed, 69 insertions(+), 27 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index addd33bbc847..62a024a7225b 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -3052,7 +3052,7 @@ int __must_check i915_gem_evict_something(struct drm_device *dev, unsigned long start, unsigned long end, unsigned flags); -int __must_check i915_gem_evict_for_vma(struct i915_vma *target); +int __must_check i915_gem_evict_for_vma(struct i915_vma *vma, unsigned flags); int i915_gem_evict_vm(struct i915_address_space *vm, bool do_idle); /* belongs in i915_gem_gtt.h */ diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index 962fd81ce26c..497b68849d09 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -2813,7 +2813,7 @@ i915_vma_insert(struct i915_vma *vma, vma->node.color = obj->cache_level; ret = drm_mm_reserve_node(&vma->vm->mm, &vma->node); if (ret) { - ret = i915_gem_evict_for_vma(vma); + ret = i915_gem_evict_for_vma(vma, flags); if (ret == 0) ret = drm_mm_reserve_node(&vma->vm->mm, &vma->node); if (ret) diff --git a/drivers/gpu/drm/i915/i915_gem_evict.c b/drivers/gpu/drm/i915/i915_gem_evict.c index fdc4941be15a..b48839fc2996 100644 --- a/drivers/gpu/drm/i915/i915_gem_evict.c +++ b/drivers/gpu/drm/i915/i915_gem_evict.c @@ -229,42 +229,61 @@ found: } int -i915_gem_evict_for_vma(struct i915_vma *target) +i915_gem_evict_for_vma(struct i915_vma *target, unsigned flags) { - struct drm_mm_node *node, *next; + struct list_head eviction_list; + struct drm_mm_node *node; + u64 end = target->node.start + target->node.size; + struct i915_vma *vma, *next; + int ret; - list_for_each_entry_safe(node, next, - &target->vm->mm.head_node.node_list, - node_list) { - struct i915_vma *vma; - int ret; + trace_i915_gem_evict_vma(target, flags); - if (node->start + node->size <= target->node.start) - continue; - if (node->start >= target->node.start + target->node.size) - break; + node = drm_mm_interval_first(&target->vm->mm, + target->node.start, end - 1); + if (node == NULL) + return 0; - vma = container_of(node, typeof(*vma), node); + INIT_LIST_HEAD(&eviction_list); + vma = container_of(node, typeof(*vma), node); + list_for_each_entry_from(vma, + &target->vm->mm.head_node.node_list, + node.node_list) { + if (vma->node.start >= end) + break; - if (vma->pin_count) { - if (!vma->exec_entry || (vma->pin_count > 1)) - /* Object is pinned for some other use */ - return -EBUSY; + if (flags & PIN_NONBLOCK && (vma->pin_count | vma->active)) { + ret = -ENOSPC; + break; + } - /* We need to evict a buffer in the same batch */ - if (vma->exec_entry->flags & EXEC_OBJECT_PINNED) - /* Overlapping fixed objects in the same batch */ - return -EINVAL; + if (vma->exec_entry && + vma->exec_entry->flags & EXEC_OBJECT_PINNED) { + /* Overlapping pinned objects in the same batch */ + ret = -EINVAL; + break; + } - return -ENOSPC; + if (vma->pin_count) { + /* We may need to evict an buffer in the same batch */ + ret = vma->exec_entry ? -ENOSPC : -EBUSY; + break; } - ret = i915_vma_unbind(vma); - if (ret) - return ret; + list_add(&vma->exec_list, &eviction_list); + drm_gem_object_reference(&vma->obj->base); } - return 0; + ret = 0; + list_for_each_entry_safe(vma, next, &eviction_list, exec_list) { + struct drm_i915_gem_object *obj = vma->obj; + list_del_init(&vma->exec_list); + if (ret == 0) + ret = i915_vma_unbind(vma); + drm_gem_object_unreference(&obj->base); + } + + return ret; } /** diff --git a/drivers/gpu/drm/i915/i915_trace.h b/drivers/gpu/drm/i915/i915_trace.h index e486dcef508d..396943fa53ea 100644 --- a/drivers/gpu/drm/i915/i915_trace.h +++ b/drivers/gpu/drm/i915/i915_trace.h @@ -448,6 +448,29 @@ TRACE_EVENT(i915_gem_evict_vm, TP_printk("dev=%d, vm=%p", __entry->dev, __entry->vm) ); +TRACE_EVENT(i915_gem_evict_vma, + TP_PROTO(struct i915_vma *vma, unsigned flags), + TP_ARGS(vma, flags), + + TP_STRUCT__entry( + __field(u32, dev) + __field(struct i915_address_space *, vm) + __field(u64, start) + __field(u64, size) + __field(unsigned, flags) + ), + + TP_fast_assign( + __entry->dev = vma->vm->dev->primary->index; + __entry->vm = vma->vm; + __entry->start = vma->node.start; + __entry->size = vma->node.size; + __entry->flags = flags; + ), + + TP_printk("dev=%d, vm=%p, start=%llx size=%llx, flags=%x", __entry->dev, __entry->vm, (long long)__entry->start, (long long)__entry->size, __entry->flags) +); + TRACE_EVENT(i915_gem_ring_sync_to, TP_PROTO(struct drm_i915_gem_request *to, struct drm_i915_gem_request *from),