Skip to content

Amlogic: handle persistent DRM hotplug events on the main thread - #70

Open
manuandre wants to merge 375 commits into
CoreELEC:aml-5.15.196-22.0from
manuandre:amlogic-persistent-drm-hotplug-mainthread
Open

Amlogic: handle persistent DRM hotplug events on the main thread#70
manuandre wants to merge 375 commits into
CoreELEC:aml-5.15.196-22.0from
manuandre:amlogic-persistent-drm-hotplug-mainthread

Conversation

@manuandre

Copy link
Copy Markdown
Contributor

Description

Keep the Amlogic DRM udev monitor active across hotplug events and defer
hotplug processing to the window-system message pump.

The udev callback now only records a pending hotplug event. MessagePump(),
which runs on Kodi's main process thread, consumes that state and calls
HotplugEvent().

The monitor cleanup path is also made safe and idempotent.

Motivation and context

The DRM hotplug monitor was stopped from inside its own event callback and
HotplugEvent() was processed directly on the event-monitor worker thread.

This had two problems:

  • stopping the monitor from its callback could re-enter the event monitor
    locking path;
  • the monitor became effectively one-shot, so subsequent HDMI hotplug events
    were no longer reliably handled.

Keeping the monitor persistent and dispatching the actual hotplug work through
the existing window-system message pump avoids both issues.

How has this been tested?

Ugoos AM6B Plus (S922X), CoreELEC 22, built as a complete Amlogic image with
this change applied.

Repeated HDMI disconnect/reconnect cycles were tested.

The runtime log confirmed:

  • the udev callback runs on the event-monitor worker thread;
  • HotplugEvent() runs on Kodi's main process thread;
  • the monitor continues receiving events over multiple hotplug cycles;
  • the DRM connector transitions through the temporary one-mode state and
    recovers the normal display modes after reconnect;
  • the same Kodi process remained active throughout, with no crash or restart.

What is the effect on users?

HDMI hotplug events on Amlogic remain monitored after the first event and the
resulting DRM/display handling is performed on Kodi's main thread.

Types of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

@Portisch

Copy link
Copy Markdown
Contributor
  1. When booting now without HDMI connected and waiting until Kodi is started screen remain black.
    The MessagePump function is not called anymore.

  2. sc mask kodi, disconnect HDMI and reboot.
    Wait until booted and then: sc unmask kodi, sc start kodi. Oops do happen: kodi.bin[1080]: unhandled exception: DABT (lower EL), ESR 0x0000000092000006, level 2 translation fault.
    This I guess happen now because of the call udev_monitor_unref.

@Portisch
Portisch force-pushed the aml-5.15.196-22.0 branch 3 times, most recently from 5d864fc to 10c62c4 Compare August 18, 2026 14:31
@manuandre
manuandre force-pushed the amlogic-persistent-drm-hotplug-mainthread branch from 136ca8c to 0810297 Compare August 18, 2026 22:20
@manuandre

Copy link
Copy Markdown
Contributor Author

Thanks, I reproduced and investigated both cases.
For the first one, the reason MessagePump() was no longer called was that Kodi's main thread could block indefinitely in libMali inside eglSwapBuffers() when booting without HDMI. I added a guard in PresentRender() to skip presentation while the cached DRM connector is disconnected or a hotplug event is pending.
With the current branch I tested:
boot with HDMI disconnected;
Kodi reaches Running the application;
reconnect HDMI;
the persistent udev monitor receives the hotplug events;
HotplugEvent() is processed on the Kodi main thread;
the connector eventually becomes ready and the picture comes back;
Kodi stays in the same process, with no restart.
I also repeated your second scenario with Kodi prevented from starting during boot, HDMI disconnected, then starting Kodi manually afterwards. I could not reproduce the DABT with the current branch. Kodi remained active/running, NRestarts=0, and there was no DABT, translation fault or kodi.bin exception in the kernel log.
So at this point I don't have evidence that udev_monitor_unref() is responsible for the DABT.
Separately, during one of the HPD/EDID negotiation sequences I did see a kernel warning:
BUG: sleeping function called from invalid context
coming from the amhdmitx workqueue (hdmitx_hpd_plugin_irq_handler → resman_notify_error_info()), but Kodi did not crash and HDMI eventually recovered normally.
I rebased the PR on the current aml-5.15.196-22.0 and pushed the tested changes.
By the way, do you have a standard test procedure or checklist you usually run for Amlogic/Kodi changes before considering a PR ready? If so, I’d be happy to run the same set of tests on this branch before considering it done.

@Portisch

Copy link
Copy Markdown
Contributor

A PR is ready when it's functionality is confirmed.

Case 1. still doesn't work: PresentRender aml_get_display_connected: true, IsHotplugPending: false
Because of the forced mode switch the device is forced to be connected and MessagePump exit again.

@Portisch
Portisch force-pushed the aml-5.15.196-22.0 branch 4 times, most recently from 7f60c46 to 9239a6d Compare August 20, 2026 13:05
Portisch and others added 19 commits August 21, 2026 08:49
Hide it so it can't be enabled in videoplayer settings and
also disable it - otherwise users who previously enabled it
would be left without audio passthrough and no option to fix
this via the GUI.
It takes some time for correct HW di frame_format value to be in file.
Now interlace flag checked only 4 times with some period on stream start or after some stream change.
Contains revert for 2 commits:
CoreELEC@e6f7a0d
CoreELEC@a655c4f
Causes flickering screen for several seconds after refresh rate change.

Ref: xbmc/xbmc/pull/13629/files#r178433923
…ix primaries chromaticity and luminance levels in metadata
… with bootloader 'hdmimode' environment variable. Save also all resolutions supported by the kernel.
Get all chars of the sysfs file.
Trim the result to remove new line char on single line.
Portisch and others added 21 commits August 21, 2026 19:53
Handle fractional refresh rate updates together with mode changes.

Previously, they were handled separately, resulting in multiple DRM
atomic commits and, consequently, multiple mode sets. Combining both
operations into a single atomic commit avoids unnecessary mode changes.
Pulldown and double refresh rate is also valid option when no whitelist is used.
New TVs most support 120Hz, so add a new whole-number repeat option for 24/30Hz to 120Hz.
This allow judder free playback for 24/30Hz on 120Hz.
Playerprocessinfo: added live audio and video bitrate.
It's now show in all file type, the old static value not showed all-time.

This closes CoreELEC#66.
Broken by "Screenshot rework".
GUI is working again but video is still broken for VFM systems.
CE features register label names and info providers from CE owned
files instead of adding rows to the upstream tables. Labels resolve
by name, so CE is no longer bounded by the free id slots in Kodi's
info label blocks. Providers append at the back of the provider list
so upstream answers first.
Readd the Linux version row on a CE id now that the battery id
matches upstream again.
The reverted patch also restyled the System Info screen. Those parts come
back here on their own so they can be kept or dropped independently: the
AMLogic header line, the hidden BogoMips and Revision rows, the bracketed
os version, and the kernel suffix dropped from osVersionInfo now that the
Linux version has its own row.
Readd the amlogic.pixformat, amlogic.displaymode and amlogic.eoft_gamut
labels on CE ids, answered by the CE provider instead of upstream table
rows and cases. The check script guards the CE id ranges against
upstream growth on future rebases.
Readd the audiochannelssink label on a CE id with the sink side
plumbing that feeds it. The ProcessInfo getter and its debug log do
not come back, the label reads the data cache directly.
The reverted patch also rounded the videofps label to a trimmed
fractional form. That presentation of an upstream value stays.
Locates the DV RPU, HDR10+ SEI and HDR static payloads in the stream and
publishes them base64 encoded under one JSON label, so add-ons parse the
raw bytes and core carries no metadata formats. Values are sequenced per
pts and released when the render clock reaches their frame.
HDMI mandatory formats do not include a 1080p24Hz SBS mode.
Keep the udev monitor active across hotplug events and defer HotplugEvent() processing to the window-system message pump. This avoids stopping the monitor from its callback and keeps DRM hotplug handling on Kodi's main thread.
@manuandre
manuandre force-pushed the amlogic-persistent-drm-hotplug-mainthread branch from 0810297 to a3373da Compare August 21, 2026 21:50
@manuandre

Copy link
Copy Markdown
Contributor Author

Thanks.
I reproduced your cases again on the current aml-5.15.196-22.0 base and found one remaining issue in case 1.
During HDMI reconnect, drmModeGetConnector() initially returned 25 modes but encoder_id == 0, so the cached m_connection remained disconnected. The hotplug recovery modeset itself succeeded, and a fresh DRM query afterwards showed the connector as connected with an encoder assigned, but Kodi was still using the stale connection state. This prevented presentation from being re-enabled.
I changed the hotplug recovery path to refresh the connector state from DRM after a successful atomic modeset. It does not force the connector to connected: the state comes from a new drmModeGetConnector() result after the modeset.
Retested:
Case 1
boot with HDMI disconnected;
Kodi reaches Running the application using dummy_l;
reconnect HDMI;
hotplug is processed on Kodi's main thread;
25 modes are detected;
forced modeset completes and the GBM surface is recreated;
Kodi Home becomes visible again;
same Kodi PID throughout, no restart.
Case 2
boot with Kodi masked and HDMI disconnected;
unmask/start Kodi manually;
Kodi reaches Running the application using dummy_l;
no DABT, translation fault or kodi.bin exception;
reconnect HDMI;
display recovers to Kodi Home with the same Kodi PID.
PR head is now 229dceb.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.