cgroup private data and DRM/i915 integration
Subsystems (4)
cover cgroup private data and DRM/i915 integration
This version of the patch series just contains some minor updates to address checkpatch and sparse warnings. There are no serious design or implementation changes since v4.
You can find the previous versions of this series (and more detailed cover letters) here:
(v1) https://lists.freedesktop.org/archives/intel-gfx/2018-January/153156.html
(v2) https://www.mail-archive.com/[email protected]/msg208170.html
(v3) https://lists.freedesktop.org/archives/intel-gfx/2018-March/157928.html
(v4) https://lists.freedesktop.org/archives/intel-gfx/2018-March/159222.html
Matt Roper (8):
cgroup: Allow registration and lookup of cgroup private data (v3)
cgroup: Introduce task_get_dfl_cgroup() (v2)
cgroup: Introduce cgroup_priv_get_current
drm/i915: Adjust internal priority definitions (v2) drm/i915: cgroup integration (v4)
drm/i915: Introduce 'priority offset' for GPU contexts (v4) drm/i915: Introduce per-cgroup display boost setting drm/i915: Add context priority & priority offset to debugfs (v2)
drivers/gpu/drm/i915/Makefile | 1 + drivers/gpu/drm/i915/i915_cgroup.c | 207 ++++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/i915_debugfs.c | 3 + drivers/gpu/drm/i915/i915_drv.c | 8 ++ drivers/gpu/drm/i915/i915_drv.h | 46 ++++++- drivers/gpu/drm/i915/i915_gem_context.c | 12 +- drivers/gpu/drm/i915/i915_gem_context.h | 9 ++ drivers/gpu/drm/i915/i915_request.h | 18 ++- drivers/gpu/drm/i915/intel_display.c | 5 +- include/linux/cgroup-defs.h | 8 ++ include/linux/cgroup.h | 37 ++++++ include/uapi/drm/i915_drm.h | 14 +++ kernel/cgroup/cgroup.c | 206 ++++++++++++++++++++++++++++++- 13 files changed, 561 insertions(+), 13 deletions(-) create mode 100644 drivers/gpu/drm/i915/i915_cgroup.c
Signature · 6 lines
2.14.3 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 1/8 cgroup: Allow registration and lookup of cgroup private data (v3)
There are cases where other parts of the kernel may wish to store data associated with individual cgroups without building a full cgroup controller. Let's add interfaces to allow them to register and lookup this private data for individual cgroups.
A kernel system (e.g., a driver) that wishes to register private data for a cgroup should start by obtaining a unique private data key by calling cgroup_priv_getkey(). It may then associate private data with a cgroup by calling cgroup_priv_install(cgrp, key, ref) where 'ref' is a pointer to a kref field inside the private data structure. The private data may later be looked up by calling cgroup_priv_get(cgrp, key) to obtain a new reference to the private data. Private data may be unregistered via cgroup_priv_release(cgrp, key).
If a cgroup is removed, the reference count for all private data objects will be decremented.
v2: Significant overhaul suggested by Tejun, Alexei, and Roman
- Rework interface to make consumers obtain an ida-based key rather than supplying their own arbitrary void*
- Internal implementation now uses per-cgroup radixtrees which should allow much faster lookup than the previous hashtable approach
- Private data is registered via kref, allowing a single private data structure to potentially be assigned to multiple cgroups.
v3:
- Spare warning fixes (kbuild test robot)
fixup! cgroup: Allow registration and lookup of cgroup private data (v2)
--- include/linux/cgroup-defs.h | 10 +++ include/linux/cgroup.h | 7 ++ kernel/cgroup/cgroup.c | 183 +++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 198 insertions(+), 2 deletions(-)
include/linux/cgroup-defs.h +10 -0
@@ -427,6 +427,16 @@ struct cgroup {/* used to store eBPF programs */ struct cgroup_bpf bpf; +/* +* cgroup private data registered by other non-controller parts of the +* kernel. Insertions are protected by privdata_lock, lookups by +* rcu_read_lock(). +*/ +struct radix_tree_root privdata; + +/* Protect against concurrent insertions/deletions to privdata */ +spinlock_t privdata_lock; +/* ids of the ancestors at each level including self */ int ancestor_ids[]; };
include/linux/cgroup.h +7 -0
@@ -833,4 +833,11 @@ static inline void put_cgroup_ns(struct cgroup_namespace *ns) free_cgroup_ns(ns); } +/* cgroup private data handling */ +int cgroup_priv_getkey (void (*free)(struct kref *)); +void cgroup_priv_destroykey (int key); +int cgroup_priv_install (struct cgroup *cgrp,int key,struct kref *ref); +struct kref *cgroup_priv_get (struct cgroup *cgrp,int key); +void cgroup_priv_release (struct cgroup *cgrp,int key); +#endif /* _LINUX_CGROUP_H */
kernel/cgroup/cgroup.c +181 -2
210 lines not on this page · raw message
Signature · 6 lines
2.14.3 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 2/8 cgroup: Introduce task_get_dfl_cgroup() (v2)
In reply to Matt RoperWraps task_dfl_cgroup() to also take a reference to the cgroup.
v2:
- Eliminate cgroup_mutex and make lighter-weight (Tejun)
--- include/linux/cgroup.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
include/linux/cgroup.h +29 -0
@@ -527,6 +527,35 @@ static inline struct cgroup *task_dfl_cgroup(struct task_struct *task)return task_css_set (task)->dfl_cgrp; } +/** +* task_get_dfl_cgroup() - find and get the cgroup for a task +* @task: the target task +* +* Find the cgroup in the v2 hierarchy that a task belongs to, increment its +* reference count, and return it. +* +* Returns: +* The appropriate cgroup from the default hierarchy. +*/ +static inline struct cgroup * +task_get_dfl_cgroup (struct task_struct *task) +{ +struct cgroup *cgrp; + +rcu_read_lock (); +while (true) { + cgrp =task_dfl_cgroup (task); + +if (likely (cgroup_tryget (cgrp))) +break ; + +cpu_relax (); + } +rcu_read_unlock (); + +return cgrp; +} +static inline struct cgroup *cgroup_parent (struct cgroup *cgrp) {struct cgroup_subsys_state *parent_css = cgrp->self.parent;
Signature · 6 lines
2.14.3 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 3/8 cgroup: Introduce cgroup_priv_get_current
In reply to Matt RoperGetting cgroup private data for the current process' cgroup is such a common pattern that we should add a convenience wrapper for it.
--- include/linux/cgroup.h | 1 + kernel/cgroup/cgroup.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+)
include/linux/cgroup.h +1 -0
@@ -867,6 +867,7 @@ int cgroup_priv_getkey(void (*free)(struct kref *));void cgroup_priv_destroykey (int key);int cgroup_priv_install (struct cgroup *cgrp,int key,struct kref *ref);struct kref *cgroup_priv_get (struct cgroup *cgrp,int key); +struct kref *cgroup_priv_get_current (int key);void cgroup_priv_release (struct cgroup *cgrp,int key);#endif /* _LINUX_CGROUP_H */
kernel/cgroup/cgroup.c +23 -0
@@ -6079,6 +6079,29 @@ cgroup_priv_get(struct cgroup *cgrp, int key) }EXPORT_SYMBOL_GPL (cgroup_priv_get); +/** +* cgroup_priv_get_current - looks up cgroup private data for current task +* @key: key uniquely identifying owner of private data to lookup +* +* Convenience function that performs cgroup_priv_get() on the cgroup that owns +* %current. +* +* Returns: +* A pointer to the private data's kref field, or NULL if no private data has +* been registered. +*/ +struct kref * +cgroup_priv_get_current (int key) +{ +struct cgroup *cgrp =task_get_dfl_cgroup (current); +struct kref *ref =cgroup_priv_get (cgrp, key); + +cgroup_put (cgrp); + +return ref; +} +EXPORT_SYMBOL_GPL (cgroup_priv_get_current); +/** * cgroup_priv_free - free cgroup private data * @cgrp: cgroup to release private data for
Signature · 6 lines
2.14.3 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 4/8 drm/i915: Adjust internal priority definitions (v2)
In reply to Matt RoperIn preparation for adding cgroup-based priority adjustments, let's define the driver's priority values a little more clearly.
v2:
- checkpatch warning fix (Intel CI)
--- drivers/gpu/drm/i915/i915_drv.h | 1 - drivers/gpu/drm/i915/i915_gem_context.c | 5 +++-- drivers/gpu/drm/i915/i915_request.h | 13 ++++++++++--- drivers/gpu/drm/i915/intel_display.c | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +0 -1
@@ -3150,7 +3150,6 @@ int i915_gem_object_wait(struct drm_i915_gem_object *obj,int i915_gem_object_wait_priority (struct drm_i915_gem_object *obj,unsigned int flags,int priority); -#define I915_PRIORITY_DISPLAY I915_PRIORITY_MAXint __must_check i915_gem_object_set_to_wc_domain (struct drm_i915_gem_object *obj,bool write);
drivers/gpu/drm/i915/i915_gem_context.c +3 -2
@@ -474,7 +474,7 @@ int i915_gem_contexts_init(struct drm_i915_private *dev_priv)ida_init (&dev_priv->contexts.hw_ida);/* lowest priority; idle task */ - ctx =i915_gem_context_create_kernel (dev_priv,I915_PRIORITY_MIN ); + ctx =i915_gem_context_create_kernel (dev_priv,I915_PRIORITY_IDLE );if (IS_ERR (ctx)) {DRM_ERROR ("Failed to create default global context\n" );return PTR_ERR (ctx);
@@ -488,7 +488,8 @@ int i915_gem_contexts_init(struct drm_i915_private *dev_priv)/* highest priority; preempting task */ if (needs_preempt_context (dev_priv)) { - ctx =i915_gem_context_create_kernel (dev_priv,INT_MAX ); + ctx =i915_gem_context_create_kernel (dev_priv, +I915_PRIORITY_PREEMPT );if (!IS_ERR (ctx)) dev_priv->preempt_context = ctx;else
drivers/gpu/drm/i915/i915_request.h +10 -3
@@ -78,12 +78,19 @@ struct i915_priotree {int priority; }; +/* +* Userspace can only assign priority values of [-1023,1023] via context param, +* but the effective priority value can fall in a larger range once we add in +* a cgroup-provided offset. +*/ enum { -I915_PRIORITY_MIN =I915_CONTEXT_MIN_USER_PRIORITY -1 ,I915_PRIORITY_NORMAL =I915_CONTEXT_DEFAULT_PRIORITY , -I915_PRIORITY_MAX =I915_CONTEXT_MAX_USER_PRIORITY +1 , +I915_PRIORITY_DEFAULT_DISPBOOST =I915_CONTEXT_MAX_USER_PRIORITY +1 , -I915_PRIORITY_INVALID =INT_MIN +/* Special case priority values */ +I915_PRIORITY_INVALID =INT_MIN , +I915_PRIORITY_IDLE =INT_MIN +1 , +I915_PRIORITY_PREEMPT =INT_MAX , };struct i915_capture_list {
drivers/gpu/drm/i915/intel_display.c +1 -1
@@ -12783,7 +12783,7 @@ intel_prepare_plane_fb(struct drm_plane *plane, ret =intel_plane_pin_fb (to_intel_plane_state (new_state)); -i915_gem_object_wait_priority (obj,0 ,I915_PRIORITY_DISPLAY ); +i915_gem_object_wait_priority (obj,0 ,I915_PRIORITY_DEFAULT_DISPBOOST );mutex_unlock (&dev_priv->drm.struct_mutex);i915_gem_object_unpin_pages (obj);
Signature · 6 lines
2.14.3 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 5/8 drm/i915: cgroup integration (v4)
In reply to Matt RoperIntroduce a new DRM_IOCTL_I915_CGROUP_SETPARAM ioctl that will allow userspace to set i915-specific parameters for individual cgroups. i915 cgroup data will be registered and later looked up via the new cgroup_priv infrastructure.
v2:
- Large rebase/rewrite for new cgroup_priv interface
v3:
- Another rebase/rewrite for ida-based keys and kref-based storage
- Access control no longer follows cgroup filesystem permissions; instead we restrict access to either DRM master or capable(CAP_SYS_RESOURCE).
v4:
- Fix checkpatch warnings (Intel CI)
--- drivers/gpu/drm/i915/Makefile | 1 + drivers/gpu/drm/i915/i915_cgroup.c | 140 +++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/i915_drv.c | 8 +++ drivers/gpu/drm/i915/i915_drv.h | 32 +++++++++ include/uapi/drm/i915_drm.h | 12 ++++ 5 files changed, 193 insertions(+) create mode 100644 drivers/gpu/drm/i915/i915_cgroup.c
drivers/gpu/drm/i915/Makefile +1 -0
@@ -48,6 +48,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_cgroup.o # GEM code i915-y += i915_cmd_parser.o \
drivers/gpu/drm/i915/i915_cgroup.c new file +140 -0
140 lines not on this page · raw message
drivers/gpu/drm/i915/i915_drv.c +8 -0
@@ -1407,6 +1407,10 @@ int i915_driver_load(struct pci_dev *pdev, const struct pci_device_id *ent)intel_runtime_pm_put (dev_priv); + ret =i915_cgroup_init (dev_priv); +if (ret <0 ) + goto out_cleanup_hw; +i915_welcome_messages (dev_priv);return 0 ;
@@ -1433,6 +1437,8 @@ void i915_driver_unload(struct drm_device *dev)struct drm_i915_private *dev_priv =to_i915 (dev);struct pci_dev *pdev = dev_priv->drm.pdev; +i915_cgroup_shutdown (dev_priv); +i915_driver_unregister (dev_priv);if (i915_gem_suspend (dev_priv))
@@ -2833,6 +2839,8 @@ static const struct drm_ioctl_desc i915_ioctls[] = {DRM_IOCTL_DEF_DRV (I915_PERF_ADD_CONFIG , i915_perf_add_config_ioctl,DRM_UNLOCKED |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (I915_PERF_REMOVE_CONFIG , i915_perf_remove_config_ioctl,DRM_UNLOCKED |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (I915_QUERY , i915_query_ioctl,DRM_UNLOCKED |DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (I915_CGROUP_SETPARAM , i915_cgroup_setparam_ioctl, + DRM_UNLOCKED | DRM_RENDER_ALLOW), }; static struct drm_driver driver = {
drivers/gpu/drm/i915/i915_drv.h +32 -0
@@ -1738,6 +1738,15 @@ struct drm_i915_private {struct intel_ppat ppat; +/* cgroup private data */ +int cgroup_priv_key; + +/* +* protects against concurrent attempts to create private data for a +* cgroup +*/ +struct mutex cgroup_lock; +/* Kernel Modesetting */ struct intel_crtc *plane_to_crtc_mapping[I915_MAX_PIPES ];
@@ -2678,6 +2687,29 @@ intel_ggtt_update_needs_vtd_wa(struct drm_i915_private *dev_priv)int intel_sanitize_enable_ppgtt (struct drm_i915_private *dev_priv,int enable_ppgtt); +/* i915_cgroup.c */ +#ifdef CONFIG_CGROUPS +int i915_cgroup_init (struct drm_i915_private *dev_priv); +int i915_cgroup_setparam_ioctl (struct drm_device *dev,void *data, +struct drm_file *file); +void i915_cgroup_shutdown (struct drm_i915_private *dev_priv); +#else +static inline int +i915_cgroup_init (struct drm_i915_private *dev_priv) +{ +return 0 ; +} + +static inline void i915_cgroup_shutdown (struct drm_i915_private *dev_priv) {} + +static inline int +i915_cgroup_setparam_ioctl (struct drm_device *dev,void *data, +struct drm_file *file) +{ +return -EINVAL ; +} +#endif +/* i915_drv.c */ void __printf(3, 4) __i915_printk(struct drm_i915_private *dev_priv, const char *level,
include/uapi/drm/i915_drm.h +12 -0
@@ -319,6 +319,7 @@ typedef struct _drm_i915_sarea {#define DRM_I915_PERF_ADD_CONFIG 0x37#define DRM_I915_PERF_REMOVE_CONFIG 0x38#define DRM_I915_QUERY 0x39 +#define DRM_I915_CGROUP_SETPARAM 0x3a#define DRM_IOCTL_I915_INIT DRM_IOW( DRM_COMMAND_BASE + DRM_I915_INIT, drm_i915_init_t)#define DRM_IOCTL_I915_FLUSH DRM_IO ( DRM_COMMAND_BASE + DRM_I915_FLUSH)
@@ -377,6 +378,7 @@ typedef struct _drm_i915_sarea {#define DRM_IOCTL_I915_PERF_ADD_CONFIG DRM_IOW(DRM_COMMAND_BASE + DRM_I915_PERF_ADD_CONFIG, struct drm_i915_perf_oa_config)#define DRM_IOCTL_I915_PERF_REMOVE_CONFIG DRM_IOW(DRM_COMMAND_BASE + DRM_I915_PERF_REMOVE_CONFIG, __u64)#define DRM_IOCTL_I915_QUERY DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_QUERY, struct drm_i915_query) +#define DRM_IOCTL_I915_CGROUP_SETPARAM DRM_IOW(DRM_COMMAND_BASE + DRM_I915_CGROUP_SETPARAM, struct drm_i915_cgroup_param)/* Allow drivers to submit batchbuffers directly to hardware, relying * on the security mechanisms provided by hardware.
@@ -1717,6 +1719,16 @@ struct drm_i915_query_topology_info {__u8 data[]; }; +/** +* Structure to set i915 parameter on a cgroup. +*/ +struct drm_i915_cgroup_param { +__s32 cgroup_fd; +__u32 flags; +__u64 param; +__s64 value; +}; +#if defined(__cplusplus) }#endif
Signature · 6 lines
2.14.3 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 6/8 drm/i915: Introduce 'priority offset' for GPU contexts (v4)
In reply to Matt RoperThere are cases where a system integrator may wish to raise/lower the priority of GPU workloads being submitted by specific OS process(es), independently of how the software self-classifies its own priority. Exposing "priority offset" as an i915-specific cgroup parameter will enable such system-level configuration.
Normally GPU contexts start with a priority value of 0 (I915_CONTEXT_DEFAULT_PRIORITY) and then may be adjusted up/down from there via other mechanisms. We'd like to provide a system-level input to the priority decision that will be taken into consideration, even when userspace later attempts to set an absolute priority value via I915_CONTEXT_PARAM_PRIORITY. The priority offset introduced here provides a base value that will always be added to (or subtracted from) the software's self-assigned priority value.
This patch makes priority offset a cgroup-specific value; contexts will be created with a priority offset based on the cgroup membership of the process creating the context at the time the context is created. Note that priority offset is assigned at context creation time; migrating a process to a different cgroup or changing the offset associated with a cgroup will only affect new context creation and will not alter the behavior of existing contexts previously created by the process.
v2:
- Rebase onto new cgroup_priv API
- Use current instead of drm_file->pid to determine which process to lookup priority for. (Chris)
- Don't forget to subtract priority offset in context_getparam ioctl to make it match setparam behavior. (Chris)
v3:
- Rebase again onto new idr/kref-based cgroup_priv API
- Bound priority offset such that effective priority from settings on context + cgroup fall within [-0x7fffff, 0x7fffff]. (Chris)
v4:
- checkpatch warning fixes (Intel CI)
--- drivers/gpu/drm/i915/i915_cgroup.c | 54 +++++++++++++++++++++++++++++++-- drivers/gpu/drm/i915/i915_drv.h | 7 +++++ drivers/gpu/drm/i915/i915_gem_context.c | 7 +++-- drivers/gpu/drm/i915/i915_gem_context.h | 9 ++++++ drivers/gpu/drm/i915/i915_request.h | 4 +++ include/uapi/drm/i915_drm.h | 1 + 6 files changed, 77 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/i915_cgroup.c +52 -2
@@ -10,6 +10,8 @@#include "i915_drv.h" struct i915_cgroup_data { +int priority_offset; +struct kref ref; };
@@ -54,7 +56,6 @@ i915_cgroup_shutdown(struct drm_i915_private *dev_priv)* Return i915 cgroup private data, creating and registering it if one doesn't * already exist for this cgroup. */ -__maybe_unused static struct i915_cgroup_data *get_or_create_cgroup_data (struct drm_i915_private *dev_priv,struct cgroup *cgrp)
@@ -98,9 +99,11 @@ i915_cgroup_setparam_ioctl(struct drm_device *dev,void *data, struct drm_file *file) { + struct drm_i915_private *dev_priv = to_i915(dev);struct drm_i915_cgroup_param *req = data;struct cgroup *cgrp; -int ret; +struct i915_cgroup_data *cgrpdata; +int top, bot, ret =0 ;/* We don't actually support any flags yet. */ if (req->flags) {
@@ -127,14 +130,61 @@ i915_cgroup_setparam_ioctl(struct drm_device *dev, goto out; } + cgrpdata =get_or_create_cgroup_data (dev_priv, cgrp); +if (IS_ERR (cgrpdata)) { + ret =PTR_ERR (cgrpdata); + goto out; + } +switch (req->param) { +case I915_CGROUP_PARAM_PRIORITY_OFFSET : + top = req->value +I915_CONTEXT_MAX_USER_PRIORITY ; + bot = req->value -I915_CONTEXT_MIN_USER_PRIORITY ; +if (top <=I915_PRIORITY_MAX && bot >=I915_PRIORITY_MIN ) { +DRM_DEBUG_DRIVER ("Setting cgroup priority offset to %lld\n" , + req->value); + cgrpdata->priority_offset = req->value; + }else { +DRM_DEBUG_DRIVER ("Invalid cgroup priority offset %lld\n" , + req->value); + ret = -EINVAL ; + } +break ; +default :DRM_DEBUG_DRIVER ("Invalid cgroup parameter %lld\n" , req->param); ret = -EINVAL ; } +kref_put (&cgrpdata->ref, i915_cgroup_free); + out:cgroup_put (cgrp);return ret; } + +/* +* Generator for simple getter functions that look up a cgroup private data +* field for the current task's cgroup. It's safe to call these before +* a cgroup private data key has been registered; they'll just return the +* default value in that case. +*/ +#define CGROUP_GET (name, field, def) \ +int i915_cgroup_get_current_##name(struct drm_i915_private *dev_priv) \ +{ \ + struct kref *ref; \ + int val = def; \ + if (!dev_priv->cgroup_priv_key) \ + return def; \ + ref = cgroup_priv_get_current(dev_priv->cgroup_priv_key); \ + if (ref) { \ + val = cgrp_ref_to_i915(ref)->field; \ + kref_put(ref, i915_cgroup_free); \ + } \ + return val; \ +} + +CGROUP_GET(prio_offset, priority_offset, 0) + +#undef CGROUP_GET
drivers/gpu/drm/i915/i915_drv.h +7 -0
@@ -2693,6 +2693,7 @@ int i915_cgroup_init(struct drm_i915_private *dev_priv);int i915_cgroup_setparam_ioctl (struct drm_device *dev,void *data,struct drm_file *file);void i915_cgroup_shutdown (struct drm_i915_private *dev_priv); +int i915_cgroup_get_current_prio_offset (struct drm_i915_private *dev_priv);#else static inline int i915_cgroup_init (struct drm_i915_private *dev_priv)
@@ -2708,6 +2709,12 @@ i915_cgroup_setparam_ioctl(struct drm_device *dev, void *data, {return -EINVAL ; } + +static inline int +i915_cgroup_get_current_prio_offset (struct drm_i915_private *dev_priv) +{ +return 0 ; +}#endif /* i915_drv.c */
drivers/gpu/drm/i915/i915_gem_context.c +4 -3
@@ -280,7 +280,8 @@ __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_offset =i915_cgroup_get_current_prio_offset (dev_priv); + ctx->priority =I915_PRIORITY_NORMAL + ctx->priority_offset;INIT_RADIX_TREE (&ctx->handles_vma,GFP_KERNEL );INIT_LIST_HEAD (&ctx->handles_list);
@@ -748,7 +749,7 @@ int i915_gem_context_getparam_ioctl(struct drm_device *dev, void *data, args->value =i915_gem_context_is_bannable (ctx);break ;case I915_CONTEXT_PARAM_PRIORITY : - args->value = ctx->priority; + args->value = ctx->priority - ctx->priority_offset;break ;default : ret = -EINVAL ;
@@ -821,7 +822,7 @@ int i915_gem_context_setparam_ioctl(struct drm_device *dev, void *data, !capable(CAP_SYS_NICE)) ret = -EPERM ; else - ctx->priority = priority; + ctx->priority = priority + ctx->priority_offset; }break ;
drivers/gpu/drm/i915/i915_gem_context.h +9 -0
@@ -150,6 +150,15 @@ struct i915_gem_context {*/ int priority; +/** +* @priority_offset: priority offset +* +* A value, configured via cgroup, that sets the starting priority +* of the context. Any priority set explicitly via context parameter +* will be added to the priority offset. +*/ +int priority_offset; +/** ggtt_offset_bias: placement restriction for context objects */ u32 ggtt_offset_bias;
drivers/gpu/drm/i915/i915_request.h +4 -0
@@ -87,6 +87,10 @@ enum {I915_PRIORITY_NORMAL =I915_CONTEXT_DEFAULT_PRIORITY ,I915_PRIORITY_DEFAULT_DISPBOOST =I915_CONTEXT_MAX_USER_PRIORITY +1 , +/* Range reachable by combining user priority + cgroup offset */ +I915_PRIORITY_MAX =0x7fffff , +I915_PRIORITY_MIN = -I915_PRIORITY_MAX , +/* Special case priority values */ I915_PRIORITY_INVALID =INT_MIN , I915_PRIORITY_IDLE = INT_MIN + 1,
include/uapi/drm/i915_drm.h +1 -0
@@ -1726,6 +1726,7 @@ struct drm_i915_cgroup_param {__s32 cgroup_fd;__u32 flags;__u64 param; +#define I915_CGROUP_PARAM_PRIORITY_OFFSET 0x1__s64 value; };
Signature · 6 lines
2.14.3 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 7/8 drm/i915: Introduce per-cgroup display boost setting
In reply to Matt RoperUsually display-boosted contexts get treated as I915_CONTEXT_MAX_USER_PRIORITY+1, which prioritizes them above regular GPU contexts. Now that we allow a much larger range of effective priority values via per-cgroup priority offsets, a system administrator may want more detailed control over how much a process should be boosted by display operations (i.e., can a context from a cgroup with a low priority offset still be display boosted above contexts from a cgroup with a much higher priority offset? or are come cgroups more important than maintaining display rate?).
--- drivers/gpu/drm/i915/i915_cgroup.c | 17 +++++++++++++++++ drivers/gpu/drm/i915/i915_drv.h | 6 ++++++ drivers/gpu/drm/i915/i915_request.h | 1 + drivers/gpu/drm/i915/intel_display.c | 5 +++-- include/uapi/drm/i915_drm.h | 1 + 5 files changed, 28 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/i915_cgroup.c +17 -0
@@ -11,6 +11,7 @@struct i915_cgroup_data {int priority_offset; +int display_boost;struct kref ref; };
@@ -75,6 +76,8 @@ get_or_create_cgroup_data(struct drm_i915_private *dev_priv, goto out; } + priv->display_boost =I915_PRIORITY_DEFAULT_DISPBOOST ; +kref_init (&priv->ref);cgroup_priv_install (cgrp, dev_priv->cgroup_priv_key, &priv->ref);
@@ -151,6 +154,19 @@ i915_cgroup_setparam_ioctl(struct drm_device *dev, }break ; +case I915_CGROUP_PARAM_DISPBOOST_PRIORITY : +if (req->value <I915_PRIORITY_MAX_DISPBOOST && + req->value >I915_PRIORITY_MIN ) { +DRM_DEBUG_DRIVER ("Setting cgroup display boost priority to %lld\n" , + req->value); + cgrpdata->display_boost = req->value; + }else { +DRM_DEBUG_DRIVER ("Invalid cgroup display boost priority %lld\n" , + req->value); + ret = -EINVAL ; + } +break ; +default :DRM_DEBUG_DRIVER ("Invalid cgroup parameter %lld\n" , req->param); ret = -EINVAL ;
@@ -186,5 +202,6 @@ int i915_cgroup_get_current_##name(struct drm_i915_private *dev_priv) \ } CGROUP_GET(prio_offset, priority_offset, 0) +CGROUP_GET (dispboost, display_boost,I915_PRIORITY_DEFAULT_DISPBOOST );#undef CGROUP_GET
drivers/gpu/drm/i915/i915_drv.h +6 -0
@@ -2694,6 +2694,7 @@ int i915_cgroup_setparam_ioctl(struct drm_device *dev, void *data, struct drm_file *file);void i915_cgroup_shutdown (struct drm_i915_private *dev_priv);int i915_cgroup_get_current_prio_offset (struct drm_i915_private *dev_priv); +int i915_cgroup_get_current_dispboost (struct drm_i915_private *dev_priv);#else static inline int i915_cgroup_init (struct drm_i915_private *dev_priv)
@@ -2715,6 +2716,11 @@ i915_cgroup_get_current_prio_offset(struct drm_i915_private *dev_priv) {return 0 ; } +static inline int +i915_cgroup_get_current_dispboost (struct drm_i915_private *dev_priv) +{ +return I915_PRIORITY_DEFAULT_DISPBOOST ; +}#endif /* i915_drv.c */
drivers/gpu/drm/i915/i915_request.h +1 -0
@@ -90,6 +90,7 @@ enum {/* Range reachable by combining user priority + cgroup offset */ I915_PRIORITY_MAX =0x7fffff ,I915_PRIORITY_MIN = -I915_PRIORITY_MAX , +I915_PRIORITY_MAX_DISPBOOST =I915_PRIORITY_MAX +1 ,/* Special case priority values */ I915_PRIORITY_INVALID = INT_MIN,
drivers/gpu/drm/i915/intel_display.c +3 -2
@@ -12731,7 +12731,7 @@ intel_prepare_plane_fb(struct drm_plane *plane,struct drm_framebuffer *fb = new_state->fb;struct drm_i915_gem_object *obj =intel_fb_obj (fb);struct drm_i915_gem_object *old_obj =intel_fb_obj (plane->state->fb); -int ret; +int boost, ret;if (old_obj) { struct drm_crtc_state *crtc_state =
@@ -12783,7 +12783,8 @@ intel_prepare_plane_fb(struct drm_plane *plane, ret =intel_plane_pin_fb (to_intel_plane_state (new_state)); -i915_gem_object_wait_priority (obj,0 ,I915_PRIORITY_DEFAULT_DISPBOOST ); + boost =i915_cgroup_get_current_dispboost (dev_priv); +i915_gem_object_wait_priority (obj,0 , boost);mutex_unlock (&dev_priv->drm.struct_mutex);i915_gem_object_unpin_pages (obj);
include/uapi/drm/i915_drm.h +1 -0
@@ -1727,6 +1727,7 @@ struct drm_i915_cgroup_param {__u32 flags;__u64 param;#define I915_CGROUP_PARAM_PRIORITY_OFFSET 0x1 +#define I915_CGROUP_PARAM_DISPBOOST_PRIORITY 0x2__s64 value; };
Signature · 6 lines
2.14.3 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 8/8 drm/i915: Add context priority & priority offset to debugfs (v2)
In reply to Matt RoperUpdate i915_context_status to include priority information.
v2:
- Clarify that the offset is based on cgroup (Chris)
--- drivers/gpu/drm/i915/i915_debugfs.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/gpu/drm/i915/i915_debugfs.c +3 -0
@@ -1959,6 +1959,9 @@ 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 (cgroup offset = %d)\n" , + ctx->priority, ctx->priority_offset); +for_each_engine (engine, dev_priv, id) {struct intel_context *ce = &ctx->engine[engine->id];
Signature · 6 lines
2.14.3 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Patchwork
CI✗ Fi.CI.CHECKPATCH: warning for cgroup private data and DRM/i915 integration (rev3)
In reply to Matt Roper== Series Details ==
== Series Details ==
Series: cgroup private data and DRM/i915 integration (rev3)
URL : https://patchwork.freedesktop.org/series/40142/
State : warning
== Summary ==
$ dim checkpatch origin/drm-tip 8c23fa59eef7 cgroup: Allow registration and lookup of cgroup private data (v3) 95f12a7ecd5d cgroup: Introduce task_get_dfl_cgroup() (v2) b6569483024f cgroup: Introduce cgroup_priv_get_current f8a545376030 drm/i915: Adjust internal priority definitions (v2) 8e4b9162691c drm/i915: cgroup integration (v4) -:36: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating? #36: new file mode 100644
-:280: WARNING:LONG_LINE: line over 100 characters #280: FILE: include/uapi/drm/i915_drm.h:381:
+#define DRM_IOCTL_I915_CGROUP_SETPARAM DRM_IOW(DRM_COMMAND_BASE + DRM_I915_CGROUP_SETPARAM, struct drm_i915_cgroup_param)
total: 0 errors, 2 warnings, 0 checks, 247 lines checked 44858a8e8b6f drm/i915: Introduce 'priority offset' for GPU contexts (v4) -:125: CHECK:MACRO_ARG_REUSE: Macro argument reuse 'def' - possible side-effects? #125: FILE: drivers/gpu/drm/i915/i915_cgroup.c:173:
+#define CGROUP_GET(name, field, def) \
+int i915_cgroup_get_current_##name(struct drm_i915_private *dev_priv) \
+{ \
+ struct kref *ref; \
+ int val = def; \
+ if (!dev_priv->cgroup_priv_key) \
+ return def; \
+ ref = cgroup_priv_get_current(dev_priv->cgroup_priv_key); \
+ if (ref) { \
+ val = cgrp_ref_to_i915(ref)->field; \
+ kref_put(ref, i915_cgroup_free); \
+ } \
+ return val; \
+}
total: 0 errors, 0 warnings, 1 checks, 164 lines checked5909f05aaca5 drm/i915: Introduce per-cgroup display boost setting
-:83: CHECK:LINE_SPACING: Please use a blank line after function/struct/union/enum declarations #83: FILE: drivers/gpu/drm/i915/i915_drv.h:2719:
}
+static inline int
total: 0 errors, 0 warnings, 1 checks, 89 lines checked 5b1782be5720 drm/i915: Add context priority & priority offset to debugfs (v2)
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Patchwork
CI✓ Fi.CI.BAT: success for cgroup private data and DRM/i915 integration (rev3)
In reply to Matt Roper== Series Details ==
== Series Details ==
Series: cgroup private data and DRM/i915 integration (rev3)
URL : https://patchwork.freedesktop.org/series/40142/
State : success
== Summary ==
Series 40142v3 cgroup private data and DRM/i915 integration
https://patchwork.freedesktop.org/api/1.0/series/40142/revisions/3/mbox/
---- Known issues:
Test debugfs_test:
Subgroup read_all_entries:
incomplete -> PASS (fi-snb-2520m) fdo#103713
Test kms_flip:
Subgroup basic-flip-vs-wf_vblank:
fail -> PASS (fi-skl-6770hq) fdo#100368
Test kms_pipe_crc_basic:
Subgroup suspend-read-crc-pipe-c:
pass -> INCOMPLETE (fi-bxt-dsi) fdo#103927fdo#103713 https://bugs.freedesktop.org/show_bug.cgi?id=103713
fdo#100368 https://bugs.freedesktop.org/show_bug.cgi?id=100368
fdo#103927 https://bugs.freedesktop.org/show_bug.cgi?id=103927
fi-bdw-5557u total:285 pass:264 dwarn:0 dfail:0 fail:0 skip:21 time:432s fi-bdw-gvtdvm total:285 pass:261 dwarn:0 dfail:0 fail:0 skip:24 time:448s fi-blb-e6850 total:285 pass:220 dwarn:1 dfail:0 fail:0 skip:64 time:379s fi-bsw-n3050 total:285 pass:239 dwarn:0 dfail:0 fail:0 skip:46 time:540s fi-bwr-2160 total:285 pass:180 dwarn:0 dfail:0 fail:0 skip:105 time:296s fi-bxt-dsi total:243 pass:216 dwarn:0 dfail:0 fail:0 skip:26 fi-bxt-j4205 total:285 pass:256 dwarn:0 dfail:0 fail:0 skip:29 time:514s fi-byt-j1900 total:285 pass:250 dwarn:0 dfail:0 fail:0 skip:35 time:514s fi-byt-n2820 total:285 pass:246 dwarn:0 dfail:0 fail:0 skip:39 time:505s fi-cfl-8700k total:285 pass:257 dwarn:0 dfail:0 fail:0 skip:28 time:411s fi-cfl-s2 total:285 pass:259 dwarn:0 dfail:0 fail:0 skip:26 time:567s fi-cfl-u total:285 pass:259 dwarn:0 dfail:0 fail:0 skip:26 time:511s fi-cnl-drrs total:285 pass:254 dwarn:3 dfail:0 fail:0 skip:28 time:548s fi-cnl-y3 total:285 pass:259 dwarn:0 dfail:0 fail:0 skip:26 time:583s fi-elk-e7500 total:285 pass:225 dwarn:1 dfail:0 fail:0 skip:59 time:426s fi-gdg-551 total:285 pass:176 dwarn:0 dfail:0 fail:1 skip:108 time:314s fi-glk-1 total:285 pass:257 dwarn:0 dfail:0 fail:0 skip:28 time:532s fi-hsw-4770 total:285 pass:258 dwarn:0 dfail:0 fail:0 skip:27 time:408s fi-ilk-650 total:285 pass:225 dwarn:0 dfail:0 fail:0 skip:60 time:422s fi-ivb-3520m total:285 pass:256 dwarn:0 dfail:0 fail:0 skip:29 time:469s fi-ivb-3770 total:285 pass:252 dwarn:0 dfail:0 fail:0 skip:33 time:430s fi-kbl-7500u total:285 pass:260 dwarn:1 dfail:0 fail:0 skip:24 time:475s fi-kbl-7567u total:285 pass:265 dwarn:0 dfail:0 fail:0 skip:20 time:467s fi-kbl-r total:285 pass:258 dwarn:0 dfail:0 fail:0 skip:27 time:513s fi-pnv-d510 total:285 pass:219 dwarn:1 dfail:0 fail:0 skip:65 time:656s fi-skl-6260u total:285 pass:265 dwarn:0 dfail:0 fail:0 skip:20 time:440s fi-skl-6600u total:285 pass:258 dwarn:0 dfail:0 fail:0 skip:27 time:531s fi-skl-6700k2 total:285 pass:261 dwarn:0 dfail:0 fail:0 skip:24 time:497s fi-skl-6770hq total:285 pass:265 dwarn:0 dfail:0 fail:0 skip:20 time:487s fi-skl-guc total:285 pass:257 dwarn:0 dfail:0 fail:0 skip:28 time:426s fi-skl-gvtdvm total:285 pass:262 dwarn:0 dfail:0 fail:0 skip:23 time:449s fi-snb-2520m total:285 pass:245 dwarn:0 dfail:0 fail:0 skip:40 time:589s fi-snb-2600 total:285 pass:245 dwarn:0 dfail:0 fail:0 skip:40 time:404s
dff9ece60048108782aab6d6123822c1d34b0e5a drm-tip: 2018y-03m-21d-20h-44m-14s UTC integration manifest 5b1782be5720 drm/i915: Add context priority & priority offset to debugfs (v2) 5909f05aaca5 drm/i915: Introduce per-cgroup display boost setting44858a8e8b6f drm/i915: Introduce 'priority offset' for GPU contexts (v4) 8e4b9162691c drm/i915: cgroup integration (v4)f8a545376030 drm/i915: Adjust internal priority definitions (v2)b6569483024f cgroup: Introduce cgroup_priv_get_current95f12a7ecd5d cgroup: Introduce task_get_dfl_cgroup() (v2)8c23fa59eef7 cgroup: Allow registration and lookup of cgroup private data (v3)
== Logs ==
For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_8442/issues.html
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Patchwork
CI✓ Fi.CI.IGT: success for cgroup private data and DRM/i915 integration (rev3)
In reply to Matt Roper== Series Details ==
== Series Details ==
Series: cgroup private data and DRM/i915 integration (rev3)
URL : https://patchwork.freedesktop.org/series/40142/
State : success
== Summary ==
---- Known issues:
Test kms_flip:
Subgroup 2x-flip-vs-expired-vblank:
pass -> FAIL (shard-hsw) fdo#102887
Subgroup 2x-plain-flip-ts-check-interruptible:
pass -> FAIL (shard-hsw) fdo#100368 +2
Subgroup dpms-vs-vblank-race-interruptible:
pass -> FAIL (shard-hsw) fdo#103060
Test kms_frontbuffer_tracking:
Subgroup fbc-rgb101010-draw-pwrite:
pass -> FAIL (shard-apl) fdo#101623
Test kms_setmode:
Subgroup basic:
pass -> FAIL (shard-apl) fdo#99912
Test kms_sysfs_edid_timing:
pass -> WARN (shard-apl) fdo#100047fdo#102887 https://bugs.freedesktop.org/show_bug.cgi?id=102887
fdo#100368 https://bugs.freedesktop.org/show_bug.cgi?id=100368
fdo#103060 https://bugs.freedesktop.org/show_bug.cgi?id=103060
fdo#101623 https://bugs.freedesktop.org/show_bug.cgi?id=101623
fdo#99912 https://bugs.freedesktop.org/show_bug.cgi?id=99912
fdo#100047 https://bugs.freedesktop.org/show_bug.cgi?id=100047
shard-apl total:3478 pass:1813 dwarn:1 dfail:0 fail:8 skip:1655 time:13047s shard-hsw total:3478 pass:1764 dwarn:1 dfail:0 fail:5 skip:1707 time:11801s shard-snb total:3478 pass:1357 dwarn:1 dfail:0 fail:3 skip:2117 time:7275s
Blacklisted hosts:
shard-kbl total:3478 pass:1933 dwarn:7 dfail:0 fail:10 skip:1528 time:9963s
== Logs ==
For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_8442/shards.html
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Jani Nikula
maintainerRe: ✗ Fi.CI.CHECKPATCH: warning for cgroup private data and DRM/i915 integration (rev3)
In reply to PatchworkQuoted 26 lines · Patchwork
== Series Details ==
Series: cgroup private data and DRM/i915 integration (rev3)
URL : https://patchwork.freedesktop.org/series/40142/
State : warning== Summary ==
$ dim checkpatch origin/drm-tip 8c23fa59eef7 cgroup: Allow registration and lookup of cgroup private data (v3) 95f12a7ecd5d cgroup: Introduce task_get_dfl_cgroup() (v2) b6569483024f cgroup: Introduce cgroup_priv_get_current f8a545376030 drm/i915: Adjust internal priority definitions (v2) 8e4b9162691c drm/i915: cgroup integration (v4) -:36: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating? #36: new file mode 100644-:280: WARNING:LONG_LINE: line over 100 characters #280: FILE:
include/uapi/drm/i915_drm.h:381:
+#defineDRM_IOCTL_I915_CGROUP_SETPARAMDRM_IOW(DRM_COMMAND_BASE + DRM_I915_CGROUP_SETPARAM, struct drm_i915_cgroup_param)total: 0 errors, 2 warnings, 0 checks, 247 lines checked
44858a8e8b6fdrm/i915: Introduce 'priority offset' for GPU contexts (v4) -:125: CHECK:MACRO_ARG_REUSE: Macro argument reuse 'def' - possible side-effects? #125: FILE:drivers/gpu/drm/i915/i915_cgroup.c:173:
Review
Quoted 7 lines
(quoted diff) +7
-0+#define CGROUP_GET(name, field, def) \ +int i915_cgroup_get_current_##name(struct drm_i915_private *dev_priv) \ +{ \ + struct kref *ref; \ + int val = def; \ + if (!dev_priv->cgroup_priv_key) \ + return def; \
Could return val here to only use def once. Even though none of the macro instantiations use side-effects. No biggie.
BR,
Jani.
Quoted 22 lines
(quoted diff) +7
-0+ ref = cgroup_priv_get_current(dev_priv->cgroup_priv_key); \ + if (ref) { \ + val = cgrp_ref_to_i915(ref)->field; \ + kref_put(ref, i915_cgroup_free); \ + } \ + return val; \ +}total: 0 errors, 0 warnings, 1 checks, 164 lines checked
5909f05aaca5drm/i915: Introduce per-cgroup display boost setting
-:83: CHECK:LINE_SPACING: Please use a blank line after function/struct/union/enum declarations #83: FILE:drivers/gpu/drm/i915/i915_drv.h:2719:
}
+static inline inttotal: 0 errors, 0 warnings, 1 checks, 89 lines checked
5b1782be5720drm/i915: Add context priority & priority offset to debugfs (v2)_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 5 lines
Jani Nikula, Intel Open Source Technology Center _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v4.5 1/8] cgroup: Allow registration and lookup of cgroup private data (v3)
In reply to Matt RoperQuoting Matt Roper (2018-03-21 23:23:37)
Quoted 83 lines
There are cases where other parts of the kernel may wish to store data associated with individual cgroups without building a full cgroup controller. Let's add interfaces to allow them to register and lookup this private data for individual cgroups.
A kernel system (e.g., a driver) that wishes to register private data for a cgroup should start by obtaining a unique private data key by calling
cgroup_priv_getkey(). It may then associate private data with a cgroup by callingcgroup_priv_install(cgrp, key, ref)where 'ref' is a pointer to a kref field inside the private data structure. The private data may later be looked up by callingcgroup_priv_get(cgrp, key)to obtain a new reference to the private data. Private data may be unregistered viacgroup_priv_release(cgrp, key).If a cgroup is removed, the reference count for all private data objects will be decremented.
v2: Significant overhaul suggested by Tejun, Alexei, and Roman
- Rework interface to make consumers obtain an ida-based key rather than supplying their own arbitrary void*
- Internal implementation now uses per-cgroup radixtrees which should allow much faster lookup than the previous hashtable approach
- Private data is registered via kref, allowing a single private data structure to potentially be assigned to multiple cgroups.v3:
- Spare warning fixes (kbuild test robot)Cc Tejun Heo <[email protected]>Cc Alexei Starovoitov <[email protected]>Cc Roman Gushchin <[email protected]>Signed-off-by Matt Roper <[email protected]>fixup! cgroup: Allow registration and lookup of cgroup private data (v2)
--- include/linux/cgroup-defs.h | 10 +++ include/linux/cgroup.h | 7 ++ kernel/cgroup/cgroup.c | 183 +++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 198 insertions(+), 2 deletions(-)include/linux/cgroup-defs.h +10
-0@@ -427,6 +427,16 @@ struct cgroup {/* used to store eBPF programs */ struct cgroup_bpf bpf; +/* +* cgroup private data registered by other non-controller parts of the +* kernel. Insertions are protected by privdata_lock, lookups by +* rcu_read_lock(). +*/ +struct radix_tree_root privdata; + +/* Protect against concurrent insertions/deletions to privdata */ +spinlock_t privdata_lock; +/* ids of the ancestors at each level including self */ int ancestor_ids[]; };include/linux/cgroup.h +7
-0@@ -833,4 +833,11 @@ static inline void put_cgroup_ns(struct cgroup_namespace *ns) free_cgroup_ns(ns); } +/* cgroup private data handling */ +int cgroup_priv_getkey (void (*free)(struct kref *)); +void cgroup_priv_destroykey (int key); +int cgroup_priv_install (struct cgroup *cgrp,int key,struct kref *ref); +struct kref *cgroup_priv_get (struct cgroup *cgrp,int key); +void cgroup_priv_release (struct cgroup *cgrp,int key); +#endif /* _LINUX_CGROUP_H */ kernel/cgroup/cgroup.c +0
-0
kernel/cgroup/cgroup.c EXPORT_SYMBOL_GPL(css_set_lock); · line 88
Quoted 10 lines
kernel/cgroup/cgroup.c +5
-2@@ -81,8 +81,15 @@ EXPORT_SYMBOL_GPL(css_set_lock);#endif /* -* Protects cgroup_idr and css_idr so that IDs can be released without -* grabbing cgroup_mutex. +* ID allocator for cgroup private data keys; the ID's allocated here will +* be used to index all per-cgroup radix trees. The radix tree built into +* the IDR itself will store a key-specific function to be passed to kref_put. +*/ +static DEFINE_IDR (cgroup_priv_idr);
Fun two radixtrees, one to hold the (*free)() and the other the void*.
Would not just a
struct cgroup_privdata {
struct rcu_head rcu;
void (*free)(struct kref *);
}suffice for subclassing? (Also this is a prime candidate for switching to XArray.)
kernel/cgroup/cgroup.c static int __init cgroup_sysfs_init(void) · line 6074
Quoted 13 lines
kernel/cgroup/cgroup.c +13
-0+struct kref * +cgroup_priv_get (struct cgroup *cgrp,int key) +{ +struct kref *ref; + +WARN_ON (cgrp->root != &cgrp_dfl_root); +WARN_ON (key ==0 ); + +rcu_read_lock (); + + ref =radix_tree_lookup (&cgrp->privdata, key); +if (ref) +kref_get (ref);
This is not safe, you need
if (ref && !kref_get_unless_zero(ref))
ref = NULL;
otherwise the cgroup_priv_release() may drop the last reference prior to you obtaining yours. Also requires the privdata to be RCU protected. -Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx