From patchwork Tue Apr 21 06:48:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernard Zhao X-Patchwork-Id: 11503105 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2DAAF14B4 for ; Wed, 22 Apr 2020 06:54:52 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 16457206D9 for ; Wed, 22 Apr 2020 06:54:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 16457206D9 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=vivo.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4B2166E83D; Wed, 22 Apr 2020 06:54:42 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from m176115.mail.qiye.163.com (m176115.mail.qiye.163.com [59.111.176.115]) by gabe.freedesktop.org (Postfix) with ESMTPS id 52A086E88A for ; Tue, 21 Apr 2020 06:48:36 +0000 (UTC) Received: from ubuntu.localdomain (unknown [157.0.31.122]) by m176115.mail.qiye.163.com (Hmail) with ESMTPA id 7E79D665C28; Tue, 21 Apr 2020 14:48:26 +0800 (CST) From: Bernard Zhao To: Felix Kuehling , Alex Deucher , =?utf-8?q?Christian_K=C3=B6nig?= , "David (ChunMing) Zhou" , David Airlie , Daniel Vetter , amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH V3] amdgpu:optimization-- reduce no need mutex_lock area Date: Mon, 20 Apr 2020 23:48:18 -0700 Message-Id: <20200421064818.129158-1-bernard@vivo.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-HM-Spam-Status: e1kfGhgUHx5ZQUtXWQgYFAkeWUFZT1VNSktLS0tKSEhOSk9PWVdZKFlBSE 83V1ktWUFJV1kJDhceCFlBWTU0KTY6NyQpLjc#WQY+ X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6OBg6Dhw*MDg5OAMJI04WVj4* ShoKCgJVSlVKTkNMT05KTEtCQ0JPVTMWGhIXVRkeCRUaCR87DRINFFUYFBZFWVdZEgtZQVlKTkxV S1VISlVKSUlZV1kIAVlBSEtCSzcG X-HM-Tid: 0a719b7ebdb29373kuws7e79d665c28 X-Mailman-Approved-At: Wed, 22 Apr 2020 06:54:41 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: 1587181464-114215-1-git-send-email-bernard@vivo.com Cc: opensource.kernel@vivo.com, Bernard Zhao Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Maybe we could reduce the mutex_lock(&mem->lock)`s protected code area, and no need to protect pr_debug. Signed-off-by: Bernard Zhao Changes since V1: *commit message improve Changes since V2: *move comment along with the mutex_unlock Link for V1: *https://lore.kernel.org/patchwork/patch/1226588/ Link for V2: *https://lore.kernel.org/patchwork/patch/1227907/ --- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c index 327317c54f7c..f03d9843d723 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c @@ -1285,21 +1285,21 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu( struct bo_vm_reservation_context ctx; struct ttm_validate_buffer *bo_list_entry; int ret; + unsigned int mapped_to_gpu_memory; mutex_lock(&mem->lock); + mapped_to_gpu_memory = mem->mapped_to_gpu_memory; + mutex_unlock(&mem->lock); + /* lock is not needed after this, since mem is unused and will + * be freed anyway + */ - if (mem->mapped_to_gpu_memory > 0) { + if (mapped_to_gpu_memory > 0) { pr_debug("BO VA 0x%llx size 0x%lx is still mapped.\n", mem->va, bo_size); - mutex_unlock(&mem->lock); return -EBUSY; } - mutex_unlock(&mem->lock); - /* lock is not needed after this, since mem is unused and will - * be freed anyway - */ - /* No more MMU notifiers */ amdgpu_mn_unregister(mem->bo);