From patchwork Wed Apr 24 16:56:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Friedrich Vock X-Patchwork-Id: 13642217 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2C119C25B4F for ; Wed, 24 Apr 2024 17:01:25 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 037F9113C9A; Wed, 24 Apr 2024 17:01:05 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; secure) header.d=gmx.de header.i=friedrich.vock@gmx.de header.b="DAWwQjDx"; dkim-atps=neutral Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4FFB4113C95; Wed, 24 Apr 2024 17:01:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1713978036; x=1714582836; i=friedrich.vock@gmx.de; bh=GGCBb+pzAx6oM1WHiEHk3wJf7oWdJZUwB7yKYQh3Qtw=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-ID:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=DAWwQjDxkN1IDNj+VC2Wv91sL2tQQvEKvMxI4Yj1ieFBC+QLcD1WzMpgcDaYqKt6 7safQBsKM01Yb27vKqQg7VgLotFq5TCDA1vlEmXnvRs+pBl3XfszaRNAwEsD7vtMZ hzWX31HlvteBrqK0JssC8I8LpZoM2T1alDueDa2uvjkD5HfvwQKCyyrE6xaHCpsGN FYRxPh62oT9EzdimuO03oERzZOoGugGrMrshIDgYlS4UPxvntQUfFUFYbGIji9Bsb JR9zUKiX4m44n7pIR44qFeumdHI5OLcPKAqU+QVkkiTT/+o8ugY3k1YnAXFnYVA7h 3bVlhIAY0lKZkRHdXQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from arch.fritz.box ([213.152.117.111]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1N49lD-1shZSP06BV-011HgO; Wed, 24 Apr 2024 19:00:36 +0200 From: Friedrich Vock To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org Cc: Pierre-Loup Griffais , Tvrtko Ursulin , Bas Nieuwenhuizen , Joshua Ashton , =?utf-8?q?Christian_K=C3=B6nig?= , Alex Deucher Subject: [RFC PATCH 01/18] drm/ttm: Add tracking for evicted memory Date: Wed, 24 Apr 2024 18:56:51 +0200 Message-ID: <20240424165937.54759-2-friedrich.vock@gmx.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240424165937.54759-1-friedrich.vock@gmx.de> References: <20240424165937.54759-1-friedrich.vock@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:3A/UFtTwEymJIuR6R8hV9aPx9tNP9L1fkblX1dTobTUP8ODeKpR ld1okkTQHCXks5V0Uiy4XFq0lOWSli1xDC9z/h5CjLJom2tvwwX5N6pUDbtRvm4FMvN3Y4k 41AD1gI7+DcmK6TLtg34y+Q6+vx4M6mLOrQwgJspZ46eBwiUstD3ZunQOCuuaafkz6k2/cf NkSUM3+vUMdhKsbQqrDWg== UI-OutboundReport: notjunk:1;M01:P0:KzCXhVYLhZE=;Xbau6rqZeHdtDBIS2iaYeAlL3B1 kKSiL63rZbf4vgwk8sHlp0A6PheYvBFBx1ohH/vRqKx9oI4Pp+zudhkj0bKliQ1Bxb5bSi2jE Od8Ngdv866o4vqK2ze06H19udoXvgOfpHUwsq/DU07cNBB2RAc9dd6zJQ2sQ5wX3RSYBWH6Gc kD+neIqZ1AWWP+33ycDYxE4b3ecVAD3iMXVYz1F3G9Mqgmsx+LONWb0SqR4sk4NZF7/+S2AC4 tKByEIK54zoTwtiVyzgZD5zRAYZx7ge/rYBl9o2uR0ofdEjcspHX9LzrG1Wz7WBKVKzs/TT9I smt5CbqFQCySidcoR+mIBDN8+en5es5j7ajFhB6DeuANIA+KXr7O85yFslDJyPoN+5tqxo4PE sF4dfA281eWcxuCeGGk123y+Q2NKOP7BBX7vHqTL5gf2dXsXK97HIyS6ANw05SrNxXwZUpbRk uJnWoVhZ3CKSuZIZqfLMI+JN9yII0n0Ucwf47XcRuZ3PToQLEY8kJCvtP5jbld4U+IGlfsbTn kDCRJYCjc6nrSr4gZooXFQoTLwLHo4pF8Mu05nrgzQYo3iMeK46rDMRvnKbWcVdYY773WcUaO VEfOgc7mVo1wGigY1EXp2Z1hnoTg+cpr/2WCZ+B1W5V3/R7NGLfw26LGCMFebOBAcQ+FsOvIH IQjIiFJdbdeROSVPmae0yp9t7vz9pS/DMjqwqqdJogx6oqoyEBz6iJT/th99QLHY/c0q3Bkoc BfBZs1aGJfUTg/Qf1Z3ETRP0gkxnEkuXNPE6zE5HA8bt3WfZMC52O+gOcHBKVzMhYh+LBcRfM rEa/VADa132mzaZ2wKFCi4hdbfB5JmTOyUjfxEdaoBjHE= X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 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" These utilities will be used to keep track of what buffers have been evicted from any particular place, to try and decide when to try undoing the eviction. Signed-off-by: Friedrich Vock --- drivers/gpu/drm/ttm/ttm_device.c | 1 + drivers/gpu/drm/ttm/ttm_resource.c | 14 ++++++++++++++ include/drm/ttm/ttm_device.h | 5 +++++ include/drm/ttm/ttm_resource.h | 9 +++++++++ 4 files changed, 29 insertions(+) -- 2.44.0 diff --git a/drivers/gpu/drm/ttm/ttm_device.c b/drivers/gpu/drm/ttm/ttm_device.c index f5187b384ae9a..969d627ba06c0 100644 --- a/drivers/gpu/drm/ttm/ttm_device.c +++ b/drivers/gpu/drm/ttm/ttm_device.c @@ -219,6 +219,7 @@ int ttm_device_init(struct ttm_device *bdev, const struct ttm_device_funcs *func bdev->vma_manager = vma_manager; spin_lock_init(&bdev->lru_lock); + spin_lock_init(&bdev->unevict_lock); INIT_LIST_HEAD(&bdev->pinned); bdev->dev_mapping = mapping; mutex_lock(&ttm_global_mutex); diff --git a/drivers/gpu/drm/ttm/ttm_resource.c b/drivers/gpu/drm/ttm/ttm_resource.c index 46ff9c75bb124..1d6755a1153b1 100644 --- a/drivers/gpu/drm/ttm/ttm_resource.c +++ b/drivers/gpu/drm/ttm/ttm_resource.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -392,9 +393,11 @@ void ttm_resource_manager_init(struct ttm_resource_manager *man, man->bdev = bdev; man->size = size; man->usage = 0; + man->evicted_bytes = 0; for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) INIT_LIST_HEAD(&man->lru[i]); + INIT_LIST_HEAD(&man->evicted); man->move = NULL; } EXPORT_SYMBOL(ttm_resource_manager_init); @@ -470,6 +473,17 @@ uint64_t ttm_resource_manager_usage(struct ttm_resource_manager *man) } EXPORT_SYMBOL(ttm_resource_manager_usage); +uint64_t ttm_resource_manager_evicted_bytes(struct ttm_resource_manager *man) +{ + uint64_t evicted; + + spin_lock(&man->bdev->unevict_lock); + evicted = man->evicted_bytes; + spin_unlock(&man->bdev->unevict_lock); + return evicted; +} +EXPORT_SYMBOL(ttm_resource_manager_evicted_bytes); + /** * ttm_resource_manager_debug * diff --git a/include/drm/ttm/ttm_device.h b/include/drm/ttm/ttm_device.h index c22f30535c848..baa264efe483d 100644 --- a/include/drm/ttm/ttm_device.h +++ b/include/drm/ttm/ttm_device.h @@ -251,6 +251,11 @@ struct ttm_device { */ spinlock_t lru_lock; + /** + * @unevict_lock: Protection for per-manager uneviction tracking + */ + spinlock_t unevict_lock; + /** * @pinned: Buffer objects which are pinned and so not on any LRU list. */ diff --git a/include/drm/ttm/ttm_resource.h b/include/drm/ttm/ttm_resource.h index 78a226eba953c..7d1ce059c8805 100644 --- a/include/drm/ttm/ttm_resource.h +++ b/include/drm/ttm/ttm_resource.h @@ -145,6 +145,7 @@ struct ttm_resource_manager_func { * @move_lock: lock for move fence * @move: The fence of the last pipelined move operation. * @lru: The lru list for this memory type. + * @evicted: List of bos evicted from this memory type * * This structure is used to identify and manage memory types for a device. */ @@ -163,6 +164,7 @@ struct ttm_resource_manager { * Protected by @move_lock. */ struct dma_fence *move; + struct list_head evicted; /* * Protected by the bdev->lru_lock. @@ -174,6 +176,12 @@ struct ttm_resource_manager { * bdev->lru_lock. */ uint64_t usage; + + /** + * @evicted_bytes: How many bytes are evicted from this manager, + * protexted by bdev->unevict_lock + */ + uint64_t evicted_bytes; }; /** @@ -382,6 +390,7 @@ int ttm_resource_manager_evict_all(struct ttm_device *bdev, struct ttm_resource_manager *man); uint64_t ttm_resource_manager_usage(struct ttm_resource_manager *man); +uint64_t ttm_resource_manager_evicted_bytes(struct ttm_resource_manager *man); void ttm_resource_manager_debug(struct ttm_resource_manager *man, struct drm_printer *p); From patchwork Wed Apr 24 16:56:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Friedrich Vock X-Patchwork-Id: 13642211 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CCC25C4345F for ; Wed, 24 Apr 2024 17:01:15 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1600B113C93; Wed, 24 Apr 2024 17:00:58 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; secure) header.d=gmx.de header.i=friedrich.vock@gmx.de header.b="bc/e41Io"; dkim-atps=neutral Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by gabe.freedesktop.org (Postfix) with ESMTPS id A9119113C80; Wed, 24 Apr 2024 17:00:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1713978036; x=1714582836; i=friedrich.vock@gmx.de; bh=1irgTkPzRfDZc/Yfs8Ct/kCThBEK1jh/ZXOzS93mNOs=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-ID:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=bc/e41IoF9ZWQK3KqSE87bXfZktD/hwe4c8W4WJ/3Ro8s0+qv1amhmwGwZuH5LYQ q5M//OuWChR/X9ZTFUVP/E3bA8Dasi7VfbyO/njLAiNUKBhvsqHYxogMTNha+mrwy tAW57N4WWFRGYki0sP+IXnsY8gESmTrV2G+H1tIXt3uCVZSmyU0M57hUbJC0c8fC9 sooosRsINGw7uvn5Q5/tT51gjyIE+52IGDZyCqeqVGON5kIDdhESxmvMOU5v34c1G FeACUbyeWmzhZKjNr2R4ktu9vNGmP76+1OqTTzb4cijHQD+DqA2tv3TeniktnNJuI nPoJQZ+mlqecnmHeAQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from arch.fritz.box ([213.152.117.111]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1N95iH-1snbb126at-01436M; Wed, 24 Apr 2024 19:00:36 +0200 From: Friedrich Vock To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org Cc: Pierre-Loup Griffais , Tvrtko Ursulin , Bas Nieuwenhuizen , Joshua Ashton , =?utf-8?q?Christian_K=C3=B6nig?= , Alex Deucher Subject: [RFC PATCH 02/18] drm/ttm: Add per-BO eviction tracking Date: Wed, 24 Apr 2024 18:56:52 +0200 Message-ID: <20240424165937.54759-3-friedrich.vock@gmx.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240424165937.54759-1-friedrich.vock@gmx.de> References: <20240424165937.54759-1-friedrich.vock@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:+pC47Vkn5FPpJP75PfW4PX1NoQHGavCKYv17CmWYggCujygafbS TYrOCNDZIssskc8hfjHmHEQaHaUHvx/jxuNFoirwqbAeL5AinpVNZSEaQFD3btzy0CJmdkt u31e6yJNeYLWWvK34T0nJ8OwKEZEQqN0F8VHXeXGT9R1cHa2C2yeOxAgFYXR3cLN5H4LEaT U5+lhNaqLNKhgRwvM54pg== UI-OutboundReport: notjunk:1;M01:P0:7EhwgSRhO/4=;7m5aJD2q1nwk6Xq83dlhRGw8VCy SXT+ivUM6oWUgSUMe+IR6ohgSNblvFrOHQVixpEyexEwH7NwtlHOBJbnWUM5AaoEc/RUHS4xq X8QYeDqXPy5VoMcusEE3sH6EXzYONwxlFltrHeLI7lUaZ5DM4GZZ+jWznUzv4wqUm/tOVAyx0 6ZZ43WbT7Z306PlaleE961F/LImEvx+cvuYDdfhi/4LPT0ZpUOVzOQmQQR+n/XaSBIR1JxVP0 GvBeCqVsHK7rIP4zjFvKgQL1hOCKeWh/ZUPa3c6cxWIWVQdZYy6NrZXj0QGQROW9LiSNFzKVA CGve0YwD1ohtfLRkPZuh5ttGrgeXao0/aPB/zg8qo45FbzyhXT+aqQ68NHZZ6K/9Ebd32Ywvd t0LoKG7vXEoq2+OWXqSbDwZlgkO8BegLBjLguLgGysgNt711Hqqc3ctjhZ4KthAuWoRS/tY7C NOdMcCXrut/IN6/00e0rro22mnrgxV903NjuZ/ojEJ1NAPRYaE9KoH0fNS6Bbkfu955MklvCy N+DflA8WbR2xYoWIVNprtCSL1GwLJJ7Uu1jQUZdoTNuxwxirsrP1vDH9rkmsOcrnuJ4nSFYmW j/RzkuORMOE44JwFsOKsOiHPcawT8Y2eQNL24PlSDMJDQ+1Owv63SxCp+05nsj8i6cmlv0VHX qBA0xh+afelfY1Em7Lel8Jdy+g+PfydKE/wf/yBVII8//OLtAN5PYsdMhlkaMRZedlROoQ81e ZiXm9EVVIgS7t+F6JaygLtolF3iKL0QFN/GFVJwXLGrVihXlqhhv1Gcgs+qeD7QgMTQKSWECc zH/grcACKg8p6I2G57usemg9WkjSeWrXsnYsWN92lPSP0= X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 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" Make each buffer object aware of whether it has been evicted or not. Signed-off-by: Friedrich Vock --- drivers/gpu/drm/ttm/ttm_bo.c | 1 + include/drm/ttm/ttm_bo.h | 11 +++++++++++ 2 files changed, 12 insertions(+) -- 2.44.0 diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index edf10618fe2b2..3968b17453569 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -980,6 +980,7 @@ int ttm_bo_init_reserved(struct ttm_device *bdev, struct ttm_buffer_object *bo, bo->pin_count = 0; bo->sg = sg; bo->bulk_move = NULL; + bo->evicted_type = TTM_NUM_MEM_TYPES; if (resv) bo->base.resv = resv; else diff --git a/include/drm/ttm/ttm_bo.h b/include/drm/ttm/ttm_bo.h index 0223a41a64b24..8a1a29c6fbc50 100644 --- a/include/drm/ttm/ttm_bo.h +++ b/include/drm/ttm/ttm_bo.h @@ -121,6 +121,17 @@ struct ttm_buffer_object { unsigned priority; unsigned pin_count; + /** + * @evicted_type: Memory type this BO was evicted from, if any. + * TTM_NUM_MEM_TYPES if this BO was not evicted. + */ + int evicted_type; + /** + * @evicted: Entry in the evicted list for the resource manager + * this BO was evicted from. + */ + struct list_head evicted; + /** * @delayed_delete: Work item used when we can't delete the BO * immediately From patchwork Wed Apr 24 16:56:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Friedrich Vock X-Patchwork-Id: 13642208 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 82443C4345F for ; Wed, 24 Apr 2024 17:01:11 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2C06F113C85; Wed, 24 Apr 2024 17:00:56 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; secure) header.d=gmx.de header.i=friedrich.vock@gmx.de header.b="BzBXZVBn"; dkim-atps=neutral Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by gabe.freedesktop.org (Postfix) with ESMTPS id A739F113C7E; Wed, 24 Apr 2024 17:00:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1713978037; x=1714582837; i=friedrich.vock@gmx.de; bh=FsCN5JZy4Gk/a3hNXMYjit3VoRRF7a2Y6fIOALfs5oU=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-ID:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=BzBXZVBnSCSLYg0gaM9bfqNAoRqvzBo0OqDuzub7Gp7DVeaQSab86G05W0scvABI SPdZl31Ve+Trf6xCWcXWvju9I7au+2qFmVTDvLyPyOjpZ6YIQjqFqQxkM+W4fYsz9 wRKKqirKfKzteqiGvAXT+MjwRBXDqF1hMQ6tXbMAUkYn9P0KixpuuH3xMBXJpx6OP kzaut4pHMdz1Q5/CHfKcJWMgClZR9LcSrPMFqDRreoOFddo4DvAdhY+rS7H9i1EtV zQNw8hwLUYFPpXoZYGl5oM7qBwOJl8+TFCUjW2neWNh5wLZ5hCTIM9wM5h/ZKOLNv qEpATylxShuPO1m94g== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from arch.fritz.box ([213.152.117.111]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MzQg6-1sv3rB0CJ6-00x8xF; Wed, 24 Apr 2024 19:00:37 +0200 From: Friedrich Vock To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org Cc: Pierre-Loup Griffais , Tvrtko Ursulin , Bas Nieuwenhuizen , Joshua Ashton , =?utf-8?q?Christian_K=C3=B6nig?= , Alex Deucher Subject: [RFC PATCH 03/18] drm/ttm: Implement BO eviction tracking Date: Wed, 24 Apr 2024 18:56:53 +0200 Message-ID: <20240424165937.54759-4-friedrich.vock@gmx.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240424165937.54759-1-friedrich.vock@gmx.de> References: <20240424165937.54759-1-friedrich.vock@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:2+RNyK8NhFATRu2jik5k00mGmFkyBnRBXgbjQoWBef/TksvvbCy AntRyXNf6GAnsqjF3B/jOp56yoKo59sgm6UeqcPox8pFyhCEbR3lSWwJEBwHdf2LaPuicOt utojTIcjlr27he0KQ54FYQ6R0DrtbF5Ogu96mptwaCRW989IqCg4Y4WJZbNwJxKzHEGBqZR IrzgdqK1nc0HDZQCSVn0g== UI-OutboundReport: notjunk:1;M01:P0:/xygCpP2LZQ=;NBFwCzvS9Y0RzV9PF4GWtb06oou KAKbUDgRhqJgWNBNN+EvxWXwttbi73MTRqWYvyyphnydU/ZkuwkPMi0R+P8Hvk2mTv+g61eWA 6gP9knC1ntd79JptkOPK30LWy/nInwB1PvpY0Lz2ypapiBe4TRVWasEnPNpeb0Nl4rd7U2vrS Ph9O+c/T2GGuznJEaiQUA1DcoGQbDsuQQKOlA2J9pSdT957rDjrWwiJly/eog2G9dEjE4PUCp txUR7mjh2wwL2qAM/NjR6+H8+3lpRN9nbMeOVWjq4e8ric5eGNqZj0Exiq6vbef03yzEZyBC3 uzJ+L7E3eI6tZxmvL1hOCzgUXCwwCVpsYwzYM9Z+apdhM3TGU6OBcA8Qwi7vYkkXqZrzxroMh r2RED9UhPhVO+TlVvxOCkq9KZfhWBEgHKtvePY+ifG1YOz8IJb37ulTSAe5fW9lPk2/00iUD6 4t0W4dsTFadPKweXQ/7I0i9ZTPObMOBf1Y1wW2O2vgaAujavSk+aNs5f64VgccHBsuN2z6M7H iU9oqK/O/PeCZdyfPFNP8avD2dNWyOTa0osbsls1LvdJCTTCND7PdzYMe2PiIMhOQlKYg0X71 G+Z1h9NoDF6EDkg2yrFYmaDp9z/DXzYPHp6RjZROLuiMRxGYkqCEbXb5pcWWhnypBxt6SiVJP /30IOt742nbHAD94KuixyS+gGqKVjH7ghEpkLjm1OYBS7wf7MUDk1HZch4cjFLzVCESYW/N7Z dfWDKUjw9VUt+1eEJlMdHaw0LRdLNy4s7Lr32QJcnfXgzWjJiVY2TusyWxdtS/RO0LSwkzInG MOuxkpMrmOuk4u426leL6B9r60KO6LdSnMBRx9KV1qMqw= X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 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" For each buffer object, remember evictions and try undoing them if memory pressure gets lower again. Signed-off-by: Friedrich Vock --- drivers/gpu/drm/ttm/ttm_bo.c | 28 +++++++++++++++++++++++++++- drivers/gpu/drm/ttm/ttm_bo_util.c | 3 +++ 2 files changed, 30 insertions(+), 1 deletion(-) -- 2.44.0 diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index 3968b17453569..9a0efbf79316c 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -178,6 +178,12 @@ static void ttm_bo_cleanup_memtype_use(struct ttm_buffer_object *bo) { if (bo->bdev->funcs->delete_mem_notify) bo->bdev->funcs->delete_mem_notify(bo); + if (bo->evicted_type != TTM_NUM_MEM_TYPES) { + spin_lock(&bo->bdev->unevict_lock); + list_del_init(&bo->evicted); + man->evicted_bytes -= bo->base.size; + spin_unlock(&bo->bdev->unevict_lock); + } ttm_bo_tt_destroy(bo); ttm_resource_free(bo, &bo->resource); @@ -429,7 +435,9 @@ static int ttm_bo_bounce_temp_buffer(struct ttm_buffer_object *bo, static int ttm_bo_evict(struct ttm_buffer_object *bo, struct ttm_operation_ctx *ctx) { + int evicted_type = bo->resource->mem_type; struct ttm_device *bdev = bo->bdev; + struct ttm_resource_manager *man; struct ttm_resource *evict_mem; struct ttm_placement placement; struct ttm_place hop; @@ -438,6 +446,7 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo, memset(&hop, 0, sizeof(hop)); dma_resv_assert_held(bo->base.resv); + man = ttm_manager_type(bdev, evicted_type); placement.num_placement = 0; placement.num_busy_placement = 0; @@ -477,6 +486,14 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo, ttm_resource_free(bo, &evict_mem); if (ret != -ERESTARTSYS && ret != -EINTR) pr_err("Buffer eviction failed\n"); + } else if (bo->evicted_type == TTM_NUM_MEM_TYPES && + bo->bdev->funcs->uneviction_valuable && + bo->bdev->funcs->uneviction_valuable(bo)) { + bo->evicted_type = evicted_type; + spin_lock(&bo->bdev->unevict_lock); + list_add_tail(&bo->evicted, &man->evicted); + man->evicted_bytes += bo->base.size; + spin_unlock(&bo->bdev->unevict_lock); } out: return ret; @@ -845,6 +862,7 @@ static int ttm_bo_move_buffer(struct ttm_buffer_object *bo, struct ttm_placement *placement, struct ttm_operation_ctx *ctx) { + struct ttm_resource_manager *man; struct ttm_resource *mem; struct ttm_place hop; int ret; @@ -873,8 +891,16 @@ static int ttm_bo_move_buffer(struct ttm_buffer_object *bo, goto bounce; } out: - if (ret) + if (ret) { ttm_resource_free(bo, &mem); + } else if (bo->evicted_type != TTM_NUM_MEM_TYPES) { + man = ttm_manager_type(bo->bdev, bo->evicted_type); + spin_lock(&bo->bdev->unevict_lock); + list_del_init(&bo->evicted); + man->evicted_bytes -= bo->base.size; + spin_unlock(&bo->bdev->unevict_lock); + bo->evicted_type = TTM_NUM_MEM_TYPES; + } return ret; } diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c index fd9fd3d15101c..119291c5ed85e 100644 --- a/drivers/gpu/drm/ttm/ttm_bo_util.c +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c @@ -262,6 +262,9 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo, fbo->base.bulk_move = NULL; } + INIT_LIST_HEAD(&fbo->base.evicted); + fbo->base.evicted_type = TTM_NUM_MEM_TYPES; + ret = dma_resv_reserve_fences(&fbo->base.base._resv, 1); if (ret) { kfree(fbo); From patchwork Wed Apr 24 16:56:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Friedrich Vock X-Patchwork-Id: 13642205 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AB103C19F53 for ; Wed, 24 Apr 2024 17:01:04 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AA95F113C84; Wed, 24 Apr 2024 17:00:55 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; secure) header.d=gmx.de header.i=friedrich.vock@gmx.de header.b="TuK1rIXE"; dkim-atps=neutral Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8DF4C113C7B; Wed, 24 Apr 2024 17:00:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1713978037; x=1714582837; i=friedrich.vock@gmx.de; bh=9+1DaWtDrR/RnwYcJilum3wFaIOANmRNKTK8VURNZ3Q=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-ID:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=TuK1rIXEpzZWvjQ5wzhSmKYopOBtsMv+LLGMPU15PYHoDdilikkpUPSMWqvZw3MX s8qGRwVs6ZhHltyaDjI6GnNg1rsqSI+wUDDVC+aBM0SmL7RZZTKWpqHd1BU7M2MHq yFKBeEzdiR3SfZBCZh/Lm3DaTBKwbP6Qr09cDry7u2zex8QEFhHUx4TS8QujYEUVv pS7O1gVah1VElzvHWOLS4ufCRalMW+wzbOpDCZ9JAFpM/f49KoXRK4xAzVYjsmOBO g2d9VbsjtsLEYheIsLy8Teq+tZdnHbdyavfJdBPIg9K3Oms3Rp4eFBL48rycbySB/ zP25/biJAO7rhggnzA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from arch.fritz.box ([213.152.117.111]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MVNAr-1s9t8E2Gwh-00QZUM; Wed, 24 Apr 2024 19:00:37 +0200 From: Friedrich Vock To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org Cc: Pierre-Loup Griffais , Tvrtko Ursulin , Bas Nieuwenhuizen , Joshua Ashton , =?utf-8?q?Christian_K=C3=B6nig?= , Alex Deucher Subject: [RFC PATCH 04/18] drm/ttm: Add driver funcs for uneviction control Date: Wed, 24 Apr 2024 18:56:54 +0200 Message-ID: <20240424165937.54759-5-friedrich.vock@gmx.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240424165937.54759-1-friedrich.vock@gmx.de> References: <20240424165937.54759-1-friedrich.vock@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:kZHHoIXfXHyCK0yJlP8QmwUncr6R0eauEwn0//xaiui76aeeEiF BrDCUe6N5JbEhkuRTHgjx59zXKJ4OdyaEID7Wt+UpBNYRsnypCEVw+DthEI0M7bqFQrC8rR SyjSAONGY1gE9kW29fSf+RSqQRd9GdFNFl8tKFsVFObAvl0t3thCqkOZt+ZNfgFxxhWqrfr YuVQSd4cbZu6cNPqYuhKg== UI-OutboundReport: notjunk:1;M01:P0:0Ffcv+pEwbk=;N30PY4iIZAIMgn3mwgtZVODUZHc V6BbG+kO/80qwnfYJyntVy+iPriSm1rRfHc1cyeiwSpTAgmKR4zOkLHAX8qR31FLvh4H4kNcg JUPHk29mtlEZIvZwHTT4lb9MZPPdOuArKJ4odmb+YBasiVggU3i0zj6PZVvRFKssr7okXfOo6 9CX4iEzi8qmFlxyr/cIWIACrQL0F1QSBgiBmuW6aXQHFCo5EkhPRIZqWIxFMwlKI/kfoFyxdm 9QkZE+CuWLj1jPqx+7YcRkuttfwuczDz+bLxwAPYZSvdW1wJN0kWU+Ym9gQEFj+kEfFBtBtHz 01qHboyNyUHL1/iaoZt+r/f+vmeywWWlJh7y9Sb7iFEOL2WwhYDSwyjLC9g3prxZ3ZQn2GmcK ZbygM/jZdurilca7peCRB9uucWQWtakhGfAcwFusmZjf5VXokxqCiFJyYqyYKv5NS8yxZ9r2j qIDQlgS3++FA5ZXWm2fMgHopVV8pX+5h22zI1OVpoe0r9MKo5I3XIzmayiGO42BDzJfuCNCNv TPGeEf7qhve2I6ZttsG9LUs3rgPgxc0ikTIzolaWM3KqiaKFjepb2ZdmWW7SzSvxhhUAsAbiH LZ7tgOYePQ204rfp182NPZTdDBL0hlPbD5W1YEx6HFYLIbu7+8R/E2YIZElFdvqlJWOkmdsCp 1593psSNdsn0UDloBAx8oL82TAMeJYmNvdLbcaxhpSoA9BCXR7Dgrk9hlQc+glt86WcRocw2D MjOZZx9NRkCe9SPhNsOyAFvn3az8pYWEaJaKLN0Hvjq+z4/k1IogVTpBr6jLvY9FGgq9awiP5 qGkxor1CpsFSBt40RzKeJJ+7V1LoENHGP9kGUKYMCdA+Y= X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 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" Provides fine-grained control for drivers over which buffers should be considered when attempting to undo evictions. Signed-off-by: Friedrich Vock --- include/drm/ttm/ttm_device.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) -- 2.44.0 diff --git a/include/drm/ttm/ttm_device.h b/include/drm/ttm/ttm_device.h index baa264efe483d..283795d674189 100644 --- a/include/drm/ttm/ttm_device.h +++ b/include/drm/ttm/ttm_device.h @@ -133,6 +133,29 @@ struct ttm_device_funcs { void (*evict_flags)(struct ttm_buffer_object *bo, struct ttm_placement *placement); + /** + * struct ttm_bo_driver member uneviction_valuable + * + * @bo: the buffer object to be unevicted + * + * Check with the driver if it is valuable to unevict a BO, + * that is to move it back to its placecment before it was + * evicted. + */ + bool (*uneviction_valuable)(struct ttm_buffer_object *bo); + /** + * struct ttm_bo_driver member evict_flags: + * + * @bo: the buffer object that can be unevicted + * @dest: The placement for the unevicted buffer + * + * This should not cause multihop evictions, and the core will warn + * if one is proposed. + */ + + void (*unevict_flags)(struct ttm_buffer_object *bo, + struct ttm_placement *dest); + /** * struct ttm_bo_driver member move: * From patchwork Wed Apr 24 16:56:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Friedrich Vock X-Patchwork-Id: 13642206 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 420A2C4345F for ; Wed, 24 Apr 2024 17:01:07 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A12E5113C81; Wed, 24 Apr 2024 17:00:55 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; secure) header.d=gmx.de header.i=friedrich.vock@gmx.de header.b="ACibeKm1"; dkim-atps=neutral Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6B69F113ABC; Wed, 24 Apr 2024 17:00:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1713978038; x=1714582838; i=friedrich.vock@gmx.de; bh=Z3bdehzsZZgfZDz/cFDr/Lcux0c33ONrf5gsVmSqteU=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-ID:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=ACibeKm1K+52KcuFLOjNZdsdKCy25tsqjeTSPDfoIJ5wxDft3dd5bveq6LkFnLbh NLehqmoypqYXT7CYlwoAHzQZucl8sGagEFCZ0XSSjcNbXmPwZwTNUdBbUvWPEgk1e vq92SPSd4l8Nywbecz4IjSMVbTDBaVejLSqjQz5+2MuM7S3T4BUZFuL/u+iYn93PR QPKdJ13YG7qEoFi7DKCwegL7aGNQLUWS9hptIlFtkjFGzemOu20rPdkzRPtCHfxRi B2Ygfr8Hp7m/IHuDEMpIE3BKPLNNOA4e5RwiVoRvGgu+SVQjtHYFKDVOfunf+lehf zNBxVdFGDzOAp8+GkA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from arch.fritz.box ([213.152.117.111]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MSt8W-1s7xBw06cY-00T3Wx; Wed, 24 Apr 2024 19:00:38 +0200 From: Friedrich Vock To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org Cc: Pierre-Loup Griffais , Tvrtko Ursulin , Bas Nieuwenhuizen , Joshua Ashton , =?utf-8?q?Christian_K=C3=B6nig?= , Alex Deucher Subject: [RFC PATCH 05/18] drm/ttm: Add option to evict no BOs in operation Date: Wed, 24 Apr 2024 18:56:55 +0200 Message-ID: <20240424165937.54759-6-friedrich.vock@gmx.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240424165937.54759-1-friedrich.vock@gmx.de> References: <20240424165937.54759-1-friedrich.vock@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:szFxOvvpkj8qn75oReT4WS50CZIKWQhEQsbdmwucQspefqrNYrx TA8/CsBWFtZaIQvXdkoBbo9cxRC1dg/L0iQddXhdPr5XAJZPE4+/JAcn1U53/sEkpvMm/7p aXEJEHPTv2nlSbRdZ6ftsEDD0rahLKio2r3CO1OqyFpVd8nZkgn/fp6F/1ba/7DM6kmQYU+ wZSxK0BFI+ukHJXwEydQg== UI-OutboundReport: notjunk:1;M01:P0:KKdoSho9HZ8=;sjG+9C26e/MIOfYwDkGlF1s8LaV RFBlFzeYQLQX1NBQvo62PgVKDpaQpzzC+eF03B78eJte/gSJN3Xd0OzIFJSizCJNNcy0Ql2dJ pYFTJTHwi0isD8GXeP/8YWl8fo/XNTIToWrQXvfJkRPmCZkDiq8boU+aMb6fT+vGsMWabzF10 j13KC3OtX6SWS2/hxKlh9FrVEe97HegsN4tqkn2ZsLErJv+uD1gMub27LA3PhnFK1i2loXV9s ZX9DgrFBZvlG7zIaMFDchNMVAqXGEPX4qTbKxWQteqUe/y2xOp6u9IBFL0Sl7v4HhB72x72EC 1h9RlYOiZpeFjb3snJNFgUFH6jS1oDvmzD6Yz7rVBSjrwJ9mAiHHC4ZRb72kOLsx/9OHrbyOQ gThLT5CmH4ZHRe2todHFoxCauXiQ4GO3MMtFhpacBHKSirE3oRf/TUH90dd9/1i/HXvyHOmsi CVthrFRcmghGB/wY6FPfJvf4syikbvxeMgMSAsVugTRQk8awJXvzOo3H5LCbHEY+70xZpRcb+ dky1+l2oVvD2atYpk/YvFhpT7XTgxESovuTyJMuk+Tl7mOgKB5WqI7FWNPodYXSnSG+KXYD4k 5L/uhMKSU9UN/apkSFbvdQ+pbLlO16ZF/sh/UVa/fwCaiLJKHitbXoQHjm4BnhhIKbJKAP3Mm /UTfAZ44dqSgDDC23SdngZfrbCZUUsdr8wpTuzvJKljVq7tiaMAYO+C00CyzoYr110eYST5c+ pIl2GqMTGZoEYw6pEVpuYgLQwuJoy7rSXQCrvjTmkfat8UJCepk0mmAtOBBNghHIhBiRoZt3v D76RVW/iKF9y0w1OPe18YbL6bHdud95+hqIxZn5snphLU= X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 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" When undoing evictions because of decreased memory pressure, it makes no sense to try evicting other buffers. Signed-off-by: Friedrich Vock --- drivers/gpu/drm/ttm/ttm_bo.c | 2 ++ include/drm/ttm/ttm_bo.h | 2 ++ 2 files changed, 4 insertions(+) -- 2.44.0 diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index 9a0efbf79316c..3b89fabc2f00a 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -764,6 +764,8 @@ static int ttm_bo_mem_force_space(struct ttm_buffer_object *bo, break; if (unlikely(ret != -ENOSPC)) return ret; + if (ctx->no_evict) + return -ENOSPC; ret = ttm_mem_evict_first(bdev, man, place, ctx, ticket); if (unlikely(ret != 0)) diff --git a/include/drm/ttm/ttm_bo.h b/include/drm/ttm/ttm_bo.h index 8a1a29c6fbc50..a8f21092403d6 100644 --- a/include/drm/ttm/ttm_bo.h +++ b/include/drm/ttm/ttm_bo.h @@ -192,6 +192,7 @@ struct ttm_operation_ctx { bool gfp_retry_mayfail; bool allow_res_evict; bool force_alloc; + bool no_evict; struct dma_resv *resv; uint64_t bytes_moved; }; @@ -358,6 +359,7 @@ static inline void *ttm_kmap_obj_virtual(struct ttm_bo_kmap_obj *map, return map->virtual; } + int ttm_bo_wait_ctx(struct ttm_buffer_object *bo, struct ttm_operation_ctx *ctx); int ttm_bo_validate(struct ttm_buffer_object *bo, From patchwork Wed Apr 24 16:56:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Friedrich Vock X-Patchwork-Id: 13642210 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 96461C07E8E for ; Wed, 24 Apr 2024 17:01:14 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 98C86113C90; Wed, 24 Apr 2024 17:00:57 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; secure) header.d=gmx.de header.i=friedrich.vock@gmx.de header.b="c7gwoqUh"; dkim-atps=neutral Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by gabe.freedesktop.org (Postfix) with ESMTPS id 98F13113C7C; Wed, 24 Apr 2024 17:00:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1713978038; x=1714582838; i=friedrich.vock@gmx.de; bh=YEoEwdZBTeDletyFf2XrgVi0oLfeiNH6JddFRwgtZks=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-ID:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=c7gwoqUhnT7GMve27XXstn9u+1BBqzgUXdCjgm9rHSO7L+0cCcyeTWsfJtL0be1R yNRHClZda+gFqdsRufJYeh8OcOrTxt0nm35cJoDzZa3wAF/nxrPxFMIhQXMTFIHoW GrAcCFmHCm9xL+Ur+dNlCSi8Y1wwEuS0htKCFSbDkOJ9WxwyDPoRyR54X8UXLJvR0 ZeK+tChpD5br3RmdUXgH0gHB6AFtrXE5rk0D3UxbhLeoxKanVj48bm0hH8CQrYd18 YVKRcWR0KLPxp1NYc3d0ZCOp85HIGto7GjfLviKxQrEOzq+ZWHfbzR45JUcwrO63R Wzr4QDzqut/YwapPMA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from arch.fritz.box ([213.152.117.111]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MRTRH-1sMYaJ2G0b-00Mhbo; Wed, 24 Apr 2024 19:00:38 +0200 From: Friedrich Vock To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org Cc: Pierre-Loup Griffais , Tvrtko Ursulin , Bas Nieuwenhuizen , Joshua Ashton , =?utf-8?q?Christian_K=C3=B6nig?= , Alex Deucher Subject: [RFC PATCH 06/18] drm/ttm: Add public buffer eviction/uneviction functions Date: Wed, 24 Apr 2024 18:56:56 +0200 Message-ID: <20240424165937.54759-7-friedrich.vock@gmx.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240424165937.54759-1-friedrich.vock@gmx.de> References: <20240424165937.54759-1-friedrich.vock@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:0/0NKfU26JPp92TtRupJLBEu1L6rO0vcTTmoElTHWE06tJXlemG K+i9R9YvCgtscOrrQrqJFCAyTqC0bZuDbjyZ1dq2So0/ZcMsYSS5mL/vPxnVYTeBNfO8RSf oNz7Fv6O86ZwU0xXxkxuHSdi+uWrT5afDkHU/rnBa0WB4HaLS3XQnBbLevGUsDFfxfUGnUT /yOMM67/MB0JpsR5Pd9GQ== UI-OutboundReport: notjunk:1;M01:P0:zzxLZerOn/Q=;cqOIDMG1GWJjPDQ0iQ2KIMC48et TIfbpCj46f6GRwNcnw58cp+ajjzTmgoLOl4a0sfmJr2GIt8g97Ki8vYgOMhtKTyCu/KvIohs5 bI6ulPi/kQcErq7SMw3CG3+BtlTdOK/t1XCpQqE+COyVohpERNqUcWFUgpojYz9rvvTyu/R2C 4Whm0rGn33C2sT/BLpssZUBYGNzmT+2zZVQ+cTeRbwGrOvug1b1L/XiTz/AlFrWmRujDrz5xR Bx/snOsNV/r2QbvfyzwEDafR/WXCCCXmreTxoUjDQeeSYfK2uXRjBF1fjk3eHWZ+LASqyTpY6 ZyIq4ebTAa5Xi2Sd4jsziziWiK9CFwzXC+O8vpUzeHjF9RVvl9qNUXm+RkANxXlqlVbqb02BU Ji8STQ8/CCxafckBHTh47TsdRSPwEtOv3LUstEV2mi0H3a7B3hSBi0VMAb8trHjgtTZJyHvHf hpDGucqnvhwhZCJBcAz5wXZuYWvQ/zROZ+lBdONn2IEZOmxWAshj2q1rQUnaflhKHjt5K7Z/f OyUtdO/hr9539HDnvaR8W4buQxgFrnS0YfKl+DvwP9Z847oee+SUuNvU/vs3kWvQS5EsnaaeF tXng4f/FE1JrgxsvTPiUKW7zVjVWmK8EUG+WwTL5Wtmdip5dnZjMdJuLwpXN8xR6fMi7VW9zu xYXNn7DW+1wuBgK4NgEttG9JlNQNMnhd/aJZso5Wom77zyYFrHRRFCCm7ESrRLgCI9fg9XLZb bNXJFsuEbezZZWcpaxnIvnarURRxdCrCdVGAk2ReVuCzhshE51X/cFU+6Ow8JbszPJxrMjf8Z J/xaA7jGa1mjug06vnHthAsF+XEBbN3pd9Na5ti0+3BY8= X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 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" For now, they are only used internally inside TTM, but this will change with the introduction of dynamic buffer priorities. Signed-off-by: Friedrich Vock --- drivers/gpu/drm/ttm/ttm_bo.c | 168 ++++++++++++++++++++++++++++++++++- include/drm/ttm/ttm_bo.h | 6 ++ 2 files changed, 172 insertions(+), 2 deletions(-) -- 2.44.0 diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index 3b89fabc2f00a..3047c763eb4eb 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -166,6 +166,111 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo, return ret; } +/** + * Fetches the next BO from the manager's list of evicted BOs. + * bdev->unevict_lock should be held when calling this function. + */ +static struct ttm_buffer_object *ttm_next_evicted_bo(struct ttm_device *bdev, + struct ttm_resource_manager *man, + struct ttm_buffer_object *cursor) +{ + struct ttm_buffer_object *bo = NULL; + + if (cursor) + cursor = list_next_entry(cursor, evicted); + else + cursor = list_first_entry(&man->evicted, struct ttm_buffer_object, evicted); + + if (!list_entry_is_head(cursor, &man->evicted, evicted)) + bo = ttm_bo_get_unless_zero(cursor); + return bo; +} + +void ttm_mem_unevict_evicted(struct ttm_device *bdev, + struct ttm_resource_manager *man, + bool interruptible) +{ + struct ttm_buffer_object *evicted_bo = NULL, *next_evicted_bo = NULL; + struct ttm_operation_ctx ctx; + int ret; + + memset(&ctx, 0, sizeof(ctx)); + ctx.interruptible = interruptible; + ctx.no_evict = true; + + spin_lock(&bdev->unevict_lock); + evicted_bo = ttm_next_evicted_bo(bdev, man, NULL); + spin_unlock(&bdev->unevict_lock); + + while (evicted_bo) { + if (interruptible) + ret = dma_resv_lock_interruptible( + evicted_bo->base.resv, NULL); + else + ret = dma_resv_lock(evicted_bo->base.resv, + NULL); + if (ret) { + ttm_bo_put(evicted_bo); + break; + } + + /* If we raced with another thread (and lost), the + * other thread already removed the buffer from the + * list. In that case, we need to start over because + * our current cursor got removed. + */ + if (evicted_bo->evicted_type == TTM_NUM_MEM_TYPES) + ret = 0; + else + ret = ttm_bo_try_unevict(evicted_bo, &ctx); + + next_evicted_bo = ret ? evicted_bo : NULL; + + spin_lock(&bdev->unevict_lock); + next_evicted_bo = ttm_next_evicted_bo(bdev, man, + next_evicted_bo); + spin_unlock(&bdev->unevict_lock); + + dma_resv_unlock(evicted_bo->base.resv); + ttm_bo_put(evicted_bo); + + evicted_bo = next_evicted_bo; + } +} +EXPORT_SYMBOL(ttm_mem_unevict_evicted); + +struct ttm_mem_unevict_work { + struct work_struct work; + struct ttm_device *bdev; + struct ttm_resource_manager *man; +}; + +static void ttm_mem_unevict_work(struct work_struct *work) +{ + struct ttm_mem_unevict_work *unevict_work; + + unevict_work = container_of(work, typeof(*unevict_work), work); + + ttm_mem_unevict_evicted(unevict_work->bdev, unevict_work->man, + false); +} + +static void ttm_mem_queue_unevict(struct ttm_device *bdev, + struct ttm_resource_manager *man) +{ + struct ttm_mem_unevict_work *work; + + work = kzalloc(sizeof(*work), GFP_KERNEL); + + if (!work) + return; + + INIT_WORK(&work->work, ttm_mem_unevict_work); + work->bdev = bdev; + work->man = man; + queue_work_node(bdev->pool.nid, bdev->wq, &work->work); +} + /* * Call bo::reserved. * Will release GPU memory type usage on destruction. @@ -176,6 +281,12 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo, static void ttm_bo_cleanup_memtype_use(struct ttm_buffer_object *bo) { + struct ttm_resource_manager *man = NULL; + struct ttm_device *bdev = bo->bdev; + + if (bo->resource) + man = ttm_manager_type(bo->bdev, bo->resource->mem_type); + if (bo->bdev->funcs->delete_mem_notify) bo->bdev->funcs->delete_mem_notify(bo); if (bo->evicted_type != TTM_NUM_MEM_TYPES) { @@ -187,6 +298,9 @@ static void ttm_bo_cleanup_memtype_use(struct ttm_buffer_object *bo) ttm_bo_tt_destroy(bo); ttm_resource_free(bo, &bo->resource); + + if (man) + ttm_mem_queue_unevict(bdev, man); } static int ttm_bo_individualize_resv(struct ttm_buffer_object *bo) @@ -432,8 +546,7 @@ static int ttm_bo_bounce_temp_buffer(struct ttm_buffer_object *bo, return 0; } -static int ttm_bo_evict(struct ttm_buffer_object *bo, - struct ttm_operation_ctx *ctx) +int ttm_bo_evict(struct ttm_buffer_object *bo, struct ttm_operation_ctx *ctx) { int evicted_type = bo->resource->mem_type; struct ttm_device *bdev = bo->bdev; @@ -499,6 +612,57 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo, return ret; } +int ttm_bo_try_unevict(struct ttm_buffer_object *bo, + struct ttm_operation_ctx *ctx) +{ + struct ttm_resource_manager *man; + struct ttm_device *bdev = bo->bdev; + struct ttm_resource *unevict_mem; + struct ttm_placement placement; + struct ttm_place hop; + int ret = 0; + + dma_resv_assert_held(bo->base.resv); + + man = ttm_manager_type(bdev, bo->evicted_type); + + if (bo->deleted) + goto out; + + placement.num_placement = 0; + placement.num_busy_placement = 0; + bdev->funcs->unevict_flags(bo, &placement); + + if (!placement.num_placement && !placement.num_busy_placement) + return -ENOSPC; + + ret = ttm_bo_mem_space(bo, &placement, &unevict_mem, ctx); + if (ret) + return ret; + + do { + ret = ttm_bo_handle_move_mem(bo, unevict_mem, true, ctx, &hop); + if (ret != -EMULTIHOP) + break; + + ret = ttm_bo_bounce_temp_buffer(bo, &unevict_mem, ctx, &hop); + } while (!ret); + + if (ret) + ttm_resource_free(bo, &unevict_mem); + +out: + if (!ret) { + spin_lock(&bdev->unevict_lock); + list_del_init(&bo->evicted); + man->evicted_bytes -= bo->base.size; + spin_unlock(&bdev->unevict_lock); + bo->evicted_type = TTM_NUM_MEM_TYPES; + } + return ret; +} +EXPORT_SYMBOL(ttm_bo_try_unevict); + /** * ttm_bo_eviction_valuable * diff --git a/include/drm/ttm/ttm_bo.h b/include/drm/ttm/ttm_bo.h index a8f21092403d6..8f4e6366c0417 100644 --- a/include/drm/ttm/ttm_bo.h +++ b/include/drm/ttm/ttm_bo.h @@ -370,6 +370,9 @@ void ttm_bo_set_bulk_move(struct ttm_buffer_object *bo, struct ttm_lru_bulk_move *bulk); bool ttm_bo_eviction_valuable(struct ttm_buffer_object *bo, const struct ttm_place *place); +int ttm_bo_evict(struct ttm_buffer_object *bo, struct ttm_operation_ctx *ctx); +int ttm_bo_try_unevict(struct ttm_buffer_object *bo, + struct ttm_operation_ctx *ctx); int ttm_bo_init_reserved(struct ttm_device *bdev, struct ttm_buffer_object *bo, enum ttm_bo_type type, struct ttm_placement *placement, uint32_t alignment, struct ttm_operation_ctx *ctx, @@ -395,6 +398,9 @@ int ttm_mem_evict_first(struct ttm_device *bdev, const struct ttm_place *place, struct ttm_operation_ctx *ctx, struct ww_acquire_ctx *ticket); +void ttm_mem_unevict_evicted(struct ttm_device *bdev, + struct ttm_resource_manager *man, + bool interruptible); vm_fault_t ttm_bo_vm_reserve(struct ttm_buffer_object *bo, struct vm_fault *vmf); vm_fault_t ttm_bo_vm_fault_reserved(struct vm_fault *vmf, From patchwork Wed Apr 24 16:56:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Friedrich Vock X-Patchwork-Id: 13642220 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3A4DCC10F15 for ; Wed, 24 Apr 2024 17:01:28 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6C512113C88; Wed, 24 Apr 2024 17:01:23 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; secure) header.d=gmx.de header.i=friedrich.vock@gmx.de header.b="Nweod4Q0"; dkim-atps=neutral Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by gabe.freedesktop.org (Postfix) with ESMTPS id D8BE5113C88; Wed, 24 Apr 2024 17:01:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1713978039; x=1714582839; i=friedrich.vock@gmx.de; bh=Nk7gng7Z1DKu4g8B79dnaCw+5SH6ersr6shXg9m/kZM=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-ID:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=Nweod4Q0do/FQ4wTwwI3EU37MehFe7ORaR6ZhAKcKjH8BLFVLI8xBUHjzeIEW5hD hEDRkjwNHeVUF0akAQthtU96MUooQpfYOeFe/WKJLzk+NW6FEX85mQ8E4ln3mRjD9 V7p/As3HliUrQmG4Qgj2w5qnxTpJ+zRewioYwpQt67VlVlp8gfvwakBY7wch704aq 5B+bydhVHorr3Tjh5fPj6InKX8cLd4qmf7p8bnMb/piAS6HMt2TrqY9Co7gOoIClz ez4wkSi4u9rnj63bQ6jl/9tcXanjEpPZLb8FBJ56sDS80p9+stfAtCZb1zPiIYwEz gdER6BRhVt71Utpzag== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from arch.fritz.box ([213.152.117.111]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MfYLa-1sbBWh06Mi-00hp1t; Wed, 24 Apr 2024 19:00:39 +0200 From: Friedrich Vock To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org Cc: Pierre-Loup Griffais , Tvrtko Ursulin , Bas Nieuwenhuizen , Joshua Ashton , =?utf-8?q?Christian_K=C3=B6nig?= , Alex Deucher Subject: [RFC PATCH 07/18] drm/amdgpu: Add TTM uneviction control functions Date: Wed, 24 Apr 2024 18:56:57 +0200 Message-ID: <20240424165937.54759-8-friedrich.vock@gmx.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240424165937.54759-1-friedrich.vock@gmx.de> References: <20240424165937.54759-1-friedrich.vock@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:CzIRNVfxema9WV3cQUwowAAn757mGRb/nJyHyAFWi8Gd7XWpoau Jt5OzKKc/5Q3zz+pAgLs5oIB8S0cyN8y8oX74WGZ/mjMg67M8uUNZQYWEIKzy+Oj8dgmf5M paONhEhvmpD0vALOvGaKUjemLofbDk4dPtXL2brrsnJ/CRtdX9ENihIMJihGIcA66OkBH7u 6fcfd17XxTLYCRyzisdrA== UI-OutboundReport: notjunk:1;M01:P0:jHvQD48aIAI=;ULHkvBQa8Wfb6AsouFW9dCEwMQZ RMOGJ+MzMHH5EhhkXq8qhpx69cZPe6MJvYFYLPueURhq2OcqkJVUlqkqdjuiynKmr5lEphA7S F7yCPS9aJ42dZjjdkcGUjvBiuiip4ITO+IF1KTIfBg+y0oElQjTK6chZKRvInjxoNaVJtXWLP ACix76jDfYiZXHE43wlAwB3FPnFV6tLijfKzu5Il6FRBnyYwRHcEtDnYt9osByH7fFuGQww29 mERf2VOiCvsNByFdd6S4Bg6uHyx0AY4iIhc9xlZWQwEM9R64hqmoEwveu7saepZmedpMS8cC0 cb17e5vHCZNYbRSg43VulCT0luhN8wZYsTjJreyGKRiODU/SlgN182ZY3HkGIwUdarde2f7Ei UyBsaqrsNn7ImxLOQGEv08z5QezkONpwSfLAlOZe6rIGm7RMPA2P5oyHvpSibjuowbTQifsWC MP7wOrBr1Fp2JsB7Js6mUfD1/AtGpJNj1etE9mHGV4YsEnlTr0RpL/rd5yZ9pz199a6V3pPLF w8uo9ve2ntW42Yvf9G0gQahqPUAwbq4gD+W2n6WHjAbke93maVatrlUuqWO4zGgvm0E/EvjCG Lxv33qOAl56EPGuzcIfKCACFK1P8hE8l0KKI5Tvm0KQRt86sQg83Ae9dV6pygh7GNer7QcObt Gx/WO9s5wewOH2AYZrdg9s4Sgb1U4La1+DjGuBZdLye8S7Qqd7B/PazmyQUexd5b9Iy9mNLPI fblgN120EFI2/AfcWnfRbrLbGdu6gC5KTrYd6zwl/y4VO68R4/IPWvK9gfTczErmVqr9eN/sS 9nxwwntsWlHyROgwN6NTNwqYvE9mLJrfEdNiPO90nn2rg= X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 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" Try unevicting only VRAM/GTT BOs. Signed-off-by: Friedrich Vock --- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 50 +++++++++++++++++++++++++ 1 file changed, 50 insertions(+) -- 2.44.0 diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c index 64f5001a7dc5d..98e8a40408804 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c @@ -166,6 +166,31 @@ static void amdgpu_evict_flags(struct ttm_buffer_object *bo, *placement = abo->placement; } +/** + * amdgpu_unevict_flags - Compute placement flags + * + * @bo: The buffer object to unevict + * @dest: Destination for unevicted BO + * + * Fill in placement data when for restoring evicted BOs + */ +static void amdgpu_unevict_flags(struct ttm_buffer_object *bo, + struct ttm_placement *dest) +{ + struct amdgpu_bo *abo = ttm_to_amdgpu_bo(bo); + + WARN_ON(bo->evicted_type == AMDGPU_PL_GDS || + bo->evicted_type == AMDGPU_PL_GWS || + bo->evicted_type == AMDGPU_PL_OA || + bo->evicted_type == AMDGPU_PL_DOORBELL); + WARN_ON(bo->evicted_type == TTM_NUM_MEM_TYPES); + + amdgpu_bo_placement_from_domain(abo, abo->preferred_domains); + *dest = abo->placement; + dest->num_placement = 1; + dest->num_busy_placement = 1; +} + /** * amdgpu_ttm_map_buffer - Map memory into the GART windows * @bo: buffer object to map @@ -1424,6 +1449,29 @@ static bool amdgpu_ttm_bo_eviction_valuable(struct ttm_buffer_object *bo, return ttm_bo_eviction_valuable(bo, place); } +/* + * amdgpu_ttm_bo_uneviction_valuable - Check to see if we can unevict a + * buffer object. + * + * Return true if uneviction is sensible. Called by ttm_bo_evict to + * decide whether to consider the buffer object for uneviction later. + */ +static bool amdgpu_ttm_bo_uneviction_valuable(struct ttm_buffer_object *bo) +{ + struct amdgpu_bo *abo; + + if (!amdgpu_bo_is_amdgpu_bo(bo)) + return false; + + abo = ttm_to_amdgpu_bo(bo); + + if (bo->type != ttm_bo_type_device) + return false; + + return (abo->preferred_domains & + (AMDGPU_GEM_DOMAIN_VRAM | AMDGPU_GEM_DOMAIN_GTT)) != 0; +} + static void amdgpu_ttm_vram_mm_access(struct amdgpu_device *adev, loff_t pos, void *buf, size_t size, bool write) { @@ -1581,6 +1629,8 @@ static struct ttm_device_funcs amdgpu_bo_driver = { .ttm_tt_destroy = &amdgpu_ttm_backend_destroy, .eviction_valuable = amdgpu_ttm_bo_eviction_valuable, .evict_flags = &amdgpu_evict_flags, + .uneviction_valuable = &amdgpu_ttm_bo_uneviction_valuable, + .unevict_flags = &amdgpu_unevict_flags, .move = &amdgpu_bo_move, .delete_mem_notify = &amdgpu_bo_delete_mem_notify, .release_notify = &amdgpu_bo_release_notify, From patchwork Wed Apr 24 16:56:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Friedrich Vock X-Patchwork-Id: 13642207 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 76715C07E8E for ; Wed, 24 Apr 2024 17:01:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1D49E113C80; Wed, 24 Apr 2024 17:00:56 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; secure) header.d=gmx.de header.i=friedrich.vock@gmx.de header.b="kAOuRdWZ"; dkim-atps=neutral Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by gabe.freedesktop.org (Postfix) with ESMTPS id A14AF113ABC; Wed, 24 Apr 2024 17:00:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1713978039; x=1714582839; i=friedrich.vock@gmx.de; bh=dmthBPwHBQEh1ERv8gosthJ46ENZPmQH3m22QLhYX8E=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-ID:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=kAOuRdWZQ3qiIK9QKbPR/x1jFBD8tM+phdjCIMXmz/HUDasq9zo4mfyZm4cMUclW 3bHS81XVjU7vKTC51tx/+jYmKfgpia6DPII55KYBlUlYKI4IYteCX3zgb84zR0qiF cZGzVdpzI3t+p6JTC72RCSAo1R/chHkQVvzsCtb1kJi8oNCvKhy1LpU+s2vHTJ2X6 OoZSUKoFoHZ5tiszJYnOg0itI0B2cTJjk91LFXX20KNNFOdWZdZgJuyw7FrCqOSeJ 4nmmMA/0oI4+SuYb0npqlj9TsYMDthxv+8amiyBkfexmPBqtNMR67BVuy8hmvcxn2 rXj6qPmHM+6kRgNl+g== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from arch.fritz.box ([213.152.117.111]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1M9FnZ-1s5R8i28vv-004cnG; Wed, 24 Apr 2024 19:00:39 +0200 From: Friedrich Vock To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org Cc: Pierre-Loup Griffais , Tvrtko Ursulin , Bas Nieuwenhuizen , Joshua Ashton , =?utf-8?q?Christian_K=C3=B6nig?= , Alex Deucher Subject: [RFC PATCH 08/18] drm/amdgpu: Don't try moving BOs to preferred domain before submit Date: Wed, 24 Apr 2024 18:56:58 +0200 Message-ID: <20240424165937.54759-9-friedrich.vock@gmx.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240424165937.54759-1-friedrich.vock@gmx.de> References: <20240424165937.54759-1-friedrich.vock@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:a5YVxco+fRIJF/KEXvFQ0JJq85dgCX7W2vIexoQ5nzqNSXmkRng EPj9yaLoQhwKn2Ljp6Nh9DtNXySMAnkEmcbxuwt+hGxWu1r+2tX/+iZOvq+UNb2uSa9VtND uF/wu2hvJ2eifX4HHRot7oh76S8qvdUxRMWaa6RJdPbimduI9BsU0CQCRBz7rOO388/6R7s iJ+w2vImzberJEGuxPdlw== UI-OutboundReport: notjunk:1;M01:P0:Eb0QnSAqzFY=;Hqa7WNtR1NEtSP1i3xP0H3Fkm/i ++WI6HvOhwhQFFyxwREL3E8b1jAu5TELdFEqQqKA9aR1LRNY5ri1SS/LikTmwxGNXt8VUxNVg e1myKOojvL4Wy9fA97lrjUQnaIYzqDKGFECl3DBSwb1g0sMh3hc1OdgLhJ1lfOiLMk+b2EbBb dML/bEgzXhzOJCRWXBFQ94s5tgo9fan+RwWu2JBNN5yU5KcHZUDsAkN6JtZS8hH6zK5xDDoFD InNvR2iV0jZDSVH9SLwvSwWk2BphtvE+vojjNpLhQaQUswcT1ACtqGCdPo24XOVepIRqa/PVZ Ydpmx+0zKLyZ05n3D6SfT0UojIPB4B6Ctu6CGxL2s8R+Big4Uk82JMcnNZhiWaFXRV+vMDlNj GcNTQaFTQ/6R2ZEBw3+2XNhSGm3LIBhqLuH+9lTZWXsz6NQYQaXpxTNydx/8nevpV86B3+Dv1 HmvNQm6HNY0NMgN7FnCdcsm5e6C91TcuN61Zoaol0siJQG4gfYjQGfIq7JvLVH4Pac8qzWI2/ eWHXEPIr+lTuUY3H0Z/eg1l+/DGEmx/POGzUGXzdN4D1lZWD25NDLET683V+MIWJmz1SmkV23 Vi68F+3ZdNA44EPoJZf8T+R4THgEqMnBr7iSXvS+GEXlIma++fzzRfY3J+wBKrWsrAtalCyG7 8Cxh24axZR4CEEIy43FyFKVOYVUcZmoxIRiKwW9ADYHlIbntZKQpEe5kUeOBg6qBrZvdwPgTu 6xnk0/P9XEQj7A3d0bgKfixlvWTNS+P2ioQFsAFEowWApLythkbPCoT7wYyPp49O1e91JWXaF BTEFheHeFuCLaIOfmPYTwubN6NunrGx4pZu6YCZAc5f38= X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 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" TTM now takes care of moving buffers to the best possible domain. Signed-off-by: Friedrich Vock --- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 - drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 191 +-------------------- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.h | 4 - drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 7 - 4 files changed, 3 insertions(+), 201 deletions(-) -- 2.44.0 diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h index cac0ca64367b3..3004adc6fa679 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h @@ -1404,8 +1404,6 @@ bool amdgpu_device_need_post(struct amdgpu_device *adev); bool amdgpu_device_seamless_boot_supported(struct amdgpu_device *adev); bool amdgpu_device_should_use_aspm(struct amdgpu_device *adev); -void amdgpu_cs_report_moved_bytes(struct amdgpu_device *adev, u64 num_bytes, - u64 num_vis_bytes); int amdgpu_device_resize_fb_bar(struct amdgpu_device *adev); void amdgpu_device_program_register_sequence(struct amdgpu_device *adev, const u32 *registers, diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c index e9168677ef0a6..92a0cffc1adc3 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c @@ -638,196 +638,19 @@ static int amdgpu_cs_pass2(struct amdgpu_cs_parser *p) return 0; } -/* Convert microseconds to bytes. */ -static u64 us_to_bytes(struct amdgpu_device *adev, s64 us) -{ - if (us <= 0 || !adev->mm_stats.log2_max_MBps) - return 0; - - /* Since accum_us is incremented by a million per second, just - * multiply it by the number of MB/s to get the number of bytes. - */ - return us << adev->mm_stats.log2_max_MBps; -} - -static s64 bytes_to_us(struct amdgpu_device *adev, u64 bytes) -{ - if (!adev->mm_stats.log2_max_MBps) - return 0; - - return bytes >> adev->mm_stats.log2_max_MBps; -} - -/* Returns how many bytes TTM can move right now. If no bytes can be moved, - * it returns 0. If it returns non-zero, it's OK to move at least one buffer, - * which means it can go over the threshold once. If that happens, the driver - * will be in debt and no other buffer migrations can be done until that debt - * is repaid. - * - * This approach allows moving a buffer of any size (it's important to allow - * that). - * - * The currency is simply time in microseconds and it increases as the clock - * ticks. The accumulated microseconds (us) are converted to bytes and - * returned. - */ -static void amdgpu_cs_get_threshold_for_moves(struct amdgpu_device *adev, - u64 *max_bytes, - u64 *max_vis_bytes) -{ - s64 time_us, increment_us; - u64 free_vram, total_vram, used_vram; - /* Allow a maximum of 200 accumulated ms. This is basically per-IB - * throttling. - * - * It means that in order to get full max MBps, at least 5 IBs per - * second must be submitted and not more than 200ms apart from each - * other. - */ - const s64 us_upper_bound = 200000; - - if (!adev->mm_stats.log2_max_MBps) { - *max_bytes = 0; - *max_vis_bytes = 0; - return; - } - - total_vram = adev->gmc.real_vram_size - atomic64_read(&adev->vram_pin_size); - used_vram = ttm_resource_manager_usage(&adev->mman.vram_mgr.manager); - free_vram = used_vram >= total_vram ? 0 : total_vram - used_vram; - - spin_lock(&adev->mm_stats.lock); - - /* Increase the amount of accumulated us. */ - time_us = ktime_to_us(ktime_get()); - increment_us = time_us - adev->mm_stats.last_update_us; - adev->mm_stats.last_update_us = time_us; - adev->mm_stats.accum_us = min(adev->mm_stats.accum_us + increment_us, - us_upper_bound); - - /* This prevents the short period of low performance when the VRAM - * usage is low and the driver is in debt or doesn't have enough - * accumulated us to fill VRAM quickly. - * - * The situation can occur in these cases: - * - a lot of VRAM is freed by userspace - * - the presence of a big buffer causes a lot of evictions - * (solution: split buffers into smaller ones) - * - * If 128 MB or 1/8th of VRAM is free, start filling it now by setting - * accum_us to a positive number. - */ - if (free_vram >= 128 * 1024 * 1024 || free_vram >= total_vram / 8) { - s64 min_us; - - /* Be more aggressive on dGPUs. Try to fill a portion of free - * VRAM now. - */ - if (!(adev->flags & AMD_IS_APU)) - min_us = bytes_to_us(adev, free_vram / 4); - else - min_us = 0; /* Reset accum_us on APUs. */ - - adev->mm_stats.accum_us = max(min_us, adev->mm_stats.accum_us); - } - - /* This is set to 0 if the driver is in debt to disallow (optional) - * buffer moves. - */ - *max_bytes = us_to_bytes(adev, adev->mm_stats.accum_us); - - /* Do the same for visible VRAM if half of it is free */ - if (!amdgpu_gmc_vram_full_visible(&adev->gmc)) { - u64 total_vis_vram = adev->gmc.visible_vram_size; - u64 used_vis_vram = - amdgpu_vram_mgr_vis_usage(&adev->mman.vram_mgr); - - if (used_vis_vram < total_vis_vram) { - u64 free_vis_vram = total_vis_vram - used_vis_vram; - - adev->mm_stats.accum_us_vis = min(adev->mm_stats.accum_us_vis + - increment_us, us_upper_bound); - - if (free_vis_vram >= total_vis_vram / 2) - adev->mm_stats.accum_us_vis = - max(bytes_to_us(adev, free_vis_vram / 2), - adev->mm_stats.accum_us_vis); - } - - *max_vis_bytes = us_to_bytes(adev, adev->mm_stats.accum_us_vis); - } else { - *max_vis_bytes = 0; - } - - spin_unlock(&adev->mm_stats.lock); -} - -/* Report how many bytes have really been moved for the last command - * submission. This can result in a debt that can stop buffer migrations - * temporarily. - */ -void amdgpu_cs_report_moved_bytes(struct amdgpu_device *adev, u64 num_bytes, - u64 num_vis_bytes) -{ - spin_lock(&adev->mm_stats.lock); - adev->mm_stats.accum_us -= bytes_to_us(adev, num_bytes); - adev->mm_stats.accum_us_vis -= bytes_to_us(adev, num_vis_bytes); - spin_unlock(&adev->mm_stats.lock); -} - static int amdgpu_cs_bo_validate(void *param, struct amdgpu_bo *bo) { - struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev); - struct amdgpu_cs_parser *p = param; struct ttm_operation_ctx ctx = { .interruptible = true, .no_wait_gpu = false, .resv = bo->tbo.base.resv }; - uint32_t domain; - int r; if (bo->tbo.pin_count) return 0; - /* Don't move this buffer if we have depleted our allowance - * to move it. Don't move anything if the threshold is zero. - */ - if (p->bytes_moved < p->bytes_moved_threshold && - (!bo->tbo.base.dma_buf || - list_empty(&bo->tbo.base.dma_buf->attachments))) { - if (!amdgpu_gmc_vram_full_visible(&adev->gmc) && - (bo->flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED)) { - /* And don't move a CPU_ACCESS_REQUIRED BO to limited - * visible VRAM if we've depleted our allowance to do - * that. - */ - if (p->bytes_moved_vis < p->bytes_moved_vis_threshold) - domain = bo->preferred_domains; - else - domain = bo->allowed_domains; - } else { - domain = bo->preferred_domains; - } - } else { - domain = bo->allowed_domains; - } - -retry: - amdgpu_bo_placement_from_domain(bo, domain); - r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx); - - p->bytes_moved += ctx.bytes_moved; - if (!amdgpu_gmc_vram_full_visible(&adev->gmc) && - amdgpu_res_cpu_visible(adev, bo->tbo.resource)) - p->bytes_moved_vis += ctx.bytes_moved; - - if (unlikely(r == -ENOMEM) && domain != bo->allowed_domains) { - domain = bo->allowed_domains; - goto retry; - } - - return r; + amdgpu_bo_placement_from_domain(bo, bo->allowed_domains); + return ttm_bo_validate(&bo->tbo, &bo->placement, &ctx); } static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p, @@ -947,13 +770,8 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p, e->user_pages = NULL; } - amdgpu_cs_get_threshold_for_moves(p->adev, &p->bytes_moved_threshold, - &p->bytes_moved_vis_threshold); - p->bytes_moved = 0; - p->bytes_moved_vis = 0; - r = amdgpu_vm_validate(p->adev, &fpriv->vm, NULL, - amdgpu_cs_bo_validate, p); + amdgpu_cs_bo_validate, NULL); if (r) { DRM_ERROR("amdgpu_vm_validate() failed.\n"); goto out_free_user_pages; @@ -973,9 +791,6 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p, p->gang_leader->uf_addr += amdgpu_bo_gpu_offset(p->uf_bo); } - amdgpu_cs_report_moved_bytes(p->adev, p->bytes_moved, - p->bytes_moved_vis); - for (i = 0; i < p->gang_size; ++i) amdgpu_job_set_resources(p->jobs[i], p->bo_list->gds_obj, p->bo_list->gws_obj, diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.h index 39c33ad100cb7..e3d04ac4764be 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.h @@ -67,10 +67,6 @@ struct amdgpu_cs_parser { struct amdgpu_bo_list *bo_list; struct amdgpu_mn *mn; struct dma_fence *fence; - uint64_t bytes_moved_threshold; - uint64_t bytes_moved_vis_threshold; - uint64_t bytes_moved; - uint64_t bytes_moved_vis; /* user fence */ struct amdgpu_bo *uf_bo; diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c index 331b9ed8062c7..5834a95d680d9 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c @@ -621,13 +621,6 @@ int amdgpu_bo_create(struct amdgpu_device *adev, if (unlikely(r != 0)) return r; - if (!amdgpu_gmc_vram_full_visible(&adev->gmc) && - amdgpu_res_cpu_visible(adev, bo->tbo.resource)) - amdgpu_cs_report_moved_bytes(adev, ctx.bytes_moved, - ctx.bytes_moved); - else - amdgpu_cs_report_moved_bytes(adev, ctx.bytes_moved, 0); - if (bp->flags & AMDGPU_GEM_CREATE_VRAM_CLEARED && bo->tbo.resource->mem_type == TTM_PL_VRAM) { struct dma_fence *fence; From patchwork Wed Apr 24 16:56:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Friedrich Vock X-Patchwork-Id: 13642209 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3B9AFC19F4F for ; Wed, 24 Apr 2024 17:01:13 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1E3CE113C8D; Wed, 24 Apr 2024 17:00:57 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; secure) header.d=gmx.de header.i=friedrich.vock@gmx.de header.b="B40I6HKZ"; dkim-atps=neutral Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by gabe.freedesktop.org (Postfix) with ESMTPS id 41A7A113C81; Wed, 24 Apr 2024 17:00:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1713978040; x=1714582840; i=friedrich.vock@gmx.de; bh=1yE1NeqzI2xECsJABNGmn3QP2VnTIaEv65ZejUrgF34=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-ID:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=B40I6HKZsy/9dIxlVKxw9KW/UDekEPvvw5smrXUdYoB3tUxig41CyKP/uR7VkYCx xUfgTTyqJ6TqYEZ61CKxuWiCG5Swv09Wn+3IHpTsiow7nry/FoS0Sc5DuqNTzodEE MLEooG0x6udsGod2hZpxvyk/fF5cQdwbv+L8H/x/N+9wYEEGRCHyeK87/ygaIhvfm vCcS0STYtrTp4gHkNRsuHiQFjAeFwfoPd5XNs27+lGAKunmH35HgIKgRpbn6thkNx fdioruqYKxCD4hz57yEDMvj15jvGp6FwnF0HPlE5+0MsTMky4yOOqEA+2TavSInhc uAR6Fsfs4kj3+HUH+A== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from arch.fritz.box ([213.152.117.111]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MlNtP-1sOnaP036j-00krIS; Wed, 24 Apr 2024 19:00:40 +0200 From: Friedrich Vock To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org Cc: Pierre-Loup Griffais , Tvrtko Ursulin , Bas Nieuwenhuizen , Joshua Ashton , =?utf-8?q?Christian_K=C3=B6nig?= , Alex Deucher Subject: [RFC PATCH 09/18] drm/amdgpu: Don't mark VRAM as a busy placement for VRAM|GTT resources Date: Wed, 24 Apr 2024 18:56:59 +0200 Message-ID: <20240424165937.54759-10-friedrich.vock@gmx.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240424165937.54759-1-friedrich.vock@gmx.de> References: <20240424165937.54759-1-friedrich.vock@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:jXP8CEkU7U1tPZcrgRj1AmESpCJzigAn5RVze3Qgl/j+U1Pzswc MhC7LqvawFt3j5R+d1nREsEBl8Q7RYv+vcs6EDDLvy7HgGb3nSj2ZD/GzSDclpSnRTLi2dz yjxjCcEjrfA+Ee9xFSrNQof62cr5yoANs2SpKokijX/n9qYOLK6fQkFS0l3Ad9zAbiKNH4E dV1DC796d19sy32Aq3mwA== UI-OutboundReport: notjunk:1;M01:P0:Z7QgOlNXbQI=;gN9H0ct65fI+4gXNmTmYoeroHfw pMKy5BcIeg3G3h3n+PXkaOs2w3fWQuLe6WFKdQpihWjB0dskpuaSfao2loSb5HUCwI4m6rL3t 69Y9YAZ/c1sgJDAcvU4KqHTHNdocGfu8MnXWCFj2CoY7aeF85vSD4/2ajLQ8KU8JDBM/gQcJ3 sxeA99qLN8sVTeDFfRWdW3sjJx3VGXm/lnjvpJByDq/hxroGBptNt0QU6I0Yk3Wfn78b/7cTs JlXq9q40GSQj6/51nRI4J1Fx5UHKpVaRLHMSXzWiMScygXm4NIcKsPfuYyfQwiMb69IT6sGVw Yfts60ljxvkILG/oSj6czb4XF/G24apiahpFFzrpfmSIU8Hl7CvgmW2g/6diYz034Kx+GLLuT fMjalnR+mpxja8GIvaqqrr6BhOL6wT1c/Gpr7l4wGOFchGvhfQ3yFmWmfrT9QjqN/OY1RtLoc PzM6cEhCkAz1kyKRaXLqnOLIL3x8BYFgAxkS/O0B3n1lLndmd1Xh9FuIngs1lZDEO8C/XjYTn m1EvdJ11f0tMCfCZpOoCkAnQ1MrS6lKbbHwZ/X89B+uax4FLVOyZUoh9CGasOtUWRxztlpoep 77CfMjLzL8FX0uz9S+IQimwII3Y+/o9ujUJdvNlDQuzVjWHDVWWZ78H6eE27AlXDYWcZFTbt2 OOa6qpszeEm5G93FFfkDbomrkFpnuiCo/r3I5Silpc80JRmP7CkVq71EtL0xZUep0oTDZ+Fo8 B0TR8bF3yEfa5Kd/yDfb2bUPcXxd0sV8ogHeK57QVFHWMy/CagXIKNxrcTntACi2gPF0WXQUJ q6AuALQDDlbn+oE1NjkXVP6qstqpBFOxF3wr8PcoSsheA= X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 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" We will never try evicting things from VRAM for these resources anyway. This affects TTM buffer uneviction logic, which would otherwise try to move these buffers into VRAM (clashing with VRAM-only allocations). Signed-off-by: Friedrich Vock --- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) -- 2.44.0 diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c index 5834a95d680d9..85c10d8086188 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c @@ -127,6 +127,7 @@ void amdgpu_bo_placement_from_domain(struct amdgpu_bo *abo, u32 domain) struct amdgpu_device *adev = amdgpu_ttm_adev(abo->tbo.bdev); struct ttm_placement *placement = &abo->placement; struct ttm_place *places = abo->placements; + bool skip_vram_busy = false; u64 flags = abo->flags; u32 c = 0; @@ -156,6 +157,13 @@ void amdgpu_bo_placement_from_domain(struct amdgpu_bo *abo, u32 domain) if (flags & AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS) places[c].flags |= TTM_PL_FLAG_CONTIGUOUS; c++; + + /* + * If GTT is preferred by the buffer as well, don't try VRAM when it's + * busy. + */ + if ((domain & abo->preferred_domains) & AMDGPU_GEM_DOMAIN_GTT) + skip_vram_busy = true; } if (domain & AMDGPU_GEM_DOMAIN_DOORBELL) { @@ -223,6 +231,11 @@ void amdgpu_bo_placement_from_domain(struct amdgpu_bo *abo, u32 domain) placement->num_busy_placement = c; placement->busy_placement = places; + + if (skip_vram_busy) { + --placement->num_busy_placement; + ++placement->busy_placement; + } } /** From patchwork Wed Apr 24 16:57:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Friedrich Vock X-Patchwork-Id: 13642218 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 56224C07E8E for ; Wed, 24 Apr 2024 17:01:27 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DD788113C9D; Wed, 24 Apr 2024 17:01:10 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; secure) header.d=gmx.de header.i=friedrich.vock@gmx.de header.b="VXxzV25o"; dkim-atps=neutral Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1A011113C87; Wed, 24 Apr 2024 17:01:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1713978040; x=1714582840; i=friedrich.vock@gmx.de; bh=a/KOIUJNEvZE7XYrz5Fp2pC4GRWaSm1HIzkguOCSfBo=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-ID:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=VXxzV25oCTQV4EIrh8DfU287FV0esWJ8e5faeT4lGSiDGPQySjknrP17oexyKh0I O8nW4owy5HWaZpqUkCBbkJSFZxe7cEs0IFcrV7DbT2z8pbARtxd/WKkTUXyo9xtgR +PFy1McrWYvEKgrz5CFvdSC1blmlEIgsdgSddXSY0EKMADkEKSR9PuELE0DhQnm8q aFAmUNhHvY6hjVhq3H/ARGk3/iRwH1+JhhxpWqyGDtDsQWAheqN2z56jSneHMMk3C j7lBCsIgqnkYkdyAkYFuRrK7tpIHNSPbuv8wVFfwheUKW1uvOTajtB47SqqDxQbjB SyW7cNaf3mRn1CGs/g== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from arch.fritz.box ([213.152.117.111]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1N4hzZ-1sjDt124rH-00zdG2; Wed, 24 Apr 2024 19:00:40 +0200 From: Friedrich Vock To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org Cc: Pierre-Loup Griffais , Tvrtko Ursulin , Bas Nieuwenhuizen , Joshua Ashton , =?utf-8?q?Christian_K=C3=B6nig?= , Alex Deucher Subject: [RFC PATCH 10/18] drm/amdgpu: Don't add GTT to initial domains after failing to allocate VRAM Date: Wed, 24 Apr 2024 18:57:00 +0200 Message-ID: <20240424165937.54759-11-friedrich.vock@gmx.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240424165937.54759-1-friedrich.vock@gmx.de> References: <20240424165937.54759-1-friedrich.vock@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:RqOYfDkRbCkpZHTVmdARozlpT5Tna7PwJpauhc3w93E/7PTOksr 04G5+bGrrUr2vmHd6A8hlduY4IwY2W9CM6QJdhDEKXP/bHtERR+iLhuapWk1M4Q414s9evW wm0/YJ1TNywIO1ZVYmnT3Mp18QBSwSqUe8Q1PHT3LpwYdhnJdPvTBL4CvkfKZWFtfqbYPVF lVkO/HO9vsGOymSeUkqpQ== UI-OutboundReport: notjunk:1;M01:P0:C0OuSatXSF4=;ww9d6YWIXILDSZ0O6bepq4oC5VR H5JGgRMhvPUJX9SMSL1akVizG7NQm6b60d5lcFUqt4HJw3re/e1ZAPMwY0Cy4O1F4jjf/VPiO bmG7IEuMbqQEII+sAlse0tU9Xi5QJLtE69BMG6ai+Vh7sCY52JINIcWSnN3DNrBYAVFeOCvZP 06/LTEk7m4Bgosp/I1t0MBx29u96jSCLmt6X6UEFVzlJvTtHTGhgyv4TNPQmnOIB03OfFnx5v /8p8xgNZRe0mQgrGOgrC/64177qjAJAJyTPlqukv2HFAgx7JriDgjPO2tsm/K0HGuVWN+CQHE 4bIguROWA8be9GlBHc6DdnAplMXoj4KGzJ0qJy1SnVY2AipNLP9X7ZfpxSp2C3xFwTFemgR4k jwAkJObUo66y4lVvOrjbENctG/3XictWDNfkZUogQph+Yj7fITARZQxgMYq2xGplBkzsz93U0 dAgmJzR2lDTSCMXcBT56gnTycgtsj6gRGMlxrE61VSwshstzHn0mWd3w1I5sbb1eI/IH8OYB+ CX/XshtGdhQpf+1Uc9wtpU7NhcT6bumg2jAwD/G/9RZXEBhV18BOfsYHEQhurzoztzq1aLwr/ wq4ZKbP+QrauoWLPUEkoa9//GDUEiixtRRmdwJC6nETu4eY1L+FH7p0ymXfXpIE47kP4ZgzjA Kws3LuJWdRYi5YEieW+9htrNfRsp903RWSBS/1OHMa0saQsXONXhwg5aHxp2TDRyVMLG/sysK ipE+X0hlrDZJD5a9UinH++hr78LuKtugvM1kNsIplH7v2pxLqcxb5nrIsuCytssmRx+oeqac5 R98UTeLptluzr3euixe93XZYUCvrX/2u0UIJqJK+MpuUw= X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 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" This adds GTT to the "preferred domains" of this buffer object, which will also prevent any attempts at moving the buffer back to VRAM if there is space. If VRAM is full, GTT will already be chosen as a fallback. Signed-off-by: Friedrich Vock --- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 4 ---- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) -- 2.44.0 diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c index 6bbab141eaaeb..aea3770d3ea2e 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c @@ -378,10 +378,6 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data, goto retry; } - if (initial_domain == AMDGPU_GEM_DOMAIN_VRAM) { - initial_domain |= AMDGPU_GEM_DOMAIN_GTT; - goto retry; - } DRM_DEBUG("Failed to allocate GEM object (%llu, %d, %llu, %d)\n", size, initial_domain, args->in.alignment, r); } diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c index 85c10d8086188..9978b85ed6f40 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c @@ -619,7 +619,7 @@ int amdgpu_bo_create(struct amdgpu_device *adev, AMDGPU_GEM_DOMAIN_GDS)) amdgpu_bo_placement_from_domain(bo, AMDGPU_GEM_DOMAIN_CPU); else - amdgpu_bo_placement_from_domain(bo, bp->domain); + amdgpu_bo_placement_from_domain(bo, bo->allowed_domains); if (bp->type == ttm_bo_type_kernel) bo->tbo.priority = 2; else if (!(bp->flags & AMDGPU_GEM_CREATE_DISCARDABLE)) From patchwork Wed Apr 24 16:57:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Friedrich Vock X-Patchwork-Id: 13642229 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7CCB5C4345F for ; Wed, 24 Apr 2024 17:06:07 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 810CF113CA5; Wed, 24 Apr 2024 17:06:06 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; secure) header.d=gmx.de header.i=friedrich.vock@gmx.de header.b="VGftg4OP"; dkim-atps=neutral Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by gabe.freedesktop.org (Postfix) with ESMTPS id B6073113C9C; Wed, 24 Apr 2024 17:06:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1713978364; x=1714583164; i=friedrich.vock@gmx.de; bh=F7lHcI6ytAxOptifXGV2LrH3pzT2g/pB/L5CHP1gZyY=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-ID:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=VGftg4OP3obyxwJd76/LeBf5Bm3o1LTqBzQ/oICPIl31ip9y9XgeQpVYxXKMC9Sa odZfOYl5f8i3UPfWVC2vq6k9ci5j0TvsiuYuUe7IlZSWmlP0Q/AdpWt2BHEvFxgrI THtrYILejpVa7QEyQ+8pO9xz6zmlHkggE1yVV6iFJLNNaYZ9FsZulphsoUqhW2e7q kYvYthQUwGs+uxun6qw7GI1enAwcXS/s+Cj49lniQiV9ZqeOjyCg8Lpvt845CkVZb zfPURqMwEr8JePhbhVf33dK9Qo9SZ6VGaLbC+5w1B/69dfEvgwFxxVLFhWBsASwyC unAupyuEyB+FQwFUdg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from arch.fritz.box ([213.152.117.111]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MmULr-1sPu3744i9-00jkpc; Wed, 24 Apr 2024 19:00:41 +0200 From: Friedrich Vock To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org Cc: Pierre-Loup Griffais , Tvrtko Ursulin , Bas Nieuwenhuizen , Joshua Ashton , =?utf-8?q?Christian_K=C3=B6nig?= , Alex Deucher Subject: [RFC PATCH 11/18] drm/ttm: Bump BO priority count Date: Wed, 24 Apr 2024 18:57:01 +0200 Message-ID: <20240424165937.54759-12-friedrich.vock@gmx.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240424165937.54759-1-friedrich.vock@gmx.de> References: <20240424165937.54759-1-friedrich.vock@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:cJ9kEEaK/mTj0xTVPmwCLOMniFXw4SoCHSCS4Bb7Bx34TvSPLdr FrfIDKKi2cxt6yJOza46WDAivXuAHGPiDPxgmDLKFgWEwF3AVC5yeNlBvH17VrT7Yxm+MWr Xw43sl8fjOkVrXNFA5EOFN/CMWd2tPciWu58bjnmNFO0FIhvVudieIfZIKIoP5frx/8ePij I14dq9CbBPSOZkWfM3e9w== UI-OutboundReport: notjunk:1;M01:P0:IO+EGkx9vBg=;yULf8o7R9IYMVYn0Kach1q27lNR zlOSv1ujHzH0IP09OnSmr9I9LavJKQzlNXhN9AukBucpEw5snJU5e8PVzf9zjTn5T+Sxa/+2V YS1s96hSeRCLzwxfC8tf+pG5Q8ihgQfuy2H+7t8H5jAoajGZE3WG/AfV3h0mAu8jqAgKaQMZ6 pHu484Wk0ze4vFxgAE2C46HcjawLo++TCxOQwHK2wa7V2im6hu84RC8FOUxxvCxzZcmOmRNzZ nw2htkhGvy8lP5YF4LQ33NV/ajnu+6AP5spqqDQfEYd1xRoG/VWFafhg3dUvZE/01uU2ptqzx +Ad9LiN1IcW99oqGVtA+cQKxONekxFqP/cF9GES2Pu007Ob9rD5IaL9r1IVDMKqiC4GCrR45u BxpOcIwfexh063J3/6/MGXg7YIoFUjTYOTZjMFjpsopd5tLtc4/Berc/DG4EXiSHikU48rhVa wHCk5NbVH+EQfJPjKHZrVty9gIdSWMMLC6MZZfSVLhILcMG2FZjLFpNwn0+hQ07foPbz7nJxL xCW7K1FNorr74zpMnSlndJRvMfDwhuM6nZ7P6OY0zJ9Eg3BIz4f1WUFhb7Lyo5v/3poeSiLPB eNhDNFa7CDWkQ2a7cUDaQ+oohS80gPR5kd6N5OWnHPr9/XnMiiQuzFEUiDAtV25c4g1RFyIuf bDQ+1A4rVq+ofRDV2ef53/TL54fOVwK8ze0k3yDYdufNi5ogy2WBcFGPMwkZgIqueE5PGx/wG wnlZv9/P6lyr5xWeeypUj/2lcYzOZ5E0FuH6wOhBU6gyerEggfLwDeGpB6CavfVsotIQMtBNq QpcZpR9fI3pUJkK2tOztfYgY9wq3OledbfGEpsJ5gNzRI= X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 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" For adjustable priorities by userspace, it is nice to have a bit more granularity. Signed-off-by: Friedrich Vock --- include/drm/ttm/ttm_resource.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.44.0 diff --git a/include/drm/ttm/ttm_resource.h b/include/drm/ttm/ttm_resource.h index 7d1ce059c8805..241643447488a 100644 --- a/include/drm/ttm/ttm_resource.h +++ b/include/drm/ttm/ttm_resource.h @@ -35,7 +35,7 @@ #include #include -#define TTM_MAX_BO_PRIORITY 4U +#define TTM_MAX_BO_PRIORITY 8U #define TTM_NUM_MEM_TYPES 8 struct ttm_device; From patchwork Wed Apr 24 16:57:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Friedrich Vock X-Patchwork-Id: 13642212 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F0C84C10F15 for ; Wed, 24 Apr 2024 17:01:16 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CF81C113C9E; Wed, 24 Apr 2024 17:00:58 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; secure) header.d=gmx.de header.i=friedrich.vock@gmx.de header.b="S2ycc8Nj"; dkim-atps=neutral Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6BB7E113C87; Wed, 24 Apr 2024 17:00:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1713978041; x=1714582841; i=friedrich.vock@gmx.de; bh=toDqG0EtftLVKgwAfYmZDmxHwmiPViX4qpOT8SmMAk0=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-ID:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=S2ycc8NjpeDGRYnt8ElFGl3rd7MxKA+ffafUzSGqJVZL6NAkSK+iUqHnEwzeymyg Mt6boTshP2BfCmu5+lDgcuv755tAcUVItcgDINndIllduc0iqR8Eg6QGVBLcnbSoP LOZFdXUQiqJVmUxfkSg0LdnVPAYmGJ2evCZutoUidKOyEdpKK1qxDYdPhJeAnAYjF Uhpl9D1TczwVKt9Ii55jjCvDQmNSzW9ZI6TzSPkeQn9bS+0Zie18T2+RzThKIrdKM 3ob2/KxMpW2/Bf0ZOThwpnmiJVHqPEQFBafnCX2j5ZqQQh4MCrErYfPXRk7Wo+8Nl 5izsN7Odl2Yn40S6pg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from arch.fritz.box ([213.152.117.111]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MQe5k-1sNNXD22xK-00MQlD; Wed, 24 Apr 2024 19:00:41 +0200 From: Friedrich Vock To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org Cc: Pierre-Loup Griffais , Tvrtko Ursulin , Bas Nieuwenhuizen , Joshua Ashton , =?utf-8?q?Christian_K=C3=B6nig?= , Alex Deucher Subject: [RFC PATCH 12/18] drm/ttm: Do not evict BOs with higher priority Date: Wed, 24 Apr 2024 18:57:02 +0200 Message-ID: <20240424165937.54759-13-friedrich.vock@gmx.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240424165937.54759-1-friedrich.vock@gmx.de> References: <20240424165937.54759-1-friedrich.vock@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:VY5VDLev0ESq1+HxUQDvrBZdcGB5VjDEAOUWfKECM8TbODUS+7k zh2hj2r6J0stnbGKskRQTsGemcLQb5RtUvv599WdbjgYWB98ioQuNrjHq8fLoCSju96OVmn ZSxEx7V6r3kwGQW08jxIt1JScTF0G+BQhHS/Bm9Zj4dLzGjOZ5njU0+cKqz4bzhRD7Mc1jl hEq0qFptw1np4f6jZFBrQ== UI-OutboundReport: notjunk:1;M01:P0:2i+Q1BCimCM=;eo3BLJ+xbUfvgH7+iTx2BYTjRta IbKS17PpU/asvAzvOo61LG/1e9YwO/CAyZvSmkHdrg63/7T/+xL3OQKLZRLOEbHh3ZnuHro1p piUNTB8f9xYc7UI+0B2LjXglxU5Ki0sN8F9iIGjR4yXOJJTqGZZQNUO5Bf8iKI3CawfHn4Zb3 XKiLZGznKaneXzvO6VRFqnklnTvuiJy5/2nvFBwtxYym0QMzB2p1vhfmb+xnp+nmipUVZoNq8 mmZrWFILB6mUicuyLf+F5QHZjeYR+Q4lOp6dPsqsh9Tpp9OR8N78NUEv6t3OVCu6bhLD0qCL+ B8TXcNJ7m7zQHEFPZei+IST/H5fJ+RtMMZohhFmN4UAHM/bZkMFYQ9mEzLa0jPWWxBgGsvRVC 5sE3yPrs/YXCiZld4lb2yhfHHz4xzsxTbzQO87KDHm8dX2ooPsKOr4BHD7TGwknoXQPQfO7lD hlsmpH4aMYd/CSD8p9mChCiWErZsa/+kyBWBJX87bFRzqCAzzK6jQ+/KzdlHQoBAkFNqF5PF/ DtHavktrBqvn7WIClfqvnZPSYlpaZzgxsFkODOeP4sYJevNEnxmEyEEp6SNZA2BFnGOEwBwPU gOtmGWWeyo+hU1oJ/BesJNe4UlKJcPjF4qtbmXJmT5EparFbuY+vheThGSsBS6i+Yn+XHJavb Na5gZGuBoq6C8fl9c2U/olbjqbKdCR5p4x9HKjnElXBhpEI5Iwgfzhgy7E+XYQFZIYh1PIYm6 8933Sj596iNVQDwyZBMVGlgMBGEX4TMuD41hYUKd1bUlvHyG6+aFqHt5EwNICbsuigwS+Q4TE Yti/t7XU2EzMujWKS+Z21EAkvHO9OgNAoR3aduAzgiIio= X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 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" This makes buffer eviction significantly more stable by avoiding ping-ponging caused by low-priority buffers evicting high-priority buffers and vice versa. Signed-off-by: Friedrich Vock --- drivers/gpu/drm/ttm/ttm_bo.c | 9 +++++++-- drivers/gpu/drm/ttm/ttm_resource.c | 5 +++-- include/drm/ttm/ttm_bo.h | 1 + 3 files changed, 11 insertions(+), 4 deletions(-) -- 2.44.0 diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index 3047c763eb4eb..eae54cd4a7ce9 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -776,6 +776,7 @@ static int ttm_mem_evict_wait_busy(struct ttm_buffer_object *busy_bo, int ttm_mem_evict_first(struct ttm_device *bdev, struct ttm_resource_manager *man, const struct ttm_place *place, + unsigned int max_priority, struct ttm_operation_ctx *ctx, struct ww_acquire_ctx *ticket) { @@ -788,6 +789,8 @@ int ttm_mem_evict_first(struct ttm_device *bdev, spin_lock(&bdev->lru_lock); ttm_resource_manager_for_each_res(man, &cursor, res) { bool busy; + if (res->bo->priority > max_priority) + break; if (!ttm_bo_evict_swapout_allowable(res->bo, ctx, place, &locked, &busy)) { @@ -930,8 +933,10 @@ static int ttm_bo_mem_force_space(struct ttm_buffer_object *bo, return ret; if (ctx->no_evict) return -ENOSPC; - ret = ttm_mem_evict_first(bdev, man, place, ctx, - ticket); + if (!bo->priority) + return -ENOSPC; + ret = ttm_mem_evict_first(bdev, man, place, bo->priority - 1, + ctx, ticket); if (unlikely(ret != 0)) return ret; } while (1); diff --git a/drivers/gpu/drm/ttm/ttm_resource.c b/drivers/gpu/drm/ttm/ttm_resource.c index 1d6755a1153b1..63d4371adb519 100644 --- a/drivers/gpu/drm/ttm/ttm_resource.c +++ b/drivers/gpu/drm/ttm/ttm_resource.c @@ -431,8 +431,9 @@ int ttm_resource_manager_evict_all(struct ttm_device *bdev, for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) { while (!list_empty(&man->lru[i])) { spin_unlock(&bdev->lru_lock); - ret = ttm_mem_evict_first(bdev, man, NULL, &ctx, - NULL); + ret = ttm_mem_evict_first(bdev, man, NULL, + TTM_MAX_BO_PRIORITY, + &ctx, NULL); if (ret) return ret; spin_lock(&bdev->lru_lock); diff --git a/include/drm/ttm/ttm_bo.h b/include/drm/ttm/ttm_bo.h index 8f4e6366c0417..91299a3b6fcfa 100644 --- a/include/drm/ttm/ttm_bo.h +++ b/include/drm/ttm/ttm_bo.h @@ -396,6 +396,7 @@ void ttm_bo_unpin(struct ttm_buffer_object *bo); int ttm_mem_evict_first(struct ttm_device *bdev, struct ttm_resource_manager *man, const struct ttm_place *place, + unsigned int max_priority, struct ttm_operation_ctx *ctx, struct ww_acquire_ctx *ticket); void ttm_mem_unevict_evicted(struct ttm_device *bdev, From patchwork Wed Apr 24 16:57:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Friedrich Vock X-Patchwork-Id: 13642214 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 85E34C07E8E for ; Wed, 24 Apr 2024 17:01:19 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0E8F4113CB2; Wed, 24 Apr 2024 17:01:00 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; secure) header.d=gmx.de header.i=friedrich.vock@gmx.de header.b="awFamVbL"; dkim-atps=neutral Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by gabe.freedesktop.org (Postfix) with ESMTPS id 246A2113C8E; Wed, 24 Apr 2024 17:00:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1713978042; x=1714582842; i=friedrich.vock@gmx.de; bh=v1EbVgOMiqUXagB/y/cMZLK1xcQnLlZIpQIszhLMlrk=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-ID:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=awFamVbL0koHnPaIicXmtGcKH2CCwscGO3BadBsMDT+eh145T2I6vF0GqqXTyy0N or6g7jeqZwX3qDkr4mtPLqNcx58iFeifO3VkrQMztHw0+lIcLzzjXitv8Wcqd8//L /+0Fx/RFivn86YLET7HCBywcSPS127AUGDQ6oDHH4cKCaaVf1E+QpHjEdEK8fsTlE sUTlsKw2DSjCkOwYJZrwpy0QmRFnBDCYwetiQXHHfz6AbZLe9pMebwPYlF+3vesNf TxeZqZKM40KdX19/YGcaV05jJiI9tXZCzBXzm/ib5EqUY47Oo9//UOWrsVEZudYWx k2m9oSIgn9Oo2msv+g== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from arch.fritz.box ([213.152.117.111]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MaJ7v-1sDism43Mr-00VXIS; Wed, 24 Apr 2024 19:00:42 +0200 From: Friedrich Vock To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org Cc: Pierre-Loup Griffais , Tvrtko Ursulin , Bas Nieuwenhuizen , Joshua Ashton , =?utf-8?q?Christian_K=C3=B6nig?= , Alex Deucher Subject: [RFC PATCH 13/18] drm/ttm: Implement ttm_bo_update_priority Date: Wed, 24 Apr 2024 18:57:03 +0200 Message-ID: <20240424165937.54759-14-friedrich.vock@gmx.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240424165937.54759-1-friedrich.vock@gmx.de> References: <20240424165937.54759-1-friedrich.vock@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:ZAaSNzUaY+QqjHlYyHPyUjkrF6rMvq32hm+AlziChmc6KNewZ4F YliItUwcoXXaBfcGbYDTaZPvG1KYZJkisxIidetdfERnH+DnVtQCJFIo3zW/MSVjvGuQFEw Z9i/UNAlJDN4A0MhwCmU2GX5K04aXll9top6g7sg+dpJJ8NtYA/QKXdpsWA6/6mkYKqt8Yh HbanuTec3uaYkcADhOQ0A== UI-OutboundReport: notjunk:1;M01:P0:Rbh3TRHnxbI=;htBDbhryNDhyJ955ohgsaqwDOTY mhD+hbGC6gJqWwIW6qSRR47BocSWlSgHqpKyMicKw0JBU0QEwYTmgzjEx+ayIueu4TJBx42iY TCqs/LKLMVJ0Rc0yrU7bZWBRABbk/QnXqYI2meWejvtvsAfGdTGqRUEsm9L7HNkmyASyw8If8 Drrj38rYvlQUPAjM4mlftqxPglir+BuLyGQDR0iLcX0JSEqhAVy1B0A2KQy2SBkVtkzwlQvJ6 Og1h814KqR0nLcYTSx0c8O8bB9rU3nQ6sgItz+cHZOSsdQ8br+kKA8VX65eGcy+lt0UcFB+ek Ndj+0/mXvGM/AxMmE2V1falVVMIRFkz3I5E8u7JbRaYwLrTwr1MLklemkiQTmue5EatSdxpvj H30DPPmZXcY5TNcVgy2vaW/GvU2DlNf1bRJs+WU8avrcNelv3dxamqrm2uh0qNJfUsVY/17Ku jUOVpvspiHfURgjvktTw0i1EcN8RMqUH4u4aUNLLMH59HI0B3nAxZMPPpilYdG4XIwc2wsik7 9JJVx0H9E20tT/2CvYrXOGYpUxzzhvymBk3PweM1PYauROydq/rGW8wCxlB5TU2nTQBdO4mxG glTwuKokvKwwCI/k66Ngwk+DQtmG9vXf6WCM6W1ryqhcnQSp9Zg6Hf6+22gTnd7bkMHzWFqSp B9x6E+OY/dhOAUDMLpd9nwxBlDJAARlPKfI3xY4eXRRPHsLXWw8gSGTzwgBTxLH0TWg6GaCda u1xceh4vCFjJHfai1aLdy1oYqIx3KskJbs+n8vHqSX7RhNtI0hqgS4QC8RmPc5F6izAP6l3et 1HLzHLYQReNCvGnq+V6jChh63CND2drspEw7qddOGPMBM= X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 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" Used to dynamically adjust priorities of buffers at runtime, to react to changes in memory pressure/usage patterns. Signed-off-by: Friedrich Vock --- drivers/gpu/drm/ttm/ttm_bo.c | 17 +++++++++++++++++ include/drm/ttm/ttm_bo.h | 2 ++ 2 files changed, 19 insertions(+) -- 2.44.0 diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index eae54cd4a7ce9..6ac939c58a6b8 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -112,6 +112,23 @@ void ttm_bo_set_bulk_move(struct ttm_buffer_object *bo, } EXPORT_SYMBOL(ttm_bo_set_bulk_move); +void ttm_bo_update_priority(struct ttm_buffer_object *bo, unsigned int new_prio) +{ + struct ttm_resource_manager *man; + + if (!bo->resource) + return; + + man = ttm_manager_type(bo->bdev, bo->resource->mem_type); + + spin_lock(&bo->bdev->lru_lock); + ttm_resource_del_bulk_move(bo->resource, bo); + bo->priority = new_prio; + ttm_resource_add_bulk_move(bo->resource, bo); + spin_unlock(&bo->bdev->lru_lock); +} +EXPORT_SYMBOL(ttm_bo_update_priority); + static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo, struct ttm_resource *mem, bool evict, struct ttm_operation_ctx *ctx, diff --git a/include/drm/ttm/ttm_bo.h b/include/drm/ttm/ttm_bo.h index 91299a3b6fcfa..51040bc443ea0 100644 --- a/include/drm/ttm/ttm_bo.h +++ b/include/drm/ttm/ttm_bo.h @@ -359,6 +359,8 @@ static inline void *ttm_kmap_obj_virtual(struct ttm_bo_kmap_obj *map, return map->virtual; } +void ttm_bo_update_priority(struct ttm_buffer_object *bo, + unsigned int new_prio); int ttm_bo_wait_ctx(struct ttm_buffer_object *bo, struct ttm_operation_ctx *ctx); From patchwork Wed Apr 24 16:57:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Friedrich Vock X-Patchwork-Id: 13642216 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1E1DCC19F4F for ; Wed, 24 Apr 2024 17:01:24 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5C9C2113C95; Wed, 24 Apr 2024 17:01:04 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; secure) header.d=gmx.de header.i=friedrich.vock@gmx.de header.b="IxCPYjfg"; dkim-atps=neutral Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3E9A1113C87; Wed, 24 Apr 2024 17:00:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1713978042; x=1714582842; i=friedrich.vock@gmx.de; bh=b6EoFsH7sLs384Atuh1oGN0mYQhG/Es5DDbOcdb23qA=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-ID:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=IxCPYjfgss1e42ng+/GsckyA9nCiETZO3bA2iaDOH/2Pb3yAB95EaPQmeOZrJpm7 iXc105bJhShdPVcczrRVh/3NKCgtUDwPVPU1qqjElOD3Uh1Nz3AiByOaxfiEP3rJF hSb1lNbWHKzTkl/olPgXMcy13IgR7W1rPydZprQkAM0G4sYsiHwwZjZwaKFMdGggw GCF7k5+u3XWqa/19QrSPvK2fLpQs8ONSk/7v2IsQBnnoWXMurBla9JGz8y5AAchZ0 NYZMexWKrRhYeVsGxq9YBJkANerMLb6uTHG45FUDnAe2wTyrM8sk456Q749Z2ga3k 62HKws2AntpDR6POhA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from arch.fritz.box ([213.152.117.111]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MpUUw-1sTSHW25Vs-00pYFx; Wed, 24 Apr 2024 19:00:42 +0200 From: Friedrich Vock To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org Cc: Pierre-Loup Griffais , Tvrtko Ursulin , Bas Nieuwenhuizen , Joshua Ashton , =?utf-8?q?Christian_K=C3=B6nig?= , Alex Deucher Subject: [RFC PATCH 14/18] drm/ttm: Consider BOs placed in non-favorite locations evicted Date: Wed, 24 Apr 2024 18:57:04 +0200 Message-ID: <20240424165937.54759-15-friedrich.vock@gmx.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240424165937.54759-1-friedrich.vock@gmx.de> References: <20240424165937.54759-1-friedrich.vock@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:yBLI2MoDBze2F6URJMuxofpt2DIPDheiA1tfa//NrDaUM1l3kFG bell4fhMj2OrNY86/heGliQ/WDTliXNq7AnjWaXsY320+DRQSteYS2kf+rWSsVZ6udRZ9v5 vME2l7OHG6FiCVgT/Qoj7F1Bf3czFpK23ReGH++sJY2LIqMu8ZBtuPRWH++QVrNK2Auk56l EfUbsh7Zga85V9sxxdx+w== UI-OutboundReport: notjunk:1;M01:P0:9oZG70QMkm4=;9FeUcAOvVEf3ykPVWsnaxc7wsmP 7emC8mKis9u8iIAdeRPHgj5gtU9n8mLIlNoJCXu+BnN6JNxdMXOV8y5QU5xyWMGnLQzQbelbD s03Y2Ne+XqSPeB2oLEbvCuRUyGWbUghdimbuaanS/34RuHqplYSx5XpzoxKakbc/YPIBTjooz HPGP11cmIW0NwOKZ3Ks886JC9cj/dKDdw5ehy5DPcGyyufPszmsoBXXLQAxtAN1Rr8iOCdh8l ZwYeZjt4XhxnVkFh5XifOVT4rgiDzP+FVPHgihsUUk0kWD1TmVRdQPKNofoMrfX6kDhL6knRH Vcow4fhmutbq/wd7V8fbFkhrv49e83khRLP9kkGJFGRWdB0eVom09zzuxRNKhpyVt7+V6vQ/e OJyOJZN3S3uGbZ9jW9yNRzh2RBHHYfh2OJeEk6Me6yOQJAODE7Pn54U4cvUfmxH1QjfHUBeFq czMH1MfMKm86gpgDlBV7tI3XFgY5RI8DzzVrK1tNxlB6fIOs5/DoD+Jj6E8ERxt4f8MVuk5dF nCJEzqnhhG9YySjFCphRHDhXJUYnvpFPSmeiwqYMOJ2AiFAt47k86EtGehoriwlNhJWZRst0H S+x2Er79Q77EiayZltGegyzOsg5dcdFRKme/Igdr90KNRmMtVf0euHYv5j6atc1PH5o9LpeD1 hL0BpphcuA5VZE6PsyzijHCf3L10kKNXYnx2GL7w9t1A5Bd3JckDEXLvRZR16Bd2C0XmA0qn7 aftqVzUNGG2tFvbGSGYkjQmOmAN7S1KscnNTIBBgeqZHjxN/poPnndZQOIfurqYi4gcN1VFs7 l39Hvyyu7K5YjbIAGiKvhL4aQBN4FGu9mwwG+8oF5ghKg= X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 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" If we didn't get the favorite placement because it was full, we should try moving it into the favorite placement once there is space. Signed-off-by: Friedrich Vock --- drivers/gpu/drm/ttm/ttm_bo.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) -- 2.44.0 diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index 6ac939c58a6b8..af8209f3bc894 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -1111,7 +1111,9 @@ int ttm_bo_validate(struct ttm_buffer_object *bo, struct ttm_placement *placement, struct ttm_operation_ctx *ctx) { - int ret; + struct ttm_resource_manager *man; + int favorite_mem_type; + int ret, i; dma_resv_assert_held(bo->base.resv); @@ -1133,6 +1135,30 @@ int ttm_bo_validate(struct ttm_buffer_object *bo, if (ret) return ret; + if (bo->resource) { + /* + * Also mark the buffer as evicted if we ended up in a + * non-favorite busy placement, so the buffer get + * moved into the favorite spot if possible. + */ + for (i = 1; i < placement->num_busy_placement; ++i) { + if (bo->resource->mem_type != + placement->busy_placement[i].mem_type) + continue; + + favorite_mem_type = + placement->busy_placement[0].mem_type; + man = ttm_manager_type(bo->bdev, + favorite_mem_type); + + spin_lock(&bo->bdev->unevict_lock); + list_add_tail(&bo->evicted, &man->evicted); + man->evicted_bytes += bo->base.size; + spin_unlock(&bo->bdev->unevict_lock); + bo->evicted_type = favorite_mem_type; + } + } + /* * We might need to add a TTM. */ From patchwork Wed Apr 24 16:57:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Friedrich Vock X-Patchwork-Id: 13642213 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0A52EC19F4F for ; Wed, 24 Apr 2024 17:01:18 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E3F22113CA2; Wed, 24 Apr 2024 17:00:58 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; secure) header.d=gmx.de header.i=friedrich.vock@gmx.de header.b="brC1TjHT"; dkim-atps=neutral Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by gabe.freedesktop.org (Postfix) with ESMTPS id C23A3113C8B; Wed, 24 Apr 2024 17:00:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1713978043; x=1714582843; i=friedrich.vock@gmx.de; bh=ZHxm4e4BKlDt3g/OuZIJ+Bxa1wcUho2Fc/9cnNxPoQc=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-ID:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=brC1TjHTfYPQa1+rGrCT+OOU1c549n6GynUUdCdZrohVrwwQ4ruLz5H9iX3GFGRN Jl1d5PisbDmccpR7kit9Ske7PXmJuzWtqZPzVIu7ofoeXqU1nGPocoxoBL8hwJST/ t8Go9vg/zm35uAVJDvglUjiGE1wV1e9H02KW7LgPVY24d+BjkcJ99hzQSsqx78oJV scH6Iflwjmxa/I+Pzy146KLE9p4voJMh5sSJGc/UDS2Z8aa3dx0rPJ56b91F8q4vG 10AA491XIm1wDE78YOnyDVpCvMjZg0WXFrYp77lqX5aYKc/7T0y07KUDCx0hyhYRp higgWeudgzxeKbJUAw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from arch.fritz.box ([213.152.117.111]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1N1fis-1sfdVy4BBo-013liz; Wed, 24 Apr 2024 19:00:43 +0200 From: Friedrich Vock To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org Cc: Pierre-Loup Griffais , Tvrtko Ursulin , Bas Nieuwenhuizen , Joshua Ashton , =?utf-8?q?Christian_K=C3=B6nig?= , Alex Deucher Subject: [RFC PATCH 15/18] drm/amdgpu: Set a default priority for user/kernel BOs Date: Wed, 24 Apr 2024 18:57:05 +0200 Message-ID: <20240424165937.54759-16-friedrich.vock@gmx.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240424165937.54759-1-friedrich.vock@gmx.de> References: <20240424165937.54759-1-friedrich.vock@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:+2jx7HC7i8HHO2c70tVkhyyYN80yjf031Qi96QlKJrZ0clmZ3p4 wADbmFIbD5W1xpWLtGgeyeWa11e2ekpWovWx5/0GMUvoKjw9JLuxLgn+9tvwuEFvG0AxXM/ nENrtd7rYcX104rGpsM2A3rJ2TJJk/zltMimya+gd+UXERrYw6pKtTXtgxlCncDfckLhYjf jY8J01PV8Gy/VDnur3i8g== UI-OutboundReport: notjunk:1;M01:P0:h9audP43sV8=;hSjdEzFdSB8ERv0M0DF9ok1EeO+ 0ATfU3ytuE+8f4ocMy1k4M0onBDa0vcrOrku4/2/ELIfDMaQqWuavhVxKKMXztM0EOjTsWH4C bj3ZYheYp/HszZHq7bANgdcrMyFF/zwQhYXXu5RNG2G7Gq27iQpb3thtG7dpeDRoAB5u1KfU5 hoMpzzmY0eTsL/a10mAr3PVqDs0c9kKuluiOxj0Mk9PFYtzetqA0PzZSYTbT9qRQct21L9HCh 1Q8/5k1100JdFY+pzj0vhWOQyFZPhpGRdUHpI4MWKDPC6ErkPJ1WhlPttBPjrFYdemkE7FHpB tUGJO/SpEVxWipeYS06CQh1zQ0Zg2dxFFUfMnjGxOtmlhp6qcKMpVIyeKzR/OZKR8UJOv1Jj6 uBuVnaYmMiXRhngGJkLRABfb0YGRX/UqL81uXZztYoh9boa1bNlv+yajn+UYa9YQUsUGNBE4I PV3O79eL1pKuJ9Z5PR734K4bOyxF4Hw8HldXHshV7GAGjbJRce2gJCGLvas4P8xBHQ/0yBzlY eqFc5AlNUZIB+bKt7sdQSGNgLMdt3p8VBoRnYAQ5xFemhlBkSSQXpuoPeu7+qmHt3Dhm+J+KM jgwqgZF34MAGOff91W0P4RYfhnZAAoQRnaS3Btc6tKuVqdAhb2FUp+Aivobwxd23AVtjT0g/f MOkEPA5A+lU6+srZ/5SDQZna9R7U3eJRu2Bp/u/UGCIKXuYTpOk/1hrLs3u1CMiTteQ4srm/0 E5gY+YM555w2Trpj16gH443PYzB3AEsBC5Ar2q3vDUJMnYburNMcz4W93FpRtUwnoSjyXgwLl 41q105CuaPob5zKYvJtytZwznBKyr0QVwZYkYIP5fXAuc= X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 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" Reserve the highest priority for the kernel, and choose a balanced value as userspace default. Userspace is intended to be able to modify these later to mark buffers as important/unimportant. Signed-off-by: Friedrich Vock --- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 4 ++++ 3 files changed, 7 insertions(+), 2 deletions(-) -- 2.44.0 diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c index aea3770d3ea2e..5ca13e2e50f50 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c @@ -114,6 +114,7 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size, bp.type = type; bp.resv = resv; bp.preferred_domain = initial_domain; + bp.priority = 4; bp.flags = flags; bp.domain = initial_domain; bp.bo_ptr_size = sizeof(struct amdgpu_bo); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c index 9978b85ed6f40..0e9ea11a873ef 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c @@ -621,9 +621,9 @@ int amdgpu_bo_create(struct amdgpu_device *adev, else amdgpu_bo_placement_from_domain(bo, bo->allowed_domains); if (bp->type == ttm_bo_type_kernel) - bo->tbo.priority = 2; + bo->tbo.priority = AMDGPU_BO_PRIORITY_KERNEL; else if (!(bp->flags & AMDGPU_GEM_CREATE_DISCARDABLE)) - bo->tbo.priority = 1; + bo->tbo.priority = bp->priority; if (!bp->destroy) bp->destroy = &amdgpu_bo_destroy; diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h index 0f277bc6a2e32..36513da0ec767 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h @@ -42,6 +42,9 @@ /* BO flag to indicate a KFD userptr BO */ #define AMDGPU_AMDKFD_CREATE_USERPTR_BO (1ULL << 63) +#define AMDGPU_BO_PRIORITY_KERNEL (TTM_MAX_BO_PRIORITY - 1) +#define AMDGPU_BO_PRIORITY_MAX_USER (TTM_MAX_BO_PRIORITY - 2) + #define to_amdgpu_bo_user(abo) container_of((abo), struct amdgpu_bo_user, bo) #define to_amdgpu_bo_vm(abo) container_of((abo), struct amdgpu_bo_vm, bo) @@ -52,6 +55,7 @@ struct amdgpu_bo_param { u32 domain; u32 preferred_domain; u64 flags; + unsigned int priority; enum ttm_bo_type type; bool no_wait_gpu; struct dma_resv *resv; From patchwork Wed Apr 24 16:57:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Friedrich Vock X-Patchwork-Id: 13642231 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E4C97C10F15 for ; Wed, 24 Apr 2024 17:06:08 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B637A113CBD; Wed, 24 Apr 2024 17:06:07 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; secure) header.d=gmx.de header.i=friedrich.vock@gmx.de header.b="QL/oPBIM"; dkim-atps=neutral X-Greylist: delayed 310 seconds by postgrey-1.36 at gabe; Wed, 24 Apr 2024 17:06:06 UTC Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7A223113C9C; Wed, 24 Apr 2024 17:06:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1713978364; x=1714583164; i=friedrich.vock@gmx.de; bh=ZFgynH9kVvXd7X71GGc8wd8zn3hjzWcTxqNGMvCSWsw=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-ID:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=QL/oPBIMC6OnNxEcvez3C1Oza5okI/5VUk9gQtY08LrfXPwxjIZn8kviSwg+kZdi lFEkeZQfV8oAHSi/97X4h3AcyDKOKl1iwJrkt++O+z/8BqG927TxdCWQvFcM+srIZ ozp9siUl4USYulmABqI3iiTsExyEcB4eIMuQF8BNJPsRs1FT4YDadRVWllThNv9E6 +Zxqi2j1XDYMXArofBMeKL6cbwHbnW9OwRkVppSeB6WqtXa3lDFG1NdmJPd6pdpIu OjAH9w1lfWLytzOjQAsz+lvor/+/T1tMxlQ6QnkGN3ftonsqLcztcnsA8vXKZM1J4 P8727wqaAaZXcLrQdw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from arch.fritz.box ([213.152.117.111]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MMGN2-1sIzoz1zUM-00I0ut; Wed, 24 Apr 2024 19:00:43 +0200 From: Friedrich Vock To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org Cc: Pierre-Loup Griffais , Tvrtko Ursulin , Bas Nieuwenhuizen , Joshua Ashton , =?utf-8?q?Christian_K=C3=B6nig?= , Alex Deucher Subject: [RFC PATCH 16/18] drm/amdgpu: Implement SET_PRIORITY GEM op Date: Wed, 24 Apr 2024 18:57:06 +0200 Message-ID: <20240424165937.54759-17-friedrich.vock@gmx.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240424165937.54759-1-friedrich.vock@gmx.de> References: <20240424165937.54759-1-friedrich.vock@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:btnRn+8eRzZVxSdWw26IvGCDOAMk3OXN59r3kdY0wQ/jG50Vh1X Wx4twcdHEUJeiRYLdQnD2cyx3HJjFIpKO3GjNLpxK0qZP3BvvjBfnA1jhKsePILqOn2Zd2a oBD+4HRuczSD/drkjEmJmZlQMezPR1yv0AFdu6Lh1wbabrixNnYiAPRarpNAmPfOM9/95cn kYXAsOo2J0+ks0ep3/Dzg== UI-OutboundReport: notjunk:1;M01:P0:cd9kI+Aei+0=;2xKl2czPTjHzyyiKmUssheRK8Re EkLS7Hr/+7CRpNIGilyhHgh6SMTk1keLooGTv32LcXxkuO74w1GQy1DSK0n6HVIQuhJ9RZrAE KBwUnTXDLVHVwQvpjddOFNPf2wuSCjMqY4hIp52NtvS26V7Cqga89TkYlOpcYtWduAMTSDduo 94DzKxbxwBPch+qtYSn8dMWNXLjkle3/viPgbaNGqM3jptniHwqFGf3CSE2nO6Cx1jiuMlj5g 2zCZBXALk6ltPSvL7EZPG+GwLEMhZc1fQpezYZI6ySixTN1BCWeZNnmpb6FnNpbOuhyU+6WK7 93KIjjewagTN15UdV9aR/zxKR6OO48I6xqiNO3qG0BfqkG92hNGLW4UIrH35Dl+aNMJfetYmo IQLJBoPyRzXq5abaHI/scI2ncJ4curOJORPbrBIv8ly0aN9FMpz/KBYhyDcg/9XZMR1Un0N3R 6SRXxzFgPJhMYXw1A/WypCgaU5ksPUh6O6lcMnaGcxdn3Cn8cEU/yZ+JDumZE32J9kUWbaX/7 qW1BHCub+YJuVy+Pfp4p5oCg8y2ahEzfWc530bxsXTUyY2m7EoJaw88pCNAPqJ0AA70w83C6W 3LFiQZF6FweSpQPQ3a8o/j4DAgpJvOorXxj7d2SAYWfVVERHGjYsd/yBTCRtbGMZaw362s/zG MyerxW4Yyy3KjM5jpZJF/XFa/dybQlNKou/rv6b+sICD5MKc9ztnqWN+DfZYtzKsM8KAvvtGU m2J3UPCg832fhvIGgWUhkJjcI1TUz93ok2z62WqbPjdnZx0F6TxhOUrCYV4k4MiPA3ujz0ydH L/f5k1jjaxQNIZBiipYJ/DS7yLB+CVz1/eiGQhJ/m0g8k= X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 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" Used by userspace to adjust buffer priorities in response to changes in application demand and memory pressure. Signed-off-by: Friedrich Vock --- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 20 ++++++++++++++++++++ include/uapi/drm/amdgpu_drm.h | 1 + 2 files changed, 21 insertions(+) -- 2.44.0 diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c index 5ca13e2e50f50..6107810a9c205 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c @@ -836,8 +836,10 @@ int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data, { struct amdgpu_device *adev = drm_to_adev(dev); struct drm_amdgpu_gem_op *args = data; + struct ttm_resource_manager *man; struct drm_gem_object *gobj; struct amdgpu_vm_bo_base *base; + struct ttm_operation_ctx ctx; struct amdgpu_bo *robj; int r; @@ -851,6 +853,9 @@ int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data, if (unlikely(r)) goto out; + memset(&ctx, 0, sizeof(ctx)); + ctx.interruptible = true; + switch (args->op) { case AMDGPU_GEM_OP_GET_GEM_CREATE_INFO: { struct drm_amdgpu_gem_create_in info; @@ -898,6 +903,21 @@ int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data, amdgpu_bo_unreserve(robj); break; + case AMDGPU_GEM_OP_SET_PRIORITY: + if (args->value > AMDGPU_BO_PRIORITY_MAX_USER) + args->value = AMDGPU_BO_PRIORITY_MAX_USER; + ttm_bo_update_priority(&robj->tbo, args->value); + if (robj->tbo.evicted_type != TTM_NUM_MEM_TYPES) { + ttm_bo_try_unevict(&robj->tbo, &ctx); + amdgpu_bo_unreserve(robj); + } else { + amdgpu_bo_unreserve(robj); + man = ttm_manager_type(robj->tbo.bdev, + robj->tbo.resource->mem_type); + ttm_mem_unevict_evicted(robj->tbo.bdev, man, + true); + } + break; default: amdgpu_bo_unreserve(robj); r = -EINVAL; diff --git a/include/uapi/drm/amdgpu_drm.h b/include/uapi/drm/amdgpu_drm.h index bdbe6b262a78d..53552dd489b9b 100644 --- a/include/uapi/drm/amdgpu_drm.h +++ b/include/uapi/drm/amdgpu_drm.h @@ -531,6 +531,7 @@ union drm_amdgpu_wait_fences { #define AMDGPU_GEM_OP_GET_GEM_CREATE_INFO 0 #define AMDGPU_GEM_OP_SET_PLACEMENT 1 +#define AMDGPU_GEM_OP_SET_PRIORITY 2 /* Sets or returns a value associated with a buffer. */ struct drm_amdgpu_gem_op { From patchwork Wed Apr 24 16:57:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Friedrich Vock X-Patchwork-Id: 13642230 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5311CC19F4F for ; Wed, 24 Apr 2024 17:06:10 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id ECB91113CA7; Wed, 24 Apr 2024 17:06:08 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; secure) header.d=gmx.de header.i=friedrich.vock@gmx.de header.b="i3Zm2/hV"; dkim-atps=neutral Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by gabe.freedesktop.org (Postfix) with ESMTPS id 54D0C113CAD; Wed, 24 Apr 2024 17:06:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1713978365; x=1714583165; i=friedrich.vock@gmx.de; bh=H7VMHB2XIt5Ji+iMj0qWT7cVsj6+B4AwJL4OaG572YU=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-ID:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=i3Zm2/hV6LZBaEUm9NEqvFvwRhsh1a9Rc5pCtKV7wIQYUOrDaVnouckFonm+4m3y dtgAs72oSNMaEHlNA1ktA/Q0J6Gj7leGCKcxqSegh5sri3V2+1a1z6ZOn7b8hNwW2 ibHUriclGKzVDh/KqPArrfLB6TnldT+z5TLxQRgd+JdZaWONcutzBLoeHz6McyEy2 0mb61tbCpJwDCgFGnb8Q/CfntsdQ+Jtpjv14T4i6vxP5BU2G5FJIqSZPMtIh+zuFw ZQMJEQ21HBQ2wlKsFkRQJkCNU2PVIng5NjcCJVOr++S6DXXHR9FxPvP7bvCFGVVdA zy83ymX6+FDoen8X9g== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from arch.fritz.box ([213.152.117.111]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MrhQ6-1sVfCx46iK-00nLKX; Wed, 24 Apr 2024 19:00:44 +0200 From: Friedrich Vock To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org Cc: Pierre-Loup Griffais , Tvrtko Ursulin , Bas Nieuwenhuizen , Joshua Ashton , =?utf-8?q?Christian_K=C3=B6nig?= , Alex Deucher Subject: [RFC PATCH 17/18] drm/amdgpu: Implement EVICTED_VRAM query Date: Wed, 24 Apr 2024 18:57:07 +0200 Message-ID: <20240424165937.54759-18-friedrich.vock@gmx.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240424165937.54759-1-friedrich.vock@gmx.de> References: <20240424165937.54759-1-friedrich.vock@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:5Vv+AbzY2a6d8vtzoZ+0TUGOmyjxTopNk7iJ4VOIoTC6AReH5ye 4UrraQ0dfRdRaFpy4+95K76+fMzW5SurymFZrKBscBMvydio7jq48JxCXVyqE0UTsmav65h oZ4XzahI3J5jwgpLkbZZC4oXQDYkyb7Kgy/fi3/bgGhaOLtHsLMF22a2YByzwJfsm1TCLBU e1ZSrSmUHkMSyftiJwuOA== UI-OutboundReport: notjunk:1;M01:P0:nNtNWCuqJpI=;kQWZfBQx4mRjGJegqOGyZkGhh6B n+ci23YNLHk77N82aduDzRARQmJG+8xkbHXPb22ALkKetFDmYcEjOf+MpDrzlwu6dw38E7xwH VZOY5MkZloP+8yyDb9y2gV2TORnbT9gWKaLycgGn6efPtB+sP58XlXeZpncHRsPbIuo375yW/ D380TpWar3z0iHv7+PwzjifuaI4AZz2dKDmnAtIPVybVpBDtcPOiCn4rW18qh8sgLzGGn+z9b G6EG2u3WjyxiMCBqhs6Foa1+6GGJjiGx54rg9S2KwWC6C/fuUr4HoTnu8Q4VKAVsaRFOxCSjx HB7Npi/eJD9F24UHQ4uK0hNqLTQsiSCdhU6zlWz/ZsOaXdyJcoS6aKMZRz8YAix6Ze2zb//5X zg7/C3t+fSd8aDxtf2Q8Z7CAinY7tgH/dwniM/bjQ0s64iqdlx24OB73QSOcW8C3Xj5fE4JMm izMKyX5/IiIv6Z7iHHYnvQalNgnXdCIaAEKfMryBCR3UdEURWCHAGihKlYsEtAKFO8znq4EUX gNbHmiOjYzH95BUq1AMnjRjlLam/eyOQ8o7VrQlr/1z7sc3FgFJdT9e/9MReUHosdWvXQGu0+ c0eibzQfAxD0WMthyFqQyQPu5jWzbDrHuEM3yuan/QndVWg1KXBBoplhDwF+XmbId0U9OX9YU zRjbz/53RQe6JADSHO6EY8Q0tAMufs2wwgEdzUwgj3+qpzIdzF1qfi+oZ/s4j6j0oz3L7g75o KF3F98JeUiRVvuBOmTA6h+alEcjFm+Tijslv59pNp2zIn4XWwZNPgp7ZUDVgPf5OhtP/A5F2w QwaB74PzESh1bv7GDrvTAI6poNN9DcTDMj5vyrtiJ7j2Y= X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 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" Used by userspace to gauge the severity of memory overcommit and make prioritization decisions based on it. Used by userspace to gauge the severity of memory overcommit and make prioritization decisions based on it. Signed-off-by: Friedrich Vock --- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 3 +++ include/uapi/drm/amdgpu_drm.h | 2 ++ 2 files changed, 5 insertions(+) -- 2.44.0 diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c index 924baf58e3226..8cba30144bac6 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c @@ -1246,6 +1246,9 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) return copy_to_user(out, &gpuvm_fault, min((size_t)size, sizeof(gpuvm_fault))) ? -EFAULT : 0; } + case AMDGPU_INFO_EVICTED_VRAM: + ui64 = ttm_resource_manager_evicted_bytes(&adev->mman.vram_mgr.manager); + return copy_to_user(out, &ui64, min(size, 8u)) ? -EFAULT : 0; default: DRM_DEBUG_KMS("Invalid request %d\n", info->query); return -EINVAL; diff --git a/include/uapi/drm/amdgpu_drm.h b/include/uapi/drm/amdgpu_drm.h index 53552dd489b9b..5d04719386686 100644 --- a/include/uapi/drm/amdgpu_drm.h +++ b/include/uapi/drm/amdgpu_drm.h @@ -920,6 +920,8 @@ struct drm_amdgpu_cs_chunk_cp_gfx_shadow { #define AMDGPU_INFO_MAX_IBS 0x22 /* query last page fault info */ #define AMDGPU_INFO_GPUVM_FAULT 0x23 +/* query size of evicted vram allocations */ +#define AMDGPU_INFO_EVICTED_VRAM 0x24 #define AMDGPU_INFO_MMR_SE_INDEX_SHIFT 0 #define AMDGPU_INFO_MMR_SE_INDEX_MASK 0xff From patchwork Wed Apr 24 16:57:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Friedrich Vock X-Patchwork-Id: 13642215 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 12441C25B74 for ; Wed, 24 Apr 2024 17:01:23 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C8BA3113C8F; Wed, 24 Apr 2024 17:01:03 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; secure) header.d=gmx.de header.i=friedrich.vock@gmx.de header.b="P4SOMRlk"; dkim-atps=neutral Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by gabe.freedesktop.org (Postfix) with ESMTPS id E1AF0113CA1; Wed, 24 Apr 2024 17:00:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1713978044; x=1714582844; i=friedrich.vock@gmx.de; bh=gXJ9sHp9nKx/vHVFcYvw3sYKm1yHpVtdqTJUe8vT2Ww=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-ID:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=P4SOMRlk9dT/GPQ3j0ootm+K7YWMB3VCbUg50h/53y0Zg0lBNhC3zRA9+OKH/ZAc UdETeWb90b2wt14Srkatw9QbdWJVXZBr3QvBZ1W8h75KhFAOYlpRLisNdcHeXHnZp SUi4/qBRQd/T3zvUYKeJh/mQP2whjOequOoOo4hI98G5J7yWn+vUnDu4+LJJGrf0j 6m23P62JuAK+gjHKI1MINKrflYEkguTq7/tTVTHaKgRuuTW65jtd7yMUgcSifn21Z LrQ9jORj27IP0dhQ95wudDcIIhutcAqKC0d6jLdaeBUb/hQBezCK24oamc5g/N6n7 uwnziOt9UgP1yCVkqw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from arch.fritz.box ([213.152.117.111]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1M5QJD-1s0VSr20XN-000kui; Wed, 24 Apr 2024 19:00:44 +0200 From: Friedrich Vock To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org Cc: Pierre-Loup Griffais , Tvrtko Ursulin , Bas Nieuwenhuizen , Joshua Ashton , =?utf-8?q?Christian_K=C3=B6nig?= , Alex Deucher Subject: [RFC PATCH 18/18] drm/amdgpu: Bump minor version Date: Wed, 24 Apr 2024 18:57:08 +0200 Message-ID: <20240424165937.54759-19-friedrich.vock@gmx.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240424165937.54759-1-friedrich.vock@gmx.de> References: <20240424165937.54759-1-friedrich.vock@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:ONz5GuGooOxL9QByDhgduUp5y7f/hAvGjazdujSbC1JsDNogNtP RztkeEh6BaPdO19GyWrili4w46GmIoJSWovGuQGAq2rvj7xcwUPTPlgK8PopGK9hASnyF0X JvBad/kYc77LmIfVM6QDpB2z5qD7DOa0UJC6sMrpYVmz1cVjTeNNO27A4TjKD/aQZ5jE2Gu TUBCwpc1rE1b0VbEbTgJA== UI-OutboundReport: notjunk:1;M01:P0:0nG14xjtdaY=;EFMeFFXXHfet4uOZ1JL75koZKDM sC3lZTv7OgRtgIngM/547kgzH4U/8ln2AYhYz0Cwfwqr1IROMpArWAnfATnJ2Fl6eqnbaEf/Z Z8UonDE2wtN68deoal7ZtLNAyMk7UkKSb2tpX/2posDDOnI8kT5rnunK5yymIhyaymwGy3mpH t7N3v2IYPvnD/OjcCjFd9yz9LhCud1ik37DARagHm77mFlgllEM1K+Kkmr5EHdHDfx+CO/Q1v zvOgAE6xDZi5b7ysDPcHz/vUiZML8/mn0p9xI4m243wXwbyF9xC0+a2xKCOqcKdDLdXKvSada Yi+fTst0YU9kkbb+Zu0RrcngKO9wX448f6qlTZDE5uH5IUDx8pOxLPwpEeAc6kkMgLn5GYvpR 8cbdSjE8cmUFq6jO2HXsATRIPmN64IFlTVlS49OqpLhWH7Hmz5TrmGLJFYZZdvww4FirP3xAg q7FEL2ow8XdvOt6B0p/AhzFEKf7TiFo1b8/JJmJb0XHjAjKFiKJv+lJU0GH8Zyofb1aH7J7ZH tdZ68KwiFrS0jtjC/MZg+1h0n0IhAYuqbtzv/5G+pxJQ6MhqWvbwEGJHBhL27cDvOEMTcP76K Qd7rZzyPivSvPhq54sKuZvtPU/HhctfTV+2Fq9opFjZ9ysdN5hxrg8hG3zdp0Nm4l+k9iUHmB u0qw5smlBbp6bABHLmg+rCjsieAE4b8xScp35vX6yhlp3po4Sb0j7vhvt/znFfej/DAIWtgD9 y7INGT2pg/nBT2bJtNKsXiVT6Ylzvt9ylpxDJ/QsLYM7d54lPv+fbJHoorCbLxvJpxP8GEgGI lLZZ04uT8smHdJj6uxGgpLwR8+G1+WBP3mmQCEV2a1nXc= X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 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" Indicates support for EVICTED_VRAM queries and AMDGPU_GEM_OP_SET_PRIORITY Signed-off-by: Friedrich Vock --- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) -- 2.44.0 diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c index ea14f1c8f4304..4f8b62dbba17f 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c @@ -116,9 +116,10 @@ * - 3.55.0 - Add AMDGPU_INFO_GPUVM_FAULT query * - 3.56.0 - Update IB start address and size alignment for decode and encode * - 3.57.0 - Compute tunneling on GFX10+ + * - 3.58.0 - Per-BO priorities and evicted memory size queries */ #define KMS_DRIVER_MAJOR 3 -#define KMS_DRIVER_MINOR 57 +#define KMS_DRIVER_MINOR 58 #define KMS_DRIVER_PATCHLEVEL 0 /*