[RFC,10/13] cgroup/drm: Client exit hook
Commit Message
From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
We need the ability for DRM core to inform the cgroup controller when a
client has closed a DRM file descriptor. This will allow us not needing
to keep state relating to GPU time usage by tasks sets in the cgroup
controller itself.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
drivers/gpu/drm/drm_cgroup.c | 8 ++++++++
include/linux/cgroup_drm.h | 4 ++++
kernel/cgroup/drm.c | 13 +++++++++++++
3 files changed, 25 insertions(+)
@@ -5,6 +5,7 @@
#include <drm/drm_drv.h>
#include <drm/drm_clients.h>
+#include <linux/cgroup_drm.h>
static DEFINE_XARRAY(drm_pid_clients);
@@ -31,6 +32,7 @@ void drm_clients_close(struct drm_file *file_priv)
{
struct drm_device *dev = file_priv->minor->dev;
struct drm_pid_clients *clients;
+ struct task_struct *task;
struct pid *pid;
lockdep_assert_held(&dev->filelist_mutex);
@@ -43,6 +45,12 @@ void drm_clients_close(struct drm_file *file_priv)
if (WARN_ON_ONCE(!clients))
return;
+ task = get_pid_task(pid, PIDTYPE_PID);
+ if (task) {
+ drmcgroup_client_exited(task);
+ put_task_struct(task);
+ }
+
__del_clients(clients, file_priv, (unsigned long)pid);
}
@@ -6,4 +6,8 @@
#ifndef _CGROUP_DRM_H
#define _CGROUP_DRM_H
+struct task_struct;
+
+void drmcgroup_client_exited(struct task_struct *task);
+
#endif /* _CGROUP_DRM_H */
@@ -18,11 +18,24 @@ css_to_drmcs(struct cgroup_subsys_state *css)
return container_of(css, struct drm_cgroup_state, css);
}
+static inline struct drm_cgroup_state *get_task_drmcs(struct task_struct *task)
+{
+ return css_to_drmcs(task_get_css(task, drm_cgrp_id));
+}
+
static void drmcs_free(struct cgroup_subsys_state *css)
{
kfree(css_to_drmcs(css));
}
+void drmcgroup_client_exited(struct task_struct *task)
+{
+ struct drm_cgroup_state *drmcs = get_task_drmcs(task);
+
+ css_put(&drmcs->css);
+}
+EXPORT_SYMBOL_GPL(drmcgroup_client_exited);
+
static struct drm_cgroup_state root_drmcs = {
};