https://bugs.kde.org/show_bug.cgi?id=529066

            Bug ID: 529066
           Summary: plasmashell spins at 100% CPU in
                    `wait_for_free_buffer()` (EGL Wayland) while the
                    session is locked and the screen is off
    Classification: Plasma
           Product: kwin
      Version First 6.8.3
       Reported In:
          Platform: Other
                OS: Linux
            Status: REPORTED
          Severity: normal
          Priority: NOR
         Component: wayland-generic
          Assignee: [email protected]
          Reporter: [email protected]
  Target Milestone: ---

With the screen locked and off, `plasmashell` sits at 100% CPU. One
QSGRenderThread is stuck in Mesa's wait_for_free_buffer()
(src/egl/drivers/dri2/platform_wayland.c). That function waits for a
wl_buffer.release by calling wl_display_roundtrip_queue() in a loop with no
backoff and no timeout. The compositor answers every wl_display.sync
immediately but never releases a buffer, so the loop never exits.

Unlocking the screen ends the spin.

Distro: Fedora
Mesa: 26.2.6 (libgallium-26.2.6.so, libEGL_mesa.so.0.0.0)
Qt: 6.11.2
libwayland: libwayland-client.so.0.26.0
Plasma / KWin: plasmashell 6.8.3, kwin 6.8.3
GPU: Intel Raptor Lake-P [Iris Xe Graphics]
EGL driver: iris (mesa-dri-drivers-26.2.6-1.fc45.x86_64)
Kernel: 7.3.3-300.fc45.x86_64
Session: Wayland, locked via kscreenlocker, output off (DPMS)

Steps to reproduce:

Not yet reliable. It occurs after plasmashell has been running for a while,
with the session locked and the screen off.

Observed trigger (from the WAYLAND_DEBUG=1 capture, section 4): a small
plasmashell popup (278x40 logical, with a blur region) that is shown and hidden
repeatedly on the same `wl_surface`. KWin never releases the last buffer of the
hidden window, so the 4-slot Mesa swapchain fills up after three show/hide
cycles. The next show spins. It took ~18 hours and four shows of that popup to
get there.

The first guess was a notification popup. The spinning surface is not one of
the 498 px wide popups that appear every hour at :45 (probably notifications).
Those get a fresh surface and swapchain each time, and are destroyed normally.

I haven't find out what the popup is (an audio OSD is my suspect: plasmashell
printed org.kde.pulseaudio: No object for name "bluez_output..." two seconds
before the spin). Could be my bluetooth ear plugs.

Stack of the spinning thread (`eu-stack`):

TID 23558, comm QSGRenderThread:

#3  wl_display_read_events
#4  wl_display_dispatch_queue_timeout
#5  wl_display_dispatch_queue
#6  wl_display_roundtrip_queue
#7  update_buffers_if_needed          (libEGL_mesa)
#8  image_get_buffers
#9  dri_image_drawable_get_buffers    (libgallium)
#10 dri2_allocate_textures
#11 dri_st_framebuffer_validate
#12 st_framebuffer_validate
#13 st_manager_validate_framebuffers
#14 st_update_framebuffer_state
#15 st_Clear
#16 QRhiGles2::executeCommandBuffer
#17 QRhiGles2::endFrame
#18 QRhi::endFrame
#19 QSGRenderThread::syncAndRender
#20 QSGRenderThread::run

strace -f -k -e trace=sendmsg - shows the same stack on every sendmsg(). The
update_buffers_if_needed frame is wait_for_free_buffer() inlined. See also
below.

The main thread (TID 3506) is blocked in QSGThreadedRenderLoop::polishAndSync
under QWaylandWindow::synthesizeExposeOnGeometryChange → handleExposure, i.e.
handling a newly shown or resized window. TID 23558 is also the newest render
thread by TID, so its window was created long after startup.

2. Wire traffic (strace -f, ~1M lines, a few seconds)

- 41,287 sendmsg and 41,287 matching recvmsg on fd 3 (the Wayland socket).
- Every sendmsg is the 12-byte wl_display.sync request. The new callback ID
alternates between 0xd7 and
  0x101.
- Every reply is 24 bytes: wl_callback.done plus wl_display.delete_id.
  The done serial is always 0x11c0 (4544), so the connection is otherwise idle.
- No other requests are sent: no attach, commit or frame.
- Two other threads, WaylandEventThr (3584) and ClipboardThread (4213), poll
the same fd. Each sync reply
  wakes them and they contend for the display mutex, which adds to the CPU use.
They are not the cause.

3. Mesa source

wait_for_free_buffer() in src/egl/drivers/dri2/platform_wayland.c:

while (dri2_surf->back == NULL) {
   /* ...pick an unlocked color_buffers[i]... */
   if (dri2_surf->back)
      break;

   /* If we don't have a buffer, then block on the server to release one for
    * us, and try again. wl_display_dispatch_queue will process any pending
    * events, however not all servers flush on issuing a buffer release
    * event. So, we spam the server with roundtrips as they always cause a
    * client flush.
    */
   if (wl_display_roundtrip_queue(dri2_dpy->wl_dpy, dri2_surf->wl_queue) < 0)
      return;
}

The roundtrip loop was introduced in `151188d1e33` ("egl/wayland: Use
roundtrips when awaiting buffer release"). A buffer stays locked until its
wl_buffer.release arrives. If the compositor holds every buffer of the
swapchain, the loop spins.

4. Wayland protocol log (`WAYLAND_DEBUG=1 plasmashell`)

The log I created was 35 GB (~26 hours).

The spinning surface is wl_surface#111, a 278x40 popup (buffers 417x60 or
429x60, so scale 1.5) that is shown and hidden several times:

Time (UTC) - Event on `wl_surface#111

15:39:33 - shown: buffers #81, #133 (417x60) attached
15:39:34 - hidden: attach(nil) + commit
15:41:34 - shown again: #81 released only now; #185, #142 (429x60) attached.
#133 is never released
15:41:36 - hidden
09:23:25 - shown: #185 released only now; #92, #205 (417x60) attached. #133 and
#142 are still not released 
09:23:26 - hidden
09:23:28.33 - shown at 286x40: #92 released; #81 (429x60) attached and
committed
09:23:28.333 - spin starts

At that point all four Mesa slots are locked: #133, #142 and #205 havenever
been released (no release() for them anywhere in the log), and #81 is the
buffer just attached. locked is only cleared by wl_buffer.release
(platform_wayland.c:351), and dri2_wl_release_buffers() on a resize does not
clear it for buffers still held (line 1039). So wait_for_free_buffer() has
nothing to pick and loops.

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to