Performance counters in the processor cannot be read from the "user" code, so for this you need some kind of kernel module. Once you have this, itβs not very difficult, there are several MSRs.
Perhaps you can also use / dev / cpu / core -number / msr to read values ββwithout a kernel module.
To describe all the details of how you do this is too much to answer (unless I copy the entire section of the Intel programmer's guide (Vol3), which, I think, is not quite what we want here ...)
source share