From patchwork Wed Nov 21 14:41:00 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Hellstrom X-Patchwork-Id: 1781141 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork2.kernel.org (Postfix) with ESMTP id B5575DF230 for ; Wed, 21 Nov 2012 14:50:28 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6F50EE6510 for ; Wed, 21 Nov 2012 06:50:28 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from smtp-outbound-2.vmware.com (smtp-outbound-2.vmware.com [208.91.2.13]) by gabe.freedesktop.org (Postfix) with ESMTP id 5F8D4E6512 for ; Wed, 21 Nov 2012 06:41:24 -0800 (PST) Received: from sc9-mailhost1.vmware.com (sc9-mailhost1.vmware.com [10.113.161.71]) by smtp-outbound-2.vmware.com (Postfix) with ESMTP id 7E17228404; Wed, 21 Nov 2012 06:41:23 -0800 (PST) Received: from zcs-prod-mta-3.vmware.com (zcs-prod-mta-3.vmware.com [10.113.163.65]) by sc9-mailhost1.vmware.com (Postfix) with ESMTP id 79887185EE; Wed, 21 Nov 2012 06:41:23 -0800 (PST) Received: from localhost (localhost.localdomain [127.0.0.1]) by zcs-prod-mta-3.vmware.com (Postfix) with ESMTP id 20262E0567; Wed, 21 Nov 2012 06:41:55 -0800 (PST) X-Virus-Scanned: amavisd-new at zcs-prod-mta-3.vmware.com Received: from zcs-prod-mta-3.vmware.com ([127.0.0.1]) by localhost (zcs-prod-mta-3.vmware.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id Azps-ABPet86; Wed, 21 Nov 2012 06:41:55 -0800 (PST) Received: from sc9-mailhost1.vmware.com (unknown [10.113.160.14]) by zcs-prod-mta-3.vmware.com (Postfix) with ESMTPSA id 8C634E0548; Wed, 21 Nov 2012 06:41:53 -0800 (PST) From: Thomas Hellstrom To: airlied@gmail.com, airlied@redhat.com Subject: [PATCH -next] drm/ttm: Optimize vm locking using kref_get_unless_zero v2 Date: Wed, 21 Nov 2012 15:41:00 +0100 Message-Id: <1353508860-6391-1-git-send-email-thellstrom@vmware.com> X-Mailer: git-send-email 1.7.4.4 Cc: Thomas Hellstrom , dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Removes the need for a write lock each time we call ttm_bo_unref(). v2: Remove an unused variable. Signed-off-by: Thomas Hellstrom --- drivers/gpu/drm/ttm/ttm_bo.c | 4 +--- drivers/gpu/drm/ttm/ttm_bo_vm.c | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index 7426fe5..2dd0238 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -696,6 +696,7 @@ static void ttm_bo_release(struct kref *kref) struct ttm_bo_device *bdev = bo->bdev; struct ttm_mem_type_manager *man = &bdev->man[bo->mem.mem_type]; + write_lock(&bdev->vm_lock); if (likely(bo->vm_node != NULL)) { rb_erase(&bo->vm_rb, &bdev->addr_space_rb); drm_mm_put_block(bo->vm_node); @@ -707,7 +708,6 @@ static void ttm_bo_release(struct kref *kref) ttm_mem_io_unlock(man); ttm_bo_cleanup_refs_or_queue(bo); kref_put(&bo->list_kref, ttm_bo_release_list); - write_lock(&bdev->vm_lock); } void ttm_bo_unref(struct ttm_buffer_object **p_bo) @@ -716,9 +716,7 @@ void ttm_bo_unref(struct ttm_buffer_object **p_bo) struct ttm_bo_device *bdev = bo->bdev; *p_bo = NULL; - write_lock(&bdev->vm_lock); kref_put(&bo->kref, ttm_bo_release); - write_unlock(&bdev->vm_lock); } EXPORT_SYMBOL(ttm_bo_unref); diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c index 3ba72db..74705f3 100644 --- a/drivers/gpu/drm/ttm/ttm_bo_vm.c +++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c @@ -259,8 +259,8 @@ int ttm_bo_mmap(struct file *filp, struct vm_area_struct *vma, read_lock(&bdev->vm_lock); bo = ttm_bo_vm_lookup_rb(bdev, vma->vm_pgoff, (vma->vm_end - vma->vm_start) >> PAGE_SHIFT); - if (likely(bo != NULL)) - ttm_bo_reference(bo); + if (likely(bo != NULL) && !kref_get_unless_zero(&bo->kref)) + bo = NULL; read_unlock(&bdev->vm_lock); if (unlikely(bo == NULL)) {