@@ -930,6 +930,12 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags)
if (drm_dev_needs_global_mutex(dev))
mutex_lock(&drm_global_mutex);
+ ret = drmm_cgroup_register_device(dev, &dev->cg);
+ if (ret) {
+ DRM_ERROR("Cannot create cgroup device.\n");
+ goto out_unlock;
+ }
+
if (drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL))
accel_debugfs_register(dev);
else
@@ -937,7 +943,7 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags)
ret = drm_minor_register(dev, DRM_MINOR_RENDER);
if (ret)
- goto err_minors;
+ goto out_unregister_cgroup;
ret = drm_minor_register(dev, DRM_MINOR_PRIMARY);
if (ret)
@@ -982,6 +988,8 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags)
drm_minor_unregister(dev, DRM_MINOR_ACCEL);
drm_minor_unregister(dev, DRM_MINOR_PRIMARY);
drm_minor_unregister(dev, DRM_MINOR_RENDER);
+out_unregister_cgroup:
+ dev_cgroup_unregister_device(&dev->cg);
out_unlock:
if (drm_dev_needs_global_mutex(dev))
mutex_unlock(&drm_global_mutex);
@@ -1024,6 +1032,7 @@ void drm_dev_unregister(struct drm_device *dev)
drm_minor_unregister(dev, DRM_MINOR_PRIMARY);
drm_minor_unregister(dev, DRM_MINOR_RENDER);
drm_debugfs_dev_fini(dev);
+ dev_cgroup_unregister_device(&dev->cg);
}
EXPORT_SYMBOL(drm_dev_unregister);
@@ -110,6 +110,10 @@ drm_gem_init(struct drm_device *dev)
DRM_FILE_PAGE_OFFSET_START,
DRM_FILE_PAGE_OFFSET_SIZE);
+ dev->cg.regions[0].size = U64_MAX;
+ dev->cg.regions[0].name = "gem";
+ dev->cg.num_regions++;
+
return drmm_add_action(dev, drm_gem_init_release, NULL);
}
@@ -106,6 +106,10 @@ __drm_gem_dma_create(struct drm_device *drm, size_t size, bool private)
goto error;
}
+ ret = dev_cgroup_try_charge(&drm->cg, 0, size, &dma_obj->base.cgroup_pool_state, NULL);
+ if (ret)
+ goto error;
+
return dma_obj;
error:
@@ -1,6 +1,7 @@
#ifndef _DRM_DEVICE_H_
#define _DRM_DEVICE_H_
+#include <linux/cgroup_dev.h>
#include <linux/list.h>
#include <linux/kref.h>
#include <linux/mutex.h>
@@ -317,6 +318,9 @@ struct drm_device {
* Root directory for debugfs files.
*/
struct dentry *debugfs_root;
+
+ /** @cg: device cgroup bookkeeping */
+ struct dev_cgroup_device cg;
};
#endif
@@ -430,6 +430,8 @@ struct drm_gem_object {
* The current LRU list that the GEM object is on.
*/
struct drm_gem_lru *lru;
+
+ struct dev_cgroup_pool_state *cgroup_pool_state;
};
/**