Hi,
On 23/01/2023 15:42, Michal Koutný wrote:
Hello Tvrtko.
Interesting work.
Thanks!
On Thu, Jan 12, 2023 at 04:55:57PM +0000, Tvrtko Ursulin <tvrtko.ursulin@xxxxxxxxxxxxxxx> wrote:
Because of the heterogenous hardware and driver DRM capabilities, soft limits
are implemented as a loose co-operative (bi-directional) interface between the
controller and DRM core.
IIUC, this periodic scanning, calculating and applying could be partly
implemented with userspace utilities. (As you write, these limits are
best effort only, so it sounds to me such a total implementation is
unnecessary.)
I don't immediately see how you envisage the half-userspace
implementation would look like in terms of what functionality/new APIs
would be provided by the kernel?
I think a better approach would be to avoid the async querying and
instead require implementing explicit foo_charge_time(client, dur) API
(similar to how other controllers achieve this).
Your argument is the heterogenity of devices -- does it mean there are
devices/drivers that can't implement such a synchronous charging?
Problem there is to find a suitable point to charge at. If for a moment
we limit the discussion to i915, out of the box we could having charging
happening at several thousand times per second to effectively never.
This is to illustrate the GPU context execution dynamics which range
from many small packets of work to multi-minute, or longer. For the
latter to be accounted for we'd still need some periodic scanning, which
would then perhaps go per driver. For the former we'd have thousands of
needless updates per second.
Hence my thinking was to pay both the cost of accounting and collecting
the usage data once per actionable event, where the latter is controlled
by some reasonable scanning period/frequency.
In addition to that, a few DRM drivers already support GPU usage
querying via fdinfo, so that being externally triggered, it is next to
trivial to wire all those DRM drivers into such common DRM cgroup
controller framework. All that every driver needs to implement on top is
the "over budget" callback.
DRM core provides an API to query per process GPU utilization and 2nd API to
receive notification from the cgroup controller when the group enters or exits
the over budget condition.
The return value of foo_charge_time() would substitute such a
notification synchronously. (By extension all clients in an affected
cgroup could be notified to achieve some broader actions.)
Right, it is doable in theory, but as mention above some rate limit
would have to be added. And the notification would still need to have
unused budget propagation through the tree, so it wouldn't work to
localize the action to the single cgroup (the one getting the charge).
Individual DRM drivers which implement the interface are expected to act on this
in the best-effort manner only. There are no guarantees that the soft limits
will be respected.
Back to original concern -- must all code reside in the kernel when it's
essentially advisory resource control?
* DRM core is required to track all DRM clients belonging to processes so it
can answer when asked how much GPU time is a process using.
[...]
* Individual drivers need to implement two similar hooks, but which work for
a single DRM client. Over budget callback and GPU utilisation query.
This information is eventually aggregated for each process in a cgroup.
(And the action is carried on a single client, not a process.)
The per-process tracking seems like an additional indirection.
Could be the clients associated directly with DRM cgroup? [1]
I think you could be right here - with some deeper integration with the
cgroup subsystem this could probably be done. It would require moving
the list of drm clients into the cgroup css state itself. Let me try and
sketch that out in the following weeks because it would be a nice
simplification if it indeed worked out.
Regards,
Tvrtko
Regards,
Michal
[1] I understand the sending a fd of a client is a regular operation, so
I'm not sure how cross-cg migrations would have to be handled in any
case.