From patchwork Wed Aug 22 07:52:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Huang Rui X-Patchwork-Id: 10572663 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 DC71C921 for ; Wed, 22 Aug 2018 07:55:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D3B702AD5F for ; Wed, 22 Aug 2018 07:55:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C6AE82AE9B; Wed, 22 Aug 2018 07:55:02 +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 884022AD5F for ; Wed, 22 Aug 2018 07:55:01 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 609676E10E; Wed, 22 Aug 2018 07:55:00 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM04-SN1-obe.outbound.protection.outlook.com (mail-eopbgr700080.outbound.protection.outlook.com [40.107.70.80]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5A77D6E10E; Wed, 22 Aug 2018 07:54:59 +0000 (UTC) Received: from DM5PR12CA0002.namprd12.prod.outlook.com (2603:10b6:4:1::12) by SN1PR12MB0255.namprd12.prod.outlook.com (2a01:111:e400:5143::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1059.23; Wed, 22 Aug 2018 07:54:56 +0000 Received: from DM3NAM03FT020.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e49::203) by DM5PR12CA0002.outlook.office365.com (2603:10b6:4:1::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1080.13 via Frontend Transport; Wed, 22 Aug 2018 07:54:56 +0000 Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from SATLEXCHOV01.amd.com (165.204.84.17) by DM3NAM03FT020.mail.protection.outlook.com (10.152.82.193) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.20.1080.9 via Frontend Transport; Wed, 22 Aug 2018 07:54:56 +0000 Received: from hr-intel.amd.com (10.34.1.3) by SATLEXCHOV01.amd.com (10.181.40.71) with Microsoft SMTP Server id 14.3.389.1; Wed, 22 Aug 2018 02:54:55 -0500 From: Huang Rui To: , Subject: [PATCH v5 4/5] drm/amdgpu: use bulk moves for efficient VM LRU handling (v5) Date: Wed, 22 Aug 2018 15:52:54 +0800 Message-ID: <1534924375-5837-5-git-send-email-ray.huang@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1534924375-5837-1-git-send-email-ray.huang@amd.com> References: <1534924375-5837-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)(376002)(39860400002)(396003)(136003)(346002)(2980300002)(428003)(189003)(199004)(2870700001)(53936002)(86362001)(50226002)(8676002)(104016004)(76176011)(36756003)(23676004)(106466001)(47776003)(81166006)(305945005)(81156014)(561944003)(8936002)(105586002)(53416004)(54906003)(68736007)(186003)(97736004)(14444005)(336012)(356003)(11346002)(26005)(5660300001)(450100002)(486006)(72206003)(50466002)(126002)(446003)(5820100001)(2616005)(110136005)(476003)(4326008)(316002)(478600001)(2906002)(7696005)(77096007)(426003); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0255; H:SATLEXCHOV01.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoDomainNonexistent; MX:1; A:1; X-Microsoft-Exchange-Diagnostics: 1; DM3NAM03FT020; 1:JVaJRWYCpXO9KG3xMyE4N6qoOI1U9RwSGzIU4p7taEOHPfMeUW7dVMAJ5RH9YG4OMKtqWl2e0IT89AhMT3zcEkU8CfrHzf6FOeStH4Lg8ZcCk7rAJeyONM9lvjXvU/sN X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8eee60cd-a7d7-4ea9-87d5-08d608048d81 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989137)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(2017052603328)(7153060); SRVR:SN1PR12MB0255; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0255; 3:C/dvWPNAHh23msmaY0jmJcYQ8IZROSCoR82TWgeEZY3tT1ZyQic5GpOVv9tOBjjCLHeLWkZChDYueBdn1TBfV2GOHNJ7SSNZoVakQWVdz0DvOzYTdinM/sYgfzg2a+RXc9l/4D/ykroaEU9fRuRdp+PosyApksiiV9VptwZzWt0lHBGNEzd+9M/YjU+VlhzKWUCtwt9w8Rg0SwqiWzK5/a/dVBnuK5SOeY4IRXmf1a0rt9TCnY5o1TUxg4FaYkc07Q9v32KrsVLUDkOWJOS6Pf6qhjm9fbff08AUErKO02tVZTHGAWAPSXlmZFmhAl3ah4FT7roXN0ji1T4ZdeGZ2c5D2WxTttnNMv+KwNhm3ho=; 25:Zpq3W8ANoJ2f/YzEvg3diIFD78eyZHzLSk0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Z7hE1z2kDrMrTKEJl5gkH+oiYPuJZO2IN7MkDC2ne0DJr330NMSKX0IomcNb071R 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)(5005006)(8121501046)(93006095)(93003095)(3231311)(944501410)(52105095)(10201501046)(3002001)(6055026)(149027)(150027)(6041310)(20161123560045)(20161123564045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(201708071742011)(7699016); SRVR:SN1PR12MB0255; BCL:0; PCL:0; RULEID:; SRVR:SN1PR12MB0255; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0255; 4:ZoSPbjVA20XBvTPZZdcnM2SRABwFsyhYgFcDmigTArSGai+T6AmzyuPsdZQZ/D21nykDDakT4MtVx+lrkBeBV6B/OOUNehEVUObiCkOFNfwkeVgMoP9Ysi/NvoqYzqnXJEA6IqBs2wWJvL4t1iAq6EGk2tB4HLoalGGSD8OceWx9pjVCJdKXOCLMzSs2dMITT9R3qJ8o92oJC3Un8TsdolWkKmJ5Q5O0AOiWlD4YtwszXm7HuibHOEum5nR1utVM2dDa6oHMlgS+scbooIwG3tLHO5u+QldKaWmAs8pZXmfl/cV0scEakVkPpJH8elOX X-Forefront-PRVS: 0772E5DAD5 X-Microsoft-Exchange-Diagnostics: =?utf-8?q?1=3BSN1PR12MB0255=3B23=3Aq2Cdqyl?= =?utf-8?q?Mk1qF9vwzBrS3dtxkngzSw8eB4QC58//OyplXdGTcLPkK5aweYD3UFUVgs9h7T4cW?= =?utf-8?q?JIO43+YA+mgIYs1o+8wVfyMDMPFdeSlq1xnExyQZiUKsGBg4NRPrer1kc8Z9MoqOI?= =?utf-8?q?2U443PuJBGRvuGy/PCAEVabqpjS6lwKYOQzdzm8HsqOvMsa2Uy2UktNXWQsKKxMa+?= =?utf-8?q?G5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z0W3waehvlTo5Mceet9hsHY8Dahe9VfL9EaDo5nSYeS3774SVP3EPxfwD4tVSk2wiiiVLtfz3Hz6KxwXOKaparLPUl/rZwoWNs29IWAI=; 7:XzcWHVBC/fUaMjzrNDvOudwmTu5/YdKX6t9TgwxK3TjgtgCTu0MUd5hq4JkQkKWeADSpfQAoYmRnB0+KUI164VWL0MxU84L/9RpRcRaDpgYJxYDPWILYQUpjU7VO2pSafVP6trcyRWwNKtznKEXRsc236kE6E05vWu8rr3VnP6ojsi21G8z5e3QwMGQA94uG40t3eJaFukNOcRNAep2tLOqnruz8OgTxQwlyeE7rCt72qconTk1ab/HNx6jAn3fT SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0255; 20:lmcR4h53Z8uYXxd3HGemAfl6KeHQ3DWjXcng8PsYd1hco9d9BVCEBWZ76374rpNov0a2U80wwCJrRAc77cqNzrFAbI2cVuLPBFX3ELA1vWpV6bsJlOFAjG8vSrcpGxestX50ILP03V8x9IJ+jGsAsP80vsfeWkIB/wLcDpMouAkdR9AeNfjUgIZ2RYwuKs1HU0yxfVcsajC6zeF05ZkYjncunl5Uai8v7aHGdBHCKqQFFWm/pXmgUl6i9DVExc8l X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2018 07:54:56.4284 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8eee60cd-a7d7-4ea9-87d5-08d608048d81 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=[SATLEXCHOV01.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0255 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: Commit 0bbf32026cf5ba41e9922b30e26e1bed1ecd38ae ("drm/amdgpu: band aid validating VM PTs") 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. v4: move the amdgpu_vm_move_to_lru_tail after command submission, at that time, all bo will be back on idle list. v5: remove amdgpu_vm_move_to_lru_tail_by_list(), use bulk_moveable instread of validated, and move ttm_bo_bulk_move_lru_tail() also into amdgpu_vm_move_to_lru_tail(). Signed-off-by: Christian König Signed-off-by: Huang Rui Tested-by: Mike Lothian Tested-by: Dieter Nützel Acked-by: Chunming Zhou --- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 10 ++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 66 +++++++++++++++++++++++----------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 11 +++++- 3 files changed, 65 insertions(+), 22 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c index 502b94f..4efdbd2 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c @@ -1260,6 +1260,15 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p, return 0; } +static void amdgpu_cs_vm_move_on_lru(struct amdgpu_device *adev, + struct amdgpu_cs_parser *p) +{ + struct amdgpu_fpriv *fpriv = p->filp->driver_priv; + struct amdgpu_vm *vm = &fpriv->vm; + + amdgpu_vm_move_to_lru_tail(adev, vm); +} + int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) { struct amdgpu_device *adev = dev->dev_private; @@ -1310,6 +1319,7 @@ int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) r = amdgpu_cs_submit(&parser, cs); + amdgpu_cs_vm_move_on_lru(adev, &parser); out: amdgpu_cs_parser_fini(&parser, r, reserved_buffers); return r; diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c index 9c84770..db1f28a 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c @@ -268,6 +268,47 @@ void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm, } /** + * 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. + */ +void amdgpu_vm_move_to_lru_tail(struct amdgpu_device *adev, + struct amdgpu_vm *vm) +{ + struct ttm_bo_global *glob = adev->mman.bdev.glob; + struct amdgpu_vm_bo_base *bo_base; + + if (vm->bulk_moveable) { + spin_lock(&glob->lru_lock); + ttm_bo_bulk_move_lru_tail(&vm->lru_bulk_move); + spin_unlock(&glob->lru_lock); + return; + } + + memset(&vm->lru_bulk_move, 0, sizeof(vm->lru_bulk_move)); + + spin_lock(&glob->lru_lock); + list_for_each_entry(bo_base, &vm->idle, 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); + } + spin_unlock(&glob->lru_lock); + + vm->bulk_moveable = true; +} + +/** * amdgpu_vm_validate_pt_bos - validate the page table BOs * * @adev: amdgpu device pointer @@ -284,10 +325,11 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, int (*validate)(void *p, struct amdgpu_bo *bo), void *param) { - struct ttm_bo_global *glob = adev->mman.bdev.glob; struct amdgpu_vm_bo_base *bo_base, *tmp; int r = 0; + vm->bulk_moveable &= list_empty(&vm->evicted); + list_for_each_entry_safe(bo_base, tmp, &vm->evicted, vm_status) { struct amdgpu_bo *bo = bo_base->bo; @@ -295,12 +337,6 @@ 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); } if (bo->tbo.type != ttm_bo_type_kernel) { @@ -312,20 +348,7 @@ 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 (!bo->parent) - continue; - - 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); - - return r; + return 0; } /** @@ -2596,6 +2619,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, return r; vm->pte_support_ats = false; + vm->bulk_moveable = true; if (vm_context == AMDGPU_VM_CONTEXT_COMPUTE) { vm->use_cpu_for_update = !!(adev->vm_manager.vm_update_mode & diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h index 67a15d4..bbdde40 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,11 @@ 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; + /* mark whether can do the bulk move */ + bool bulk_moveable; }; struct amdgpu_vm_manager { @@ -330,8 +336,11 @@ bool amdgpu_vm_need_pipeline_sync(struct amdgpu_ring *ring, void amdgpu_vm_check_compute_bug(struct amdgpu_device *adev); void amdgpu_vm_get_task_info(struct amdgpu_device *adev, unsigned int pasid, - struct amdgpu_task_info *task_info); + struct amdgpu_task_info *task_info); void amdgpu_vm_set_task_info(struct amdgpu_vm *vm); +void amdgpu_vm_move_to_lru_tail(struct amdgpu_device *adev, + struct amdgpu_vm *vm); + #endif