Note that there are some explanatory texts on larger screens.

plurals
  1. POBENCH_INNER : lmbench3.0 src code macro query
    text
    copied!<p>I was reading the <a href="http://www.bitmover.com/lmbench/mhz-usenix.pdf" rel="nofollow">MHZ - Anatomy of a Benchmark</a> paper by the creators of lmbench and source browsing the code alongside. </p> <ol> <li>The paper can be downloaded @ <a href="http://www.bitmover.com/lmbench/mhz-usenix.pdf" rel="nofollow">MHz : Anatomy of a Microbenchmark</a></li> <li>Source Code <a href="http://nchc.dl.sourceforge.net/project/lmbench/development/lmbench-3.0-a9/lmbench-3.0-a9.tgz" rel="nofollow">lmbench-3.0</a> authored by Carl Staelin and Larry McVoy</li> </ol> <p>Inside the BENCH_INNER() macro I have a doubt :</p> <pre><code>#define BENCH_INNER(loop_body, enough) { \ static iter_t __iterations = 1; \ int __enough = get_enough(enough); \ iter_t __n; \ double __result = 0.; \ \ while(__result &lt; 0.95 * __enough) { \ start(0); \ for (__n = __iterations; __n &gt; 0; __n--) { \ loop_body; \ } \ __result = stop(0,0); \ if (__result &lt; 0.99 * __enough \ || __result &gt; 1.2 * __enough) { \ if (__result &gt; 150.) { \ double tmp = __iterations / __result; \ tmp *= 1.1 * __enough; \ __iterations = (iter_t)(tmp + 1); \ } else { \ if (__iterations &gt; (iter_t)1&lt;&lt;27) { \ __result = 0.; \ break; \ } \ __iterations &lt;&lt;= 3; \ } \ } \ } /* while */ \ save_n((uint64)__iterations); settime((uint64)__result); \ } </code></pre> <ol> <li><p>From what I understood, BENCH_INNER is used to auto compute the optimal number of iterations for a chosen timing interval ('enough'). The loop executes till we keep iterating over a piece of code 'loop_body' that would take at least 95% of our chosen timing interval which could range from 5ms to a 1second. </p></li> <li><p>For simplicity sake let us take 'enough' to be 10000 microseconds</p></li> <li>We start off with __iterations = 1</li> <li>Say over time we reached a stage where __result > 1.2 * 'enough' i.e. __result > 12000 microseconds</li> <li>Now since __result > 150 microseconds, we go ahead and scale the value of __iterations so that __result would be approximately equal to 1.1 * 'enough'</li> <li>But before we can recompute __result, we would break the loop since the earlier __result > .95 * 'enough'</li> <li>We go ahead and save the value of __result and modified value __iterations (here the value of __result is not for the __iterations which we save) </li> </ol> <p>Shouldn't the code in such a case recompute __result ? Did I miss something fundamental ?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload