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 basic priority tests

Add some basic tests for exercising entity priority handling.

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-5-tvrtko.ursulin@igalia.com

authored by

Tvrtko Ursulin and committed by
Philipp Stanner
7b765cda 53e65974

+94 -1
+94 -1
drivers/gpu/drm/scheduler/tests/tests_basic.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* Copyright (c) 2025 Valve Corporation */ 3 3 4 + #include <linux/delay.h> 5 + 4 6 #include "sched_tests.h" 5 7 6 8 /* ··· 256 254 .test_cases = drm_sched_timeout_tests, 257 255 }; 258 256 257 + static void drm_sched_priorities(struct kunit *test) 258 + { 259 + struct drm_mock_sched_entity *entity[DRM_SCHED_PRIORITY_COUNT]; 260 + struct drm_mock_scheduler *sched = test->priv; 261 + struct drm_mock_sched_job *job; 262 + const unsigned int qd = 100; 263 + unsigned int i, cur_ent = 0; 264 + enum drm_sched_priority p; 265 + bool done; 266 + 267 + /* 268 + * Submit a bunch of jobs against entities configured with different 269 + * priorities. 270 + */ 271 + 272 + BUILD_BUG_ON(DRM_SCHED_PRIORITY_KERNEL > DRM_SCHED_PRIORITY_LOW); 273 + BUILD_BUG_ON(ARRAY_SIZE(entity) != DRM_SCHED_PRIORITY_COUNT); 274 + 275 + for (p = DRM_SCHED_PRIORITY_KERNEL; p <= DRM_SCHED_PRIORITY_LOW; p++) 276 + entity[p] = drm_mock_sched_entity_new(test, p, sched); 277 + 278 + for (i = 0; i < qd; i++) { 279 + job = drm_mock_sched_job_new(test, entity[cur_ent++]); 280 + cur_ent %= ARRAY_SIZE(entity); 281 + drm_mock_sched_job_set_duration_us(job, 1000); 282 + drm_mock_sched_job_submit(job); 283 + } 284 + 285 + done = drm_mock_sched_job_wait_finished(job, HZ); 286 + KUNIT_ASSERT_TRUE(test, done); 287 + 288 + for (i = 0; i < ARRAY_SIZE(entity); i++) 289 + drm_mock_sched_entity_free(entity[i]); 290 + } 291 + 292 + static void drm_sched_change_priority(struct kunit *test) 293 + { 294 + struct drm_mock_sched_entity *entity[DRM_SCHED_PRIORITY_COUNT]; 295 + struct drm_mock_scheduler *sched = test->priv; 296 + struct drm_mock_sched_job *job; 297 + const unsigned int qd = 1000; 298 + unsigned int i, cur_ent = 0; 299 + enum drm_sched_priority p; 300 + 301 + /* 302 + * Submit a bunch of jobs against entities configured with different 303 + * priorities and while waiting for them to complete, periodically keep 304 + * changing their priorities. 305 + * 306 + * We set up the queue-depth (qd) and job duration so the priority 307 + * changing loop has some time to interact with submissions to the 308 + * backend and job completions as they progress. 309 + */ 310 + 311 + for (p = DRM_SCHED_PRIORITY_KERNEL; p <= DRM_SCHED_PRIORITY_LOW; p++) 312 + entity[p] = drm_mock_sched_entity_new(test, p, sched); 313 + 314 + for (i = 0; i < qd; i++) { 315 + job = drm_mock_sched_job_new(test, entity[cur_ent++]); 316 + cur_ent %= ARRAY_SIZE(entity); 317 + drm_mock_sched_job_set_duration_us(job, 1000); 318 + drm_mock_sched_job_submit(job); 319 + } 320 + 321 + do { 322 + drm_sched_entity_set_priority(&entity[cur_ent]->base, 323 + (entity[cur_ent]->base.priority + 1) % 324 + DRM_SCHED_PRIORITY_COUNT); 325 + cur_ent++; 326 + cur_ent %= ARRAY_SIZE(entity); 327 + usleep_range(200, 500); 328 + } while (!drm_mock_sched_job_is_finished(job)); 329 + 330 + for (i = 0; i < ARRAY_SIZE(entity); i++) 331 + drm_mock_sched_entity_free(entity[i]); 332 + } 333 + 334 + static struct kunit_case drm_sched_priority_tests[] = { 335 + KUNIT_CASE(drm_sched_priorities), 336 + KUNIT_CASE(drm_sched_change_priority), 337 + {} 338 + }; 339 + 340 + static struct kunit_suite drm_sched_priority = { 341 + .name = "drm_sched_basic_priority_tests", 342 + .init = drm_sched_basic_init, 343 + .exit = drm_sched_basic_exit, 344 + .test_cases = drm_sched_priority_tests, 345 + }; 346 + 259 347 kunit_test_suites(&drm_sched_basic, 260 - &drm_sched_timeout); 348 + &drm_sched_timeout, 349 + &drm_sched_priority);