On Mon, Dec 18, 2017 at 04:58:53PM -0500, Shih-Wei Li wrote: > On Mon, Dec 18, 2017 at 2:10 PM, Andrew Jones <drjones@xxxxxxxxxx> wrote: > >> +static void loop_test(struct exit_test *test) > >> +{ > >> + unsigned long i, iterations = 32; > >> + unsigned long sample, cycles; > >> + unsigned long long min = 0, max = 0; > >> + const unsigned long long goal = (1ULL << 29); > >> + > >> + do { > >> + iterations *= 2; > >> + cycles = 0; > >> + for (i = 0; i < iterations; i++) { > >> + sample = test->test_fn(); > >> + if (sample == 0) { > >> + /* > >> + * If something went wrong or we had an > >> + * overflow, don't count that sample. > >> + */ > >> + iterations--; > >> + i--; > > > > I'd prefer incrementing a different counter after the sample==0 test / > > continue, than to decrement both i and iterations. > > I'm not sure about the comment above. Could you please substantiate > how a new counter should work here? It doesn't really matter, but how about do { iterations *= 2; cycles = 0; i = 0; while (i < iterations) { sample = test->test_fn(); if (sample == 0) continue; cycles += sample; ... ++i; } } while (cycles < goal); > > > > >> + debug("cycle count overflow: %lu\n", sample); > >> + continue; > >> + } > >> + cycles += sample; > >> + if (min == 0 || min > sample) > >> + min = sample; > >> + if (max < sample) > >> + max = sample; > >> + } > >> + } while (cycles < goal); > >> + printf("%s:\t avg %lu\t min %llu\t max %llu\n", > >> + test->name, cycles / (iterations), min, max); > > Thanks, drew