@@ -128,3 +128,27 @@ drm_clients_migrate(struct drm_file *file_priv,
atomic_inc(&clients->num);
list_add_tail_rcu(&file_priv->clink, &clients->file_list);
}
+
+u64 drm_pid_get_active_time_us(struct pid *pid)
+{
+ struct drm_pid_clients *clients;
+ u64 total = 0;
+
+ rcu_read_lock();
+ clients = xa_load(&drm_pid_clients, (unsigned long)pid);
+ if (clients) {
+ struct drm_file *fpriv;
+
+ list_for_each_entry_rcu(fpriv, &clients->file_list, clink) {
+ const struct drm_cgroup_ops *cg_ops =
+ fpriv->minor->dev->driver->cg_ops;
+
+ if (cg_ops && cg_ops->active_time_us)
+ total += cg_ops->active_time_us(fpriv);
+ }
+ }
+ rcu_read_unlock();
+
+ return total;
+}
+EXPORT_SYMBOL_GPL(drm_pid_get_active_time_us);
@@ -41,4 +41,6 @@ drm_clients_migrate(struct drm_file *file_priv,
}
#endif
+u64 drm_pid_get_active_time_us(struct pid *pid);
+
#endif
@@ -148,6 +148,24 @@ enum drm_driver_feature {
DRIVER_KMS_LEGACY_CONTEXT = BIT(31),
};
+/**
+ * struct drm_cgroup_ops
+ *
+ * This structure contains a number of callbacks that drivers can provide if
+ * they are able to support one or more of the functionalities implemented by
+ * the DRM cgroup controller.
+ */
+struct drm_cgroup_ops {
+ /**
+ * @active_time_us:
+ *
+ * Optional callback for reporting the GPU time consumed by this client.
+ *
+ * Used by the DRM core when queried by the DRM cgroup controller.
+ */
+ u64 (*active_time_us) (struct drm_file *);
+};
+
/**
* struct drm_driver - DRM driver structure
*
@@ -459,6 +477,16 @@ struct drm_driver {
*/
const struct file_operations *fops;
+#ifdef CONFIG_CGROUP_DRM
+ /**
+ * @cg_ops:
+ *
+ * Optional pointer to driver callbacks facilitating integration with
+ * the DRM cgroup controller.
+ */
+ const struct drm_cgroup_ops *cg_ops;
+#endif
+
#ifdef CONFIG_DRM_LEGACY
/* Everything below here is for legacy driver, never use! */
/* private: */