title: How do I programmatically disable hardware prefetching?
body: <p>I would like to programmatically disable hardware prefetching. </p>
  
  <p>From <a href="http://software.intel.com/en-us/articles/optimizing-application-performance-on-intel-coret-microarchitecture-using-hardware-implemented-prefetchers/" rel="nofollow noreferrer">Optimizing Application Performance on Intel® Core™ Microarchitecture Using Hardware-Implemented Prefetchers</a> and 
  <a href="http://software.intel.com/en-us/articles/how-to-choose-between-hardware-and-software-prefetch-on-32-bit-intel-architecture/" rel="nofollow noreferrer">How to Choose between Hardware and Software Prefetch on 32-Bit Intel® Architecture</a>,
  I need to update the MSR to disable hardware prefetching.</p>
  
  <p>Here is a relevant snippet:</p>
  
  <blockquote>
    <p>"DPL Prefetch and L2 Streaming Prefetch settings can also be changed programmatically
    by writing a device driver utility for changing the bits in the <code>IA32_MISC_ENABLE</code>
    register – <code>MSR 0x1A0</code>. Such a utility offers the ability to enable or disable prefetch
    mechanisms without requiring any server downtime.</p>
  </blockquote>
  
  <p>The table below shows the bits in the <code>IA32_MISC_ENABLE MSR</code> that have to be changed in order to control the <code>DPL</code> and L2 Streaming Prefetch:</p>
  
  <pre><code>Prefetcher Type MSR (0x1A0) Bit Value 
  DPL (Hardware Prefetch) Bit 9 0 = Enable 1 = Disable 
  L2 Streamer (Adjacent Cache Line Prefetch) Bit 19 0 = Enable 1 = Disable"
  </code></pre>
  
  <p>I tried using <a href="http://etallen.com/msr.html" rel="nofollow noreferrer">http://etallen.com/msr.html</a> but this did not work. 
  I also tried using <code>wrmsr</code> in <code>asm/msr.h</code> directly but that segfaults. 
  I tried doing this in a kernel module ... and killed the machine. </p>
  
  <p>BTW - I am using kernel 2.6.18-92.el5 and it has <code>MSR</code> linked in the kernel:</p>
  
  <pre><code>$ grep -i msr /boot/config-$(uname -r)
  CONFIG_X86_MSR=y
  ...
  </code></pre>