PMONs are enabled using MSRs. MSRs 开发者_如何学JAVAare accessible only from ring 0. Is there any API to enable PMONs in Linux from user space?
I believe that what you're looking for is called "oprofile" on Linux. You can enable it from userspace, but it requires root access.
http://oprofile.sourceforge.net/
perfctr api allows this: http://www.ale.csce.kyushu-u.ac.jp/~satoshi/how_to_use_perfctr.htm
PAPI is another API. http://icl.cs.utk.edu/papi/
Use the Perf tool. It's a userspace tool for accessing the Linux kernel's perf_event API.
If you want to do the syscalls yourself, use perf_event syscalls, which are poorly documented as of May 2016. Check out the Unofficial Documentation, or the kernel source itself. The kernel source is guaranteed to be "correct" documentation, but, unfortunately, inscrutable.
精彩评论