From patchwork Mon Dec 25 06:07:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "He, Hongbo" X-Patchwork-Id: 10132309 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 977D16037D for ; Mon, 25 Dec 2017 06:08:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8957128531 for ; Mon, 25 Dec 2017 06:08:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7CB4F28B88; Mon, 25 Dec 2017 06:08:20 +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 0C87E28531 for ; Mon, 25 Dec 2017 06:08:19 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4447A89D44; Mon, 25 Dec 2017 06:08:19 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM02-BL2-obe.outbound.protection.outlook.com (mail-bl2nam02on0056.outbound.protection.outlook.com [104.47.38.56]) by gabe.freedesktop.org (Postfix) with ESMTPS id 23D4189D44 for ; Mon, 25 Dec 2017 06:08:17 +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=3p8MXGe78O2uqmXeFkEoE/RPbv71FRAgb22dl83VQI0=; b=EkA65FyzN5oJk5g8B6cFaQfVqtalLGJUIrxm2krpoWu/OpbWM/wu3UTZaKBH9E7F6/L+7W5rhNEf0YVYRFPCEY3nWBxC6glXMsP5eoFAFIGdP+ZPze1mGJ4L6XPLztOzMiw1I0sfilzPZYrlCVJQtKluAPKDrTNZ1GGCBiER0vs= Received: from CY1PR12CA0084.namprd12.prod.outlook.com (10.163.230.52) by BN6PR1201MB0049.namprd12.prod.outlook.com (10.174.114.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.345.14; Mon, 25 Dec 2017 06:08:15 +0000 Received: from DM3NAM03FT064.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e49::202) by CY1PR12CA0084.outlook.office365.com (2a01:111:e400:c42b::52) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.345.14 via Frontend Transport; Mon, 25 Dec 2017 06:08:15 +0000 Authentication-Results: spf=none (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; shipmail.org; dkim=none (message not signed) header.d=none; shipmail.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 SATLEXCHOV01.amd.com (165.204.84.17) by DM3NAM03FT064.mail.protection.outlook.com (10.152.83.1) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.20.345.12 via Frontend Transport; Mon, 25 Dec 2017 06:08:13 +0000 Received: from roger-build-server.amd.com (10.34.1.3) by SATLEXCHOV01.amd.com (10.181.40.71) with Microsoft SMTP Server id 14.3.361.1; Mon, 25 Dec 2017 00:08:11 -0600 From: Roger He To: Subject: [PATCH 2/3] drm/ttm: add new function to check if bo is allowable to evict or swapout Date: Mon, 25 Dec 2017 14:07:31 +0800 Message-ID: <1514182052-20798-2-git-send-email-Hongbo.He@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1514182052-20798-1-git-send-email-Hongbo.He@amd.com> References: <1514182052-20798-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)(979002)(39380400002)(396003)(376002)(39860400002)(346002)(2980300002)(428003)(189003)(199004)(7696005)(356003)(106466001)(68736007)(8936002)(50226002)(104016004)(105586002)(305945005)(53416004)(2351001)(97736004)(51416003)(47776003)(76176011)(2950100002)(86362001)(53936002)(478600001)(81166006)(81156014)(6666003)(72206003)(6916009)(8676002)(5660300001)(59450400001)(50466002)(54906003)(36756003)(316002)(4326008)(77096006)(16586007)(48376002)(2906002)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1101; SCL:1; SRVR:BN6PR1201MB0049; H:SATLEXCHOV01.amd.com; FPR:; SPF:None; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; DM3NAM03FT064; 1:xYsuUQjuHShYCGnM6U9OLVdhMJQMthVarn1VmcAHjpK1XGXqtOoNoM7lg0i+kLd0WMNfEqmQjxw/gJWI3VUhxTkL/jqlVx260J5zLpQtkROMb6NnWCkrgjmuldpQRHE6 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ecfb961d-c440-4449-dbbe-08d54b5de256 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060); SRVR:BN6PR1201MB0049; X-Microsoft-Exchange-Diagnostics: 1; BN6PR1201MB0049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StwVdwjHKeLtsa2vPoGIRCxYYZDIjQogF5FoHZXmsum2+7cwsEORQRd+jOzar0vJQxVnO2qyMPRFPa1cWjgIYM1h56hOW0yieo6Cd8wo7XHF5TRJKQXq277tiG8FGWiEhrrxpHEwBZ6amtkn893N5+5JHI6j9rpL8w5HoYOMgfc3jbovkDbNYRegKPSqMUlqx5vCPF7Q3UCd/G6r46pH2c/FR5xonw+8NZjWFnju0QyvEHHxq2MTI/MoSbk96leGc3Hq7ZHWh73QLTVtmNaNUq581KYBYgnGwwhrU8EQF/lFEtolQieeokozuacQaapTcUoZr5c7CMrBYuUrjQ0Sbk3s80nCJ/KU0Y0XXZW2UGv2poHVTnqk84XxGY7NSgtvvCtw0TqbI7scA9dz7+Fbr5zPGP6Ev9ygwjI3VPWYj6uiwB2V+xkSce/6ajVvvurjnlI7zBR+Hw8AkMmMHcZ7htC 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)(93006095)(93003095)(3002001)(10201501046)(3231023)(944501075)(6055026)(6041268)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123558120)(20161123564045)(20161123560045)(6072148)(201708071742011); SRVR:BN6PR1201MB0049; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:BN6PR1201MB0049; X-Microsoft-Exchange-Diagnostics: 1; BN6PR1201MB0049; 4:S17wRfz1hRlcV5qIHQ/nHDSxK58lNED4HmxkEzJelDwrdXSOhOC6RTkkMew86FjgtbnmyCx0E+kcGA+88L9XXKtMBB8o/adH0uk5n1y058tuC5ClS29smaWDQG531JnCYo8rAJTGzgkI+EDZ9sxAqaQuDaHAni9VxFNk0H5iORXWr8p4DZoh0t4+Z8AJ+BPwHDj3X8skHlbKLQN2A7YxYiZaXs21yddCe4pbfh2H+KNzlfcFDH6a/GX3ieof7HV7eo7r0vH4umXSGknD5JxCqXrsJ4bmAgs95euAp6eBd0ZSrK6/TIXdt3grbAaJVnSN X-Forefront-PRVS: 0532BF6DC2 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN6PR1201MB0049; 23:oQfHadRbwHyQ40vHKM+BbZUsWE/YGzFFSzwiXf3?= =?us-ascii?Q?kUOMl7dD/p+dzIlo/XzKh7p/nM0hXT7WGyt+4k78WDPf7kRozEytEMIrgMaQ?= =?us-ascii?Q?7MhavuC1zsp4zpwpDKv7LVmsGSzKBBl48ucHwJBmCHo8A24pWa/zqGBA+1PM?= =?us-ascii?Q?PiffpjrAw8npZRlqdOQQJQQ5Ze/uekPo6O/ib5EYRe7gz3KB7A6jIvK7S39m?= =?us-ascii?Q?8D+FCAo0sIX1Chb6UOEvCi7Z6OPTBIggb5/5GfroN/cX8eRKTQf2osstdx18?= =?us-ascii?Q?WFiyfq2KkYboZkF22VTkDpnC8GdyEl9cFrmsTNAy1rU8uyisvGAe1u9ldbSf?= =?us-ascii?Q?56vvFmtoXg3BiDCDC0YzwQ9ovWXCIsBlIncXH6x/khFUpCzy6uRyjtQW5Aed?= =?us-ascii?Q?u8l7enQvL/pDWH7+eWtGvcUSmmpSLazKPr0DDkEr3ePuOlghIA5LTYhFOQ3x?= =?us-ascii?Q?bdXeDUyW97iEQPlIWWb7dByItwyeF/2hOo+T/pnRHSDmcI6A9hl+Bk+Xm2E9?= =?us-ascii?Q?7Yfmt0Sb5464kFpztkdbAtniorM0GYRLMwnNrEHkqDbjB825qhPfs1WOSWRo?= =?us-ascii?Q?+i+tToWqJpJvhYyftvN37A+PI9mFgT/4VCU1pCcBm+gkKQKQSYCfIbtl8DI9?= =?us-ascii?Q?QAFPuUkGSVg8hbQ6IaP/Bkhqpq0tcVy3BTymumKYO9BnQtWbTxc24HhIitYO?= =?us-ascii?Q?/b9S8p6N9nEmght+fmZJ84L9PRTo35WN8P1svoIFap0lkI21+lwGkkxpbvGn?= =?us-ascii?Q?jGyxfK2CMT3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:OEO1B3AU4rpGur4T+6N/lYicXbj1SPuI/4ImlfoQSLjrcp0KqKSjWx7yYCvw8jhypaeQgbwZcBDAQFCth9NgCUQrglgpBcyPFn3i9GdjN3Q=; 7:LD2btaRTUlBjql6ymEd/23d5xeD6V+AV2LY5GD0P2W49RxYH9Lb0hxSL2Om4b4Cd+B50yuUmOasUJpOC++q7HAUge6iqjPoLQDR5XzIxBfjEGR+ndVMupoHNPCjD6aFxm+IG51Py4gY5Q6Q/JHX1XAXQCeiR0nRGCOWNqpCn5/y3koWuwbWQfHHoTgnBZ+l0E+8PktP5ffSB7ieILX6TGJGHUcbeqHOLzFdKQlMmqvTEzcYA7rMz5JDRyV41BH9a SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BN6PR1201MB0049; 20:TM7mSFuqqe2oWGAYqIrwQhrq7yQA9xlH4zTHLdEHoVfVm4eeaUqhLS/+dxUU8Mr/1Il9XeYLbTTcxEz0Sg9GUibFGalF8vfK8RDV6L/85/Df+EgjbRy0hurTfvS1rDvGNd6wIBgi9unrxXcNBcqCFfYssMc9apF8K/XiJe4Z55RJIxw341INqxubcT9kdCxJz/I8yabTxyELJ24w6USnB2pBerRRhyZnOgef+uxxZGgzO4o7E2tFwVaCkZA9pqCO X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Dec 2017 06:08:13.6052 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ecfb961d-c440-4449-dbbe-08d54b5de256 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: BN6PR1201MB0049 Cc: Roger He , Christian.Koenig@amd.com 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 extract a function as ttm_bo_evict_swapout_allowable since eviction and swapout can share same logic. v2: modify commit message and add description in the code Change-Id: I80a475a93fceed8d66d74a1832c815a0756341ac Signed-off-by: Roger He Reviewed-by: Christian König for now. --- drivers/gpu/drm/ttm/ttm_bo.c | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index e7595b4..5e64091 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -706,6 +706,34 @@ bool ttm_bo_eviction_valuable(struct ttm_buffer_object *bo, } EXPORT_SYMBOL(ttm_bo_eviction_valuable); +/** + * Check the target bo is allowable to be evicted or swapout, including cases: + * + * a. if share same reservation object with ctx->resv, have assumption + * reservation objects should already be locked, so not lock again and + * return true directly when either the opreation allow_reserved_eviction + * or the target bo already is in delayed free list; + * + * b. Otherwise, trylock it. + */ +static bool ttm_bo_evict_swapout_allowable(struct ttm_buffer_object *bo, + struct ttm_operation_ctx *ctx, bool *locked) +{ + bool ret = false; + + *locked = false; + if (bo->resv == ctx->resv) { + reservation_object_assert_held(bo->resv); + if (ctx->allow_reserved_eviction || !list_empty(&bo->ddestroy)) + ret = true; + } else { + *locked = reservation_object_trylock(bo->resv); + ret = *locked; + } + + return ret; +} + static int ttm_mem_evict_first(struct ttm_bo_device *bdev, uint32_t mem_type, const struct ttm_place *place, @@ -721,21 +749,13 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev, spin_lock(&glob->lru_lock); for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) { list_for_each_entry(bo, &man->lru[i], lru) { - if (bo->resv == ctx->resv) { - if (!ctx->allow_reserved_eviction && - list_empty(&bo->ddestroy)) - continue; - } else { - locked = reservation_object_trylock(bo->resv); - if (!locked) - continue; - } + if (!ttm_bo_evict_swapout_allowable(bo, ctx, &locked)) + continue; if (place && !bdev->driver->eviction_valuable(bo, place)) { if (locked) reservation_object_unlock(bo->resv); - locked = false; continue; } break;