Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp4425588ybz; Mon, 20 Apr 2020 23:50:57 -0700 (PDT) X-Google-Smtp-Source: APiQypLWg/Venk+XoeacM8uJZQYa4Qg5I3rXS/0EzJBVFl9U6NBHucTUmtsuxtTb1upmKbdXYAWG X-Received: by 2002:a50:a2e5:: with SMTP id 92mr17965318edm.139.1587451856972; Mon, 20 Apr 2020 23:50:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587451856; cv=none; d=google.com; s=arc-20160816; b=0FhEHbnKASmbofkJAttvFU4V1hoifPuHeW76VJas7mF4b66Kq399GZ1NaQYiSWXOA/ KaOvMNC45h/AXC/rymL7lyg9uMBnEf4jFTQXXEAF5vkCclgwmhQR9RRaG4jPu5xBJ2Jw p/uvE/StfNDK563i4b3w1YAq8jUcC0Os0fsbn7eZs3qj24z1PnaNNXah/yPsE44vHR44 Mdw76L9jRGnNH8MqWElpx6zdrN1URpYWf9I+dxVfae7BxWRIXyEB/Ts6bXYQ/UBbbGsY 6J2dtrcp2P2u3FL3GW2vjoHiwGniECa4x8V5I/puaA8D/sAk/0h+RNgqkq7VYAEDDTMO +FRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :reply-to:message-id:date:subject:cc:to:from; bh=4vWQikwzHwvmgzMBQ6VgpU9tvjNEOwYLVu458WUI3Us=; b=VOWjC3CLOVBzQUjp0u/DVySwkIu1DBUFJkfqqKCNnHc4wos1QwzoN1MKXlg2Bl8TUX 2h6ZX8pR359vQoKn3nREcOl17JXIWb15fw8i7b7xIAH65I2vpg3RaKreHNQJgnyqvGOA KvyZbbbAseH20ufmT/6Ucg+eFsnQGjtsPPixtAaFuDJR7fB8riU81wzM5d2dj1Jye3eZ DheEUABpQ1y3Dc662A8Ej2VLkEezM35WKR1Uqf0Db1BnWrzeiZ9R+I2YrsGFCA72OMt6 73NTyjP/QqqN+QtAhQPUsbCqCzQI+crMOMnTmaqWn00bRxftTRXaPh+8OkokgHuLrm3f abyw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t11si1020729edj.346.2020.04.20.23.50.33; Mon, 20 Apr 2020 23:50:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726874AbgDUGsd (ORCPT + 99 others); Tue, 21 Apr 2020 02:48:33 -0400 Received: from m176115.mail.qiye.163.com ([59.111.176.115]:63957 "EHLO m176115.mail.qiye.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726018AbgDUGsd (ORCPT ); Tue, 21 Apr 2020 02:48:33 -0400 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=20K=C3=B6nig?= , "David (ChunMing) Zhou" , David Airlie , Daniel Vetter , amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: opensource.kernel@vivo.com, Bernard Zhao 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 Reply-To: 1587181464-114215-1-git-send-email-bernard@vivo.com MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-HM-Spam-Status: e1kfGhgUHx5ZQUtXWQgYFAkeWUFZT1VNSktLS0tKSEhOSk9PWVdZKFlBSE 83V1ktWUFJV1kJDhceCFlBWTU0KTY6NyQpLjc#WQY+ X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6OBg6Dhw*MDg5OAMJI04WVj4* ShoKCgJVSlVKTkNMT05KTEtCQ0JPVTMWGhIXVRkeCRUaCR87DRINFFUYFBZFWVdZEgtZQVlKTkxV S1VISlVKSUlZV1kIAVlBSEtCSzcG X-HM-Tid: 0a719b7ebdb29373kuws7e79d665c28 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); -- 2.26.2