Skip to content

Commit e448372

Browse files
committed
drm/xe/pf: Use migration-friendly GGTT auto-provisioning
Instead of trying very hard to find the largest fair GGTT size that could be allocated for VFs on the current tile, pick some smaller rounded down to power-of-two value that is more likely to be provisioned in the same manner by the other PF instance: num VFs | GGTT space (MiB) --------+----------------- 63..57 | 56 56..29 | 64 28..15 | 128 14..8 | 256 7..4 | 512 3..2 | 1024 1 | 2048 (regular PF) 1 | 3584 (admin only PF) Note that due to FW/HW limitations we can't share all 4GiB GGTT address space with VFs, so for the larger (>7) number of the VFs the change in the outcome is happening at different points than we have in case of GuC contexts/doorbells IDs. Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com> Reviewed-by: Piotr Piórkowski <piotr.piorkowski@intel.com> Link: https://patch.msgid.link/20251112124408.8094-1-michal.wajdeczko@intel.com
1 parent aaecfad commit e448372

2 files changed

Lines changed: 69 additions & 0 deletions

File tree

drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_config_kunit.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,57 @@ static void fair_doorbells(struct kunit *test)
145145
KUNIT_ASSERT_EQ(test, SZ_128, pf_profile_fair_dbs(gt, num_vfs));
146146
}
147147

148+
static void fair_ggtt_1vf(struct kunit *test)
149+
{
150+
struct xe_gt *gt = test->priv;
151+
struct xe_device *xe = gt_to_xe(gt);
152+
153+
pf_set_admin_mode(xe, false);
154+
KUNIT_ASSERT_FALSE(test, xe_sriov_pf_admin_only(xe));
155+
KUNIT_EXPECT_EQ(test, SZ_2G, pf_profile_fair_ggtt(gt, 1));
156+
157+
pf_set_admin_mode(xe, true);
158+
KUNIT_ASSERT_TRUE(test, xe_sriov_pf_admin_only(xe));
159+
KUNIT_EXPECT_EQ(test, SZ_2G + SZ_1G + SZ_512M, pf_profile_fair_ggtt(gt, 1));
160+
}
161+
162+
static void fair_ggtt(struct kunit *test)
163+
{
164+
unsigned int num_vfs = (unsigned long)test->param_value;
165+
struct xe_gt *gt = test->priv;
166+
struct xe_device *xe = gt_to_xe(gt);
167+
u64 alignment = pf_get_ggtt_alignment(gt);
168+
u64 shareable = SZ_2G + SZ_1G + SZ_512M;
169+
170+
pf_set_admin_mode(xe, false);
171+
KUNIT_ASSERT_FALSE(test, xe_sriov_pf_admin_only(xe));
172+
173+
KUNIT_EXPECT_TRUE(test, IS_ALIGNED(pf_profile_fair_ggtt(gt, num_vfs), alignment));
174+
KUNIT_EXPECT_GE(test, shareable, num_vfs * pf_profile_fair_ggtt(gt, num_vfs));
175+
176+
if (num_vfs > 56)
177+
KUNIT_ASSERT_EQ(test, SZ_64M - SZ_8M, pf_profile_fair_ggtt(gt, num_vfs));
178+
else if (num_vfs > 28)
179+
KUNIT_ASSERT_EQ(test, SZ_64M, pf_profile_fair_ggtt(gt, num_vfs));
180+
else if (num_vfs > 14)
181+
KUNIT_ASSERT_EQ(test, SZ_128M, pf_profile_fair_ggtt(gt, num_vfs));
182+
else if (num_vfs > 7)
183+
KUNIT_ASSERT_EQ(test, SZ_256M, pf_profile_fair_ggtt(gt, num_vfs));
184+
else if (num_vfs > 3)
185+
KUNIT_ASSERT_EQ(test, SZ_512M, pf_profile_fair_ggtt(gt, num_vfs));
186+
else if (num_vfs > 1)
187+
KUNIT_ASSERT_EQ(test, SZ_1G, pf_profile_fair_ggtt(gt, num_vfs));
188+
else
189+
KUNIT_ASSERT_EQ(test, SZ_2G, pf_profile_fair_ggtt(gt, num_vfs));
190+
}
191+
148192
static struct kunit_case pf_gt_config_test_cases[] = {
149193
KUNIT_CASE(fair_contexts_1vf),
150194
KUNIT_CASE(fair_doorbells_1vf),
195+
KUNIT_CASE(fair_ggtt_1vf),
151196
KUNIT_CASE_PARAM(fair_contexts, num_vfs_gen_param),
152197
KUNIT_CASE_PARAM(fair_doorbells, num_vfs_gen_param),
198+
KUNIT_CASE_PARAM(fair_ggtt, num_vfs_gen_param),
153199
{}
154200
};
155201

drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "abi/guc_actions_sriov_abi.h"
1010
#include "abi/guc_klvs_abi.h"
1111

12+
#include "regs/xe_gtt_defs.h"
1213
#include "regs/xe_guc_regs.h"
1314

1415
#include "xe_bo.h"
@@ -697,6 +698,22 @@ static u64 pf_estimate_fair_ggtt(struct xe_gt *gt, unsigned int num_vfs)
697698
return fair;
698699
}
699700

701+
static u64 pf_profile_fair_ggtt(struct xe_gt *gt, unsigned int num_vfs)
702+
{
703+
bool admin_only_pf = xe_sriov_pf_admin_only(gt_to_xe(gt));
704+
u64 shareable = ALIGN_DOWN(GUC_GGTT_TOP, SZ_512M);
705+
u64 alignment = pf_get_ggtt_alignment(gt);
706+
707+
if (admin_only_pf && num_vfs == 1)
708+
return ALIGN_DOWN(shareable, alignment);
709+
710+
/* need to hardcode due to ~512M of GGTT being reserved */
711+
if (num_vfs > 56)
712+
return SZ_64M - SZ_8M;
713+
714+
return rounddown_pow_of_two(shareable / num_vfs);
715+
}
716+
700717
/**
701718
* xe_gt_sriov_pf_config_set_fair_ggtt - Provision many VFs with fair GGTT.
702719
* @gt: the &xe_gt (can't be media)
@@ -710,6 +727,7 @@ static u64 pf_estimate_fair_ggtt(struct xe_gt *gt, unsigned int num_vfs)
710727
int xe_gt_sriov_pf_config_set_fair_ggtt(struct xe_gt *gt, unsigned int vfid,
711728
unsigned int num_vfs)
712729
{
730+
u64 profile = pf_profile_fair_ggtt(gt, num_vfs);
713731
u64 fair;
714732

715733
xe_gt_assert(gt, vfid);
@@ -723,6 +741,11 @@ int xe_gt_sriov_pf_config_set_fair_ggtt(struct xe_gt *gt, unsigned int vfid,
723741
if (!fair)
724742
return -ENOSPC;
725743

744+
fair = min(fair, profile);
745+
if (fair < profile)
746+
xe_gt_sriov_info(gt, "Using non-profile provisioning (%s %llu vs %llu)\n",
747+
"GGTT", fair, profile);
748+
726749
return xe_gt_sriov_pf_config_bulk_set_ggtt(gt, vfid, num_vfs, fair);
727750
}
728751

0 commit comments

Comments
 (0)