Skip to contentSkip to conversation

DRM management via cgroups

RFC PATCH In review Matt Roper 8 participants 21 messages Jan 20, 2018 – Jan 26, 2018 3 messages not in the archive

Subsystems (5)
lore
Share & tools
lore

Matt Roper

author
#0 lore raw

cover DRM management via cgroups

cgroups are core kernel mechanism that allows a system integrator / system administrator to collect OS processes into a hierarchy of groups according to their intended role in the overall system; resource management and policy configuration can then be applied to each cgroup independently.

The DRM subsystem manages several concepts that would be a good match for cgroup-level configuration. This series adds infrastructure to allow DRM drivers to track 'parameters' associated with individual cgroups. These parameters can be used to manage things like GPU priority, discrete/stolen memory limits, etc.; drivers will be able to query the parameters set for a process' cgroup and then apply appropriate driver-level policy.

The series is organized as follows:
* Patches 1-4 export some additional interfaces from the cgroup core kernel implementation to make them accessible to modules and drivers.
* Patch 5 introduces a new DRM ioctl that allows userspace to set parameter values for specific cgroups.
* Patch 6 introduces a DRM helper library to simplify the management of allocation/storage/fetching of per-cgroup driver-specific data.
* Patch 7 adds a helper function to obtain the v2 cgroup of the process associated with a drm_file.
* Patch 8 implements support for GPU priority as a cgroup parameter in the i915 driver.
* Patch 9 adds context priority to i915's debugfs output to make it easier to verify that context priorities are being initialized as expected.

Anticipated questions / concerns
--------------------------------

Q: What's the userspace consumer of this?

A: I'll send a follow-up to the dri-devel / intel-gfx mailing lists
with a small patch that adds a simple command line tool to the libdrm tests directory. Although it looks more like a simple test program than a real consumer, I think it's about the only userspace we'll ever want/need. Keep in mind that the real "consumers" here aren't the graphics applications themselves, but rather the system startup process (e.g., a sysv-init script or systemd service). The startup scripts can shuffle the various services/programs into appropriate cgroups and then make some calls like:

drm_set_cgrp_param /dev/dri/card0 /cgroup2/safety_critical/ 1 900 drm_set_cgrp_param /dev/dri/card0 /cgroup2/high_priority/ 1 100 drm_set_cgrp_param /dev/dri/card0 /cgroup2/best_effort/ 1 -200

to define the priority policy for each cgroup. Aside from initial startup scripts, none of the actual graphics clients are expected to touch this interface.

Q: The initial use case here is for setting i915 GPU priority according
to cgroup. How/why does this differ from existing priority mechanisms (e.g., setting I915_CONTEXT_PARAM_PRIORITY via the I915_GEM_CONTEXT_SETPARAM ioctl on individual GPU contexts)?

A: Existing mechanisms like the i915 context priority parameter will
ultimately be called by the software that priority is being assigned for (e.g., a 3D application might use EGL_IMG_context_priority to self-classify as high priority or low priority). However the priority of an application usually isn't a characteristic of an application itself, but rather a decision that an admin/integrator makes from a system-level perspective. cgroups provide a standard, convenient mechanism for a system integrator to apply the specific policy he needs to build a cohesive system.

Note that the cgroups support for i915 priority here just assigns the initial/default priority for GPU contexts and doesn't block runtime adjustment of the priority via other mechanisms.

Q: Do we really anticipate other DRM concepts (beyond GPU priority)
being a reasonable match for cgroups-style management/control?

A: I think there's a lot of potential to use cgroups to manage limits
on various types of "graphics memory" in the future. That could either be things like stolen memory on i915 (granted, we don't allow direct allocations of this from userspace today, but it's been talked about in the past) or discrete video RAM on systems that have that.

Q: Why is this implemented via DRM ioctl rather than as a cgroup
controller which would expose settings via kernfs nodes?

A: The kernel has a concept of 'cgroup controllers' for exposing
settings via virtual filesystem nodes. My initial thought was to expose this kind of functionality as a driver-level cgroup controller so that, for example, virtual files like "i915.priority" would appear in each cgroup folder and be readable/writable directly. However as of commit ("3ed80a6 ("cgroup: drop module support")), it's now required that controllers be built directly into the kernel; they can no longer be provided by modules. There was some discussion about this direction at the time here:
https://www.spinics.net/lists/cgroups/msg10077.html
and we discussed it recently again on the cgroups mailing list here:
https://www.spinics.net/lists/cgroups/msg18672.html

The way I see it, usage of cgroups can pretty much be broken down into two categories: (a) distribution/management of a limited resource across a hierarchy of processes, and (b) general policy/configuration setting for groups of processes. The cgroup controller concept is really designed for category (a) above, and a lot of work is done to take the cgroup hierarchy itself into account, not just the details of the final leaf node. In contrast, my initial use of cgroups for DRM drivers (i915 GPU priority) falls into the second category --- we're managing the GPU priority that the scheduler makes use of rather than share of GPU time. The solution I've taken here (driver/subsystem call that takes a cgroup as a parameter and manages data locally) is closer in design to some other areas of the kernel (like the BPF_PROG_ATTACH command accepted by the bpf() system call).

It's possible that if/when we do start looking to cgroups for graphics-specific memory management we will want to consider using a true cgroup controller for that type of management (since it will fit more into category (a) above as a true resource controller). That will probably be some serious work to resurrect module-based controller support in the cgroup subsystem, so I'll leave that until we have a definite use case that needs it. For simpler policy (like GPU priority), the approach here is probably a better direction forward. Of course this is an initial RFC, so feedback welcome!

Q: Why does the DRM cgroup support here restrict itself to the
cgroup-v2 hierarchy? Why not allow DRM parameters to be set on all the cgroup-v1 hierarchies my distro has?

A: cgroups has two ABI's (a multi-hierarchy cgroup-v1 and a single
hierarchy cgroup-v2). Both can co-exist and be used simultaneously on a system, but cgroups-v1 is really for backward compatility, and cgroups-v2 is supposed to be the way of the future. I restricted the support here to v2 mostly so that we wouldn't be building on a legacy framework, but also because the multi-hierarchy nature of v1 cgroups adds some extra complexity. When creating a new GPU context, how would you decide which hierarchy to try to lookup priority in? What if a process had different priority values set on its cgroups in different hierarchies? It's easiest to just avoid the confusion by sticking with the single v2 hierarchy.

Q: The patches here add support for "i915 priority." Should we
simplify this to a more general "GPU priority" that isn't driver-specific or device-specific?

A: I opted for a device-specific approach here for a few reasons.
First, it doesn't seem unreasonable to have a multi-GPU system where groups have different priorities for each GPU they can submit workloads to. Second, we already have multiple scheduler implementations in the DRM tree (e.g., the shared "DRM scheduler" contributed by AMD and the Intel i915 scheduler). These schedulers have different priority ranges and expectations so it might be confusing to try to map any general purpose "GPU priority" range into the specifc range used by an individual scheduler, especially when driver-specific interfaces would then have the ability to alter the priority further via driver-specific interfaces.

Q: Given the justification above, is "i915 priority" too high-level?

    Should we allow priority to be set independently for different
    engines within a single GPU (e.g., render prio != blit prio != video
    prio)?

A: Maybe? I'm open to feedback on this one. If we decide to stick
with a single i915 priority for now, we can always add per-engine priority parameters in the future and update the code so that the existing parameter (I915_CGRP_DEF_CONTEXT_PRIORITY) simply sets the priority for all engines to the same value at once.

Q: What is the access control on this ioctl? Who/what is allowed to
set cgroup parameters?

A: I've tied the access to this ioctl to filesystem permissions on the
cgroup kernfs directory. If a process has write access on the directory (meaning it can make other types of cgroup modifications), then it can update cgroup parameters via the ioctl. I think this is the most sensible way to handle access permission, but alternate suggestions are welcome.

TODO
----
- Add some i-g-t tests to exercise the ioctl interface, especially interaction with various cgroup operations (e.g., set parameter for a cgroup, then rmdir the cgroup directory)

- Documentation: the new code here has a lot of kerneldoc embedded in it, but none of that is actually integrated into the rst files in the Documentation/gpu directory yet.

Matt Roper (9):
kernfs: Export kernfs_get_inode
cgroup: Add notifier call chain for cgroup destruction
cgroup: Export cgroup_on_dfl() to drivers
cgroup: Export task_cgroup_from_root() and cgroup_mutex for drivers
drm: Introduce DRM_IOCTL_CGROUP_SETPARAM
drm: Add cgroup helper library
drm: Add helper to obtain cgroup of drm_file's owning process drm/i915: Allow default context priority to be set via cgroup
parameter
drm/i915: Add context priority to debugfs

 drivers/gpu/drm/Makefile                |   2 +
 drivers/gpu/drm/drm_cgroup.c            | 120 ++++++++++++++++
 drivers/gpu/drm/drm_cgroup_helper.c     | 244 ++++++++++++++++++++++++++++++++
 drivers/gpu/drm/drm_ioctl.c             |   5 +
 drivers/gpu/drm/i915/Makefile           |   1 +
 drivers/gpu/drm/i915/i915_cgroups.c     | 162 +++++++++++++++++++++
 drivers/gpu/drm/i915/i915_debugfs.c     |   2 +
 drivers/gpu/drm/i915/i915_drv.c         |   4 +
 drivers/gpu/drm/i915/i915_drv.h         |  32 +++++
 drivers/gpu/drm/i915/i915_gem_context.c |   2 +-
 fs/kernfs/inode.c                       |   1 +
 include/drm/drm_cgroup.h                |  38 +++++
 include/drm/drm_cgroup_helper.h         | 153 ++++++++++++++++++++
 include/drm/drm_device.h                |  13 ++
 include/drm/drm_file.h                  |  28 ++++
 include/linux/cgroup.h                  |  10 +-
 include/uapi/drm/drm.h                  |  10 ++
 include/uapi/drm/i915_drm.h             |   9 ++
 kernel/cgroup/cgroup-internal.h         |   4 -
 kernel/cgroup/cgroup.c                  |  27 +++-
 20 files changed, 858 insertions(+), 9 deletions(-)
 create mode 100644 drivers/gpu/drm/drm_cgroup.c
 create mode 100644 drivers/gpu/drm/drm_cgroup_helper.c
 create mode 100644 drivers/gpu/drm/i915/i915_cgroups.c
 create mode 100644 include/drm/drm_cgroup.h
 create mode 100644 include/drm/drm_cgroup_helper.h
Signature · 1 line
2.14.3
author
#2 lore raw

RFC PATCH 1/9 kernfs: Export kernfs_get_inode

In reply to a message not in the archive

Drivers may wish to access a cgroup's inode to perform permission checks on driver-specific operations.

---
 fs/kernfs/inode.c | 1 +
 1 file changed, 1 insertion(+)
fs/kernfs/inode.c +1 -0
index a34303981deb..e1e8a0404c5b 100644
@@ -272,6 +272,7 @@ struct inode *kernfs_get_inode(struct super_block *sb, struct kernfs_node *kn)
 
 	return inode;
 }
+EXPORT_SYMBOL(kernfs_get_inode);
 
 /*
  * The kernfs_node serves as both an inode and a directory entry for
Signature · 1 line
2.14.3
#16 lore raw

RFC PATCH 2/9 cgroup: Add notifier call chain for cgroup destruction

In reply to Matt Roper

Drivers or other kernel subsystems may allow subsystem-specific policy and configuration to be applied to cgroups. If these subsystems track private data on a per-cgroup basis, they need a way to be notified about cgroup destruction so that they can clean up their own internal data for that cgroup. Let's add a blocking_notifier that will be called whenever a cgroup in the v2 hierarchy is destroyed to allow this cleanup.

I'm arbitrarily restricting this behavior to the default (cgroup-v2) hierarchy for now since I don't anticipate it being terribly useful on the legacy hierarchies. We can certainly relax that restriction if someone comes up with a use case that needs this on the v1 hierarchies.

---
 include/linux/cgroup.h |  3 +++
 kernel/cgroup/cgroup.c | 18 ++++++++++++++++++
 2 files changed, 21 insertions(+)
include/linux/cgroup.h +3 -0
index 473e0c0abb86..c9896027ed99 100644
@@ -43,6 +43,9 @@
 /* walk all threaded css_sets in the domain */
 #define CSS_TASK_ITER_THREADED		(1U << 1)
 
+/* Driver-registered callbacks for cgroup destruction */
+extern struct blocking_notifier_head cgroup_destroy_notifier_list;
+
 /* a css_task_iter should be treated as an opaque object */
 struct css_task_iter {
 	struct cgroup_subsys		*ss;
kernel/cgroup/cgroup.c +18 -0
index 2cf06c274e4c..f12c32c6ec7f 100644
@@ -75,6 +75,15 @@
 DEFINE_MUTEX(cgroup_mutex);
 DEFINE_SPINLOCK(css_set_lock);
 
+/*
+ * Driver-registered callbacks for cgroup destruction.  Drivers may wish to
+ * track their own per-cgroup data.  Registering a callback on this list will
+ * allow them to detect cgroup destruction and perform any appropriate cleanup
+ * of that data when the cgroup is destroyed.
+ */
+BLOCKING_NOTIFIER_HEAD(cgroup_destroy_notifier_list);
+EXPORT_SYMBOL_GPL(cgroup_destroy_notifier_list);
+
 #ifdef CONFIG_PROVE_RCU
 EXPORT_SYMBOL_GPL(cgroup_mutex);
 EXPORT_SYMBOL_GPL(css_set_lock);
@@ -5086,6 +5095,15 @@ static int cgroup_destroy_locked(struct cgroup *cgrp)
 	for_each_css(css, ssid, cgrp)
 		kill_css(css);
 
+	/*
+	 * Notify listeners of cgroup destruction on the default hierarchy.
+	 * Drivers that store per-cgroup data may register for callback to know
+	 * when it's safe to reap that data.
+	 */
+	if (cgroup_on_dfl(cgrp))
+		blocking_notifier_call_chain(&cgroup_destroy_notifier_list,
+					     0, cgrp);
+
 	/*
 	 * Remove @cgrp directory along with the base files.  @cgrp has an
 	 * extra ref on its kn.
Signature · 6 lines
2.14.3

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author
#3 lore raw

RFC PATCH 3/9 cgroup: Export cgroup_on_dfl() to drivers

In reply to a message not in the archive

Drivers may wish to limit their own cgroup operations to cgroups in the cgroup-v2 hierarchy. Let's make this helper function usable outside the cgroup core code.

---
 include/linux/cgroup.h          | 2 ++
 kernel/cgroup/cgroup-internal.h | 1 -
 kernel/cgroup/cgroup.c          | 1 +
 3 files changed, 3 insertions(+), 1 deletion(-)
include/linux/cgroup.h +2 -0
index c9896027ed99..1c1758ac1a97 100644
@@ -656,6 +656,8 @@ static inline union kernfs_node_id *cgroup_get_kernfs_id(struct cgroup *cgrp)
 
 void cgroup_path_from_kernfs_id(const union kernfs_node_id *id,
 					char *buf, size_t buflen);
+bool cgroup_on_dfl(const struct cgroup *cgrp);
+
 #else /* !CONFIG_CGROUPS */
 
 struct cgroup_subsys_state;
kernel/cgroup/cgroup-internal.h +0 -1
index b928b27050c6..7338083ee3bc 100644
@@ -156,7 +156,6 @@ static inline void get_css_set(struct css_set *cset)
 }
 
 bool cgroup_ssid_enabled(int ssid);
-bool cgroup_on_dfl(const struct cgroup *cgrp);
 bool cgroup_is_thread_root(struct cgroup *cgrp);
 bool cgroup_is_threaded(struct cgroup *cgrp);
 
kernel/cgroup/cgroup.c +1 -0
index f12c32c6ec7f..6069191653f8 100644
@@ -298,6 +298,7 @@ bool cgroup_on_dfl(const struct cgroup *cgrp)
 {
 	return cgrp->root == &cgrp_dfl_root;
 }
+EXPORT_SYMBOL(cgroup_on_dfl);
 
 /* IDR wrappers which synchronize using cgroup_idr_lock */
 static int cgroup_idr_alloc(struct idr *idr, void *ptr, int start, int end,
Signature · 1 line
2.14.3
#17 lore raw

RFC PATCH 4/9 cgroup: Export task_cgroup_from_root() and cgroup_mutex for drivers

In reply to Matt Roper

Drivers that handle processes on a per-cgroup basis need to be able to lookup the cgroup that a process belongs to.

---
 include/linux/cgroup.h          | 5 ++++-
 kernel/cgroup/cgroup-internal.h | 3 ---
 kernel/cgroup/cgroup.c          | 8 +++++---
 3 files changed, 9 insertions(+), 7 deletions(-)
include/linux/cgroup.h +4 -1
index 1c1758ac1a97..1b93fb018bfc 100644
@@ -103,6 +103,8 @@ struct cgroup_subsys_state *css_tryget_online_from_dir(struct dentry *dentry,
 
 struct cgroup *cgroup_get_from_path(const char *path);
 struct cgroup *cgroup_get_from_fd(int fd);
+struct cgroup *task_cgroup_from_root(struct task_struct *task,
+				     struct cgroup_root *root);
 
 int cgroup_attach_task_all(struct task_struct *from, struct task_struct *);
 int cgroup_transfer_tasks(struct cgroup *to, struct cgroup *from);
@@ -432,7 +434,6 @@ static inline void cgroup_put(struct cgroup *cgrp)
  * as locks used during the cgroup_subsys::attach() methods.
  */
 #ifdef CONFIG_PROVE_RCU
-extern struct mutex cgroup_mutex;
 extern spinlock_t css_set_lock;
 #define task_css_set_check(task, __c)					\
 	rcu_dereference_check((task)->cgroups,				\
@@ -444,6 +445,8 @@ extern spinlock_t css_set_lock;
 	rcu_dereference((task)->cgroups)
 #endif
 
+extern struct mutex cgroup_mutex;
+
 /**
  * task_css_check - obtain css for (task, subsys) w/ extra access conds
  * @task: the target task
kernel/cgroup/cgroup-internal.h +0 -3
index 7338083ee3bc..5471f8fe8c2d 100644
@@ -99,7 +99,6 @@ struct cgroup_sb_opts {
 	bool none;
 };
 
-extern struct mutex cgroup_mutex;
 extern spinlock_t css_set_lock;
 extern struct cgroup_subsys *cgroup_subsys[];
 extern struct list_head cgroup_roots;
@@ -160,8 +159,6 @@ bool cgroup_is_thread_root(struct cgroup *cgrp);
 bool cgroup_is_threaded(struct cgroup *cgrp);
 
 struct cgroup_root *cgroup_root_from_kf(struct kernfs_root *kf_root);
-struct cgroup *task_cgroup_from_root(struct task_struct *task,
-				     struct cgroup_root *root);
 struct cgroup *cgroup_kn_lock_live(struct kernfs_node *kn, bool drain_offline);
 void cgroup_kn_unlock(struct kernfs_node *kn);
 int cgroup_path_ns_locked(struct cgroup *cgrp, char *buf, size_t buflen,
kernel/cgroup/cgroup.c +5 -3
index 6069191653f8..0a0093a36a7f 100644
@@ -69,8 +69,9 @@
  * css_set_lock protects task->cgroups pointer, the list of css_set
  * objects, and the chain of tasks off each css_set.
  *
- * These locks are exported if CONFIG_PROVE_RCU so that accessors in
- * cgroup.h can use them for lockdep annotations.
+ * cgroup_mutex is always exported so that it may be taken by non-controller
+ * drivers.  css_set_lock is exported if CONFIG_PROVE_RCU so that accessors in
+ * cgroup.h can use it for lockdep annotations.
  */
 DEFINE_MUTEX(cgroup_mutex);
 DEFINE_SPINLOCK(css_set_lock);
@@ -84,8 +85,8 @@ DEFINE_SPINLOCK(css_set_lock);
 BLOCKING_NOTIFIER_HEAD(cgroup_destroy_notifier_list);
 EXPORT_SYMBOL_GPL(cgroup_destroy_notifier_list);
 
-#ifdef CONFIG_PROVE_RCU
 EXPORT_SYMBOL_GPL(cgroup_mutex);
+#ifdef CONFIG_PROVE_RCU
 EXPORT_SYMBOL_GPL(css_set_lock);
 #endif
 
@@ -1367,6 +1368,7 @@ struct cgroup *task_cgroup_from_root(struct task_struct *task,
 	 */
 	return cset_cgroup_from_root(task_css_set(task), root);
 }
+EXPORT_SYMBOL(task_cgroup_from_root);
 
 /*
  * A task must hold cgroup_mutex to modify cgroups.
Signature · 6 lines
2.14.3

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#18 lore raw

RFC PATCH 5/9 drm: Introduce DRM_IOCTL_CGROUP_SETPARAM

In reply to Matt Roper

cgroups are a convenient mechanism for system integrators to organize processes into a logical hierarchy for system configuration purposes. cgroups can be used to control resources (memory, cpu time share, etc.) or apply other types of subsystem-specific policy (network priorty, BPF programs, etc.) to subsets of processes.

The DRM subsystem manages several concepts that would be good candidates for exposure and control via the existing cgroup hierarchy --- GPU priorities for sets of applications, limits on discrete or stolen video memories, etc. Let's add a 'setparam' ioctl to the DRM subsystem that allows a userspace tool to set parameters on a cgroup for use by a DRM driver.

DRM cgroup parameters are a (u64 param, s64 value) pair associated with a cgroup for a specific drm_device. In the future there may potentially be both driver-specific parameters as well as common parameters supported by all DRM drivers. We define parameter keys 0-0xFFFFFF as being driver-specific parameters and reserve all higher keys for DRM core use.

---
 drivers/gpu/drm/Makefile     |   1 +
 drivers/gpu/drm/drm_cgroup.c | 120 +++++++++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/drm_ioctl.c  |   5 ++
 include/drm/drm_cgroup.h     |  38 ++++++++++++++
 include/drm/drm_device.h     |   8 +++
 include/uapi/drm/drm.h       |  10 ++++
 6 files changed, 182 insertions(+)
 create mode 100644 drivers/gpu/drm/drm_cgroup.c
 create mode 100644 include/drm/drm_cgroup.h
drivers/gpu/drm/Makefile +1 -0
index dd5ae67f8e2b..351f3817bc27 100644
@@ -30,6 +30,7 @@ drm-$(CONFIG_OF) += drm_of.o
 drm-$(CONFIG_AGP) += drm_agpsupport.o
 drm-$(CONFIG_DEBUG_FS) += drm_debugfs.o drm_debugfs_crc.o
 drm-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o
+drm-$(CONFIG_CGROUPS) += drm_cgroup.o
 
 drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o drm_probe_helper.o \
 		drm_plane_helper.o drm_dp_mst_topology.o drm_atomic_helper.o \
drivers/gpu/drm/drm_cgroup.c new file +120 -0

120 lines not on this page · raw message

drivers/gpu/drm/drm_ioctl.c +5 -0
index b1e96fb68ea8..d457a012427c 100644
@@ -31,6 +31,7 @@
 #include <drm/drm_ioctl.h>
 #include <drm/drmP.h>
 #include <drm/drm_auth.h>
+#include <drm/drm_cgroup.h>
 #include "drm_legacy.h"
 #include "drm_internal.h"
 #include "drm_crtc_internal.h"
@@ -549,6 +550,10 @@ static const struct drm_ioctl_desc drm_ioctls[] = {
 	DRM_IOCTL_DEF(DRM_IOCTL_GET_CAP, drm_getcap, DRM_UNLOCKED|DRM_RENDER_ALLOW),
 	DRM_IOCTL_DEF(DRM_IOCTL_SET_CLIENT_CAP, drm_setclientcap, DRM_UNLOCKED),
 	DRM_IOCTL_DEF(DRM_IOCTL_SET_VERSION, drm_setversion, DRM_UNLOCKED | DRM_MASTER),
+#if IS_ENABLED(CONFIG_CGROUPS)
+	DRM_IOCTL_DEF(DRM_IOCTL_CGROUP_SETPARAM, drm_cgroup_setparam_ioctl,
+		      DRM_UNLOCKED|DRM_RENDER_ALLOW),
+#endif
 
 	DRM_IOCTL_DEF(DRM_IOCTL_SET_UNIQUE, drm_invalid_op, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
 	DRM_IOCTL_DEF(DRM_IOCTL_BLOCK, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
include/drm/drm_cgroup.h new file +38 -0
new file mode 100644
index 000000000000..b43b6e5b4222
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2018 Intel Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no representations
+ * about the suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#ifndef __DRM_CGROUP_H__
+
+#include <linux/cgroup.h>
+#include <drm/drm_file.h>
+
+struct drm_cgroup_funcs {
+	int (*set_param)(struct drm_device *dev,
+			 struct cgroup *cgrp,
+			 uint64_t param,
+			 int64_t val);
+};
+
+int drm_cgroup_setparam_ioctl(struct drm_device *dev, void *data,
+			      struct drm_file *file_priv);
+
+#endif
include/drm/drm_device.h +8 -0
index 7c4fa32f3fc6..6eee7bbee602 100644
@@ -18,6 +18,7 @@ struct drm_sg_mem;
 struct drm_local_map;
 struct drm_vma_offset_manager;
 struct drm_fb_helper;
+struct drm_cgroup_funcs;
 
 struct inode;
 
@@ -194,6 +195,13 @@ struct drm_device {
 	 * Set by drm_fb_helper_init() and cleared by drm_fb_helper_fini().
 	 */
 	struct drm_fb_helper *fb_helper;
+
+#ifdef CONFIG_CGROUPS
+	/**
+	 * @cgroup: Per-driver cgroup handlers.
+	 */
+	struct drm_cgroup_funcs *cgroup;
+#endif /* CONFIG_CGROUPS */
 };
 
 #endif
include/uapi/drm/drm.h +10 -0
index 6fdff5945c8a..1caa1ce446e7 100644
@@ -686,6 +686,15 @@ struct drm_set_client_cap {
 	__u64 value;
 };
 
+/** DRM_IOCTL_CGROUP_SETPARAM ioctl argument type */
+struct drm_cgroup_setparam {
+	__s32 cgroup_fd;
+	__u32 reserved;
+	__u64 param;
+	__s64 value;
+};
+#define DRM_CGROUP_MAX_DRIVER_PARAM  0xFFFFFF
+
 #define DRM_RDWR O_RDWR
 #define DRM_CLOEXEC O_CLOEXEC
 struct drm_prime_handle {
@@ -789,6 +798,7 @@ extern "C" {
 #define DRM_IOCTL_GEM_OPEN		DRM_IOWR(0x0b, struct drm_gem_open)
 #define DRM_IOCTL_GET_CAP		DRM_IOWR(0x0c, struct drm_get_cap)
 #define DRM_IOCTL_SET_CLIENT_CAP	DRM_IOW( 0x0d, struct drm_set_client_cap)
+#define DRM_IOCTL_CGROUP_SETPARAM	DRM_IOW( 0x0e, struct drm_cgroup_setparam)
 
 #define DRM_IOCTL_SET_UNIQUE		DRM_IOW( 0x10, struct drm_unique)
 #define DRM_IOCTL_AUTH_MAGIC		DRM_IOW( 0x11, struct drm_auth)
Signature · 6 lines
2.14.3

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
author
#4 lore raw

RFC PATCH 6/9 drm: Add cgroup helper library

In reply to a message not in the archive

Most DRM drivers will want to handle the CGROUP_SETPARAM ioctl by looking up a driver-specific per-cgroup data structure (or allocating a new one) and storing the supplied parameter value into the data structure (possibly after doing some checking and sanitization on the provided value). Let's provide a helper library for drivers that will take care of the details of storing per-cgroup data structures in a hashtable and destroying those structures if/when the cgroup itself is removed.

---
 drivers/gpu/drm/Makefile            |   1 +
 drivers/gpu/drm/drm_cgroup_helper.c | 244 ++++++++++++++++++++++++++++++++++++
 include/drm/drm_cgroup_helper.h     | 153 ++++++++++++++++++++++
 include/drm/drm_device.h            |   5 +
 4 files changed, 403 insertions(+)
 create mode 100644 drivers/gpu/drm/drm_cgroup_helper.c
 create mode 100644 include/drm/drm_cgroup_helper.h
drivers/gpu/drm/Makefile +1 -0
index 351f3817bc27..45cd58d66658 100644
@@ -31,6 +31,7 @@ drm-$(CONFIG_AGP) += drm_agpsupport.o
 drm-$(CONFIG_DEBUG_FS) += drm_debugfs.o drm_debugfs_crc.o
 drm-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o
 drm-$(CONFIG_CGROUPS) += drm_cgroup.o
+drm-$(CONFIG_CGROUPS) += drm_cgroup_helper.o
 
 drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o drm_probe_helper.o \
 		drm_plane_helper.o drm_dp_mst_topology.o drm_atomic_helper.o \
drivers/gpu/drm/drm_cgroup_helper.c new file +244 -0

244 lines not on this page · raw message

include/drm/drm_cgroup_helper.h new file +153 -0

153 lines not on this page · raw message

include/drm/drm_device.h +5 -0
index 6eee7bbee602..609c1528d681 100644
@@ -201,6 +201,11 @@ struct drm_device {
 	 * @cgroup: Per-driver cgroup handlers.
 	 */
 	struct drm_cgroup_funcs *cgroup;
+
+	/**
+	 * @cgrp_helper: cgroup helper handlers and data
+	 */
+	struct drm_cgroup_helper *cgroup_helper;
 #endif /* CONFIG_CGROUPS */
 };
 
Signature · 1 line
2.14.3
author
#6 lore raw

RFC PATCH 7/9 drm: Add helper to obtain cgroup of drm_file's owning process

In reply to a message not in the archive
---
 include/drm/drm_file.h | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
include/drm/drm_file.h +28 -0
index 0e0c868451a5..08855a99069c 100644
@@ -32,6 +32,7 @@
 
 #include <linux/types.h>
 #include <linux/completion.h>
+#include <linux/cgroup.h>
 
 #include <uapi/drm/drm.h>
 
@@ -378,4 +379,31 @@ void drm_event_cancel_free(struct drm_device *dev,
 void drm_send_event_locked(struct drm_device *dev, struct drm_pending_event *e);
 void drm_send_event(struct drm_device *dev, struct drm_pending_event *e);
 
+#ifdef CONFIG_CGROUPS
+/**
+ * drm_file_get_cgroup - obtain cgroup for drm_file's owning process
+ * @file_priv: DRM file
+ * @root: cgroup hierarchy to search for process in
+ *
+ * Obtains the cgroup from a specific hierarchy that the drm_file's owning
+ * process belongs to.  The cgroup may be used to set driver-specific
+ * policy (priority, vram usage, etc.).
+ */
+static inline struct cgroup *
+drm_file_get_cgroup(struct drm_file *file_priv, struct cgroup_root *root)
+{
+	struct task_struct *task = pid_task(file_priv->pid, PIDTYPE_PID);
+	struct cgroup *cgrp;
+
+	mutex_lock(&cgroup_mutex);
+	cgrp = task_cgroup_from_root(task, root);
+	mutex_unlock(&cgroup_mutex);
+
+	return cgrp;
+}
+#else
+static inline struct cgroup *
+drm_file_get_cgroup(struct drm_file *file_priv) { return NULL; }
+#endif
+
 #endif /* _DRM_FILE_H_ */
Signature · 1 line
2.14.3
author
#7 lore raw

RFC PATCH 8/9 drm/i915: Allow default context priority to be set via cgroup parameter

In reply to a message not in the archive

GPU contexts are usually created with "normal" priority as a starting point and then may be adjusted from their either via explicit methods (context_set_param) or implicit methods (boosts/penalization due to runtime behavior). Let's allow a system integrator to override this starting GPU priority for a group of processes by setting a parameter on the cgroup that these processes belong to.

---
 drivers/gpu/drm/i915/Makefile           |   1 +
 drivers/gpu/drm/i915/i915_cgroups.c     | 162 ++++++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/i915_drv.c         |   4 +
 drivers/gpu/drm/i915/i915_drv.h         |  32 +++++++
 drivers/gpu/drm/i915/i915_gem_context.c |   2 +-
 include/uapi/drm/i915_drm.h             |   9 ++
 6 files changed, 209 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/i915/i915_cgroups.c
drivers/gpu/drm/i915/Makefile +1 -0
index 3bddd8a06806..b9f00a6c1e64 100644
@@ -47,6 +47,7 @@ i915-y := i915_drv.o \
 i915-$(CONFIG_COMPAT)   += i915_ioc32.o
 i915-$(CONFIG_DEBUG_FS) += i915_debugfs.o intel_pipe_crc.o
 i915-$(CONFIG_PERF_EVENTS) += i915_pmu.o
+i915-$(CONFIG_CGROUPS)  += i915_cgroups.o
 
 # GEM code
 i915-y += i915_cmd_parser.o \
drivers/gpu/drm/i915/i915_cgroups.c new file +162 -0

162 lines not on this page · raw message

drivers/gpu/drm/i915/i915_drv.c +4 -0
index 173d0095e3b2..0a11e4b31c2f 100644
@@ -1394,6 +1394,8 @@ int i915_driver_load(struct pci_dev *pdev, const struct pci_device_id *ent)
 
 	intel_runtime_pm_put(dev_priv);
 
+	i915_cgroup_init(dev_priv);
+
 	i915_welcome_messages(dev_priv);
 
 	return 0;
@@ -1422,6 +1424,8 @@ void i915_driver_unload(struct drm_device *dev)
 
 	i915_driver_unregister(dev_priv);
 
+	i915_cgroup_shutdown(dev_priv);
+
 	if (i915_gem_suspend(dev_priv))
 		DRM_ERROR("failed to idle hardware; continuing to unload!\n");
 
drivers/gpu/drm/i915/i915_drv.h +32 -0
index 2b1d2f802c39..f3991ab847da 100644
@@ -51,6 +51,7 @@
 #include <drm/drm_gem.h>
 #include <drm/drm_auth.h>
 #include <drm/drm_cache.h>
+#include <drm/drm_cgroup_helper.h>
 
 #include "i915_params.h"
 #include "i915_reg.h"
@@ -4078,4 +4079,35 @@ static inline int intel_hws_csb_write_index(struct drm_i915_private *i915)
 		return I915_HWS_CSB_WRITE_INDEX;
 }
 
+/* i915_cgroups.c */
+#ifdef CONFIG_CGROUPS
+void i915_cgroup_init(struct drm_i915_private *dev_priv);
+void i915_cgroup_shutdown(struct drm_i915_private *dev_priv);
+int i915_cgroup_get_prio(struct drm_i915_private *dev_priv,
+			 struct drm_i915_file_private *file_priv);
+#else
+static inline void
+i915_cgroup_init(struct drm_i915_private *dev_priv) { return; }
+static inline void
+i915_cgroup_shutdown(struct drm_i915_private *dev_priv) { return; }
+
+static inline int
+i915_cgroup_get_prio(struct drm_i915_private *dev_priv,
+		     struct drm_i915_private *file_priv)
+{
+	return I915_PRIORITY_NORMAL;
+}
+#endif
+
+enum i915_cgroup_param {
+	I915_CGRP_DEF_CONTEXT_PRIORITY = 1,
+};
+
+/* Driver-specific per-cgroup parameters to track */
+struct i915_cgroup_data {
+	struct drm_cgroup_helper_data base;
+
+	int priority;
+};
+
 #endif
drivers/gpu/drm/i915/i915_gem_context.c +1 -1
index 648e7536ff51..ee30f90ae5b2 100644
@@ -274,7 +274,7 @@ __create_hw_context(struct drm_i915_private *dev_priv,
 	kref_init(&ctx->ref);
 	list_add_tail(&ctx->link, &dev_priv->contexts.list);
 	ctx->i915 = dev_priv;
-	ctx->priority = I915_PRIORITY_NORMAL;
+	ctx->priority = i915_cgroup_get_prio(dev_priv, file_priv);
 
 	INIT_RADIX_TREE(&ctx->handles_vma, GFP_KERNEL);
 	INIT_LIST_HEAD(&ctx->handles_list);
include/uapi/drm/i915_drm.h +9 -0
index 536ee4febd74..07cab6eefaba 100644
@@ -1613,6 +1613,15 @@ struct drm_i915_perf_oa_config {
 	__u64 flex_regs_ptr;
 };
 
+/**
+ * Structure to supply driver-specific cgroup parameters
+ */
+struct drm_i915_cgroup_param {
+	__u32 cgroup_fd;
+	__u64 param;
+	__u64 value;
+};
+
 #if defined(__cplusplus)
 }
 #endif
Signature · 1 line
2.14.3
author
#15 lore raw

RFC PATCH 9/9 drm/i915: Add context priority to debugfs

In reply to a message not in the archive

Update i915_context_status to include priority.

---
 drivers/gpu/drm/i915/i915_debugfs.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/i915/i915_debugfs.c +2 -0
index cc659b4b2a45..075b269ac63b 100644
@@ -1915,6 +1915,8 @@ static int i915_context_status(struct seq_file *m, void *unused)
 		seq_putc(m, ctx->remap_slice ? 'R' : 'r');
 		seq_putc(m, '\n');
 
+		seq_printf(m, "Priority %d\n", ctx->priority);
+
 		for_each_engine(engine, dev_priv, id) {
 			struct intel_context *ce = &ctx->engine[engine->id];
 
Signature · 1 line
2.14.3
#19 lore raw

✗ Fi.CI.BAT: warning for DRM management via cgroups

In reply to Matt Roper
== Series Details ==

== Series Details ==

Series: DRM management via cgroups
URL : https://patchwork.freedesktop.org/series/36837/
State : warning

== Summary ==

Series 36837v1 DRM management via cgroups
https://patchwork.freedesktop.org/api/1.0/series/36837/revisions/1/mbox/

Test core_auth:

        Subgroup basic-auth:
                pass       -> DMESG-WARN (fi-gdg-551)
                pass       -> DMESG-WARN (fi-blb-e6850)
                pass       -> DMESG-WARN (fi-pnv-d510)
                pass       -> DMESG-WARN (fi-bwr-2160)
                pass       -> DMESG-WARN (fi-elk-e7500)
                pass       -> DMESG-WARN (fi-ilk-650)
                pass       -> DMESG-WARN (fi-snb-2520m)
                pass       -> DMESG-WARN (fi-snb-2600)
                pass       -> DMESG-WARN (fi-ivb-3520m)
                pass       -> DMESG-WARN (fi-ivb-3770)
                pass       -> DMESG-WARN (fi-byt-j1900)
                pass       -> DMESG-WARN (fi-byt-n2820)
                pass       -> DMESG-WARN (fi-hsw-4770)
                pass       -> DMESG-WARN (fi-hsw-4770r)
                pass       -> DMESG-WARN (fi-bdw-5557u)
                pass       -> DMESG-WARN (fi-bdw-gvtdvm)
                pass       -> DMESG-WARN (fi-bsw-n3050)
                pass       -> DMESG-WARN (fi-skl-6260u)
                pass       -> DMESG-WARN (fi-skl-6600u)
                pass       -> DMESG-WARN (fi-skl-6700hq)
                pass       -> DMESG-WARN (fi-skl-6700k2)
                pass       -> DMESG-WARN (fi-skl-6770hq)
                pass       -> DMESG-WARN (fi-skl-gvtdvm)
                pass       -> DMESG-WARN (fi-bxt-dsi)
                pass       -> DMESG-WARN (fi-bxt-j4205)
                pass       -> DMESG-WARN (fi-kbl-7500u)
                pass       -> DMESG-WARN (fi-kbl-7560u)
                pass       -> DMESG-WARN (fi-kbl-7567u)
                pass       -> DMESG-WARN (fi-kbl-r)
                pass       -> DMESG-WARN (fi-glk-1)
Test core_prop_blob:
        Subgroup basic:
                pass       -> DMESG-WARN (fi-gdg-551)
                pass       -> DMESG-WARN (fi-blb-e6850)
                pass       -> DMESG-WARN (fi-pnv-d510)
                pass       -> DMESG-WARN (fi-bwr-2160)
                pass       -> DMESG-WARN (fi-elk-e7500)
                pass       -> DMESG-WARN (fi-ilk-650)
                pass       -> DMESG-WARN (fi-snb-2520m)
                pass       -> DMESG-WARN (fi-snb-2600)
                pass       -> DMESG-WARN (fi-ivb-3520m)
                pass       -> DMESG-WARN (fi-ivb-3770)
                pass       -> DMESG-WARN (fi-byt-j1900)
                pass       -> DMESG-WARN (fi-byt-n2820)
                pass       -> DMESG-WARN (fi-hsw-4770)
                pass       -> DMESG-WARN (fi-hsw-4770r)
                pass       -> DMESG-WARN (fi-bdw-5557u)
                pass       -> DMESG-WARN (fi-bdw-gvtdvm)
                pass       -> DMESG-WARN (fi-bsw-n3050)
                pass       -> DMESG-WARN (fi-skl-6260u)
                pass       -> DMESG-WARN (fi-skl-6600u)
                pass       -> DMESG-WARN (fi-skl-6700hq)
                pass       -> DMESG-WARN (fi-skl-6700k2)
                pass       -> DMESG-WARN (fi-skl-6770hq)
                pass       -> DMESG-WARN (fi-skl-gvtdvm)
                pass       -> DMESG-WARN (fi-bxt-dsi)
                pass       -> DMESG-WARN (fi-bxt-j4205)
                pass       -> DMESG-WARN (fi-kbl-7500u)
                pass       -> DMESG-WARN (fi-kbl-7560u)
                pass       -> DMESG-WARN (fi-kbl-7567u)
                pass       -> DMESG-WARN (fi-kbl-r)
                pass       -> DMESG-WARN (fi-glk-1)
Test debugfs_test:
        Subgroup read_all_entries:
                pass       -> DMESG-WARN (fi-gdg-551)
                pass       -> DMESG-WARN (fi-blb-e6850)
                pass       -> DMESG-WARN (fi-pnv-d510)
                pass       -> DMESG-WARN (fi-bwr-2160)
                pass       -> DMESG-WARN (fi-elk-e7500) fdo#103989 +7
                pass       -> DMESG-WARN (fi-ilk-650)
                pass       -> INCOMPLETE (fi-snb-2520m) fdo#103713
                pass       -> DMESG-WARN (fi-snb-2600)
                pass       -> DMESG-WARN (fi-ivb-3520m)
                pass       -> DMESG-WARN (fi-ivb-3770)
                pass       -> DMESG-WARN (fi-byt-j1900)
                pass       -> DMESG-WARN (fi-byt-n2820)
                pass       -> DMESG-WARN (fi-hsw-4770)
                pass       -> DMESG-WARN (fi-hsw-4770r)
                pass       -> DMESG-WARN (fi-bdw-5557u)
                pass       -> DMESG-WARN (fi-bdw-gvtdvm) fdo#103938 +1
                pass       -> DMESG-WARN (fi-bsw-n3050)
                pass       -> DMESG-WARN (fi-skl-6260u)
                pass       -> DMESG-WARN (fi-skl-6600u)
                pass       -> DMESG-WARN (fi-skl-6700hq)
                pass       -> DMESG-WARN (fi-skl-6700k2)
                pass       -> DMESG-WARN (fi-skl-6770hq)
                pass       -> DMESG-WARN (fi-skl-gvtdvm)
                pass       -> DMESG-WARN (fi-bxt-dsi)
                pass       -> DMESG-WARN (fi-bxt-j4205)
                pass       -> DMESG-WARN (fi-kbl-7500u)
                pass       -> DMESG-WARN (fi-kbl-7560u)
                pass       -> DMESG-WARN (fi-kbl-7567u)
                pass       -> DMESG-WARN (fi-kbl-r)
                pass       -> DMESG-WARN (fi-glk-1)

Test drv_getparams_basic:
WARNING: Long output truncated

c2ce7a59fe93cae48eec312bb5a80bcd05455f76 drm-tip: 2018y-01m-20d-00h-46m-27s UTC integration manifest 19a7a8ea78f7 drm/i915: Add context priority to debugfs
486d685bc2f6 drm/i915: Allow default context priority to be set via cgroup parameter 7c36e783c3ec drm: Add helper to obtain cgroup of drm_file's owning process 58a0e69c398c drm: Add cgroup helper library
eb89f3c4a656 drm: Introduce DRM_IOCTL_CGROUP_SETPARAM
1ec4ba5f54b4 cgroup: Export task_cgroup_from_root() and cgroup_mutex for drivers 4ac713bf6041 cgroup: Export cgroup_on_dfl() to drivers
7b8b9500a18b cgroup: Add notifier call chain for cgroup destruction
6f90bb167936 kernfs: Export kernfs_get_inode

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_7730/issues.html
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#9 lore raw

Re: [PATCH RFC 8/9] drm/i915: Allow default context priority to be set via cgroup parameter

In reply to a message not in the archive

Quoting Matt Roper (2018-01-20 01:51:40)

Quoted 5 lines

GPU contexts are usually created with "normal" priority as a starting point and then may be adjusted from their either via explicit methods (context_set_param) or implicit methods (boosts/penalization due to runtime behavior). Let's allow a system integrator to override this starting GPU priority for a group of processes by setting a parameter on the cgroup that these processes belong to.

You are still allowing a process to undo the cgroup by changing its own priority. What you want I think is a priority-offset or somesuch. -Chris

#11 lore raw

Re: [PATCH RFC 8/9] drm/i915: Allow default context priority to be set via cgroup parameter

In reply to a message not in the archive

Quoting Chris Wilson (2018-01-20 09:36:10)

Quoted 9 lines

Quoting Matt Roper (2018-01-20 01:51:40)

Quoted 5 lines

GPU contexts are usually created with "normal" priority as a starting point and then may be adjusted from their either via explicit methods (context_set_param) or implicit methods (boosts/penalization due to runtime behavior). Let's allow a system integrator to override this starting GPU priority for a group of processes by setting a parameter on the cgroup that these processes belong to.

You are still allowing a process to undo the cgroup by changing its own priority. What you want I think is a priority-offset or somesuch.

Along this vein, it's worthwhile pointing out that the current scheduler is not even close to being the cgroup-enabled CFS implementation it needs to be to call itself a scheduler. (It's more or less a no-op scheduler.) It may be premature to start exposing hooks into it. -Chris

#12 lore raw

Re: [PATCH RFC 8/9] drm/i915: Allow default context priority to be set via cgroup parameter

Quoted 5 lines · Chris Wilson

Along this vein, it's worthwhile pointing out that the current scheduler is not even close to being the cgroup-enabled CFS implementation it needs to be to call itself a scheduler. (It's more or less a no-op scheduler.) It may be premature to start exposing hooks into it.

Sounds like it may not be too late to abandon the separate i915 scheduler in favour of the common one used by amdgpu and etnaviv?

Signature · 6 lines
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#13 lore raw

Re: [PATCH RFC 8/9] drm/i915: Allow default context priority to be set via cgroup parameter

Quoting Michel Dänzer (2018-01-22 09:50:38)

Quoted 9 lines · Chris Wilson
Quoted 5 lines

Along this vein, it's worthwhile pointing out that the current scheduler is not even close to being the cgroup-enabled CFS implementation it needs to be to call itself a scheduler. (It's more or less a no-op scheduler.) It may be premature to start exposing hooks into it.

Sounds like it may not be too late to abandon the separate i915 scheduler in favour of the common one used by amdgpu and etnaviv?

Why? It doesn't do anything of the sort either. It has a lot of code to achieve less.
-Chris
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#20 lore raw

PATCH 1/1 tests: Add drm_set_cgrp_param

In reply to Matt Roper

drm_set_cgrp_param is a simple tool to set DRM parameters associated with a cgroup. It is intended to be called at system initialization time (e.g., from a sysv-init script or systemd service) to configure graphics policy and resource management according to the wishes of the system integrator.

---
 configure.ac                                  |  1 +
 tests/Makefile.am                             |  2 +-
 tests/drm_set_cgrp_param/Makefile.am          | 18 ++++++
 tests/drm_set_cgrp_param/drm_set_cgrp_param.c | 80 +++++++++++++++++++++++++++
 4 files changed, 100 insertions(+), 1 deletion(-)
 create mode 100644 tests/drm_set_cgrp_param/Makefile.am
 create mode 100644 tests/drm_set_cgrp_param/drm_set_cgrp_param.c
configure.ac +1 -0
index 35378b3384..9b5f340e2a 100644
@@ -567,6 +567,7 @@ AC_CONFIG_FILES([
 	tests/nouveau/Makefile
 	tests/etnaviv/Makefile
 	tests/util/Makefile
+	tests/drm_set_cgrp_param/Makefile
 	man/Makefile
 	libdrm.pc])
 AC_OUTPUT
tests/Makefile.am +1 -1
index 0355a9255f..d77a8639c8 100644
@@ -1,4 +1,4 @@
-SUBDIRS = util kms modeprint proptest modetest vbltest
+SUBDIRS = util kms modeprint proptest modetest vbltest drm_set_cgrp_param
 
 if HAVE_LIBKMS
 SUBDIRS += kmstest
tests/drm_set_cgrp_param/Makefile.am new file +18 -0
new file mode 100644
index 0000000000..c32ec1c440
@@ -0,0 +1,18 @@
+AM_CFLAGS = \
+	$(WARN_CFLAGS)\
+	-I$(top_srcdir)/include/drm \
+	-I$(top_srcdir)/tests \
+	-I$(top_srcdir)
+
+if HAVE_INSTALL_TESTS
+bin_PROGRAMS = \
+	drm_set_cgrp_param
+else
+noinst_PROGRAMS = \
+	drm_set_cgrp_param
+endif
+
+drm_set_cgrp_param_SOURCES = \
+	drm_set_cgrp_param.c
+drm_set_cgrp_param_LDADD = \
+	$(top_builddir)/libdrm.la
tests/drm_set_cgrp_param/drm_set_cgrp_param.c new file +80 -0

80 lines not on this page · raw message

Signature · 6 lines
2.14.3

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#14 lore raw

Re: [PATCH RFC 8/9] drm/i915: Allow default context priority to be set via cgroup parameter

In reply to Chris Wilson
Quoted 8 lines · Chris Wilson

Quoting Chris Wilson (2018-01-20 09:36:10)

Quoted 7 lines

Quoting Matt Roper (2018-01-20 01:51:40)

Quoted 5 lines

GPU contexts are usually created with "normal" priority as a starting point and then may be adjusted from their either via explicit methods (context_set_param) or implicit methods (boosts/penalization due to runtime behavior). Let's allow a system integrator to override this starting GPU priority for a group of processes by setting a parameter on the cgroup that these processes belong to.

Quoted 8 lines
Quoted 2 lines

You are still allowing a process to undo the cgroup by changing its own priority. What you want I think is a priority-offset or somesuch.

Along this vein, it's worthwhile pointing out that the current scheduler is not even close to being the cgroup-enabled CFS implementation it needs to be to call itself a scheduler. (It's more or less a no-op scheduler.) It may be premature to start exposing hooks into it. -Chris

I think that probably depends a bit on what you need from a "scheduler." The current i915 scheduler isn't fair (i.e., it allows higher priority processes to potentially starve out lower priority processes), but that winds up being exactly what we want in a lot of embedded use cases where the higher priority apps truly need absolute precedence over lower priority. Granted, in those kind of settings the higher priority apps tend to be curated, so there's already a reasonable expectation that they're well-behaved and won't overcommit the system.

The suggestion of switching the cgroup to give a priority offset vs a priority starting point is a good suggestion though; thanks!

Matt

Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe cgroups" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 9 lines
Matt Roper
Graphics Software Engineer
IoTG Platform Enabling & Development
Intel Corporation
(916) 356-2795
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
maintainer
#5 lore raw

Re: [PATCH RFC 6/9] drm: Add cgroup helper library

In reply to Matt Roper

Hello, Matt.

Quoted 7 lines · Matt Roper

Most DRM drivers will want to handle the CGROUP_SETPARAM ioctl by looking up a driver-specific per-cgroup data structure (or allocating a new one) and storing the supplied parameter value into the data structure (possibly after doing some checking and sanitization on the provided value). Let's provide a helper library for drivers that will take care of the details of storing per-cgroup data structures in a hashtable and destroying those structures if/when the cgroup itself is removed.

Would it be possible to make the core of this a built-in part of cgroup like cgroup-bpf does? My gut feeling is that that isn't gonna be much code anyway and likely to be cleaner to implement and use.

Being a full-fledged controller comes with quite a bit of complexity in terms of sync rules and everything, and we may build a simpler modular infrastructure if usages like this proliferate but for now extending from the core seems the most straight forward.

Thanks.

Signature · 5 lines
tejun
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#21 lore raw

Re: [PATCH libdrm] tests: Add drm_set_cgrp_param

In reply to Matt Roper
Quoted 6 lines · Matt Roper

drm_set_cgrp_param is a simple tool to set DRM parameters associated with a cgroup. It is intended to be called at system initialization time (e.g., from a sysv-init script or systemd service) to configure graphics policy and resource management according to the wishes of the system integrator.

Quoted 9 lines
---
 configure.ac                                  |  1 +
 tests/Makefile.am                             |  2 +-
 tests/drm_set_cgrp_param/Makefile.am          | 18 ++++++
 tests/drm_set_cgrp_param/drm_set_cgrp_param.c | 80 +++++++++++++++++++++++++++
 4 files changed, 100 insertions(+), 1 deletion(-)
 create mode 100644 tests/drm_set_cgrp_param/Makefile.am
 create mode 100644 tests/drm_set_cgrp_param/drm_set_cgrp_param.c

Hi Matt,

Adding a small test/demo in libdrm sounds good. Although I think we need some IGT tests, if you haven't prepped them already. After all we need to ensure the kernel correctly validates and errors when we feed it the wrong info through the IOCTL.

There's a small suggestions about the IOCTL design. s/reserved/flags/ to make future extension are possible - as mentioned in [2]

Thanks
Emil

[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/ioctl/botching-up-ioctls.txt?h=v4.15-rc9#n64
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#22 lore raw

Re: [Intel-gfx] [PATCH libdrm] tests: Add drm_set_cgrp_param

Quoted 16 lines · Emil Velikov
Quoted 6 lines · Matt Roper

drm_set_cgrp_param is a simple tool to set DRM parameters associated with a cgroup. It is intended to be called at system initialization time (e.g., from a sysv-init script or systemd service) to configure graphics policy and resource management according to the wishes of the system integrator.

Quoted 9 lines
---
 configure.ac                                  |  1 +
 tests/Makefile.am                             |  2 +-
 tests/drm_set_cgrp_param/Makefile.am          | 18 ++++++
 tests/drm_set_cgrp_param/drm_set_cgrp_param.c | 80 +++++++++++++++++++++++++++
 4 files changed, 100 insertions(+), 1 deletion(-)
 create mode 100644 tests/drm_set_cgrp_param/Makefile.am
 create mode 100644 tests/drm_set_cgrp_param/drm_set_cgrp_param.c
Quoted 6 lines

Hi Matt,

Adding a small test/demo in libdrm sounds good. Although I think we need some IGT tests, if you haven't prepped them already. After all we need to ensure the kernel correctly validates and errors when we feed it the wrong info through the IOCTL.

Yeah, agreed. Writing real IGT's was in the TODO list of the cover-letter for my kernel patch series. This kernel work is still a pretty early RFC just to gather feedback on the general approach of integrating cgroups with DRM; I figured I'd wait on writing real IGT's until we're more confident that this is the right approach in general.

I'm working on a v2 right now that makes some pretty significant changes to the series, but I'm not sure yet whether the uapi will change in my next iteration or not.

Quoted 2 lines

There's a small suggestions about the IOCTL design. s/reserved/flags/ to make future extension are possible - as mentioned in [2]

Yeah, that's why I added the reserved field; we don't have any actual flags yet, but as soon as we do we'd rename the field to flags and document it accordingly. I can rename the field immediately if you think that's easier. I think the most important thing that's missing at the moment is that the kernel patches forgot to check that the reserved field is actually empty (i.e., we should reject calls with any garbage in there now so that we don't break ABI in the future when we start really using those bits for something).

Thanks for the feedback!

Matt

Quoted 5 lines

Thanks
Emil

[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/ioctl/botching-up-ioctls.txt?h=v4.15-rc9#n64

Signature · 9 lines
Matt Roper
Graphics Software Engineer
IoTG Platform Enabling & Development
Intel Corporation
(916) 356-2795
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#23 lore raw

Re: [PATCH libdrm] tests: Add drm_set_cgrp_param

Quoted 30 lines · Matt Roper
Quoted 16 lines · Emil Velikov
Quoted 6 lines · Matt Roper

drm_set_cgrp_param is a simple tool to set DRM parameters associated with a cgroup. It is intended to be called at system initialization time (e.g., from a sysv-init script or systemd service) to configure graphics policy and resource management according to the wishes of the system integrator.

Quoted 9 lines
---
 configure.ac                                  |  1 +
 tests/Makefile.am                             |  2 +-
 tests/drm_set_cgrp_param/Makefile.am          | 18 ++++++
 tests/drm_set_cgrp_param/drm_set_cgrp_param.c | 80 +++++++++++++++++++++++++++
 4 files changed, 100 insertions(+), 1 deletion(-)
 create mode 100644 tests/drm_set_cgrp_param/Makefile.am
 create mode 100644 tests/drm_set_cgrp_param/drm_set_cgrp_param.c
Quoted 6 lines

Hi Matt,

Adding a small test/demo in libdrm sounds good. Although I think we need some IGT tests, if you haven't prepped them already. After all we need to ensure the kernel correctly validates and errors when we feed it the wrong info through the IOCTL.

Yeah, agreed. Writing real IGT's was in the TODO list of the cover-letter for my kernel patch series. This kernel work is still a pretty early RFC just to gather feedback on the general approach of integrating cgroups with DRM; I figured I'd wait on writing real IGT's until we're more confident that this is the right approach in general.

Quoted 4 lines

I'm working on a v2 right now that makes some pretty significant changes to the series, but I'm not sure yet whether the uapi will change in my next iteration or not.

Good call - have an agreement about the interface and usage first. Then iron out all the fiddly bits.

Quoted 12 lines
Quoted 2 lines

There's a small suggestions about the IOCTL design. s/reserved/flags/ to make future extension are possible - as mentioned in [2]

Yeah, that's why I added the reserved field; we don't have any actual flags yet, but as soon as we do we'd rename the field to flags and document it accordingly. I can rename the field immediately if you think that's easier. I think the most important thing that's missing at the moment is that the kernel patches forgot to check that the reserved field is actually empty (i.e., we should reject calls with any garbage in there now so that we don't break ABI in the future when we start really using those bits for something).

Please rename it now. Otherwise we'll get a build break for new kernel and old userspace.
And yes, validating (returning -EINVAL IIRC) the flags is a must.

Thanks
Emil
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx