From: Ray Strode <halfline@gmail.com>
To: dri-devel@lists.freedesktop.org
Cc: Ray Strode <rstrode@redhat.com>,
daniel.vetter@ffwll.ch, Xinhui.Pan@amd.com, mdaenzer@redhat.com,
alexander.deucher@amd.com, airlied@redhat.com,
christian.koenig@amd.com
Subject: [PATCH] drm/atomic: Perform blocking commits on workqueue
Date: Tue, 26 Sep 2023 13:05:49 -0400 [thread overview]
Message-ID: <20230926170549.2589045-1-halfline@gmail.com> (raw)
From: Ray Strode <rstrode@redhat.com>
A drm atomic commit can be quite slow on some hardware. It can lead
to a lengthy queue of commands that need to get processed and waited
on before control can go back to user space.
If user space is a real-time thread, that delay can have severe
consequences, leading to the process getting killed for exceeding
rlimits.
This commit addresses the problem by always running the slow part of
a commit on a workqueue, separated from the task initiating the
commit.
This change makes the nonblocking and blocking paths work in the same way,
and as a result allows the task to sleep and not use up its
RLIMIT_RTTIME allocation.
Link: https://gitlab.freedesktop.org/drm/amd/-/issues/2861
Signed-off-by: Ray Strode <rstrode@redhat.com>
---
drivers/gpu/drm/drm_atomic_helper.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c
index 292e38eb6218..1a1e68d98d38 100644
--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -2028,64 +2028,63 @@ int drm_atomic_helper_commit(struct drm_device *dev,
* This is the point of no return - everything below never fails except
* when the hw goes bonghits. Which means we can commit the new state on
* the software side now.
*/
ret = drm_atomic_helper_swap_state(state, true);
if (ret)
goto err;
/*
* Everything below can be run asynchronously without the need to grab
* any modeset locks at all under one condition: It must be guaranteed
* that the asynchronous work has either been cancelled (if the driver
* supports it, which at least requires that the framebuffers get
* cleaned up with drm_atomic_helper_cleanup_planes()) or completed
* before the new state gets committed on the software side with
* drm_atomic_helper_swap_state().
*
* This scheme allows new atomic state updates to be prepared and
* checked in parallel to the asynchronous completion of the previous
* update. Which is important since compositors need to figure out the
* composition of the next frame right after having submitted the
* current layout.
*
* NOTE: Commit work has multiple phases, first hardware commit, then
* cleanup. We want them to overlap, hence need system_unbound_wq to
* make sure work items don't artificially stall on each another.
*/
drm_atomic_state_get(state);
- if (nonblock)
- queue_work(system_unbound_wq, &state->commit_work);
- else
- commit_tail(state);
+ queue_work(system_unbound_wq, &state->commit_work);
+ if (!nonblock)
+ flush_work(&state->commit_work);
return 0;
err:
drm_atomic_helper_cleanup_planes(dev, state);
return ret;
}
EXPORT_SYMBOL(drm_atomic_helper_commit);
/**
* DOC: implementing nonblocking commit
*
* Nonblocking atomic commits should use struct &drm_crtc_commit to sequence
* different operations against each another. Locks, especially struct
* &drm_modeset_lock, should not be held in worker threads or any other
* asynchronous context used to commit the hardware state.
*
* drm_atomic_helper_commit() implements the recommended sequence for
* nonblocking commits, using drm_atomic_helper_setup_commit() internally:
*
* 1. Run drm_atomic_helper_prepare_planes(). Since this can fail and we
* need to propagate out of memory/VRAM errors to userspace, it must be called
* synchronously.
*
* 2. Synchronize with any outstanding nonblocking commit worker threads which
* might be affected by the new state update. This is handled by
* drm_atomic_helper_setup_commit().
*
* Asynchronous workers need to have sufficient parallelism to be able to run
* different atomic commits on different CRTCs in parallel. The simplest way to
--
2.41.0
next reply other threads:[~2023-09-26 19:14 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-26 17:05 Ray Strode [this message]
2023-09-27 8:04 ` [PATCH] drm/atomic: Perform blocking commits on workqueue Christian König
2023-09-27 20:25 ` Ray Strode
2023-09-28 6:56 ` Christian König
2023-09-28 9:43 ` Michel Dänzer
2023-09-28 12:59 ` Ray Strode
2023-09-28 13:37 ` Michel Dänzer
2023-09-28 14:51 ` Christian König
2023-09-28 15:19 ` Michel Dänzer
2023-09-28 12:46 ` Ray Strode
2023-09-28 13:23 ` Christian König
2023-09-28 13:58 ` Michel Dänzer
2023-09-28 15:02 ` Christian König
2023-09-28 14:20 ` Ray Strode
2023-09-28 15:03 ` Ville Syrjälä
2023-09-28 19:33 ` Ray Strode
2023-10-04 17:27 ` Ville Syrjälä
2023-10-04 19:38 ` Ray Strode
2023-10-05 9:57 ` Daniel Vetter
2023-10-05 10:16 ` Ville Syrjälä
2023-10-10 11:36 ` Daniel Vetter
2023-10-05 11:51 ` Christian König
2023-10-05 21:04 ` Ray Strode
2023-10-06 7:12 ` Christian König
2023-10-06 18:48 ` Ray Strode
2023-10-08 10:37 ` Michel Dänzer
2023-10-09 6:42 ` Christian König
2023-10-09 12:19 ` Ville Syrjälä
2023-10-09 12:36 ` Christian König
2023-10-10 11:41 ` Daniel Vetter
2023-10-12 18:19 ` Ray Strode
2023-10-13 9:41 ` Daniel Vetter
2023-10-13 10:22 ` Michel Dänzer
2023-10-17 7:32 ` Daniel Vetter
2023-10-17 7:55 ` Christian König
2023-10-13 14:04 ` Ray Strode
2023-10-17 7:37 ` Daniel Vetter
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=20230926170549.2589045-1-halfline@gmail.com \
--to=halfline@gmail.com \
--cc=Xinhui.Pan@amd.com \
--cc=airlied@redhat.com \
--cc=alexander.deucher@amd.com \
--cc=christian.koenig@amd.com \
--cc=daniel.vetter@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=mdaenzer@redhat.com \
--cc=rstrode@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.