From: Roman Pen Date: Wed, 19 Aug 2015 10:33:08 +0000 (+0200) Subject: replace 'fill_pattern' with 'cpy_pattern' from 'lib/pattern.c' X-Git-Tag: fio-2.2.10~7 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=2cac8fcb5ecaf5de549c36ee1cc2db75f00f8ff4 replace 'fill_pattern' with 'cpy_pattern' from 'lib/pattern.c' 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 Signed-off-by: Jens Axboe --- diff --git a/Makefile b/Makefile index cb0a1b5a..296655bc 100644 --- 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 diff --git a/lib/rand.c b/lib/rand.c index 2e4c66e1..1b661a86 100644 --- a/lib/rand.c +++ b/lib/rand.c @@ -36,6 +36,7 @@ #include #include #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); diff --git a/lib/rand.h b/lib/rand.h index cab91585..b99f618c 100644 --- a/lib/rand.h +++ b/lib/rand.h @@ -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 diff --git a/verify.c b/verify.c index 7608caf5..6133608e 100644 --- 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; }