From patchwork Thu Dec 21 09:42:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "He, Hongbo" X-Patchwork-Id: 10127245 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 50E7D603B5 for ; Thu, 21 Dec 2017 09:45:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 392B629B77 for ; Thu, 21 Dec 2017 09:45:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2E1A229B88; Thu, 21 Dec 2017 09:45:01 +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=-4.1 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID 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 966DA29B77 for ; Thu, 21 Dec 2017 09:45:00 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1C5AA89F3C; Thu, 21 Dec 2017 09:45:00 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM03-DM3-obe.outbound.protection.outlook.com (mail-dm3nam03on0085.outbound.protection.outlook.com [104.47.41.85]) by gabe.freedesktop.org (Postfix) with ESMTPS id DE77689F3C for ; Thu, 21 Dec 2017 09:44:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=Oka7efaj0aQYgXHmVwXVMhupcKDMD1Oj1VCmzpoLJQw=; b=dFB6p2EQh+/FeFEWwH/Yo+nxeyjv3vLFFOwROm6JOjubLlM9FG4zMZwgmVdRg5ZTJ2A5z0Eg9B5V3jII+LgofNoBDEI63jf1xJdVmbzGFcYuNQXs5IrTK5KpBHJqbHprNka2SOJJlyf2GU1wD9ZrxTnqR1BQNNXsCSPRX7fksCo= Received: from BN4PR12CA0017.namprd12.prod.outlook.com (10.164.241.27) by CY4PR12MB1446.namprd12.prod.outlook.com (10.172.71.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.323.15; Thu, 21 Dec 2017 09:44:56 +0000 Received: from BY2NAM03FT022.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e4a::200) by BN4PR12CA0017.outlook.office365.com (2603:10b6:403:2::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.218.12 via Frontend Transport; Thu, 21 Dec 2017 09:44:56 +0000 Authentication-Results: spf=none (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; lists.freedesktop.org; dkim=none (message not signed) header.d=none;lists.freedesktop.org; dmarc=permerror action=none header.from=amd.com; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from SATLEXCHOV02.amd.com (165.204.84.17) by BY2NAM03FT022.mail.protection.outlook.com (10.152.84.225) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.20.302.6 via Frontend Transport; Thu, 21 Dec 2017 09:44:56 +0000 Received: from roger-build-server.amd.com (10.34.1.3) by SATLEXCHOV02.amd.com (10.181.40.72) with Microsoft SMTP Server id 14.3.361.1; Thu, 21 Dec 2017 03:44:52 -0600 From: Roger He To: Subject: [PATCH 5/5] drm/ttm: enable swapout of per VM BOs during allocation Date: Thu, 21 Dec 2017 17:42:53 +0800 Message-ID: <1513849373-7970-5-git-send-email-Hongbo.He@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513849373-7970-1-git-send-email-Hongbo.He@amd.com> References: <1513849373-7970-1-git-send-email-Hongbo.He@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)(376002)(39380400002)(39860400002)(396003)(2980300002)(428003)(199004)(189003)(478600001)(72206003)(48376002)(50466002)(7696005)(51416003)(104016004)(76176011)(2906002)(97736004)(59450400001)(5660300001)(47776003)(8936002)(81166006)(4326008)(105586002)(106466001)(2351001)(68736007)(53416004)(575784001)(86362001)(50226002)(2950100002)(6916009)(356003)(81156014)(8676002)(77096006)(305945005)(316002)(36756003)(16586007)(53936002); DIR:OUT; SFP:1101; SCL:1; SRVR:CY4PR12MB1446; H:SATLEXCHOV02.amd.com; FPR:; SPF:None; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BY2NAM03FT022; 1:CnZ8jb5uA621KT/dp/3GOozK1/jjxKv4/GNRK5IgoNQ8rU+Iz+0FiU9s/Lms0g6Pn43dZYrzlh7ijSPQG/fSEqEdIF0uXfCT2ETY5ChRMXrXikLsGNWOmoG9uQ6LVdAV X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8eea637f-6764-412e-6212-08d548577e6b X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(5600026)(4604075)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(2017052603307)(7153060); SRVR:CY4PR12MB1446; X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1446; 3:EMoSmxK97/Os/+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zIIA4coOQqM8cOE1CMnTQ/2r9xTG2HR7ypej84iGE3GYCYfKYj67BjoDt+2ITb5B07Y04/SwQ0GhiGhX33Vg6IDXoCTBQUHHVR1Q3Ken6EeLrhnDkZUh24+XwEGiOqjG+NVJRZGr/wHggH5pN2ZnntZZpFBLJYjjefa/OTFYNZHjCxlM53JFlfbB/kA4aDYvBzUeDio3Ot6DzYNfLERUTMnOOcx9wynV1HKZ6ibI+bDufD0jk2s1KwDM7uTuGz/+oGxcNxGEIqL+KtsuEQLRUw+8zvFTDrBdOjWhJXZwr15HakiPJg1BVcHULFPbXWaOlh1VlvjKRlPwuKVINJhgHW8E90aG38RnV6ZW1TGFQUr7guGnMdSdxu9regYbuf0RSeKJJS/CdInGp4L9to64+3iE3eJNMhHsuoFd/MnoHatyiq8JIUCsJSZ97/XeWmhFnZCdw1KH9obG5v X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040470)(2401047)(8121501046)(5005006)(3002001)(93006095)(93003095)(10201501046)(3231023)(6055026)(6041268)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123562045)(20161123564045)(6072148)(201708071742011); SRVR:CY4PR12MB1446; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:CY4PR12MB1446; X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1446; 4:DjUVrgqQjLdsuhbMDZ4Gy2A+Izp7hXC2qW/MLOEcjY4UQ/dALnfbLq0UvhdEhetj/D6Mo1+A7qpaaJLKrd5dxPJrJLOsKL4pEQSMQCPBYntU+bf5n0OQrKLOzXI9Dla3rUmRMp1Y8mz9CCnF9kHJQKBoHVOEMRGob8XHXLaR6SyrfnSZCnGV9uF3M1haaw8f+8UNd5KlwiA3Wd4L/GzgiN07Oqv0mb4g+JEmHQKvtQnlLgvGx0Ty/t8KwTwXOYej9cmEvDD65Z9ORnKqHp3BTEFdipgKR83F8uyRMkFuwZxPmoxptK5mupwrkFGhsr/q X-Forefront-PRVS: 0528942FD8 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY4PR12MB1446; 23:4o/vG8+LbjBXru0ygZYJT1PpdN1p92u7OMxo84aYv?= =?us-ascii?Q?KLSLb8QvwSCfZWkFTpTOg/TcUY/DETNmouA7MdEyFzWUYsR83DjB8HaEnf1Z?= =?us-ascii?Q?NYDn+AWgszwqnEeU5v7a//4Tgocmb8FP1n5E/vmXV+m30Pus0CV/Ipusj4Wo?= =?us-ascii?Q?QV4KXwkCalw1mDpVTkfBXFf3nVkJfa8XyleJ5lP011L13kgMFKf9ZSe9K7QA?= =?us-ascii?Q?YVDyZyMcCjaI1RF4Uln5tV7/YTOa+NG5XV+pyUX6Y9wIub+qstnkLrIc01tb?= =?us-ascii?Q?xzwywOKorQeAWPqrVb1W8azSn6k29iARndiKfQEJuain99Mftwik1XyrwTqh?= =?us-ascii?Q?xUmAfQBuFsmFXm8DujaBubzo4uOBN60xq1ADtcYEy6Jqo2ybl9bJamOe3mUd?= =?us-ascii?Q?ZeUCQpsid/FEcRzoYz+tIJfO3xa9oWARbJ06Bnq5P6oUHKI8oiJDFEqTYjwA?= =?us-ascii?Q?zP7X+41L/s8O55mjHaw5tBu1l1/PZQ5EjmxUP0bwSAruKBWY8MYWG8ociYgm?= =?us-ascii?Q?BCaBWittdnkHPo+jEjB5I1JeLnQi/sEYeih5d7yN8WGOD4Y92C6NOadtLTfJ?= =?us-ascii?Q?umFAGTLO5PnquQx9blK7eCNIblcsG08Z70qwJJWS1JNq6rpsUQtUAwUzjz+1?= =?us-ascii?Q?f9ZHUgpx2tjGUuEv2cADgLu50obOEAeI6oEGoTAmU+NrntIOH0mvAG8itmWR?= =?us-ascii?Q?yRkaWXKN76ZBpapFu8QHOgSD8D3L8c0SgEO8TiMeCs5en3COuq/dqZGupaNd?= =?us-ascii?Q?7PT8u4r/tmmlsuv/ZRjj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glyFlMHQKAR9nLyER2vaylM12a5atQGY42Lb17BSMlY1f8pBc8+xJzfw420Szh3srXcATKBcTELPsk7RHkQ/llbzO5SV0W1yNKo4yV059fvt1J9FwBgVadG4ilw6zp//pXp3YCrWVEUXk6hjAhF1sAjnNgrA9LJF6zNRRf4/r3oM8oQ+p4Mt3oTDw0x8xryDqZMnhSopDjCs1GJvIqQLuQMkYwRVR+SQbKZy+XuwhwvzYthxGGjegjidlsB6kzI SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1446; 20:MwOV4hcclc52KWZY1SDqREDvafTOUW1nsJs1gcXYC8fu4P/zU54froviTXPdgvaQNLMi1hT+67fBX58X9j/q7o76C5DGxBglFeBP+SV1ZVJU8Ype9l4jl//aNMts6+Gy5ietLtgjFPLuWMv6+eTOgtyIFYDIDcH5yaB04Z4yWLUlRXuBU8VJkjwgAbO45SO/xUMbHHwpxzgFtg8gW7Yi0EsSrdrD7c9pBQG3tvar/6gf0biwv0zEIqZZGoClmgMP X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Dec 2017 09:44:56.1365 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8eea637f-6764-412e-6212-08d548577e6b 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: CY4PR12MB1446 Cc: Roger He X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP if the bo shares same reservation object then not lock it again at swapout time to make it possible to swap out. Change-Id: I1e87954564f38ad298bf6e4ff88c9f26f291a62d Signed-off-by: Roger He --- drivers/gpu/drm/ttm/ttm_bo.c | 15 +++++++++++---- drivers/gpu/drm/ttm/ttm_memory.c | 12 ++++++++---- include/drm/ttm/ttm_bo_api.h | 3 ++- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index 313925c..ecb8916 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -1686,18 +1686,20 @@ EXPORT_SYMBOL(ttm_bo_synccpu_write_release); * A buffer object shrink method that tries to swap out the first * buffer object on the bo_global::swap_lru list. */ -int ttm_bo_swapout(struct ttm_bo_global *glob) +int ttm_bo_swapout(struct ttm_bo_global *glob, struct ttm_operation_ctx *ctx) { struct ttm_buffer_object *bo; int ret = -EBUSY; + bool locked; unsigned i; spin_lock(&glob->lru_lock); for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) { list_for_each_entry(bo, &glob->swap_lru[i], swap) { - ret = reservation_object_trylock(bo->resv) ? 0 : -EBUSY; - if (!ret) + if (ttm_bo_evict_swapout_allowable(bo, ctx, &locked)) { + ret = 0; break; + } } if (!ret) break; @@ -1773,7 +1775,12 @@ EXPORT_SYMBOL(ttm_bo_swapout); void ttm_bo_swapout_all(struct ttm_bo_device *bdev) { - while (ttm_bo_swapout(bdev->glob) == 0) + struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + }; + + while (ttm_bo_swapout(bdev->glob, &ctx) == 0) ; } EXPORT_SYMBOL(ttm_bo_swapout_all); diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c index 102b326..aa0c381 100644 --- a/drivers/gpu/drm/ttm/ttm_memory.c +++ b/drivers/gpu/drm/ttm/ttm_memory.c @@ -211,7 +211,7 @@ static bool ttm_zones_above_swap_target(struct ttm_mem_global *glob, */ static void ttm_shrink(struct ttm_mem_global *glob, bool from_wq, - uint64_t extra) + uint64_t extra, struct ttm_operation_ctx *ctx) { int ret; @@ -219,7 +219,7 @@ static void ttm_shrink(struct ttm_mem_global *glob, bool from_wq, while (ttm_zones_above_swap_target(glob, from_wq, extra)) { spin_unlock(&glob->lock); - ret = ttm_bo_swapout(glob->bo_glob); + ret = ttm_bo_swapout(glob->bo_glob, ctx); spin_lock(&glob->lock); if (unlikely(ret != 0)) break; @@ -230,10 +230,14 @@ static void ttm_shrink(struct ttm_mem_global *glob, bool from_wq, static void ttm_shrink_work(struct work_struct *work) { + struct ttm_operation_ctx ctx = { + .interruptible = false, + .no_wait_gpu = false + }; struct ttm_mem_global *glob = container_of(work, struct ttm_mem_global, work); - ttm_shrink(glob, true, 0ULL); + ttm_shrink(glob, true, 0ULL, &ctx); } static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob, @@ -520,7 +524,7 @@ static int ttm_mem_global_alloc_zone(struct ttm_mem_global *glob, return -ENOMEM; if (unlikely(count-- == 0)) return -ENOMEM; - ttm_shrink(glob, false, memory + (memory >> 2) + 16); + ttm_shrink(glob, false, memory + (memory >> 2) + 16, ctx); } return 0; diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h index 24a8db7..f1c74c2 100644 --- a/include/drm/ttm/ttm_bo_api.h +++ b/include/drm/ttm/ttm_bo_api.h @@ -752,7 +752,8 @@ ssize_t ttm_bo_io(struct ttm_bo_device *bdev, struct file *filp, const char __user *wbuf, char __user *rbuf, size_t count, loff_t *f_pos, bool write); -int ttm_bo_swapout(struct ttm_bo_global *glob); +int ttm_bo_swapout(struct ttm_bo_global *glob, + struct ttm_operation_ctx *ctx); void ttm_bo_swapout_all(struct ttm_bo_device *bdev); int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo); #endif