From patchwork Fri Aug 17 10:08:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Huang Rui X-Patchwork-Id: 10568573 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 2C1B514BD for ; Fri, 17 Aug 2018 10:09:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1C47C2AFF3 for ; Fri, 17 Aug 2018 10:09:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 106BD2B020; Fri, 17 Aug 2018 10:09:05 +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 6F6702AFF3 for ; Fri, 17 Aug 2018 10:09:04 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 33C2E6E602; Fri, 17 Aug 2018 10:09:03 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM05-DM3-obe.outbound.protection.outlook.com (mail-eopbgr730069.outbound.protection.outlook.com [40.107.73.69]) by gabe.freedesktop.org (Postfix) with ESMTPS id A7E446E601; Fri, 17 Aug 2018 10:09:01 +0000 (UTC) Received: from DM5PR12CA0067.namprd12.prod.outlook.com (2603:10b6:3:103::29) by SN1PR12MB0253.namprd12.prod.outlook.com (2a01:111:e400:5143::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1038.23; Fri, 17 Aug 2018 10:08:59 +0000 Received: from DM3NAM03FT007.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e49::206) by DM5PR12CA0067.outlook.office365.com (2603:10b6:3:103::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1059.21 via Frontend Transport; Fri, 17 Aug 2018 10:08:58 +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 DM3NAM03FT007.mail.protection.outlook.com (10.152.82.68) 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; Fri, 17 Aug 2018 10:08:58 +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; Fri, 17 Aug 2018 05:08:57 -0500 From: Huang Rui To: , Subject: [PATCH v4 4/5] drm/amdgpu: use bulk moves for efficient VM LRU handling (v4) Date: Fri, 17 Aug 2018 18:08:00 +0800 Message-ID: <1534500481-15123-5-git-send-email-ray.huang@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1534500481-15123-1-git-send-email-ray.huang@amd.com> References: <1534500481-15123-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)(136003)(396003)(346002)(39860400002)(2980300002)(428003)(189003)(199004)(76176011)(86362001)(6666003)(47776003)(14444005)(104016004)(97736004)(23676004)(478600001)(72206003)(4326008)(450100002)(50226002)(8936002)(77096007)(26005)(186003)(81156014)(81166006)(561944003)(446003)(8676002)(36756003)(106466001)(105586002)(110136005)(53416004)(5660300001)(54906003)(336012)(53936002)(11346002)(426003)(356003)(476003)(305945005)(5820100001)(50466002)(2870700001)(2616005)(126002)(486006)(2906002)(316002)(68736007)(7696005); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0253; H:SATLEXCHOV01.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoDomainNonexistent; MX:1; A:1; X-Microsoft-Exchange-Diagnostics: 1; DM3NAM03FT007; 1:kHtlszo5sPlqDxUKbnbI8ptOQDfgvA3MRaWCVz7T7UrSIZxG6gD7MsV6R/fejCFxbaL9XbG4jI4L5gDi/xnKbUrJs5lfgcto1xXvuTS9P8fvFV8ZzxGVbrEJQ5adV9YX X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ae83036f-cd01-4f52-2824-08d604297323 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989137)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(2017052603328)(7153060); SRVR:SN1PR12MB0253; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0253; 3:F6VeIVzPAq+aJvpT7AZOvMy8/ArFu4dQorm3B2VUiCKfUDrHjlGWcZAs3k31vi4aljwCeILb5yNVbB6u2ADRvrhENcknQZC06j0npd3nRuiNN5DLxfHpDEg7KnYCoWVcdHaLk52m02GE52I3nMIQW3PU2DrW/q6+UUk48RvS8IK2B04j6XAwLUu2QfBKlh3QQZD21Qw5FVuGsMtqW0o7tfvTib4lS9ef0fH/mMFpi0m+MlBL/jLycLr1Ovq6rITnEcG2GN6IFpeHLFb5Z40UX10QQKm3hUNIb1jFL3THE63/iKWuBh+1TVBYn2ysFUnFxvIc6AZ3mOkwTlvQ7SIy57j1xIbTvF8BXbyb4Itz8SE=; 25:/WJb/vWvg0wmgpKgolS+sdcKmxeAyWIE4tTu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WijDLKv6GaSkzh6om8kYAjyn9a+bZ4dGx61gv8WJsp9mfHPFVQM6VCdbtA1vVRFofOSVkm7HTi 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)(10201501046)(3231311)(944501410)(52105095)(93006095)(93003095)(3002001)(6055026)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(201708071742011)(7699016); SRVR:SN1PR12MB0253; BCL:0; PCL:0; RULEID:; SRVR:SN1PR12MB0253; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0253; 4:EyFAAECZddwaIx8/0HzeQ0Tx860HtRLoeOJkzkyrzmh1pWaW9iHoPmnLVe7FTNNlxtvHgTUCLCSB5H7HTiFi+zykHm0q6RyjBSB3Ku7/v/tQBCMiuedwGMNTmWUcVx1OfP3Q6LGYGvyjN9apgQORQFmnjL40Eqh7E8Ud6KuudWqBae6S76YuYi461Qcgmem8y8ga0dOB9UBArocSw2JZI7B9zg1eUTFaXMzJZn2nR1FAyucXU+upihEAXZchePLGzSILtWu4pXOsvAP5t9UCfze6RQNTVdca4M/wC/S/g03XzQSLtXb2bPGru9/3d3qa X-Forefront-PRVS: 076777155F X-Microsoft-Exchange-Diagnostics: =?utf-8?q?1=3BSN1PR12MB0253=3B23=3A684xRGx?= =?utf-8?q?eAMtEA5Rt2Wa3k2PTfPG/mM8s03Y6OryDm0esgzXdlKA4DzhWL6O7I2+8A48ryK+r?= =?utf-8?q?awPYXX9SvAZEyFPJ1HT5YRj1b2RXtGV4Zz9FBgy5lpmNMSqA4QpV0Ajbq7ywa8YFR?= =?utf-8?q?f8IuAve8/bT4n47GNoJOlvhXC37NI4Ixw9nDVvxK3xKuZZJtZOIZpbU67rVIhyseJ?= =?ut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BlhSV9J8vtjhRMcftYX+jHDY8fu0HGEzhlNbvF8CffIsMLfrhZKCb1ACtkol6wWYlqc4orYVntymSOCDcWlxGoSm57D7yLNKKyY9m3S82IVKm118AlnXH3tobVbs3XV76QA+0hfNstJyUIRim7g=; 7:Uio5sHhGh8VViTNJONOD9GRggaj+QvDUZZvkJkVMIuuhHIhn1Hrnc4Llv8QMZuw6AZlrTvnk234Xxu86Z4RSTckW9Seov1lLl8eXM7VFGaPRVKRuOctnIZcx27BTP4hPO93XiRTtEQ/rhdrGaEi31Hqihkoge4n+ttlUdWetwJ6y/b7niPvFyevaBw0I9RDEuH5ao++5ZJmnhylZhLSDqjNEQT4O2u/zE2GY0aiTYcpOQ5fMEmwn1qdVge42cPGd SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0253; 20:Y70URKh5w1MBmREYIg7ZnaZgFxL7a77BzenDFGSjWkGQI3S+iI8yjzDQp+ptB2eQnNI8ng68T0uWW1Lmbg8rV8M+d6zSuyBJSu905ZNs9US2HfScmGWRSOxO7zewnWt5r8C6QDjq1h/UkxrsPYWjHsXUihpDzJCPV/7DLReWpXP7dsIsG1MBppl1TIvMx9CvBt29HfaXob04cqvVfg2ec+uV+SmhIPcWZFAu2mIsX9v/SzImMD0DOf8FLBO1nQo9 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2018 10:08:58.9170 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ae83036f-cd01-4f52-2824-08d604297323 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: SN1PR12MB0253 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. v4: move the amdgpu_vm_move_to_lru_tail after command submission, at that time, all bo will be back on idle list. 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 | 11 ++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 71 ++++++++++++++++++++++++++-------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 11 +++++- 3 files changed, 75 insertions(+), 18 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c index 502b94f..9fbdf02 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c @@ -1260,6 +1260,16 @@ 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; + + if (vm->validated) + 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 +1320,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..037cfbc 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_by_list - 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. + */ +void amdgpu_vm_move_to_lru_tail(struct amdgpu_device *adev, + struct amdgpu_vm *vm) +{ + struct ttm_bo_global *glob = adev->mman.bdev.glob; + + memset(&vm->lru_bulk_move, 0, sizeof(vm->lru_bulk_move)); + + spin_lock(&glob->lru_lock); + amdgpu_vm_move_to_lru_tail_by_list(vm, &vm->idle); + spin_unlock(&glob->lru_lock); +} + +/** * amdgpu_vm_validate_pt_bos - validate the page table BOs * * @adev: amdgpu device pointer @@ -288,6 +335,7 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, struct amdgpu_vm_bo_base *bo_base, *tmp; int r = 0; + vm->validated = false; list_for_each_entry_safe(bo_base, tmp, &vm->evicted, vm_status) { struct amdgpu_bo *bo = bo_base->bo; @@ -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); } + vm->validated = true; if (bo->tbo.type != ttm_bo_type_kernel) { spin_lock(&vm->moved_lock); list_move(&bo_base->vm_status, &vm->moved); @@ -312,20 +355,14 @@ 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; + if (vm->validated) + return 0; - ttm_bo_move_to_lru_tail(&bo->tbo, NULL); - if (bo->shadow) - ttm_bo_move_to_lru_tail(&bo->shadow->tbo, NULL); - } + spin_lock(&glob->lru_lock); + ttm_bo_bulk_move_lru_tail(&vm->lru_bulk_move); spin_unlock(&glob->lru_lock); - return r; + return 0; } /** diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h index 67a15d4..85d57bb 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 has bo validated on evicted list */ + bool validated; }; 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