[RFC,12/17] 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 | 1 +
kernel/cgroup/drm.c | 8 ++++++++
3 files changed, 17 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);
@@ -25,6 +26,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;
lockdep_assert_held(&dev->filelist_mutex);
@@ -35,6 +37,12 @@ void drm_clients_close(struct drm_file *file_priv)
if (WARN_ON_ONCE(!clients))
return;
+ task = get_pid_task(file_priv->cpid, PIDTYPE_PID);
+ if (task) {
+ drmcgroup_client_exited(task);
+ put_task_struct(task);
+ }
+
__del_clients(clients, file_priv);
/*
@@ -13,5 +13,6 @@ struct task_struct;
#define DRM_CGROUP_PRIORITY_MAX (10000)
int drmcgroup_lookup_effective_priority(struct task_struct *task);
+void drmcgroup_client_exited(struct task_struct *task);
#endif /* _CGROUP_DRM_H */
@@ -221,6 +221,14 @@ static void drmcs_attach(struct cgroup_taskset *tset)
css_to_drmcs(css)->effective_priority);
}
+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 = {
.priority = DRM_CGROUP_PRIORITY_DEF,
.effective_priority = DRM_CGROUP_PRIORITY_DEF,