How can I read a specific register (performance counter)?

I can read / write the MSR register, but I do not know how to indicate which main MSR should be started.

For example, I want to write the gaps of the private L2 cache for each core, respectively, so I need to specify the kernel ID for each core.

I know smp_call_function () to call code on all cores. If I add an insn that writes the kernel ID, this code runs and uses smp_call_function (), it should work. But if I just want to learn about the 1st personal cache memory of kernel 1, I will have to leave all the kernels, writing down a number that does not match me.

Is there a better solution for this?

My codes for the MSR read / write operation are:

   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)
+4
1

smp_call_function_single .

+3

Source: https://habr.com/ru/post/1524094/


All Articles