Reputation: 487
Is it possible to use the Haswell CPU feature PEBS (Precise Event Based Sampling) directly from a Linux userspace process instead of using a kernel interface?
I have succeeded in accessing performance counters from userspace using the RDPMC instruction and only using the kernel for WRMSR. This makes me very happy.
Now I want to also access PEBS. To do this I need to use the MSR IA32_DS_AREA to supply a "debug store" memory area. However, I am not sure how to allocate this memory and what address I need to use. I can allocate 2MB of contiguous physical memory (Linux HugeTLB with mlock()). I can also resolve the physical address of this memory (via procfs). However, I am not sure whether either the virtual or physical address is suitable as the "linear address" to supply for the MSR. (My concern is that the address may have to be in the kernel's virtual address space that I don't have access to.)
How can I prepare suitable memory for IA32_DS_AREA and logging PEBS events without writing a custom kernel module?
Upvotes: 2
Views: 491
Reputation: 3180
Yes, it is possible by using the perf infrastructure (you avoid using RDPMC/WRMSR). You can find several examples in this Github repo and more specifically tests within the tests/record_sample
directory have multiple examples using the PEBS infrastructure through perf.
Upvotes: 0