drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c- Extension
.c- Size
- 7205 bytes
- Lines
- 263
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
drm/amdgpu_drm.hamdgpu.h
Detected Declarations
function filesfunction amdgpu_benchmark_log_resultsfunction amdgpu_benchmark_movefunction amdgpu_benchmark
Annotated Snippet
#include <drm/amdgpu_drm.h>
#include "amdgpu.h"
#define AMDGPU_BENCHMARK_ITERATIONS 1024
#define AMDGPU_BENCHMARK_COMMON_MODES_N 17
static int amdgpu_benchmark_do_move(struct amdgpu_device *adev, unsigned size,
uint64_t saddr, uint64_t daddr, int n, s64 *time_ms)
{
ktime_t stime, etime;
struct dma_fence *fence;
int i, r;
mutex_lock(&adev->mman.default_entity.lock);
stime = ktime_get();
for (i = 0; i < n; i++) {
r = amdgpu_copy_buffer(adev, &adev->mman.default_entity,
saddr, daddr, size, NULL, &fence,
false, 0);
if (r)
goto exit_do_move;
r = dma_fence_wait(fence, false);
dma_fence_put(fence);
if (r)
goto exit_do_move;
}
exit_do_move:
mutex_unlock(&adev->mman.default_entity.lock);
etime = ktime_get();
*time_ms = ktime_ms_delta(etime, stime);
return r;
}
static void amdgpu_benchmark_log_results(struct amdgpu_device *adev,
int n, unsigned size,
s64 time_ms,
unsigned sdomain, unsigned ddomain,
char *kind)
{
s64 throughput = (n * (size >> 10));
throughput = div64_s64(throughput, time_ms);
dev_info(adev->dev, " %s %u bo moves of %u kB from"
" %d to %d in %lld ms, throughput: %lld Mb/s or %lld MB/s\n",
kind, n, size >> 10, sdomain, ddomain, time_ms,
throughput * 8, throughput);
}
static int amdgpu_benchmark_move(struct amdgpu_device *adev, unsigned size,
unsigned sdomain, unsigned ddomain)
{
struct amdgpu_bo *dobj = NULL;
struct amdgpu_bo *sobj = NULL;
uint64_t saddr, daddr;
s64 time_ms;
int r, n;
n = AMDGPU_BENCHMARK_ITERATIONS;
r = amdgpu_bo_create_kernel(adev, size,
PAGE_SIZE, sdomain,
&sobj,
&saddr,
NULL);
if (r)
goto out_cleanup;
r = amdgpu_bo_create_kernel(adev, size,
PAGE_SIZE, ddomain,
&dobj,
&daddr,
NULL);
if (r)
goto out_cleanup;
if (adev->mman.buffer_funcs) {
r = amdgpu_benchmark_do_move(adev, size, saddr, daddr, n, &time_ms);
if (r)
goto out_cleanup;
else
amdgpu_benchmark_log_results(adev, n, size, time_ms,
sdomain, ddomain, "dma");
}
out_cleanup:
/* Check error value now. The value can be overwritten when clean up.*/
if (r < 0)
Annotation
- Immediate include surface: `drm/amdgpu_drm.h`, `amdgpu.h`.
- Detected declarations: `function files`, `function amdgpu_benchmark_log_results`, `function amdgpu_benchmark_move`, `function amdgpu_benchmark`.
- 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.