chiark / gitweb /
udevd: use a tighter loop for compare_devpath()
authorAlan Jenkins <alan-jenkins@tuffmail.co.uk>
Sat, 25 Oct 2008 16:01:21 +0000 (17:01 +0100)
committerKay Sievers <kay.sievers@vrfy.org>
Sat, 25 Oct 2008 17:41:52 +0000 (19:41 +0200)
This crops up in my threaded udevd profiles from time to time.
It's not consistent - probably due to variations in the number
of concurrent events - but it can hit 4% user time and higher.

The change halves the user time spent in compare_devpath().

Signed-off-by: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
udev/udevd.c

index 21fd6f82e7355acbad3d0c3074d39783dd23791b..0bacb3994b00a716fa2af15aaaa64af7391fa4c5 100644 (file)
@@ -310,26 +310,24 @@ static int mem_size_mb(void)
 
 static int compare_devpath(const char *running, const char *waiting)
 {
-       int i;
+       int i = 0;
 
-       for (i = 0; i < UTIL_PATH_SIZE; i++) {
-               /* identical device event found */
-               if (running[i] == '\0' && waiting[i] == '\0')
-                       return 1;
+       while (running[i] == waiting[i] && running[i] != '\0')
+               i++;
 
-               /* parent device event found */
-               if (running[i] == '\0' && waiting[i] == '/')
-                       return 2;
+       /* identical device event found */
+       if (running[i] == '\0' && waiting[i] == '\0')
+               return 1;
 
-               /* child device event found */
-               if (running[i] == '/' && waiting[i] == '\0')
-                       return 3;
+       /* parent device event found */
+       if (running[i] == '\0' && waiting[i] == '/')
+               return 2;
 
-               /* no matching event */
-               if (running[i] != waiting[i])
-                       break;
-       }
+       /* child device event found */
+       if (running[i] == '/' && waiting[i] == '\0')
+               return 3;
 
+       /* no matching event */
        return 0;
 }