How do I read a specific core's (performance counter) register?
assembly, kernel, linux-kernel
Solution
Use `smp_call_function_single` to run your code on a specific CPU.
Problem
I can read/write a MSR register, but I don't know how to specify which core's MSR should be run. For example, I want to record the L2 private cache miss of each core respectively, so I need to specify the core id for each core. I know the smp_call_function() to call the code on all cores. If I add an insn that record the core ID this code is running and use the smp_call_function(), it should work. But if I only want to know core 1's L2 private cache miss, I will have to let all cores record the number, which is not neat to me. Is there any better solution to this? My codes for read/write operation MSR: ``` mov $0x0001010E, %eax # Write selector value to EAX xor %edx, %edx # Zero EDX mov $0x187, %ecx # Write logical register id to ECX (IA32_PERFEVTSEL1) wrmsr mov $0xc2, %ecx # Address of MSR IA32_PMC1 rdmsr # Read value into EAX:EDX (EAX contains low-order bytes) ```