Created
December 7, 2012 17:12
-
-
Save Coneko/4234770 to your computer and use it in GitHub Desktop.
How to check what core your code is running on.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The x86 cpuid instruction gives information about the processor | |
static inline void cpuid(uint32_t code, uint32_t data[4]) { | |
asm volatile("cpuid":"=a"(*data),"=b"(*(data+1)), | |
"=c"(*(data+2)),"=d"(*(data+3)):"a"(code)); | |
} | |
// Gets the APIC ID of the processor. Returns a unique identifier for each core. | |
static inline uint8_t apic_id(void) { | |
uint32_t data[4]; | |
cpuid(1, data); | |
uint32_t ebx = data[1]; | |
uint8_t apic_id = *((uint8_t *)&ebx + 3); | |
return apic_id; | |
} | |
// More information: http://wiki.osdev.org/Detecting_CPU_Topology_(80x86) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment