title: How to find the size of the L1 cache line size with IO timing measurements?
body: <p>As a school assignment, I need to find a way to get the L1 data cache line size, without reading config files or using api calls. Supposed to use memory accesses read/write timings to analyze &amp; get this info. So how might I do that? </p>
  
  <p>In an incomplete try for another part of the assignment, to find the levels &amp; size of cache, I have: </p>
  
  <pre><code>for (i = 0; i &lt; steps; i++) {
      arr[(i * 4) &amp; lengthMod]++;
  }
  </code></pre>
  
  <p>I was thinking maybe I just need vary line 2, <code>(i * 4)</code> part? So once I exceed the cache line size, I might need to replace it, which takes sometime? But is it so straightforward? The required block might already be in memory somewhere? Or perpahs I can still count on the fact that if I have a large enough <code>steps</code>, it will still work out quite accurately? </p>
  
  <p><strong>UPDATE</strong></p>
  
  <p><strong><a href="https://github.com/jiewmeng/cs3210-assign1/blob/master/cache-l1-line.cpp" rel="noreferrer">Heres an attempt on GitHub</a></strong>  ... main part below</p>
  
  <pre><code>// repeatedly access/modify data, varying the STRIDE
  for (int s = 4; s &lt;= MAX_STRIDE/sizeof(int); s*=2) {
      start = wall_clock_time();
      for (unsigned int k = 0; k &lt; REPS; k++) {
          data[(k * s) &amp; lengthMod]++;
      }
      end = wall_clock_time();
      timeTaken = ((float)(end - start))/1000000000;
      printf("%d, %1.2f \n", s * sizeof(int), timeTaken);
  }
  </code></pre>
  
  <p>Problem is there dont seem to be much differences between the timing. FYI. since its for L1 cache. I have SIZE = 32 K (size of array)</p>