drivers/gpu/drm/i915/selftests/i915_gem_evict.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/i915/selftests/i915_gem_evict.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/i915/selftests/i915_gem_evict.c- Extension
.c- Size
- 14308 bytes
- Lines
- 572
- Domain
- Driver Families
- Bucket
- drivers/gpu
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
gem/i915_gem_internal.hgem/i915_gem_pm.hgem/selftests/igt_gem_utils.hgem/selftests/mock_context.hgt/intel_gt.hgt/intel_gt_print.hi915_selftest.higt_flush_test.hlib_sw_fence.hmock_drm.hmock_gem_device.h
Detected Declarations
struct reservedfunction filesfunction populate_ggttfunction unpin_ggttfunction cleanup_objectsfunction list_for_each_entry_safefunction igt_evict_somethingfunction igt_overcommitfunction igt_evict_for_vmafunction mock_color_adjustfunction igt_evict_vmfunction for_i915_gem_wwfunction igt_evict_contextsfunction i915_gem_evict_mock_selftestsfunction i915_gem_evict_live_selftests
Annotated Snippet
struct reserved {
struct drm_mm_node node;
struct reserved *next;
} *reserved = NULL;
intel_wakeref_t wakeref;
struct drm_mm_node hole;
unsigned long count;
int err;
/*
* The purpose of this test is to verify that we will trigger an
* eviction in the GGTT when constructing a request that requires
* additional space in the GGTT for pinning the context. This space
* is not directly tied to the request so reclaiming it requires
* extra work.
*
* As such this test is only meaningful for full-ppgtt environments
* where the GTT space of the request is separate from the GGTT
* allocation required to build the request.
*/
if (!HAS_FULL_PPGTT(i915))
return 0;
wakeref = intel_runtime_pm_get(&i915->runtime_pm);
/* Reserve a block so that we know we have enough to fit a few rq */
memset(&hole, 0, sizeof(hole));
mutex_lock(&ggtt->vm.mutex);
err = i915_gem_gtt_insert(&ggtt->vm, NULL, &hole,
PRETEND_GGTT_SIZE, 0, I915_COLOR_UNEVICTABLE,
0, ggtt->vm.total,
PIN_NOEVICT);
if (err)
goto out_locked;
/* Make the GGTT appear small by filling it with unevictable nodes */
count = 0;
do {
struct reserved *r;
mutex_unlock(&ggtt->vm.mutex);
r = kzalloc_objs(*r, 1);
mutex_lock(&ggtt->vm.mutex);
if (!r) {
err = -ENOMEM;
goto out_locked;
}
if (i915_gem_gtt_insert(&ggtt->vm, NULL, &r->node,
1ul << 20, 0, I915_COLOR_UNEVICTABLE,
0, ggtt->vm.total,
PIN_NOEVICT)) {
kfree(r);
break;
}
r->next = reserved;
reserved = r;
count++;
} while (1);
drm_mm_remove_node(&hole);
mutex_unlock(&ggtt->vm.mutex);
pr_info("Filled GGTT with %lu 1MiB nodes\n", count);
/* Overfill the GGTT with context objects and so try to evict one. */
for_each_engine(engine, gt, id) {
struct i915_sw_fence fence;
struct i915_request *last = NULL;
count = 0;
onstack_fence_init(&fence);
do {
struct intel_context *ce;
struct i915_request *rq;
ce = intel_context_create(engine);
if (IS_ERR(ce))
break;
/* We will need some GGTT space for the rq's context */
igt_evict_ctl.fail_if_busy = true;
rq = intel_context_create_request(ce);
igt_evict_ctl.fail_if_busy = false;
intel_context_put(ce);
if (IS_ERR(rq)) {
/* When full, fail_if_busy will trigger EBUSY */
if (PTR_ERR(rq) != -EBUSY) {
pr_err("Unexpected error from request alloc (on %s): %d\n",
Annotation
- Immediate include surface: `gem/i915_gem_internal.h`, `gem/i915_gem_pm.h`, `gem/selftests/igt_gem_utils.h`, `gem/selftests/mock_context.h`, `gt/intel_gt.h`, `gt/intel_gt_print.h`, `i915_selftest.h`, `igt_flush_test.h`.
- Detected declarations: `struct reserved`, `function files`, `function populate_ggtt`, `function unpin_ggtt`, `function cleanup_objects`, `function list_for_each_entry_safe`, `function igt_evict_something`, `function igt_overcommit`, `function igt_evict_for_vma`, `function mock_color_adjust`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.