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.

Dependency Surface

Detected Declarations

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

Implementation Notes