From patchwork Mon Dec 25 06:17:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "He, Hongbo" X-Patchwork-Id: 10132313 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 EBC216037D for ; Mon, 25 Dec 2017 06:17:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB773287C5 for ; Mon, 25 Dec 2017 06:17:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CE57C28B24; Mon, 25 Dec 2017 06:17:55 +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=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 12763287C5 for ; Mon, 25 Dec 2017 06:17:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C7D7089AFF; Mon, 25 Dec 2017 06:17:53 +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-bl2nam02on0084.outbound.protection.outlook.com [104.47.38.84]) by gabe.freedesktop.org (Postfix) with ESMTPS id 19E8789AFF for ; Mon, 25 Dec 2017 06:17:51 +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=f4PxTz1JcLLsRkVw9hmrxQOEpWmZDfSSZWE3wq0hYRc=; b=OYze7g0B2xU3Jbrbjp9wgG5+fSpah1k75wLA4u8lglKg0PRr5jViiI+qysVI1OOzsAbweYc3AKm6QNkTtbGvThPNATGl095Ey5kzu2GB2o6waRXOnVH6fN6QMU7/09Jqqpg+su65N1cQfNaO0kzRoFGmmdWY6nykgtSo8EJjmds= Received: from MWHPR1201MB0127.namprd12.prod.outlook.com (10.174.98.142) by MWHPR1201MB0128.namprd12.prod.outlook.com (10.174.98.143) 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:17:50 +0000 Received: from MWHPR1201MB0127.namprd12.prod.outlook.com ([10.174.98.142]) by MWHPR1201MB0127.namprd12.prod.outlook.com ([10.174.98.142]) with mapi id 15.20.0345.016; Mon, 25 Dec 2017 06:17:48 +0000 From: "He, Roger" To: "He, Roger" , "dri-devel@lists.freedesktop.org" Subject: RE: [PATCH 2/3] drm/ttm: add new function to check if bo is allowable to evict or swapout Thread-Topic: [PATCH 2/3] drm/ttm: add new function to check if bo is allowable to evict or swapout Thread-Index: AQHTfUbG+VT6/pku9Uq9//rdrQZXYKNTlTdw Date: Mon, 25 Dec 2017 06:17:48 +0000 Message-ID: References: <1514182052-20798-1-git-send-email-Hongbo.He@amd.com> <1514182052-20798-2-git-send-email-Hongbo.He@amd.com> In-Reply-To: <1514182052-20798-2-git-send-email-Hongbo.He@amd.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Hongbo.He@amd.com; x-originating-ip: [116.228.147.241] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; MWHPR1201MB0128; 7:lnIvyfWq0Hrw3FnRxw/KESw4TijiEfUOkSPpEvjspLJD2I88cb4vI0MaQfWGjhVJsYp5Nn9KGhQIjj+45/4j1ov1y1465Jzsw7iQUiTZwCrpQka/wsCSatN+iqCl5e36j4K+m1CrdjEQpBit1oDcrUaMbfkqu1Cjx3afiqrllC5PgkxIzqfd0KlY88vqKgZ+SH2HXd5SETfit/ZxUsMO8uQCwqNHh/LdmP5mf9pHvi5X3ZG3fmoD7at6zhjMCjJB; 20:PeSDPkK7EX78LvQNwanN9pATspusdkvbUj/ihCzl1Vn08YOio2yiHYIz67TAp7Z62MiTmi9xfTYuyxb+heORCqSM0/ZjI4xGtGHj49RtlaEhDm6cYKc1BwClIzSS4ap+BCtJ5DLOiubI1EpA/BB2tv5cChJ0aIxpWeteJys+gTUbB4iItNUHbugC7wMTw4KQB0+bwPAc/VfPE7Nu/7FBmffDd3M5LgdFz5h4+F3wPoGwtWhBMA81Oq57OavvNpCd x-ms-exchange-antispam-srfa-diagnostics: SSOS;SSOR; x-forefront-antispam-report: SFV:SKI; SCL:-1; SFV:NSPM; SFS:(10009020)(376002)(39850400004)(396003)(39380400002)(366004)(346002)(13464003)(189003)(199004)(54906003)(8676002)(68736007)(229853002)(81156014)(6436002)(81166006)(110136005)(3280700002)(55016002)(2900100001)(97736004)(6306002)(77096006)(53936002)(86362001)(6246003)(3660700001)(6116002)(105586002)(53546011)(2906002)(4326008)(59450400001)(106356001)(3846002)(25786009)(6506007)(5660300001)(305945005)(7736002)(33656002)(2950100002)(316002)(478600001)(14454004)(7696005)(72206003)(66066001)(9686003)(2501003)(102836004)(99286004)(8936002)(966005)(76176011)(74316002); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR1201MB0128; H:MWHPR1201MB0127.namprd12.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; x-ms-office365-filtering-correlation-id: b42c616f-ed64-42ac-5508-08d54b5f38cb x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(3008032)(48565401081)(2017052603307)(7153060); SRVR:MWHPR1201MB0128; x-ms-traffictypediagnostic: MWHPR1201MB0128: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(767451399110)(217544274631240); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040470)(2401047)(8121501046)(5005006)(3002001)(93006095)(93001095)(3231023)(944501075)(10201501046)(6055026)(6041268)(20161123560045)(20161123558120)(20161123564045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:MWHPR1201MB0128; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:MWHPR1201MB0128; x-forefront-prvs: 0532BF6DC2 received-spf: None (protection.outlook.com: amd.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: zskqr8rO0iD6gMYgfKwRgDNxUrWdUftDaLoBT9pMX1qkVSpGRsEzdXshvv0ImuvD5XTOarmN6t1+DR2nUtaMpA== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: b42c616f-ed64-42ac-5508-08d54b5f38cb X-MS-Exchange-CrossTenant-originalarrivaltime: 25 Dec 2017 06:17:48.7744 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR1201MB0128 Cc: Thomas Hellstrom , "Koenig, Christian" 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 + Thomas -----Original Message----- From: dri-devel [mailto:dri-devel-bounces@lists.freedesktop.org] On Behalf Of Roger He Sent: Monday, December 25, 2017 2:08 PM To: dri-devel@lists.freedesktop.org Cc: He, Roger ; Koenig, Christian Subject: [PATCH 2/3] drm/ttm: add new function to check if bo is allowable to evict or swapout 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 --- drivers/gpu/drm/ttm/ttm_bo.c | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) 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; -- 2.7.4 _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel 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) {