Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
To: Thadeu Lima de Souza Cascardo <cascardo@igalia.com>,
	igt-dev@lists.freedesktop.org
Cc: siqueira@igalia.com, dri-devel@lists.freedesktop.org,
	amd-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org,
	"Christian Koenig" <christian.koenig@amd.com>,
	maarten.lankhorst@linux.intel.com,
	"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
	"Kamil Konieczny" <kamil.konieczny@linux.intel.com>,
	"Janusz Krzysztofik" <janusz.krzysztofik@linux.intel.com>,
	"Vitaly Prosyak" <vitaly.prosyak@amd.com>,
	"Natalie Vock" <natalie.vock@gmx.de>,
	kernel-dev@igalia.com
Subject: Re: [PATCH i-g-t v6 6/9] lib/amdgpu: add amdgpu support to igt_dmem_driver
Date: Fri, 4 Sep 2026 11:11:21 +0100	[thread overview]
Message-ID: <33fabbd4-d87b-440d-b5f8-3b9be9618d7b@igalia.com> (raw)
In-Reply-To: <20260903-dmem_max-v6-6-61dc62970fae@igalia.com>


On 03/09/2026 23:00, Thadeu Lima de Souza Cascardo wrote:
> This allows dmem cgroups tests to run on top of amdgpu driver, adding
> support to allocate and release VRAM memory.
> 
> This does this by allocating a BO from VRAM domain, which will try to
> place BOs on VRAM, but may fallback to GTT.
> 
> Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@igalia.com>
> ---
>   lib/amdgpu/amd_dmem.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++
>   lib/igt_dmem_driver.h |  1 +
>   lib/meson.build       |  1 +
>   3 files changed, 92 insertions(+)
> 
> diff --git a/lib/amdgpu/amd_dmem.c b/lib/amdgpu/amd_dmem.c
> new file mode 100644
> index 000000000000..cb0fed4b870a
> --- /dev/null
> +++ b/lib/amdgpu/amd_dmem.c
> @@ -0,0 +1,90 @@
> +// SPDX-License-Identifier: MIT
> +/*
> + * Copyright 2026 Valve Corporation
> + * Authors:
> + *  Thadeu Lima de Souza Cascardo <cascardo@igalia.com>
> + */
> +
> +#include <errno.h>
> +
> +#include "igt.h"
> +#include "igt_cgroup.h"
> +#include "igt_dmem_driver.h"
> +#include "lib/amdgpu/amd_memory.h"
> +
> +struct amdgpu_dmem_ctx {
> +	int fd;
> +	amdgpu_device_handle device;
> +};
> +
> +static int amdgpu_dmem_init(void **ctx, int fd)
> +{
> +	struct amdgpu_dmem_ctx *actx;
> +	uint32_t major, minor;
> +	int err;
> +
> +	actx = malloc(sizeof(*actx));
> +	if (!actx)
> +		return -ENOMEM;
> +
> +	err = amdgpu_device_initialize(fd, &major, &minor, &actx->device);
> +	if (err)
> +		goto out;
> +
> +	actx->fd = fd;
> +
> +	*ctx = actx;
> +
> +	return 0;
> +
> +out:
> +	free(actx);
> +
> +	return err;
> +}
> +
> +static void amdgpu_dmem_deinit(void *ctx)
> +{
> +	struct amdgpu_dmem_ctx *actx = ctx;
> +
> +	amdgpu_device_deinitialize(actx->device);
> +	free(actx);
> +}
> +
> +static char * amdgpu_dmem_get_region_name(void *ctx)
> +{
> +	struct amdgpu_dmem_ctx *actx = ctx;
> +
> +	return amdgpu_cgroup_region_name(actx->fd);
> +}
> +
> +static int amdgpu_dmem_allocate_vram(void *ctx, size_t len, void **ret_handle)
> +{
> +	struct amdgpu_dmem_ctx *actx = ctx;
> +	amdgpu_bo_handle handle;
> +	int err;
> +
> +	err = amdgpu_bo_alloc_wrap(actx->device, len, 4096,
> +				   AMDGPU_GEM_DOMAIN_VRAM, 0, &handle);
> +	if (err)
> +		return err;
> +
> +	if (ret_handle)
> +		*ret_handle = (void *) handle;

Is there an use case for ret_handle == NULL? Xe backend does not bother 
with the check. This aside, the rest looks good to me:

Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>

Regards,

Tvrtko

> +
> +	return 0;
> +}
> +
> +static void amdgpu_dmem_free_vram(void *ctx, void *handle)
> +{
> +	amdgpu_bo_free(handle);
> +}
> +
> +const struct igt_dmem_driver amdgpu_dmem_driver = {
> +	.name = "amdgpu",
> +	.get_region_name = amdgpu_dmem_get_region_name,
> +	.init = amdgpu_dmem_init,
> +	.deinit = amdgpu_dmem_deinit,
> +	.allocate_vram = amdgpu_dmem_allocate_vram,
> +	.free_vram = amdgpu_dmem_free_vram,
> +};
> diff --git a/lib/igt_dmem_driver.h b/lib/igt_dmem_driver.h
> index e6998387eff9..f2d9d74196db 100644
> --- a/lib/igt_dmem_driver.h
> +++ b/lib/igt_dmem_driver.h
> @@ -30,5 +30,6 @@ struct igt_dmem_driver {
>   };
>   
>   extern const struct igt_dmem_driver xe_dmem_driver;
> +extern const struct igt_dmem_driver amdgpu_dmem_driver;
>   
>   #endif
> diff --git a/lib/meson.build b/lib/meson.build
> index 022408ce6864..e191793f0097 100644
> --- a/lib/meson.build
> +++ b/lib/meson.build
> @@ -205,6 +205,7 @@ if libdrm_amdgpu.found()
>   		'amdgpu/amd_mmd_shared.c',
>   		'amdgpu/amd_jpeg_shared.c',
>   		'amdgpu/amd_utils.c',
> +		'amdgpu/amd_dmem.c',
>   		'amdgpu/amd_vcn_shared.c'
>   	]
>   	if libdrm_amdgpu.version().version_compare('> 2.4.99')
> 


  reply	other threads:[~2026-09-04 10:11 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-03 22:00 [PATCH i-g-t v6 0/9] add cgroup_dmem test Thadeu Lima de Souza Cascardo
2026-09-03 22:00 ` [PATCH i-g-t v6 1/9] lib/igt_cgroup: add cgroup v2 and dmem controller helpers Thadeu Lima de Souza Cascardo
2026-09-03 22:00 ` [PATCH i-g-t v6 2/9] tests/cgroup_dmem: add dmem cgroup controller test Thadeu Lima de Souza Cascardo
2026-09-03 22:00 ` [PATCH i-g-t v6 3/9] lib/xe: add xe_cgroup_region_name() helper Thadeu Lima de Souza Cascardo
2026-09-03 22:00 ` [PATCH i-g-t v6 4/9] lib/xe: Introduce dmem driver and implement Xe support Thadeu Lima de Souza Cascardo
2026-09-04 10:02   ` Tvrtko Ursulin
2026-09-03 22:00 ` [PATCH i-g-t v6 5/9] lib/amdgpu: add amdgpu_cgroup_region_name Thadeu Lima de Souza Cascardo
2026-09-04 10:00   ` Tvrtko Ursulin
2026-09-03 22:00 ` [PATCH i-g-t v6 6/9] lib/amdgpu: add amdgpu support to igt_dmem_driver Thadeu Lima de Souza Cascardo
2026-09-04 10:11   ` Tvrtko Ursulin [this message]
2026-09-03 22:00 ` [PATCH i-g-t v6 7/9] tests/cgroup_dmem: add test for dmem.current Thadeu Lima de Souza Cascardo
2026-09-04 12:40   ` Tvrtko Ursulin
2026-09-03 22:00 ` [PATCH i-g-t v6 8/9] tests/cgroup_dmem: add dmem cgroup eviction test Thadeu Lima de Souza Cascardo
2026-09-04 14:48   ` Tvrtko Ursulin
2026-09-03 22:00 ` [PATCH i-g-t v6 9/9] tests/cgroup_dmem: add write_eviction_nonblock subtest Thadeu Lima de Souza Cascardo
2026-09-04 14:51   ` Tvrtko Ursulin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=33fabbd4-d87b-440d-b5f8-3b9be9618d7b@igalia.com \
    --to=tvrtko.ursulin@igalia.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=cascardo@igalia.com \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=janusz.krzysztofik@linux.intel.com \
    --cc=kamil.konieczny@linux.intel.com \
    --cc=kernel-dev@igalia.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=natalie.vock@gmx.de \
    --cc=siqueira@igalia.com \
    --cc=thomas.hellstrom@linux.intel.com \
    --cc=vitaly.prosyak@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox