From patchwork Tue Mar 6 14:43:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 10261949 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 E12E5602C8 for ; Tue, 6 Mar 2018 14:43:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D1AE528FEF for ; Tue, 6 Mar 2018 14:43:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C63792900E; Tue, 6 Mar 2018 14:43:53 +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_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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 48F2128FEF for ; Tue, 6 Mar 2018 14:43:53 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 362126E0C4; Tue, 6 Mar 2018 14:43:52 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr0-x242.google.com (mail-wr0-x242.google.com [IPv6:2a00:1450:400c:c0c::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id 605F46E074; Tue, 6 Mar 2018 14:43:50 +0000 (UTC) Received: by mail-wr0-x242.google.com with SMTP id k9so21167280wre.9; Tue, 06 Mar 2018 06:43:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=AGqfCJGyeRhS3a2lgiBPrGMmQafCRKGcQCMRHcE/KyE=; b=LunThuWii+jtkEZU82DwijRf6k8TOo6d4m+6rQ/5EfQjofG6kmLruWpWBVDYGAH2Jx y5tPqBTb0oaRj0fPAibPTKIyeepykNLI7wP5CnX0Hd9OWLvpX4uQwCbyQYu3RBXfSPbZ maPU+YYNzTBeLkrCvd3GjwqglF0te8QukFZY1fscPnQS9vBwbl8aeaPwFm0UrReF3hD5 3X9B2Er/ufswKWveB2cSXiPzUGuK3SW/7XBcmooW2whNDU7kBBiPkapdyurkQDrFES7F VgQkhsdoisdefrS6jId2brv2GPRrsnJ3uSgnA6Xlk8pRYZhD/Le8vOGpofH2rVTwPFuX P9sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=AGqfCJGyeRhS3a2lgiBPrGMmQafCRKGcQCMRHcE/KyE=; b=alI9u230qmEmtpNnnA244Ni0luXltL779T1t+d5jr8n0skoU9HhxLzSxHIVhkIp5ZY CupnRE2P/1LFIgy/6cnBK1lgkulTu6SNImZTvPfbm+ZCLpyCt/AFDel+RgzKlhx207pq ZPo6rM9yYvxKvFFiPf8B+ZgLEKofvKEC4pWJ1oBf4FejWcxV9D0y470iZtd1C0nAjuL0 k3K553C5+Xule5UPi6c6ouWwnhNB2teWpQBmiid0TyclT9IqEMlhnE0AZex9saiFJCO+ tKNcXIqXA3t2wn05ZJoIUP6LoGqgA9l831Soa8JC/P8wpndtuWERHlAgQm+SGx9IyOm0 J6Eg== X-Gm-Message-State: APf1xPDJHZb/81fQ6myPjEvOiCVwJ7hP3Yr/4Ok4G0Aal1zkpeKoxPas Z8/bXgFbQlXoTLZ59luPgzHRRQ== X-Google-Smtp-Source: AG47ELtw/X01Mz1mOqBhhAovbbfj/t0Hs2q/CoUAWygv/HzHOSxPzyk0QEM+Nl4J3INWNRtybLI1mA== X-Received: by 10.223.197.1 with SMTP id q1mr15379991wrf.268.1520347428800; Tue, 06 Mar 2018 06:43:48 -0800 (PST) Received: from baker.fritz.box ([2a02:908:1251:8fc0:44ab:16c7:7c4f:90f9]) by smtp.gmail.com with ESMTPSA id s21sm13419206wra.45.2018.03.06.06.43.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Mar 2018 06:43:48 -0800 (PST) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?UTF-8?q?Christian=20K=C3=B6nig?= To: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH 1/6] drm/ttm: add ttm_bo_pipeline_gutting Date: Tue, 6 Mar 2018 15:43:42 +0100 Message-Id: <20180306144347.1702-1-christian.koenig@amd.com> X-Mailer: git-send-email 2.14.1 MIME-Version: 1.0 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Allows us to gut a BO of it's backing store when the driver says that it isn't needed any more. Signed-off-by: Christian König --- drivers/gpu/drm/ttm/ttm_bo.c | 15 ++++++++++++--- drivers/gpu/drm/ttm/ttm_bo_util.c | 24 ++++++++++++++++++++++++ include/drm/ttm/ttm_bo_driver.h | 9 +++++++++ 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index ad142a92eb80..98e06f8bf23b 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -622,14 +622,23 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo, reservation_object_assert_held(bo->resv); + placement.num_placement = 0; + placement.num_busy_placement = 0; + bdev->driver->evict_flags(bo, &placement); + + if (!placement.num_placement && !placement.num_busy_placement) { + ret = ttm_bo_pipeline_gutting(bo); + if (ret) + return ret; + + return ttm_tt_create(bo, false); + } + evict_mem = bo->mem; evict_mem.mm_node = NULL; evict_mem.bus.io_reserved_vm = false; evict_mem.bus.io_reserved_count = 0; - placement.num_placement = 0; - placement.num_busy_placement = 0; - bdev->driver->evict_flags(bo, &placement); ret = ttm_bo_mem_space(bo, &placement, &evict_mem, ctx); if (ret) { if (ret != -ERESTARTSYS) { diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c index 6d6a3f46143b..1f730b3f18e5 100644 --- a/drivers/gpu/drm/ttm/ttm_bo_util.c +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c @@ -801,3 +801,27 @@ int ttm_bo_pipeline_move(struct ttm_buffer_object *bo, return 0; } EXPORT_SYMBOL(ttm_bo_pipeline_move); + +int ttm_bo_pipeline_gutting(struct ttm_buffer_object *bo) +{ + struct ttm_buffer_object *ghost; + int ret; + + ret = ttm_buffer_object_transfer(bo, &ghost); + if (ret) + return ret; + + ret = reservation_object_copy_fences(ghost->resv, bo->resv); + /* Last resort, wait for the BO to be idle when we are OOM */ + if (ret) + ttm_bo_wait(bo, false, false); + + memset(&bo->mem, 0, sizeof(bo->mem)); + bo->mem.mem_type = TTM_PL_SYSTEM; + bo->ttm = NULL; + + ttm_bo_unreserve(ghost); + ttm_bo_unref(&ghost); + + return 0; +} diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h index f8e2515b401f..39cd6b086d3a 100644 --- a/include/drm/ttm/ttm_bo_driver.h +++ b/include/drm/ttm/ttm_bo_driver.h @@ -849,6 +849,15 @@ int ttm_bo_pipeline_move(struct ttm_buffer_object *bo, struct dma_fence *fence, bool evict, struct ttm_mem_reg *new_mem); +/** + * ttm_bo_pipeline_gutting. + * + * @bo: A pointer to a struct ttm_buffer_object. + * + * Pipelined gutting a BO of it's backing store. + */ +int ttm_bo_pipeline_gutting(struct ttm_buffer_object *bo); + /** * ttm_io_prot *