title: Is memory latency affected by CPU frequency? Is it a result of memory power management by the memory controller?
body: <p>I basically need some help to explain/confirm some experimental results.</p>
  
  <p><strong>Basic Theory</strong></p>
  
  <p>A common idea expressed in papers on DVFS is that execution times have on-chip and off-chip components. On-chip components of execution time scale linearly with CPU frequency whereas the off-chip components remain unaffected. </p>
  
  <p>Therefore, for CPU-bound applications, there is a linear relationship between CPU frequency and instruction-retirement rate. On the other hand, for a memory bound application where the caches are often missed and DRAM has to be accessed frequently, the relationship should be affine (one is not just a multiple of the other, you also have to add a constant).</p>
  
  <p><strong>Experiment</strong></p>
  
  <p>I was doing experiments looking at how CPU frequency affects instruction-retirement rate and execution time under different levels of memory-boundedness.</p>
  
  <p>I wrote a test application in C that traverses a linked list. I effectively create a linked list whose individual nodes have sizes equal to the size of a cache-line (64 bytes). I allocated a large amount of memory that is a multiple of the cache-line size. </p>
  
  <p>The linked list is circular such that the last element links to the first element. Also, this linked list randomly traverses through the cache-line sized blocks in the allocated memory. Every cache-line sized block in the allocated memory is accessed, and no block is accessed more than once. </p>
  
  <p>Because of the random traversal, I assumed it should not be possible for the hardware to use any pre-fetching. Basically, by traversing the list, you have a sequence of memory accesses with no stride pattern, no temporal locality, and no spacial locality. Also, because this is a linked list, one memory access can not begin until the previous one completes. Therefore, the memory accesses should not be parallelizable. </p>
  
  <p>When the amount of allocated memory is small enough, you should have no cache misses beyond initial warm up. In this case, the workload is effectively CPU bound and the instruction-retirement rate scales very cleanly with CPU frequency. </p>
  
  <p>When the amount of allocated memory is large enough (bigger than the LLC), you should be missing the caches. The workload is memory bound and the instruction-retirement rate should not scale as well with CPU frequency.</p>
  
  <p>The basic experimental setup is similiar to the one described here:
  "<a href="http://software.intel.com/en-us/forums/topic/495393" rel="nofollow noreferrer">Actual CPU Frequency vs CPU Frequency Reported by the Linux "cpufreq" Subsystem</a>".</p>
  
  <p>The above application is run repeatedly for some duration. At the start and end of the duration, the hardware performance counter is sampled to determine the number of instructions retired over the duration. The length of the duration is measured as well. The average instruction-retirement rate is measured as the ratio between these two values. </p>
  
  <p>This experiment is repeated across all the possible CPU frequency settings using the "userspace" CPU-frequency governor in Linux. Also, the experiment is repeated for the CPU-bound case and the memory-bound case as described above.</p>
  
  <p><strong>Results</strong></p>
  
  <p>The two following plots show results for the CPU-bound case and memory-bound case respectively. On the x-axis, the CPU clock frequency is specified in GHz. On the y-axis, the instruction-retirement rate is specified in (1/ns). </p>
  
  <p>A marker is placed for repetition of the experiment described above. The line shows what the result would be if instruction-retirement rate increased at the same rate as CPU frequency and passed through the lowest-frequency marker. </p>
  
  <hr>
  
  <p><img src="https://i.stack.imgur.com/OfrTA.jpg" alt="Instruction-retirement rate Vs CPU frequency for a CPU-bound application.">
  Results for the CPU-bound case.</p>
  
  <hr>
  
  <p><img src="https://i.stack.imgur.com/2fuwI.jpg" alt="Instruction-retirement rate Vs CPU frequency for a memory-bound application.">
  Results for the memory-bound case.</p>
  
  <hr>
  
  <p>The results make sense for the CPU-bound case, but not as much for the memory-bound case. All the markers for the memory-bound fall below the line which is expected because the instruction-retirement rate should not increase at the same rate as CPU frequency for a memory-bound application. The markers appear to fall on straight lines, which is also expected. </p>
  
  <p>However, there appears to be step-changes in the instruction-retirement rate with change in CPU frequency. </p>
  
  <p><strong>Question</strong></p>
  
  <p>What is causing the step changes in the instruction-retirement rate? The only explanation I could think of is that the memory controller is somehow changing the speed and power-consumption of memory with changes in the rate of memory requests. (As instruction-retirement rate increases, the rate of memory requests should increase as well.) Is this a correct explanation?</p>