verify: use 'cmp_pattern' from 'lib/pattern.c' to compare pattern and buffer
authorRoman Pen <r.peniaev@gmail.com>
Wed, 19 Aug 2015 10:33:09 +0000 (12:33 +0200)
committerJens Axboe <axboe@fb.com>
Fri, 4 Sep 2015 19:33:06 +0000 (13:33 -0600)
'cmp_pattern' function should be faster, since it does not use loops
and while doing 'memcmp' the same CPU cache line is used.

Keep in mind, that now single-byte pattern becomes the string of 512 bytes.
In that case this optimization will not work as expected, since 'memcmp'
will be called twice for the whole pattern, but in next patches this
behaviour will be avoided and single-byte pattern will stay single-byte
pattern without any attempt to duplicate it.

Also print buffer and pattern bytes as unsigned chars.

Signed-off-by: Roman Pen <r.peniaev@gmail.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
verify.c

index 6133608e0f59f0c0789abdd89aeadaf05dd3e34d..00daf9ccee1e3d2d5829e4b009ed07c2e4ab34a7 100644 (file)
--- a/verify.c
+++ b/verify.c
@@ -359,7 +359,8 @@ static int verify_io_u_pattern(struct verify_header *hdr, struct vcont *vc)
        struct io_u *io_u = vc->io_u;
        char *buf, *pattern;
        unsigned int header_size = __hdr_size(td->o.verify);
-       unsigned int len, mod, i, size, pattern_size;
+       unsigned int len, mod, i, pattern_size;
+       int rc;
 
        pattern = td->o.verify_pattern;
        pattern_size = td->o.verify_pattern_bytes;
@@ -369,23 +370,20 @@ static int verify_io_u_pattern(struct verify_header *hdr, struct vcont *vc)
        len = get_hdr_inc(td, io_u) - header_size;
        mod = header_size % pattern_size;
 
-       for (i = 0; i < len; i += size) {
-               size = pattern_size - mod;
-               if (size > (len - i))
-                       size = len - i;
-               if (memcmp(buf + i, pattern + mod, size))
-                       /* Let the slow compare find the first mismatch byte. */
-                       break;
-               mod = 0;
-       }
+       rc = cmp_pattern(pattern, pattern_size, mod, buf, len);
+       if (!rc)
+               return 0;
 
-       for (; i < len; i++) {
+       /* Slow path, compare each byte */
+       for (i = 0; i < len; i++) {
                if (buf[i] != pattern[mod]) {
                        unsigned int bits;
 
                        bits = hweight8(buf[i] ^ pattern[mod]);
-                       log_err("fio: got pattern %x, wanted %x. Bad bits %d\n",
-                               buf[i], pattern[mod], bits);
+                       log_err("fio: got pattern '%02x', wanted '%02x'. Bad bits %d\n",
+                               (unsigned char)buf[i],
+                               (unsigned char)pattern[mod],
+                               bits);
                        log_err("fio: bad pattern block offset %u\n", i);
                        dump_verify_buffers(hdr, vc);
                        return EILSEQ;
@@ -395,7 +393,9 @@ static int verify_io_u_pattern(struct verify_header *hdr, struct vcont *vc)
                        mod = 0;
        }
 
-       return 0;
+       /* Unreachable line */
+       assert(0);
+       return EILSEQ;
 }
 
 static int verify_io_u_meta(struct verify_header *hdr, struct vcont *vc)