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

Configure Feed

Select the types of activity you want to include in your feed.

drm/sched: Add a simple timeout test

Add a very simple timeout test which submits a single job and verifies
that the timeout handling will run if the backend failed to complete the
job in time.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Cc: Christian König <christian.koenig@amd.com>
Cc: Danilo Krummrich <dakr@kernel.org>
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: Philipp Stanner <phasta@kernel.org>
Acked-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Philipp Stanner <phasta@kernel.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20250324092633.49746-4-tvrtko.ursulin@igalia.com

authored by

Tvrtko Ursulin and committed by
Philipp Stanner
53e65974 5a993507

+73 -6
+8 -3
drivers/gpu/drm/scheduler/tests/mock_scheduler.c
··· 203 203 static enum drm_gpu_sched_stat 204 204 mock_sched_timedout_job(struct drm_sched_job *sched_job) 205 205 { 206 - return DRM_GPU_SCHED_STAT_ENODEV; 206 + struct drm_mock_sched_job *job = drm_sched_job_to_mock_job(sched_job); 207 + 208 + job->flags |= DRM_MOCK_SCHED_JOB_TIMEDOUT; 209 + 210 + return DRM_GPU_SCHED_STAT_NOMINAL; 207 211 } 208 212 209 213 static void mock_sched_free_job(struct drm_sched_job *sched_job) ··· 238 234 * drm_mock_sched_new - Create a new mock scheduler 239 235 * 240 236 * @test: KUnit test owning the job 237 + * @timeout: Job timeout to set 241 238 * 242 239 * Returns: New mock scheduler with allocation managed by the test 243 240 */ 244 - struct drm_mock_scheduler *drm_mock_sched_new(struct kunit *test) 241 + struct drm_mock_scheduler *drm_mock_sched_new(struct kunit *test, long timeout) 245 242 { 246 243 struct drm_sched_init_args args = { 247 244 .ops = &drm_mock_scheduler_ops, 248 245 .num_rqs = DRM_SCHED_PRIORITY_COUNT, 249 246 .credit_limit = U32_MAX, 250 247 .hang_limit = 1, 251 - .timeout = MAX_SCHEDULE_TIMEOUT, 248 + .timeout = timeout, 252 249 .name = "drm-mock-scheduler", 253 250 }; 254 251 struct drm_mock_scheduler *sched;
+3 -1
drivers/gpu/drm/scheduler/tests/sched_tests.h
··· 97 97 struct completion done; 98 98 99 99 #define DRM_MOCK_SCHED_JOB_DONE 0x1 100 + #define DRM_MOCK_SCHED_JOB_TIMEDOUT 0x2 100 101 unsigned long flags; 101 102 102 103 struct list_head link; ··· 130 129 return container_of(sched_job, struct drm_mock_sched_job, base); 131 130 }; 132 131 133 - struct drm_mock_scheduler *drm_mock_sched_new(struct kunit *test); 132 + struct drm_mock_scheduler *drm_mock_sched_new(struct kunit *test, 133 + long timeout); 134 134 void drm_mock_sched_fini(struct drm_mock_scheduler *sched); 135 135 unsigned int drm_mock_sched_advance(struct drm_mock_scheduler *sched, 136 136 unsigned int num);
+62 -2
drivers/gpu/drm/scheduler/tests/tests_basic.c
··· 12 12 13 13 static int drm_sched_basic_init(struct kunit *test) 14 14 { 15 - test->priv = drm_mock_sched_new(test); 15 + test->priv = drm_mock_sched_new(test, MAX_SCHEDULE_TIMEOUT); 16 16 17 17 return 0; 18 18 } ··· 22 22 struct drm_mock_scheduler *sched = test->priv; 23 23 24 24 drm_mock_sched_fini(sched); 25 + } 26 + 27 + static int drm_sched_timeout_init(struct kunit *test) 28 + { 29 + test->priv = drm_mock_sched_new(test, HZ); 30 + 31 + return 0; 25 32 } 26 33 27 34 static void drm_sched_basic_submit(struct kunit *test) ··· 202 195 .test_cases = drm_sched_basic_tests, 203 196 }; 204 197 205 - kunit_test_suite(drm_sched_basic); 198 + static void drm_sched_basic_timeout(struct kunit *test) 199 + { 200 + struct drm_mock_scheduler *sched = test->priv; 201 + struct drm_mock_sched_entity *entity; 202 + struct drm_mock_sched_job *job; 203 + bool done; 204 + 205 + /* 206 + * Submit a single job against a scheduler with the timeout configured 207 + * and verify that the timeout handling will run if the backend fails 208 + * to complete it in time. 209 + */ 210 + 211 + entity = drm_mock_sched_entity_new(test, 212 + DRM_SCHED_PRIORITY_NORMAL, 213 + sched); 214 + job = drm_mock_sched_job_new(test, entity); 215 + 216 + drm_mock_sched_job_submit(job); 217 + 218 + done = drm_mock_sched_job_wait_scheduled(job, HZ); 219 + KUNIT_ASSERT_TRUE(test, done); 220 + 221 + done = drm_mock_sched_job_wait_finished(job, HZ / 2); 222 + KUNIT_ASSERT_FALSE(test, done); 223 + 224 + KUNIT_ASSERT_EQ(test, 225 + job->flags & DRM_MOCK_SCHED_JOB_TIMEDOUT, 226 + 0); 227 + 228 + done = drm_mock_sched_job_wait_finished(job, HZ); 229 + KUNIT_ASSERT_FALSE(test, done); 230 + 231 + KUNIT_ASSERT_EQ(test, 232 + job->flags & DRM_MOCK_SCHED_JOB_TIMEDOUT, 233 + DRM_MOCK_SCHED_JOB_TIMEDOUT); 234 + 235 + drm_mock_sched_entity_free(entity); 236 + } 237 + 238 + static struct kunit_case drm_sched_timeout_tests[] = { 239 + KUNIT_CASE(drm_sched_basic_timeout), 240 + {} 241 + }; 242 + 243 + static struct kunit_suite drm_sched_timeout = { 244 + .name = "drm_sched_basic_timeout_tests", 245 + .init = drm_sched_timeout_init, 246 + .exit = drm_sched_basic_exit, 247 + .test_cases = drm_sched_timeout_tests, 248 + }; 249 + 250 + kunit_test_suites(&drm_sched_basic, 251 + &drm_sched_timeout);