@@ -206,3 +206,27 @@ void drm_pid_update_priority(struct pid *pid, int priority)
rcu_read_unlock();
}
EXPORT_SYMBOL_GPL(drm_pid_update_priority);
+
+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);
@@ -37,5 +37,6 @@ static inline void drm_clients_migrate(struct drm_file *file_priv)
unsigned int drm_pid_priority_levels(struct pid *pid, bool *non_uniform);
void drm_pid_update_priority(struct pid *pid, int priority);
+u64 drm_pid_get_active_time_us(struct pid *pid);
#endif
@@ -183,6 +183,15 @@ struct drm_cgroup_ops {
* priorities of already running workloads.
*/
void (*update_priority) (struct drm_file *, int priority);
+
+ /**
+ * @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 *);
};
/**