From: "Chen, Chen-Yu" <Chen-Yu.Chen@amd.com>
To: hugo@hsal.es, Harry Wentland <harry.wentland@amd.com>,
Leo Li <sunpeng.li@amd.com>,
Rodrigo Siqueira <siqueira@igalia.com>,
Alex Deucher <alexander.deucher@amd.com>
Cc: "Mario Limonciello" <mario.limonciello@amd.com>,
"Ray Wu" <ray.wu@amd.com>, "Alex Hung" <alex.hung@amd.com>,
"Bhawanpreet Lakha" <bhawanpreet.lakha@amd.com>,
"Ivan Lipski" <ivan.lipski@amd.com>,
"Christian König" <christian.koenig@amd.com>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 4/5] drm/amd/display: Commit panel_power_savings writes from the kernel
Date: Mon, 16 Nov 2026 17:07:43 +0800 [thread overview]
Message-ID: <737aad6d-24d1-4496-83af-9db8fd93c736@amd.com> (raw)
In-Reply-To: <20261113-abm-sysfs-commit-v2-4-5808d17a7e89@hsal.es>
On 11/14/2026 4:24 AM, Hugo Sales via B4 Relay wrote:
> [Some people who received this message don't often get email from devnull+hugo.hsal.es@kernel.org. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>
> From: Hugo Sales <hugo@hsal.es>
>
> panel_power_savings_store() currently writes the level into
> connector->state and sends a hotplug uevent, and the hardware only gets it
> on a later atomic commit that includes the connector. Hyprland adds the
> connector to a commit only on a modeset or when a connector property it
> sets changes, so it never applies the level
>
> Programs that write the sysfs file, such as power-profiles-daemon, aren't
> the DRM master and can't commit themselves, so they depend on the master
> taking the uevent as a cue to commit the connector, but nothing documents
> they should. A master that wants to control ABM sets the 'adaptive
> backlight modulation' property, and from then on writes return -EBUSY. The
> file has to work without the master's help, like the backlight device,
> whose writes reach DC without a commit
>
> Commit the level from the store instead, with a duplicated connector state
> and no modeset. The write returns once the commit is done, or with the
> commit's error, so no uevent is needed. A connector that is off gets the
> level when it is next enabled. A write of the level the connector already
> has, or one the DRM master forbids, returns without a commit and without
> waking a runtime-suspended GPU
>
> Document the new behaviour in the kernel-doc
>
> Signed-off-by: Hugo Sales <hugo@hsal.es>
> ---
> This needs "drm/amd/display: Don't force a modeset when the ABM level
> changes". Without it, atomic check sees the changed level, asks for a
> modeset and the commit fails with -EINVAL
>
> A failed write used to leave the level stored and send the uevent anyway.
> Now the level only changes through the commit, so the store reports the
> error. power-profiles-daemon logs a failed write and tries again on the
> next profile, AC or battery change, because it compares against the value
> it reads back. It ignores the hotplug uevent. Compositors used it only as
> a cue to commit the connector, which the store now does itself
>
> The commit is blocking, so a write can hold the CRTC locks for up to a
> frame while a compositor commit waits. The other way round, while the
> store's commit is pending, a nonblocking commit from the compositor on the
> same CRTC fails with -EBUSY, as it would behind any pending commit
>
> The store takes a runtime PM reference around the commit, like the
> atomic ioctl path. Its locks are interruptible, and a write a signal
> interrupts returns -ERESTARTSYS so that it restarts
> ---
> .../amd/display/amdgpu_dm/amdgpu_dm_backlight.c | 118 +++++++++++++++++++--
> 1 file changed, 107 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_backlight.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_backlight.c
> index 27546febf90d3..8487ac0661396 100644
> --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_backlight.c
> +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_backlight.c
> @@ -40,7 +40,10 @@
>
> #include <linux/backlight.h>
> #include <linux/minmax.h>
> +#include <linux/pm_runtime.h>
> #include <linux/power_supply.h>
> +#include <drm/drm_atomic.h>
> +#include <drm/drm_drv.h>
> #include <drm/drm_edid.h>
> #include <drm/drm_utils.h>
>
> @@ -691,6 +694,18 @@ EXPORT_IF_KUNIT(amdgpu_dm_setup_backlight_device);
> *
> * Modifying this value can have implications on color accuracy, so tread
> * carefully.
> + *
> + * A write commits the new level before it returns, without a modeset. The
> + * commit waits for any commit already pending on the connector's CRTC, and
> + * while it is pending, a nonblocking commit from the DRM master on that CRTC
> + * fails with -EBUSY. If the connector or its CRTC is off, the driver stores
I don't think the -EBUSY part can happen. The store's commit is blocking
and keeps the CRTC lock until commit_tail has finished, so a master commit
on that CRTC waits on the lock, and by the time it runs stall_checks()
there is nothing pending. On a Strix laptop under GNOME with es2gears
running (about 120 commits/s), 26-28 back-to-back writes with v1 gave no
-EBUSY; the compositor commit just waited. Could you say that the master's
commit on that CRTC waits for the write instead?
Regards,
Chenyu
> + * the level and applies it when the connector is next enabled
> + *
> + * If the commit fails, the write returns its error and the level stays as it
> + * was. While the CRTC needs a modeset, as after a DSC override in debugfs,
> + * writes fail with -EINVAL until a commit that allows a modeset clears that
> + * state. Writes fail with -EBUSY once the DRM master has set the connector's
> + * 'adaptive backlight modulation' property to a value other than 'sysfs'
> */
>
> STATIC_IFN_KUNIT
> @@ -712,13 +727,100 @@ ssize_t panel_power_savings_show(struct device *device,
> }
> EXPORT_IF_KUNIT(panel_power_savings_show);
>
> +static int panel_power_savings_apply(struct drm_connector *connector,
> + unsigned int level)
> +{
> + struct drm_connector_state *conn_state;
> + struct dm_connector_state *dm_state;
> + struct drm_device *dev = connector->dev;
> + struct drm_modeset_acquire_ctx ctx;
> + struct drm_atomic_commit *state;
> + bool forbidden, unchanged;
> + int ret, idx;
> +
> + level = level ?: ABM_LEVEL_IMMEDIATE_DISABLE;
> +
> + if (!drm_dev_enter(dev, &idx))
> + return -ENODEV;
> +
> + /*
> + * Don't wake the GPU for a write that changes nothing. The duplicated
> + * state below is checked again. This check only spares the runtime resume
> + */
> + ret = drm_modeset_lock_single_interruptible(&dev->mode_config.connection_mutex);
> + if (ret)
> + goto dev_exit;
> + dm_state = to_dm_connector_state(connector->state);
> + forbidden = dm_state->abm_sysfs_forbidden;
> + unchanged = dm_state->abm_level == level;
> + drm_modeset_unlock(&dev->mode_config.connection_mutex);
> +
> + if (forbidden || unchanged) {
> + ret = forbidden ? -EBUSY : 0;
> + goto dev_exit;
> + }
> +
> + ret = pm_runtime_resume_and_get(dev->dev);
> + if (ret < 0)
> + goto dev_exit;
> +
> + state = drm_atomic_commit_alloc(dev);
> + if (!state) {
> + ret = -ENOMEM;
> + goto pm_put;
> + }
> +
> + /* Kernel commits allow a modeset by default, which a level change doesn't need */
> + state->allow_modeset = false;
> +
> + drm_modeset_acquire_init(&ctx, DRM_MODESET_ACQUIRE_INTERRUPTIBLE);
> + state->acquire_ctx = &ctx;
> +retry:
> + conn_state = drm_atomic_get_connector_state(state, connector);
> + if (IS_ERR(conn_state)) {
> + ret = PTR_ERR(conn_state);
> + goto out;
> + }
> +
> + dm_state = to_dm_connector_state(conn_state);
> + if (dm_state->abm_sysfs_forbidden) {
> + ret = -EBUSY;
> + goto out;
> + }
> +
> + if (dm_state->abm_level == level) {
> + ret = 0;
> + goto out;
> + }
> +
> + dm_state->abm_level = level;
> +
> + ret = drm_atomic_commit(state);
> +out:
> + if (ret == -EDEADLK) {
> + drm_atomic_commit_clear(state);
> + ret = drm_modeset_backoff(&ctx);
> + if (!ret)
> + goto retry;
> + }
> +
> + drm_atomic_commit_put(state);
> + drm_modeset_drop_locks(&ctx);
> + drm_modeset_acquire_fini(&ctx);
> +pm_put:
> + pm_runtime_put_autosuspend(dev->dev);
> +dev_exit:
> + drm_dev_exit(idx);
> +
> + return ret;
> +}
> +
> STATIC_IFN_KUNIT
> ssize_t panel_power_savings_store(struct device *device,
> struct device_attribute *attr,
> const char *buf, size_t count)
> {
> struct drm_connector *connector = dev_get_drvdata(device);
> - struct drm_device *dev = connector->dev;
> long val;
> int ret;
>
> @@ -730,19 +832,13 @@ ssize_t panel_power_savings_store(struct device *device,
> if (val < 0 || val > 4)
> return -EINVAL;
>
> - drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
> - if (to_dm_connector_state(connector->state)->abm_sysfs_forbidden)
> - ret = -EBUSY;
> - else
> - to_dm_connector_state(connector->state)->abm_level = val ?:
> - ABM_LEVEL_IMMEDIATE_DISABLE;
> - drm_modeset_unlock(&dev->mode_config.connection_mutex);
> -
> + ret = panel_power_savings_apply(connector, val);
> + /* The modeset locks return -EINTR, which write(2) would not restart */
> + if (ret == -EINTR)
> + return -ERESTARTSYS;
> if (ret)
> return ret;
>
> - drm_kms_helper_hotplug_event(dev);
> -
> return count;
> }
> EXPORT_IF_KUNIT(panel_power_savings_store);
>
> --
> 2.56.0
>
>
next prev parent reply other threads:[~2026-11-16 9:08 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-13 20:24 [PATCH v2 0/5] drm/amd/display: Commit panel_power_savings writes from the kernel Hugo Sales via B4 Relay
2026-11-13 20:24 ` [PATCH v2 1/5] drm/amd/display: Render the panel power savings kernel-doc Hugo Sales via B4 Relay
2026-11-13 20:24 ` [PATCH v2 2/5] drm/amd/display: Don't force a modeset when the ABM level changes Hugo Sales via B4 Relay
2026-11-16 9:18 ` Chen, Chen-Yu
2026-11-13 20:24 ` [PATCH v2 3/5] drm/amd/display: Give the panel_power_savings store tests a full pipe Hugo Sales via B4 Relay
2026-11-13 20:24 ` [PATCH v2 4/5] drm/amd/display: Commit panel_power_savings writes from the kernel Hugo Sales via B4 Relay
2026-11-16 9:07 ` Chen, Chen-Yu [this message]
2026-11-13 20:24 ` [PATCH v2 5/5] drm/amd/display: Test panel_power_savings commits Hugo Sales via B4 Relay
2026-11-16 14:11 ` [PATCH v2 0/5] drm/amd/display: Commit panel_power_savings writes from the kernel Hugo Sales
2026-11-16 14:28 ` Chen, Chen-Yu
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=737aad6d-24d1-4496-83af-9db8fd93c736@amd.com \
--to=chen-yu.chen@amd.com \
--cc=airlied@gmail.com \
--cc=alex.hung@amd.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=bhawanpreet.lakha@amd.com \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=harry.wentland@amd.com \
--cc=hugo@hsal.es \
--cc=ivan.lipski@amd.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mario.limonciello@amd.com \
--cc=ray.wu@amd.com \
--cc=simona@ffwll.ch \
--cc=siqueira@igalia.com \
--cc=sunpeng.li@amd.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