While this can be done for the uncore PCI counters, I don't think there is any reasonable way to do this for the MSRs. And you'd still be relying on the kernel to service your request since 'wrmsr' and 'rdmsr' can only be executed from Ring 0 (kernel mode).
But if your goal is to reduce overhead, you can read the performance counters with 'rdpmc', which can be configured to be usable from Ring 3 (user level). This is a route that I'm currently pursuing. More details in some of the messages here: https://groups.google.com/forum/#!forum/likwid-developers
Firstly, the Linux kernel already provides easy accessors for the MSRs, see arch/x86/include/asm/msr.h. Secondly, have you investigated the existing msr-tools package, and the existing driver for msr accesses? (see /dev/cpu/<n>/msr in usermode and arch/x86/kernel/msr.c providing the functionality).
Yes, I've looked at those, and presume the original author has too. You are definitely right that most users will find the built in functionality a better choice. My current interest is currently on how to allow low overhead self-profiling of user code without root access. I found this code to be a good introduction to what's happening under the hood, and possibly a good base for creating a PMU specific module to extend access to non-root non-SYS_CAP_RAWIO users.
6 comments
[ 2.2 ms ] story [ 27.4 ms ] threadI think that is be much less overhead for profiling if possible.
But if your goal is to reduce overhead, you can read the performance counters with 'rdpmc', which can be configured to be usable from Ring 3 (user level). This is a route that I'm currently pursuing. More details in some of the messages here: https://groups.google.com/forum/#!forum/likwid-developers
This link about mapping PCI configuration space to be accessible to non-root users might be useful too: http://www.cs.usfca.edu/~cruse/cs698f11/uhci.c
It sounds like you have some familiarity with this. If you have thoughts, I'd love to hear on the Likwid developers list: https://groups.google.com/forum/#!forum/likwid-developers