[PATCH RFC 0/5] DRM cgroup controller
Kenny.Ho at amd.com
Tue Nov 20 18:58:09 UTC 2018
The purpose of this patch series is to start a discussion for a generic cgroup
controller for the drm subsystem. The design proposed here is a very early one.
We are hoping to engage the community as we develop the idea.
Control Groups/cgroup provide a mechanism for aggregating/partitioning sets of
tasks, and all their future children, into hierarchical groups with specialized
behaviour, such as accounting/limiting the resources which processes in a cgroup
can access. Weights, limits, protections, allocations are the main resource
distribution models. Existing cgroup controllers includes cpu, memory, io,
rdma, and more. cgroup is one of the foundational technologies that enables the
popular container application deployment and management method.
Direct Rendering Manager/drm contains code intended to support the needs of
complex graphics devices. Graphics drivers in the kernel may make use of DRM
functions to make tasks like memory management, interrupt handling and DMA
easier, and provide a uniform interface to applications. The DRM has also
developed beyond traditional graphics applications to support compute/GPGPU
As GPU grow beyond the realm of desktop/workstation graphics into areas like
data center clusters and IoT, there are increasing needs to monitor and regulate
GPU as a resource like cpu, memory and io.
Matt Roper from Intel began working on similar idea in early 2018  for the
purpose of managing GPU priority using the cgroup hierarchy. While that
particular use case may not warrant a standalone drm cgroup controller, there
are other use cases where having one can be useful . Monitoring GPU
resources such as VRAM and buffers, CU (compute unit [AMD's nomenclature])/EU
(execution unit [Intel's nomenclature]), GPU job scheduling  can help
sysadmins get a better understanding of the applications usage profile. Further
usage regulations of the aforementioned resources can also help sysadmins
optimize workload deployment on limited GPU resources.
With the increased importance of machine learning, data science and other
cloud-based applications, GPUs are already in production use in data centers
today [5,6,7]. Existing GPU resource management is very course grain, however,
as sysadmins are only able to distribute workload on a per-GPU basis . An
alternative is to use GPU virtualization (with or without SRIOV) but it
generally acts on the entire GPU instead of the specific resources in a GPU.
With a drm cgroup controller, we can enable alternate, fine-grain, sub-GPU
resource management (in addition to what may be available via GPU
In addition to production use, the DRM cgroup can also help with testing
graphics application robustness by providing a mean to artificially limit DRM
resources availble to the applications.
While there are common infrastructure in DRM that is shared across many vendors
(the scheduler  for example), there are also aspects of DRM that are vendor
specific. To accommodate this, we borrowed the mechanism used by the cgroup to
handle different kinds of cgroup controller.
Resources for DRM are also often device (GPU) specific instead of system
specific and a system may contain more than one GPU. For this, we borrowed some
of the ideas from RDMA cgroup controller.
To experiment with the idea of a DRM cgroup, we would like to start with basic
accounting and statistics, then continue to iterate and add regulating
mechanisms into the driver.
Kenny Ho (5):
cgroup: Introduce cgroup for drm subsystem
cgroup: Add mechanism to register vendor specific DRM devices
drm/amdgpu: Add DRM cgroup support for AMD devices
drm/amdgpu: Add accounting of command submission via DRM cgroup
drm/amdgpu: Add accounting of buffer object creation request via DRM
drivers/gpu/drm/amd/amdgpu/Makefile | 3 +
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 5 +
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 7 +
drivers/gpu/drm/amd/amdgpu/amdgpu_drmcgrp.c | 147 ++++++++++++++++++++
drivers/gpu/drm/amd/amdgpu/amdgpu_drmcgrp.h | 27 ++++
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 13 ++
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 15 ++
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h | 5 +-
include/drm/drm_cgroup.h | 39 ++++++
include/drm/drmcgrp_vendors.h | 8 ++
include/linux/cgroup_drm.h | 58 ++++++++
include/linux/cgroup_subsys.h | 4 +
include/uapi/drm/amdgpu_drm.h | 24 +++-
init/Kconfig | 5 +
kernel/cgroup/Makefile | 1 +
kernel/cgroup/drm.c | 130 +++++++++++++++++
16 files changed, 484 insertions(+), 7 deletions(-)
create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_drmcgrp.c
create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_drmcgrp.h
create mode 100644 include/drm/drm_cgroup.h
create mode 100644 include/drm/drmcgrp_vendors.h
create mode 100644 include/linux/cgroup_drm.h
create mode 100644 kernel/cgroup/drm.c
More information about the dri-devel