new file mode 100644
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: MIT
+ * Copyright 2018 Advanced Micro Devices, Inc.
+ */
+#ifndef _CGROUP_DRM_H
+#define _CGROUP_DRM_H
+
+#ifdef CONFIG_CGROUP_DRM
+
+#include <linux/cgroup.h>
+
+struct drmcgrp {
+ struct cgroup_subsys_state css;
+};
+
+static inline struct drmcgrp *css_drmcgrp(struct cgroup_subsys_state *css)
+{
+ return css ? container_of(css, struct drmcgrp, css) : NULL;
+}
+
+static inline struct drmcgrp *get_drmcgrp(struct task_struct *task)
+{
+ return css_drmcgrp(task_get_css(task, drm_cgrp_id));
+}
+
+
+static inline struct drmcgrp *parent_drmcgrp(struct drmcgrp *cg)
+{
+ return css_drmcgrp(cg->css.parent);
+}
+
+#endif /* CONFIG_CGROUP_DRM */
+#endif /* _CGROUP_DRM_H */
@@ -61,6 +61,10 @@ SUBSYS(pids)
SUBSYS(rdma)
#endif
+#if IS_ENABLED(CONFIG_CGROUP_DRM)
+SUBSYS(drm)
+#endif
+
/*
* The following subsystems are not supported on the default hierarchy.
*/
@@ -836,6 +836,11 @@ config CGROUP_RDMA
Attaching processes with active RDMA resources to the cgroup
hierarchy is allowed even if can cross the hierarchy's limit.
+config CGROUP_DRM
+ bool "DRM controller (EXPERIMENTAL)"
+ help
+ Provides accounting and enforcement of resources in the DRM subsystem.
+
config CGROUP_FREEZER
bool "Freezer controller"
help
@@ -4,5 +4,6 @@ obj-y := cgroup.o rstat.o namespace.o cgroup-v1.o
obj-$(CONFIG_CGROUP_FREEZER) += freezer.o
obj-$(CONFIG_CGROUP_PIDS) += pids.o
obj-$(CONFIG_CGROUP_RDMA) += rdma.o
+obj-$(CONFIG_CGROUP_DRM) += drm.o
obj-$(CONFIG_CPUSETS) += cpuset.o
obj-$(CONFIG_CGROUP_DEBUG) += debug.o
new file mode 100644
@@ -0,0 +1,46 @@
+// SPDX-License-Identifier: MIT
+// Copyright 2018 Advanced Micro Devices, Inc.
+#include <linux/slab.h>
+#include <linux/cgroup.h>
+#include <linux/cgroup_drm.h>
+
+static u64 drmcgrp_test_read(struct cgroup_subsys_state *css,
+ struct cftype *cft)
+{
+ return 88;
+}
+
+static void drmcgrp_css_free(struct cgroup_subsys_state *css)
+{
+ struct drmcgrp *drmcgrp = css_drmcgrp(css);
+
+ kfree(css_drmcgrp(css));
+}
+
+static struct cgroup_subsys_state *
+drmcgrp_css_alloc(struct cgroup_subsys_state *parent_css)
+{
+ struct drmcgrp *drmcgrp;
+
+ drmcgrp = kzalloc(sizeof(struct drmcgrp), GFP_KERNEL);
+ if (!drmcgrp)
+ return ERR_PTR(-ENOMEM);
+
+ return &drmcgrp->css;
+}
+
+struct cftype files[] = {
+ {
+ .name = "drm_test",
+ .read_u64 = drmcgrp_test_read,
+ },
+ { } /* terminate */
+};
+
+struct cgroup_subsys drm_cgrp_subsys = {
+ .css_alloc = drmcgrp_css_alloc,
+ .css_free = drmcgrp_css_free,
+ .early_init = false,
+ .legacy_cftypes = files,
+ .dfl_cftypes = files,
+};
Change-Id: I6830d3990f63f0c13abeba29b1d330cf28882831 Signed-off-by: Kenny Ho <Kenny.Ho@amd.com> --- include/linux/cgroup_drm.h | 32 ++++++++++++++++++++++++ include/linux/cgroup_subsys.h | 4 +++ init/Kconfig | 5 ++++ kernel/cgroup/Makefile | 1 + kernel/cgroup/drm.c | 46 +++++++++++++++++++++++++++++++++++ 5 files changed, 88 insertions(+) create mode 100644 include/linux/cgroup_drm.h create mode 100644 kernel/cgroup/drm.c