[PATCH v2 4/4] drm/xe/pf: Explicitly use shareable GuC IDs for VFs provisioning
Piórkowski, Piotr <[email protected]>
| Newsgroups | org.freedesktop.lists.intel-xe |
|---|---|
| Message-ID | <[email protected]> |
From: Piotr Piórkowski <[email protected]> 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. Signed-off-by: Piotr Piórkowski <[email protected]> Cc: Michal Wajdeczko <[email protected]> --- .../xe/tests/xe_gt_sriov_pf_config_kunit.c | 5 ++ drivers/gpu/drm/xe/tests/xe_guc_id_mgr_test.c | 36 ++++++---- drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c | 14 ++-- drivers/gpu/drm/xe/xe_guc_id_mgr.c | 71 ------------------- drivers/gpu/drm/xe/xe_guc_id_mgr.h | 1 - 5 files changed, 37 insertions(+), 90 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 e6eaa94d4d30..4d72411cd570 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/tests/xe_guc_id_mgr_test.c b/drivers/gpu/drm/xe/tests/xe_guc_id_mgr_test.c index f21d3341b503..3e6d289f7d7a 100644 --- a/drivers/gpu/drm/xe/tests/xe_guc_id_mgr_test.c +++ b/drivers/gpu/drm/xe/tests/xe_guc_id_mgr_test.c @@ -59,7 +59,7 @@ static void no_init(struct kunit *test) KUNIT_EXPECT_EQ(test, -ENODATA, xe_guc_id_mgr_reserve_usable_locked(idm, 0)); mutex_unlock(idm_mutex(idm)); - KUNIT_EXPECT_EQ(test, -ENODATA, xe_guc_id_mgr_reserve(idm, 1, 1)); + KUNIT_EXPECT_EQ(test, -ENODATA, xe_guc_id_mgr_reserve_shareable(idm, 1, 1)); } static void init_fini(struct kunit *test) @@ -127,6 +127,13 @@ static void check_init_shared(struct kunit *test) } #endif +static unsigned int idm_used_total(struct xe_guc_id_mgr *idm) +{ + lockdep_assert_held(idm_mutex(idm)); + + return bitmap_weight(idm->bitmap, idm_total(idm)); +} + static void check_used(struct kunit *test) { struct xe_guc_id_mgr *idm = test->priv; @@ -153,26 +160,31 @@ static void check_quota(struct kunit *test) { struct xe_guc_id_mgr *idm = test->priv; unsigned int n; + unsigned int max; - KUNIT_ASSERT_EQ(test, 0, idm_init(idm, 2, 0)); + KUNIT_ASSERT_EQ(test, 0, idm_init(idm, 2, 2)); + max = xe_guc_id_mgr_max_shareable(idm); mutex_lock(idm_mutex(idm)); - for (n = 0; n < idm_total(idm) - 1; n++) { + for (n = 0; n < max - 1; n++) { kunit_info(test, "n=%u", n); - KUNIT_EXPECT_EQ(test, idm_reserve_chunk_locked(idm, 1, idm_total(idm)), -EDQUOT); + KUNIT_EXPECT_GE(test, + xe_guc_id_mgr_reserve_shareable_locked(idm, 1, max), 0); + KUNIT_EXPECT_GE(test, + xe_guc_id_mgr_reserve_shareable_locked(idm, 1, max - n), 0); KUNIT_EXPECT_EQ(test, - idm_reserve_chunk_locked(idm, 1, idm_total(idm) - n), - -EDQUOT); + xe_guc_id_mgr_reserve_shareable_locked(idm, max - n, 1), + -ENOSPC); KUNIT_EXPECT_EQ(test, - idm_reserve_chunk_locked(idm, idm_total(idm) - n, 1), - -EDQUOT); - KUNIT_EXPECT_GE(test, idm_reserve_chunk_locked(idm, 1, 1), 0); + xe_guc_id_mgr_reserve_shareable_locked(idm, 1, 1), -ENOSPC); } - KUNIT_EXPECT_LE(test, 0, idm_reserve_chunk_locked(idm, 1, 0)); - KUNIT_EXPECT_EQ(test, idm_used_total(idm), idm_total(idm)); - idm_release_chunk_locked(idm, 0, idm_total(idm)); + KUNIT_EXPECT_EQ(test, + xe_guc_id_mgr_reserve_shareable_locked(idm, 1, 0), -ENOSPC); + KUNIT_EXPECT_EQ(test, idm_used_shareable(idm), max); + idm_release_chunk_locked(idm, idm_shareable_start(idm), max); KUNIT_EXPECT_EQ(test, idm_used_total(idm), 0); + mutex_unlock(idm_mutex(idm)); } 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 f4725af59fc5..01b8463693c7 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) { @@ -1173,9 +1173,11 @@ static u32 pf_profile_fair_ctxs(struct xe_gt *gt, unsigned int num_vfs) 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(xe_guc_id_mgr_max_shareable(>->uc.guc.submission_state.idm), + SZ_1K); - return rounddown_pow_of_two(GUC_ID_MAX / num_vfs); + return rounddown_pow_of_two(xe_guc_id_mgr_max_shareable(>->uc.guc.submission_state.idm) / + num_vfs); } static u32 pf_estimate_fair_ctxs(struct xe_gt *gt, unsigned int num_vfs) @@ -1186,7 +1188,7 @@ static u32 pf_estimate_fair_ctxs(struct xe_gt *gt, unsigned int num_vfs) int ret; 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 31425011a311..ddf4338f742b 100644 --- a/drivers/gpu/drm/xe/xe_guc_id_mgr.c +++ b/drivers/gpu/drm/xe/xe_guc_id_mgr.c @@ -62,13 +62,6 @@ static unsigned int idm_used_shareable(struct xe_guc_id_mgr *idm) bitmap_weight(idm->bitmap, idm_shareable_start(idm)); } -static unsigned int idm_used_total(struct xe_guc_id_mgr *idm) -{ - lockdep_assert_held(idm_mutex(idm)); - - return bitmap_weight(idm->bitmap, idm_total(idm)); -} - static void __fini_idm(struct drm_device *drm, void *arg) { struct xe_guc_id_mgr *idm = arg; @@ -345,43 +338,6 @@ static int idm_release_chunk_in_range_locked(struct xe_guc_id_mgr *idm, return 0; } -static int idm_reserve_chunk_locked(struct xe_guc_id_mgr *idm, unsigned int count, - unsigned int retain) -{ - int id; - - idm_assert(idm, count); - lockdep_assert_held(idm_mutex(idm)); - - if (!idm_total(idm)) - return -ENODATA; - - if (retain) { - /* - * For IDs reservations (used on PF for VFs) we want to make - * sure there will be at least 'retain' available for the PF - */ - if (idm_used_total(idm) + count + retain > idm_total(idm)) - return -EDQUOT; - /* - * ... and we want to reserve highest IDs close to the end. - */ - id = idm_find_last_zero_area_in_range(idm->bitmap, 0, idm_total(idm), count); - } else { - /* - * For regular IDs reservations (used by submission code) - * we start searching from the lower range of IDs. - */ - id = bitmap_find_next_zero_area(idm->bitmap, idm_total(idm), 0, count, 0); - } - if (id >= idm_total(idm)) - return -ENOSPC; - - bitmap_set(idm->bitmap, id, count); - - return id; -} - /** * xe_guc_id_mgr_reserve_usable_locked() - Reserve one or more GuC context IDs. * @idm: the &xe_guc_id_mgr @@ -499,33 +455,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); } -/** - * xe_guc_id_mgr_reserve() - Reserve a range of GuC context IDs. - * @idm: the &xe_guc_id_mgr - * @count: number of GuC context IDs to reserve (can't be 0) - * @retain: number of GuC context IDs to keep available (can't be 0) - * - * This function is dedicated for the use by the PF driver which expects that - * reserved range of IDs will be contiguous and that there will be at least - * &retain IDs still available for the PF after this reservation. - * - * Return: starting ID of the allocated GuC context ID range or - * a negative error code on failure. - */ -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); - - mutex_lock(idm_mutex(idm)); - ret = idm_reserve_chunk_locked(idm, count, retain); - mutex_unlock(idm_mutex(idm)); - - return ret; -} /** * xe_guc_id_mgr_release() - Release a range of GuC context IDs. diff --git a/drivers/gpu/drm/xe/xe_guc_id_mgr.h b/drivers/gpu/drm/xe/xe_guc_id_mgr.h index f7ab753070da..844d68440b0a 100644 --- a/drivers/gpu/drm/xe/xe_guc_id_mgr.h +++ b/drivers/gpu/drm/xe/xe_guc_id_mgr.h @@ -31,7 +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(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); -- 2.34.1