0

I need to measure a very short time interval when debugging something in Linux kernel on an ARM android device (Nexus 7 with Qualcomm's quad-core Snapdragon S4 SoC). I found the shortest time interval that ktime_get() can measure is 30us since Nexus 7 uses a 30MHz timer, but my testing code (a simple interrupt handler) running less than 30us, so I always get 0us or 30us. I tried to read performance counter like below:

   unsigned long t1, t2;
   asm volatile ("MRC p15, 0, %0, c9, c13, 0\t\n": "=r"(t1));
   ...... //my interrupt handling code
   asm volatile ("MRC p15, 0, %0, c9, c13, 0\t\n": "=r"(t2));
   unsigned long interval = t2 - t1;

but the value of "t1", "t2" and "interval" was always 0.

My questions are: 1. does "asm volatile ("MRC p15, 0, %0, c9, c13, 0\t\n": "=r"(value));" work on Nexus 7? 2. what is this register? CPU cycles at current CPU frequency or a particular frequency? 3. Is there any method to measure the code execution time that shorter than a tick of 30MHz timer on Nexus 7?

Many thanks in advance!

Thanks Wang Li

Di Ding
  • 1
  • 1
  • Maybe a pragmatic workaround: Assuming that the handling code always does the same, you could measure it by calling it multiple times and then calculate an average for each call. – Jens Wirth Aug 26 '14 at 08:41
  • Thank you Jewirth. I cannot run this piece of code times, that will change system's behaviour. I have read the thread http://stackoverflow.com/questions/3247373, the difference is I need to read CCNT in kernel mode. Does anyone know the method or steps to enable and read cycle counter in kernel mode? – Di Ding Aug 27 '14 at 08:24
  • To enable CCNT, you have to write a kernel module and load it. Then you can read CCNT, also from usermode. In the question you mentioned, Nils Pipenbrinck commented on Jul 15 '10 at 22:47 to is own answer and explains how to do write the kernel module. – Jens Wirth Aug 27 '14 at 09:24

0 Answers0