[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250903152327.66002-20-tvrtko.ursulin@igalia.com>
Date: Wed, 3 Sep 2025 16:23:25 +0100
From: Tvrtko Ursulin <tvrtko.ursulin@...lia.com>
To: dri-devel@...ts.freedesktop.org
Cc: amd-gfx@...ts.freedesktop.org,
kernel-dev@...lia.com,
intel-xe@...ts.freedesktop.org,
cgroups@...r.kernel.org,
linux-kernel@...r.kernel.org,
Tvrtko Ursulin <tvrtko.ursulin@...lia.com>
Subject: [RFC 19/21] drm/amdgpu: Register with the DRM scheduling cgroup controller
Connect the driver to the DRM scheduling cgroup controller by using the
appropriate DRM scheduler helpers.
First part is tracking the scheduling entities belonging to clients and
second is to register the weight change notification helper in the driver
specific struct drm_cgroup_ops.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@...lia.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 13 ++++++++++++-
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h | 1 +
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 9 +++++++++
3 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
index f5d5c45ddc0d..160dddbe892d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
@@ -22,6 +22,7 @@
* Authors: monk liu <monk.liu@....com>
*/
+#include <linux/cgroup_drm.h>
#include <drm/drm_auth.h>
#include <drm/drm_drv.h>
#include "amdgpu.h"
@@ -258,6 +259,8 @@ static int amdgpu_ctx_init_entity(struct amdgpu_ctx *ctx, u32 hw_ip,
if (cmpxchg(&ctx->entities[hw_ip][ring], NULL, entity))
goto cleanup_entity;
+ drm_sched_cgroup_track_sched_entity(ctx->filp, &entity->entity);
+
return 0;
cleanup_entity:
@@ -331,6 +334,7 @@ static int amdgpu_ctx_init(struct amdgpu_ctx_mgr *mgr, int32_t priority,
memset(ctx, 0, sizeof(*ctx));
kref_init(&ctx->refcount);
+ ctx->filp = filp;
ctx->mgr = mgr;
spin_lock_init(&ctx->ring_lock);
@@ -511,10 +515,15 @@ static void amdgpu_ctx_do_release(struct kref *ref)
ctx = container_of(ref, struct amdgpu_ctx, refcount);
for (i = 0; i < AMDGPU_HW_IP_NUM; ++i) {
for (j = 0; j < amdgpu_ctx_num_entities[i]; ++j) {
+ struct drm_sched_entity *entity;
+
if (!ctx->entities[i][j])
continue;
- drm_sched_entity_destroy(&ctx->entities[i][j]->entity);
+ entity = &ctx->entities[i][j]->entity;
+ drm_sched_cgroup_untrack_sched_entity(ctx->filp,
+ entity);
+ drm_sched_entity_destroy(entity);
}
}
@@ -941,6 +950,8 @@ static void amdgpu_ctx_mgr_entity_fini(struct amdgpu_ctx_mgr *mgr)
continue;
entity = &ctx->entities[i][j]->entity;
+ drm_sched_cgroup_untrack_sched_entity(ctx->filp,
+ entity);
drm_sched_entity_fini(entity);
}
}
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h
index 090dfe86f75b..e6541e56da16 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h
@@ -44,6 +44,7 @@ struct amdgpu_ctx_entity {
struct amdgpu_ctx {
struct kref refcount;
+ struct drm_file *filp;
struct amdgpu_ctx_mgr *mgr;
unsigned reset_counter;
unsigned reset_counter_query;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 17f754d1135d..a9c38054c0d7 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -3053,6 +3053,12 @@ const struct drm_ioctl_desc amdgpu_ioctls_kms[] = {
DRM_IOCTL_DEF_DRV(AMDGPU_USERQ_WAIT, amdgpu_userq_wait_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
};
+#ifdef CONFIG_CGROUP_DRM
+static const struct drm_cgroup_ops amdgpu_drm_cgroup_ops = {
+ .notify_weight = drm_sched_cgroup_notify_weight,
+};
+#endif
+
static const struct drm_driver amdgpu_kms_driver = {
.driver_features =
DRIVER_ATOMIC |
@@ -3071,6 +3077,9 @@ static const struct drm_driver amdgpu_kms_driver = {
#ifdef CONFIG_PROC_FS
.show_fdinfo = amdgpu_show_fdinfo,
#endif
+#ifdef CONFIG_CGROUP_DRM
+ .cg_ops = &amdgpu_drm_cgroup_ops,
+#endif
.gem_prime_import = amdgpu_gem_prime_import,
--
2.48.0
Powered by blists - more mailing lists