How to operate registers on different processors in SMP Environment

Source: Internet
Author: User


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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.