From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: Intel-gfx@lists.freedesktop.org
Cc: "Rob Clark" <robdclark@chromium.org>,
Kenny.Ho@amd.com, "Daniel Vetter" <daniel.vetter@ffwll.ch>,
"Johannes Weiner" <hannes@cmpxchg.org>,
linux-kernel@vger.kernel.org,
"Stéphane Marchesin" <marcheu@chromium.org>,
"Christian König" <christian.koenig@amd.com>,
"Zefan Li" <lizefan.x@bytedance.com>,
"Dave Airlie" <airlied@redhat.com>, "Tejun Heo" <tj@kernel.org>,
cgroups@vger.kernel.org, "T . J . Mercier" <tjmercier@google.com>
Subject: [Intel-gfx] [RFC 14/17] cgroup/drm: Show group budget signaling capability in sysfs
Date: Wed, 19 Oct 2022 18:32:51 +0100 [thread overview]
Message-ID: <20221019173254.3361334-15-tvrtko.ursulin@linux.intel.com> (raw)
In-Reply-To: <20221019173254.3361334-1-tvrtko.ursulin@linux.intel.com>
From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Show overall status of a task group - whether all DRM clients in a group
support over budget signaling, or some do not, or if there are no DRM
clients in the group to start with.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
Documentation/admin-guide/cgroup-v2.rst | 7 ++++
drivers/gpu/drm/drm_cgroup.c | 33 ++++++++++++++++
include/drm/drm_clients.h | 7 ++++
include/drm/drm_drv.h | 11 +++++-
kernel/cgroup/drm.c | 52 +++++++++++++++++++++++++
5 files changed, 109 insertions(+), 1 deletion(-)
diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst
index 318f463a1316..6ee94ee109f0 100644
--- a/Documentation/admin-guide/cgroup-v2.rst
+++ b/Documentation/admin-guide/cgroup-v2.rst
@@ -2491,6 +2491,13 @@ DRM scheduling soft limits interface files
signal.
Value of zero (defaul) disables the soft limit checking.
+ drm.budget_supported
+ One of:
+ 1) 'yes' - when all DRM clients in the group support the functionality.
+ 2) 'no' - when at least one of the DRM clients does not support the
+ functionality.
+ 3) 'n/a' - when there are no DRM clients in the group.
+
Misc
----
diff --git a/drivers/gpu/drm/drm_cgroup.c b/drivers/gpu/drm/drm_cgroup.c
index ff99d1f4f1d4..d2d8b2cb4ab3 100644
--- a/drivers/gpu/drm/drm_cgroup.c
+++ b/drivers/gpu/drm/drm_cgroup.c
@@ -259,3 +259,36 @@ void drm_pid_signal_budget(struct pid *pid, u64 usage, u64 budget)
rcu_read_unlock();
}
EXPORT_SYMBOL_GPL(drm_pid_signal_budget);
+
+enum drm_cg_supported drm_pid_signal_budget_supported(struct pid *pid)
+{
+ enum drm_cg_supported supported = DRM_CG_NOT_APPLICABLE;
+ struct drm_pid_clients *clients;
+
+ 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 ||
+ !cg_ops->signal_budget ||
+ cg_ops->signal_budget(fpriv, 0, 0) < 0) {
+ supported = DRM_CG_NOT_SUPPORTED;
+ break;
+ }
+
+ if (supported == DRM_CG_NOT_APPLICABLE)
+ supported = DRM_CG_SUPPORTED;
+
+ }
+ }
+ rcu_read_unlock();
+
+ return supported;
+}
+EXPORT_SYMBOL_GPL(drm_pid_signal_budget_supported);
diff --git a/include/drm/drm_clients.h b/include/drm/drm_clients.h
index 7ad09fd0a404..5d14ae26ece6 100644
--- a/include/drm/drm_clients.h
+++ b/include/drm/drm_clients.h
@@ -14,6 +14,12 @@ struct drm_pid_clients {
struct rcu_head rcu;
};
+enum drm_cg_supported {
+ DRM_CG_NOT_APPLICABLE = -1,
+ DRM_CG_NOT_SUPPORTED = 0,
+ DRM_CG_SUPPORTED
+};
+
#if IS_ENABLED(CONFIG_CGROUP_DRM)
void drm_clients_close(struct drm_file *file_priv);
int drm_clients_open(struct drm_file *file_priv);
@@ -39,5 +45,6 @@ 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);
void drm_pid_signal_budget(struct pid *pid, u64 usage, u64 budget);
+enum drm_cg_supported drm_pid_signal_budget_supported(struct pid *pid);
#endif
diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h
index 07dec956ebfb..7a1a20d1b8de 100644
--- a/include/drm/drm_drv.h
+++ b/include/drm/drm_drv.h
@@ -198,8 +198,17 @@ struct drm_cgroup_ops {
*
* Optional callback used by the DRM core to forward over/under GPU time
* messages sent by the DRM cgroup controller.
+ *
+ * Zero used with zero budget is a special budgeting support status
+ * query which needs to return either zero or -EINVAL if client does not
+ * support budget control.
+ *
+ * Returns:
+ * * 1 when client has been throttled.
+ * * 0 when no action has been taken.
+ * * -EINVAL when not supported by the client.
*/
- void (*signal_budget) (struct drm_file *, u64 used, u64 budget);
+ int (*signal_budget) (struct drm_file *, u64 used, u64 budget);
};
/**
diff --git a/kernel/cgroup/drm.c b/kernel/cgroup/drm.c
index af50ead1564a..dd7db70c2831 100644
--- a/kernel/cgroup/drm.c
+++ b/kernel/cgroup/drm.c
@@ -239,6 +239,53 @@ drmcs_write_weight(struct cgroup_subsys_state *css, struct cftype *cftype,
return 0;
}
+static int drmcs_show_budget_supported(struct seq_file *sf, void *v)
+{
+ struct drm_cgroup_state *drmcs = css_to_drmcs(seq_css(sf));
+ enum drm_cg_supported overall = DRM_CG_NOT_APPLICABLE;
+ struct cgroup *cgrp = drmcs->css.cgroup;
+ struct task_struct *task;
+ struct css_task_iter it;
+
+ css_task_iter_start(&cgrp->self,
+ CSS_TASK_ITER_PROCS | CSS_TASK_ITER_THREADED,
+ &it);
+ while ((task = css_task_iter_next(&it))) {
+ enum drm_cg_supported supported;
+
+ /* Ignore kernel threads here. */
+ if (task->flags & PF_KTHREAD)
+ continue;
+
+ supported = drm_pid_signal_budget_supported(task_pid(task));
+ if (supported == DRM_CG_SUPPORTED &&
+ overall == DRM_CG_NOT_APPLICABLE) {
+ overall = DRM_CG_SUPPORTED;
+ } else if (supported == DRM_CG_NOT_SUPPORTED) {
+ overall = DRM_CG_NOT_SUPPORTED;
+ break;
+ }
+ }
+ css_task_iter_end(&it);
+
+ switch (overall) {
+ case DRM_CG_NOT_APPLICABLE:
+ seq_puts(sf, "n/a\n");
+ break;
+ case DRM_CG_NOT_SUPPORTED:
+ seq_puts(sf, "no\n");
+ break;
+ case DRM_CG_SUPPORTED:
+ seq_puts(sf, "yes\n");
+ break;
+ default:
+ seq_printf(sf, "%u\n", overall);
+ break;
+ }
+
+ return 0;
+}
+
static int drmcs_online(struct cgroup_subsys_state *css)
{
struct drm_cgroup_state *drmcs = css_to_drmcs(css);
@@ -690,6 +737,11 @@ struct cftype files[] = {
.read_u64 = drmcs_read_weight,
.write_u64 = drmcs_write_weight,
},
+ {
+ .name = "budget_supported",
+ .flags = CFTYPE_NOT_ON_ROOT,
+ .seq_show = drmcs_show_budget_supported,
+ },
{
.name = "period_us",
.flags = CFTYPE_NOT_ON_ROOT,
--
2.34.1
next prev parent reply other threads:[~2022-10-19 17:34 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-19 17:32 [Intel-gfx] [RFC 00/17] DRM scheduling cgroup controller Tvrtko Ursulin
2022-10-19 17:32 ` [Intel-gfx] [RFC 01/17] cgroup: Add the DRM " Tvrtko Ursulin
2022-10-19 17:32 ` [Intel-gfx] [RFC 02/17] drm: Track clients per owning process Tvrtko Ursulin
2022-10-20 6:40 ` Christian König
2022-10-20 7:34 ` Tvrtko Ursulin
2022-10-20 11:33 ` Christian König
2022-10-27 14:35 ` Tvrtko Ursulin
2022-10-19 17:32 ` [Intel-gfx] [RFC 03/17] cgroup/drm: Support cgroup priority control Tvrtko Ursulin
2022-10-19 17:32 ` [Intel-gfx] [RFC 04/17] drm/cgroup: Allow safe external access to file_priv Tvrtko Ursulin
2022-10-19 17:32 ` [Intel-gfx] [RFC 05/17] drm: Connect priority updates to drm core Tvrtko Ursulin
2022-10-19 17:32 ` [Intel-gfx] [RFC 06/17] drm: Only track clients which are providing drm_cgroup_ops Tvrtko Ursulin
2022-10-19 17:32 ` [Intel-gfx] [RFC 07/17] drm/i915: i915 priority Tvrtko Ursulin
2022-10-19 17:32 ` [Intel-gfx] [RFC 08/17] drm: Allow for migration of clients Tvrtko Ursulin
2022-10-19 17:32 ` [Intel-gfx] [RFC 09/17] cgroup/drm: Introduce weight based drm cgroup control Tvrtko Ursulin
2022-10-19 17:32 ` [Intel-gfx] [RFC 10/17] drm: Add ability to query drm cgroup GPU time Tvrtko Ursulin
2022-10-19 17:32 ` [Intel-gfx] [RFC 11/17] drm: Add over budget signalling callback Tvrtko Ursulin
2022-10-19 17:32 ` [Intel-gfx] [RFC 12/17] cgroup/drm: Client exit hook Tvrtko Ursulin
2022-10-19 17:32 ` [Intel-gfx] [RFC 13/17] cgroup/drm: Ability to periodically scan cgroups for over budget GPU usage Tvrtko Ursulin
2022-10-21 22:52 ` T.J. Mercier
2022-10-27 14:45 ` Tvrtko Ursulin
2022-10-19 17:32 ` Tvrtko Ursulin [this message]
2022-10-19 17:32 ` [Intel-gfx] [RFC 15/17] drm/i915: Migrate client to new owner on context create Tvrtko Ursulin
2022-10-19 17:32 ` [Intel-gfx] [RFC 16/17] drm/i915: Wire up with drm controller GPU time query Tvrtko Ursulin
2022-10-19 17:32 ` [Intel-gfx] [RFC 17/17] drm/i915: Implement cgroup controller over budget throttling Tvrtko Ursulin
2022-10-19 18:45 ` [Intel-gfx] [RFC 00/17] DRM scheduling cgroup controller Tejun Heo
2022-10-27 14:32 ` Tvrtko Ursulin
2022-10-31 20:20 ` Tejun Heo
2022-11-09 16:59 ` Tvrtko Ursulin
2022-10-19 19:25 ` [Intel-gfx] ✗ Fi.CI.BUILD: failure for " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221019173254.3361334-15-tvrtko.ursulin@linux.intel.com \
--to=tvrtko.ursulin@linux.intel.com \
--cc=Intel-gfx@lists.freedesktop.org \
--cc=Kenny.Ho@amd.com \
--cc=airlied@redhat.com \
--cc=cgroups@vger.kernel.org \
--cc=christian.koenig@amd.com \
--cc=daniel.vetter@ffwll.ch \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lizefan.x@bytedance.com \
--cc=marcheu@chromium.org \
--cc=robdclark@chromium.org \
--cc=tj@kernel.org \
--cc=tjmercier@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox