From patchwork Fri Aug 10 11:55:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Huang Rui X-Patchwork-Id: 10562649 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 157EA13B4 for ; Fri, 10 Aug 2018 11:58:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 05D612B672 for ; Fri, 10 Aug 2018 11:58:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ED2D82B960; Fri, 10 Aug 2018 11:58:33 +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 6B5BD2B672 for ; Fri, 10 Aug 2018 11:58:33 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 165D96E87F; Fri, 10 Aug 2018 11:58:32 +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-dm3nam05on0601.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe51::601]) by gabe.freedesktop.org (Postfix) with ESMTPS id 518266E87F; Fri, 10 Aug 2018 11:58:30 +0000 (UTC) Received: from CY1PR12CA0079.namprd12.prod.outlook.com (2a01:111:e400:c42b::47) by DM2PR12MB0250.namprd12.prod.outlook.com (2a01:111:e400:50d1::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1038.20; Fri, 10 Aug 2018 11:58:27 +0000 Received: from BY2NAM03FT035.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e4a::208) by CY1PR12CA0079.outlook.office365.com (2a01:111:e400:c42b::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1038.22 via Frontend Transport; Fri, 10 Aug 2018 11:58:27 +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 BY2NAM03FT035.mail.protection.outlook.com (10.152.84.223) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.20.1038.3 via Frontend Transport; Fri, 10 Aug 2018 11:58:25 +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, 10 Aug 2018 06:58:22 -0500 From: Huang Rui To: , Subject: [PATCH v2 4/5] drm/amdgpu: use bulk moves for efficient VM LRU handling (v2) Date: Fri, 10 Aug 2018 19:55:58 +0800 Message-ID: <1533902159-14232-5-git-send-email-ray.huang@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1533902159-14232-1-git-send-email-ray.huang@amd.com> References: <1533902159-14232-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)(396003)(136003)(346002)(376002)(39860400002)(2980300002)(428003)(199004)(189003)(2870700001)(50226002)(86362001)(76176011)(23676004)(97736004)(4326008)(450100002)(47776003)(7696005)(2906002)(356003)(5820100001)(50466002)(6666003)(14444005)(305945005)(8936002)(36756003)(486006)(105586002)(110136005)(53936002)(53416004)(476003)(126002)(2616005)(478600001)(316002)(68736007)(11346002)(446003)(186003)(104016004)(5660300001)(54906003)(8676002)(81156014)(81166006)(336012)(106466001)(77096007)(26005)(72206003)(561944003)(426003); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR12MB0250; H:SATLEXCHOV01.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoDomainNonexistent; A:1; MX:1; X-Microsoft-Exchange-Diagnostics: 1; BY2NAM03FT035; 1:N0ByxhP99YVF6RW7uVBpbqrcZKVMI0ufoDQ6odfbTiKL8M6aZUdg17/ISlbnVNSTFaX8iXhxrK8oo97htXdZF44aFmWwwkIA2UFlzbLJWAvrqcYv50iVsNNm22AZrIch X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3f713eec-02bf-4fd2-5880-08d5feb894d9 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989117)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(2017052603328)(7153060); SRVR:DM2PR12MB0250; X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0250; 3:62cgKOufA5k9feM8Sq043gRHV5PGIJupjxk8rOdVKdqh1N2O/93h/yX5vWwQClwGEuE4mt2DKGo2VA5qi3C8JxqrsfqTacU4hBydVt4JUc+9lmqyIl2dPATHDQGqriSNpSqzOmUCrAjdPO6ag6DoR6uFDNLYburBUg33V9zzQscqcRYGPBlb1QWio9A+avs64QKHYX4xJ5/ot53ghxWt/kxNRsgbiFQN6Slua6eG3WB2rUxYFjSeHWnSYQ731PQYzSXL7Xpb9xGoSTnjypmK2+rXd+5Q/aseZCLdR9k/KmQyqtxAnwBSNu1pMGAB0trlUHvNDAOUagYFaAw3b7P0txu0inb70LM9mOsqUkzT+yQ=; 25:f1jGDIu4CkPcg8W9bqHZBBNS18Btg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o+o2mp83LZFOj0OED9xD9a8jOInGE+GrxN4R7C1udVSPTK7RGECUrkppOEsAmYrc1gchKlb0xppvlhmNfGwQTGCkb/YzPg 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)(3002001)(10201501046)(6055026)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123560045)(20161123564045)(20161123558120)(6072148)(201708071742011)(7699016); SRVR:DM2PR12MB0250; BCL:0; PCL:0; RULEID:; SRVR:DM2PR12MB0250; X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0250; 4:LFx7S1husRRHN5GogPxHnCfC1atalZRD3tGiOpW2NMwhMqHRC+dCh/BUhQjT2G9hzjxWXb4Ox9+Njpq/6ZmY4AWd954Eb/rgyeInMyXRtivwYUI8VVvmdacSc87aE27+CLJIJTV7rlxzohkh20VmeowV8J1wuR8oe0DhcSwAwAqtnBB9P3qjSBXO782g577ZipUy1bNVK/BBmxczA85gnYL2gI7ZExWtlUsC9LDk6AVGqPwpRF/2TpA3j0HNBu9DO2vEeEs82+Ev60GBBw1JAvX0G+dEx94Lc9RXv6Iki5IWYESHMpnv30UcticqNbeb X-Forefront-PRVS: 07607ED19A X-Microsoft-Exchange-Diagnostics: =?utf-8?q?1=3BDM2PR12MB0250=3B23=3AQqvI/Iu?= =?utf-8?q?jzkRylIXYX7hr8WzpQwQFHst/5z9DVm6U05TuDp0LgkJ++Nbw0z3AAY7wrqOQLBzW?= =?utf-8?q?0faxvd5B3OhZAHlsJYXZc8A8coHwQomzkKXXQPjph+ae3yZzxKVRa9x1KNOvwZ/+2?= =?utf-8?q?7BpY6JDpI23algR4uia/lpMAXMaPCh/MTD0sjMorztDcB/OmtlAbvn615itX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6juDzJ7m4Hayzhz9ORBF+mHmOwQlJJXHVeHoFvULxZlc502qyq3MtWNv8BKWTO5W1MvGYfisDyenw8fpSSzokLchbRvkZGBzGy8dOF4QEfeEYoECebQvSnHr1Fg6V5Ih/ot6Gc0SOvZCeboeiXNDY73WfQTZd+o=; 7:TpVHX14pYZYXm+Y0mLc8BJcp6wLC/vbIU1Twmpa3P9C/0FkwOJK2x+TP0P65XkNfrYUU7lYTe0I63s2bn7GuHxAf3Je+GpeHzRT85uR03xcfs2iBHS0PHch5SlPk5pn5B7DnJrV9Qfl58TXHHhjHmKsX9SrQ+WlZQwM+2su7ySs2GBrioSF/g1biCwnclTL0O9P+FNuWakXar8q1d+xs/vcum1nzM8x5e/e3SttnC3Dtd4AAUSsKTlcCc6lPTITg SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0250; 20:RYuhDKYK8G3bsd8HOw9INOwffW8aIoQVyb/LsH25FcHXB1azBRtT2P6fKlRh2gYbZhuRavFq/IyUaKtU5MLv/11h1/tVCdW5doHOR+CrGBZRE/MlmucuOijTTrCvNlSi9CtObyC7IDmP3H6bU7waw6iW+P16EReibMP4Rc05DVbGPmIN+cl/2pHCTUjh9DahapRCyERkNiaqtA3304PgudR3WMC4d2rDLi4PY2ruggAEegXegXbH4AWNa6yusnUq X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Aug 2018 11:58:25.9690 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3f713eec-02bf-4fd2-5880-08d5feb894d9 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: DM2PR12MB0250 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. Signed-off-by: Christian König Signed-off-by: Huang Rui --- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 75 ++++++++++++++++++++++++++-------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 4 ++ 2 files changed, 63 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..81fb1ac 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c @@ -268,6 +268,55 @@ 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 + * + * @adev: amdgpu device pointer + * @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_device *adev, + struct amdgpu_vm *vm, struct list_head *list) +{ + struct amdgpu_vm_bo_base *bo_base, *tmp; + + list_for_each_entry_safe(bo_base, tmp, 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(adev, vm, &vm->idle); + amdgpu_vm_move_to_lru_tail_by_list(adev, vm, &vm->relocated); + amdgpu_vm_move_to_lru_tail_by_list(adev, vm, &vm->moved); + spin_unlock(&glob->lru_lock); +} + +/** * amdgpu_vm_validate_pt_bos - validate the page table BOs * * @adev: amdgpu device pointer @@ -286,6 +335,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 +345,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 +357,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 {