X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=lib%2Flfsr.c;h=9771318ab00163b8b6a9f68dc076cd896c00fda6;hp=b10ba7a7e1b3cfc07609b53f6c68317fa14cb53e;hb=225ba9e3433cf27d8ff7b213d9f78b7ef2776c70;hpb=d0f85362c978904661bd6785cd6a7f3437ff85dd diff --git a/lib/lfsr.c b/lib/lfsr.c index b10ba7a7..9771318a 100644 --- a/lib/lfsr.c +++ b/lib/lfsr.c @@ -2,6 +2,7 @@ #include #include "lfsr.h" +#include "../compiler/compiler.h" /* * LFSR taps retrieved from: @@ -87,7 +88,6 @@ static inline void __lfsr_next(struct fio_lfsr *fl, unsigned int spin) * this switch. */ switch (spin) { - case 16: __LFSR_NEXT(fl, fl->last_val); case 15: __LFSR_NEXT(fl, fl->last_val); case 14: __LFSR_NEXT(fl, fl->last_val); case 13: __LFSR_NEXT(fl, fl->last_val); @@ -126,23 +126,16 @@ static inline void __lfsr_next(struct fio_lfsr *fl, unsigned int spin) */ int lfsr_next(struct fio_lfsr *fl, uint64_t *off, uint64_t last) { - unsigned int spin = fl->spin; - if (fl->num_vals++ > fl->max_val) return 1; do { - if (fl->cycle_length) { - fl->cycle_length--; - if (!fl->cycle_length) { - __lfsr_next(fl, fl->spin + 1); - fl->cycle_length = fl->cached_cycle_length; - goto check; - } - } - __lfsr_next(fl, spin); -check: ; - } while (fl->last_val > fl->max_val); + if (fl->cycle_length && !--fl->cycle_length) { + __lfsr_next(fl, fl->spin + 1); + fl->cycle_length = fl->cached_cycle_length; + } else + __lfsr_next(fl, fl->spin); + } while (fio_unlikely(fl->last_val > fl->max_val)); *off = fl->last_val; return 0; @@ -163,8 +156,13 @@ static uint8_t *find_lfsr(uint64_t size) { int i; + /* + * For an LFSR, there is always a prohibited state (all ones). + * Thus, if we need to find the proper LFSR for our size, we must take that + * into account. + */ for (i = 3; i < 64; i++) - if ((1UL << i) > size) /* TODO: Explain why. */ + if ((1UL << i) > size) return taps[i]; return NULL; @@ -210,6 +208,12 @@ int prepare_spin(struct fio_lfsr *fl, unsigned int spin) } fl->cached_cycle_length = fl->cycle_length; + /* + * Increment cycle length for the first time only since the stored value + * will not be printed otherwise. + */ + fl->cycle_length++; + return 0; }