All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH RFC 0/9] DRM management via cgroups
@ 2018-01-20  1:51 Matt Roper
  2018-01-20  1:51 ` [PATCH RFC 2/9] cgroup: Add notifier call chain for cgroup destruction Matt Roper
                   ` (5 more replies)
  0 siblings, 6 replies; 22+ messages in thread
From: Matt Roper @ 2018-01-20  1:51 UTC (permalink / raw)
  To: dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	intel-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	cgroups-u79uwXL29TY76Z2rM5mHXA
  Cc: Matt Roper

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

-- 
2.14.3

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH RFC 1/9] kernfs: Export kernfs_get_inode
       [not found] ` <20180120015141.10118-1-matthew.d.roper-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
@ 2018-01-20  1:51   ` Matt Roper
  2018-01-20  1:51   ` [PATCH RFC 3/9] cgroup: Export cgroup_on_dfl() to drivers Matt Roper
                     ` (4 subsequent siblings)
  5 siblings, 0 replies; 22+ messages in thread
From: Matt Roper @ 2018-01-20  1:51 UTC (permalink / raw)
  To: dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	intel-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	cgroups-u79uwXL29TY76Z2rM5mHXA
  Cc: Matt Roper, Tejun Heo

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

Cc: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Signed-off-by: Matt Roper <matthew.d.roper-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
---
 fs/kernfs/inode.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/fs/kernfs/inode.c b/fs/kernfs/inode.c
index a34303981deb..e1e8a0404c5b 100644
--- a/fs/kernfs/inode.c
+++ b/fs/kernfs/inode.c
@@ -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
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH RFC 2/9] cgroup: Add notifier call chain for cgroup destruction
  2018-01-20  1:51 [PATCH RFC 0/9] DRM management via cgroups Matt Roper
@ 2018-01-20  1:51 ` Matt Roper
  2018-01-20  1:51 ` [PATCH RFC 4/9] cgroup: Export task_cgroup_from_root() and cgroup_mutex for drivers Matt Roper
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 22+ messages in thread
From: Matt Roper @ 2018-01-20  1:51 UTC (permalink / raw)
  To: dri-devel, intel-gfx, cgroups; +Cc: Tejun Heo

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.

Cc: Tejun Heo <tj@kernel.org>
Cc: cgroups@vger.kernel.org
Signed-off-by: Matt Roper <matthew.d.roper@intel.com>
---
 include/linux/cgroup.h |  3 +++
 kernel/cgroup/cgroup.c | 18 ++++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index 473e0c0abb86..c9896027ed99 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -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;
diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index 2cf06c274e4c..f12c32c6ec7f 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -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.
-- 
2.14.3

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH RFC 3/9] cgroup: Export cgroup_on_dfl() to drivers
       [not found] ` <20180120015141.10118-1-matthew.d.roper-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
  2018-01-20  1:51   ` [PATCH RFC 1/9] kernfs: Export kernfs_get_inode Matt Roper
@ 2018-01-20  1:51   ` Matt Roper
  2018-01-20  1:51   ` [PATCH RFC 6/9] drm: Add cgroup helper library Matt Roper
                     ` (3 subsequent siblings)
  5 siblings, 0 replies; 22+ messages in thread
From: Matt Roper @ 2018-01-20  1:51 UTC (permalink / raw)
  To: dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	intel-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	cgroups-u79uwXL29TY76Z2rM5mHXA
  Cc: Matt Roper, Tejun Heo

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.

Cc: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Signed-off-by: Matt Roper <matthew.d.roper-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
---
 include/linux/cgroup.h          | 2 ++
 kernel/cgroup/cgroup-internal.h | 1 -
 kernel/cgroup/cgroup.c          | 1 +
 3 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index c9896027ed99..1c1758ac1a97 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -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;
diff --git a/kernel/cgroup/cgroup-internal.h b/kernel/cgroup/cgroup-internal.h
index b928b27050c6..7338083ee3bc 100644
--- a/kernel/cgroup/cgroup-internal.h
+++ b/kernel/cgroup/cgroup-internal.h
@@ -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);
 
diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index f12c32c6ec7f..6069191653f8 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -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,
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH RFC 4/9] cgroup: Export task_cgroup_from_root() and cgroup_mutex for drivers
  2018-01-20  1:51 [PATCH RFC 0/9] DRM management via cgroups Matt Roper
  2018-01-20  1:51 ` [PATCH RFC 2/9] cgroup: Add notifier call chain for cgroup destruction Matt Roper
@ 2018-01-20  1:51 ` Matt Roper
  2018-01-20  1:51 ` [PATCH RFC 5/9] drm: Introduce DRM_IOCTL_CGROUP_SETPARAM Matt Roper
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 22+ messages in thread
From: Matt Roper @ 2018-01-20  1:51 UTC (permalink / raw)
  To: dri-devel, intel-gfx, cgroups; +Cc: Tejun Heo

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

Cc: Tejun Heo <tj@kernel.org>
Cc: cgroups@vger.kernel.org
Signed-off-by: Matt Roper <matthew.d.roper@intel.com>
---
 include/linux/cgroup.h          | 5 ++++-
 kernel/cgroup/cgroup-internal.h | 3 ---
 kernel/cgroup/cgroup.c          | 8 +++++---
 3 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index 1c1758ac1a97..1b93fb018bfc 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -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
diff --git a/kernel/cgroup/cgroup-internal.h b/kernel/cgroup/cgroup-internal.h
index 7338083ee3bc..5471f8fe8c2d 100644
--- a/kernel/cgroup/cgroup-internal.h
+++ b/kernel/cgroup/cgroup-internal.h
@@ -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,
diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index 6069191653f8..0a0093a36a7f 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -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.
-- 
2.14.3

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH RFC 5/9] drm: Introduce DRM_IOCTL_CGROUP_SETPARAM
  2018-01-20  1:51 [PATCH RFC 0/9] DRM management via cgroups Matt Roper
  2018-01-20  1:51 ` [PATCH RFC 2/9] cgroup: Add notifier call chain for cgroup destruction Matt Roper
  2018-01-20  1:51 ` [PATCH RFC 4/9] cgroup: Export task_cgroup_from_root() and cgroup_mutex for drivers Matt Roper
@ 2018-01-20  1:51 ` Matt Roper
       [not found] ` <20180120015141.10118-1-matthew.d.roper-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 22+ messages in thread
From: Matt Roper @ 2018-01-20  1:51 UTC (permalink / raw)
  To: dri-devel, intel-gfx, cgroups; +Cc: Tejun Heo

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.

Cc: Tejun Heo <tj@kernel.org>
Cc: cgroups@vger.kernel.org
Signed-off-by: Matt Roper <matthew.d.roper@intel.com>
---
 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

diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index dd5ae67f8e2b..351f3817bc27 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -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 \
diff --git a/drivers/gpu/drm/drm_cgroup.c b/drivers/gpu/drm/drm_cgroup.c
new file mode 100644
index 000000000000..0d9187ee435d
--- /dev/null
+++ b/drivers/gpu/drm/drm_cgroup.c
@@ -0,0 +1,120 @@
+/*
+ * 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.
+ */
+
+#include <drm/drmP.h>
+#include <drm/drm_cgroup.h>
+
+/**
+ * DOC: cgroup handling
+ *
+ * cgroups are a core kernel mechanism for organizing OS processes into logical
+ * groupings to which policy configuration or resource management may be
+ * applied.  Some DRM drivers may control resources or have policy settings
+ * that a system integrator would wish to configure according to the system
+ * cgroups hierarchy.  To support such use cases, the DRM framework allows
+ * drivers to track 'parameters' on a per-cgroup basis.  Parameters are a (u64
+ * key, s64 value) pair which would generally be set on specific cgroups
+ * during system configuration (e.g., by a sysv init script or systemd service)
+ * and then used by the driver at runtime to manage GPU-specific resources or
+ * control driver-specific policy.
+ */
+
+/**
+ * drm_cgroup_setparam_ioctl
+ * @dev: DRM device
+ * @data: data pointer for the ioctl
+ * @file_priv: DRM file handle for the ioctl call
+ *
+ * Set DRM-specific parameters for a cgroup
+ */
+int
+drm_cgroup_setparam_ioctl(struct drm_device *dev, void *data,
+			  struct drm_file *file_priv)
+{
+	struct drm_cgroup_setparam *req = data;
+	struct cgroup *cgrp;
+	struct file *f;
+	struct inode *inode = NULL;
+	int ret;
+
+	/*
+	 * We'll let drivers create their own parameters with ID's from
+	 * 0-0xFFFFFF.  We'll reserve parameter ID's above that range for
+	 * anything the DRM core wants to control directly; today we don't
+	 * have any such core-managed parameters, so just reject attempts
+	 * to set a cgroup parameter in this range.
+	 */
+	if (req->param > DRM_CGROUP_MAX_DRIVER_PARAM) {
+		DRM_DEBUG("Invalid cgroup parameter ID\n");
+		return -EINVAL;
+	}
+
+	if (!dev->cgroup) {
+		DRM_DEBUG("Invalid cgroup parameter ID\n");
+		return -EINVAL;
+	}
+
+	/* Make sure the file descriptor really is a cgroup fd */
+	cgrp = cgroup_get_from_fd(req->cgroup_fd);
+	if (IS_ERR(cgrp)) {
+		DRM_DEBUG("Invalid cgroup file descriptor\n");
+		return PTR_ERR(cgrp);
+	}
+
+	/*
+	 * Restrict this functionality to cgroups on the cgroups-v2
+	 * (i.e., default) hierarchy.
+	 */
+	if (!cgroup_on_dfl(cgrp)) {
+		DRM_DEBUG("setparam only supported on cgroup-v2 hierarchy\n");
+		return -EINVAL;
+	}
+
+	/*
+	 * Access control:  The strategy for using cgroups in a given
+	 * environment is generally determined by the system integrator
+	 * and/or OS vendor, so the specific policy about who can/can't
+	 * manipulate them tends to be domain-specific (and may vary
+	 * depending on the location in the cgroup hierarchy).  Rather than
+	 * trying to tie permission on this ioctl to a DRM-specific concepts
+	 * like DRM master, we'll allow cgroup parameters to be set by any
+	 * process that has been granted write access on the cgroup's
+	 * virtual file system (i.e., the same permissions that would
+	 * generally be needed to update the virtual files provided by
+	 * cgroup controllers).
+	 */
+	f = fget_raw(req->cgroup_fd);
+	if (WARN_ON(!f))
+		return -EBADF;
+
+	inode = kernfs_get_inode(f->f_path.dentry->d_sb, cgrp->kn);
+	if (inode)
+		ret = inode_permission(inode, MAY_WRITE);
+	else
+		ret = -ENOMEM;
+
+	iput(inode);
+	fput(f);
+
+	return ret ?: dev->cgroup->set_param(dev, cgrp, req->param,
+					     req->value);
+}
diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
index b1e96fb68ea8..d457a012427c 100644
--- a/drivers/gpu/drm/drm_ioctl.c
+++ b/drivers/gpu/drm/drm_ioctl.c
@@ -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),
diff --git a/include/drm/drm_cgroup.h b/include/drm/drm_cgroup.h
new file mode 100644
index 000000000000..b43b6e5b4222
--- /dev/null
+++ b/include/drm/drm_cgroup.h
@@ -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
diff --git a/include/drm/drm_device.h b/include/drm/drm_device.h
index 7c4fa32f3fc6..6eee7bbee602 100644
--- a/include/drm/drm_device.h
+++ b/include/drm/drm_device.h
@@ -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
diff --git a/include/uapi/drm/drm.h b/include/uapi/drm/drm.h
index 6fdff5945c8a..1caa1ce446e7 100644
--- a/include/uapi/drm/drm.h
+++ b/include/uapi/drm/drm.h
@@ -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)
-- 
2.14.3

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH RFC 6/9] drm: Add cgroup helper library
       [not found] ` <20180120015141.10118-1-matthew.d.roper-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
  2018-01-20  1:51   ` [PATCH RFC 1/9] kernfs: Export kernfs_get_inode Matt Roper
  2018-01-20  1:51   ` [PATCH RFC 3/9] cgroup: Export cgroup_on_dfl() to drivers Matt Roper
@ 2018-01-20  1:51   ` Matt Roper
  2018-01-22 16:24     ` Tejun Heo
  2018-01-20  1:51   ` [PATCH RFC 7/9] drm: Add helper to obtain cgroup of drm_file's owning process Matt Roper
                     ` (2 subsequent siblings)
  5 siblings, 1 reply; 22+ messages in thread
From: Matt Roper @ 2018-01-20  1:51 UTC (permalink / raw)
  To: dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	intel-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	cgroups-u79uwXL29TY76Z2rM5mHXA
  Cc: Matt Roper, Tejun Heo

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.

Cc: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Signed-off-by: Matt Roper <matthew.d.roper-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
---
 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

diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index 351f3817bc27..45cd58d66658 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -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 \
diff --git a/drivers/gpu/drm/drm_cgroup_helper.c b/drivers/gpu/drm/drm_cgroup_helper.c
new file mode 100644
index 000000000000..b62843456f63
--- /dev/null
+++ b/drivers/gpu/drm/drm_cgroup_helper.c
@@ -0,0 +1,244 @@
+/*
+ * 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.
+ */
+
+#include <drm/drmP.h>
+#include <drm/drm_cgroup_helper.h>
+
+/**
+ * DOC: cgroup helper library
+ *
+ * This helper library provides implementations for the DRM cgroup parameter
+ * entry points.  Most drivers will wish to store driver-specific data
+ * associated with individual cgroups; this helper will manage the storage
+ * and lookup of these data structures and will ensure that they are properly
+ * destroyed when the corresponding cgroup is destroyed.
+ *
+ * This helper library should be initialized by calling drm_cgrp_helper_init()
+ * and torn down (on driver unload) by calling drm_cgrp_helper_shutdown().
+ * Drivers wishing to make use of this helper library should subclass the
+ * &drm_cgroup_helper_data structure to store values for any driver-specific
+ * cgroup parameters and provide implementations of at least
+ * &drm_cgroup_helper.alloc_params, &drm_cgroup_helper.update_param, and
+ * &drm_cgroup_helper.read_param.
+ */
+
+/**
+ * drm_cgrp_helper_set_param - set parameter value for cgroup
+ * @dev: DRM device
+ * @cgrp: cgroup to set parameter for
+ * @param: parameter to set
+ * @val: value to assign to parameter
+ *
+ * Provides a default handler for the CGROUP_SETPARAM ioctl.  At this time
+ * parameters may only be set on cgroups in the v2 hierarchy.
+ *
+ * RETURNS:
+ * Zero on success, error code on failure
+ */
+int
+drm_cgrp_helper_set_param(struct drm_device *dev,
+			  struct cgroup *cgrp,
+			  uint64_t param,
+			  int64_t val)
+{
+	struct drm_cgroup_helper *helper = dev->cgroup_helper;
+	struct drm_cgroup_helper_data *data;
+	int ret;
+
+	if (WARN_ON(!helper))
+		return -EINVAL;
+
+	mutex_lock(&helper->hash_mutex);
+
+	/*
+	 * Search for an existing parameter set for this cgroup and update
+	 * it if found.
+	 */
+	hash_for_each_possible(helper->param_hash, data, node, cgrp->id) {
+		if (data->cgroup == cgrp) {
+			DRM_DEBUG("Updating existing data for cgroup %d\n",
+				  cgrp->id);
+			ret = helper->update_param(data, param, val);
+			goto out;
+		}
+	}
+
+	/*
+	 * Looks like this is the first time we've tried to set a parameter
+	 * on this cgroup.  We need to allocate a new parameter storage
+	 * structure.  Note that we'll still allocate the structure and
+	 * associate it with the cgroup even if the setting of the specific
+	 * parameter fails.
+	 */
+	DRM_DEBUG("Allocating new data for cgroup %d\n", cgrp->id);
+	data = helper->alloc_params();
+	if (IS_ERR(data)) {
+		ret = PTR_ERR(data);
+		goto out;
+	}
+
+	data->dev = dev;
+	data->cgroup = cgrp;
+	hash_add(helper->param_hash, &data->node, cgrp->id);
+
+	ret = helper->update_param(data, param, val);
+
+out:
+	mutex_unlock(&helper->hash_mutex);
+	return ret;
+}
+EXPORT_SYMBOL(drm_cgrp_helper_set_param);
+
+/**
+ * drm_cgrp_helper_get_param - retrieve parameter value for cgroup
+ * @dev: DRM device
+ * @cgrp: cgroup to set parameter for
+ * @param: parameter to retrieve
+ * @val: parameter value returned by reference
+ *
+ * Helper function that drivers may call to lookup a parameter associated
+ * with a specific cgroup.
+ *
+ * RETURNS:
+ * If a parameter value is found for this cgroup, returns zero and sets
+ * 'val' to the value retrieved.  If no parameters have been explicitly
+ * set for this cgroup in the past, returns -EINVAL and does not update
+ * 'val.'  If other errors occur, a negative error code will be returned
+ * and 'val' will not be modified.
+ */
+int
+drm_cgrp_helper_get_param(struct drm_device *dev,
+			  struct cgroup *cgrp,
+			  uint64_t param,
+			  int64_t *val)
+{
+	struct drm_cgroup_helper *helper = dev->cgroup_helper;
+	struct drm_cgroup_helper_data *data;
+	int ret;
+
+	if (WARN_ON(!helper))
+		return -EINVAL;
+
+	mutex_lock(&helper->hash_mutex);
+
+	ret = -EINVAL;
+	hash_for_each_possible(helper->param_hash, data, node, cgrp->id) {
+		if (data->cgroup == cgrp) {
+			ret = helper->read_param(data, param, val);
+			break;
+		}
+	}
+
+	mutex_unlock(&helper->hash_mutex);
+	return ret;
+}
+EXPORT_SYMBOL(drm_cgrp_helper_get_param);
+
+/*
+ * Notifier callback for cgroup destruction.  Search for any driver-specific
+ * data associated with the cgroup and free it.
+ */
+static int
+cgrp_destroyed(struct notifier_block *nb,
+	       unsigned long val,
+	       void *ptr)
+{
+	struct cgroup *cgrp = ptr;
+	struct drm_cgroup_helper *helper = container_of(nb,
+							struct drm_cgroup_helper,
+							cgrp_notifier);
+	struct drm_cgroup_helper_data *data;
+	struct hlist_node *tmp;
+
+	mutex_lock(&helper->hash_mutex);
+
+	hash_for_each_possible_safe(helper->param_hash, data, tmp, node,
+				    cgrp->id) {
+		if (data->cgroup == cgrp) {
+			if (helper->remove_params)
+				helper->remove_params(data);
+			else
+				kfree(data);
+
+			DRM_DEBUG("Destroyed DRM parameters for cgroup %d\n",
+				  cgrp->id);
+
+			break;
+		}
+	}
+
+	mutex_unlock(&helper->hash_mutex);
+
+	return 0;
+}
+
+/**
+ * drm_cgrp_helper_init - initialize cgroup helper library
+ * @dev: DRM device
+ *
+ * Drivers that wish to make use of the cgroup helper library should
+ * call this function during driver load.
+ */
+void
+drm_cgrp_helper_init(struct drm_device *dev,
+		     struct drm_cgroup_helper *helper)
+{
+	dev->cgroup_helper = helper;
+	helper->dev = dev;
+
+	hash_init(helper->param_hash);
+	mutex_init(&helper->hash_mutex);
+
+	helper->cgrp_notifier.notifier_call = cgrp_destroyed;
+	blocking_notifier_chain_register(&cgroup_destroy_notifier_list,
+					 &helper->cgrp_notifier);
+}
+EXPORT_SYMBOL(drm_cgrp_helper_init);
+
+/**
+ * drm_cgrp_helper_shutdown - tear down cgroup helper library
+ * @helper: cgroup helper structure
+ *
+ * Drivers making use of the cgroup helper library should call this function
+ * when unloaded.
+ */
+void
+drm_cgrp_helper_shutdown(struct drm_cgroup_helper *helper)
+{
+	struct drm_cgroup_helper_data *data;
+	struct hlist_node *tmp;
+	int i;
+
+	mutex_lock(&helper->hash_mutex);
+	hash_for_each_safe(helper->param_hash, i, tmp, data, node) {
+		hash_del(&data->node);
+		if (helper->remove_params)
+			helper->remove_params(data);
+		else
+			kfree(data);
+	}
+	mutex_unlock(&helper->hash_mutex);
+
+	blocking_notifier_chain_unregister(&cgroup_destroy_notifier_list,
+					   &helper->cgrp_notifier);
+}
+EXPORT_SYMBOL(drm_cgrp_helper_shutdown);
diff --git a/include/drm/drm_cgroup_helper.h b/include/drm/drm_cgroup_helper.h
new file mode 100644
index 000000000000..435973fadd32
--- /dev/null
+++ b/include/drm/drm_cgroup_helper.h
@@ -0,0 +1,153 @@
+/*
+ * 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_HELPER_H__
+
+#include <linux/cgroup.h>
+#include <linux/hashtable.h>
+
+#ifdef CONFIG_CGROUPS
+
+/**
+ * struct drm_cgroup_helper_data - storage of cgroup-specific information
+ * @dev: DRM device
+ * @node: hashtable node
+ * @cgroup: individual cgroup that this structure instance is associated with
+ *
+ * Drivers should subclass this structure and add fields for all parameters
+ * that they wish to track on a per-cgroup basis.  The cgroup helper library
+ * will allocate a new instance of this structure the first time the
+ * CGROUP_SETPARAM ioctl is called for a cgroup and will destroy this structure
+ * if the corresponding cgroup is destroyed or if the DRM driver is unloaded.
+ */
+struct drm_cgroup_helper_data {
+	struct drm_device *dev;
+	struct hlist_node node;
+	struct cgroup *cgroup;
+};
+
+/**
+ * struct drm_cgroup_helper - main cgroup helper data structure
+ * @dev: DRM device
+ * @param_hash: hashtable used to store per-cgroup parameter data
+ * @hash_mutex: mutex to protect access to hash_mutex
+ * @cgrp_notifier: blocking notifier for cgroup destruction
+ */
+struct drm_cgroup_helper {
+	struct drm_device *dev;
+
+	DECLARE_HASHTABLE(param_hash, 5);
+	struct mutex hash_mutex;
+
+	struct notifier_block cgrp_notifier;
+
+	/**
+	 * @alloc_params:
+	 *
+	 * Driver callback to allocate driver-specific parameter data
+	 * associated with a single cgroup.  This callback will be called if
+	 * CGROUP_SETPARAM is issued for a cgroup that does not already have
+	 * driver-specific storage allocated.
+	 *
+	 * This callback is mandatory.
+	 *
+	 * RETURNS:
+	 *
+	 * The driver should allocate and return a driver-specific subclass
+	 * of drm_cgroup_helper_data.  Returns -ENOMEM on allocation failure.
+	 */
+	struct drm_cgroup_helper_data *(*alloc_params)(void);
+
+	/**
+	 * @update_param:
+	 *
+	 * Driver callback to update a parameter's value in a specific
+	 * cgroup's driver-side storage structure.
+	 *
+	 * This callback is mandatory.
+	 *
+	 * RETURNS:
+	 *
+	 * The driver should return 0 on success or a negative error code
+	 * on failure.
+	 */
+	int (*update_param)(struct drm_cgroup_helper_data *data,
+			    uint64_t param, int64_t val);
+
+	/**
+	 * @read_param:
+	 *
+	 * Driver callback to read a parameter's value from a specific
+	 * cgroup's driver-side storage structure.  If successful, the
+	 * parameter val will be updated with the appropriate value.
+	 *
+	 * This callback is mandatory.
+	 *
+	 * RETURNS:
+	 *
+	 * The driver should return 0 on success or a negative error code
+	 * on failure.
+	 */
+	int (*read_param)(struct drm_cgroup_helper_data *data,
+			  uint64_t param, int64_t *val);
+
+	/**
+	 * @remove_params:
+	 *
+	 * Driver callback to reap the driver-specific data structure
+	 * after the corresponding cgroup has been removed.
+	 *
+	 * This callback is optional.  If not provided, the helper library
+	 * will call kfree() on the driver-specific structure.
+	 */
+	void (*remove_params)(struct drm_cgroup_helper_data *data);
+};
+
+
+void drm_cgrp_helper_init(struct drm_device *dev,
+			  struct drm_cgroup_helper *helper);
+void drm_cgrp_helper_shutdown(struct drm_cgroup_helper *helper);
+int drm_cgrp_helper_set_param(struct drm_device *dev,
+			      struct cgroup *cgrp,
+			      uint64_t param,
+			      int64_t val);
+int drm_cgrp_helper_get_param(struct drm_device *dev,
+			      struct cgroup *cgrp,
+			      uint64_t param,
+			      int64_t *val);
+
+#else /* CGROUPS */
+
+void drm_cgrp_helper_init(struct drm_device *dev) {}
+void drm_cgrp_helper_shutdown(struct drm_device *dev) {}
+int drm_cgrp_helper_set_param(struct drm_device *dev,
+			      struct cgroup *cgrp,
+			      uint64_t param,
+			      int64_t val) { return -EINVAL; }
+int drm_cgrp_helper_get_param(struct drm_device *dev,
+			      struct cgroup *cgrp,
+			      uint64_t param,
+			      int64_t *val) { return -EINVAL; }
+
+#endif
+
+#endif
diff --git a/include/drm/drm_device.h b/include/drm/drm_device.h
index 6eee7bbee602..609c1528d681 100644
--- a/include/drm/drm_device.h
+++ b/include/drm/drm_device.h
@@ -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 */
 };
 
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH RFC 7/9] drm: Add helper to obtain cgroup of drm_file's owning process
       [not found] ` <20180120015141.10118-1-matthew.d.roper-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
                     ` (2 preceding siblings ...)
  2018-01-20  1:51   ` [PATCH RFC 6/9] drm: Add cgroup helper library Matt Roper
@ 2018-01-20  1:51   ` Matt Roper
  2018-01-20  1:51     ` Matt Roper
  2018-01-20  1:51   ` [PATCH RFC 9/9] drm/i915: Add context priority to debugfs Matt Roper
  5 siblings, 0 replies; 22+ messages in thread
From: Matt Roper @ 2018-01-20  1:51 UTC (permalink / raw)
  To: dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	intel-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	cgroups-u79uwXL29TY76Z2rM5mHXA
  Cc: Matt Roper, Tejun Heo

Cc: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Signed-off-by: Matt Roper <matthew.d.roper-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
---
 include/drm/drm_file.h | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h
index 0e0c868451a5..08855a99069c 100644
--- a/include/drm/drm_file.h
+++ b/include/drm/drm_file.h
@@ -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_ */
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH RFC 8/9] drm/i915: Allow default context priority to be set via cgroup parameter
       [not found] ` <20180120015141.10118-1-matthew.d.roper-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
@ 2018-01-20  1:51     ` Matt Roper
  2018-01-20  1:51   ` [PATCH RFC 3/9] cgroup: Export cgroup_on_dfl() to drivers Matt Roper
                       ` (4 subsequent siblings)
  5 siblings, 0 replies; 22+ messages in thread
From: Matt Roper @ 2018-01-20  1:51 UTC (permalink / raw)
  To: dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	intel-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	cgroups-u79uwXL29TY76Z2rM5mHXA
  Cc: Matt Roper, Tejun Heo

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.

Cc: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Signed-off-by: Matt Roper <matthew.d.roper-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
---
 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

diff --git a/drivers/gpu/drm/i915/Makefile b/drivers/gpu/drm/i915/Makefile
index 3bddd8a06806..b9f00a6c1e64 100644
--- a/drivers/gpu/drm/i915/Makefile
+++ b/drivers/gpu/drm/i915/Makefile
@@ -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 \
diff --git a/drivers/gpu/drm/i915/i915_cgroups.c b/drivers/gpu/drm/i915/i915_cgroups.c
new file mode 100644
index 000000000000..6e42ba01b8e8
--- /dev/null
+++ b/drivers/gpu/drm/i915/i915_cgroups.c
@@ -0,0 +1,162 @@
+/*
+ * Copyright © 2018 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * DOC: cgroups integration
+ *
+ * i915 makes use of the DRM cgroup helper library.  Currently i915 only
+ * supports a single cgroup parameter:
+ *
+ * I915_CGRP_DEF_CONTEXT_PRIORITY -
+ *   Setting this parameter on a cgroup will cause GPU contexts created by
+ *   processes in the cgroup to start with the specified default priority (in
+ *   the range of I915_CONTEXT_MIN_USER_PRIORITY to
+ *   I915_CONTEXT_MAX_USER_PRIORITY) instead of the usual priority of
+ *   I915_CONTEXT_DEFAULT_PRIORITY.  This cgroup parameter only provides
+ *   a default starting point; the context priorities may still be overridden
+ *   by other mechanisms (e.g., I915_CONTEXT_PARAM_PRIORITY) or adjusted at
+ *   runtime due to system behavior.
+ */
+
+#include <linux/cgroup.h>
+#include <drm/drm_cgroup.h>
+
+#include "i915_drv.h"
+
+static struct drm_cgroup_funcs i915_cgrp = {
+	.set_param = drm_cgrp_helper_set_param,
+};
+
+static struct drm_cgroup_helper_data *
+i915_cgrp_alloc_params(void)
+{
+	struct i915_cgroup_data *data;
+
+	data = kzalloc(sizeof *data, GFP_KERNEL);
+	if (!data)
+		return ERR_PTR(-ENOMEM);
+
+	return &data->base;
+}
+
+static int
+i915_cgrp_update_param(struct drm_cgroup_helper_data *data,
+		       uint64_t param, int64_t val)
+{
+	struct i915_cgroup_data *idata =
+		container_of(data, struct i915_cgroup_data, base);
+
+	if (param != I915_CGRP_DEF_CONTEXT_PRIORITY) {
+		DRM_DEBUG_DRIVER("Invalid cgroup parameter %llu\n", param);
+		return -EINVAL;
+	}
+
+	if (val > I915_CONTEXT_MAX_USER_PRIORITY ||
+	    val < I915_CONTEXT_MIN_USER_PRIORITY) {
+		DRM_DEBUG_DRIVER("Context priority must be in range (%d,%d)\n",
+				 I915_CONTEXT_MIN_USER_PRIORITY,
+				 I915_CONTEXT_MAX_USER_PRIORITY);
+		return -EINVAL;
+	}
+
+	idata->priority = val;
+
+	return 0;
+}
+
+static int
+i915_cgrp_read_param(struct drm_cgroup_helper_data *data,
+		     uint64_t param, int64_t *val)
+{
+	struct i915_cgroup_data *idata =
+		container_of(data, struct i915_cgroup_data, base);
+
+	switch (param)
+	{
+	case I915_CGRP_DEF_CONTEXT_PRIORITY:
+		*val = idata->priority;
+		break;
+	default:
+		DRM_DEBUG_DRIVER("Invalid cgroup parameter %llu\n", param);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static struct drm_cgroup_helper i915_cgrp_helper = {
+	.alloc_params = i915_cgrp_alloc_params,
+	.update_param = i915_cgrp_update_param,
+	.read_param = i915_cgrp_read_param,
+};
+
+void
+i915_cgroup_init(struct drm_i915_private *dev_priv)
+{
+	dev_priv->drm.cgroup = &i915_cgrp;
+
+	drm_cgrp_helper_init(&dev_priv->drm,
+			     &i915_cgrp_helper);
+}
+
+void
+i915_cgroup_shutdown(struct drm_i915_private *dev_priv)
+{
+	drm_cgrp_helper_shutdown(&i915_cgrp_helper);
+}
+
+/**
+ * i915_cgroup_get_prio() - get priority associated with current proc's cgroup
+ * @dev_priv: drm device
+ * @file_priv: file handle for calling process
+ *
+ * RETURNS:
+ * Priority associated with the calling process' cgroup in the default (v2)
+ * hierarchy, otherwise I915_PRIORITY_NORMAL if no explicit priority has
+ * been assigned.
+ */
+int
+i915_cgroup_get_prio(struct drm_i915_private *dev_priv,
+		     struct drm_i915_file_private *file_priv)
+{
+	struct cgroup *cgrp;
+	int64_t prio;
+	int ret;
+
+	/* Ignore internally-created contexts not associated with a process */
+	if (!file_priv)
+		return I915_PRIORITY_NORMAL;
+
+	cgrp = drm_file_get_cgroup(file_priv->file, &cgrp_dfl_root);
+	if (WARN_ON(!cgrp))
+		return I915_PRIORITY_NORMAL;
+
+	ret = drm_cgrp_helper_get_param(&dev_priv->drm, cgrp,
+					I915_CGRP_DEF_CONTEXT_PRIORITY,
+					&prio);
+	if (ret)
+		/* No default priority has been associated with cgroup */
+		return I915_PRIORITY_NORMAL;
+	else
+		return prio;
+}
diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index 173d0095e3b2..0a11e4b31c2f 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -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");
 
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 2b1d2f802c39..f3991ab847da 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -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
diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c
index 648e7536ff51..ee30f90ae5b2 100644
--- a/drivers/gpu/drm/i915/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/i915_gem_context.c
@@ -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);
diff --git a/include/uapi/drm/i915_drm.h b/include/uapi/drm/i915_drm.h
index 536ee4febd74..07cab6eefaba 100644
--- a/include/uapi/drm/i915_drm.h
+++ b/include/uapi/drm/i915_drm.h
@@ -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
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH RFC 8/9] drm/i915: Allow default context priority to be set via cgroup parameter
@ 2018-01-20  1:51     ` Matt Roper
  0 siblings, 0 replies; 22+ messages in thread
From: Matt Roper @ 2018-01-20  1:51 UTC (permalink / raw)
  To: dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	intel-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	cgroups-u79uwXL29TY76Z2rM5mHXA
  Cc: Matt Roper, Tejun Heo

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.

Cc: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Signed-off-by: Matt Roper <matthew.d.roper-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
---
 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

diff --git a/drivers/gpu/drm/i915/Makefile b/drivers/gpu/drm/i915/Makefile
index 3bddd8a06806..b9f00a6c1e64 100644
--- a/drivers/gpu/drm/i915/Makefile
+++ b/drivers/gpu/drm/i915/Makefile
@@ -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 \
diff --git a/drivers/gpu/drm/i915/i915_cgroups.c b/drivers/gpu/drm/i915/i915_cgroups.c
new file mode 100644
index 000000000000..6e42ba01b8e8
--- /dev/null
+++ b/drivers/gpu/drm/i915/i915_cgroups.c
@@ -0,0 +1,162 @@
+/*
+ * Copyright © 2018 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * DOC: cgroups integration
+ *
+ * i915 makes use of the DRM cgroup helper library.  Currently i915 only
+ * supports a single cgroup parameter:
+ *
+ * I915_CGRP_DEF_CONTEXT_PRIORITY -
+ *   Setting this parameter on a cgroup will cause GPU contexts created by
+ *   processes in the cgroup to start with the specified default priority (in
+ *   the range of I915_CONTEXT_MIN_USER_PRIORITY to
+ *   I915_CONTEXT_MAX_USER_PRIORITY) instead of the usual priority of
+ *   I915_CONTEXT_DEFAULT_PRIORITY.  This cgroup parameter only provides
+ *   a default starting point; the context priorities may still be overridden
+ *   by other mechanisms (e.g., I915_CONTEXT_PARAM_PRIORITY) or adjusted at
+ *   runtime due to system behavior.
+ */
+
+#include <linux/cgroup.h>
+#include <drm/drm_cgroup.h>
+
+#include "i915_drv.h"
+
+static struct drm_cgroup_funcs i915_cgrp = {
+	.set_param = drm_cgrp_helper_set_param,
+};
+
+static struct drm_cgroup_helper_data *
+i915_cgrp_alloc_params(void)
+{
+	struct i915_cgroup_data *data;
+
+	data = kzalloc(sizeof *data, GFP_KERNEL);
+	if (!data)
+		return ERR_PTR(-ENOMEM);
+
+	return &data->base;
+}
+
+static int
+i915_cgrp_update_param(struct drm_cgroup_helper_data *data,
+		       uint64_t param, int64_t val)
+{
+	struct i915_cgroup_data *idata =
+		container_of(data, struct i915_cgroup_data, base);
+
+	if (param != I915_CGRP_DEF_CONTEXT_PRIORITY) {
+		DRM_DEBUG_DRIVER("Invalid cgroup parameter %llu\n", param);
+		return -EINVAL;
+	}
+
+	if (val > I915_CONTEXT_MAX_USER_PRIORITY ||
+	    val < I915_CONTEXT_MIN_USER_PRIORITY) {
+		DRM_DEBUG_DRIVER("Context priority must be in range (%d,%d)\n",
+				 I915_CONTEXT_MIN_USER_PRIORITY,
+				 I915_CONTEXT_MAX_USER_PRIORITY);
+		return -EINVAL;
+	}
+
+	idata->priority = val;
+
+	return 0;
+}
+
+static int
+i915_cgrp_read_param(struct drm_cgroup_helper_data *data,
+		     uint64_t param, int64_t *val)
+{
+	struct i915_cgroup_data *idata =
+		container_of(data, struct i915_cgroup_data, base);
+
+	switch (param)
+	{
+	case I915_CGRP_DEF_CONTEXT_PRIORITY:
+		*val = idata->priority;
+		break;
+	default:
+		DRM_DEBUG_DRIVER("Invalid cgroup parameter %llu\n", param);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static struct drm_cgroup_helper i915_cgrp_helper = {
+	.alloc_params = i915_cgrp_alloc_params,
+	.update_param = i915_cgrp_update_param,
+	.read_param = i915_cgrp_read_param,
+};
+
+void
+i915_cgroup_init(struct drm_i915_private *dev_priv)
+{
+	dev_priv->drm.cgroup = &i915_cgrp;
+
+	drm_cgrp_helper_init(&dev_priv->drm,
+			     &i915_cgrp_helper);
+}
+
+void
+i915_cgroup_shutdown(struct drm_i915_private *dev_priv)
+{
+	drm_cgrp_helper_shutdown(&i915_cgrp_helper);
+}
+
+/**
+ * i915_cgroup_get_prio() - get priority associated with current proc's cgroup
+ * @dev_priv: drm device
+ * @file_priv: file handle for calling process
+ *
+ * RETURNS:
+ * Priority associated with the calling process' cgroup in the default (v2)
+ * hierarchy, otherwise I915_PRIORITY_NORMAL if no explicit priority has
+ * been assigned.
+ */
+int
+i915_cgroup_get_prio(struct drm_i915_private *dev_priv,
+		     struct drm_i915_file_private *file_priv)
+{
+	struct cgroup *cgrp;
+	int64_t prio;
+	int ret;
+
+	/* Ignore internally-created contexts not associated with a process */
+	if (!file_priv)
+		return I915_PRIORITY_NORMAL;
+
+	cgrp = drm_file_get_cgroup(file_priv->file, &cgrp_dfl_root);
+	if (WARN_ON(!cgrp))
+		return I915_PRIORITY_NORMAL;
+
+	ret = drm_cgrp_helper_get_param(&dev_priv->drm, cgrp,
+					I915_CGRP_DEF_CONTEXT_PRIORITY,
+					&prio);
+	if (ret)
+		/* No default priority has been associated with cgroup */
+		return I915_PRIORITY_NORMAL;
+	else
+		return prio;
+}
diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index 173d0095e3b2..0a11e4b31c2f 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -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");
 
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 2b1d2f802c39..f3991ab847da 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -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
diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c
index 648e7536ff51..ee30f90ae5b2 100644
--- a/drivers/gpu/drm/i915/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/i915_gem_context.c
@@ -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);
diff --git a/include/uapi/drm/i915_drm.h b/include/uapi/drm/i915_drm.h
index 536ee4febd74..07cab6eefaba 100644
--- a/include/uapi/drm/i915_drm.h
+++ b/include/uapi/drm/i915_drm.h
@@ -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
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH RFC 9/9] drm/i915: Add context priority to debugfs
       [not found] ` <20180120015141.10118-1-matthew.d.roper-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
                     ` (4 preceding siblings ...)
  2018-01-20  1:51     ` Matt Roper
@ 2018-01-20  1:51   ` Matt Roper
  5 siblings, 0 replies; 22+ messages in thread
From: Matt Roper @ 2018-01-20  1:51 UTC (permalink / raw)
  To: dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	intel-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	cgroups-u79uwXL29TY76Z2rM5mHXA
  Cc: Matt Roper

Update i915_context_status to include priority.

Signed-off-by: Matt Roper <matthew.d.roper-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
---
 drivers/gpu/drm/i915/i915_debugfs.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
index cc659b4b2a45..075b269ac63b 100644
--- a/drivers/gpu/drm/i915/i915_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_debugfs.c
@@ -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];
 
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* ✗ Fi.CI.BAT: warning for DRM management via cgroups
  2018-01-20  1:51 [PATCH RFC 0/9] DRM management via cgroups Matt Roper
                   ` (3 preceding siblings ...)
       [not found] ` <20180120015141.10118-1-matthew.d.roper-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
@ 2018-01-20  2:20 ` Patchwork
  2018-01-22 15:44 ` [PATCH libdrm] tests: Add drm_set_cgrp_param Matt Roper
  5 siblings, 0 replies; 22+ messages in thread
From: Patchwork @ 2018-01-20  2:20 UTC (permalink / raw)
  To: Matt Roper; +Cc: intel-gfx

== 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
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH RFC 8/9] drm/i915: Allow default context priority to be set via cgroup parameter
       [not found]     ` <20180120015141.10118-9-matthew.d.roper-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
@ 2018-01-20  9:36       ` Chris Wilson
       [not found]         ` <151644097064.13504.16277692057900569412-M6iVdVfohj6unts5RBS2dVaTQe2KTcn/@public.gmane.org>
  0 siblings, 1 reply; 22+ messages in thread
From: Chris Wilson @ 2018-01-20  9:36 UTC (permalink / raw)
  To: Matt Roper, dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	intel-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	cgroups-u79uwXL29TY76Z2rM5mHXA
  Cc: Tejun Heo

Quoting Matt Roper (2018-01-20 01:51:40)
> 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

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH RFC 8/9] drm/i915: Allow default context priority to be set via cgroup parameter
       [not found]         ` <151644097064.13504.16277692057900569412-M6iVdVfohj6unts5RBS2dVaTQe2KTcn/@public.gmane.org>
@ 2018-01-20 10:40           ` Chris Wilson
  2018-01-22  9:50             ` Michel Dänzer
  2018-01-22 15:57             ` Matt Roper
  0 siblings, 2 replies; 22+ messages in thread
From: Chris Wilson @ 2018-01-20 10:40 UTC (permalink / raw)
  To: Matt Roper, dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	intel-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	cgroups-u79uwXL29TY76Z2rM5mHXA
  Cc: Tejun Heo

Quoting Chris Wilson (2018-01-20 09:36:10)
> Quoting Matt Roper (2018-01-20 01:51:40)
> > 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

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH RFC 8/9] drm/i915: Allow default context priority to be set via cgroup parameter
  2018-01-20 10:40           ` Chris Wilson
@ 2018-01-22  9:50             ` Michel Dänzer
  2018-01-22  9:56               ` Chris Wilson
  2018-01-22 15:57             ` Matt Roper
  1 sibling, 1 reply; 22+ messages in thread
From: Michel Dänzer @ 2018-01-22  9:50 UTC (permalink / raw)
  To: Chris Wilson, Matt Roper; +Cc: intel-gfx, dri-devel

On 2018-01-20 11:40 AM, Chris Wilson wrote:
> 
> 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?


-- 
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH RFC 8/9] drm/i915: Allow default context priority to be set via cgroup parameter
  2018-01-22  9:50             ` Michel Dänzer
@ 2018-01-22  9:56               ` Chris Wilson
  0 siblings, 0 replies; 22+ messages in thread
From: Chris Wilson @ 2018-01-22  9:56 UTC (permalink / raw)
  To: Michel Dänzer, Matt Roper; +Cc: intel-gfx, dri-devel

Quoting Michel Dänzer (2018-01-22 09:50:38)
> On 2018-01-20 11:40 AM, Chris Wilson wrote:
> > 
> > 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
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH libdrm] tests: Add drm_set_cgrp_param
  2018-01-20  1:51 [PATCH RFC 0/9] DRM management via cgroups Matt Roper
                   ` (4 preceding siblings ...)
  2018-01-20  2:20 ` ✗ Fi.CI.BAT: warning for DRM management via cgroups Patchwork
@ 2018-01-22 15:44 ` Matt Roper
  2018-01-26 17:08   ` Emil Velikov
  5 siblings, 1 reply; 22+ messages in thread
From: Matt Roper @ 2018-01-22 15:44 UTC (permalink / raw)
  To: dri-devel, intel-gfx

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.

Signed-off-by: Matt Roper <matthew.d.roper@intel.com>
---
 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

diff --git a/configure.ac b/configure.ac
index 35378b3384..9b5f340e2a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0355a9255f..d77a8639c8 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -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
diff --git a/tests/drm_set_cgrp_param/Makefile.am b/tests/drm_set_cgrp_param/Makefile.am
new file mode 100644
index 0000000000..c32ec1c440
--- /dev/null
+++ b/tests/drm_set_cgrp_param/Makefile.am
@@ -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
diff --git a/tests/drm_set_cgrp_param/drm_set_cgrp_param.c b/tests/drm_set_cgrp_param/drm_set_cgrp_param.c
new file mode 100644
index 0000000000..987bd18e88
--- /dev/null
+++ b/tests/drm_set_cgrp_param/drm_set_cgrp_param.c
@@ -0,0 +1,80 @@
+/*
+ * \file drm_set_cgrp_prop.c
+ * Simple tool to set a DRM property for a cgroup.  Intended for use in
+ * system-specific initialization handling (e.g., sysv init, systemd, etc.).
+ */
+
+/*
+ * Copyright © 2018 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ */
+
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "xf86drm.h"
+#include "xf86drmMode.h"
+
+#include "util/common.h"
+
+int main(int argc, char **argv)
+{
+	int drm_fd, cgrp_fd;
+	struct drm_cgroup_setparam req;
+	int ret;
+
+	if (argc != 5) {
+		puts("Usage:");
+		printf("  %s <drm device> <cgroup-v2> <prop> <val>\n\n", argv[0]);
+		puts("Example:");
+		printf("  %s /dev/dri/card0 /sys/fs/cgroup-2/highprio 1 10\n",
+		       argv[0]);
+		return 1;
+	}
+
+	drm_fd = open(argv[1], O_RDWR, 0);
+	if (drm_fd < 0) {
+		perror("Invalid DRM device");
+		return 1;
+	}
+
+	cgrp_fd = open(argv[2], O_RDONLY|O_DIRECTORY, 0);
+	if (cgrp_fd < 0) {
+		perror("Invalid cgroup directory");
+		return 1;
+	}
+
+	req.cgroup_fd = cgrp_fd;
+	req.reserved = 0;
+	req.param = (uint64_t)strtoul(argv[3], NULL, 0);
+	req.value = (int64_t)strtol(argv[4], NULL, 0);
+
+	ret = drmIoctl(drm_fd, DRM_IOCTL_CGROUP_SETPARAM, &req);
+	if (ret)
+		perror("Failed to set cgroup parameter");
+
+	close(cgrp_fd);
+	close(drm_fd);
+
+	return ret;
+}
-- 
2.14.3

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* Re: [PATCH RFC 8/9] drm/i915: Allow default context priority to be set via cgroup parameter
  2018-01-20 10:40           ` Chris Wilson
  2018-01-22  9:50             ` Michel Dänzer
@ 2018-01-22 15:57             ` Matt Roper
  1 sibling, 0 replies; 22+ messages in thread
From: Matt Roper @ 2018-01-22 15:57 UTC (permalink / raw)
  To: Chris Wilson; +Cc: Tejun Heo, cgroups, intel-gfx, dri-devel

On Sat, Jan 20, 2018 at 10:40:19AM +0000, Chris Wilson wrote:
> Quoting Chris Wilson (2018-01-20 09:36:10)
> > Quoting Matt Roper (2018-01-20 01:51:40)
> > > 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

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


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

-- 
Matt Roper
Graphics Software Engineer
IoTG Platform Enabling & Development
Intel Corporation
(916) 356-2795
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH RFC 6/9] drm: Add cgroup helper library
  2018-01-20  1:51   ` [PATCH RFC 6/9] drm: Add cgroup helper library Matt Roper
@ 2018-01-22 16:24     ` Tejun Heo
  0 siblings, 0 replies; 22+ messages in thread
From: Tejun Heo @ 2018-01-22 16:24 UTC (permalink / raw)
  To: Matt Roper; +Cc: cgroups, intel-gfx, dri-devel

Hello, Matt.

On Fri, Jan 19, 2018 at 05:51:38PM -0800, Matt Roper wrote:
> 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.

-- 
tejun
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH libdrm] tests: Add drm_set_cgrp_param
  2018-01-22 15:44 ` [PATCH libdrm] tests: Add drm_set_cgrp_param Matt Roper
@ 2018-01-26 17:08   ` Emil Velikov
  2018-01-26 17:27     ` [Intel-gfx] " Matt Roper
  0 siblings, 1 reply; 22+ messages in thread
From: Emil Velikov @ 2018-01-26 17:08 UTC (permalink / raw)
  To: Matt Roper; +Cc: intel-gfx, ML dri-devel

On 22 January 2018 at 15:44, Matt Roper <matthew.d.roper@intel.com> wrote:
> 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.
>
> Signed-off-by: Matt Roper <matthew.d.roper@intel.com>
> ---
>  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
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Intel-gfx] [PATCH libdrm] tests: Add drm_set_cgrp_param
  2018-01-26 17:08   ` Emil Velikov
@ 2018-01-26 17:27     ` Matt Roper
  2018-01-26 17:57       ` Emil Velikov
  0 siblings, 1 reply; 22+ messages in thread
From: Matt Roper @ 2018-01-26 17:27 UTC (permalink / raw)
  To: Emil Velikov; +Cc: intel-gfx, ML dri-devel

On Fri, Jan 26, 2018 at 05:08:48PM +0000, Emil Velikov wrote:
> On 22 January 2018 at 15:44, Matt Roper <matthew.d.roper@intel.com> wrote:
> > 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.
> >
> > Signed-off-by: Matt Roper <matthew.d.roper@intel.com>
> > ---
> >  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.

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.

> 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

> 
> 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

-- 
Matt Roper
Graphics Software Engineer
IoTG Platform Enabling & Development
Intel Corporation
(916) 356-2795
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH libdrm] tests: Add drm_set_cgrp_param
  2018-01-26 17:27     ` [Intel-gfx] " Matt Roper
@ 2018-01-26 17:57       ` Emil Velikov
  0 siblings, 0 replies; 22+ messages in thread
From: Emil Velikov @ 2018-01-26 17:57 UTC (permalink / raw)
  To: Matt Roper; +Cc: intel-gfx, ML dri-devel

On 26 January 2018 at 17:27, Matt Roper <matthew.d.roper@intel.com> wrote:
> On Fri, Jan 26, 2018 at 05:08:48PM +0000, Emil Velikov wrote:
>> On 22 January 2018 at 15:44, Matt Roper <matthew.d.roper@intel.com> wrote:
>> > 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.
>> >
>> > Signed-off-by: Matt Roper <matthew.d.roper@intel.com>
>> > ---
>> >  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.
>
> 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.
>
Good call - have an agreement about the interface and usage first.
Then iron out all the fiddly bits.

>> 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
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2018-01-26 17:57 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-20  1:51 [PATCH RFC 0/9] DRM management via cgroups Matt Roper
2018-01-20  1:51 ` [PATCH RFC 2/9] cgroup: Add notifier call chain for cgroup destruction Matt Roper
2018-01-20  1:51 ` [PATCH RFC 4/9] cgroup: Export task_cgroup_from_root() and cgroup_mutex for drivers Matt Roper
2018-01-20  1:51 ` [PATCH RFC 5/9] drm: Introduce DRM_IOCTL_CGROUP_SETPARAM Matt Roper
     [not found] ` <20180120015141.10118-1-matthew.d.roper-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2018-01-20  1:51   ` [PATCH RFC 1/9] kernfs: Export kernfs_get_inode Matt Roper
2018-01-20  1:51   ` [PATCH RFC 3/9] cgroup: Export cgroup_on_dfl() to drivers Matt Roper
2018-01-20  1:51   ` [PATCH RFC 6/9] drm: Add cgroup helper library Matt Roper
2018-01-22 16:24     ` Tejun Heo
2018-01-20  1:51   ` [PATCH RFC 7/9] drm: Add helper to obtain cgroup of drm_file's owning process Matt Roper
2018-01-20  1:51   ` [PATCH RFC 8/9] drm/i915: Allow default context priority to be set via cgroup parameter Matt Roper
2018-01-20  1:51     ` Matt Roper
     [not found]     ` <20180120015141.10118-9-matthew.d.roper-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2018-01-20  9:36       ` Chris Wilson
     [not found]         ` <151644097064.13504.16277692057900569412-M6iVdVfohj6unts5RBS2dVaTQe2KTcn/@public.gmane.org>
2018-01-20 10:40           ` Chris Wilson
2018-01-22  9:50             ` Michel Dänzer
2018-01-22  9:56               ` Chris Wilson
2018-01-22 15:57             ` Matt Roper
2018-01-20  1:51   ` [PATCH RFC 9/9] drm/i915: Add context priority to debugfs Matt Roper
2018-01-20  2:20 ` ✗ Fi.CI.BAT: warning for DRM management via cgroups Patchwork
2018-01-22 15:44 ` [PATCH libdrm] tests: Add drm_set_cgrp_param Matt Roper
2018-01-26 17:08   ` Emil Velikov
2018-01-26 17:27     ` [Intel-gfx] " Matt Roper
2018-01-26 17:57       ` Emil Velikov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.