In the SMP environment, how does one operate registers on different processors? In the SMP environment, your current code can only run on a certain processor at the same time, so how does this code operate registers on other processors? Let's take a simple example. Suppose there are four cores in my current system (this article does not show the differences between Socket, Processor, and core ), if I want to write a piece of code to initialize the PMU registers on these four cores (each core has its own registers), how can I perform this operation? The msr module of the actually kernel at www.2cto.com provides the reference code: get_online_cpus (); for_each_online_cpu (I ){...} put_online_cpus (); the above Code uses for_each_online_cpu to enumerate the id values of all cores in the system, that is, cpuid. in the preceding example, cpuid = 0, 1, 2, 3. with cpuid, you can use rdmsr_safe_on_cpu (cpu ...) and wrmsr_safe_on_cpu (cpu ...) to operate the registers of each core. Www.2cto.com so what is the principle behind the rdmsr/wrmsr_safe_on_cpu () function to obtain the register addresses on each cpu? The answer is APIC. in the system, each cpu is identified by APIC and its base addr is recorded in a per_cpu variable during system initialization. In this way, the register base addr of each processor can be obtained through cpuid.