swaywm / swaybg

Wallpaper tool for Wayland compositors
MIT License
490 stars 31 forks source link

High CPU usage with wlroots 0.15 #38

Closed adigitoleo closed 2 years ago

adigitoleo commented 2 years ago

Swaybg started using up to 100% CPU after upgrading to wlroots 0.15.0-4

Also upgraded kernel:

%zsh> uname -r
5.16.2-arch1-1

Happens also after shutting down and restarting the swaybg process (with or without setsid). Doesn't seem to depend on the -m mode.

I can make it happen with simple stuff like swaybg -c #ff0000 (seems to be ~65%, rather than ~100% when using an image).

%zsh> swaybg --version
swaybg version 1.1

I'm using the dwl compositor, I'll try on sway if I get a chance.

Output of the example, for reference:

%zsh> swaybg -c #ff0000
2022-01-28 08:36:36 - [swaybg-1.1/main.c:321] Found config * for output HDMI-A-5 (Samsung Electric Company C24F390 HTPJ700036)
2022-01-28 08:36:36 - [swaybg-1.1/main.c:321] Found config * for output HDMI-A-4 (Unknown MSI MAG161V AA1H010800597)
adigitoleo commented 2 years ago

Occurs also on 5.16.1 and 5.15.13 kernels (had to rollback due to other issues).

mstoeckl commented 2 years ago

There was an issue in the past where sway or wayfire would ask swaybg to redraw unnecessarily, but I forgot what caused it; dwl might have the same problem? Try running WAYLAND_DEBUG=1 swaybg -c #ff0000 and post the resulting logs, to see if this is the case for you.

Building swaybg from git might limit the cost of this problem, since the the commit 5e2df3a600e07b71923c28a8cd51861289319c91 avoids rerendering frames if nothing has changed.

adigitoleo commented 2 years ago

Indeed, it seems to be redrawing and destroying something continuously.

Log sample ``` %zsh> WAYLAND_DEBUG=1 swaybg -c #ff0000 [ 591685.727] -> wl_display@1.get_registry(new id wl_registry@2) [ 591685.758] -> wl_display@1.sync(new id wl_callback@3) [ 591685.882] wl_display@1.delete_id(3) [ 591685.892] wl_registry@2.global(1, "wl_shm", 1) [ 591685.912] -> wl_registry@2.bind(1, "wl_shm", 1, new id [unknown]@4) [ 591685.938] wl_registry@2.global(2, "wl_drm", 2) [ 591685.947] wl_registry@2.global(3, "zwp_linux_dmabuf_v1", 4) [ 591685.977] wl_registry@2.global(4, "wl_compositor", 4) [ 591685.989] -> wl_registry@2.bind(4, "wl_compositor", 4, new id [unknown]@5) [ 591686.034] wl_registry@2.global(5, "wl_subcompositor", 1) [ 591686.046] wl_registry@2.global(6, "zwlr_export_dmabuf_manager_v1", 1) [ 591686.057] wl_registry@2.global(7, "zwlr_screencopy_manager_v1", 3) [ 591686.068] wl_registry@2.global(8, "zwlr_data_control_manager_v1", 2) [ 591686.079] wl_registry@2.global(9, "wl_data_device_manager", 3) [ 591686.090] wl_registry@2.global(10, "zwlr_gamma_control_manager_v1", 1) [ 591686.101] wl_registry@2.global(11, "zwp_primary_selection_device_manager_v1", 1) [ 591686.113] wl_registry@2.global(12, "wp_viewporter", 1) [ 591686.124] wl_registry@2.global(13, "xdg_activation_v1", 1) [ 591686.134] wl_registry@2.global(14, "zxdg_output_manager_v1", 3) [ 591686.146] -> wl_registry@2.bind(14, "zxdg_output_manager_v1", 2, new id [unknown]@6) [ 591686.163] wl_registry@2.global(15, "org_kde_kwin_idle", 1) [ 591686.175] wl_registry@2.global(16, "zwlr_layer_shell_v1", 4) [ 591686.188] -> wl_registry@2.bind(16, "zwlr_layer_shell_v1", 1, new id [unknown]@7) [ 591686.204] wl_registry@2.global(17, "xdg_wm_base", 2) [ 591686.216] wl_registry@2.global(18, "org_kde_kwin_server_decoration_manager", 1) [ 591686.229] wl_registry@2.global(19, "zxdg_decoration_manager_v1", 1) [ 591686.241] wl_registry@2.global(20, "zwp_virtual_keyboard_manager_v1", 1) [ 591686.254] wl_registry@2.global(21, "wl_seat", 7) [ 591686.264] wl_registry@2.global(22, "zwlr_output_manager_v1", 2) [ 591686.275] wl_registry@2.global(23, "wp_presentation", 1) [ 591686.287] wl_registry@2.global(24, "wl_output", 4) [ 591686.298] -> wl_registry@2.bind(24, "wl_output", 3, new id [unknown]@8) [ 591686.313] wl_registry@2.global(25, "wl_output", 4) [ 591686.326] -> wl_registry@2.bind(25, "wl_output", 3, new id [unknown]@9) [ 591686.340] wl_callback@3.done(2346) [ 591686.347] -> zxdg_output_manager_v1@6.get_xdg_output(new id zxdg_output_v1@3, wl_output@9) [ 591686.358] -> zxdg_output_manager_v1@6.get_xdg_output(new id zxdg_output_v1@10, wl_output@8) [ 591686.441] wl_output@8.geometry(0, 0, 300, 260, 0, "Unknown", "MSI MAG161V", 0) [ 591686.480] wl_output@8.mode(1, 1920, 1080, 60000) [ 591686.496] wl_output@8.scale(2) [ 591686.501] wl_output@8.done() [ 591686.504] wl_output@9.geometry(0, 0, 520, 290, 0, "Samsung Electric Company", "C24F390", 0) [ 591686.529] wl_output@9.mode(1, 1920, 1080, 60000) [ 591686.545] wl_output@9.scale(1) [ 591686.550] wl_output@9.done() [ 591686.553] zxdg_output_v1@3.name("HDMI-A-2") [ 591686.559] zxdg_output_v1@3.description("Samsung Electric Company C24F390 HTPJ700036 (HDMI-A-2)") [ 591686.565] zxdg_output_v1@3.logical_position(0, 0) [ 591686.574] zxdg_output_v1@3.logical_size(1920, 1080) [ 591686.582] zxdg_output_v1@3.done() 2022-01-30 15:31:12 - [swaybg-1.1/main.c:321] Found config * for output HDMI-A-2 (Samsung Electric Company C24F390 HTPJ700036) [ 591686.621] -> wl_compositor@5.create_surface(new id wl_surface@11) [ 591686.629] -> wl_compositor@5.create_region(new id wl_region@12) [ 591686.636] -> wl_surface@11.set_input_region(wl_region@12) [ 591686.642] -> wl_region@12.destroy() [ 591686.647] -> zwlr_layer_shell_v1@7.get_layer_surface(new id zwlr_layer_surface_v1@13, wl_surface@11, wl_output@9, 0, "wallpaper") [ 591686.664] -> zwlr_layer_surface_v1@13.set_size(0, 0) [ 591686.673] -> zwlr_layer_surface_v1@13.set_anchor(15) [ 591686.679] -> zwlr_layer_surface_v1@13.set_exclusive_zone(-1) [ 591686.683] -> wl_surface@11.commit() [ 591686.687] wl_output@9.done() [ 591686.692] zxdg_output_v1@10.name("HDMI-A-1") [ 591686.697] zxdg_output_v1@10.description("Unknown MSI MAG161V AA1H010800597 (HDMI-A-1)") [ 591686.703] zxdg_output_v1@10.logical_position(-1372, 0) [ 591686.711] zxdg_output_v1@10.logical_size(1372, 772) [ 591686.719] zxdg_output_v1@10.done() 2022-01-30 15:31:12 - [swaybg-1.1/main.c:321] Found config * for output HDMI-A-1 (Unknown MSI MAG161V AA1H010800597) [ 591686.734] -> wl_compositor@5.create_surface(new id wl_surface@14) [ 591686.741] -> wl_compositor@5.create_region(new id wl_region@15) [ 591686.748] -> wl_surface@14.set_input_region(wl_region@15) [ 591686.754] -> wl_region@15.destroy() [ 591686.759] -> zwlr_layer_shell_v1@7.get_layer_surface(new id zwlr_layer_surface_v1@16, wl_surface@14, wl_output@8, 0, "wallpaper") [ 591686.775] -> zwlr_layer_surface_v1@16.set_size(0, 0) [ 591686.782] -> zwlr_layer_surface_v1@16.set_anchor(15) [ 591686.788] -> zwlr_layer_surface_v1@16.set_exclusive_zone(-1) [ 591686.793] -> wl_surface@14.commit() [ 591686.797] wl_output@8.done() [ 591686.866] wl_display@1.delete_id(12) [ 591686.872] wl_display@1.delete_id(15) [ 591686.876] zwlr_layer_surface_v1@13.configure(2347, 1920, 1080) [ 591686.897] zwlr_layer_surface_v1@13.configure(2348, 1920, 1080) [ 591686.906] zwlr_layer_surface_v1@16.configure(2349, 1372, 772) [ 591686.916] zwlr_layer_surface_v1@16.configure(2350, 1372, 772) [ 591686.927] -> zwlr_layer_surface_v1@13.ack_configure(2348) [ 591686.933] -> zwlr_layer_surface_v1@16.ack_configure(2350) [ 591686.959] -> wl_shm@4.create_pool(new id wl_shm_pool@15, fd 5, 8294400) [ 591686.973] -> wl_shm_pool@15.create_buffer(new id wl_buffer@12, 0, 1920, 1080, 7680, 0) [ 591686.990] -> wl_shm_pool@15.destroy() [ 591691.582] -> wl_surface@11.set_buffer_scale(1) [ 591691.600] -> wl_surface@11.attach(wl_buffer@12, 0, 0) [ 591691.642] -> wl_surface@11.damage_buffer(0, 0, 2147483647, 2147483647) [ 591691.673] -> wl_surface@11.commit() [ 591691.677] -> wl_buffer@12.destroy() [ 591691.951] -> wl_shm@4.create_pool(new id wl_shm_pool@17, fd 6, 16946944) [ 591691.967] -> wl_shm_pool@17.create_buffer(new id wl_buffer@18, 0, 2744, 1544, 10976, 0) [ 591692.014] -> wl_shm_pool@17.destroy() [ 591700.130] -> wl_surface@14.set_buffer_scale(2) [ 591700.146] -> wl_surface@14.attach(wl_buffer@18, 0, 0) [ 591700.158] -> wl_surface@14.damage_buffer(0, 0, 2147483647, 2147483647) [ 591700.171] -> wl_surface@14.commit() [ 591700.202] -> wl_buffer@18.destroy() [ 591709.454] discarded [unknown]@12.[event 0](0 fd, 8 byte) [ 591709.464] discarded [unknown]@18.[event 0](0 fd, 8 byte) [ 591709.469] wl_display@1.delete_id(15) [ 591709.475] wl_display@1.delete_id(12) [ 591709.480] wl_display@1.delete_id(17) [ 591709.485] wl_display@1.delete_id(18) [ 591709.510] zwlr_layer_surface_v1@13.configure(2352, 1920, 1080) [ 591709.524] zwlr_layer_surface_v1@16.configure(2353, 1372, 772) [ 591709.538] -> zwlr_layer_surface_v1@13.ack_configure(2352) [ 591709.545] -> zwlr_layer_surface_v1@16.ack_configure(2353) [ 591709.611] -> wl_shm@4.create_pool(new id wl_shm_pool@18, fd 5, 8294400) [ 591709.628] -> wl_shm_pool@18.create_buffer(new id wl_buffer@17, 0, 1920, 1080, 7680, 0) [ 591709.649] -> wl_shm_pool@18.destroy() [ 591713.440] -> wl_surface@11.set_buffer_scale(1) [ 591713.455] -> wl_surface@11.attach(wl_buffer@17, 0, 0) [ 591713.481] -> wl_surface@11.damage_buffer(0, 0, 2147483647, 2147483647) [ 591713.491] -> wl_surface@11.commit() [ 591713.494] -> wl_buffer@17.destroy() [ 591713.780] -> wl_shm@4.create_pool(new id wl_shm_pool@12, fd 6, 16946944) [ 591713.809] -> wl_shm_pool@12.create_buffer(new id wl_buffer@15, 0, 2744, 1544, 10976, 0) [ 591713.828] -> wl_shm_pool@12.destroy() [ 591721.464] -> wl_surface@14.set_buffer_scale(2) [ 591721.481] -> wl_surface@14.attach(wl_buffer@15, 0, 0) [ 591721.488] -> wl_surface@14.damage_buffer(0, 0, 2147483647, 2147483647) [ 591721.496] -> wl_surface@14.commit() [ 591721.498] -> wl_buffer@15.destroy() [ 591728.283] discarded [unknown]@17.[event 0](0 fd, 8 byte) [ 591728.291] discarded [unknown]@15.[event 0](0 fd, 8 byte) [ 591728.311] wl_display@1.delete_id(18) [ 591728.316] wl_display@1.delete_id(17) [ 591728.320] wl_display@1.delete_id(12) [ 591728.342] wl_display@1.delete_id(15) ```

The part between discarded [unknown]... messages is continuously repeated afterwards. I'll grab the git HEAD and see if it helps.

adigitoleo commented 2 years ago

The issue is solved on git master, both for a simple color and for images. Thanks for the help. If you have some hints on what might have caused the rerendering, I can take a look in dwl and maybe report this over there.

mstoeckl commented 2 years ago

The fix for the sway+wlroots issue was: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/3402 which landed in 0.15.0 . There was also the following sway PR, superseded by the wlroots change https://github.com/swaywm/sway/pull/6709 . It looks like the problem on sway was caused by the compositor assuming that the client had changed some significant surface property, when it had actually only resent the same value as before.

adigitoleo commented 2 years ago

Have moved to sway at the moment due to fatal pageflip errors in dwl that I don't have time to debug right now. I'll close this and maybe look into it on the dwl side later, thanks for the info.