From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 96A02606A31A for ; Tue, 20 Oct 2026 19:09:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=M+Xdk5Cc Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 54FE410E215; Tue, 20 Oct 2026 19:08:57 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.21]) by gabe.freedesktop.org (Postfix) with ESMTPS id D200310E215 for ; Tue, 20 Oct 2026 19:08:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1792523331; x=1824059331; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=Q+a0KRkWbPKPPXbj5S0Roto3SXW+vy8mMj3iYqdK9kM=; b=M+Xdk5CcWSahbybCjX8SVPvEneEWJ40fegbkjC38bopjJyQ1IhUdeLiD XLI/DCCMgznZvj4EuC1oDFO9H1t0t6Hnm+rs06r0Sxfntj20Wr+MJDnZK XgHyzo1lBN/79CZxcNnh1A4t4/DDBZV92HYpbhPu5yLDqfgYmA4Dpx8a+ 0r45J8JywkrCbNM7wCnPqzjjgQYAfTEHEOu63gAAMB1oapxB7vVMrplRf 69nJsuZH7p13RNk5cYrdLWd8hdPCymfmyU3Q0KU7WgI76WCq0s9KYZeiP AfD3NgPxJci6K/bPHPYOjBsvW2HHJruB1wSNpUVOM8cxSN9iwki5dzm2q A==; X-CSE-ConnectionGUID: z9R2jKIzRUWndBSh7jWEKA== X-CSE-MsgGUID: JQdn0ApWT2OoCGJoQbWAew== X-IronPort-AV: E=McAfee;i="6800,10657,11941"; a="1339818" X-IronPort-AV: E=Sophos;i="6.27,168,1787036400"; d="scan'208";a="1339818" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa113.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2026 12:08:45 -0700 X-CSE-ConnectionGUID: KwHKpE+2Q/WLDvRSAYCggQ== X-CSE-MsgGUID: 427KKvV/Q+KtHgFcK7bv9A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,168,1787036400"; d="scan'208";a="3226593" Received: from gsse-cloud1.jf.intel.com ([10.54.39.91]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2026 12:08:45 -0700 From: Matthew Brost To: intel-xe@lists.freedesktop.org Subject: [PATCH v3 2/3] drm/ttm: Allow skipping to the next priority in the bo LRU cursor Date: Tue, 20 Oct 2026 12:08:39 -0700 Message-Id: <20261020190840.854525-3-matthew.brost@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261020190840.854525-1-matthew.brost@intel.com> References: <20261020190840.854525-1-matthew.brost@intel.com> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Intel-xe" X-Spam-Status: No, score=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Drivers walking a manager's LRU with ttm_bo_lru_for_each_reserved_guarded() may decide that the rest of the current priority isn't worth walking, for example when the priority is roughly age ordered and the walk hit a BO that is still too hot to evict. Today the only option is to stop the walk altogether, which also gives up on the remaining priorities. Add ttm_resource_manager_next_priority() to move a resource cursor to the start of the next priority, and ttm_bo_lru_cursor_skip_priority() to make the next ttm_bo_lru_cursor_next() use it. While at it, stop incrementing the cursor priority past the last valid priority once the iteration is done. Assisted-by: LLM Signed-off-by: Matthew Brost --- drivers/gpu/drm/ttm/ttm_bo_util.c | 3 +++ drivers/gpu/drm/ttm/ttm_resource.c | 35 ++++++++++++++++++++++++++---- include/drm/ttm/ttm_bo.h | 19 ++++++++++++++++ include/drm/ttm/ttm_resource.h | 2 ++ 4 files changed, 55 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c index f9458a4d5a09..d626f014e61f 100644 --- a/drivers/gpu/drm/ttm/ttm_bo_util.c +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c @@ -997,6 +997,9 @@ __ttm_bo_lru_cursor_next(struct ttm_bo_lru_cursor *curs) if (first) { res = ttm_resource_manager_first(&curs->res_curs); first = false; + } else if (curs->skip_priority) { + res = ttm_resource_manager_next_priority(&curs->res_curs); + curs->skip_priority = false; } else { res = ttm_resource_manager_next(&curs->res_curs); } diff --git a/drivers/gpu/drm/ttm/ttm_resource.c b/drivers/gpu/drm/ttm/ttm_resource.c index 4e6d3d658d85..e631507d7aa1 100644 --- a/drivers/gpu/drm/ttm/ttm_resource.c +++ b/drivers/gpu/drm/ttm/ttm_resource.c @@ -674,6 +674,17 @@ ttm_resource_cursor_check_bulk(struct ttm_resource_cursor *cursor, } } +static bool ttm_resource_cursor_next_priority(struct ttm_resource_cursor *cursor) +{ + if (cursor->priority + 1 >= TTM_MAX_BO_PRIORITY) + return false; + + list_move(&cursor->hitch.link, &cursor->man->lru[++cursor->priority]); + ttm_resource_cursor_clear_bulk(cursor); + + return true; +} + /** * ttm_resource_manager_first() - Start iterating over the resources * of a resource manager @@ -723,16 +734,32 @@ ttm_resource_manager_next(struct ttm_resource_cursor *cursor) } } - if (++cursor->priority >= TTM_MAX_BO_PRIORITY) + if (!ttm_resource_cursor_next_priority(cursor)) break; - - list_move(&cursor->hitch.link, &man->lru[cursor->priority]); - ttm_resource_cursor_clear_bulk(cursor); } return NULL; } +/** + * ttm_resource_manager_next_priority() - Skip the rest of the current + * priority and continue iterating at the next one + * @cursor: cursor to record the position + * + * Return: the first resource of the next non-empty priority, or NULL if + * there is none. + */ +struct ttm_resource * +ttm_resource_manager_next_priority(struct ttm_resource_cursor *cursor) +{ + lockdep_assert_held(&cursor->man->bdev->lru_lock); + + if (!ttm_resource_cursor_next_priority(cursor)) + return NULL; + + return ttm_resource_manager_next(cursor); +} + /** * ttm_lru_first_res_or_null() - Return the first resource on an lru list * @head: The list head of the lru list. diff --git a/include/drm/ttm/ttm_bo.h b/include/drm/ttm/ttm_bo.h index 32791c4db2a9..2fc517dbf03d 100644 --- a/include/drm/ttm/ttm_bo.h +++ b/include/drm/ttm/ttm_bo.h @@ -507,10 +507,29 @@ struct ttm_bo_lru_cursor { * unlock before the next iteration or after loop exit. */ bool needs_unlock; + /** + * @skip_priority: Continue at the next LRU priority on the next + * iteration. See ttm_bo_lru_cursor_skip_priority(). + */ + bool skip_priority; /** @arg: Pointer to common BO LRU walk arguments. */ struct ttm_lru_walk_arg *arg; }; +/** + * ttm_bo_lru_cursor_skip_priority() - Skip the rest of the current priority + * @curs: The cursor. + * + * Make the next ttm_bo_lru_cursor_next() skip the remaining buffer objects + * of the current LRU priority and continue at the next priority, for + * example when the caller decides the rest of the priority isn't worth + * walking. + */ +static inline void ttm_bo_lru_cursor_skip_priority(struct ttm_bo_lru_cursor *curs) +{ + curs->skip_priority = true; +} + void ttm_bo_lru_cursor_fini(struct ttm_bo_lru_cursor *curs); struct ttm_bo_lru_cursor * diff --git a/include/drm/ttm/ttm_resource.h b/include/drm/ttm/ttm_resource.h index 714c533622c2..8cd70d1e5481 100644 --- a/include/drm/ttm/ttm_resource.h +++ b/include/drm/ttm/ttm_resource.h @@ -499,6 +499,8 @@ struct ttm_resource * ttm_resource_manager_first(struct ttm_resource_cursor *cursor); struct ttm_resource * ttm_resource_manager_next(struct ttm_resource_cursor *cursor); +struct ttm_resource * +ttm_resource_manager_next_priority(struct ttm_resource_cursor *cursor); struct ttm_resource * ttm_lru_first_res_or_null(struct list_head *head); -- 2.34.1