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 <[email protected]>
---
 meta/recipes-core/udev/udev/init       | 29 +++++++----------------------
 meta/recipes-core/udev/udev/udev-cache | 17 +++--------------
 2 files changed, 10 insertions(+), 36 deletions(-)

diff --git a/meta/recipes-core/udev/udev/init b/meta/recipes-core/udev/udev/init
index d26cbfc..ee79670 100644
--- a/meta/recipes-core/udev/udev/init
+++ b/meta/recipes-core/udev/udev/init
@@ -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
diff --git a/meta/recipes-core/udev/udev/udev-cache 
b/meta/recipes-core/udev/udev/udev-cache
index a1410f5..e0e1c39 100644
--- a/meta/recipes-core/udev/udev/udev-cache
+++ b/meta/recipes-core/udev/udev/udev-cache
@@ -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"
-- 
2.1.3

-- 
_______________________________________________
Openembedded-core mailing list
[email protected]
http://lists.openembedded.org/mailman/listinfo/openembedded-core

Reply via email to