udev-cache: replace readfiles() with cmp

Currently, udev-cache system configurations are compared as shell string
variables, read into memory with the readfiles() function. This is more
complex, and significantly (27-41%) slower, than comparing them using
`cmp`. (Performance was verified on both Cortex-A9 and Intel Nehalem
systems.)

So just use cmp. This requires a few other small changes:

exclude /proc/atags from CMP_FILE_LIST if it doesn't exist to avoid
errors in `cat` and `cmp`.

`cmp -q` doesn't exist in busybox, so instead, redirect output to
/dev/null.

(From OE-Core rev: e8ea6a29ed3ab9892a3bc7ee8249f10688c0af29)

Signed-off-by: Richard Tollerton <rich.tollerton@ni.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Richard Tollerton 2014-12-08 17:13:35 -06:00 committed by Richard Purdie
parent 24a159e169
commit 7f8634cc90
2 changed files with 10 additions and 36 deletions

View File

@ -20,17 +20,6 @@ SYSCONF_TMP="/dev/shm/udev.cache"
[ -f /etc/udev/udev.conf ] && . /etc/udev/udev.conf
[ -f /etc/default/rcS ] && . /etc/default/rcS
readfiles () {
READDATA=""
for filename in $@; do
if [ -r $filename ]; then
while read line; do
READDATA="$READDATA$line"
done < $filename
fi
done
}
kill_udevd () {
pid=`pidof -x udevd`
[ -n "$pid" ] && kill $pid
@ -63,14 +52,12 @@ case "$1" in
# Cache handling.
# A list of files which are used as a criteria to judge whether the udev cache could be reused.
CMP_FILE_LIST="/proc/version /proc/cmdline /proc/devices /proc/atags"
CMP_FILE_LIST="/proc/version /proc/cmdline /proc/devices"
[ -f /proc/atags ] && CMP_FILE_LIST="$CMP_FILE_LIST /proc/atags"
if [ "$DEVCACHE" != "" ]; then
if [ -e $DEVCACHE ]; then
readfiles $CMP_FILE_LIST
NEWDATA="$READDATA"
readfiles "$SYSCONF_CACHED"
OLDDATA="$READDATA"
if [ "$OLDDATA" = "$NEWDATA" ]; then
cat -- "$CMP_FILE_LIST" > "$SYSCONF_TMP"
if cmp $SYSCONF_CACHED $SYSCONF_TMP >/dev/null; then
tar xmf $DEVCACHE -C / -m
not_first_boot=1
[ "$VERBOSE" != "no" ] && echo "udev: using cache file $DEVCACHE"
@ -80,17 +67,15 @@ case "$1" in
if [ "$VERBOSE" != "no" ]; then
echo "udev: udev cache not used"
echo "udev: we use $CMP_FILE_LIST as criteria to judge whether the cache /dev could be resued"
echo "udev: olddata: $OLDDATA"
echo "udev: newdata: $NEWDATA"
echo "udev: cached sysconf: $SYSCONF_CACHED"
echo "udev: current sysconf: $SYSCONF_TMP"
fi
echo "$NEWDATA" > "$SYSCONF_TMP"
fi
else
if [ "$ROOTFS_READ_ONLY" != "yes" ]; then
# If rootfs is not read-only, it's possible that a new udev cache would be generated;
# otherwise, we do not bother to read files.
readfiles $CMP_FILE_LIST
echo "$READDATA" > "$SYSCONF_TMP"
cat -- "$CMP_FILE_LIST" > "$SYSCONF_TMP"
fi
fi
fi

View File

@ -21,20 +21,10 @@ SYSCONF_CACHED="/etc/udev/cache.data"
SYSCONF_TMP="/dev/shm/udev.cache"
# A list of files which are used as a criteria to judge whether the udev cache could be reused.
CMP_FILE_LIST="/proc/version /proc/cmdline /proc/devices /proc/atags"
CMP_FILE_LIST="/proc/version /proc/cmdline /proc/devices"
[ -f /proc/atags ] && CMP_FILE_LIST="$CMP_FILE_LIST /proc/atags"
[ -f /etc/default/udev-cache ] && . /etc/default/udev-cache
readfiles () {
READDATA=""
for filename in $@; do
if [ -r $filename ]; then
while read line; do
READDATA="$READDATA$line"
done < $filename
fi
done
}
if [ "$ROOTFS_READ_ONLY" = "yes" ]; then
[ "$VERBOSE" != "no" ] && echo "udev-cache: read-only rootfs, skip generating udev-cache"
exit 0
@ -43,8 +33,7 @@ fi
if [ "$DEVCACHE" != "" -a -e "$SYSCONF_TMP" ]; then
echo "Populating dev cache"
udevadm control --stop-exec-queue
readfiles $CMP_FILE_LIST
echo "$READDATA" > "$SYSCONF_TMP"
cat -- $CMP_FILE_LIST > "$SYSCONF_TMP"
find /dev -xdev \( -type b -o -type c -o -type l \) | cut -c 2- \
| xargs tar cf "${DEVCACHE_TMP}" -T-
gzip < "${DEVCACHE_TMP}" > "$DEVCACHE"