From: Piotr Piórkowski <piotr.piorkowski@intel.com>
Switch PF VF-context provisioning to explicitly allocate IDs from
the dedicated shareable ID pool.
Also, lets remove the legacy GuC ID reservation API now that all VFs
provisioning paths use the shareable allocation helpers.
v2: Use local variable for max shareable GuC IDs in fair profile (Satya)
Assisted-by: Claude:claude-5-sonnet
Signed-off-by: Piotr Piórkowski <piotr.piorkowski@intel.com>
Cc: Michal Wajdeczko <michal.wajdeczko@intel.com>
---
.../xe/tests/xe_gt_sriov_pf_config_kunit.c | 5 ++
drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c | 21 ++++---
drivers/gpu/drm/xe/xe_guc_id_mgr.c | 56 ++-----------------
drivers/gpu/drm/xe/xe_guc_id_mgr.h | 2 -
4 files changed, 24 insertions(+), 60 deletions(-)
diff --git a/drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_config_kunit.c b/drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_config_kunit.c
index e6eaa94d4d30f..4d72411cd570c 100644
--- a/drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_config_kunit.c
+++ b/drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_config_kunit.c
@@ -68,6 +68,7 @@ static int pf_gt_config_test_init(struct kunit *test)
.graphics_verx100 = 2001,
};
struct xe_vram_region *vram;
+ struct xe_guc_id_mgr *idm;
struct xe_device *xe;
struct xe_gt *gt;
@@ -102,6 +103,10 @@ static int pf_gt_config_test_init(struct kunit *test)
pf_set_admin_mode(xe, false);
KUNIT_ASSERT_EQ(test, xe_sriov_init(xe), 0);
+ idm = >->uc.guc.submission_state.idm;
+ mutex_init(>->uc.guc.submission_state.lock);
+ KUNIT_ASSERT_EQ(test, xe_guc_id_mgr_init_shared(idm), 0);
+
/* more sanity checks */
KUNIT_EXPECT_EQ(test, GUC_ID_MAX + 1, SZ_64K);
KUNIT_EXPECT_EQ(test, GUC_NUM_DOORBELLS, SZ_256);
diff --git a/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c b/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c
index de1ac58e31412..0a47458e5bf20 100644
--- a/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c
+++ b/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c
@@ -889,7 +889,7 @@ static int pf_set_spare_ctxs(struct xe_gt *gt, u32 spare)
xe_gt_assert(gt, IS_SRIOV_PF(gt_to_xe(gt)));
lockdep_assert_held(xe_gt_sriov_pf_master_mutex(gt));
- if (spare > GUC_ID_MAX)
+ if (spare > xe_guc_id_mgr_max_shareable(>->uc.guc.submission_state.idm))
return -EINVAL;
if (spare && spare < pf_get_min_spare_ctxs(gt))
@@ -906,7 +906,7 @@ static int pf_reserve_ctxs(struct xe_gt *gt, u32 num)
struct xe_guc_id_mgr *idm = >->uc.guc.submission_state.idm;
unsigned int spare = pf_get_spare_ctxs(gt);
- return xe_guc_id_mgr_reserve(idm, num, spare);
+ return xe_guc_id_mgr_reserve_shareable(idm, num, spare);
}
static void pf_release_ctxs(struct xe_gt *gt, u32 start, u32 num)
@@ -933,7 +933,7 @@ static int pf_provision_vf_ctxs(struct xe_gt *gt, unsigned int vfid, u32 num_ctx
xe_gt_assert(gt, vfid);
- if (num_ctxs > GUC_ID_MAX)
+ if (num_ctxs > xe_guc_id_mgr_max_shareable(>->uc.guc.submission_state.idm))
return -EINVAL;
if (config->num_ctxs) {
@@ -1170,23 +1170,30 @@ int xe_gt_sriov_pf_config_bulk_set_ctxs(struct xe_gt *gt, unsigned int vfid,
static u32 pf_profile_fair_ctxs(struct xe_gt *gt, unsigned int num_vfs)
{
+ u32 max_shareable = xe_guc_id_mgr_max_shareable(>->uc.guc.submission_state.idm);
bool admin_only_pf = xe_sriov_pf_admin_only(gt_to_xe(gt));
if (admin_only_pf && num_vfs == 1)
- return ALIGN_DOWN(GUC_ID_MAX, SZ_1K);
+ return ALIGN_DOWN(max_shareable, SZ_1K);
- return rounddown_pow_of_two(GUC_ID_MAX / num_vfs);
+ return rounddown_pow_of_two(max_shareable / num_vfs);
}
static u32 pf_estimate_fair_ctxs(struct xe_gt *gt, unsigned int num_vfs)
{
struct xe_guc_id_mgr *idm = >->uc.guc.submission_state.idm;
+ u32 max_shareable = xe_guc_id_mgr_max_shareable(idm);
u32 spare = pf_get_spare_ctxs(gt);
- u32 fair = (xe_guc_id_mgr_max_usable(idm) - spare) / num_vfs;
+ u32 fair;
int ret;
+ if (max_shareable <= spare)
+ return 0;
+
+ fair = (max_shareable - spare) / num_vfs;
+
for (; fair; --fair) {
- ret = xe_guc_id_mgr_reserve(idm, fair * num_vfs, spare);
+ ret = xe_guc_id_mgr_reserve_shareable(idm, fair * num_vfs, spare);
if (ret < 0)
continue;
xe_guc_id_mgr_release(idm, ret, fair * num_vfs);
diff --git a/drivers/gpu/drm/xe/xe_guc_id_mgr.c b/drivers/gpu/drm/xe/xe_guc_id_mgr.c
index dc918221b78de..6cd73009177af 100644
--- a/drivers/gpu/drm/xe/xe_guc_id_mgr.c
+++ b/drivers/gpu/drm/xe/xe_guc_id_mgr.c
@@ -120,9 +120,13 @@ static int idm_init(struct xe_guc_id_mgr *idm, unsigned int usable, unsigned int
}
/**
- * xe_guc_id_mgr_init() - Initialize GuC context ID manager in native mode.
+ * xe_guc_id_mgr_init() - Initialize GuC ID manager for native.
* @idm: the &xe_guc_id_mgr to initialize
*
+ * This function initializes the GuC ID manager to manage the full range of
+ * GuC context IDs (0..GUC_ID_MAX - 1) for use by the GuC submission code.
+ * No GuC context IDs will be reserved for sharing with VFs.
+ *
* Can only be called when the device is not in SR-IOV mode.
*
* Return: 0 on success or a negative error code on failure.
@@ -283,37 +287,6 @@ static int idm_reserve_chunk_shareable_locked(struct xe_guc_id_mgr *idm, unsigne
return id;
}
-static int idm_reserve_chunk_locked(struct xe_guc_id_mgr *idm, unsigned int count,
- unsigned int retain)
-{
- unsigned int total = idm_total(idm);
- int id;
-
- idm_assert(idm, count);
- lockdep_assert_held(idm_mutex(idm));
-
- if (!total)
- return -ENODATA;
-
- if (retain) {
- unsigned int used = bitmap_weight(idm->bitmap, total);
-
- if (used + count + retain > total)
- return -EDQUOT;
-
- id = idm_find_last_zero_area_in_range(idm->bitmap, 0, total, count);
- } else {
- id = bitmap_find_next_zero_area(idm->bitmap, total, 0, count, 0);
- }
-
- if (id >= total)
- return -ENOSPC;
-
- bitmap_set(idm->bitmap, id, count);
-
- return id;
-}
-
static void idm_release_chunk_locked(struct xe_guc_id_mgr *idm,
unsigned int start, unsigned int count)
{
@@ -471,25 +444,6 @@ int xe_guc_id_mgr_reserve_shareable(struct xe_guc_id_mgr *idm, unsigned int coun
return idm_reserve_chunk_shareable_locked(idm, count, spare);
}
-int xe_guc_id_mgr_reserve_locked(struct xe_guc_id_mgr *idm, unsigned int count)
-{
- return idm_reserve_chunk_locked(idm, count, 0);
-}
-
-int xe_guc_id_mgr_reserve(struct xe_guc_id_mgr *idm, unsigned int count,
- unsigned int retain)
-{
- int ret;
-
- idm_assert(idm, count);
- idm_assert(idm, retain);
-
- guard(mutex)(idm_mutex(idm));
- ret = idm_reserve_chunk_locked(idm, count, retain);
-
- return ret;
-}
-
/**
* xe_guc_id_mgr_release() - Release one or more GuC context IDs.
* @idm: the &xe_guc_id_mgr
diff --git a/drivers/gpu/drm/xe/xe_guc_id_mgr.h b/drivers/gpu/drm/xe/xe_guc_id_mgr.h
index ed9970829a939..844d68440b0af 100644
--- a/drivers/gpu/drm/xe/xe_guc_id_mgr.h
+++ b/drivers/gpu/drm/xe/xe_guc_id_mgr.h
@@ -31,8 +31,6 @@ int xe_guc_id_mgr_reserve_shareable_locked(struct xe_guc_id_mgr *idm, unsigned i
unsigned int spare);
int xe_guc_id_mgr_reserve_shareable(struct xe_guc_id_mgr *idm, unsigned int count,
unsigned int spare);
-int xe_guc_id_mgr_reserve_locked(struct xe_guc_id_mgr *idm, unsigned int count);
-int xe_guc_id_mgr_reserve(struct xe_guc_id_mgr *idm, unsigned int count, unsigned int retain);
void xe_guc_id_mgr_release_locked(struct xe_guc_id_mgr *idm, unsigned int id, unsigned int count);
int xe_guc_id_mgr_release_usable_locked(struct xe_guc_id_mgr *idm, unsigned int id,
unsigned int count);
LGTM.
Reviewed-by: Satyanarayana K V P <satyanarayana.k.v.p@intel.com>