title: How to use Raspberry Pi Clock Count for performance measurement
body: <p>I make performance measurements on the Raspberry Pi and would like to have higher resolution then just clock_gettime().</p>
  
  <p>Therefor I need to enable the CPU register PMUSERENR. </p>
  
  <p>According to /proc/cpuinfo on my Raspberry Pi I have an "ARMv7 Processor rev 5 (v7l)". So I downloaded the architecture reference manual and found that I have to use:</p>
  
  <p>CRn = c9, opc1 = 0, CRm = c14, opc2 = 0</p>
  
  <pre><code>asm ("MCR p15, 0, %0, C9, C14, 0\n\t" :: "r"(1));
  </code></pre>
  
  <p>But when using this code in a kernel module, I get following oops:</p>
  
  <pre><code>Message from syslogd@raspberrypi at Apr 29 20:58:12 ...
   kernel:[   84.604846] Internal error: Oops: 5 [#1] SMP ARM
  
  Message from syslogd@raspberrypi at Apr 29 20:58:12 ...
   kernel:[   84.715199] Process insmod (pid: 2944, stack limit = 0xac80e210)
  
  Message from syslogd@raspberrypi at Apr 29 20:58:12 ...
   kernel:[   84.722399] Stack: (0xac80fe90 to 0xac810000)
  
  Message from syslogd@raspberrypi at Apr 29 20:58:12 ...
   kernel:[   84.727920] fe80:                                     7f1ba0f8 00007fff 80098128 ac80fea8
  
  Message from syslogd@raspberrypi at Apr 29 20:58:12 ...
   kernel:[   84.738472] fea0: 80578128 0000002d 00000000 7f1ba0f8 7f1ba0f8 7f1ba26c 7f1ba264 7f1ba134
  
  Message from syslogd@raspberrypi at Apr 29 20:58:12 ...
   kernel:[   84.749092] fec0: ac80e000 8057608c ac80feec ac80fed8 8057608c 00000000 00000000 00000000
  
  Message from syslogd@raspberrypi at Apr 29 20:58:12 ...
   kernel:[   84.759724] fee0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
  pi@raspberrypi ~/projects/timer $ 
  Message from syslogd@raspberrypi at Apr 29 20:58:12 ...
   kernel:[   84.770389] ff00: 00000000 00000000 00000000 00000000 76f5e948 00007390 00000000 76f7b390
  
  Message from syslogd@raspberrypi at Apr 29 20:58:12 ...
   kernel:[   84.781147] ff20: 76f5e948 b91a2390 ac80e000 00000000 ac80ffa4 ac80ff40 8009b6c4 80099714
  
  Message from syslogd@raspberrypi at Apr 29 20:58:12 ...
   kernel:[   84.792000] ff40: b919b000 00007390 b91a0598 b91a0457 b91a22c8 0000026c 000002ac 00000000
  
  Message from syslogd@raspberrypi at Apr 29 20:58:12 ...
   kernel:[   84.802930] ff60: 00000000 00000000 0000001f 00000020 0000000c 0000000a 00000009 00000000
  
  Message from syslogd@raspberrypi at Apr 29 20:58:12 ...
   kernel:[   84.813947] ff80: 7ea4371c 00000000 55afc028 00000080 8000fc28 ac80e000 00000000 ac80ffa8
  
  Message from syslogd@raspberrypi at Apr 29 20:58:12 ...
   kernel:[   84.825056] ffa0: 8000fa20 8009b5f0 7ea4371c 00000000 76f74000 00007390 76f5e948 76f74000
  
  Message from syslogd@raspberrypi at Apr 29 20:58:12 ...
   kernel:[   84.836170] ffc0: 7ea4371c 00000000 55afc028 00000080 55afbf78 00007390 76f5e948 00000000
  
  Message from syslogd@raspberrypi at Apr 29 20:58:12 ...
   kernel:[   84.847338] ffe0: 00000000 7ea436c4 76f55fb4 76ec0534 60000010 76f74000 00000000 00000000
  
  Message from syslogd@raspberrypi at Apr 29 20:58:12 ...
   kernel:[   84.880715] Code: e51b3084 e1530005 e2455008 0a000009 (e5953014) 
  </code></pre>
  
  <p>I am new to kernel modules, so I do not know which direction I should go. Is there a good way to debug such things?</p>