I am using Linux 5.8.18 to do performance tuning, then I hit a confusion.
PMU in X86 is limited resource, and perf is the tool to use the PMU to complete profiling/sampling.
IIRC, perf document says the PMU resource is being shared by different processes, so Linux kernel will keep/snapshot the PMCs during process scheduling.
To verify that PMU setting is process specific, I did following tests.
A process running in background to call perf API to enable and use X86 FIXed_Counter0 (instruction retired) (MSR 0x309) on CPU0.
Then in the bash, I rdmsr -p0 0x309, I found the counter is increasing when the process is running in the background.
I had thought that each process (A and Bash) should have its own snapshot of the PMC (FIXed_Counter0 in this case), but the test shows that the PMC is global visible...
I got really confused.