Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/xe/tests: Add KUnit tests for PF fair provisioning

Add test cases to check outcome of fair GuC context or doorbells
IDs allocations for regular and admin-only PF mode.

Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
Reviewed-by: Piotr Piórkowski <piotr.piorkowski@intel.com>
Link: https://patch.msgid.link/20251106165932.2143-1-michal.wajdeczko@intel.com

+166
+162
drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_config_kunit.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 AND MIT 2 + /* 3 + * Copyright © 2025 Intel Corporation 4 + */ 5 + 6 + #include <kunit/static_stub.h> 7 + #include <kunit/test.h> 8 + #include <kunit/test-bug.h> 9 + 10 + #include "xe_kunit_helpers.h" 11 + #include "xe_pci_test.h" 12 + 13 + #define TEST_MAX_VFS 63 14 + 15 + static void pf_set_admin_mode(struct xe_device *xe, bool enable) 16 + { 17 + /* should match logic of xe_sriov_pf_admin_only() */ 18 + xe->info.probe_display = !enable; 19 + KUNIT_EXPECT_EQ(kunit_get_current_test(), enable, xe_sriov_pf_admin_only(xe)); 20 + } 21 + 22 + static const void *num_vfs_gen_param(struct kunit *test, const void *prev, char *desc) 23 + { 24 + unsigned long next = 1 + (unsigned long)prev; 25 + 26 + if (next > TEST_MAX_VFS) 27 + return NULL; 28 + snprintf(desc, KUNIT_PARAM_DESC_SIZE, "%lu VF%s", 29 + next, str_plural(next)); 30 + return (void *)next; 31 + } 32 + 33 + static int pf_gt_config_test_init(struct kunit *test) 34 + { 35 + struct xe_pci_fake_data fake = { 36 + .sriov_mode = XE_SRIOV_MODE_PF, 37 + .platform = XE_TIGERLAKE, /* any random platform with SR-IOV */ 38 + .subplatform = XE_SUBPLATFORM_NONE, 39 + }; 40 + struct xe_device *xe; 41 + struct xe_gt *gt; 42 + 43 + test->priv = &fake; 44 + xe_kunit_helper_xe_device_test_init(test); 45 + 46 + xe = test->priv; 47 + KUNIT_ASSERT_TRUE(test, IS_SRIOV_PF(xe)); 48 + 49 + gt = xe_root_mmio_gt(xe); 50 + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, gt); 51 + test->priv = gt; 52 + 53 + /* pretend it can support up to 63 VFs */ 54 + xe->sriov.pf.device_total_vfs = TEST_MAX_VFS; 55 + xe->sriov.pf.driver_max_vfs = TEST_MAX_VFS; 56 + KUNIT_ASSERT_EQ(test, xe_sriov_pf_get_totalvfs(xe), 63); 57 + 58 + pf_set_admin_mode(xe, false); 59 + KUNIT_ASSERT_EQ(test, xe_sriov_init(xe), 0); 60 + 61 + /* more sanity checks */ 62 + KUNIT_EXPECT_EQ(test, GUC_ID_MAX + 1, SZ_64K); 63 + KUNIT_EXPECT_EQ(test, GUC_NUM_DOORBELLS, SZ_256); 64 + 65 + return 0; 66 + } 67 + 68 + static void fair_contexts_1vf(struct kunit *test) 69 + { 70 + struct xe_gt *gt = test->priv; 71 + struct xe_device *xe = gt_to_xe(gt); 72 + 73 + pf_set_admin_mode(xe, false); 74 + KUNIT_ASSERT_FALSE(test, xe_sriov_pf_admin_only(xe)); 75 + KUNIT_EXPECT_EQ(test, SZ_32K, pf_profile_fair_ctxs(gt, 1)); 76 + 77 + pf_set_admin_mode(xe, true); 78 + KUNIT_ASSERT_TRUE(test, xe_sriov_pf_admin_only(xe)); 79 + KUNIT_EXPECT_EQ(test, SZ_64K - SZ_1K, pf_profile_fair_ctxs(gt, 1)); 80 + } 81 + 82 + static void fair_contexts(struct kunit *test) 83 + { 84 + unsigned int num_vfs = (unsigned long)test->param_value; 85 + struct xe_gt *gt = test->priv; 86 + struct xe_device *xe = gt_to_xe(gt); 87 + 88 + pf_set_admin_mode(xe, false); 89 + KUNIT_ASSERT_FALSE(test, xe_sriov_pf_admin_only(xe)); 90 + 91 + KUNIT_EXPECT_TRUE(test, is_power_of_2(pf_profile_fair_ctxs(gt, num_vfs))); 92 + KUNIT_EXPECT_GT(test, GUC_ID_MAX, num_vfs * pf_profile_fair_ctxs(gt, num_vfs)); 93 + 94 + if (num_vfs > 31) 95 + KUNIT_ASSERT_EQ(test, SZ_1K, pf_profile_fair_ctxs(gt, num_vfs)); 96 + else if (num_vfs > 15) 97 + KUNIT_ASSERT_EQ(test, SZ_2K, pf_profile_fair_ctxs(gt, num_vfs)); 98 + else if (num_vfs > 7) 99 + KUNIT_ASSERT_EQ(test, SZ_4K, pf_profile_fair_ctxs(gt, num_vfs)); 100 + else if (num_vfs > 3) 101 + KUNIT_ASSERT_EQ(test, SZ_8K, pf_profile_fair_ctxs(gt, num_vfs)); 102 + else if (num_vfs > 1) 103 + KUNIT_ASSERT_EQ(test, SZ_16K, pf_profile_fair_ctxs(gt, num_vfs)); 104 + else 105 + KUNIT_ASSERT_EQ(test, SZ_32K, pf_profile_fair_ctxs(gt, num_vfs)); 106 + } 107 + 108 + static void fair_doorbells_1vf(struct kunit *test) 109 + { 110 + struct xe_gt *gt = test->priv; 111 + struct xe_device *xe = gt_to_xe(gt); 112 + 113 + pf_set_admin_mode(xe, false); 114 + KUNIT_ASSERT_FALSE(test, xe_sriov_pf_admin_only(xe)); 115 + KUNIT_EXPECT_EQ(test, 128, pf_profile_fair_dbs(gt, 1)); 116 + 117 + pf_set_admin_mode(xe, true); 118 + KUNIT_ASSERT_TRUE(test, xe_sriov_pf_admin_only(xe)); 119 + KUNIT_EXPECT_EQ(test, 240, pf_profile_fair_dbs(gt, 1)); 120 + } 121 + 122 + static void fair_doorbells(struct kunit *test) 123 + { 124 + unsigned int num_vfs = (unsigned long)test->param_value; 125 + struct xe_gt *gt = test->priv; 126 + struct xe_device *xe = gt_to_xe(gt); 127 + 128 + pf_set_admin_mode(xe, false); 129 + KUNIT_ASSERT_FALSE(test, xe_sriov_pf_admin_only(xe)); 130 + 131 + KUNIT_EXPECT_TRUE(test, is_power_of_2(pf_profile_fair_dbs(gt, num_vfs))); 132 + KUNIT_EXPECT_GE(test, GUC_NUM_DOORBELLS, (num_vfs + 1) * pf_profile_fair_dbs(gt, num_vfs)); 133 + 134 + if (num_vfs > 31) 135 + KUNIT_ASSERT_EQ(test, SZ_4, pf_profile_fair_dbs(gt, num_vfs)); 136 + else if (num_vfs > 15) 137 + KUNIT_ASSERT_EQ(test, SZ_8, pf_profile_fair_dbs(gt, num_vfs)); 138 + else if (num_vfs > 7) 139 + KUNIT_ASSERT_EQ(test, SZ_16, pf_profile_fair_dbs(gt, num_vfs)); 140 + else if (num_vfs > 3) 141 + KUNIT_ASSERT_EQ(test, SZ_32, pf_profile_fair_dbs(gt, num_vfs)); 142 + else if (num_vfs > 1) 143 + KUNIT_ASSERT_EQ(test, SZ_64, pf_profile_fair_dbs(gt, num_vfs)); 144 + else 145 + KUNIT_ASSERT_EQ(test, SZ_128, pf_profile_fair_dbs(gt, num_vfs)); 146 + } 147 + 148 + static struct kunit_case pf_gt_config_test_cases[] = { 149 + KUNIT_CASE(fair_contexts_1vf), 150 + KUNIT_CASE(fair_doorbells_1vf), 151 + KUNIT_CASE_PARAM(fair_contexts, num_vfs_gen_param), 152 + KUNIT_CASE_PARAM(fair_doorbells, num_vfs_gen_param), 153 + {} 154 + }; 155 + 156 + static struct kunit_suite pf_gt_config_suite = { 157 + .name = "pf_gt_config", 158 + .test_cases = pf_gt_config_test_cases, 159 + .init = pf_gt_config_test_init, 160 + }; 161 + 162 + kunit_test_suite(pf_gt_config_suite);
+4
drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c
··· 2826 2826 2827 2827 return 0; 2828 2828 } 2829 + 2830 + #if IS_BUILTIN(CONFIG_DRM_XE_KUNIT_TEST) 2831 + #include "tests/xe_gt_sriov_pf_config_kunit.c" 2832 + #endif