]> code.ossystems Code Review - openembedded-core.git/commitdiff
udev-cache: replace readfiles() with cmp
authorRichard Tollerton <rich.tollerton@ni.com>
Mon, 8 Dec 2014 23:13:35 +0000 (17:13 -0600)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Fri, 19 Dec 2014 17:54:14 +0000 (17:54 +0000)
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.

Signed-off-by: Richard Tollerton <rich.tollerton@ni.com>
meta/recipes-core/udev/udev/init
meta/recipes-core/udev/udev/udev-cache

index d26cbfca96c50efa0b2ad94de6f43b2f022a68c9..ee7967063a3f7fbdac4532eb3d9184a6e683fd7a 100644 (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
index a1410f5579202eaa88926c5f175495d8fa851087..e0e1c39488eebee2cc813389e6c1d1e16078073e 100644 (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"