From b1273639823f4010d88557ab716c41aa200c5d76 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Mon, 23 Mar 2020 17:38:18 +0100 Subject: [PATCH] ply-device-manager: Only consume one udev event at a time Commit f9e376797a91 ("ply-device-manager: Consume all events in one go") changed ply-device-manager to consume all pending udev events in one go instead of consuming only 1 and then returning back to the mainloop. The idea here was to avoid the overhead of returning back to the mainloop, doing the poll again, seeing more events were pending and then re-enter ply-device-manager. In retrospect this is not a good idea. Systemd waits for oneshot units like plymouth-switch-root.service to finish and this can block the boot. Specifically plymouth-switch-root.service must complete before systemd in the initrd will exec the systemd from the real rootfs. This means that systemd inside the initrd waits for the: ExecStart=-/usr/bin/plymouth update-root-fs --new-root-dir=/sysroot Command to complete, if this command runs while we are consuming udev events from the graphics card (which sends a change event per probed connector during the initial probe), then plymouth will not send the ack to the plymouth boot-client (completing the ExecStart) until all udev events are consumed. On my main workstation with i915 graphics and 2 HDMI connected FHD monitors, this delays the actual switching of the root by 1.9 - 2.1 seconds, because the re-enumaration of the connectors in the drm plugin takes about 0.4 seconds per run. Other upcoming changes will greatly reduce that 0.4 seconds, but still returning to the main-loop after a single udev event so that we can answer any waiting boot-clients ASAP is a good idea. This reverts commit f9e376797a91ad5fbc1f8e8e4aea778f4f22397c. Signed-off-by: Hans de Goede --- src/libply-splash-core/ply-device-manager.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/libply-splash-core/ply-device-manager.c b/src/libply-splash-core/ply-device-manager.c index 160b8cb4..f65d7317 100644 --- a/src/libply-splash-core/ply-device-manager.c +++ b/src/libply-splash-core/ply-device-manager.c @@ -415,7 +415,7 @@ on_drm_udev_add_or_change (ply_device_manager_t *manager, } } -static bool +static void on_udev_event (ply_device_manager_t *manager) { struct udev_device *device; @@ -423,14 +423,14 @@ on_udev_event (ply_device_manager_t *manager) device = udev_monitor_receive_device (manager->udev_monitor); if (device == NULL) - return false; + return; action = udev_device_get_action (device); ply_trace ("got %s event for device %s", action, udev_device_get_sysname (device)); if (action == NULL) - return false; + return; if (strcmp (action, "add") == 0 || strcmp (action, "change") == 0) { const char *subsystem; @@ -450,14 +450,6 @@ on_udev_event (ply_device_manager_t *manager) } udev_device_unref (device); - return true; -} - -static void -on_udev_event_loop (ply_device_manager_t *manager) -{ - /* Call on_udev_event until all events are consumed */ - while (on_udev_event (manager)) {} } static void @@ -487,7 +479,7 @@ watch_for_udev_events (ply_device_manager_t *manager) fd, PLY_EVENT_LOOP_FD_STATUS_HAS_DATA, (ply_event_handler_t) - on_udev_event_loop, + on_udev_event, NULL, manager); } -- 2.47.3