site  contact  subhomenews

Fixed wait for kernel video modules to load

October 17, 2021 — BarryK

I have been working on hardware profiling for loading of kernel video modules, see recent posts:

The pups have, I think, "udevadm settle" in /etc/rc.d/rc.sysinit, which waits for all kernel drivers to load before continuing. However, attempting to get to the desktop quicker, EasyOS does not have this, instead waits for the kernel video module(s) to load before bringing up the desktop. That is, EasyOS does not wait for all modules to load, just enough to bring up the Xorg desktop.

The wait code is in /usr/bin/xwin, and it has required some fixing. This is the new code:

#20211016 rewritten...
#180501 restored this, removed "udevadm settle" in rc.sysinit...
##180410 remove (inserted "udevadm settle" in rc.sysinit instead)...
echo -n 'Waiting for kernel video drivers to load: '
VIDPATHS="$(busybox lspci | grep 'Class 0300:' | cut -f 1 -d ' ' | tr '\n' ' ')" #ex: 00:02.0
while [ $CNT -lt 20 ];do
if [ ! "$VIDMODULE" ];then
if [ -e /sys/bus/pci/devices/*:${VIDPATH}/modalias ];then
VIDALIAS="$(cat /sys/bus/pci/devices/*${VIDPATH}/modalias)"
if [ "$VIDALIAS" ];then
VIDMODULE="$(modprobe -R ${VIDALIAS} 2>/dev/null)"
if [ "$VIDMODULE" ];then
grep -q "^blacklist ${VIDMODULE}" /etc/modprobe.d/gpu.conf
[ $? -eq 0 ] && continue 2
if [ "$VIDMODULE" ];then
#kernel can be incredibly slow to update /proc/modules, check module loaded this way...
[ -e /sys/bus/pci/devices/*:${VIDPATH}/driver ] && continue 2 #module has loaded.
#fall to here, then video driver not yet loaded.
sleep 0.5
echo -n "${CNT} "

What the code does, is use lspci to obtain the "modalias" for the video interface, then uses modprobe to return the name of the module that is to be loaded. Finally, looks for the existence /sys/bus/pci/devices/.../driver which means that the driver has loaded. However, if the module is blacklisted, do not wait for it to load.

The code seems logical. I did try grepping /proc/modules, but found that to be very unreliable. The kernel is incredibly slow to update /proc/modules.

There are other ways to check that the module has loaded. For example:

# busybox lspci -k | grep 'Class 0300'
00:02.0 Class 0300: 8086:3e91 i915

...the last column, "i915", is the name of the loaded video module, and that column will only exist if the module has loaded.

This code is really just a precaution. It is only on a very slow old PC that there might have to be a wait.   

Tags: easy