To make the PCM counters work on Linux the user running the code needs to read/write access to the /dev/cpu/*/msr files. A nice way to do this is using unix groups.
First create a new group to give msr privileges too:
sudo groupadd msr
Add the user that needs to run the PCM code to that group:
sudo usermod -G -a msr someuser
Set the permissions on the msr device files to allow that users to read and write (you may need to put this in a script to run at start up if it needs to be persistent).
sudo chgrp msr /dev/cpu/*/msr sudo chmod 0660 /dev/cpu/*/msr