Skip to content

runtime: implement cputicks using MRC(PMCCNTR) on arm #9892

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dvyukov opened this issue Feb 16, 2015 · 6 comments
Closed

runtime: implement cputicks using MRC(PMCCNTR) on arm #9892

dvyukov opened this issue Feb 16, 2015 · 6 comments
Milestone

Comments

@dvyukov
Copy link
Member

dvyukov commented Feb 16, 2015

Current implementation of cputicks on ARM is very low precision which hurts block profile and tracer.

http://gperftools.googlecode.com/svn/trunk/src/base/cycleclock.h
contains lots of goodness, and in particular cputicks implementation for arm:

#elif defined(ARMV3)
#if defined(ARMV6)  // V6 is the earliest arch that has a standard cyclecount
    uint32 pmccntr;
    uint32 pmuseren;
    uint32 pmcntenset;
    // Read the user mode perf monitor counter access permissions.
    asm volatile ("mrc p15, 0, %0, c9, c14, 0" : "=r" (pmuseren));
    if (pmuseren & 1) {  // Allows reading perfmon counters for user mode code.
      asm volatile ("mrc p15, 0, %0, c9, c12, 1" : "=r" (pmcntenset));
      if (pmcntenset & 0x80000000ul) {  // Is it counting?
        asm volatile ("mrc p15, 0, %0, c9, c13, 0" : "=r" (pmccntr));
        // The counter is set up to count every 64th cycle
        return static_cast<int64>(pmccntr) * 64;  // Should optimize to << 6
      }
    }
#endif

Should consider switching to it.

There is also an impl for power processors.

@dvyukov dvyukov added this to the Go1.5 milestone Feb 16, 2015
@dvyukov
Copy link
Member Author

dvyukov commented Feb 16, 2015

@minux @davecheney

@minux
Copy link
Member

minux commented Feb 16, 2015 via email

@davecheney
Copy link
Contributor

That was my suspicion as well, I don't see how the kernel could multiplex these singleton resources across anyone who could whip up an MRC instruction.

On 16 Feb 2015, at 19:40, Minux Ma notifications@github.com wrote:

The problem is that not all kernel allow user access to performance
counters.

I tried to read pmuseren, but the result is 0 with an old 3.0 kernel.

Reply to this email directly or view it on GitHub.

@crawshaw
Copy link
Member

We discussed this recently on #9725 (in fact this may be a duplicate). The best I could find was perf_event_open, which still requires a read syscall.

@bradfitz
Copy link
Contributor

bradfitz commented Jul 7, 2015

Time to punt this to Go 1.6?

@rsc
Copy link
Contributor

rsc commented Jul 21, 2015

Dup of #9725

@rsc rsc closed this as completed Jul 21, 2015
@golang golang locked and limited conversation to collaborators Jul 20, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants