Message ID | 20221019173254.3361334-1-tvrtko.ursulin@linux.intel.com |
---|---|
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp451948wrs; Wed, 19 Oct 2022 10:37:55 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5VONthce+eVnz7v+7rR1g1FgXKHbfxQuHGU3dUydwwb67n7CBohfET0P3WRxO/ZgbeInBU X-Received: by 2002:a17:907:969e:b0:791:9ba2:497f with SMTP id hd30-20020a170907969e00b007919ba2497fmr7814393ejc.8.1666201074874; Wed, 19 Oct 2022 10:37:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666201074; cv=none; d=google.com; s=arc-20160816; b=ZnjTe/umghsoGZWFLjbDNoN7mHc7AAUGTaWkWji91WnD7K7aK4gAw08T2TYpVTWelB L/n8eJ1jhFNj0R3tXh9bmibrCarh08ya+usnE9jvb/vySrlfguhpsmsyPnuXy8CxJKO6 M848vdHpQKpkJCcwQEFdY9gDIUFPgFTeW59yo9QlS7LqZLkc2oSYFUIn7oezmZI8MnFZ ozry4pheYc51cBlAfTP3eRBx1QUwL6Yncbu9wiEdsB7tO0DhRALIIZpXpTXHRXCtphu8 15AzyScXA2qDlHly8ciG51i3bEMXxqLjlJikSocg+XrVtQ06C8dQn0PNElHudZrcSO+d I1Cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=hyDIBDEXu+Og+WtyximeUtLVQfTDS6d2CD1M+FeiZtE=; b=BdHm2W+EnSZ8hy2opIa6rgCQfP+5J98c6nzW+0AKnaDb00xfsyEMbgtiIsNhuFjFMn a/mnrV1eCgI0hpTNgjVABRX3zxMA6+csNR4bEC4ez19kf0CBW85bqTPaCkEWagAqYrQM yuk60vQjSafupqMBe/PXX425uGVjkjuHOm+vHG2PMUhbIwPFLqkxGe6aW0FW3NVnh0Ki 8OActLVSNGjoqxAh5qhK6b8IB/aEkVM+fOuFgk7aZ6boFKN4XGoKTBgU33ekQ9LVo+L4 8YC4wdK6qjs6EiQlCoz9t0YRsjyPv1+AT6zocKrmUqla+i+tyOhkZ6r51aGQVVTxPC0M hR/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=LedX074F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id rn25-20020a170906d93900b0076f061ffab4si11410360ejb.51.2022.10.19.10.37.29; Wed, 19 Oct 2022 10:37:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=LedX074F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229914AbiJSRdY (ORCPT <rfc822;samuel.l.nystrom@gmail.com> + 99 others); Wed, 19 Oct 2022 13:33:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229491AbiJSRdW (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 19 Oct 2022 13:33:22 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E77631C19D5; Wed, 19 Oct 2022 10:33:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1666200801; x=1697736801; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=1rzbHXSDTF9kSQKAGkXBlCWE2acf03cl0S7cxgjoDng=; b=LedX074FKPQ+NBNfF7wisdPWniB33HEkVk27vUt6q5+0uDYYNrxtS8l9 eodGRypbVDYOFY4c2pjF4dXGX8O+Xq1QrMyVR29GfXo2qb0OBUK7a/6VB jHKRImXHMElLjO5XWT5FNSDJ0AyNYPJb4XFe8uYSrEUoCgKRHVRJDPtZN ZPyJHxw7CV90d0oZDDF891p+nD2aElSkyzyj9SxWX2YGa+9UUv1k7Bkco k5zK3sVF4bQMEBe4H2Q2I95N1b8kfEo6bFhIN8i8HOm1vi4U24WtQpuxZ osDTGFYw3OLRfEfpXWmYXnA73F2KTsjovsdI55/J1D/r+3nSR+TAXM7FV g==; X-IronPort-AV: E=McAfee;i="6500,9779,10505"; a="306474266" X-IronPort-AV: E=Sophos;i="5.95,196,1661842800"; d="scan'208";a="306474266" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Oct 2022 10:33:20 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10505"; a="607204657" X-IronPort-AV: E=Sophos;i="5.95,196,1661842800"; d="scan'208";a="607204657" Received: from mjmcener-mobl1.amr.corp.intel.com (HELO localhost.localdomain) ([10.213.233.40]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Oct 2022 10:33:15 -0700 From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com> To: Intel-gfx@lists.freedesktop.org Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Tejun Heo <tj@kernel.org>, Johannes Weiner <hannes@cmpxchg.org>, Zefan Li <lizefan.x@bytedance.com>, Dave Airlie <airlied@redhat.com>, Daniel Vetter <daniel.vetter@ffwll.ch>, Rob Clark <robdclark@chromium.org>, =?utf-8?q?St=C3=A9phane_Marchesin?= <marcheu@chromium.org>, "T . J . Mercier" <tjmercier@google.com>, Kenny.Ho@amd.com, =?utf-8?q?Chris?= =?utf-8?q?tian_K=C3=B6nig?= <christian.koenig@amd.com>, Brian Welty <brian.welty@intel.com>, Tvrtko Ursulin <tvrtko.ursulin@intel.com> Subject: [RFC 00/17] DRM scheduling cgroup controller Date: Wed, 19 Oct 2022 18:32:37 +0100 Message-Id: <20221019173254.3361334-1-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,HK_RANDOM_ENVFROM,HK_RANDOM_FROM, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747138458116114373?= X-GMAIL-MSGID: =?utf-8?q?1747138458116114373?= |
Series |
DRM scheduling cgroup controller
|
|
Message
Tvrtko Ursulin
Oct. 19, 2022, 5:32 p.m. UTC
From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
This series contains two independent proposals for a DRM scheduling cgroup
controller: static priority based controller and GPU usage budget based
controller.
Motivation mostly comes from my earlier proposal where I identified that GPU
scheduling lags significantly behind what is available for CPU and IO. Whereas
back then I was proposing to somehow tie this with process nice, feedback mostly
was that people wanted cgroups. So here it is - in the world of heterogenous
computing pipelines I think it is time to do something about this gap.
Code is not finished but should survive some light experimenting with. I am
sharing it early since the topic has been controversial in the past. I hope to
demonstrate there are gains to be had in real world usage(*), today, and that
the concepts the proposal relies are well enough established and stable.
*) Specifically under ChromeOS which uses cgroups to control CPU bandwith for
VMs based on the window focused status. It can be demonstrated how GPU
scheduling control can easily be integrated into that setup.
There should be no conflict with this proposal and any efforts to implement
memory usage based controller. Skeleton DRM cgroup controller is deliberatly
purely a skeleton patch where any further functionality can be added with no
real conflicts. [In fact, perhaps scheduling is even easier to deal with than
memory accounting.]
To re-iterate, two proposal are completely functionaly independent and can be
evaluated and progressed independently.
Structure of the series is as follows:
1) Adds a skeleton DRM cgroup controller with no functionality.
2-6) First proposal - static priority based controller.
7) i915 adds support for the static priority based controller.
8-14) Second proposal - GPU usage based controller.
15-17) i915 adds support for the GPU usage based controller.
Both proposals define a delegation of duties between the tree parties: cgroup
controller, DRM core and individual drivers. Two way communication interfaces
are then defined to enable the delegation to work. Principle of discoverability
is also employed so that the level of supported functionality can be observed
in situation when there are multiple GPUs in use, each with a different set of
scheduling capabilities.
DRM static priority control
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Static priority control exposes a hierarchical control interface for the
scheduling priority support present in many DRM device drivers.
Hierarchical meaning that the child group priorities are relative to their
parent. As an example:
A=-1000
/\
/ \
/ \
B=0 C=100
This results in the effective priority of a group B of -1000 and C of -900. In
other words the fact C is configured for elevated priority is relative to its
parent being a low priority and hence is only elevated in the context of its
siblings.
The scope of individual DRM scheduling priority may be per device or per device
driver, or a combination of both, depending on the implementation. The
controller does not ensure any priority ordering across multiple DRM drivers nor
does it impose any further policy and leaves desired configuration to the system
administrator.
Individual DRM drivers are required to transparently convert the cgroup priority
into values suitable for their capabilities.
No guarantees on effectiveness or granularity are provided by the controller,
apart the available range being chosen to be an integer and hence allowing a
generic concept of normal (zero), lower (negative values) and higher (positive
values) priority.
DRM static priority interface files
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drm.priority_levels
One of:
1) And integer representing the minimum number of discrete priority
levels for the whole group.
Optionally followed by an asterisk ('*') indicating some DRM clients
in the group support more than the minimum number.
2) '0'- indicating one or more DRM clients in the group has no support
for static priority control.
3) 'n/a' - when there are no DRM clients in the configured group.
drm.priority
A read-write integer between -10000 and 10000 (inclusive) representing
an abstract static priority level.
drm.effective_priority
Read only integer showing the current effective priority level for the
group. Effective meaning taking into account the chain of inherited
This approach should work with all DRM drivers which support priority control,
for instance i915, amdgpu or msm. In the future possibly all that are built on
top of the drm/scheduler as well.
I considered a few options for priority control including range based (min/max
limits, or a flavour of) but ended up settling for simplest one. Mainly because
of the limited priority level support with some drivers, and so to enable adding
wide spread support as easily as possible.
All that is required to enable the setup to be useful is for the drivers to
support the concept of a low, normal and high scheduling priority, which can
then be mapped to from the abstract negatitve, default zero and positive cgroup
priorities.
If range based controls are later wanted they can be added in a backward
compatible manner. Until then priority overlap is possible meaning groups need
to be correctly configured by the "administrator" (entity configuring cgroup
usage on a given system).
As mentioned before, this controller can be easily integrated with the current
ChromeOS architecture for managing CPU bandwith of focused versus unfocused
VM windows. As the OS re-configures the respective CPU shares in a respective
cgroup on a window focus status change, DRM cgroup controller could be attached
to the same group and DRM scheduling priority changed at the same time.
I have ran an experiment where I have shown that doing this can enable the
foreground browser window hit 60fps with no dropped frames, when faced with a
Android game runnning in the background, where if DRM priorities were not used
foreground window was only able to maintain around 45fps.
DRM scheduling soft limits
~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
The controller configures the GPU time allowed per group and periodically scans
the belonging tasks to detect the over budget condition, at which point it
invokes a callback notifying the DRM core of the condition.
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.
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.
DRM scheduling soft limits interface files
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drm.weight
Standard cgroup weight based control [1, 10000] used to configure the
relative distributing of GPU time between the sibling groups.
drm.period_us
An integer representing the period with which the controller should look
at the GPU usage by the group and potentially send the over/under budget
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.
The second proposal is a little bit more advanced in concept and also a little
bit less finished. Interesting thing is that it builds upon the per client GPU
utilisation work which landed recently for a few drivers. So my thinking is that
in principle, an intersect of drivers which support both that and some sort of
priority scheduling control, could also in theory support this.
Another really interesting angle for this controller is that it mimics the same
control menthod used by the CPU scheduler. That is the proportional/weight based
GPU time budgeting. Which makes it easy to configure and does not need a new
mental model.
However, as the introduction mentions, GPUs are much more heterogenous and
therefore the controller uses very "soft" wording as to what it promises. The
general statement is that it can define budgets, notify clients when they are
over them, and let individual drivers implement best effort handling of those
conditions.
Delegation of duties in the implementation goes likes this:
* DRM cgroup controller implements the control files and the scanning loop.
* 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.
* DRM core also provides a call back which the controller will call when a
certain process is over budget.
* Individual drivers need to implement two similar hooks, but which work for
a single DRM client. Over budget callback and GPU utilisation query.
What I have demonstrated in practice is that when wired to i915, in a really
primitive way where the over-budget condition simply lowers the scheduling
priority, the concept can be almost equally effective as the static priority
control. I say almost because the design where budget control depends on the
periodic usage scanning has a fundamental delay, so responsiveness will depend
on the scanning period, which may or may not be a problem for a particular use
case.
The unfinished part is the GPU budgeting split which currently does not
propagate unused bandwith to children, neither can share it with siblings. But
this is not due fundamental reasons, just to avoid spending too much time on it
too early.
There are also interesting conversations to be had around mental models for what
is GPU usage as a single number when faced with GPUs which have different
execution engines. To an extent this is similar to the multi-core and cgroup
CPU controller problems, but definitely goes further than that.
I deliberately did not want to include any such complications in the controller
itself and left the individual drivers to handle it. For instance in the i915
over-budget callback it will not do anything unless client's GPU usage is on a
physical engine which is oversubscribed. This enables multiple clients to be
harmlessly over budget, as long as they are not competing for the same GPU
resource.
This much for now, hope some good discussion will follow.
P.S.
A disclaimer of a kind - I was not familiar with how to implement a cgroup
controller at all when I started this prototype therefore it is quite possible
there are many bugs and misunderstandings on how it should be done.
Tvrtko Ursulin (17):
cgroup: Add the DRM cgroup controller
drm: Track clients per owning process
cgroup/drm: Support cgroup priority control
drm/cgroup: Allow safe external access to file_priv
drm: Connect priority updates to drm core
drm: Only track clients which are providing drm_cgroup_ops
drm/i915: i915 priority
drm: Allow for migration of clients
cgroup/drm: Introduce weight based drm cgroup control
drm: Add ability to query drm cgroup GPU time
drm: Add over budget signalling callback
cgroup/drm: Client exit hook
cgroup/drm: Ability to periodically scan cgroups for over budget GPU
usage
cgroup/drm: Show group budget signaling capability in sysfs
drm/i915: Migrate client to new owner on context create
drm/i915: Wire up with drm controller GPU time query
drm/i915: Implement cgroup controller over budget throttling
Documentation/admin-guide/cgroup-v2.rst | 100 +++
drivers/gpu/drm/Kconfig | 1 +
drivers/gpu/drm/Makefile | 1 +
drivers/gpu/drm/drm_cgroup.c | 294 +++++++
drivers/gpu/drm/drm_file.c | 22 +-
drivers/gpu/drm/i915/gem/i915_gem_context.c | 3 +
.../gpu/drm/i915/gem/i915_gem_execbuffer.c | 45 +-
drivers/gpu/drm/i915/i915_driver.c | 12 +
drivers/gpu/drm/i915/i915_drm_client.c | 183 ++++-
drivers/gpu/drm/i915/i915_drm_client.h | 15 +
include/drm/drm_clients.h | 50 ++
include/drm/drm_drv.h | 73 ++
include/drm/drm_file.h | 15 +
include/linux/cgroup_drm.h | 18 +
include/linux/cgroup_subsys.h | 4 +
init/Kconfig | 8 +
kernel/cgroup/Makefile | 1 +
kernel/cgroup/drm.c | 764 ++++++++++++++++++
18 files changed, 1594 insertions(+), 15 deletions(-)
create mode 100644 drivers/gpu/drm/drm_cgroup.c
create mode 100644 include/drm/drm_clients.h
create mode 100644 include/linux/cgroup_drm.h
create mode 100644 kernel/cgroup/drm.c
Comments
Hello, On Wed, Oct 19, 2022 at 06:32:37PM +0100, Tvrtko Ursulin wrote: ... > DRM static priority interface files > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > drm.priority_levels > One of: > 1) And integer representing the minimum number of discrete priority > levels for the whole group. > Optionally followed by an asterisk ('*') indicating some DRM clients > in the group support more than the minimum number. > 2) '0'- indicating one or more DRM clients in the group has no support > for static priority control. > 3) 'n/a' - when there are no DRM clients in the configured group. > > drm.priority > A read-write integer between -10000 and 10000 (inclusive) representing > an abstract static priority level. > > drm.effective_priority > Read only integer showing the current effective priority level for the > group. Effective meaning taking into account the chain of inherited From interface POV, this is a lot worse than the second proposal and I'd really like to avoid this. Even if we go with mapping user priority configuration to per-driver priorities, I'd much prefer if the interface presented to user is weight based and let each driver try to match the resulting hierarchical weight (ie. the absolute proportion a given cgroup should have at the point in time) as best as they can rather than exposing opaque priority numbers to userspace whose meaning isn't defined at all. > DRM scheduling soft limits interface files > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > drm.weight > Standard cgroup weight based control [1, 10000] used to configure the > relative distributing of GPU time between the sibling groups. Please take a look at io.weight. This can follow the same convention to express both global and per-device weights. > drm.period_us > An integer representing the period with which the controller should look > at the GPU usage by the group and potentially send the over/under budget > signal. > Value of zero (defaul) disables the soft limit checking. Can we not do period_us or at least make it a per-driver tuning parameter exposed as module param? Weight, users can easily understand and configure. period_us is a lot more an implementation detail. If we want to express the trade-off between latency and bandwidth at the interface, we prolly should encode the latency requirement in a more canonical way but let's leave that for the future. > 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. Yeah, I'm not sure about this. This isn't a per-cgroup property to begin with and I'm not sure 'no' meaning at least one device not supporting is intuitive. The distinction between 'no' and 'n/a' is kinda weird too. Please drop this. Another basic interface question. Is everyone happy with the drm prefix or should it be something like gpu? Also, in the future, if there's a consensus around how to control gpu memory, what prefix would that take? > The second proposal is a little bit more advanced in concept and also a little > bit less finished. Interesting thing is that it builds upon the per client GPU > utilisation work which landed recently for a few drivers. So my thinking is that > in principle, an intersect of drivers which support both that and some sort of > priority scheduling control, could also in theory support this. > > Another really interesting angle for this controller is that it mimics the same > control menthod used by the CPU scheduler. That is the proportional/weight based > GPU time budgeting. Which makes it easy to configure and does not need a new > mental model. > > However, as the introduction mentions, GPUs are much more heterogenous and > therefore the controller uses very "soft" wording as to what it promises. The > general statement is that it can define budgets, notify clients when they are > over them, and let individual drivers implement best effort handling of those > conditions. > > Delegation of duties in the implementation goes likes this: > > * DRM cgroup controller implements the control files and the scanning loop. > * 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. > * DRM core also provides a call back which the controller will call when a > certain process is over budget. > * Individual drivers need to implement two similar hooks, but which work for > a single DRM client. Over budget callback and GPU utilisation query. > > What I have demonstrated in practice is that when wired to i915, in a really > primitive way where the over-budget condition simply lowers the scheduling > priority, the concept can be almost equally effective as the static priority > control. I say almost because the design where budget control depends on the > periodic usage scanning has a fundamental delay, so responsiveness will depend > on the scanning period, which may or may not be a problem for a particular use > case. > > The unfinished part is the GPU budgeting split which currently does not > propagate unused bandwith to children, neither can share it with siblings. But > this is not due fundamental reasons, just to avoid spending too much time on it > too early. Rather than doing it hierarchically on the spot, it's usually a lot cheaper and easier to calculate the flattened hierarchical weight per leaf cgroup and divide the bandwidth according to the eventual portions. For an example, please take a look at block/blk-iocost.c. I don't know much about the drm driver side, so can't comment much on it but I do really like the idea of having the core implementation determining who should get how much and then letting each driver enforce the target. That seems a lot more robust and generic than trying to somehow coax and expose per-driver priority implementations directly. Thanks.
Hi Tejun, On 19/10/2022 19:45, Tejun Heo wrote: > Hello, > > On Wed, Oct 19, 2022 at 06:32:37PM +0100, Tvrtko Ursulin wrote: > ... >> DRM static priority interface files >> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> >> drm.priority_levels >> One of: >> 1) And integer representing the minimum number of discrete priority >> levels for the whole group. >> Optionally followed by an asterisk ('*') indicating some DRM clients >> in the group support more than the minimum number. >> 2) '0'- indicating one or more DRM clients in the group has no support >> for static priority control. >> 3) 'n/a' - when there are no DRM clients in the configured group. >> >> drm.priority >> A read-write integer between -10000 and 10000 (inclusive) representing >> an abstract static priority level. >> >> drm.effective_priority >> Read only integer showing the current effective priority level for the >> group. Effective meaning taking into account the chain of inherited > >>From interface POV, this is a lot worse than the second proposal and I'd > really like to avoid this. Even if we go with mapping user priority > configuration to per-driver priorities, I'd much prefer if the interface > presented to user is weight based and let each driver try to match the > resulting hierarchical weight (ie. the absolute proportion a given cgroup > should have at the point in time) as best as they can rather than exposing > opaque priority numbers to userspace whose meaning isn't defined at all. I actually somewhat agree here and this proposal was mainly motivated by my desire to come up with *something* which would allow similar _external_ control as it exists in the CPU and IO world (nice/ionice). Because currently priority of GPU workloads cannot be controlled from the outside at all. And especially if we consider pipelines composed of stages where part of the processing is done on the CPU and part on the GPU (or AI/VPU accelerator), then I think it would be really useful to be able to do so. To this effect I proposed connecting CPU nice with GPU priority, same as it is connected for IO priority (so only if it hasn't been explicitly changed away from the defaults), but at that point I was getting feedback nudging me into direction of cgroups. Looking at what's available in cgroups world now, I have spotted the blkio.prio.class control. For my current use case (lower GPU scheduling of background/unfocused windows) that would also work. Even if starting with just two possible values - 'no-change' and 'idle' (to follow the IO controller naming). How would you view that as a proposal? It would be a bit tougher "sell" to the DRM community, perhaps, given that many drivers do have scheduling priority, but the concept of scheduling class is not really there. Nevertheless a concept of normal-vs-background could be plausible in my mind. It could be easily implemented by using the priority controls available in many drivers. >> DRM scheduling soft limits interface files >> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> >> drm.weight >> Standard cgroup weight based control [1, 10000] used to configure the >> relative distributing of GPU time between the sibling groups. > > Please take a look at io.weight. This can follow the same convention to > express both global and per-device weights. > >> drm.period_us >> An integer representing the period with which the controller should look >> at the GPU usage by the group and potentially send the over/under budget >> signal. >> Value of zero (defaul) disables the soft limit checking. > > Can we not do period_us or at least make it a per-driver tuning parameter > exposed as module param? Weight, users can easily understand and configure. > period_us is a lot more an implementation detail. If we want to express the > trade-off between latency and bandwidth at the interface, we prolly should > encode the latency requirement in a more canonical way but let's leave that > for the future. Yes agreed - for the moment (while RFC) it is handy for me to have it controllable per group. But I agree a kernel global (modparam) should be sufficient in the final solution. > >> 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. > > Yeah, I'm not sure about this. This isn't a per-cgroup property to begin > with and I'm not sure 'no' meaning at least one device not supporting is > intuitive. The distinction between 'no' and 'n/a' is kinda weird too. Please > drop this. The idea actually is for this to be per-cgroup and potentially change dynamically. It implements the concept of "observability", how I have, perhaps clumsily, named it. This is because we can have a mix of DRM file descriptors in a cgroup, not all of which support the proposed functionality. So I wanted to have something by which the administrator can observe the status of the group. For instance seeing some clients do not support the feature could be signal that things have been misconfigured, or that appeal needs to be made for driver X to start supporting the feature. Seeing a "no" there in other words is a signal that budgeting may not really work as expected and needs to be investigated. > Another basic interface question. Is everyone happy with the drm prefix or > should it be something like gpu? Also, in the future, if there's a consensus > around how to control gpu memory, what prefix would that take? Given the current effort to bring in AI/VPU/ML accelerator devices under the DRM umbrella I think drm prefix is okay. At least some of those devices (the ones I looked at) will accept the same concepts of scheduling and memory allocation as well. And for memory specifically, I don't see why the drm prefix would not work. But yeah, I echo the calls for wider feedback. Given how drm cgroup controller has been on a wish list for ages I have to say I expected a bit more interest. :) >> The second proposal is a little bit more advanced in concept and also a little >> bit less finished. Interesting thing is that it builds upon the per client GPU >> utilisation work which landed recently for a few drivers. So my thinking is that >> in principle, an intersect of drivers which support both that and some sort of >> priority scheduling control, could also in theory support this. >> >> Another really interesting angle for this controller is that it mimics the same >> control menthod used by the CPU scheduler. That is the proportional/weight based >> GPU time budgeting. Which makes it easy to configure and does not need a new >> mental model. >> >> However, as the introduction mentions, GPUs are much more heterogenous and >> therefore the controller uses very "soft" wording as to what it promises. The >> general statement is that it can define budgets, notify clients when they are >> over them, and let individual drivers implement best effort handling of those >> conditions. >> >> Delegation of duties in the implementation goes likes this: >> >> * DRM cgroup controller implements the control files and the scanning loop. >> * 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. >> * DRM core also provides a call back which the controller will call when a >> certain process is over budget. >> * Individual drivers need to implement two similar hooks, but which work for >> a single DRM client. Over budget callback and GPU utilisation query. >> >> What I have demonstrated in practice is that when wired to i915, in a really >> primitive way where the over-budget condition simply lowers the scheduling >> priority, the concept can be almost equally effective as the static priority >> control. I say almost because the design where budget control depends on the >> periodic usage scanning has a fundamental delay, so responsiveness will depend >> on the scanning period, which may or may not be a problem for a particular use >> case. >> >> The unfinished part is the GPU budgeting split which currently does not >> propagate unused bandwith to children, neither can share it with siblings. But >> this is not due fundamental reasons, just to avoid spending too much time on it >> too early. > > Rather than doing it hierarchically on the spot, it's usually a lot cheaper > and easier to calculate the flattened hierarchical weight per leaf cgroup > and divide the bandwidth according to the eventual portions. For an example, > please take a look at block/blk-iocost.c. This seems exactly what I had in mind (but haven't implemented it yet). So in this RFC I have budget splitting per group where each tree level adds up to "100%" and the thing which I have not implemented is "borrowing" or yielding (how blk-iocost.c calls it, or donating) unused budgets to siblings. I am very happy to hear my idea is the right one and someone already implemented it. Thanks for this pointer! > I don't know much about the drm driver side, so can't comment much on it but > I do really like the idea of having the core implementation determining who > should get how much and then letting each driver enforce the target. That > seems a lot more robust and generic than trying to somehow coax and expose > per-driver priority implementations directly. Thanks, and thanks for having a detailed read and providing great feedback so far! Regards, Tvrtko
Hello, On Thu, Oct 27, 2022 at 03:32:00PM +0100, Tvrtko Ursulin wrote: > Looking at what's available in cgroups world now, I have spotted the > blkio.prio.class control. For my current use case (lower GPU scheduling of > background/unfocused windows) that would also work. Even if starting with > just two possible values - 'no-change' and 'idle' (to follow the IO > controller naming). I wouldn't follow that example. That's only meaningful within the context of bfq and it probabaly shouldn't have been merged in the first place. > How would you view that as a proposal? It would be a bit tougher "sell" to > the DRM community, perhaps, given that many drivers do have scheduling > priority, but the concept of scheduling class is not really there. > Nevertheless a concept of normal-vs-background could be plausible in my > mind. It could be easily implemented by using the priority controls > available in many drivers. I don't feel great about that. * The semantics aren't clearly defined. While not immediately obvious in the interface, the task nice levels have definite mappings to weight values and thus clear meanings. I don't think it's a good idea to leave the interface semantics open to interpretation. * Maybe GPUs are better but my experience with optional hardware features in the storage world has been that vendors diverge wildly and unexpectedly to the point many features are mostly useless. There are fewer GPU vendors and more software effort behind each, so maybe the situation is better but I think it'd be helpul to keep some skepticism. * Even when per-vendor or per-driver features are consistent enough to be useful, they often aren't thought through enough to be truly useful. e.g. nvme has priority features but they aren't really that useful because they can't do much without congestion control on the issuer side and once you have congestion control on the issuer side which is usually a lot more complex (e.g. dealing with work-conserving hierarchical weight distributions, priority inversions and so on), you can achieve most of what you need in terms of resource control from the issuer side anyway. So, I'd much prefer to have a fuller solution on the kernel side which integrates per-vendor/driver features where they make sense. > > > 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. > > > > Yeah, I'm not sure about this. This isn't a per-cgroup property to begin > > with and I'm not sure 'no' meaning at least one device not supporting is > > intuitive. The distinction between 'no' and 'n/a' is kinda weird too. Please > > drop this. > > The idea actually is for this to be per-cgroup and potentially change > dynamically. It implements the concept of "observability", how I have, > perhaps clumsily, named it. > > This is because we can have a mix of DRM file descriptors in a cgroup, not > all of which support the proposed functionality. So I wanted to have > something by which the administrator can observe the status of the group. > > For instance seeing some clients do not support the feature could be signal > that things have been misconfigured, or that appeal needs to be made for > driver X to start supporting the feature. Seeing a "no" there in other words > is a signal that budgeting may not really work as expected and needs to be > investigated. I still don't see how this is per-cgroup given that it's indicating whether the driver supports some feature. Also, the eventual goal would be supporting the same control mechanisms across most (if not all) GPUs, right? > > Rather than doing it hierarchically on the spot, it's usually a lot cheaper > > and easier to calculate the flattened hierarchical weight per leaf cgroup > > and divide the bandwidth according to the eventual portions. For an example, > > please take a look at block/blk-iocost.c. > > This seems exactly what I had in mind (but haven't implemented it yet). So > in this RFC I have budget splitting per group where each tree level adds up > to "100%" and the thing which I have not implemented is "borrowing" or > yielding (how blk-iocost.c calls it, or donating) unused budgets to > siblings. > > I am very happy to hear my idea is the right one and someone already > implemented it. Thanks for this pointer! The budget donation thing in iocost is necessary only because it wants to make the hot path local to the cgroup because io control has to support very high decision rate. For time-slicing GPU, it's likely that following the current hierarchical weight on the spot is enough. Thanks.
On 31/10/2022 20:20, Tejun Heo wrote: > Hello, > > On Thu, Oct 27, 2022 at 03:32:00PM +0100, Tvrtko Ursulin wrote: >> Looking at what's available in cgroups world now, I have spotted the >> blkio.prio.class control. For my current use case (lower GPU scheduling of >> background/unfocused windows) that would also work. Even if starting with >> just two possible values - 'no-change' and 'idle' (to follow the IO >> controller naming). > > I wouldn't follow that example. That's only meaningful within the context of > bfq and it probabaly shouldn't have been merged in the first place. > >> How would you view that as a proposal? It would be a bit tougher "sell" to >> the DRM community, perhaps, given that many drivers do have scheduling >> priority, but the concept of scheduling class is not really there. >> Nevertheless a concept of normal-vs-background could be plausible in my >> mind. It could be easily implemented by using the priority controls >> available in many drivers. > > I don't feel great about that. > > * The semantics aren't clearly defined. While not immediately obvious in the > interface, the task nice levels have definite mappings to weight values > and thus clear meanings. I don't think it's a good idea to leave the > interface semantics open to interpretation. Agreed it is not clearly defined, but it was the same with nice levels. As in it changed a lot over the years how exactly they behave (with a few scheduler rewrites) and they were constantly at least somewhat useful as a mean of external control. Nevertheless you will notice I have dropped everything priority based from the v2 of the RFC to simplify the conversation going forward. > * Maybe GPUs are better but my experience with optional hardware features in > the storage world has been that vendors diverge wildly and unexpectedly to > the point many features are mostly useless. There are fewer GPU vendors > and more software effort behind each, so maybe the situation is better but > I think it'd be helpul to keep some skepticism. > > * Even when per-vendor or per-driver features are consistent enough to be > useful, they often aren't thought through enough to be truly useful. e.g. > nvme has priority features but they aren't really that useful because they > can't do much without congestion control on the issuer side and once you > have congestion control on the issuer side which is usually a lot more > complex (e.g. dealing with work-conserving hierarchical weight > distributions, priority inversions and so on), you can achieve most of > what you need in terms of resource control from the issuer side anyway. GPUs will not be fully uniform either, especially in the terms of how well the controls work, which is why I am spelling out how this is only attempting to do "soft limits", everywhere in the documentation, cover letter and patch commit message. But at least concept of GPU time feels to me like a very universal one so should be something which we can base the control on. > So, I'd much prefer to have a fuller solution on the kernel side which > integrates per-vendor/driver features where they make sense. > >>>> 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. >>> >>> Yeah, I'm not sure about this. This isn't a per-cgroup property to begin >>> with and I'm not sure 'no' meaning at least one device not supporting is >>> intuitive. The distinction between 'no' and 'n/a' is kinda weird too. Please >>> drop this. >> >> The idea actually is for this to be per-cgroup and potentially change >> dynamically. It implements the concept of "observability", how I have, >> perhaps clumsily, named it. >> >> This is because we can have a mix of DRM file descriptors in a cgroup, not >> all of which support the proposed functionality. So I wanted to have >> something by which the administrator can observe the status of the group. >> >> For instance seeing some clients do not support the feature could be signal >> that things have been misconfigured, or that appeal needs to be made for >> driver X to start supporting the feature. Seeing a "no" there in other words >> is a signal that budgeting may not really work as expected and needs to be >> investigated. > > I still don't see how this is per-cgroup given that it's indicating whether > the driver supports some feature. Also, the eventual goal would be > supporting the same control mechanisms across most (if not all) GPUs, right? I have dropped this from v2 as well, to focus the feedback on most important points. But in general the problem it wanted to address is that a single cgroup can contain multiple processes, each with zero to N open DRM file descriptors to any random GPU which happens to be installed in the system. And it can all change dynamically. It may be different vendors or different hardware generations, where some do not support the required functionality to support the cgroup controller. So I wanted to give the sysadmin some visibility if at any given time the configuration applied to a cgroup has a chance to work fully, or only partially. For instance with i915 we can have two supported devices in a laptop - integrated and discrete. Integrated can support the controller well, while for discrete is work in progress, maybe comes in the next kernel release. And then we can have this: 1) cgexec -g drm:gfx/clients glxgears This runs fully on integrated and budgeting works as expected. 2) DRI_PRIME=1 cgexec -g drm:gfx/clients glxgears This one runs on the discrete GPU where budgeting does not work yet. While at the same time there can be another client in the same cgroup for which budgeting works. Or in other words: cgexec -g drm:gfx/clients transcode_me_a_video DRI_PRIME=1 cgexec -g drm:gfx/clients run_a_game In this case game is not taking part in budgeting, even though it is a same driver. Maybe it will in a few kernel releases but not yet. Or in case of super old GPUs maybe support never gets added. Perhaps I am over complicating things and what it would enough is to log the capability per device during driver probe: i915 0000:00:02.0: DRM cgroup support: weights i915 0000:01:00.0: DRM cgroup support: none ? >>> Rather than doing it hierarchically on the spot, it's usually a lot cheaper >>> and easier to calculate the flattened hierarchical weight per leaf cgroup >>> and divide the bandwidth according to the eventual portions. For an example, >>> please take a look at block/blk-iocost.c. >> >> This seems exactly what I had in mind (but haven't implemented it yet). So >> in this RFC I have budget splitting per group where each tree level adds up >> to "100%" and the thing which I have not implemented is "borrowing" or >> yielding (how blk-iocost.c calls it, or donating) unused budgets to >> siblings. >> >> I am very happy to hear my idea is the right one and someone already >> implemented it. Thanks for this pointer! > > The budget donation thing in iocost is necessary only because it wants to > make the hot path local to the cgroup because io control has to support very > high decision rate. For time-slicing GPU, it's likely that following the > current hierarchical weight on the spot is enough. I think I completed this part in v2. At least some quick smoke testing showed me that budgets now correctly propagate through the tree. Not guaranteeing no bugs just yet and there are certainly still things to polish up in v2. Regards, Tvrtko