From patchwork Mon Aug 13 09:58:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Huang Rui X-Patchwork-Id: 10563971 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 79E1D13BB for ; Mon, 13 Aug 2018 10:00:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6689128E63 for ; Mon, 13 Aug 2018 10:00:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5A71828EA0; Mon, 13 Aug 2018 10:00:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CA8D528EAF for ; Mon, 13 Aug 2018 10:00:06 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 762286E116; Mon, 13 Aug 2018 10:00:04 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM02-CY1-obe.outbound.protection.outlook.com (mail-cys01nam02on0605.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe45::605]) by gabe.freedesktop.org (Postfix) with ESMTPS id B0F206E0EF; Mon, 13 Aug 2018 10:00:02 +0000 (UTC) Received: from BN6PR12CA0041.namprd12.prod.outlook.com (2603:10b6:405:70::27) by DM5PR1201MB0122.namprd12.prod.outlook.com (2603:10b6:4:55::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1038.23; Mon, 13 Aug 2018 10:00:00 +0000 Received: from CO1NAM03FT007.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e48::206) by BN6PR12CA0041.outlook.office365.com (2603:10b6:405:70::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1038.20 via Frontend Transport; Mon, 13 Aug 2018 09:59:59 +0000 Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from SATLEXCHOV02.amd.com (165.204.84.17) by CO1NAM03FT007.mail.protection.outlook.com (10.152.80.117) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.1059.14 via Frontend Transport; Mon, 13 Aug 2018 09:59:59 +0000 Received: from hr-intel.amd.com (10.34.1.3) by SATLEXCHOV02.amd.com (10.181.40.72) with Microsoft SMTP Server id 14.3.389.1; Mon, 13 Aug 2018 04:59:58 -0500 From: Huang Rui To: , Subject: [PATCH v3 4/5] drm/amdgpu: use bulk moves for efficient VM LRU handling (v3) Date: Mon, 13 Aug 2018 17:58:50 +0800 Message-ID: <1534154331-11810-5-git-send-email-ray.huang@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1534154331-11810-1-git-send-email-ray.huang@amd.com> References: <1534154331-11810-1-git-send-email-ray.huang@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:165.204.84.17; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(346002)(396003)(39860400002)(376002)(136003)(2980300002)(428003)(189003)(199004)(316002)(68736007)(36756003)(54906003)(478600001)(110136005)(76176011)(72206003)(23676004)(81156014)(81166006)(6666003)(97736004)(86362001)(356003)(4326008)(50466002)(450100002)(305945005)(50226002)(104016004)(8936002)(8676002)(5660300001)(7696005)(14444005)(336012)(26005)(126002)(11346002)(53936002)(2616005)(47776003)(2906002)(77096007)(2870700001)(106466001)(186003)(426003)(53416004)(476003)(561944003)(105586002)(446003)(5820100001)(486006); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR1201MB0122; H:SATLEXCHOV02.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoDomainNonexistent; MX:1; A:1; X-Microsoft-Exchange-Diagnostics: 1; CO1NAM03FT007; 1:Xnc7EB/3vBqZqsqeBSqkcreuu16k727JrxU95PktW8KJ5Xi35C1HKF0hjRbImaeq8RESiD+OK9mO/9CMj3ys//Rw8BMFKbNSiV9cV9/u0yMcRWdtCkWzH8qPBvdKGSY/ X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c8277074-062f-4b82-182c-08d6010387da X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989117)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(2017052603328)(7153060); SRVR:DM5PR1201MB0122; X-Microsoft-Exchange-Diagnostics: 1; DM5PR1201MB0122; 3:KZkil/wOwGvvmQpbqIkh7gIe/PwcZk525Xh2vUr+gdS6GZ9cvqAgHCdhvgo+QMr+47V8bQplt6jyfhdUAsxbdLRW5FmMDQF2hjq4HTrGAS5txHmROm0kFklTscrm7Dy6TkjkHJXImCdv0X6UAGI4NNBHd3i3392OGoYLI22JUgeoteiYXRDPJKBRughzF7b9fl4wWYU0UfjUSIf+tH4dIPUhhX/sF1Xdf7sBG1GNHa9k4btJ9V1ZpHApUbAxXFG5lDSj/yTIF66PlIlhvFLTK3k+poh2KX/dHGM7OBnMkdGDGA0YOitBCzWLHkNcg5761eZqQroi2mvu3yxmT2gkmgnoIJ7XGALkL38BDTcu/bA=; 25:Mw96rgkL8+loVGh7U64SxPR39Bm7wbiak4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wswP2zs16LZsbYitpftmkTSXhgJ0TQXeu2mFZ/u6+DBHTX/VBjjopElMsR1qG X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(93006095)(93003095)(3231311)(944501410)(52105095)(10201501046)(3002001)(6055026)(149027)(150027)(6041310)(20161123560045)(20161123564045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(6072148)(201708071742011)(7699016); SRVR:DM5PR1201MB0122; BCL:0; PCL:0; RULEID:; SRVR:DM5PR1201MB0122; X-Microsoft-Exchange-Diagnostics: 1; DM5PR1201MB0122; 4:ZB9u2u4xWiggiZRSWqpJZ6jeGuPSz/aiYkdgn9T8ySua4VocZoFqNbnUQpDX9gNdPUPxf/qWAKsRGXblX4VpJ/RevjbcktHSE99haCAK2uSwlp7ZAyvqcoSHepJBUzsgJnnjlzqMtwtVegniTXRWC+a38t0XBVpbDvBj0TAQPblFOY/zQasrhJ8ZnMoq7zdvpIieS2WevPSgNDZeJiyASvCMqEFVSmK4IynigyF09YhXfAYYe7gYFARD8GqQYbIxLRV3wntDGET40LVJV5YTu5nyRWXUkQ0axTjXIhVezNYYAWg/nBz3h7HhdswU1+/i X-Forefront-PRVS: 07630F72AD X-Microsoft-Exchange-Diagnostics: =?utf-8?q?1=3BDM5PR1201MB0122=3B23=3AUCRmQ?= =?utf-8?q?FRAf7eOe0jBMtrqx2F9GGPJWV1jRw0pAApcUFBtH5AFyKW78owy55Va+xKJUYgHFZ?= =?utf-8?q?rHD1JK4trCpNkFoWglB5jH4f4XQ2gCvyO2QjMgVAhQReuluflwZavjJsgiAYLyRHQ?= =?utf-8?q?+0wpNPmM3ivS3xIIp42Aaw8pzfw5pnkej1py9kk69m/KmlMHgx9k/QTWZBQNyAl69?= =?utf-8?q?kGSJz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Xzw75FC+gc7q9PpyaEmo/Y/Zu7p6KgQFBRvygEBOvdjCfbOpZem7tgQsX+ArwI+55RGakveH6J0TFhO1Qf7Qh3nPj6Ct1EH01e0gCfAsAhMpyyOJ2kSFd97vmbmp8YqhPMAoISKCjEgiXiUlIqpWdrKtk=; 7:ooB9QfTbkDC8XSVx9vDfUW9r1PFqw2/+R86+7Bmh1H5V7ILk6K4qawmssZbOxASCtl8gANoMhe1dSCM1kQvpIcq9gWERX2OsOg7zZKcp65atfon54oPtpFPR3pmMXC9adXF6KNjunD7a9CbsVcrtswPZB+uihJEuZC4/mYQRFdK2e5HfGtmrxiqyqDBd297eKcQ/WkHTP81vdqjCe9EhCbVVxRkWSqxgBe2I/WJG0kHMUX4niMyQ34GKkXD8/eyM SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM5PR1201MB0122; 20:HnfsY65R6IL1bVO7tH5GpHxROSFCTGT3c07niIqVxu8F5RRtpzX6HmOOMS4YzXCTwg63piKB6CaT2mfKUyXvze7dtfVlSGnFcfvDbqPdcT2ozWSfk9JckWbQT/FpFI2lMY10PcGEIVmNk4eWyGgaiDTjRYA127thqiZEywzmcQ6hL0uOt1wpMZU7sfPV3d0h81TITIO8T5qMtC7mzs4t7Wyw1DkXefhVoq9BCNucwdRDzlBMM+vaL5ACngGSnDnb X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Aug 2018 09:59:59.3219 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c8277074-062f-4b82-182c-08d6010387da X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXCHOV02.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR1201MB0122 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Huang Rui , =?utf-8?q?Christian_K=C3=B6nig?= Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP I continue to work for bulk moving that based on the proposal by Christian. Background: amdgpu driver will move all PD/PT and PerVM BOs into idle list. Then move all of them on the end of LRU list one by one. Thus, that cause so many BOs moved to the end of the LRU, and impact performance seriously. Then Christian provided a workaround to not move PD/PT BOs on LRU with below patch: "drm/amdgpu: band aid validating VM PTs" Commit 0bbf32026cf5ba41e9922b30e26e1bed1ecd38ae However, the final solution should bulk move all PD/PT and PerVM BOs on the LRU instead of one by one. Whenever amdgpu_vm_validate_pt_bos() is called and we have BOs which need to be validated we move all BOs together to the end of the LRU without dropping the lock for the LRU. While doing so we note the beginning and end of this block in the LRU list. Now when amdgpu_vm_validate_pt_bos() is called and we don't have anything to do, we don't move every BO one by one, but instead cut the LRU list into pieces so that we bulk move everything to the end in just one operation. Test data: +--------------+-----------------+-----------+---------------------------------------+ | |The Talos |Clpeak(OCL)|BusSpeedReadback(OCL) | | |Principle(Vulkan)| | | +------------------------------------------------------------------------------------+ | | | |0.319 ms(1k) 0.314 ms(2K) 0.308 ms(4K) | | Original | 147.7 FPS | 76.86 us |0.307 ms(8K) 0.310 ms(16K) | +------------------------------------------------------------------------------------+ | Orignial + WA| | |0.254 ms(1K) 0.241 ms(2K) | |(don't move | 162.1 FPS | 42.15 us |0.230 ms(4K) 0.223 ms(8K) 0.204 ms(16K)| |PT BOs on LRU)| | | | +------------------------------------------------------------------------------------+ | Bulk move | 163.1 FPS | 40.52 us |0.244 ms(1K) 0.252 ms(2K) 0.213 ms(4K) | | | | |0.214 ms(8K) 0.225 ms(16K) | +--------------+-----------------+-----------+---------------------------------------+ After test them with above three benchmarks include vulkan and opencl. We can see the visible improvement than original, and even better than original with workaround. v2: move all BOs include idle, relocated, and moved list to the end of LRU and put them together. v3: remove unused parameter and use list_for_each_entry instead of the one with save entry. Signed-off-by: Christian König Signed-off-by: Huang Rui Tested-by: Mike Lothian --- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 73 ++++++++++++++++++++++++++-------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 4 ++ 2 files changed, 61 insertions(+), 16 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c index 9c84770..ee1af53 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c @@ -268,6 +268,53 @@ void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm, } /** + * amdgpu_vm_move_to_lru_tail - move one list of BOs to end of LRU + * + * @vm: vm providing the BOs + * @list: the list that stored BOs + * + * Move one list of BOs to the end of LRU and update the positions. + */ +static void +amdgpu_vm_move_to_lru_tail_by_list(struct amdgpu_vm *vm, struct list_head *list) +{ + struct amdgpu_vm_bo_base *bo_base; + + list_for_each_entry(bo_base, list, vm_status) { + struct amdgpu_bo *bo = bo_base->bo; + + if (!bo->parent) + continue; + + ttm_bo_move_to_lru_tail(&bo->tbo, &vm->lru_bulk_move); + if (bo->shadow) + ttm_bo_move_to_lru_tail(&bo->shadow->tbo, + &vm->lru_bulk_move); + } +} + +/** + * amdgpu_vm_move_to_lru_tail - move all BOs to the end of LRU + * + * @adev: amdgpu device pointer + * @vm: vm providing the BOs + * + * Move all BOs to the end of LRU and remember their positions to put them + * together. + */ +static void +amdgpu_vm_move_to_lru_tail(struct amdgpu_device *adev, struct amdgpu_vm *vm) +{ + struct ttm_bo_global *glob = adev->mman.bdev.glob; + + spin_lock(&glob->lru_lock); + amdgpu_vm_move_to_lru_tail_by_list(vm, &vm->idle); + amdgpu_vm_move_to_lru_tail_by_list(vm, &vm->relocated); + amdgpu_vm_move_to_lru_tail_by_list(vm, &vm->moved); + spin_unlock(&glob->lru_lock); +} + +/** * amdgpu_vm_validate_pt_bos - validate the page table BOs * * @adev: amdgpu device pointer @@ -286,6 +333,7 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, { struct ttm_bo_global *glob = adev->mman.bdev.glob; struct amdgpu_vm_bo_base *bo_base, *tmp; + bool validated = false; int r = 0; list_for_each_entry_safe(bo_base, tmp, &vm->evicted, vm_status) { @@ -295,14 +343,9 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, r = validate(param, bo); if (r) break; - - spin_lock(&glob->lru_lock); - ttm_bo_move_to_lru_tail(&bo->tbo, NULL); - if (bo->shadow) - ttm_bo_move_to_lru_tail(&bo->shadow->tbo, NULL); - spin_unlock(&glob->lru_lock); } + validated = true; if (bo->tbo.type != ttm_bo_type_kernel) { spin_lock(&vm->moved_lock); list_move(&bo_base->vm_status, &vm->moved); @@ -312,18 +355,16 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, } } - spin_lock(&glob->lru_lock); - list_for_each_entry(bo_base, &vm->idle, vm_status) { - struct amdgpu_bo *bo = bo_base->bo; + if (!validated) { + spin_lock(&glob->lru_lock); + ttm_bo_bulk_move_lru_tail(&vm->lru_bulk_move); + spin_unlock(&glob->lru_lock); + return 0; + } - if (!bo->parent) - continue; + memset(&vm->lru_bulk_move, 0, sizeof(vm->lru_bulk_move)); - ttm_bo_move_to_lru_tail(&bo->tbo, NULL); - if (bo->shadow) - ttm_bo_move_to_lru_tail(&bo->shadow->tbo, NULL); - } - spin_unlock(&glob->lru_lock); + amdgpu_vm_move_to_lru_tail(adev, vm); return r; } diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h index 67a15d4..92725ac 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h @@ -29,6 +29,7 @@ #include #include #include +#include #include "amdgpu_sync.h" #include "amdgpu_ring.h" @@ -226,6 +227,9 @@ struct amdgpu_vm { /* Some basic info about the task */ struct amdgpu_task_info task_info; + + /* Store positions of group of BOs */ + struct ttm_lru_bulk_move lru_bulk_move; }; struct amdgpu_vm_manager {