This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

how to read CCNT on ARM1176

I want to use CCNT register readings to profile short code segments. The code to read CCNT would be in C (if possible) or C inline assembly compiled under Linux by ccp. Can somebody provide an example? I found this in online documentation:

MRC p15, 0, <Rd>, c15, c12, 1   ; read the CCNT

I don't know ARM assembly syntax. c15 seems to refer to the CCNT, according to the documentation, but what about p15, c12 and 0 and 1? Does <Rd> stand for where you want to put the result?

I am using RDTSC in x86 inline assembly for this purpose. Does the CCNT have similar semantics?

  • The syntax for accessing coprocessor registers takes a little getting used to.  I'll try to explain it (see below), but IMHO it's kind of academic.  The Architecture Reference Manual gives the the required instruction to read or write each register, so you can treat them as "magic runes".

    On accessing the PMU, do you mean you are writing a Linux app (i.e. running in User space)?  If so, by default the PMU can only be accessed from privileged modes (think kernel space).  You can enable User mode access, but you'd need to check whether your kernel has.  Generally to avoid this (and other issues related to allowing apps direct access to the PMU) application code accesses the PMU via an API.  Such as oprofile or perf.

    ----

    The basic syntax of a coprocessor register write instruction is:

      MCR <coproc>, <opc1>, <Rt>, <CRn>, <CRm>, <opc2>

    MCR is a write of a coprocessor register, MRC would be a read from a coprocessor.

    <coproc> is the coprocessor number.  You'll pretty much only use p15 (system control registers) or p14 (debug registers)

    <CRn> is the primary register group.  Usually a group of functionally related registers.  For example c7 for cache maintenance operations.

    <opc1>+<CRm>+<opc2> specifies the particular register in the group.

    <Rt> is the ARM register being used.  As the MCR is a write of a coprocessor register, this is the register containing the date you want to write.  If it were a MRC (coprocessor read) it's where the read data would end up.

  • Thanks, Martin, The decision to make reading CCNT a privileged operation seems to me unfortunate. I'll just disable that level of profiling in my program when I compile for ARM.