Re: [PATCH v2 4/5] drm/scheduler: Add basic priority tests

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 2025-02-21 at 12:09 +0000, Tvrtko Ursulin wrote:
> Add some basic tests for exercising entity priority handling.
> 
> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@xxxxxxxxxx>
> Cc: Christian König <christian.koenig@xxxxxxx>
> Cc: Danilo Krummrich <dakr@xxxxxxxxxx>
> Cc: Matthew Brost <matthew.brost@xxxxxxxxx>
> Cc: Philipp Stanner <phasta@xxxxxxxxxx>
> ---
>  drivers/gpu/drm/scheduler/tests/tests_basic.c | 99
> ++++++++++++++++++-
>  1 file changed, 98 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/scheduler/tests/tests_basic.c
> b/drivers/gpu/drm/scheduler/tests/tests_basic.c
> index 023143b80d78..f0e5ae1220c7 100644
> --- a/drivers/gpu/drm/scheduler/tests/tests_basic.c
> +++ b/drivers/gpu/drm/scheduler/tests/tests_basic.c
> @@ -1,5 +1,7 @@
>  // SPDX-License-Identifier: GPL-2.0
>  
> +#include <linux/delay.h>
> +
>  #include "sched_tests.h"
>  
>  /*
> @@ -253,5 +255,100 @@ static struct kunit_suite drm_sched_timeout = {
>  	.test_cases = drm_sched_timeout_tests,
>  };
>  
> +static void drm_sched_priorities(struct kunit *test)
> +{
> +	struct drm_mock_sched_entity
> *entity[DRM_SCHED_PRIORITY_COUNT];
> +	struct drm_mock_scheduler *sched = test->priv;
> +	struct drm_mock_sched_job *job;
> +	const unsigned int qd = 100;
> +	unsigned int i, cur_ent = 0;
> +	enum drm_sched_priority p;
> +	bool done;
> +
> +	/*
> +	 * Submit a bunch of jobs against entities configured with
> different
> +	 * priorities.
> +	 */

Same as in patch 2, better have it above the function, since it
describes the entire function's purpose.

> +
> +	BUILD_BUG_ON(DRM_SCHED_PRIORITY_KERNEL >
> DRM_SCHED_PRIORITY_LOW);
> +	BUILD_BUG_ON(ARRAY_SIZE(entity) !=
> DRM_SCHED_PRIORITY_COUNT);
> +
> +	for (p = DRM_SCHED_PRIORITY_KERNEL; p <=
> DRM_SCHED_PRIORITY_LOW; p++)
> +		entity[p] = drm_mock_new_sched_entity(test, p,
> sched);
> +
> +	for (i = 0; i < qd; i++) {
> +		job = drm_mock_new_sched_job(test,
> entity[cur_ent++]);
> +		cur_ent %= ARRAY_SIZE(entity);
> +		drm_mock_sched_job_set_duration_us(job, 1000);
> +		drm_mock_sched_job_submit(job);
> +	}
> +
> +	done = drm_mock_sched_job_wait_finished(job, HZ);
> +	KUNIT_ASSERT_EQ(test, done, true);
> +
> +	for (i = 0; i < ARRAY_SIZE(entity); i++)
> +		drm_mock_sched_entity_free(entity[i]);
> +}
> +
> +static void drm_sched_change_priority(struct kunit *test)
> +{
> +	struct drm_mock_sched_entity
> *entity[DRM_SCHED_PRIORITY_COUNT];
> +	struct drm_mock_scheduler *sched = test->priv;
> +	struct drm_mock_sched_job *job;
> +	const unsigned int qd = 1000;
> +	unsigned int i, cur_ent = 0;
> +	enum drm_sched_priority p;
> +	bool done;
> +
> +	/*
> +	 * Submit a bunch of jobs against entities configured with
> different
> +	 * priorities and while waiting for them to complete,
> periodically keep
> +	 * changing their priorities.
> +	 *
> +	 * We set up the queue-depth (qd) and job duration so the
> priority
> +	 * changing loop has some time to interact with submissions
> to the
> +	 * backend and job completions as they progress.
> +	 */

Same


P.

> +
> +	for (p = DRM_SCHED_PRIORITY_KERNEL; p <=
> DRM_SCHED_PRIORITY_LOW; p++)
> +		entity[p] = drm_mock_new_sched_entity(test, p,
> sched);
> +
> +	for (i = 0; i < qd; i++) {
> +		job = drm_mock_new_sched_job(test,
> entity[cur_ent++]);
> +		cur_ent %= ARRAY_SIZE(entity);
> +		drm_mock_sched_job_set_duration_us(job, 1000);
> +		drm_mock_sched_job_submit(job);
> +	}
> +
> +	do {
> +		drm_sched_entity_set_priority(&entity[cur_ent]-
> >base,
> +					      (entity[cur_ent]-
> >base.priority + 1) %
> +					     
> DRM_SCHED_PRIORITY_COUNT);
> +		cur_ent++;
> +		cur_ent %= ARRAY_SIZE(entity);
> +		usleep_range(200, 500);
> +	} while (!drm_mock_sched_job_is_finished(job));
> +
> +	done = drm_mock_sched_job_wait_finished(job, HZ);
> +	KUNIT_ASSERT_EQ(test, done, true);
> +
> +	for (i = 0; i < ARRAY_SIZE(entity); i++)
> +		drm_mock_sched_entity_free(entity[i]);
> +}
> +
> +static struct kunit_case drm_sched_priority_tests[] = {
> +	KUNIT_CASE(drm_sched_priorities),
> +	KUNIT_CASE(drm_sched_change_priority),
> +	{}
> +};
> +
> +static struct kunit_suite drm_sched_priority = {
> +	.name = "drm_sched_basic_priority_tests",
> +	.init = drm_sched_basic_init,
> +	.exit = drm_sched_basic_exit,
> +	.test_cases = drm_sched_priority_tests,
> +};
> +
>  kunit_test_suites(&drm_sched_basic,
> -		  &drm_sched_timeout);
> +		  &drm_sched_timeout,
> +		  &drm_sched_priority);





[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux