LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   smp_processor_id() internal (https://www.linuxquestions.org/questions/linux-kernel-70/smp_processor_id-internal-736162/)

kuru 06-28-2009 04:48 AM

smp_processor_id() internal
 
If I follow the smp_processor_id(), I reach at per_cpu__cpu_number. However, I can not find when the per_cpu__cpu_number is set :(

Please let me know.
Thank you for your reading.

Uncle_Theodore 06-28-2009 11:12 PM

I think it's in the /boot/System.map file. But your question is not very clear to me...

osor 06-29-2009 06:09 AM

I think the OP means where in the running of the kernel is this value set (this is not at all obvious since it is given a value through preprocessor stringification). The answer is, at least for x86(_64) systems, in arch/x86/kernel/setup_percpu.c, line 491:
Code:

                per_cpu(cpu_number, cpu) = cpu;
What looks like a function is actually a macro which assigns to the variable with identifier per_cpu__cpu_number, through some magic on lines 28-29 of the same file as well as in include/linux/percpu-defs.h and elsewhere.

kuru 06-29-2009 10:24 PM

First of all, thank you for your answers and I'm sorry for not to mention about my working environment. My working environment is like below:
- Linux kernel 2.6.29
- x86, 32bit machine with 2 processors

I have seen that code and feel strange because of below code.
Code:

// arch/x86/kernel/smpboot.c
void __init native_smp_prepare_boot_cpu(void)
{
        int me = smp_boot_processor_id();
        init_gdt(me);
        ...
}

// arch/x86/kernel/smpcommon.c
__cpuinit void init_gdt(int cpu)
{
        ...
        per_cpu(cpu_number, cpu) = cpu;
}

As you see, 'me' is per_cpu__cpu_number. In init_gdt() it sets the per_cpu__cpu_number to the 'me' again.

osor 06-30-2009 02:19 PM

Quote:

Originally Posted by kuru (Post 3590909)
As you see, 'me' is per_cpu__cpu_number. In init_gdt() it sets the per_cpu__cpu_number to the 'me' again.

Yes, you are correct. There may have been a few reasons for this (perhaps there was a difference in smp_processor_id, which gets the cpu_number after temporarily disabling preemption, or maybe the init_gdt function was needed elsewhere to set the cpu_number).

This, however, is irrelevant since the offending code has already been removed. Moreover, the entire function init_gdt() is now gone.


All times are GMT -5. The time now is 02:28 AM.