Counting cycles on the Sharp NetWalker PC-Z1

The NetWalker has an 800MHz Freescale i.MX515 (ARM Cortex A8) CPU. It runs Ubuntu 9.04.

Create an enableccnt directory. Inside that directory, create Makefile with the following contents:

     KERNELDIR := /usr/src/linux-headers-2.6.28-15-araneo
     obj-m := enableccnt.o
             $(MAKE) -C $(KERNELDIR) M=`pwd` modules
On the last line, make sure to use a tab rather than eight spaces. Create enableccnt.c with the following contents:
     #include <linux/module.h>
     #include <linux/kernel.h>
     #define DEVICE_NAME "enableccnt"
     static int enableccnt_init(void)
       printk(KERN_INFO DEVICE_NAME " starting\n");
       asm volatile("mcr p15, 0, %0, c9, c14, 0" :: "r"(1));
       return 0;
     static void enableccnt_exit(void)
       asm volatile("mcr p15, 0, %0, c9, c14, 0" :: "r"(0));
       printk(KERN_INFO DEVICE_NAME " stopping\n");
to create enableccnt.ko. As root, type
     insmod enableccnt.ko
     dmesg | grep enableccnt
so that the kernel runs enableccnt.ko. This should print enableccnt starting.

Now user programs can read the ARM Cortex A8 cycle counter for high-resolution timings. In particular, SUPERCOP (through its cortex module) will automatically use the ARM Cortex A8 cycle counter.

Rebooting will turn off access to the cycle counter. That probably isn't what you want, so edit /etc/rc.local to do the same insmod, but with a full path to enableccnt.ko.