Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Nareshkumar Gollakoti <naresh.kumar.g@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: himal.prasad.ghimiray@intel.com,
	Nareshkumar Gollakoti <naresh.kumar.g@intel.com>
Subject: [PATCH v2 5/8] drm/xe: apply debug page-size policy to user BO creation
Date: Wed,  1 Jul 2026 22:03:45 +0530	[thread overview]
Message-ID: <20260701163348.3432358-6-naresh.kumar.g@intel.com> (raw)
In-Reply-To: <20260701163348.3432358-1-naresh.kumar.g@intel.com>

Apply the debug page-size allocation policy in xe_bo_create_user().

In 2M-only and 1G-only modes, set the matching BO flag when the
requested size is aligned. In mixed mode, rotate across 4K, 64K, 2M,
and 1G, and set the selected flag only when the size is aligned for
it.

Otherwise, leave the flags unchanged and use the default allocation
behavior.

This makes user BO creation follow the same debug page-size policy as
other BO allocation paths.

v2
- make sure debug page-size allocation do not
  break default/usual path(sashiko)
- add atomic accesses to avoid race for concurrent access(sashiko)
- refactored commit messages for readability

Signed-off-by: Nareshkumar Gollakoti <naresh.kumar.g@intel.com>
---
 drivers/gpu/drm/xe/xe_bo.c | 56 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)

diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
index 45ff01df68e1..e1da9701c898 100644
--- a/drivers/gpu/drm/xe/xe_bo.c
+++ b/drivers/gpu/drm/xe/xe_bo.c
@@ -2612,6 +2612,60 @@ static struct xe_bo *xe_bo_create_novm(struct xe_device *xe, struct xe_tile *til
 	return ret ? ERR_PTR(ret) : bo;
 }
 
+static u32 get_flag_from_cur_index_in_mixed_mode(struct xe_device *xe, size_t size)
+{
+	static const u32 map[4] = {
+		0, //default mode 4K
+		XE_BO_FLAG_NEEDS_64K,
+		XE_BO_FLAG_NEEDS_2M,
+		XE_BO_FLAG_NEEDS_1G,
+	};
+	u32 idx;
+
+	idx = (atomic_inc_return(&xe->page_size_alloc_ctrl.cur_index) - 1) % 4;
+
+	if (!map[idx] && IS_ALIGNED(size, SZ_4K))
+		return 0;
+
+	if (map[idx] == XE_BO_FLAG_NEEDS_64K && IS_ALIGNED(size, SZ_64K))
+		return map[idx];
+
+	if (map[idx] == XE_BO_FLAG_NEEDS_2M && IS_ALIGNED(size, SZ_2M))
+		return map[idx];
+
+	if (map[idx] == XE_BO_FLAG_NEEDS_1G && IS_ALIGNED(size, SZ_1G))
+		return map[idx];
+
+	return 0;
+}
+
+static void xe_bo_apply_debug_page_size_policy(struct xe_device *xe,
+					       u32 *bo_flags,
+					       size_t size)
+{
+	int mode = READ_ONCE(xe->page_size_alloc_ctrl.mode);
+	u32 want = 0;
+
+	if (!xe_device_supports_multi_pagesize(xe))
+		return;
+
+	/* No action if default mode */
+	if (!mode)
+		return;
+
+	if (mode == XE_PAGE_SIZE_ALLOC_CTRL_MODE_ONLY_2M && IS_ALIGNED(size, SZ_2M))
+		want = XE_BO_FLAG_NEEDS_2M;
+	else if (mode == XE_PAGE_SIZE_ALLOC_CTRL_MODE_ONLY_1G &&
+		 IS_ALIGNED(size, SZ_1G))
+		want = XE_BO_FLAG_NEEDS_1G;
+	else if (mode == XE_PAGE_SIZE_ALLOC_CTRL_MODE_MIXED)
+		want = get_flag_from_cur_index_in_mixed_mode(xe, size);
+	else
+		return;
+
+	*bo_flags |= want;
+}
+
 /**
  * xe_bo_create_user() - Create a user BO
  * @xe: The xe device.
@@ -2635,6 +2689,8 @@ struct xe_bo *xe_bo_create_user(struct xe_device *xe,
 
 	flags |= XE_BO_FLAG_USER;
 
+	xe_bo_apply_debug_page_size_policy(xe, &flags, size);
+
 	if (vm || exec) {
 		xe_assert(xe, exec);
 		bo = __xe_bo_create_locked(xe, NULL, vm, size, 0, ~0ULL,
-- 
2.43.0


  parent reply	other threads:[~2026-07-01 16:33 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-01 16:33 [PATCH v2 0/8] drm/xe: add page size allocation mode control Nareshkumar Gollakoti
2026-07-01 16:33 ` [PATCH v2 1/8] drm/xe: add page size allocation control state to xe_device Nareshkumar Gollakoti
2026-07-01 16:33 ` [PATCH v2 2/8] drm/xe: add helper for multi page-size support Nareshkumar Gollakoti
2026-07-01 16:33 ` [PATCH v2 3/8] drm/xe/debugfs: add page size allocation mode knob Nareshkumar Gollakoti
2026-07-01 16:33 ` [PATCH v2 4/8] drm/xe: add 1G BO page-size alignment flag Nareshkumar Gollakoti
2026-07-01 16:33 ` Nareshkumar Gollakoti [this message]
2026-07-01 16:33 ` [PATCH v2 6/8] drm/xe/vm: apply debug page-size policy to VMA map flags Nareshkumar Gollakoti
2026-07-01 16:33 ` [PATCH v2 7/8] drm/xe/vm: validate large-page user BO bind alignment Nareshkumar Gollakoti
2026-07-01 16:33 ` [PATCH v2 8/8] drm/xe/pt: allow selecting the bind leaf PTE level Nareshkumar Gollakoti
2026-07-01 17:19 ` ✓ CI.KUnit: success for drm/xe: add page size allocation mode control Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260701163348.3432358-6-naresh.kumar.g@intel.com \
    --to=naresh.kumar.g@intel.com \
    --cc=himal.prasad.ghimiray@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox