drivers/gpu/drm/xe/tests/xe_bo.c

Source file repositories/reference/linux-study-clean/drivers/gpu/drm/xe/tests/xe_bo.c

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/xe/tests/xe_bo.c
Extension
.c
Size
15745 bytes
Lines
633
Domain
Driver Families
Bucket
drivers/gpu
Inferred role
Driver Families: exported/initcall integration point
Status
integration implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

struct xe_bo_link {
	struct list_head link;
	struct xe_bo *bo;
	u32 val;
};

#define XE_BO_SHRINK_SIZE ((unsigned long)SZ_64M)

static int shrink_test_fill_random(struct xe_bo *bo, struct rnd_state *state,
				   struct xe_bo_link *link)
{
	struct iosys_map map;
	int ret = ttm_bo_vmap(&bo->ttm, &map);
	size_t __maybe_unused i;

	if (ret)
		return ret;

	for (i = 0; i < bo->ttm.base.size; i += sizeof(u32)) {
		u32 val = prandom_u32_state(state);

		iosys_map_wr(&map, i, u32, val);
		if (i == 0)
			link->val = val;
	}

	ttm_bo_vunmap(&bo->ttm, &map);
	return 0;
}

static bool shrink_test_verify(struct kunit *test, struct xe_bo *bo,
			       unsigned int bo_nr, struct rnd_state *state,
			       struct xe_bo_link *link)
{
	struct iosys_map map;
	int ret = ttm_bo_vmap(&bo->ttm, &map);
	size_t i;
	bool failed = false;

	if (ret) {
		KUNIT_FAIL(test, "Error mapping bo %u for content check.\n", bo_nr);
		return true;
	}

	for (i = 0; i < bo->ttm.base.size; i += sizeof(u32)) {
		u32 val = prandom_u32_state(state);

		if (iosys_map_rd(&map, i, u32) != val) {
			KUNIT_FAIL(test, "Content not preserved, bo %u offset 0x%016llx",
				   bo_nr, (unsigned long long)i);
			kunit_info(test, "Failed value is 0x%08x, recorded 0x%08x\n",
				   (unsigned int)iosys_map_rd(&map, i, u32), val);
			if (i == 0 && val != link->val)
				kunit_info(test, "Looks like PRNG is out of sync.\n");
			failed = true;
			break;
		}
	}

	ttm_bo_vunmap(&bo->ttm, &map);

	return failed;
}

/*
 * Try to create system bos corresponding to twice the amount
 * of available system memory to test shrinker functionality.
 * If no swap space is available to accommodate the
 * memory overcommit, mark bos purgeable.
 */
static int shrink_test_run_device(struct xe_device *xe)
{
	struct kunit *test = kunit_get_current_test();
	LIST_HEAD(bos);
	struct xe_bo_link *link, *next;
	struct sysinfo si;
	u64 ram, ram_and_swap, purgeable = 0, alloced, to_alloc, limit;
	unsigned int interrupted = 0, successful = 0, count = 0;
	struct rnd_state prng;
	u64 rand_seed;
	bool failed = false;

	rand_seed = get_random_u64();
	prandom_seed_state(&prng, rand_seed);
	kunit_info(test, "Random seed is 0x%016llx.\n",
		   (unsigned long long)rand_seed);

	/* Skip if execution time is expected to be too long. */

	limit = SZ_32G;

Annotation

Implementation Notes