From patchwork Tue Mar 31 15:37:00 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 6131231 Return-Path: X-Original-To: patchwork-dri-devel@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 9902DBF4A6 for ; Tue, 31 Mar 2015 15:37:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7AC912015A for ; Tue, 31 Mar 2015 15:37:12 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 5962C20173 for ; Tue, 31 Mar 2015 15:37:10 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 57C966E6CF; Tue, 31 Mar 2015 08:37:09 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from pegasos-out.vodafone.de (pegasos-out.vodafone.de [80.84.1.38]) by gabe.freedesktop.org (Postfix) with ESMTP id 274056E6D1 for ; Tue, 31 Mar 2015 08:37:06 -0700 (PDT) Received: from localhost (localhost.localdomain [127.0.0.1]) by pegasos-out.vodafone.de (Rohrpostix2 Daemon) with ESMTP id 88E2062EC8E for ; Tue, 31 Mar 2015 17:37:05 +0200 (CEST) X-Virus-Scanned: amavisd-new at vodafone.de X-Spam-Score: 0.201 X-Spam-Level: X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, FREEMAIL_FROM,RCVD_IN_DNSWL_MED,T_DKIM_INVALID,T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Authentication-Results: rohrpostix2.prod.vfnet.de (amavisd-new); dkim=pass header.i=@vodafone.de Received: from pegasos-out.vodafone.de ([127.0.0.1]) by localhost (rohrpostix2.prod.vfnet.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id UQtvZmcTMgq5 for ; Tue, 31 Mar 2015 17:37:03 +0200 (CEST) Received: from smtp-05.vodafone.de (xsmail-dmz2.prod.vfnet.de [10.215.254.33]) by pegasos-out.vodafone.de (Rohrpostix2 Daemon) with ESMTP id BDE1962EC8B; Tue, 31 Mar 2015 17:37:03 +0200 (CEST) X-DKIM: OpenDKIM Filter v2.6.8 pegasos-out.vodafone.de BDE1962EC8B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vodafone.de; s=mail; t=1427816223; bh=MnXJQlLXtm4uFWo/BUqJBfj4na/rIeVF7hwmGHEwZc4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=3HSyNXQCeViUVjbq8DMLR4DOt0QrGvRqhXwmvFr2uEnQ0O4VpWFcWaicZ7c+hDDcK +uDs+swE35ASVkf9NZ+/rQaAWkKVYO+gZ6M1EPmfAuHJl3gp5thW3rfrIi6Ydv2AeN A2Ly+hRG4PYOmAe27TUkj5HjUt6yUvt4ge8dX1Lc= X-Virus-Scanned: amavisd-new at vodafone.de Received: from smtp-05.vodafone.de ([127.0.0.1]) by localhost (xsmail-dmz2.prod.vfnet.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id mCX4PWGBGylU; Tue, 31 Mar 2015 17:37:02 +0200 (CEST) From: =?UTF-8?q?Christian=20K=C3=B6nig?= To: alexdeucher@gmail.com Subject: [PATCH 4/4] drm/radeon: allow creating overlapping userptrs Date: Tue, 31 Mar 2015 17:37:00 +0200 Message-Id: <1427816220-1670-4-git-send-email-deathsimple@vodafone.de> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1427816220-1670-1-git-send-email-deathsimple@vodafone.de> References: <1427816220-1670-1-git-send-email-deathsimple@vodafone.de> MIME-Version: 1.0 Cc: serguei.sagalovitch@amd.com, dri-devel@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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Christian König Similar to the Intel implementation, but instead of just falling back to a global linear list when we have an overlapping userptr request we accumulate all overlapping userptrs in a local list. Signed-off-by: Christian König --- drivers/gpu/drm/radeon/radeon.h | 2 +- drivers/gpu/drm/radeon/radeon_mn.c | 102 +++++++++++++++++++++++++++---------- 2 files changed, 76 insertions(+), 28 deletions(-) diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h index 35ab65d..a0c272e 100644 --- a/drivers/gpu/drm/radeon/radeon.h +++ b/drivers/gpu/drm/radeon/radeon.h @@ -507,7 +507,7 @@ struct radeon_bo { pid_t pid; struct radeon_mn *mn; - struct interval_tree_node mn_it; + struct list_head mn_list; }; #define gem_to_radeon_bo(gobj) container_of((gobj), struct radeon_bo, gem_base) diff --git a/drivers/gpu/drm/radeon/radeon_mn.c b/drivers/gpu/drm/radeon/radeon_mn.c index 572b4db..0170137 100644 --- a/drivers/gpu/drm/radeon/radeon_mn.c +++ b/drivers/gpu/drm/radeon/radeon_mn.c @@ -53,6 +53,11 @@ struct radeon_mn { struct rb_root objects; }; +struct radeon_mn_node { + struct interval_tree_node it; + struct list_head bos; +}; + /** * radeon_mn_destroy - destroy the rmn * @@ -64,14 +69,21 @@ static void radeon_mn_destroy(struct work_struct *work) { struct radeon_mn *rmn = container_of(work, struct radeon_mn, work); struct radeon_device *rdev = rmn->rdev; - struct radeon_bo *bo, *next; + struct radeon_mn_node *node, *next_node; + struct radeon_bo *bo, *next_bo; mutex_lock(&rdev->mn_lock); mutex_lock(&rmn->lock); hash_del(&rmn->node); - rbtree_postorder_for_each_entry_safe(bo, next, &rmn->objects, mn_it.rb) { - interval_tree_remove(&bo->mn_it, &rmn->objects); - bo->mn = NULL; + rbtree_postorder_for_each_entry_safe(node, next_node, &rmn->objects, + it.rb) { + + interval_tree_remove(&node->it, &rmn->objects); + list_for_each_entry_safe(bo, next_bo, &node->bos, mn_list) { + bo->mn = NULL; + list_del_init(&bo->mn_list); + } + kfree(node); } mutex_unlock(&rmn->lock); mutex_unlock(&rdev->mn_lock); @@ -121,29 +133,33 @@ static void radeon_mn_invalidate_range_start(struct mmu_notifier *mn, it = interval_tree_iter_first(&rmn->objects, start, end); while (it) { + struct radeon_mn_node *node; struct radeon_bo *bo; int r; - bo = container_of(it, struct radeon_bo, mn_it); + node = container_of(it, struct radeon_mn_node, it); it = interval_tree_iter_next(it, start, end); - r = radeon_bo_reserve(bo, true); - if (r) { - DRM_ERROR("(%d) failed to reserve user bo\n", r); - continue; - } + list_for_each_entry(bo, &node->bos, mn_list) { - r = reservation_object_wait_timeout_rcu(bo->tbo.resv, true, - false, MAX_SCHEDULE_TIMEOUT); - if (r) - DRM_ERROR("(%d) failed to wait for user bo\n", r); + r = radeon_bo_reserve(bo, true); + if (r) { + DRM_ERROR("(%d) failed to reserve user bo\n", r); + continue; + } - radeon_ttm_placement_from_domain(bo, RADEON_GEM_DOMAIN_CPU); - r = ttm_bo_validate(&bo->tbo, &bo->placement, false, false); - if (r) - DRM_ERROR("(%d) failed to validate user bo\n", r); + r = reservation_object_wait_timeout_rcu(bo->tbo.resv, + true, false, MAX_SCHEDULE_TIMEOUT); + if (r) + DRM_ERROR("(%d) failed to wait for user bo\n", r); - radeon_bo_unreserve(bo); + radeon_ttm_placement_from_domain(bo, RADEON_GEM_DOMAIN_CPU); + r = ttm_bo_validate(&bo->tbo, &bo->placement, false, false); + if (r) + DRM_ERROR("(%d) failed to validate user bo\n", r); + + radeon_bo_unreserve(bo); + } } mutex_unlock(&rmn->lock); @@ -220,24 +236,44 @@ int radeon_mn_register(struct radeon_bo *bo, unsigned long addr) unsigned long end = addr + radeon_bo_size(bo) - 1; struct radeon_device *rdev = bo->rdev; struct radeon_mn *rmn; + struct radeon_mn_node *node = NULL; + struct list_head bos; struct interval_tree_node *it; rmn = radeon_mn_get(rdev); if (IS_ERR(rmn)) return PTR_ERR(rmn); + INIT_LIST_HEAD(&bos); + mutex_lock(&rmn->lock); - it = interval_tree_iter_first(&rmn->objects, addr, end); - if (it) { - mutex_unlock(&rmn->lock); - return -EEXIST; + while ((it = interval_tree_iter_first(&rmn->objects, addr, end))) { + kfree(node); + node = container_of(it, struct radeon_mn_node, it); + interval_tree_remove(&node->it, &rmn->objects); + addr = min(it->start, addr); + end = max(it->last, end); + list_splice(&node->bos, &bos); + } + + if (!node) { + node = kmalloc(sizeof(struct radeon_mn_node), GFP_KERNEL); + if (!node) { + mutex_unlock(&rmn->lock); + return -ENOMEM; + } } bo->mn = rmn; - bo->mn_it.start = addr; - bo->mn_it.last = end; - interval_tree_insert(&bo->mn_it, &rmn->objects); + + node->it.start = addr; + node->it.last = end; + INIT_LIST_HEAD(&node->bos); + list_splice(&bos, &node->bos); + list_add(&bo->mn_list, &node->bos); + + interval_tree_insert(&node->it, &rmn->objects); mutex_unlock(&rmn->lock); @@ -255,6 +291,7 @@ void radeon_mn_unregister(struct radeon_bo *bo) { struct radeon_device *rdev = bo->rdev; struct radeon_mn *rmn; + struct list_head *head; mutex_lock(&rdev->mn_lock); rmn = bo->mn; @@ -264,8 +301,19 @@ void radeon_mn_unregister(struct radeon_bo *bo) } mutex_lock(&rmn->lock); - interval_tree_remove(&bo->mn_it, &rmn->objects); + /* save the next list entry for later */ + head = bo->mn_list.next; + bo->mn = NULL; + list_del(&bo->mn_list); + + if (list_empty(head)) { + struct radeon_mn_node *node; + node = container_of(head, struct radeon_mn_node, bos); + interval_tree_remove(&node->it, &rmn->objects); + kfree(node); + } + mutex_unlock(&rmn->lock); mutex_unlock(&rdev->mn_lock); }