]> git.ipfire.org Git - thirdparty/dracut-ng.git/commitdiff
perf(drm): group dracut_instmods calls
authorAntonio Alvarez Feijoo <antonio.feijoo@suse.com>
Thu, 30 Nov 2023 14:04:43 +0000 (15:04 +0100)
committerLaszlo Gombos <laszlo.gombos@gmail.com>
Tue, 16 Apr 2024 23:10:22 +0000 (19:10 -0400)
This module loops over many bus devices, and calls `dracut_instmods` for each
one. E.g., on a Lenovo Thinkpad laptop:

```
> for i in /sys/bus/{pci/devices,platform/devices,virtio/devices,soc/devices/soc?,vmbus/devices}/*/modalias; do [[ -e $i ]] && [[ -n $(< "$i") ]]  && echo $i; done | wc -l
79
```

Every call to `dracut_instmods` spawns a `dracut-install` process, which in the
previous example means calling `dracut-install` 79 times using the same
arguments.

If any call to `dracut-install` fails, dracut continues its execution (even the
errors are not shown, because it's called with `--silent`). Therefore, let's
take the contents of all the `modalias` files into an array and call
`dracut-install` only once, adding also the `-o` argument, so if any of the
modules cannot be installed, `dracut-install` does not stop.

modules.d/50drm/module-setup.sh

index 1fb386778c806a29589b9f28b64b49e6529d88cc..43a99e8c27c2f364bd3fd53c7cf8651d4fa1d719 100755 (executable)
@@ -29,18 +29,22 @@ installkernel() {
     # as we could e.g. be in the installer; nokmsboot boot parameter will disable
     # loading of the driver if needed
     if [[ $hostonly ]]; then
+        local -a _mods
         local i modlink modname
 
         for i in /sys/bus/{pci/devices,platform/devices,virtio/devices,soc/devices/soc?,vmbus/devices}/*/modalias; do
             [[ -e $i ]] || continue
             [[ -n $(< "$i") ]] || continue
-            # shellcheck disable=SC2046
-            if hostonly="" dracut_instmods --silent -s "drm_crtc_init|drm_dev_register|drm_encoder_init" -S "iw_handler_get_spy" $(< "$i"); then
-                if strstr "$(modinfo -F filename $(< "$i") 2> /dev/null)" radeon.ko; then
+            mapfile -t -O "${#_mods[@]}" _mods < "$i"
+        done
+        if ((${#_mods[@]})); then
+            # shellcheck disable=SC2068
+            if hostonly="" dracut_instmods --silent -o -s "drm_crtc_init|drm_dev_register|drm_encoder_init" -S "iw_handler_get_spy" ${_mods[@]}; then
+                if strstr "$(modinfo -F filename "${_mods[@]}" 2> /dev/null)" radeon.ko; then
                     hostonly='' instmods amdkfd
                 fi
             fi
-        done
+        fi
         # if there is a privacy screen then its driver must be loaded before the
         # kms driver will bind, otherwise its probe() will return -EPROBE_DEFER
         # note privacy screens always register, even with e.g. nokmsboot