<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">On Friday, May 10, 2024 9:11:13 AM EDT Jonas Ådahl wrote:</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> On Fri, May 10, 2024 at 02:45:48PM +0200, Thomas Zimmermann wrote:</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > Hi</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > (This was discussed on #dri-devel, but I'll reiterate here as well).</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > There are two problems at hand; one is the race condition during boot</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > when the login screen (or whatever display server appears first) is</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > launched with simpledrm, only some moments later having the real GPU</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > driver appear.</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > The other is general purpose GPU hotplugging, including the unplugging</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > the GPU decided by the compositor to be the primary one.</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > The situation of booting with simpledrm (problem 2) is a special case of</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > problem 1. From the kernel's perspective, unloading simpledrm is the same as</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > what you call general purpose GPU hotplugging. Even through there is not a</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > full GPU, but a trivial scanout buffer. In userspace, you see the same</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > sequence of events as in the general case.</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> Sure, in a way it is, but the consequence and frequency of occurence is</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> quite different, so I think it makes sense to think of them as different</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> problems, since they need different solutions. One is about fixing</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> userspace components support for arbitrary hotplugging, the other for</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> mitigating the race condition that caused this discussion to begin with.</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > The latter is something that should be handled in userspace, by</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > compositors, etc, I agree.</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > The former, however, is not properly solved by userspace learning how to</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > deal with primary GPU unplugging and switching to using a real GPU</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > driver, as it'd break the booting and login experience.</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > When it works, i.e. the race condition is not hit, is this:</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > >   * System boots</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > >   * Plymouth shows a "splash" screen</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > >   * The login screen display server is launched with the real GPU driver</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > >   * The login screen interface is smoothly animating using hardware</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > >     accelerating, presenting "advanced" graphical content depending on</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > >     hardware capabilities (e.g. high color bit depth, HDR, and so on)</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > If the race condition is hit, with a compositor supporting primary GPU</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > hotplugging, it'll work like this:</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > >   * System boots</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > >   * Plymouth shows a "splash" screen</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > >   * The login screen display server is launched with simpledrm</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > >   * Due to using simpldrm, the login screen interface is not animated and</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > >     just plops up, and no "advanced" graphical content is enabled due to</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > >     apparent missing hardware capabilities</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > >   * The real GPU driver appears, the login screen now starts to become</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > >     animated, and may suddenly change appearance due to capabilties</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > >     having changed</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > Thus, by just supporting hotplugging the primary GPU in userspace, we'll</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > still end up with a glitchy boot experience, and it forces userspace to</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > add things like sleep(10) to work around this.</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > In other words, fixing userspace is *not* a correct solution to the</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > problem, it's a work around (albeit a behaivor we want for other</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > reasons) for the race condition.</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > To really fix the flickering, you need to read the old DRM device's atomic</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > state and apply it to the new device. Then tell the desktop and applications</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > to re-init their rendering stack.</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > Depending on the DRM driver and its hardware, it might be possible to do</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > this without flickering. The key is to not loose the original scanout</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > buffer, while not probing the new device driver. But that needs work in each</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > individual DRM driver.</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> This doesn't sound like it'll fix any flickering as I describe them.</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> First, the loss of initial animation when the login interface appears is</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> not something one can "fix", since it has already happened.</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">I feel like whatever animations that a login screen has though is going to be </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">in the realm of a fade-in animation, or maybe a sliding animation though, or </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">one of those that are more on the simple side.</p>
<br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">llvmpipe should be good enough for animations like that these days I would </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">think, right? Or is it really bad on very very old CPUs, like say a Pentium III?</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> Avoiding flickering when switching to the new driver is only possible</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> if one limits oneself to what simpledrm was capable of doing, i.e. no</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> HDR signaling etc.</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > Arguably, the only place a more educated guess about whether to wait or</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > not, and if so how long, is the kernel.</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > As I said before, driver modules come and go and hardware devices come and</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > go.</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > To detect if there might be a native driver waiting to be loaded, you can</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > test for</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > - 'nomodeset' on the command line -> no native driver</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> Makes sense to not wait here, and just assume simpledrm forever.</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > - 'systemd-load-modules' not started -> maybe wait</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > - look for drivers under /lib/modules/<version>/kernel/drivers/gpu/drm/ -></p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > maybe wait</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> I suspect this is not useful for general purpose distributions. I have</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> 43 kernel GPU modules there, on a F40 installation.</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > - maybe udev can tell you more</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > - it might for detection help that recently simpledrm devices refer to their</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > parent PCI device</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > - maybe systemd tracks the probed devices</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> If the kernel already plumbs enough state so userspace components can</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> make a decent decision, instead of just sleeping for an arbitrary amount</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> of time, then great. This is to some degree what</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> https://github.com/systemd/systemd/issues/32509 is about.</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> Jonas</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > Best regards</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > Thomas</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > Jonas</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > > The next best solution is to keep the final DRM device open until a new one</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > > shows up. All DRM graphics drivers with hotplugging support are required to</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > > accept commands after their hardware has been unplugged. They simply won't</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > > display anything.</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > > </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > > Best regards</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > > Thomas</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > > </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > > </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > > > Thanks</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > > > > </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> > </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> </p>
<br /><br /></body>
</html>