Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Wajdeczko <michal.wajdeczko@intel.com>
To: Jonathan Cavitt <jonathan.cavitt@intel.com>,
	<intel-xe@lists.freedesktop.org>
Cc: <saurabhg.gupta@intel.com>, <alex.zuo@intel.com>,
	<matthew.d.roper@intel.com>, <rodrigo.vivi@intel.com>,
	<tejas.upadhyay@intel.com>
Subject: Re: [PATCH v3 7/7] drm/xe/tests: Use any available GT for testing
Date: Tue, 14 Oct 2025 19:51:19 +0200	[thread overview]
Message-ID: <d8982e34-7f5f-4c82-b7f7-523007378a3c@intel.com> (raw)
In-Reply-To: <20251014164758.125598-16-jonathan.cavitt@intel.com>



On 10/14/2025 6:48 PM, Jonathan Cavitt wrote:
> The xe kunit test code expects GT0 to always be available as a part of
> the test setup.  However, these tests are generally able to run the tests
> using whatever GT is available, even if GT0 itself is unavailable.  Of
> course, if GT0 is unavailable, then the system itself is likely in a
> non-functional state, but this might change in the future.

in kunit we build our fake-Xe-device by ourselves so we *know* that GT0
is part of that xe, we were just using existing helper to get it, and
equally it could be:

	gt = xe_device_primary_gt(xe)

as suggested in 1/7 or direct access as:

	gt = xe->tile[0].primary_gt;

but the latter should avoided as the idea was to use as much as possible
of the original driver code

if your tool is still unhappy, instead of adding yet another helper like
xe_device_get_any_gt() maybe add some (redundant IMO) checks like:

	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, gt)

and maybe just one in xe_kunit_helper_xe_device_test_init() will be sufficient:

	xe = xe_kunit_helper_alloc_xe_device(test, dev);
	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xe);

	err = xe_pci_fake_device_init(xe);
	KUNIT_ASSERT_EQ(test, err, 0);

+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xe->tile[0].primary_gt); 
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xe_device_get_gt(xe, 0)); 


> 
> Add a helper function that returns the first available GT, asserting that
> at least one exists.  Then, use that helper to return the GT for use in
> the kunit tests.
> 
> Note that since the helper function is only used for the kunit tests,
> it's existence in xe_device.h is also predicated on the kunit tests
> being enabled.  Additionally, the helper function is logically identical
> to xe_device_lookup_gt(xe, 0) when that gt is available.
> 
> v2: Reword commit message (Michal)
> 
> v3: Add xe_device_get_any_gt helper function and use that instead
> (jcavitt)
> 
> Signed-off-by: Jonathan Cavitt <jonathan.cavitt@intel.com>
> Cc: Michal Wajdeczko <michal.wajdeczko@intel.com>
> ---
>  drivers/gpu/drm/xe/tests/xe_guc_buf_kunit.c   |  2 +-
>  drivers/gpu/drm/xe/tests/xe_guc_db_mgr_test.c |  2 +-
>  drivers/gpu/drm/xe/tests/xe_guc_g2g_test.c    |  2 +-
>  drivers/gpu/drm/xe/tests/xe_guc_id_mgr_test.c |  2 +-
>  drivers/gpu/drm/xe/tests/xe_guc_relay_test.c  |  8 +++----
>  drivers/gpu/drm/xe/xe_device.h                | 22 +++++++++++++++++++
>  6 files changed, 30 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/gpu/drm/xe/tests/xe_guc_buf_kunit.c b/drivers/gpu/drm/xe/tests/xe_guc_buf_kunit.c
> index 592dfce21add..656574e6cfb0 100644
> --- a/drivers/gpu/drm/xe/tests/xe_guc_buf_kunit.c
> +++ b/drivers/gpu/drm/xe/tests/xe_guc_buf_kunit.c
> @@ -63,7 +63,7 @@ static int guc_buf_test_init(struct kunit *test)
>  	xe_kunit_helper_xe_device_test_init(test);
>  
>  	ggtt = xe_device_get_root_tile(test->priv)->mem.ggtt;
> -	guc = &xe_device_lookup_gt(test->priv, 0)->uc.guc;
> +	guc = &xe_device_get_any_gt(test->priv)->uc.guc;
>  
>  	KUNIT_ASSERT_EQ(test, 0,
>  			xe_ggtt_init_kunit(ggtt, DUT_GGTT_START,
> diff --git a/drivers/gpu/drm/xe/tests/xe_guc_db_mgr_test.c b/drivers/gpu/drm/xe/tests/xe_guc_db_mgr_test.c
> index 5afdf7887098..e3330099e970 100644
> --- a/drivers/gpu/drm/xe/tests/xe_guc_db_mgr_test.c
> +++ b/drivers/gpu/drm/xe/tests/xe_guc_db_mgr_test.c
> @@ -13,7 +13,7 @@ static int guc_dbm_test_init(struct kunit *test)
>  	struct xe_guc_db_mgr *dbm;
>  
>  	xe_kunit_helper_xe_device_test_init(test);
> -	dbm = &xe_device_lookup_gt(test->priv, 0)->uc.guc.dbm;
> +	dbm = &xe_device_get_any_gt(test->priv)->uc.guc.dbm;
>  
>  	mutex_init(dbm_mutex(dbm));
>  	test->priv = dbm;
> diff --git a/drivers/gpu/drm/xe/tests/xe_guc_g2g_test.c b/drivers/gpu/drm/xe/tests/xe_guc_g2g_test.c
> index 3e77f501e27f..2a4429101c6d 100644
> --- a/drivers/gpu/drm/xe/tests/xe_guc_g2g_test.c
> +++ b/drivers/gpu/drm/xe/tests/xe_guc_g2g_test.c
> @@ -355,7 +355,7 @@ static void g2g_distribute(struct kunit *test, struct xe_device *xe, struct xe_b
>  	struct xe_gt *root_gt, *gt;
>  	int i;
>  
> -	root_gt = xe_device_lookup_gt(xe, 0);
> +	root_gt = xe_device_get_any_gt(xe);
>  	root_gt->uc.guc.g2g.bo = bo;
>  	root_gt->uc.guc.g2g.owned = true;
>  	kunit_info(test, "[%d.%d] Assigned 0x%p\n", gt_to_tile(root_gt)->id, root_gt->info.id, bo);
> 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 8b29db38d394..ee30a1939eb0 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
> @@ -13,7 +13,7 @@ static int guc_id_mgr_test_init(struct kunit *test)
>  	struct xe_guc_id_mgr *idm;
>  
>  	xe_kunit_helper_xe_device_test_init(test);
> -	idm = &xe_device_lookup_gt(test->priv, 0)->uc.guc.submission_state.idm;
> +	idm = &xe_device_get_any_gt(test->priv)->uc.guc.submission_state.idm;
>  
>  	mutex_init(idm_mutex(idm));
>  	test->priv = idm;
> diff --git a/drivers/gpu/drm/xe/tests/xe_guc_relay_test.c b/drivers/gpu/drm/xe/tests/xe_guc_relay_test.c
> index a891b1e0644e..8577a721cf42 100644
> --- a/drivers/gpu/drm/xe/tests/xe_guc_relay_test.c
> +++ b/drivers/gpu/drm/xe/tests/xe_guc_relay_test.c
> @@ -38,7 +38,7 @@ static int relay_test_init(struct kunit *test)
>  	xe = test->priv;
>  	KUNIT_ASSERT_EQ(test, xe_sriov_init(xe), 0);
>  
> -	relay = &xe_device_lookup_gt(xe, 0)->uc.guc.relay;
> +	relay = &xe_device_get_any_gt(xe)->uc.guc.relay;
>  	kunit_activate_static_stub(test, relay_get_totalvfs,
>  				   replacement_relay_get_totalvfs);
>  
> @@ -476,7 +476,7 @@ static struct kunit_suite vf_relay_suite = {
>  static void xe_drops_guc2pf_if_not_ready(struct kunit *test)
>  {
>  	struct xe_device *xe = test->priv;
> -	struct xe_guc_relay *relay = &xe_device_lookup_gt(xe, 0)->uc.guc.relay;
> +	struct xe_guc_relay *relay = &xe_device_get_any_gt(xe)->uc.guc.relay;
>  	const u32 *msg = test_guc2pf;
>  	u32 len = GUC2PF_RELAY_FROM_VF_EVENT_MSG_MIN_LEN + GUC_RELAY_MSG_MIN_LEN;
>  
> @@ -486,7 +486,7 @@ static void xe_drops_guc2pf_if_not_ready(struct kunit *test)
>  static void xe_drops_guc2vf_if_not_ready(struct kunit *test)
>  {
>  	struct xe_device *xe = test->priv;
> -	struct xe_guc_relay *relay = &xe_device_lookup_gt(xe, 0)->uc.guc.relay;
> +	struct xe_guc_relay *relay = &xe_device_get_any_gt(xe)->uc.guc.relay;
>  	const u32 *msg = test_guc2vf;
>  	u32 len = GUC2VF_RELAY_FROM_PF_EVENT_MSG_MIN_LEN + GUC_RELAY_MSG_MIN_LEN;
>  
> @@ -496,7 +496,7 @@ static void xe_drops_guc2vf_if_not_ready(struct kunit *test)
>  static void xe_rejects_send_if_not_ready(struct kunit *test)
>  {
>  	struct xe_device *xe = test->priv;
> -	struct xe_guc_relay *relay = &xe_device_lookup_gt(xe, 0)->uc.guc.relay;
> +	struct xe_guc_relay *relay = &xe_device_get_any_gt(xe)->uc.guc.relay;
>  	u32 msg[GUC_RELAY_MSG_MIN_LEN];
>  	u32 len = ARRAY_SIZE(msg);
>  
> diff --git a/drivers/gpu/drm/xe/xe_device.h b/drivers/gpu/drm/xe/xe_device.h
> index af9476879454..56fe0be86b37 100644
> --- a/drivers/gpu/drm/xe/xe_device.h
> +++ b/drivers/gpu/drm/xe/xe_device.h
> @@ -150,6 +150,28 @@ static inline bool xe_device_uc_enabled(struct xe_device *xe)
>  	for_each_gt((gt__), (tile__)->xe, (id__)) \
>  		for_each_if((gt__)->tile == (tile__))
>  
> +#if IS_ENABLED(CONFIG_DRM_XE_KUNIT_TEST)
> +/**
> + * xe_device_get_any_gt() - Returns any valid GT, asserting one exists
> + * @xe: The XE device to search
> + *
> + * Returns a pointer to the first available xe_gt struct.  If no such gt exists,
> + * then the system should not be functional at all, but just in case that changes,
> + * assert the returned GT is not NULL.
> + */
> +static inline struct xe_gt *xe_device_get_any_gt(struct xe_device *xe)
> +{
> +	struct xe_gt *gt = NULL;
> +	int i;
> +
> +	for_each_gt(gt, xe, i)
> +		break;
> +
> +	xe_assert(xe, gt);
> +	return gt;
> +}
> +#endif
> +
>  static inline struct xe_force_wake *gt_to_fw(struct xe_gt *gt)
>  {
>  	return &gt->pm.fw;


  reply	other threads:[~2025-10-14 17:51 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-14 16:47 [PATCH v3 0/7] drm/xe: Guard against NULL return for xe_device_get_gt Jonathan Cavitt
2025-10-14 16:48 ` [PATCH v3 1/7] drm/xe: s/xe_device_get_gt/xe_device_lookup_gt Jonathan Cavitt
2025-10-14 17:17   ` Michal Wajdeczko
2025-10-14 17:21     ` Cavitt, Jonathan
2025-10-14 16:48 ` [PATCH v3 2/7] drm/xe: Don't call xe_device_lookup_gt twice in xe_hw_engine_lookup Jonathan Cavitt
2025-10-14 16:48 ` [PATCH v3 3/7] drm/xe/xe_device: Reintroduce xe_device_get_gt Jonathan Cavitt
2025-10-14 17:28   ` Michal Wajdeczko
2025-10-14 16:48 ` [PATCH v3 4/7] drm/xe: Guard against NULL GT in xe_sriov_vf.c Jonathan Cavitt
2025-10-14 17:32   ` Michal Wajdeczko
2025-10-14 17:34     ` Cavitt, Jonathan
2025-10-14 16:48 ` [PATCH v3 5/7] drm/xe: Guard against NULL GT in xe_pmu.c Jonathan Cavitt
2025-10-14 16:48 ` [PATCH v3 6/7] drm/xe: Guard against NULL GT in xe_guc.c Jonathan Cavitt
2025-10-14 16:48 ` [PATCH v3 7/7] drm/xe/tests: Use any available GT for testing Jonathan Cavitt
2025-10-14 17:51   ` Michal Wajdeczko [this message]
2025-10-14 18:06     ` Cavitt, Jonathan
2025-10-14 16:55 ` ✓ CI.KUnit: success for drm/xe: Guard against NULL return for xe_device_get_gt Patchwork
2025-10-14 17:44 ` ✓ Xe.CI.BAT: " Patchwork
2025-10-15  2:37 ` ✗ Xe.CI.Full: failure " 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=d8982e34-7f5f-4c82-b7f7-523007378a3c@intel.com \
    --to=michal.wajdeczko@intel.com \
    --cc=alex.zuo@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=jonathan.cavitt@intel.com \
    --cc=matthew.d.roper@intel.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=saurabhg.gupta@intel.com \
    --cc=tejas.upadhyay@intel.com \
    /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