Reading Cycle Count register on ARM cortex-a8

0

I am trying to read the cycle count register on an ARM cortex-a8 CPU from an android native library on an emulator, emulating the Nexus S.

Here are links regarding the two registers I am trying to read and write: http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0344b/Bgbcjifb.html http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0344b/Bgbjjhaj.html

Here is what I have done:

  1. Started the emulator with a modified goldfish kernel, with the line CONFIG_MODULES=y insterted into the .config file to enable module loading.

  2. Created a module from the following C file: android_module.c

    #include <linux/module.h>
    #include <linux/kernel.h>
    
    MODULE_LICENSE ("GPL");
    
    int init_module(void)
    {  
        /* enable user-mode access to the performance counter*/
        asm volatile ("mcr p15,  0, %0, c9,  c14, 0\n" : : "r" (1));
    
        /* disable counter overflow interrupts (just in case)*/
        asm volatile ("MCR p15, 0, %0, C9, C14, 2\n\t" :: "r"(0x8000000f));
    
        printk (KERN_INFO "User-level access to CCR has been turned on.\n");
        return 0;
    }
    
    
    
    void cleanup_module(void)
    {
        printk (KERN_INFO "Goodbye Module\n");
    }
    
  3. The library has the following lines that attempt to read the cycle counter:

     unsigned int result;
     asm volatile ("MRC p15, 0, %0, c9, c13, 0\n\t":  "=r" (result)::);
    
  4. I start the emulator from eclipse with the following command line options:

     -kernel /home/developer/AndroidDevelopment/kernel/goldfish/arch/arm/boot/zImage
    
  5. I push the module into the emulator then:

     $adb shell insmod android_module.ko
    
     $dmesg
    

and the last line of that is:

<6>User-level access to CCR has been turned on.

so I know that the module has been installed. However when I run the App that uses the library, I get the following message in Logcat and the App terminates.

06-20 19:16:03.860: A/libc(806): Fatal signal 4 (SIGILL) at 0x4e9c31b8 (code=1), thread 826 (Thread-75)

Does anyone know why I am still getting this error? It goes away when I delete the line trying to access the cycle count register, so some how I must still not be allowed to read it even though I think I did everything to allow reading.

android
performance
arm
cortex-a8
asked on Stack Overflow Jun 20, 2013 by Eric Telmer

1 Answer

0

I think you are seeing this problem because you have to enable user-mode access for all the cores. Try using on_each_cpu, and see if it works.

answered on Stack Overflow Jun 20, 2013 by Ash

User contributions licensed under CC BY-SA 3.0