LFSR: Fix spin related bug
PATCH 1/1 LFSR: Fix spin related bug
Hi Jens,
Thanks for the inclusion in your code, hopefully it was easy to review. I stumbled upon a silly bug which may affect some rare cases, so you may want to include that patch too, just in case.
Regards,
Alex
Alex Pyrgiotis (1):
Fix spin related bug
lib/lfsr.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
Signature · 1 line
1.8.1.4
PATCH 1/1 Fix spin related bug
On the previous patch on cycle detection, we would incremet spin value when:
num_vals % cycle_length == 0
which would evaluate always to true for the first iteration since we start with num_vals = 0. Only one corner-case is affected by this bug and this patch should fix it.
lib/lfsr.c +11 -5
@@ -108,22 +108,28 @@ static inline void __lfsr_next(struct fio_lfsr *fl, unsigned int spin) } } +/* +* lfsr_next does the following: +* +* a. Return if the number of max values has been exceeded. +* b. Check if the next iteration(s) produce a cycle (due to spin) and add "1" +* where necessary. +* c. Calculate the next value and return. +*/ int lfsr_next (struct fio_lfsr *fl,uint64_t *off,uint64_t last) {int repeat;unsigned int spin; +if (fl->num_vals++ > fl->max_val) +return 1 ; + repeat = fl->num_vals % fl->cycle_length;if (repeat ==0 ) spin = fl->spin +1 ;else spin = fl->spin; -if (fl->num_vals > fl->max_val) -return 1 ; - - fl->num_vals++; -do {__lfsr_next (fl, spin); }while (fl->last_val > fl->max_val);
Signature · 1 line
1.8.1.4
Re: [PATCH] Fix spin related bug
Quoted 8 lines · Alex Pyrgiotis
On the previous patch on cycle detection, we would incremet spin value when:
num_vals % cycle_length == 0which would evaluate always to true for the first iteration since we start with
num_vals= 0. Only one corner-case is affected by this bug and this patch should fix it.
Thanks Alex, applied.
Signature · 1 line
Jens Axboe