replace 'fill_pattern' with 'cpy_pattern' from 'lib/pattern.c'
authorRoman Pen <r.peniaev@gmail.com>
Wed, 19 Aug 2015 10:33:08 +0000 (12:33 +0200)
committerJens Axboe <axboe@fb.com>
Fri, 4 Sep 2015 19:33:04 +0000 (13:33 -0600)
All pattern helpers are now located inside 'lib/pattern.c',
and 'cpy_pattern' should be sligtly faster, since it does
copy doubling the size on every iteration.

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

index cb0a1b5a7e9a8fce2525cc443ff58d72c250a4ad..296655bcc8b604ed31f2ac03ea4f1e9b590c9207 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -198,7 +198,8 @@ T_IEEE_OBJS += lib/ieee754.o
 T_IEEE_PROGS = t/ieee754
 
 T_ZIPF_OBS = t/genzipf.o
-T_ZIPF_OBJS += t/log.o lib/ieee754.o lib/rand.o lib/zipf.o lib/gauss.o t/genzipf.o
+T_ZIPF_OBJS += t/log.o lib/ieee754.o lib/rand.o lib/pattern.o lib/zipf.o \
+               lib/strntol.o lib/gauss.o t/genzipf.o
 T_ZIPF_PROGS = t/fio-genzipf
 
 T_AXMAP_OBJS = t/axmap.o
index 2e4c66e144b5cc56a04ec8c4747e435368b68a3a..1b661a86946bd75a06c2048022422487b00f17ea 100644 (file)
@@ -36,6 +36,7 @@
 #include <string.h>
 #include <assert.h>
 #include "rand.h"
+#include "lib/pattern.h"
 #include "../hash.h"
 
 int arch_random;
@@ -134,32 +135,6 @@ unsigned long fill_random_buf(struct frand_state *fs, void *buf,
        return r;
 }
 
-void fill_pattern(void *p, unsigned int len, char *pattern,
-                 unsigned int pattern_bytes)
-{
-       switch (pattern_bytes) {
-       case 0:
-               assert(0);
-               break;
-       case 1:
-               memset(p, pattern[0], len);
-               break;
-       default: {
-               unsigned int i = 0, size = 0;
-               unsigned char *b = p;
-
-               while (i < len) {
-                       size = pattern_bytes;
-                       if (size > (len - i))
-                               size = len - i;
-                       memcpy(b+i, pattern, size);
-                       i += size;
-               }
-               break;
-               }
-       }
-}
-
 void __fill_random_buf_percentage(unsigned long seed, void *buf,
                                  unsigned int percentage,
                                  unsigned int segment, unsigned int len,
@@ -169,7 +144,7 @@ void __fill_random_buf_percentage(unsigned long seed, void *buf,
 
        if (percentage == 100) {
                if (pbytes)
-                       fill_pattern(buf, len, pattern, pbytes);
+                       (void)cpy_pattern(pattern, pbytes, buf, len);
                else
                        memset(buf, 0, len);
                return;
@@ -199,7 +174,7 @@ void __fill_random_buf_percentage(unsigned long seed, void *buf,
                        this_len = len;
 
                if (pbytes)
-                       fill_pattern(buf, this_len, pattern, pbytes);
+                       (void)cpy_pattern(pattern, pbytes, buf, this_len);
                else
                        memset(buf, 0, this_len);
 
index cab91585cac9e63fc76dd14d21a507deb179c8c6..b99f618c000f108db5fb56adfc4bc0eaa00cad30 100644 (file)
@@ -110,6 +110,5 @@ extern void __fill_random_buf(void *buf, unsigned int len, unsigned long seed);
 extern unsigned long fill_random_buf(struct frand_state *, void *buf, unsigned int len);
 extern void __fill_random_buf_percentage(unsigned long, void *, unsigned int, unsigned int, unsigned int, char *, unsigned int);
 extern unsigned long fill_random_buf_percentage(struct frand_state *, void *, unsigned int, unsigned int, unsigned int, char *, unsigned int);
-extern void fill_pattern(void *p, unsigned int len, char *pattern, unsigned int pattern_bytes);
 
 #endif
index 7608caf5e1ad58e4c6db18e8befd28fcae6da6c3..6133608e0f59f0c0789abdd89aeadaf05dd3e34d 100644 (file)
--- a/verify.c
+++ b/verify.c
@@ -13,6 +13,7 @@
 #include "trim.h"
 #include "lib/rand.h"
 #include "lib/hweight.h"
+#include "lib/pattern.h"
 
 #include "crc/md5.h"
 #include "crc/crc64.h"
@@ -35,7 +36,7 @@ static void __fill_hdr(struct verify_header *hdr, int verify_type, uint32_t len,
 
 void fill_buffer_pattern(struct thread_data *td, void *p, unsigned int len)
 {
-       fill_pattern(p, len, td->o.buffer_pattern, td->o.buffer_pattern_bytes);
+       (void)cpy_pattern(td->o.buffer_pattern, td->o.buffer_pattern_bytes, p, len);
 }
 
 void __fill_buffer(struct thread_options *o, unsigned long seed, void *p,
@@ -73,7 +74,7 @@ void fill_verify_pattern(struct thread_data *td, void *p, unsigned int len,
                return;
        }
 
-       fill_pattern(p, len, o->verify_pattern, o->verify_pattern_bytes);
+       (void)cpy_pattern(td->o.verify_pattern, td->o.verify_pattern_bytes, p, len);
        io_u->buf_filled_len = len;
 }